-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpanel.go
134 lines (122 loc) · 4.13 KB
/
panel.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
package main
import (
"fmt"
"github.com/jcgraybill/ship-shape/panel"
"github.com/jcgraybill/ship-shape/planet"
"github.com/jcgraybill/ship-shape/resource"
"github.com/jcgraybill/ship-shape/structure"
"github.com/jcgraybill/ship-shape/ui"
)
func showBuildOptionsPanel(p *planet.Planet, g *Game) {
for _, s := range g.level.AllowedStructures() {
if g.structureData[s].Buildable {
if g.structureData[s].Class == structure.Tax {
g.panel.AddButton(fmt.Sprintf("build %s ($%d)", g.structureData[structure.HQ].DisplayName, g.structureData[structure.HQ].Cost),
generateConstructionCallback(g, p, structure.HQ),
func() bool {
if hasCapitol, _ := g.player.Capitol(); !hasCapitol && g.player.Money() >= g.structureData[structure.HQ].Cost {
return true
} else {
return false
}
},
)
} else {
cost := g.structureData[s].Cost
g.panel.AddButton(fmt.Sprintf("build %s ($%d)", g.structureData[s].DisplayName, cost),
generateConstructionCallback(g, p, s),
func() bool {
if g.player.Money() >= cost {
return true
} else {
return false
}
},
)
}
}
}
}
func showPlanetPanel(pl *panel.Panel, p *planet.Planet, rd *[resource.ResourceDataLength]resource.ResourceData, allowed []int) {
pl.AddLabel(func() string { return fmt.Sprintf("planet: %s", p.Name()) }, ui.TtfBold)
for _, resource := range allowed {
if level, exists := p.Resources()[resource]; exists {
lvl := level
name := rd[resource].DisplayName
pl.AddLabel(func() string { return name }, ui.TtfRegular)
pl.AddBar(func() uint8 { return lvl }, rd[resource].Color)
}
}
}
func showPlayerPanel(g *Game) int {
g.panel.AddInvertedLabel(g.level.Title, ui.TtfBold)
g.panel.AddLabel(g.player.PopulationLabel, ui.TtfRegular)
g.panel.AddLabel(g.player.MoneyLabel, ui.TtfRegular)
g.panel.AddDivider()
g.panel.AddLabel(g.level.Message, ui.TtfRegular)
g.panel.AddDivider()
g.panel.AddLabel(g.level.Label, ui.TtfRegular)
g.panel.AddBar(g.level.ProgressBarValue, ui.LevelProgressColor)
g.panel.AddDivider()
return 9
}
func showStructure(pl *panel.Panel, s *structure.Structure, rd *[resource.ResourceDataLength]resource.ResourceData, allowed []int) {
pl.AddLabel(func() string { return s.Name() }, ui.TtfBold)
if s.WorkerCapacity() > 0 {
pl.AddLabel(s.WorkersLabel, ui.TtfRegular)
}
if len(s.Storage()) > 0 {
pl.AddDivider()
for _, resource := range allowed {
if st, exists := s.Storage()[resource]; exists {
pl.AddLabel(s.ResourceLabelCallback(rd[resource].DisplayName, resource), ui.TtfRegular)
pl.AddBar(s.ResourceBarCallback(resource), rd[st.Resource].Color)
}
}
}
}
func showStructurePanel(g *Game, s *structure.Structure) {
showStructure(g.panel, s, g.resourceData, g.level.AllowedResources())
if g.structureData[s.StructureType()].Workers > 0 {
if s.IsPaused() {
g.panel.AddButton("resume production", generateUnPauseCallback(g, s), func() bool { return true })
} else {
g.panel.AddButton("pause production", generatePauseCallback(g, s), func() bool { return true })
}
}
if g.structureData[s.StructureType()].Prioritize > 0 && !s.IsPaused() {
if s.IsPrioritized() {
g.panel.AddButton("normal deliveries", generateUnPrioritizeCallback(g, s), func() bool { return true })
} else {
g.panel.AddButton(fmt.Sprintf("prioritize deliveries ($%d)", g.structureData[s.StructureType()].Prioritize),
generatePrioritizeCallback(g, s),
func() bool {
if g.player.Money() >= g.structureData[s.StructureType()].Prioritize {
return true
} else {
return false
}
},
)
}
}
for _, st := range g.level.AllowedStructures() {
if st > 0 && st == s.UpgradeTo() {
cost := g.structureData[s.UpgradeTo()].Cost
s1 := s
g.panel.AddButton(fmt.Sprintf("upgrade to %s ($%d)", g.structureData[s.UpgradeTo()].DisplayName, cost),
generateUpgradeCallBack(g, s, s.UpgradeTo()),
func() bool {
if g.player.Money() >= cost && s1.Upgradeable() {
return true
} else {
return false
}
},
)
}
}
g.panel.AddDivider()
showPlanetPanel(g.panel, s.Planet(), g.resourceData, g.level.AllowedResources())
g.panel.AddDivider()
}