Commit 8953e511 authored by talljosh's avatar talljosh

Refactored main menu in preparation for adding facility to swap between arenas on a server.

parent 0630de1698b7
......@@ -6,11 +6,10 @@
<inspection_tool class="PyCompatibilityInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ourVersions">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="3.7" />
<item index="1" class="java.lang.String" itemvalue="3.8" />
<item index="2" class="java.lang.String" itemvalue="3.9" />
<item index="3" class="java.lang.String" itemvalue="3.10" />
<list size="3">
<item index="0" class="java.lang.String" itemvalue="3.8" />
<item index="1" class="java.lang.String" itemvalue="3.9" />
<item index="2" class="java.lang.String" itemvalue="3.10" />
</list>
</value>
</option>
......
......@@ -28,6 +28,7 @@ from trosnoth.gui.common import Abs
class MainMenu(MenuDisplay):
def __init__(self, app, location, interface, keymapping):
self.interface = interface
font = app.screenManager.fonts.gameMenuFont
titleColour = (64, 64, 255)
stdColour = (96, 96, 96)
......@@ -39,73 +40,65 @@ class MainMenu(MenuDisplay):
self.ACCELERATION = 2000 # pix/s/s
self.do_action = interface.doAction
manager = MenuManager()
self.quitMenu = Menu(name='Really Quit?', listener=interface.doAction, items=[
self.quit_menu = Menu(name='Really Quit?', listener=interface.doAction, items=[
MenuItem('Leave game', ACTION_REALLY_QUIT),
MenuItem('---'),
MenuItem('Cancel', ACTION_MAIN_MENU)
])
play_menu_items = [
MenuItem('Taunt', ACTION_EMOTE),
MenuItem('Toggle upgrade select', ACTION_RADIAL_UPGRADE_MENU),
MenuItem('Activate upgrade', ACTION_USE_UPGRADE),
MenuItem('Toggle chat', ACTION_CHAT),
]
if interface.world.isServer:
play_menu_items.append(
MenuItem('Pause / resume', ACTION_PAUSE_GAME)
)
play_menu_items.extend([
MenuItem('Settings', ACTION_SETTINGS_MENU),
MenuItem('---'),
MenuItem('Leave game', ACTION_QUIT_MENU)
])
self.playMenu = Menu(name='Menu', listener=interface.doAction, items=play_menu_items)
self.replayMenu = Menu(
name='Menu', listener=self.spectate_menu_item_selected,
items=[
super().__init__(
app, location, size, font, manager,
titleColour, stdColour, hvrColour, None, backColour, autosize,
hidable, keymapping, x_padding=20, y_padding=10, hidden=True)
self.main_menu = None
self.refresh_menu_items()
def refresh_menu_items(self, replay=False, spectate=False):
main_menu_items = []
print(f'{replay=}, {spectate=}')
if replay or spectate:
if spectate:
main_menu_items.append(MenuItem('Join game', ACTION_JOIN_GAME))
main_menu_items.extend([
MenuItem('Settings', ACTION_SETTINGS_MENU),
MenuItem('---'),
MenuItem('Quit', ACTION_QUIT_MENU)
],
)
self.spectateMenu = Menu(
name='Menu', listener=self.spectate_menu_item_selected,
items=[
MenuItem('Join game', ACTION_JOIN_GAME),
])
else:
main_menu_items.extend([
MenuItem('Taunt', ACTION_EMOTE),
MenuItem('Toggle upgrade select', ACTION_RADIAL_UPGRADE_MENU),
MenuItem('Activate upgrade', ACTION_USE_UPGRADE),
MenuItem('Toggle chat', ACTION_CHAT),
])
if self.interface.world.isServer:
main_menu_items.append(
MenuItem('Pause / resume', ACTION_PAUSE_GAME)
)
main_menu_items.extend([
MenuItem('Settings', ACTION_SETTINGS_MENU),
MenuItem('---'),
MenuItem('Quit', ACTION_QUIT_MENU)
],
)
manager.setDefaultMenu(self.playMenu)
super().__init__(
app, location, size, font, manager,
titleColour, stdColour, hvrColour, None, backColour, autosize,
hidable, keymapping, x_padding=20, y_padding=10, hidden=True)
MenuItem('Leave game', ACTION_QUIT_MENU)
])
self.main_menu = Menu(name='Menu', listener=self.do_action, items=main_menu_items)
self.manager.setDefaultMenu(self.main_menu)
self.manager.reset()
def spectate_menu_item_selected(self, action):
if action != ACTION_QUIT_MENU:
def do_action(self, action):
if action in (ACTION_JOIN_GAME, ACTION_SETTINGS_MENU):
self.hide()
self.do_action(action)
self.interface.doAction(action)
def setMode(self, replay=False, spectate=False):
if replay:
self.manager.setDefaultMenu(self.replayMenu)
elif spectate:
self.manager.setDefaultMenu(self.spectateMenu)
else:
self.manager.setDefaultMenu(self.playMenu)
self.manager.reset()
print(f'setMode({replay=}, {spectate=})')
self.refresh_menu_items(replay=replay, spectate=spectate)
def showQuitMenu(self):
self.manager.reset()
self.manager.showMenu(self.quitMenu)
self.manager.showMenu(self.quit_menu)
def escape(self):
if self.hidden:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment