-
Notifications
You must be signed in to change notification settings - Fork 28
/
ui.go
564 lines (498 loc) · 19.5 KB
/
ui.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
// Copyright 2017 Daniel Salvadori. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"github.com/g3n/engine/camera"
"github.com/g3n/engine/gui"
"github.com/g3n/engine/math32"
"github.com/g3n/engine/window"
)
var creditsColor = math32.Color{0.6, 0.6, 0.6}
var transparent = math32.Color4{0, 0, 0, 0}
var blackTextColor = math32.Color4{0.3, 0.3, 0.3, 1.0}
var sliderColor = math32.Color4{0.628, 0.882, 0.1, 1}
var sliderColorOff = math32.Color4{0.82, 0.48, 0.48, 1}
var sliderColorOver = math32.Color4{0.728, 0.982, 0.2, 1}
var sliderBorderColor = math32.Color4{0.71, 0.482, 0.26, 1}
var sliderBorder = gui.RectBounds{3, 3, 3, 3}
var gameScreenPadding float32 = 20.0
type UI struct {
gui.Panel
game *Gokoban
inMenu bool
// Main menu
menuScreen *gui.Panel
titleImage *gui.ImageButton
loadingLabel *gui.Label
menuPanel *gui.Panel
quitButton *gui.ImageButton
playButton *gui.ImageButton
sfxButton *gui.ImageButton
sfxSlider *gui.Slider
musicButton *gui.ImageButton
musicSlider *gui.Slider
fullScreenButton *gui.ImageButton
// In-game controls and HUD
gameScreen *gui.Panel
gameScreenHeader *gui.Panel
gameScreenFooter *gui.Panel
levelLabelImage *gui.ImageLabel
levelLabelText *gui.Label
nextButton *gui.ImageButton
prevButton *gui.ImageButton
restartButton *gui.ImageButton
menuButton *gui.ImageButton
instructions1 *gui.ImageLabel
instructions2 *gui.ImageLabel
instructions3 *gui.ImageLabel
instructionsRestart *gui.ImageLabel
instructionsMenu *gui.ImageLabel
}
// NewUI creates a ui panel with a loading label and title
func NewUI(game *Gokoban) *UI {
ui := new(UI)
ui.game = game
var err error
ui.Panel.Initialize(ui, 1280, 920)
ui.SetEnabled(false)
ui.inMenu = true
ui.loadingLabel = gui.NewLabel("Loading...")
ui.loadingLabel.SetColor(&math32.Color{1, 1, 1})
ui.loadingLabel.SetFontSize(42)
ui.loadingLabel.SetPositionX(((ui.ContentWidth() - ui.loadingLabel.ContentWidth()) / 2)+ 0.5)
ui.loadingLabel.SetPositionY(((ui.ContentHeight() - ui.loadingLabel.ContentHeight()) / 2)+ 0.5)
ui.Add(ui.loadingLabel)
// Title
ui.titleImage, err = gui.NewImageButton("./gui/title3.png")
if err != nil {
panic(err)
}
ui.titleImage.SetImage(gui.ButtonDisabled, "./gui/title3.png")
ui.titleImage.SetEnabled(false)
ui.titleImage.SetZLayerDelta(1)
ui.titleImage.SetPositionX((ui.ContentWidth() - ui.titleImage.ContentWidth()) / 2)
ui.Add(ui.titleImage)
return ui
}
// Init sets up the styling and creates the menu and game screens
func (ui *UI) Init() {
// Modify ImageButton style
s := gui.StyleDefault()
s.ImageButton = gui.ImageButtonStyles{}
s.ImageButton.Normal = gui.ImageButtonStyle{}
s.ImageButton.Normal.BgColor = transparent
s.ImageButton.Normal.FgColor = blackTextColor
s.ImageButton.Over = s.ImageButton.Normal
s.ImageButton.Focus = s.ImageButton.Normal
s.ImageButton.Pressed = s.ImageButton.Normal
s.ImageButton.Disabled = s.ImageButton.Normal
// Modify Slider style
s.Slider = gui.SliderStyles{}
s.Slider.Normal = gui.SliderStyle{}
s.Slider.Normal.Border = sliderBorder
s.Slider.Normal.BorderColor = sliderBorderColor
s.Slider.Normal.BgColor = math32.Color4{0.2, 0.2, 0.2, 1}
s.Slider.Normal.FgColor = sliderColor
s.Slider.Over = s.Slider.Normal
s.Slider.Over.BgColor = math32.Color4{0.3, 0.3, 0.3, 1}
s.Slider.Over.FgColor = sliderColorOver
s.Slider.Focus = s.Slider.Over
s.Slider.Disabled = s.Slider.Normal
s.Slider.Disabled.FgColor = sliderColorOff
// Create menu and game screens
ui.CreateMenuScreen()
ui.CreateGameScreen()
// Show menu screen
ui.Add(ui.menuScreen)
// Move title image to menu
ui.menuScreen.Add(ui.titleImage)
}
// Resize updates the UI elements based on the provided screen dimensions
func (ui *UI) Resize(width, height int) {
// Update screen container panels
ui.SetSize(float32(width), float32(height))
ui.titleImage.SetPositionX((float32(width) - ui.titleImage.ContentWidth()) / 2)
ui.menuScreen.SetSize(float32(width), float32(height))
ui.gameScreen.SetSize(float32(width), float32(height))
// Note: below we add a half-pixel in several places to prevent a visual bleeding artifact
// Menu Screen
ui.menuPanel.SetPositionX(math32.Round((float32(width)-ui.menuPanel.Width())/2) + 0.5)
ui.menuPanel.SetPositionY(math32.Round((float32(height)-ui.menuPanel.Height())/1.6) + 0.5)
// Game Screen
// Note: for some reason calling SetPosition instead of SetPositionX and SetPositionY (separately) results in the same visual bleeding artifact
ui.prevButton.SetPositionX(math32.Round(gameScreenPadding) + 0.5)
ui.prevButton.SetPositionY(math32.Round(gameScreenPadding) + 0.5)
ui.levelLabelImage.SetPositionX(math32.Round((float32(width)-ui.levelLabelImage.ContentWidth())/2) + 0.5)
ui.levelLabelText.SetPositionX(math32.Round((float32(width) - ui.levelLabelText.ContentWidth()) / 2))
ui.nextButton.SetPositionX(math32.Round(float32(width)-ui.prevButton.ContentWidth()-gameScreenPadding) + 0.5)
ui.restartButton.SetPositionY(math32.Round(float32(height)-ui.restartButton.ContentHeight()-gameScreenPadding) + 0.5)
ui.menuButton.SetPositionX(math32.Round(float32(width)-ui.menuButton.Width()-gameScreenPadding) + 0.5)
ui.menuButton.SetPositionY(math32.Round(float32(height)-ui.menuButton.Height()-gameScreenPadding) + 0.5)
ui.instructions1.SetWidth(float32(width))
ui.instructions1.SetPositionY(4 * ui.instructions1.ContentHeight())
ui.instructions2.SetWidth(float32(width))
ui.instructions2.SetPositionY(5 * ui.instructions2.ContentHeight())
ui.instructions3.SetWidth(float32(width))
ui.instructions3.SetPositionY(float32(height) - 2*ui.instructions3.ContentHeight())
buttonInstructionsPad := float32(24)
ui.instructionsRestart.SetPositionX(buttonInstructionsPad)
ui.instructionsRestart.SetPositionY(float32(height) - 6*ui.instructionsRestart.ContentHeight())
ui.instructionsMenu.SetPositionX(float32(width) - ui.instructionsMenu.ContentWidth() - buttonInstructionsPad)
ui.instructionsMenu.SetPositionY(float32(height) - 6*ui.instructionsMenu.ContentHeight())
}
// ToggleMenu switched the menu, title, and credits overlay for the in-level corner buttons
func (ui *UI) ToggleMenu() {
if ui.inMenu {
// Dispatch OnCursorLeave and OnMouseUp to sliders in case user had cursor over sliders when they pressed Esc to hide menu
ui.sfxSlider.Dispatch(gui.OnCursorLeave, &window.MouseEvent{})
ui.sfxSlider.Dispatch(gui.OnMouseUp, &window.MouseEvent{})
ui.musicSlider.Dispatch(gui.OnCursorLeave, &window.MouseEvent{})
ui.musicSlider.Dispatch(gui.OnMouseUp, &window.MouseEvent{})
ui.Remove(ui.menuScreen)
ui.Add(ui.gameScreen)
ui.game.orbit.SetEnabled(camera.OrbitRot + camera.OrbitZoom)
ui.game.gopherLocked = false
ui.game.audio.musicMenu.Stop()
ui.game.audio.musicGame.Play()
} else {
ui.Remove(ui.gameScreen)
ui.Add(ui.menuScreen)
ui.game.orbit.SetEnabled(camera.OrbitNone)
ui.game.gopherLocked = true
ui.game.audio.musicGame.Stop()
ui.game.audio.musicMenu.Play()
}
ui.inMenu = !ui.inMenu
}
// CreateMenuScreen creates the menu screen widgets
func (ui *UI) CreateMenuScreen() {
var err error
// Create menu screen container panel
ui.menuScreen = gui.NewPanel(100, 100)
ui.menuScreen.SetColor4(&math32.Color4{0.1, 0.1, 0.1, 0.6})
// Main menu panel
ui.menuPanel = gui.NewPanel(600, 300)
ui.menuPanel.SetZLayerDelta(2)
mainLayout := gui.NewVBoxLayout()
mainLayout.SetAlignV(gui.AlignHeight)
ui.menuPanel.SetLayout(mainLayout)
ui.menuPanel.SetBorders(2, 2, 2, 2)
ui.menuPanel.SetBordersColor4(&sliderBorderColor)
ui.menuPanel.SetColor4(&math32.Color4{0.2, 0.2, 0.2, 0.6})
// Main menu's top row
topRow := gui.NewPanel(ui.menuPanel.ContentWidth(), 100)
topRowLayout := gui.NewHBoxLayout()
topRowLayout.SetAlignH(gui.AlignWidth)
topRow.SetLayout(topRowLayout)
alignCenterVerical := gui.HBoxLayoutParams{Expand: 0, AlignV: gui.AlignCenter}
// Music Control
musicControl := gui.NewPanel(130, 100)
musicControl.SetLayout(topRowLayout)
ui.musicButton, err = gui.NewImageButton("./gui/music_normal.png")
ui.musicButton.SetImage(gui.ButtonOver, "./gui/music_hover.png")
ui.musicButton.SetImage(gui.ButtonPressed, "./gui/music_click.png")
ui.musicButton.SetImage(gui.ButtonDisabled, "./gui/music_disabled2.png")
if err != nil {
panic(err)
}
ui.musicButton.Subscribe(gui.OnMouseUp, func(evname string, ev interface{}) {
ui.game.audio.click.Play()
ui.game.userData.MusicOn = !ui.game.userData.MusicOn
ui.UpdateMusicButton(ui.game.userData.MusicOn)
})
ui.musicButton.Subscribe(gui.OnCursorEnter, func(evname string, ev interface{}) {
ui.game.audio.hover.Play()
})
musicControl.Add(ui.musicButton)
// Music Volume Slider
ui.musicSlider = gui.NewVSlider(20, 80)
ui.musicSlider.SetValue(ui.game.userData.MusicVol)
ui.musicSlider.Subscribe(gui.OnChange, func(evname string, ev interface{}) {
ui.game.audio.SetMusicVolume(ui.musicSlider.Value())
})
ui.musicSlider.Subscribe(gui.OnCursorEnter, func(evname string, ev interface{}) {
ui.game.audio.hover.Play()
})
ui.musicSlider.SetLayoutParams(&alignCenterVerical)
musicControl.Add(ui.musicSlider)
topRow.Add(musicControl)
// Sound Effects Control
sfxControl := gui.NewPanel(130, 100)
sfxControl.SetLayout(topRowLayout)
ui.sfxButton, err = gui.NewImageButton("./gui/sound_normal.png")
ui.sfxButton.SetImage(gui.ButtonOver, "./gui/sound_hover.png")
ui.sfxButton.SetImage(gui.ButtonPressed, "./gui/sound_click.png")
ui.sfxButton.SetImage(gui.ButtonDisabled, "./gui/sound_disabled2.png")
if err != nil {
panic(err)
}
ui.sfxButton.Subscribe(gui.OnMouseUp, func(evname string, ev interface{}) {
ui.game.audio.click.Play()
ui.game.userData.SfxOn = !ui.game.userData.SfxOn
ui.UpdateSfxButton(ui.game.userData.SfxOn)
})
ui.sfxButton.Subscribe(gui.OnCursorEnter, func(evname string, ev interface{}) {
ui.game.audio.hover.Play()
})
sfxControl.Add(ui.sfxButton)
// Sound Effects Volume Slider
ui.sfxSlider = gui.NewVSlider(20, 80)
ui.sfxSlider.SetValue(ui.game.userData.SfxVol)
ui.sfxSlider.Subscribe(gui.OnChange, func(evname string, ev interface{}) {
ui.game.audio.SetSfxVolume(ui.sfxSlider.Value())
})
ui.sfxSlider.Subscribe(gui.OnCursorEnter, func(evname string, ev interface{}) {
ui.game.audio.hover.Play()
})
ui.sfxSlider.SetLayoutParams(&alignCenterVerical)
sfxControl.Add(ui.sfxSlider)
topRow.Add(sfxControl)
// FullScreen Button
ui.fullScreenButton, err = gui.NewImageButton("./gui/screen_normal.png")
ui.fullScreenButton.SetImage(gui.ButtonOver, "./gui/screen_hover.png")
ui.fullScreenButton.SetImage(gui.ButtonPressed, "./gui/screen_click.png")
ui.fullScreenButton.SetImage(gui.ButtonDisabled, "./gui/screen_disabled2.png")
if err != nil {
panic(err)
}
ui.fullScreenButton.Subscribe(gui.OnMouseUp, func(evname string, ev interface{}) {
ui.game.audio.click.Play()
ui.game.ToggleFullScreen()
})
ui.fullScreenButton.Subscribe(gui.OnCursorEnter, func(evname string, ev interface{}) {
ui.game.audio.hover.Play()
})
topRow.Add(ui.fullScreenButton)
ui.menuPanel.Add(topRow)
buttonRow := gui.NewPanel(ui.menuPanel.ContentWidth(), 100)
buttonRowLayout := gui.NewHBoxLayout()
buttonRowLayout.SetAlignH(gui.AlignWidth)
buttonRow.SetLayout(buttonRowLayout)
// Quit Button
ui.quitButton, err = gui.NewImageButton("./gui/quit_normal.png")
ui.quitButton.SetImage(gui.ButtonOver, "./gui/quit_hover.png")
ui.quitButton.SetImage(gui.ButtonPressed, "./gui/quit_click.png")
ui.quitButton.SetImage(gui.ButtonDisabled, "./gui/quit_disabled2.png")
if err != nil {
panic(err)
}
ui.quitButton.Subscribe(gui.OnMouseUp, func(evname string, ev interface{}) {
ui.game.Quit()
})
ui.quitButton.Subscribe(gui.OnCursorEnter, func(evname string, ev interface{}) {
ui.game.audio.hover.Play()
})
buttonRow.Add(ui.quitButton)
// Play Button
ui.playButton, err = gui.NewImageButton("./gui/play_normal.png")
ui.playButton.SetImage(gui.ButtonOver, "./gui/play_hover.png")
ui.playButton.SetImage(gui.ButtonPressed, "./gui/play_click.png")
ui.playButton.SetImage(gui.ButtonDisabled, "./gui/play_disabled2.png")
if err != nil {
panic(err)
}
ui.playButton.Subscribe(gui.OnMouseUp, func(evname string, ev interface{}) {
ui.game.audio.click.Play()
ui.ToggleMenu()
})
ui.playButton.Subscribe(gui.OnCursorEnter, func(evname string, ev interface{}) {
ui.game.audio.hover.Play()
})
buttonRow.Add(ui.playButton)
ui.menuPanel.Add(buttonRow)
// Add credits labels
lCredits1 := gui.NewImageLabel(CREDITS_LINE1)
lCredits1.SetColor(&creditsColor)
lCredits1.SetFontSize(20)
ui.menuScreen.Subscribe(gui.OnResize, func(evname string, ev interface{}) {
lCredits1.SetWidth(ui.menuScreen.ContentWidth())
lCredits1.SetPositionY(ui.menuScreen.ContentHeight() - 2*lCredits1.ContentHeight())
})
ui.menuScreen.Add(lCredits1)
lCredits2 := gui.NewImageLabel(CREDITS_LINE2)
lCredits2.SetColor(&creditsColor)
lCredits2.SetFontSize(20)
ui.menuScreen.Subscribe(gui.OnResize, func(evname string, ev interface{}) {
lCredits2.SetWidth(ui.menuScreen.ContentWidth())
lCredits2.SetPositionY(ui.menuScreen.ContentHeight() - lCredits2.ContentHeight())
})
ui.menuScreen.Add(lCredits2)
// G3N logo
g3n := gui.NewImageLabel("")
g3n.SetImageFromFile("./gui/g3n.png")
g3n.SetSize(50, 87)
ui.menuScreen.Subscribe(gui.OnResize, func(evname string, ev interface{}) {
g3n.SetPositionX(math32.Round(ui.menuScreen.ContentWidth()-g3n.Width()) + 0.5)
g3n.SetPositionY(math32.Round(ui.menuScreen.ContentHeight()-g3n.Height()) + 0.5)
})
ui.menuScreen.Add(g3n)
ui.menuScreen.Add(ui.menuPanel)
}
// UpdateMusicButton updates the state of the music button, slider, and the appropriate audio setting
func (ui *UI) UpdateMusicButton(on bool) {
if on {
ui.musicButton.SetImage(gui.ButtonNormal, "./gui/music_normal.png")
ui.musicButton.SetImage(gui.ButtonOver, "./gui/music_hover.png")
ui.musicButton.SetImage(gui.ButtonPressed, "./gui/music_click.png")
ui.musicSlider.SetEnabled(true)
ui.musicSlider.SetValue(ui.musicSlider.Value())
} else {
ui.musicButton.SetImage(gui.ButtonNormal, "./gui/music_normal_off.png")
ui.musicButton.SetImage(gui.ButtonOver, "./gui/music_hover_off.png")
ui.musicButton.SetImage(gui.ButtonPressed, "./gui/music_click_off.png")
ui.musicSlider.SetEnabled(false)
ui.game.audio.SetMusicVolume(0)
}
}
// UpdateSfxButton updates the state of the sfx button, slider, and the appropriate audio setting
func (ui *UI) UpdateSfxButton(on bool) {
if on {
ui.sfxButton.SetImage(gui.ButtonNormal, "./gui/sound_normal.png")
ui.sfxButton.SetImage(gui.ButtonOver, "./gui/sound_hover.png")
ui.sfxButton.SetImage(gui.ButtonPressed, "./gui/sound_click.png")
ui.sfxSlider.SetEnabled(true)
ui.sfxSlider.SetValue(ui.sfxSlider.Value())
} else {
ui.sfxButton.SetImage(gui.ButtonNormal, "./gui/sound_normal_off.png")
ui.sfxButton.SetImage(gui.ButtonOver, "./gui/sound_hover_off.png")
ui.sfxButton.SetImage(gui.ButtonPressed, "./gui/sound_click_off.png")
ui.sfxSlider.SetEnabled(false)
ui.game.audio.SetSfxVolume(0)
}
}
// CreateGameScreen creates the game screen widgets
func (ui *UI) CreateGameScreen() {
var err error
// Create game screen container panel
ui.gameScreen = gui.NewPanel(100, 100)
ui.gameScreen.SetEnabled(false)
// Previous Level Button
ui.prevButton, err = gui.NewImageButton("./gui/left_normal.png")
ui.prevButton.SetImage(gui.ButtonOver, "./gui/left_hover.png")
ui.prevButton.SetImage(gui.ButtonPressed, "./gui/left_click.png")
ui.prevButton.SetImage(gui.ButtonDisabled, "./gui/left_disabled2.png")
if err != nil {
panic(err)
}
ui.prevButton.Subscribe(gui.OnMouseUp, func(evname string, ev interface{}) {
if !ui.prevButton.Enabled() {
return
}
ui.game.audio.click.Play()
ui.game.PreviousLevel()
})
ui.prevButton.Subscribe(gui.OnCursorEnter, func(evname string, ev interface{}) {
if !ui.prevButton.Enabled() {
return
}
ui.game.audio.hover.Play()
})
ui.gameScreen.Add(ui.prevButton)
// Level Label Image
ui.levelLabelImage = gui.NewImageLabel("")
ui.levelLabelImage.SetImageFromFile("./gui/panel.png")
ui.levelLabelImage.SetHeight(92)
ui.levelLabelImage.SetEnabled(false)
ui.gameScreen.Add(ui.levelLabelImage)
// Level Label Text
ui.levelLabelText = gui.NewLabel("Level")
ui.levelLabelText.SetFontSize(35)
ui.levelLabelText.SetColor(&math32.Color{0, 0, 0})
ui.levelLabelText.SetPositionY(24)
ui.levelLabelText.SetEnabled(false)
ui.gameScreen.Add(ui.levelLabelText)
// Next Level Button
ui.nextButton, err = gui.NewImageButton("./gui/right_normal.png")
ui.nextButton.SetImage(gui.ButtonOver, "./gui/right_hover.png")
ui.nextButton.SetImage(gui.ButtonPressed, "./gui/right_click.png")
ui.nextButton.SetImage(gui.ButtonDisabled, "./gui/right_disabled2.png")
if err != nil {
panic(err)
}
ui.nextButton.Subscribe(gui.OnMouseUp, func(evname string, ev interface{}) {
if !ui.nextButton.Enabled() {
return
}
ui.game.audio.click.Play()
ui.game.NextLevel()
})
ui.nextButton.Subscribe(gui.OnCursorEnter, func(evname string, ev interface{}) {
if !ui.nextButton.Enabled() {
return
}
ui.game.audio.hover.Play()
})
ui.nextButton.SetPositionY(gameScreenPadding + 0.5)
ui.gameScreen.Add(ui.nextButton)
// Restart Level Button
ui.restartButton, err = gui.NewImageButton("./gui/restart_normal.png")
ui.restartButton.SetImage(gui.ButtonOver, "./gui/restart_hover.png")
ui.restartButton.SetImage(gui.ButtonPressed, "./gui/restart_click.png")
ui.restartButton.SetImage(gui.ButtonDisabled, "./gui/restart_disabled2.png")
if err != nil {
panic(err)
}
ui.restartButton.Subscribe(gui.OnMouseUp, func(evname string, ev interface{}) {
if !ui.restartButton.Enabled() {
return
}
ui.game.RestartLevel(true)
})
ui.restartButton.Subscribe(gui.OnCursorEnter, func(evname string, ev interface{}) {
if !ui.restartButton.Enabled() {
return
}
ui.game.audio.hover.Play()
})
ui.restartButton.SetPositionX(gameScreenPadding + 0.5)
ui.gameScreen.Add(ui.restartButton)
// Show Menu Button
ui.menuButton, err = gui.NewImageButton("./gui/menu_normal.png")
ui.menuButton.SetImage(gui.ButtonOver, "./gui/menu_hover.png")
ui.menuButton.SetImage(gui.ButtonPressed, "./gui/menu_click.png")
ui.menuButton.SetImage(gui.ButtonDisabled, "./gui/menu_disabled2.png")
if err != nil {
panic(err)
}
ui.menuButton.Subscribe(gui.OnMouseUp, func(evname string, ev interface{}) {
if !ui.menuButton.Enabled() {
return
}
ui.game.audio.click.Play()
ui.ToggleMenu()
})
ui.menuButton.Subscribe(gui.OnCursorEnter, func(evname string, ev interface{}) {
if !ui.menuButton.Enabled() {
return
}
ui.game.audio.hover.Play()
})
ui.gameScreen.Add(ui.menuButton)
// Instructions
ui.instructions1 = gui.NewImageLabel(INSTRUCTIONS_LINE1)
ui.instructions1.SetColor(&creditsColor)
ui.instructions1.SetFontSize(28)
ui.instructions1.SetEnabled(false)
ui.gameScreen.Add(ui.instructions1)
ui.instructions2 = gui.NewImageLabel(INSTRUCTIONS_LINE2)
ui.instructions2.SetColor(&creditsColor)
ui.instructions2.SetFontSize(28)
ui.instructions2.SetEnabled(false)
ui.gameScreen.Add(ui.instructions2)
ui.instructions3 = gui.NewImageLabel(INSTRUCTIONS_LINE3)
ui.instructions3.SetColor(&creditsColor)
ui.instructions3.SetFontSize(28)
ui.instructions3.SetEnabled(false)
ui.gameScreen.Add(ui.instructions3)
ui.instructionsRestart = gui.NewImageLabel("Restart Level (R)")
ui.instructionsRestart.SetColor(&creditsColor)
ui.instructionsRestart.SetFontSize(20)
ui.instructionsRestart.SetEnabled(false)
ui.gameScreen.Add(ui.instructionsRestart)
ui.instructionsMenu = gui.NewImageLabel("Show Menu (Esc)")
ui.instructionsMenu.SetColor(&creditsColor)
ui.instructionsMenu.SetFontSize(20)
ui.instructionsMenu.SetEnabled(false)
ui.gameScreen.Add(ui.instructionsMenu)
}