-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathuieditserver.go
98 lines (81 loc) · 2.38 KB
/
uieditserver.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
// Copyright 2015 Matthew Collins
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package steven
import (
"github.com/thinkofdeath/steven/ui"
"github.com/thinkofdeath/steven/ui/scene"
)
type editServer struct {
baseUI
scene *scene.Type
logo uiLogo
name *ui.TextBox
address *ui.TextBox
index int
}
func newEditServer(index int) *editServer {
se := &editServer{
scene: scene.New(true),
index: index,
}
se.logo.init(se.scene)
uiFooter(se.scene)
done, txt := newButtonText("Done", 110, 100, 200, 40)
se.scene.AddDrawable(done.Attach(ui.Center, ui.Middle))
se.scene.AddDrawable(txt)
done.AddClick(func() {
se.save()
})
cancel, txt := newButtonText("Cancel", -110, 100, 200, 40)
se.scene.AddDrawable(cancel.Attach(ui.Center, ui.Middle))
se.scene.AddDrawable(txt)
cancel.AddClick(func() {
setScreen(newServerList())
})
se.name = ui.NewTextBox(0, -20, 400, 40)
se.scene.AddDrawable(se.name.Attach(ui.Middle, ui.Center))
label := ui.NewText("Name:", 0, -18, 255, 255, 255).Attach(ui.Top, ui.Left)
label.AttachTo(se.name)
se.scene.AddDrawable(label)
se.address = ui.NewTextBox(0, 40, 400, 40)
se.scene.AddDrawable(se.address.Attach(ui.Middle, ui.Center))
label = ui.NewText("Address:", 0, -18, 255, 255, 255).Attach(ui.Top, ui.Left)
label.AttachTo(se.address)
se.scene.AddDrawable(label)
if index != -1 {
server := Config.Servers[index]
se.name.Update(server.Name)
se.address.Update(server.Address)
}
return se
}
func (se *editServer) save() {
if se.index == -1 {
Config.Servers = append(Config.Servers, ConfigServer{
Name: se.name.Value(),
Address: se.address.Value(),
})
} else {
Config.Servers[se.index].Name = se.name.Value()
Config.Servers[se.index].Address = se.address.Value()
}
saveServers()
setScreen(newServerList())
}
func (se *editServer) tick(delta float64) {
se.logo.tick(delta)
}
func (se *editServer) remove() {
se.scene.Hide()
}