-
Notifications
You must be signed in to change notification settings - Fork 4
/
gui.py
152 lines (123 loc) · 4.6 KB
/
gui.py
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
# -*- coding: utf-8 -*-
# Authors: TurBoss
# Models: TurBoss
# GUI
import os
import sys
from panda3d.core import AntialiasAttrib, TransparencyAttrib
from direct.showbase import DirectObject
from direct.gui.DirectGui import *
import direct.gui.DirectGuiGlobals as DGG
class StartMenu(DirectObject.DirectObject):
def __init__(self, game):
self.game = game
self.active_button = 0
self.frame = DirectFrame()
self.frame['frameColor'] = (0.8, 0.8, 0.8, 0)
self.frame['image'] = "data/startMenu.png"
self.frame['image_scale'] = (1.0, 1.0, 1.0)
self.frame.setPos(0, 0, 0)
self.frame.setTransparency(TransparencyAttrib.MAlpha)
self.maps_start = loader.loadModel("data/start_menu/buttons_start_maps")
self.start_button = DirectButton(
parent=self.frame,
pos=(0, 0, 0),
image=(
self.maps_start.find('**/startready'),
self.maps_start.find('**/startclicked'),
self.maps_start.find('**/startrollover'),
self.maps_start.find('**/startdisable')
),
command=self.start_game,
scale=0.2,
borderWidth=(0.01, 0.01),
frameSize=(-0.55, 0.55, -0.2, 0.2),
frameColor=(0.8, 0.8, 0.8, 0)
)
# rolloverSound=self.soundManager.over,
# clickSound=self.soundManager.click))
self.maps_credits = loader.loadModel("data/start_menu/buttons_credits_maps.egg")
self.credits_button = DirectButton(
parent=self.frame,
pos=(0, 0, -0.1),
image=(
self.maps_credits.find('**/creditsready'),
self.maps_credits.find('**/creditsclicked'),
self.maps_credits.find('**/creditsrollover'),
self.maps_credits.find('**/creditsdisable')
),
#command=self.action,
scale=0.2,
borderWidth=(0.01, 0.01),
frameSize=(-0.55, 0.55, -0.2, 0.2),
frameColor=(0.8, 0.8, 0.8, 0)
)
# rolloverSound=self.soundManager.over,
# clickSound=self.soundManager.click))
self.maps_quit = loader.loadModel("data/start_menu/buttons_quit_maps.egg")
self.quit_button = DirectButton(
parent=self.frame,
pos=(0, 0, -0.2),
image=(
self.maps_quit.find('**/quitready'),
self.maps_quit.find('**/quitclicked'),
self.maps_quit.find('**/quitrollover'),
self.maps_quit.find('**/quitdisable')
),
command=self.end_game,
scale=0.2,
borderWidth=(0.01, 0.01),
frameSize=(-0.55, 0.55, -0.2, 0.2),
frameColor=(0.8, 0.8, 0.8, 0)
)
# rolloverSound=self.soundManager.over,
# clickSound=self.soundManager.click))
self.start_button.node().setState(2)
self.accept("escape", self.end_game)
self.accept("arrow_up", self.up)
self.accept("arrow_down", self.down)
self.accept("enter", self.action)
def show(self):
self.frame.show()
def hide(self):
self.frame.hide()
def start_game(self):
self.frame.hide()
self.game.setup()
def end_game(self):
sys.exit(0)
def up(self):
if self.active_button == 0:
self.active_button = 2
self.start_button.node().setState(0)
self.quit_button.node().setState(2)
elif self.active_button == 1:
self.active_button = 0
self.credits_button.node().setState(0)
self.start_button.node().setState(2)
elif self.active_button == 2:
self.active_button = 1
self.quit_button.node().setState(0)
self.credits_button.node().setState(2)
print(self.active_button)
def down(self):
if self.active_button == 0:
self.active_button = 1
self.start_button.node().setState(0)
self.credits_button.node().setState(2)
elif self.active_button == 1:
self.active_button = 2
self.credits_button.node().setState(0)
self.quit_button.node().setState(2)
elif self.active_button == 2:
self.active_button = 0
self.quit_button.node().setState(0)
self.start_button.node().setState(2)
print(self.active_button)
def action(self):
if self.active_button == 0:
self.start_game()
elif self.active_button == 1:
pass
elif self.active_button == 2:
self.end_game()