/
order_widget.go
87 lines (76 loc) · 2.09 KB
/
order_widget.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
package appwindow
import (
"fyne.io/fyne"
"fyne.io/fyne/theme"
"fyne.io/fyne/widget"
"github.com/steveoc64/republique5/gui/store"
rp "github.com/steveoc64/republique5/proto"
)
type commanderOrders struct {
widget.Box
panel *OrdersPanel
command *rp.Command
btn *widget.Button
order *widget.Label
store *store.Store
}
func newCommanderOrders(panel *OrdersPanel, command *rp.Command, store *store.Store) *commanderOrders {
vbox := widget.NewVBox()
o := &commanderOrders{
Box: *vbox,
panel: panel,
command: command,
store: store,
}
orderButton := theme.CheckButtonIcon()
if command.GameState.GetHas().GetOrder() {
orderButton = theme.CheckButtonCheckedIcon()
}
o.btn = widget.NewButtonWithIcon(" "+command.LabelString(), orderButton, func() {
o.commanderAction()
})
switch command.Rank {
case rp.Rank_ARMY, rp.Rank_CORPS:
o.btn.HideShadow = false
o.btn.Style = widget.PrimaryButton
}
o.Append(o.btn)
orderName := upString(command.GameState.GetOrders().String())
o.order = widget.NewLabelWithStyle(orderName, fyne.TextAlignCenter, fyne.TextStyle{Bold: true})
o.Append(o.order)
store.CommanderMap.AddCommandListener(command, o.Listen)
return o
}
func (o *commanderOrders) Listen(data fyne.DataItem) {
cmd, ok := data.(*store.Commander)
if ok && o != nil {
o.command = cmd.Data
o.Show()
}
}
func (o *commanderOrders) Show() {
// do the command
orderButton := theme.CheckButtonIcon()
if o.command.GameState.GetHas().GetOrder() {
orderButton = theme.CheckButtonCheckedIcon()
}
o.btn.SetIcon(orderButton)
// do the label
orderName := upString(o.command.GetGameState().GetOrders().String())
o.order.SetText(orderName)
// zap the contents
o.Children = o.Children[:2]
// add new contents
waypoints := o.panel.app.MapData.GetWaypoints(o.command)
for _, v := range waypoints {
w := widget.NewLabelWithStyle(v.Path, fyne.TextAlignCenter, fyne.TextStyle{Italic: true})
o.Append(w)
}
// paint it all
widget.Refresh(o)
o.Box.Show()
}
func (o *commanderOrders) commanderAction() {
o.panel.app.mapPanel.mapWidget.Select(o.command.Id)
o.panel.app.Tab(TabMap)
}