-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.py
116 lines (106 loc) · 4.15 KB
/
menu.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
from pymunk import Vec2d
import arcade
from arcade.gui import (
UIFlatButton,
UIGridLayout,
UIManager,
)
from loguru import logger
from game import Bomberdude
class MainView(arcade.View):
def __init__(self, window, args, **kwargs):
super().__init__()
self.args = args
self.debug = args.debug
self.window = window
self.game = Bomberdude(args)
self.manager = UIManager()
self.grid = UIGridLayout(x=300,y=300,align_horizontal='center', align_vertical='center', column_count=8, row_count=8)
self.startbtn = self.grid.add(UIFlatButton(text="Start New Game", width=150), col_num=0,row=1)
self.connectb = self.grid.add(UIFlatButton(text="Connect", width=250), col_num=1,row=2)
self.exitbtn = self.grid.add(UIFlatButton(text="Exit", width=150), col_num=2,row=3)
self.testbtn = self.grid.add(UIFlatButton(text="test", width=150), col_num=3,row=4)
self.grid.do_layout()
self.anchor = self.manager.add(self.grid)
self.mouse_pos = Vec2d(x=0, y=0)
@self.testbtn.event("on_click")
def on_testbtn_click(event):
logger.debug(f"{self} {event=}")
@self.startbtn.event("on_click")
def on_click_start_new_game_button(event):
self.startbtn.visible = False
self.exitbtn.visible = False
self.startbtn.disabled = True
self.exitbtn.disabled = True
self.connectb.disabled = True
self.connectb.visible = False
self.window.show_view(self.game)
@self.exitbtn.event("on_click")
def on_click_exit_button(event):
arcade.exit()
@self.connectb.event("on_click")
def on_connect_to_server(event):
self.game.do_connect()
self.startbtn.visible = False
self.exitbtn.visible = False
self.startbtn.disabled = True
self.exitbtn.disabled = True
# self.game._connected = True
self.connectb.text = f"{self.game.args.server}"
self.connectb.disabled = True
self.connectb.visible = False
self.window.show_view(self.game)
def on_mouse_motion(self, x: int, y: int, dx: int, dy: int):
self.mouse_pos = Vec2d(x=x, y=y)
def on_key_press(self, key, modifiers):
if self.debug:
pass # logger.debug(f'{key=} {modifiers=} ap={self.anchor.position} gp={self.grid.position}')
if key == arcade.key.F1:
self.debug = not self.debug
logger.debug(f"debug: {self.debug}")
elif key == arcade.key.F2:
pass
elif key == arcade.key.F3:
pass
elif key == arcade.key.F4:
pass
elif key == arcade.key.F5:
pass
elif key == arcade.key.F6:
pass
elif key == arcade.key.F7:
pass
elif key == arcade.key.ESCAPE or key == arcade.key.Q:
logger.warning("quit")
arcade.close_window()
return
elif key == arcade.key.SPACE:
pass
elif key == arcade.key.UP or key == arcade.key.W:
if modifiers == 16:
pass # self.anchor.move(0,1)
if modifiers == 18:
pass # self.anchor.move(0,11)
elif key == arcade.key.DOWN or key == arcade.key.S:
if modifiers == 16:
pass # self.anchor.move(0,-1)
if modifiers == 18:
pass # self.anchor.move(0, -11)
elif key == arcade.key.LEFT or key == arcade.key.A:
if modifiers == 16:
pass # self.anchor.move(-1,0)
if modifiers == 18:
pass # self.anchor.move(-11,0)
elif key == arcade.key.RIGHT or key == arcade.key.D:
if modifiers == 16:
pass # self.anchor.move(1,0)
if modifiers == 18:
pass # self.anchor.move(11,0)
def on_show_view(self):
self.window.background_color = arcade.color.BLACK
self.manager.enable()
def on_draw(self):
self.clear()
self.manager.draw()
def on_hide_view(self):
self.manager.disable() # pass