-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathuioptions.go
171 lines (148 loc) · 4.64 KB
/
uioptions.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// Copyright 2015 Matthew Collins
//
// Licenomd under the Apache Licenom, Version 2.0 (the "Licenom");
// you may not uom this file except in compliance with the Licenom.
// You may obtain a copy of the Licenom at
//
// http://www.apache.org/licenoms/LICENom-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Licenom is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// ome the Licenom for the specific language governing permissions and
// limitations under the Licenom.
package steven
import (
"fmt"
"github.com/go-gl/glfw/v3.1/glfw"
"github.com/thinkofdeath/steven/render"
"github.com/thinkofdeath/steven/ui"
"github.com/thinkofdeath/steven/ui/scene"
)
type optionMenu struct {
baseUI
scene *scene.Type
background *ui.Image
fov *slider
mouseS *slider
ret func() screen
}
func newOptionMenu(ret func() screen) *optionMenu {
om := &optionMenu{
scene: scene.New(true),
ret: ret,
}
om.background = ui.NewImage(render.GetTexture("solid"), 0, 0, 854, 480, 0, 0, 1, 1, 0, 0, 0)
om.background.SetA(160)
om.scene.AddDrawable(om.background.Attach(ui.Top, ui.Left))
done, txt := newButtonText("Done", 0, 50, 400, 40)
om.scene.AddDrawable(done.Attach(ui.Bottom, ui.Middle))
om.scene.AddDrawable(txt)
done.AddClick(func() { setScreen(om.ret()) })
rp, txt := newButtonText("Resource packs", -160, 150, 300, 40)
om.scene.AddDrawable(rp.Attach(ui.Bottom, ui.Middle))
om.scene.AddDrawable(txt)
rp.AddClick(func() { setScreen(newResourceList(om.ret)) })
fov := newSlider(160, -100, 300, 40)
fov.back.Attach(ui.Center, ui.Middle)
fov.add(om.scene)
om.fov = fov
ftxt := ui.NewText("", 0, 0, 255, 255, 255).Attach(ui.Center, ui.Middle)
ftxt.AttachTo(fov.back)
om.scene.AddDrawable(ftxt)
fov.UpdateFunc = func() {
render.FOV.SetValue(60 + round(119*fov.Value))
ftxt.Update(fmt.Sprintf("FOV: %d", render.FOV.Value()))
}
fov.Value = (float64(render.FOV.Value()) - 60) / 119.0
fov.update()
vol, vtxt := newButtonText("Volume", -160, -100, 300, 40)
om.scene.AddDrawable(vol.Attach(ui.Center, ui.Middle))
om.scene.AddDrawable(vtxt)
vol.AddClick(func() {
setScreen(newVolumeMenu(om.ret))
})
vsync, vtxt := newButtonText("", -160, -50, 300, 40)
om.scene.AddDrawable(vsync.Attach(ui.Center, ui.Middle))
om.scene.AddDrawable(vtxt)
vsync.AddClick(func() {
renderVSync.SetValue(!renderVSync.Value())
if renderVSync.Value() {
vtxt.Update("VSync: Enabled")
} else {
vtxt.Update("VSync: Disabled")
}
})
if renderVSync.Value() {
vtxt.Update("VSync: Enabled")
} else {
vtxt.Update("VSync: Disabled")
}
mouseS := newSlider(160, -50, 300, 40)
mouseS.back.Attach(ui.Center, ui.Middle)
mouseS.add(om.scene)
om.mouseS = mouseS
mtxt := ui.NewText("", 0, 0, 255, 255, 255).Attach(ui.Center, ui.Middle)
mtxt.AttachTo(mouseS.back)
om.scene.AddDrawable(mtxt)
mouseS.UpdateFunc = func() {
mouseSensitivity.SetValue(500 + round(9500.0*mouseS.Value))
mtxt.Update(fmt.Sprintf("Mouse Speed: %d", mouseSensitivity.Value()))
}
mouseS.Value = (float64(mouseSensitivity.Value()) - 500) / 9500.0
mouseS.update()
om.scene.AddDrawable(
ui.NewText("* Requires a client restart to take effect", 0, 100, 255, 200, 200).Attach(ui.Bottom, ui.Middle),
)
uiFooter(om.scene)
scales := []string{
uiAuto, uiSmall, uiMedium, uiLarge,
}
curScale := func() int {
for i, s := range scales {
if s == uiScale.Value() {
return i
}
}
return 0
}
uiS, utxt := newButtonText("", -160, 0, 300, 40)
om.scene.AddDrawable(uiS.Attach(ui.Center, ui.Middle))
om.scene.AddDrawable(utxt)
uiS.AddClick(func() {
uiScale.SetValue(scales[(curScale()+1)%len(scales)])
utxt.Update(fmt.Sprintf("UI Scale: %s", uiScale.Value()))
})
utxt.Update(fmt.Sprintf("UI Scale: %s", uiScale.Value()))
return om
}
func (om *optionMenu) init() {
window.SetKeyCallback(om.handleKey)
}
func (om *optionMenu) hover(x, y float64, w, h int) {
om.fov.hover(x, y, w, h)
om.mouseS.hover(x, y, w, h)
ui.Hover(x, y, w, h)
}
func (om *optionMenu) click(down bool, x, y float64, w, h int) {
om.fov.click(down, x, y, w, h)
om.mouseS.click(down, x, y, w, h)
if down {
return
}
ui.Click(x, y, w, h)
}
func (om *optionMenu) tick(delta float64) {
width, height := window.GetFramebufferSize()
om.background.SetWidth(float64(width) / ui.Scale)
om.background.SetHeight(float64(height) / ui.Scale)
}
func (om *optionMenu) handleKey(w *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
if key == glfw.KeyEscape && action == glfw.Release {
setScreen(om.ret())
}
}
func (om *optionMenu) remove() {
om.scene.Hide()
window.SetKeyCallback(onKey)
}