-
Notifications
You must be signed in to change notification settings - Fork 1
/
debugopponentwidget.go
119 lines (103 loc) · 2.97 KB
/
debugopponentwidget.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
package dctycoon
import (
"fmt"
"github.com/nzin/dctycoon/global"
"github.com/nzin/dctycoon/supplier"
"github.com/nzin/sws"
)
type DebugOpponentWidget struct {
sws.CoreWidget
refreshbutton *sws.ButtonWidget
table *sws.TableWidget
data [][]string
datachangecallback func()
bigmapbutton *sws.ButtonWidget
smallmapbutton *sws.ButtonWidget
game *Game
}
func NewDebugOpponentWidget(w, h int32, game *Game) *DebugOpponentWidget {
core := sws.NewCoreWidget(w, h)
widget := &DebugOpponentWidget{
CoreWidget: *core,
refreshbutton: sws.NewButtonWidget(200, 25, "Refresh"),
data: make([][]string, 0, 0),
bigmapbutton: sws.NewButtonWidget(200, 25, "Switch to 32x32 map"),
smallmapbutton: sws.NewButtonWidget(200, 25, "Switch to 3x4 map"),
game: game,
}
widget.refreshbutton.SetClicked(widget.refresh)
widget.AddChild(widget.refreshbutton)
widget.table = sws.NewTableWidget(200, 200, widget)
widget.table.Move(0, 25)
widget.AddChild(widget.table)
widget.bigmapbutton.Move(0, 250)
widget.AddChild(widget.bigmapbutton)
widget.bigmapbutton.SetClicked(func() {
game.MigrateMap("32_32_standard.json")
})
widget.smallmapbutton.Move(200, 250)
widget.AddChild(widget.smallmapbutton)
widget.smallmapbutton.SetClicked(func() {
game.MigrateMap("3_4_room.json")
})
return widget
}
func (self *DebugOpponentWidget) refresh() {
self.data = make([][]string, 0, 0)
for _, o := range self.game.GetNPActors() {
for _, i := range o.GetInventory().Items {
if i.Typeitem == supplier.PRODUCT_SERVER {
array := make([]string, 5, 5)
array[0] = o.GetName()
array[1] = global.AdjustMega(i.Serverconf.NbDisks * i.Serverconf.DiskSize)
array[2] = global.AdjustMega(i.Serverconf.NbSlotRam * i.Serverconf.RamSize)
array[3] = fmt.Sprintf("%d", i.Serverconf.NbCore)
array[4] = "false"
if i.Diskallocated != 0 {
array[4] = "true"
}
self.data = append(self.data, array)
}
}
}
self.datachangecallback()
}
func (self *DebugOpponentWidget) Resize(w, h int32) {
self.CoreWidget.Resize(w, h)
if h > 50 {
self.table.Resize(w, h-50)
self.bigmapbutton.Move(0, h-25)
self.smallmapbutton.Move(200, h-25)
}
}
func (self *DebugOpponentWidget) GetNbColumns() int32 {
return 5
}
func (self *DebugOpponentWidget) GetNbRows() int32 {
return int32(len(self.data))
}
func (self *DebugOpponentWidget) GetHeader(column int32) (string, int32) {
switch column {
case 0:
return "owner", 200
case 1:
return "disk", 100
case 2:
return "ram", 100
case 3:
return "cpu", 100
case 4:
return "allocated", 100
}
return "undefined", 100
}
func (self *DebugOpponentWidget) GetCell(column, row int32) string {
return self.data[row][column]
}
// when the table grows/shrink
func (self *DebugOpponentWidget) SetRowUpdateCallback(callback func()) {
self.datachangecallback = callback
}
// when the table need to be refreshed
func (self *DebugOpponentWidget) SetDataChangeCallback(callback func()) {
}