-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathuivolume.go
136 lines (118 loc) · 3.51 KB
/
uivolume.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
// Copyright 2015 Matthew Collins
//
// Licenvmd under the Apache Licenvm, Version 2.0 (the "Licenvm");
// you may not uvm this file except in cvmpliance with the Licenvm.
// You may obtain a copy of the Licenvm at
//
// http://www.apache.org/licenvms/LICENvm-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Licenvm is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// vme the Licenvm for the specific language governing permissions and
// limitations under the Licenvm.
package steven
import (
"fmt"
"strings"
"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 volumeMenu struct {
baseUI
scene *scene.Type
background *ui.Image
sliders []*slider
ret func() screen
}
func newVolumeMenu(ret func() screen) *volumeMenu {
vm := &volumeMenu{
scene: scene.New(true),
ret: ret,
}
vm.background = ui.NewImage(render.GetTexture("solid"), 0, 0, 854, 480, 0, 0, 1, 1, 0, 0, 0)
vm.background.SetA(160)
vm.scene.AddDrawable(vm.background.Attach(ui.Top, ui.Left))
done, txt := newButtonText("Done", 0, 50, 400, 40)
vm.scene.AddDrawable(done.Attach(ui.Bottom, ui.Middle))
vm.scene.AddDrawable(txt)
done.AddClick(func() { setScreen(newOptionMenu(vm.ret)) })
master := newSlider(0, -100, 620, 40)
master.back.Attach(ui.Center, ui.Middle)
master.add(vm.scene)
mtxt := ui.NewText("", 0, 0, 255, 255, 255).Attach(ui.Center, ui.Middle)
mtxt.AttachTo(master.back)
vm.scene.AddDrawable(mtxt)
master.UpdateFunc = func() {
muVolMaster.SetValue(round(master.Value * 100))
if muVolMaster.Value() == 0 {
mtxt.Update("Master: OFF")
return
}
mtxt.Update(fmt.Sprintf("Master: %d%%", muVolMaster.Value()))
}
master.Value = float64(muVolMaster.Value()) / 100.0
master.update()
vm.sliders = append(vm.sliders, master)
for i, cat := range soundCategories {
cat := cat
x := 160.0
if i&1 == 0 {
x = -x
}
y := 50 * float64(i/2)
snd := newSlider(x, -50+y, 300, 40)
snd.back.Attach(ui.Center, ui.Middle)
snd.add(vm.scene)
stxt := ui.NewText("", 0, 0, 255, 255, 255).Attach(ui.Center, ui.Middle)
stxt.AttachTo(snd.back)
vm.scene.AddDrawable(stxt)
v := volVars[cat]
snd.UpdateFunc = func() {
v.SetValue(round(snd.Value * 100))
if val := v.Value(); val != 0 {
stxt.Update(fmt.Sprintf("%s: %d%%", strings.Title(string(cat)), val))
return
}
stxt.Update(fmt.Sprintf("%s: OFF", strings.Title(string(cat))))
}
snd.Value = float64(v.Value()) / 100.0
snd.update()
vm.sliders = append(vm.sliders, snd)
}
return vm
}
func (vm *volumeMenu) init() {
window.SetKeyCallback(vm.handleKey)
}
func (vm *volumeMenu) hover(x, y float64, w, h int) {
for _, s := range vm.sliders {
s.hover(x, y, w, h)
}
ui.Hover(x, y, w, h)
}
func (vm *volumeMenu) click(down bool, x, y float64, w, h int) {
for _, s := range vm.sliders {
s.click(down, x, y, w, h)
}
if down {
return
}
ui.Click(x, y, w, h)
}
func (vm *volumeMenu) tick(delta float64) {
width, height := window.GetFramebufferSize()
vm.background.SetWidth(float64(width) / ui.Scale)
vm.background.SetHeight(float64(height) / ui.Scale)
}
func (vm *volumeMenu) handleKey(w *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
if key == glfw.KeyEscape && action == glfw.Release {
setScreen(newOptionMenu(vm.ret))
}
}
func (vm *volumeMenu) remove() {
vm.scene.Hide()
window.SetKeyCallback(onKey)
}