mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Improved style of main menu, configuration menu, and base menu
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
import pickle
|
||||
|
||||
from ui.basemenu import *
|
||||
from ui.overviewcanvas import *
|
||||
from ui.configurationmenu import *
|
||||
|
||||
from game.game import *
|
||||
from ui.basemenu import *
|
||||
from ui.configurationmenu import *
|
||||
from ui.overviewcanvas import *
|
||||
from userdata import persistency
|
||||
from .styles import STYLES
|
||||
|
||||
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
|
||||
|
||||
class MainMenu(Menu):
|
||||
@@ -18,45 +20,57 @@ class MainMenu(Menu):
|
||||
self.upd.update()
|
||||
|
||||
self.frame = self.window.right_pane
|
||||
self.frame.grid_columnconfigure(0, weight=1)
|
||||
self.frame.columnconfigure(0, weight=1)
|
||||
self.frame.rowconfigure(0, weight=1)
|
||||
|
||||
def display(self):
|
||||
persistency.save_game(self.game)
|
||||
|
||||
self.window.clear_right_pane()
|
||||
self.upd.update()
|
||||
row = 1
|
||||
row = 0
|
||||
|
||||
# Header :
|
||||
header = Frame(self.frame, **STYLES["header"])
|
||||
Button(header, text="Configuration", command=self.configuration_menu, **STYLES["btn-primary"]).grid(column=0, row=0, sticky=NE)
|
||||
Label(header, text="Budget: {}m (+{}m)".format(self.game.budget, self.game.budget_reward_amount), **STYLES["strong"]).grid(column=1, row=0, sticky=NSEW, padx=50)
|
||||
Button(header, text="Pass turn", command=self.pass_turn, **STYLES["btn-primary"]).grid(column=2, row=0, sticky=NW)
|
||||
header.grid(column=0, row=0, sticky=N+EW)
|
||||
|
||||
body = LabelFrame(self.frame, **STYLES["body"])
|
||||
body.grid(column=0, row=1, sticky=NSEW)
|
||||
|
||||
def label(text):
|
||||
nonlocal row
|
||||
Label(self.frame, text=text).grid(row=row, sticky=NW)
|
||||
nonlocal row, body
|
||||
frame = LabelFrame(body, **STYLES["label-frame"])
|
||||
frame.grid(row=row, sticky=NSEW, columnspan=2)
|
||||
Label(frame, text=text, **STYLES["widget"]).grid(row=row, sticky=NS)
|
||||
row += 1
|
||||
|
||||
def event_button(event):
|
||||
nonlocal row
|
||||
Message(self.frame, text="{}{} at {}".format(
|
||||
nonlocal row, body
|
||||
frame = LabelFrame(body, **STYLES["label-frame"])
|
||||
frame.grid(row=row, sticky=NSEW)
|
||||
Message(frame, text="{}{} at {}".format(
|
||||
event.defender_name == self.game.player and "Enemy attacking: " or "",
|
||||
event,
|
||||
event.to_cp,
|
||||
), aspect=1600).grid(column=0, row=row, sticky=NW)
|
||||
Button(self.frame, text=">", command=self.start_event(event)).grid(column=0, row=row, sticky=NE+S); row += 1
|
||||
), aspect=1600, **STYLES["widget"]).grid(column=0, row=0, sticky=NSEW)
|
||||
Button(body, text=">", command=self.start_event(event), **STYLES["btn-primary"]).grid(column=1, row=row, sticky=E)
|
||||
row += 1
|
||||
|
||||
def destination_header(text, separator=True):
|
||||
nonlocal row
|
||||
if separator:
|
||||
Separator(self.frame, orient=HORIZONTAL).grid(row=row, sticky=EW); row += 1
|
||||
Label(self.frame, text=text).grid(column=0, row=row, sticky=N); row += 1
|
||||
def destination_header(text, pady=0):
|
||||
nonlocal row, body
|
||||
Label(body, text=text, **STYLES["strong"]).grid(column=0, columnspan=2, row=row, sticky=N+EW, pady=(pady,0)); row += 1
|
||||
|
||||
Button(self.frame, text="Configuration", command=self.configuration_menu).grid(column=0, row=0, sticky=NE)
|
||||
Button(self.frame, text="Pass turn", command=self.pass_turn).grid(column=0, row=0, sticky=NW)
|
||||
Label(self.frame, text="Budget: {}m (+{}m)".format(self.game.budget, self.game.budget_reward_amount)).grid(column=0, row=0, sticky=N)
|
||||
Separator(self.frame, orient='horizontal').grid(row=row, sticky=EW); row += 1
|
||||
#Separator(self.frame, orient='horizontal').grid(row=row, sticky=EW); row += 1
|
||||
|
||||
events = self.game.events
|
||||
events.sort(key=lambda x: x.from_cp.name)
|
||||
events.sort(key=lambda x: x.informational and 2 or (self.game.is_player_attack(x) and 1 or 0))
|
||||
|
||||
destination = None
|
||||
deliveries = False
|
||||
for event in events:
|
||||
if not event.informational:
|
||||
if self.game.is_player_attack(event):
|
||||
@@ -64,10 +78,13 @@ class MainMenu(Menu):
|
||||
else:
|
||||
new_destination = "Enemy attack"
|
||||
if destination != new_destination:
|
||||
destination_header(new_destination, destination is not None)
|
||||
destination_header(new_destination)
|
||||
destination = new_destination
|
||||
|
||||
if event.informational:
|
||||
if not deliveries:
|
||||
deliveries = True
|
||||
destination_header("Deliveries", 15)
|
||||
label(str(event))
|
||||
else:
|
||||
event_button(event)
|
||||
@@ -92,3 +109,7 @@ class MainMenu(Menu):
|
||||
|
||||
self.basemenu = BaseMenu(self.window, self, self.game, cp)
|
||||
self.basemenu.display()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user