Confirm dialog to start a new game

This commit is contained in:
Khopa
2018-10-31 17:18:08 +01:00
parent 858e5d2d04
commit c656c0f7e4
3 changed files with 116 additions and 48 deletions

View File

@@ -25,11 +25,16 @@ class OverviewCanvas:
BACKGROUND = pygame.Color(0, 64, 64)
ANTIALIASING = True
started = None
def __init__(self, frame: Frame, parent, game: Game):
self.parent = parent
self.game = game
# Remove any previously existing pygame instance
pygame.quit()
# Pygame objects
self.map = None
self.screen = None
@@ -148,8 +153,12 @@ class OverviewCanvas:
pygame.display.update()
def init_sdl_thread(self):
if OverviewCanvas.started is not None:
OverviewCanvas.started.exited = True
self.thread = Thread(target=self.sdl_thread)
self.thread.start()
OverviewCanvas.started = self
print("Started SDL app")
def sdl_thread(self):
self.redraw_required = True
@@ -158,15 +167,17 @@ class OverviewCanvas:
self.clock.tick(60)
self.draw()
i += 1
if i == 300:
self.frontline_vector_cache = {}
i = 300
i = 0
print("Stopped SDL app")
def draw(self):
try:
self.parent.window.tk.winfo_ismapped()
#self.parent.window.tk.winfo_ismapped()
self.embed.winfo_ismapped()
self.embed.winfo_manager()
except:
self.exited = True
@@ -270,7 +281,7 @@ class OverviewCanvas:
else:
color = self.BLACK
pygame.draw.line(surface, color, coords, connected_coords, 4)
pygame.draw.line(surface, color, coords, connected_coords, 2)
if cp.captured and not connected_cp.captured and Conflict.has_frontline_between(cp, connected_cp):

View File

@@ -1,8 +1,14 @@
from tkinter import *
from tkinter import Menu as TkMenu
from tkinter import messagebox
from game.game import *
from theater import persiangulf, nevada, caucasus, start_generator
from .styles import BG_COLOR,BG_TITLE_COLOR
import sys
import webbrowser
class Window:
image = None
left_pane = None # type: Frame
right_pane = None # type: Frame
@@ -15,6 +21,33 @@ class Window:
self.tk.grid_columnconfigure(0, weight=1)
self.tk.grid_rowconfigure(0, weight=1)
self.frame = None
self.right_pane = None
self.left_pane = None
self.build()
menubar = TkMenu(self.tk)
filemenu = TkMenu(menubar, tearoff=0)
filemenu.add_command(label="New Game", command=lambda: self.new_game_confirm())
filemenu.add_separator()
filemenu.add_command(label="Exit", command=lambda: self.exit())
menubar.add_cascade(label="File", menu=filemenu)
helpmenu = TkMenu(menubar, tearoff=0)
helpmenu.add_command(label="Online Manual", command=lambda: webbrowser.open_new_tab("https://github.com/shdwp/dcs_liberation/wiki/Manual"))
helpmenu.add_command(label="Troubleshooting Guide", command=lambda: webbrowser.open_new_tab("https://github.com/shdwp/dcs_liberation/wiki/Troubleshooting"))
helpmenu.add_command(label="Modding Guide", command=lambda: webbrowser.open_new_tab("https://github.com/shdwp/dcs_liberation/wiki/Modding-tutorial"))
helpmenu.add_separator()
helpmenu.add_command(label="Contribute", command=lambda: webbrowser.open_new_tab("https://github.com/shdwp/dcs_liberation"))
helpmenu.add_command(label="Forum Thread", command=lambda: webbrowser.open_new_tab("https://forums.eagle.ru/showthread.php?t=214834"))
helpmenu.add_command(label="Report an issue", command=lambda: webbrowser.open_new_tab("https://github.com/shdwp/dcs_liberation/issues"))
menubar.add_cascade(label="Help", menu=helpmenu)
self.tk.config(menu=menubar)
self.tk.focus()
def build(self):
self.frame = Frame(self.tk, bg=BG_COLOR)
self.frame.grid(column=0, row=0, sticky=NSEW)
self.frame.grid_columnconfigure(0)
@@ -29,8 +62,6 @@ class Window:
self.right_pane = Frame(self.frame, bg=BG_COLOR)
self.right_pane.grid(row=0, column=1, sticky=NSEW)
self.tk.focus()
def clear_right_pane(self):
for i in range(100):
self.right_pane.grid_columnconfigure(1, weight=0)
@@ -40,10 +71,68 @@ class Window:
x.grid_remove()
def clear(self):
for x in self.left_pane.winfo_children():
x.grid_remove()
for x in self.right_pane.winfo_children():
x.grid_remove()
def clear_recursive(x, n=50):
if n < 0:
return
for y in x.winfo_children():
clear_recursive(y, n-1)
x.grid_forget()
clear_recursive(self.frame, 50)
self.left_pane.grid_remove()
self.right_pane.grid_remove()
self.build()
def start_new_game(self, player_name: str, enemy_name: str, terrain: str, sams: bool, midgame: bool, multiplier: float):
if terrain == "persiangulf":
conflicttheater = persiangulf.PersianGulfTheater()
elif terrain == "nevada":
conflicttheater = nevada.NevadaTheater()
else:
conflicttheater = caucasus.CaucasusTheater()
if midgame:
for i in range(0, int(len(conflicttheater.controlpoints) / 2)):
conflicttheater.controlpoints[i].captured = True
start_generator.generate_inital_units(conflicttheater, enemy_name, sams, multiplier)
start_generator.generate_groundobjects(conflicttheater)
game = Game(player_name=player_name,
enemy_name=enemy_name,
theater=conflicttheater)
game.budget = int(game.budget * multiplier)
game.settings.multiplier = multiplier
game.settings.sams = sams
game.settings.version = "1.4.0"
if midgame:
game.budget = game.budget * 4 * len(list(conflicttheater.conflicts()))
self.proceed_to_main_menu(game)
def proceed_to_main_menu(self, game: Game):
from ui.mainmenu import MainMenu
self.clear()
m = MainMenu(self, None, game)
m.display()
def proceed_to_new_game_menu(self):
from ui.newgamemenu import NewGameMenu
self.clear()
new_game_menu = NewGameMenu(self, self.start_new_game)
new_game_menu.display()
def new_game_confirm(self):
result = messagebox.askquestion("Start a new game", "Are you sure you want to start a new game ? Your current campaign will be overriden and there is no going back !", icon='warning')
if result == 'yes':
self.proceed_to_new_game_menu()
else:
pass
def exit(self):
self.tk.destroy()
sys.exit(0)
def run(self):
self.tk.mainloop()