-
Notifications
You must be signed in to change notification settings - Fork 1
/
gameui.go
132 lines (113 loc) · 4.06 KB
/
gameui.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
package dctycoon
import (
"github.com/nzin/dctycoon/accounting"
"github.com/nzin/dctycoon/global"
"github.com/nzin/dctycoon/supplier"
"github.com/nzin/dctycoon/timer"
"github.com/nzin/sws"
log "github.com/sirupsen/logrus"
)
type GameUI struct {
rootwindow *sws.RootWidget
dc *DcWidget
opening *MainOpening
supplierwidget *MainSupplierWidget
inventorywidget *MainInventoryWidget
statswidget *MainStatsWidget
accountingwidget *accounting.MainAccountingWidget
electricitywidget *MainElectricityWidget
firewallwidget *MainFirewallWidget
dock *DockWidget
eventpublisher *timer.EventPublisher
}
func NewGameUI(quit *bool, root *sws.RootWidget, game *Game) *GameUI {
gamemenu := NewMainGameMenu(game, root, quit)
gameui := &GameUI{
rootwindow: root,
dc: NewDcWidget(root.Width(), root.Height(), root),
opening: NewMainOpening(root.Width(), root.Height(), root, gamemenu),
supplierwidget: NewMainSupplierWidget(root),
inventorywidget: NewMainInventoryWidget(root),
statswidget: NewMainStatsWidget(root, game),
accountingwidget: accounting.NewMainAccountingWidget(root),
electricitywidget: NewMainElectricityWidget(root),
dock: NewDockWidget(root, game, gamemenu),
eventpublisher: timer.NewEventPublisher(root),
firewallwidget: NewMainFirewallWidget(root),
}
gameui.dock.SetShopCallback(func() {
gameui.supplierwidget.Show()
})
gameui.dock.SetStatsCallback(func() {
gameui.statswidget.Show()
})
gameui.dock.SetFirewallCallback(func() {
gameui.firewallwidget.Show()
})
gameui.dock.SetLedgerCallback(func() {
gameui.accountingwidget.Show()
})
gameui.dock.SetInventoryCallback(func() {
gameui.inventorywidget.Show()
})
gameui.dock.SetElectricityCallback(func() {
gameui.electricitywidget.Show()
})
gameui.dc.SetInventoryManagementCallback(func() {
gameui.inventorywidget.Show()
})
return gameui
}
//
// SetGame is used when creating a new game, or loading a game
// This re-init all ledger / inventory UI.
// Therefore you have to populate the ledger and inventory AFTER calling this method
func (self *GameUI) SetGame(globaltimer *timer.GameTimer, player *Player, trends *supplier.Trend, dcmap *DatacenterMap) {
log.Debug("GameUI::InitGame()")
self.dc.SetGame(player.GetInventory(), globaltimer.CurrentTime, dcmap)
self.supplierwidget.SetGame(globaltimer, player.GetInventory(), player.GetLedger(), trends)
self.inventorywidget.SetGame(player, globaltimer.CurrentTime)
self.accountingwidget.SetGame(globaltimer, player.GetLedger())
self.dock.SetGame(globaltimer, player.GetLedger())
self.statswidget.SetGame()
self.firewallwidget.SetGame(player.GetFirewall())
self.electricitywidget.SetGame(player.GetInventory(), player.GetLocation())
self.supplierwidget.Hide()
self.inventorywidget.Hide()
self.accountingwidget.Hide()
self.statswidget.Hide()
self.firewallwidget.Hide()
}
func (self *GameUI) ShowDC() {
self.rootwindow.RemoveChild(self.opening)
self.rootwindow.AddChild(self.dc)
self.rootwindow.AddChild(self.dock)
self.rootwindow.SetFocus(self.dc)
self.supplierwidget.Hide()
self.inventorywidget.Hide()
self.accountingwidget.Hide()
self.statswidget.Hide()
self.firewallwidget.Hide()
self.dc.HideUpgrade()
self.dc.PostUpdate()
}
func (self *GameUI) ShowOpening() {
self.rootwindow.RemoveChild(self.dc)
self.rootwindow.RemoveChild(self.dock)
self.rootwindow.AddChild(self.opening)
self.rootwindow.SetFocus(self.opening)
}
func (self *GameUI) ShowUpgrade(game *Game, nextmap string) {
self.dc.ShowUpgrade()
self.dc.SetUpgradeCallback(func() {
speed := game.GetCurrentSpeed()
game.ChangeGameSpeed(SPEED_STOP)
iconsurface, _ := global.LoadImageAsset("assets/ui/small-rocket-ship-silhouette.png")
sws.ShowModalYesNoSurfaceicon(self.rootwindow, "Relocate for bigger", iconsurface, "Are you sure you want to relocate now?\nThere is a 50k fee for that.", func() {
game.GetPlayer().GetLedger().PayMapUpgrade(50000, game.timer.CurrentTime)
game.MigrateMap(nextmap)
}, func() {
game.ChangeGameSpeed(speed)
})
})
}