forked from dmitmel/CCUpdaterUI
/
primaryView.go
144 lines (133 loc) · 4.22 KB
/
primaryView.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
package main
import (
"github.com/20kdc/CCUpdaterUI/frenyard/framework"
"github.com/20kdc/CCUpdaterUI/design"
"github.com/20kdc/CCUpdaterUI/middle"
"github.com/CCDirectLink/CCUpdaterCLI"
"sort"
)
// ShowPrimaryView shows the "Primary View" (the mod list right now)
func (app *upApplication) ShowPrimaryView() {
// This is used to preserve the state when nothing has changed (for example, when browsing).
var thePage framework.UILayoutElement
slots := []framework.FlexboxSlot{}
warnings := middle.FindWarnings(app.gameInstance)
if app.config.DevMode {
warnings = append(warnings, middle.Warning{
Text: "You are in developer mode! Go to the Build Information (top-right button, 'Credits', 'Build Information') to deactivate it.",
Action: middle.NullActionWarningID,
})
}
for _, v := range warnings {
fixAction := framework.ButtonBehavior(nil)
if v.Action == middle.InstallOrUpdatePackageWarningID {
pkgID := v.Parameter
fixAction = func () {
app.GSRightwards()
app.ShowPackageView(func () {
app.GSLeftwards()
app.ShowPrimaryView()
}, func () {
app.GSLeftwards()
app.Teleport(thePage)
}, pkgID)
}
}
slots = append(slots, framework.FlexboxSlot{
Element: design.InformationPanel(design.InformationPanelDetails{
Text: v.Text,
ActionText: "FIX",
Action: fixAction,
}),
})
}
// Ok, let's get all the packages in a nice row
localPackages := app.gameInstance.Packages()
remotePackages := middle.GetRemotePackages()
packageSet := make(map[string]bool)
packageList := []design.ListItemDetails{}
for k := range localPackages {
packageSet[k] = true
}
for k := range remotePackages {
packageSet[k] = true
}
// Actually build the UI now!
for pkgID := range packageSet {
local := localPackages[pkgID]
remote := remotePackages[pkgID]
latest := middle.GetLatestOf(local, remote)
var typeCheck ccmodupdater.Package = local
if typeCheck == nil {
typeCheck = remote
}
if (!app.config.DevMode) && (typeCheck.Metadata().Type() != ccmodupdater.PackageTypeMod) {
continue
}
status := "unable to comprehend status"
if local != nil && remote != nil {
lmv := local.Metadata().Version()
rmv := remote.Metadata().Version()
if local.Metadata().Version().GreaterThan(remote.Metadata().Version()) {
status = lmv.Original() + " installed (local development build, " + rmv.Original() + " remote)"
} else if remote.Metadata().Version().GreaterThan(local.Metadata().Version()) {
status = lmv.Original() + " installed (out of date, " + rmv.Original() + " available)"
} else {
status = lmv.Original() + " (up to date)"
}
} else if local != nil {
status = latest.Metadata().Version().Original() + " installed (no remote copy)"
} else if remote != nil {
status = latest.Metadata().Version().Original() + " available"
}
pkgIDLocal := pkgID
packageList = append(packageList, design.ListItemDetails{
Icon: middle.PackageIcon(latest),
Text: latest.Metadata().HumanName(),
Subtext: status,
Click: func () {
app.GSRightwards()
app.ShowPackageView(func () {
app.GSLeftwards()
app.ShowPrimaryView()
}, func () {
app.GSLeftwards()
app.Teleport(thePage)
}, pkgIDLocal)
},
})
}
sort.Sort(design.SortListItemDetails(packageList))
slots = append(slots, framework.FlexboxSlot{
Element: design.NewUISearchBoxPtr("Search...", packageList),
Grow: 1,
})
// Keep copies of whatever the options menu can change.
// If we're returned to with something changed, refresh.
// Otherwise try to reuse the element; it's better-performant and preserves state.
thePresentStateOfDevMode := app.config.DevMode
thePage = design.LayoutDocument(design.Header{
Title: "Mods",
Back: func () {
app.GSLeftwards()
app.ResetWithGameLocation(false, middle.GameFinderVFSPathDefault)
},
BackIcon: design.GameIconID,
ForwardIcon: design.MenuIconID,
Forward: func () {
app.GSRightwards()
app.ShowOptionsMenu(func () {
app.GSLeftwards()
if thePresentStateOfDevMode != app.config.DevMode {
app.ShowPrimaryView()
} else {
app.Teleport(thePage)
}
})
},
}, framework.NewUIFlexboxContainerPtr(framework.FlexboxContainer{
DirVertical: true,
Slots: slots,
}), true)
app.Teleport(thePage)
}