-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.go
165 lines (143 loc) · 3.29 KB
/
ui.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
// Drawing the giu UI
package main
import (
"fmt"
"github.com/AllenDang/giu"
"golang.org/x/text/language"
"golang.org/x/text/message"
)
const leftColumnWidth = 200
type SpeedWidgets struct {
pause *giu.ButtonWidget
slider *giu.SliderFloatWidget
max *giu.ButtonWidget
}
func (a *Anaxim) initUI() {
a.speedWidgets = NewSpeedWidgets(a)
switch a.speed {
case Paused:
a.setSpeedToPaused()
case Custom:
a.setSpeedToCustom()
case Unlimited:
a.setSpeedToUnlimited()
}
}
func (a *Anaxim) NewBaseSpeedButton(label string, onClick func(*Anaxim)) *giu.ButtonWidget {
return giu.Button(label).OnClick(func() { onClick(a) }).Size(100, 20)
}
func (a *Anaxim) PauseButton(label string) *giu.ButtonWidget {
return a.NewBaseSpeedButton(label, clickPause)
}
func (a *Anaxim) MaxButton(label string) *giu.ButtonWidget {
return a.NewBaseSpeedButton(label, clickMax)
}
func NewSpeedWidgets(a *Anaxim) *SpeedWidgets {
return &SpeedWidgets{
a.PauseButton("Pause"),
giu.SliderFloat(&a.speedCustomTPS, 0, 1).
OnChange(func() { a.setSpeedToCustom() }).
Size(300),
a.MaxButton("Enable max"),
}
}
func (a *Anaxim) genSpeedText() string {
return "Speed controls. Currently " + map[Speed]string{
Paused: "paused",
Custom: "on custom (slider) speed.",
Unlimited: "on unlimited (max) speed.",
}[a.speed]
}
func (a *Anaxim) genGlobalStatsString() string {
biggestCell := a.simulation.humanGrid.biggestPopCell
printer := message.NewPrinter(language.English)
return printer.Sprintf(
`Simulation generation:
%d
World population:
%d
Biggest population:
%d @ (%d,%d)`,
a.simulation.humanGrid.generation,
a.simulation.humanGrid.globalPop,
biggestCell.population, biggestCell.x, biggestCell.y,
)
}
func (a *Anaxim) genLocalStatsString() string {
ic := a.inspectingCell
if ic == nil {
return "Click on the map to inspect."
}
printer := message.NewPrinter(language.English)
dev := fmt.Sprint(ic.development)
if dev == "1" {
dev += " (base)"
}
prefix := fmt.Sprintf(
`Inspecting cell @ %v
Map info:`, a.inspectingCellAt.String())
mc := ic.mapCell
if !mc.isLand {
return prefix + "\n\tWater cell"
}
mapInfo := fmt.Sprintf("Land cell\n\tHabitability:\n\t%v", mc.habitability)
return printer.Sprintf(
`%v
%v
Human activity:
Population:
%d
Development:
%v`,
prefix,
mapInfo,
ic.population, dev,
)
}
func (a *Anaxim) createLayout() {
img := giu.Image(a.mapTexture)
img.Size(
float32(a.mapImage.Bounds().Dx()*mapResize),
float32(a.mapImage.Bounds().Dy()*mapResize))
giu.SingleWindow().Layout(
giu.Row(
giu.Column(
giu.Row(
giu.Label(a.genGlobalStatsString()).Wrapped(true),
),
giu.Row(
giu.Dummy(leftColumnWidth, 30),
),
giu.Row(
giu.Label(a.genLocalStatsString()).Wrapped(true),
),
),
giu.Column(
giu.Row(
giu.Label(a.genSpeedText()),
),
giu.Row(
a.speedWidgets.pause,
a.speedWidgets.slider,
a.speedWidgets.max,
giu.Label(a.TimeBetweenLastTicks().String()),
),
giu.Row(
giu.Button("+").OnClick(func() {
mapResize++
}).Size(60, 20),
giu.Button("-").OnClick(func() {
if mapResize > 1 {
mapResize--
}
}).Size(60, 20),
giu.Label(a.howeringOverCellAt.String()),
),
giu.Row(
img,
a.mapInputEvents(),
),
),
),
)
}