forked from dmitmel/CCUpdaterUI
/
packedModManager.go
176 lines (163 loc) · 5.37 KB
/
packedModManager.go
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package main
import (
"github.com/20kdc/CCUpdaterUI/design"
"github.com/20kdc/CCUpdaterUI/middle"
"github.com/20kdc/CCUpdaterUI/frenyard"
"github.com/20kdc/CCUpdaterUI/frenyard/framework"
"github.com/20kdc/CCUpdaterUI/frenyard/integration"
"github.com/CCDirectLink/CCUpdaterCLI"
"github.com/CCDirectLink/CCUpdaterCLI/remote"
)
type upPackedModState map[string]ccmodupdater.RemotePackage
func (app *upApplication) ShowInitPackedModManager(back framework.ButtonBehavior, firstModPath string) {
initState := make(upPackedModState)
app.ShowPackedModManagerAttemptToAddMod(initState, back, func () {
app.ShowPackedModManager(back, initState)
}, firstModPath)
}
func (app *upApplication) ShowPackedModManagerAttemptToAddMod(state upPackedModState, back framework.ButtonBehavior, fwd framework.ButtonBehavior, modPath string) {
pmr, err := remote.NewPackedModRemotePackage(modPath)
if err != nil {
app.MessageBox("Error", err.Error(), back)
}
id := pmr.Metadata().Name()
if state[id] != nil {
app.MessageBox("Error", "You've already added mod " + id + ".", back)
} else {
state[id] = pmr
fwd()
}
}
func (app *upApplication) ShowPackedModManager(back framework.ButtonBehavior, mods upPackedModState) {
backHere := func () {
app.GSLeftwards()
app.ShowPackedModManager(back, mods)
}
localPackages := app.gameInstance.Packages()
remotePackages := make(map[string]ccmodupdater.RemotePackage)
// Overlay these two to create the actual transaction environment
for k, v := range middle.GetRemotePackages() {
remotePackages[k] = v
}
for k, v := range mods {
remotePackages[k] = v
}
packageTXContext := ccmodupdater.PackageTXContext {
LocalPackages: localPackages,
RemotePackages: remotePackages,
}
// Setup the transaction, solve it, and find involved of results
packageTX := make(ccmodupdater.PackageTX)
for modID, _ := range mods {
packageTX[modID] = ccmodupdater.PackageTXOperationInstall
}
// This relies on packageTXSolutions always containing some meaningful information even on error.
packageTXSolutions, packageTXErr := packageTXContext.Solve(packageTX)
involved := make(map[string]bool)
for _, solution := range packageTXSolutions {
for k, _ := range solution {
involved[k] = true
}
}
modSlots := []framework.FlexboxSlot{}
for modID, modPkg := range mods {
localModID := modID
modSlots = append(modSlots, framework.FlexboxSlot{
Element: design.ListItem(design.ListItemDetails{
Icon: design.ModIconID,
Text: modID,
Subtext: modPkg.Metadata().Description(),
Click: func () {
delete(mods, localModID)
backHere()
},
}),
RespectMinimumSize: true,
})
}
for depID, _ := range involved {
if mods[depID] != nil {
// ok, it's already dealt with
continue
}
// it hasn't been dealt with, show an obvious warning
depItem := design.ListItemDetails{
Icon: design.WarningIconID,
Text: depID,
Subtext: "This is missing. If it's available as a .ccmod, you can add it - it isn't available in CCModDB.",
Click: func () {
// Nothing to do here, can't do anything...
},
}
if remotePackages[depID] != nil {
depItem.Icon = design.UpdatableIconID
depItem.Subtext = "This will automatically be downloaded. Alternatively, you can add a specific version as a .ccmod here."
}
modSlots = append(modSlots, framework.FlexboxSlot{
Element: design.ListItem(depItem),
RespectMinimumSize: true,
})
}
// Space-taker to prevent wrongly scaled list items
modSlots = append(modSlots, framework.FlexboxSlot{
Grow: 1,
Shrink: 0,
})
readyModsScroller := design.ScrollboxV(framework.NewUIFlexboxContainerPtr(framework.FlexboxContainer{
DirVertical: true,
WrapMode: framework.FlexboxWrapModeNone,
Slots: modSlots,
}))
installButtonColour := design.ThemeOkActionButton
installButtonText := "INSTALL"
if packageTXErr != nil {
installButtonColour = design.ThemeImpossibleActionButton
installButtonText = "NOT INSTALLABLE"
}
content := framework.NewUIFlexboxContainerPtr(framework.FlexboxContainer{
DirVertical: true,
Slots: []framework.FlexboxSlot{
framework.FlexboxSlot{
Element: framework.NewUILabelPtr(integration.NewTextTypeChunk("This is the set of mods to install so far. To remove a mod, click on it in the list.", design.GlobalFont), design.ThemeText, 0, frenyard.Alignment2i{}),
},
framework.FlexboxSlot{
Basis: design.SizeMarginAroundEverything,
},
framework.FlexboxSlot{
Element: readyModsScroller,
Grow: 1,
Shrink: 1,
RespectMinimumSize: true,
},
framework.FlexboxSlot{
Basis: design.SizeMarginAroundEverything,
},
framework.FlexboxSlot{
Element: design.ButtonBar([]framework.UILayoutElement{
design.ButtonAction(design.ThemeUpdateActionButton, "ADD MOD...", func () {
app.GSRightwards()
app.ShowPackedModFinder(backHere, func (path string) {
app.ShowPackedModManagerAttemptToAddMod(mods, backHere, backHere, path)
}, middle.BrowserVFSPathDefault)
}),
design.ButtonAction(installButtonColour, installButtonText, func () {
app.GSRightwards()
app.PerformTransaction(func (success bool) {
if success {
app.GSLeftwards()
app.ShowPrimaryView()
} else {
backHere()
}
}, packageTX, remotePackages)
}),
}),
},
},
})
primary := design.LayoutDocument(design.Header{
Back: back,
Title: "Install Packed Mods...",
}, content, true)
app.Teleport(primary)
}