-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathselect_palette_widget.go
127 lines (104 loc) · 3.04 KB
/
select_palette_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
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
package hswidget
import (
"log"
"path/filepath"
"github.com/ianling/giu"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dat"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
"github.com/OpenDiablo2/HellSpawner/hscommon"
"github.com/OpenDiablo2/HellSpawner/hscommon/hsfiletypes"
"github.com/OpenDiablo2/HellSpawner/hscommon/hsproject"
"github.com/OpenDiablo2/HellSpawner/hsconfig"
"github.com/OpenDiablo2/HellSpawner/hswindow/hstoolwindow/hsmpqexplorer"
"github.com/OpenDiablo2/HellSpawner/hswindow/hstoolwindow/hsprojectexplorer"
)
const (
paletteSelectW, paletteSelectH = 400, 600
actionButtonW, actionButtonH = 200, 30
)
// SelectPaletteWidget represents an pop-up MPQ explorer, when we're
// selectin DAT palette
type SelectPaletteWidget struct {
mpqExplorer *hsmpqexplorer.MPQExplorer
projectExplorer *hsprojectexplorer.ProjectExplorer
id string
saveCB func(colors *[256]d2interface.Color)
closeCB func()
}
// NewSelectPaletteWidget creates a select palette widget
func NewSelectPaletteWidget(
id string,
project *hsproject.Project,
config *hsconfig.Config,
saveCB func(colors *[256]d2interface.Color),
closeCB func(),
) *SelectPaletteWidget {
result := &SelectPaletteWidget{
saveCB: saveCB,
closeCB: closeCB,
}
callback := func(path *hscommon.PathEntry) {
bytes, bytesErr := path.GetFileBytes()
if bytesErr != nil {
log.Print(bytesErr)
return
}
ft, err := hsfiletypes.GetFileTypeFromExtension(filepath.Ext(path.FullPath), &bytes)
if err != nil {
log.Print(err)
return
}
if ft == hsfiletypes.FileTypePalette {
// load new palette:
paletteData, err := path.GetFileBytes()
if err != nil {
log.Print(err)
}
palette, err := d2dat.Load(paletteData)
if err != nil {
log.Print(err)
}
colors := palette.GetColors()
saveCB(&colors)
closeCB()
}
}
mpqExplorer, err := hsmpqexplorer.Create(callback, config, 0, 0)
if err != nil {
log.Print(err)
}
mpqExplorer.SetProject(project)
result.mpqExplorer = mpqExplorer
projectExplorer, err := hsprojectexplorer.Create(nil, callback, 0, 0)
if err != nil {
log.Print(err)
}
projectExplorer.SetProject(project)
result.projectExplorer = projectExplorer
return result
}
// Build builds a widget
func (p *SelectPaletteWidget) Build() {
// always true (we don't use this feature in this case
isOpen := true
giu.Layout{
giu.PopupModal("##" + p.id + "popUpSelectPalette").IsOpen(&isOpen).Layout(giu.Layout{
giu.Child("##"+p.id+"popUpSelectPaletteChildWidget").Size(paletteSelectW, paletteSelectH).Layout(giu.Layout{
p.projectExplorer.GetProjectTreeNodes(),
giu.Layout(p.mpqExplorer.GetMpqTreeNodes()),
giu.Separator(),
giu.Button("Don't use any palette##"+p.id+"selectPaletteDonotUseAny").
Size(actionButtonW, actionButtonH).
OnClick(func() {
p.saveCB(nil)
p.closeCB()
}),
giu.Button("Exit##"+p.id+"selectPaletteExit").
Size(actionButtonW, actionButtonH).
OnClick(func() {
p.closeCB()
}),
}),
}),
}.Build()
}