This repository was archived by the owner on Aug 8, 2024. It is now read-only.
forked from dmitmel/CCUpdaterUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackageView.go
More file actions
141 lines (134 loc) · 5.16 KB
/
packageView.go
File metadata and controls
141 lines (134 loc) · 5.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package main
import (
"github.com/CCDirectLink/CCUpdaterUI/design"
"github.com/CCDirectLink/CCUpdaterUI/frenyard"
"github.com/CCDirectLink/CCUpdaterUI/frenyard/framework"
"github.com/CCDirectLink/CCUpdaterUI/frenyard/integration"
"github.com/CCDirectLink/CCUpdaterUI/middle"
"github.com/CCDirectLink/CCUpdaterCLI"
)
// ShowPackageView shows a dialog for a package.
// backHeavy is used if nothing actually happened.
// backLight is used if something happened (the ShowPackageView return call has both set to the same value).
// This allows preserving state in the PrimaryView.
func (app *upApplication) ShowPackageView(backHeavy framework.ButtonBehavior, backLight framework.ButtonBehavior, pkg string) {
// Construct a package context here and use it to sanity-check some things.
// It also makes a nice cup-holder for the local/remote repositories.
txCtx := ccmodupdater.PackageTXContext{
LocalPackages: app.gameInstance.Packages(),
RemotePackages: middle.GetRemotePackages(),
}
// Get local, remote and latest packages for reference.
localPkg := txCtx.LocalPackages[pkg]
remotePkg := txCtx.RemotePackages[pkg]
var latestPkg ccmodupdater.Package = middle.GetLatestOf(localPkg, remotePkg)
// No latest package = no information.
if latestPkg == nil {
if middle.InternetConnectionWarning {
app.MessageBox("Package not available", "The package '" + pkg + "' could not be found.\n\nAs you have ended up here, the package probably had to exist in some form.\nThis error is probably because CCUpdaterUI was unable to retrieve remote packages.\n\n1. Check your internet connection\n2. Try restarting CCUpdaterUI\n3. Contact us", backLight)
} else {
app.MessageBox("I just don't know what went wrong...", "The package '" + pkg + "' could not be found.\nYou should never be able to see this dialog in normal operation.", backLight)
}
return
}
// Ok, now let's actually start work on the UI
showInstallButton := false
annotations := "\n ID: " + pkg + "\n Latest Version: " + latestPkg.Metadata().Version().Original()
if localPkg != nil {
if remotePkg != nil && remotePkg.Metadata().Version().GreaterThan(localPkg.Metadata().Version()) {
annotations += "\n Installed: " + localPkg.Metadata().Version().Original()
showInstallButton = true
} else {
annotations += "\n Installed"
}
} else {
showInstallButton = true
}
chunks := []integration.TypeChunk{
integration.NewColouredTextTypeChunk(latestPkg.Metadata().HumanName(), design.GlobalFont, design.ThemeText),
integration.NewColouredTextTypeChunk(annotations, design.ListItemSubTextFont, design.ThemeSubText),
}
buttons := []framework.UILayoutElement{}
if (localPkg != nil) && pkg != "Simplify" {
removeTx := ccmodupdater.PackageTX{
pkg: ccmodupdater.PackageTXOperationRemove,
}
removeTheme := design.ThemeRemoveActionButton
_, removeErr := txCtx.Solve(removeTx)
buttonText := "REMOVE"
if removeErr != nil {
buttonText = "NOT REMOVABLE"
removeTheme = design.ThemeImpossibleActionButton
}
buttons = append(buttons, design.ButtonAction(removeTheme, buttonText, func () {
app.GSDownwards()
app.PerformTransaction(func () {
app.GSUpwards()
app.ShowPackageView(backHeavy, backHeavy, pkg)
}, removeTx)
}))
}
if showInstallButton {
installTx := ccmodupdater.PackageTX{
pkg: ccmodupdater.PackageTXOperationInstall,
}
buttonText := "INSTALL"
buttonColour := design.ThemeOkActionButton
if localPkg != nil {
buttonText = "UPDATE"
buttonColour = design.ThemeUpdateActionButton
}
_, removeErr := txCtx.Solve(installTx)
if removeErr != nil {
buttonText = "NOT INSTALLABLE"
buttonColour = design.ThemeImpossibleActionButton
}
buttons = append(buttons, design.ButtonAction(buttonColour, buttonText, func () {
app.GSDownwards()
app.PerformTransaction(func () {
app.GSUpwards()
app.ShowPackageView(backHeavy, backHeavy, pkg)
}, installTx)
}))
}
detail := framework.NewUIFlexboxContainerPtr(framework.FlexboxContainer{
DirVertical: false,
Slots: []framework.FlexboxSlot{
framework.FlexboxSlot{
Element: design.NewIconPtr(0xFFFFFFFF, middle.PackageIcon(latestPkg), 36),
},
framework.FlexboxSlot{
Basis: design.SizeMarginAroundEverything,
},
framework.FlexboxSlot{
Element: framework.NewUILabelPtr(integration.NewCompoundTypeChunk(chunks), 0xFFFFFFFF, 0, frenyard.Alignment2i{X: frenyard.AlignStart, Y: frenyard.AlignStart}),
},
},
})
fullPanel := framework.NewUIFlexboxContainerPtr(framework.FlexboxContainer{
DirVertical: true,
Slots: []framework.FlexboxSlot{
framework.FlexboxSlot{
Element: detail,
},
framework.FlexboxSlot{
Basis: design.SizeMarginAroundEverything,
},
framework.FlexboxSlot{
Element: framework.NewUILabelPtr(integration.NewTextTypeChunk(latestPkg.Metadata().Description(), design.GlobalFont), design.ThemeText, 0, frenyard.Alignment2i{X: frenyard.AlignStart, Y: frenyard.AlignStart}),
Shrink: 1,
},
framework.FlexboxSlot{
Grow: 1,
Shrink: 1,
},
framework.FlexboxSlot{
Element: design.ButtonBar(buttons),
},
},
})
app.Teleport(design.LayoutDocument(design.Header{
Title: latestPkg.Metadata().HumanName(),
Back: backLight,
}, fullPanel, true))
}