Skip to content
Snippets Groups Projects
Commit a3d40aaf authored by Fabian Heinrich's avatar Fabian Heinrich
Browse files

Changed init window size to minimum window size

parent dd1507a9
No related branches found
No related tags found
1 merge request!28Resolve "Game time limit"
Pipeline #43856 passed
...@@ -4,4 +4,4 @@ plates: ...@@ -4,4 +4,4 @@ plates:
plate_delay: [ 5, 10 ] plate_delay: [ 5, 10 ]
game: game:
time_limit_seconds: 30.0 time_limit_seconds: 90
...@@ -44,6 +44,10 @@ ...@@ -44,6 +44,10 @@
}, },
"misc": { "misc": {
"tool_tip_delay": "1.5" "tool_tip_delay": "1.5"
},
"font": {
"size": 15,
"bold": 1
} }
}, },
"#timer_label": { "#timer_label": {
...@@ -63,5 +67,12 @@ ...@@ -63,5 +67,12 @@
"size": 20, "size": 20,
"bold": 1 "bold": 1
} }
},
"#quit_button": {
"colours": {
"normal_bg": "#f71b29",
"hovered_bg": "#bf0310",
"normal_border": "#DDDDDD"
}
} }
} }
\ No newline at end of file
...@@ -115,11 +115,14 @@ class PyGameGUI: ...@@ -115,11 +115,14 @@ class PyGameGUI:
self.visualization_config = yaml.safe_load(file) self.visualization_config = yaml.safe_load(file)
self.screen_margin = self.visualization_config["GameWindow"]["screen_margin"] self.screen_margin = self.visualization_config["GameWindow"]["screen_margin"]
self.init_width = self.visualization_config["GameWindow"]["init_width"] self.min_width = self.visualization_config["GameWindow"]["min_width"]
self.init_height = self.visualization_config["GameWindow"]["init_height"] self.min_height = self.visualization_config["GameWindow"]["min_height"]
self.window_width = self.init_width self.buttons_width = self.visualization_config["GameWindow"]["buttons_width"]
self.window_height = self.init_height self.buttons_height = self.visualization_config["GameWindow"]["buttons_height"]
self.window_width = self.min_width
self.window_height = self.min_height
self.main_window = pygame.display.set_mode( self.main_window = pygame.display.set_mode(
( (
...@@ -146,27 +149,38 @@ class PyGameGUI: ...@@ -146,27 +149,38 @@ class PyGameGUI:
kitchen_aspect_ratio = kitchen_height / kitchen_width kitchen_aspect_ratio = kitchen_height / kitchen_width
game_height = int(game_width * kitchen_aspect_ratio) game_height = int(game_width * kitchen_aspect_ratio)
grid_size = int(game_width / self.simulator.env.kitchen_width) grid_size = int(game_width / self.simulator.env.kitchen_width)
elif self.visualization_config["GameWindow"]["WhatIsFixed"] == "window_height": elif self.visualization_config["GameWindow"]["WhatIsFixed"] == "window_height":
game_height = self.visualization_config["GameWindow"]["size"] game_height = self.visualization_config["GameWindow"]["size"]
kitchen_aspect_ratio = kitchen_width / kitchen_height kitchen_aspect_ratio = kitchen_width / kitchen_height
game_width = int(game_height * kitchen_aspect_ratio) game_width = int(game_height * kitchen_aspect_ratio)
grid_size = int(game_width / self.simulator.env.kitchen_width) grid_size = int(game_width / self.simulator.env.kitchen_width)
elif self.visualization_config["GameWindow"]["WhatIsFixed"] == "grid": elif self.visualization_config["GameWindow"]["WhatIsFixed"] == "grid":
grid_size = self.visualization_config["GameWindow"]["size"] grid_size = self.visualization_config["GameWindow"]["size"]
game_width, game_height = ( game_width, game_height = (
kitchen_width * grid_size, kitchen_width * grid_size,
kitchen_height * grid_size, kitchen_height * grid_size,
) )
else: else:
game_width, game_height = 0, 0 game_width, game_height = 0, 0
grid_size = 0 grid_size = 0
window_width, window_height = ( window_width, window_height = (
game_width + (2 * self.screen_margin), game_width + (2 * self.screen_margin),
game_height + (2 * self.screen_margin), game_height + (2 * self.screen_margin), # bar with orders
) )
return int(window_width), int(window_height), game_width, game_height, grid_size window_width = max(window_width, self.min_width)
window_height = max(window_height, self.min_height)
return (
int(window_width),
int(window_height),
game_width,
game_height,
grid_size,
)
def create_player_colors(self) -> list[Color]: def create_player_colors(self) -> list[Color]:
number_player = len(self.simulator.env.players) number_player = len(self.simulator.env.players)
...@@ -515,14 +529,13 @@ class PyGameGUI: ...@@ -515,14 +529,13 @@ class PyGameGUI:
self.manager = pygame_gui.UIManager((self.window_width, self.window_height)) self.manager = pygame_gui.UIManager((self.window_width, self.window_height))
self.manager.get_theme().load_theme(ROOT_DIR / "gui_2d_vis" / "gui_theme.json") self.manager.get_theme().load_theme(ROOT_DIR / "gui_2d_vis" / "gui_theme.json")
button_width, button_height = 200, 60
self.start_button = pygame_gui.elements.UIButton( self.start_button = pygame_gui.elements.UIButton(
relative_rect=pygame.Rect( relative_rect=pygame.Rect(
( (
(self.window_width // 2) - button_width // 2, (self.window_width // 2) - self.buttons_width // 2,
(self.window_height / 2) - button_height // 2, (self.window_height / 2) - self.buttons_height // 2,
), ),
(button_width, button_height), (self.buttons_width, self.buttons_height),
), ),
text="Start Game", text="Start Game",
manager=self.manager, manager=self.manager,
...@@ -532,23 +545,24 @@ class PyGameGUI: ...@@ -532,23 +545,24 @@ class PyGameGUI:
self.quit_button = pygame_gui.elements.UIButton( self.quit_button = pygame_gui.elements.UIButton(
relative_rect=pygame.Rect( relative_rect=pygame.Rect(
( (
(self.window_width - button_width), (self.window_width - self.buttons_width),
0, 0,
), ),
(button_width, button_height), (self.buttons_width, self.buttons_height),
), ),
text="Quit Game", text="Quit Game",
manager=self.manager, manager=self.manager,
object_id="#quit_button",
) )
self.quit_button.can_hover() self.quit_button.can_hover()
self.finished_button = pygame_gui.elements.UIButton( self.finished_button = pygame_gui.elements.UIButton(
relative_rect=pygame.Rect( relative_rect=pygame.Rect(
( (
(self.window_width - button_width), (self.window_width - self.buttons_width),
(self.window_height - button_height), (self.window_height - self.buttons_height),
), ),
(button_width, button_height), (self.buttons_width, self.buttons_height),
), ),
text="End screen", text="End screen",
manager=self.manager, manager=self.manager,
...@@ -559,9 +573,9 @@ class PyGameGUI: ...@@ -559,9 +573,9 @@ class PyGameGUI:
relative_rect=pygame.Rect( relative_rect=pygame.Rect(
( (
(0), (0),
(self.window_height - button_height), (self.window_height - self.buttons_height),
), ),
(button_width, button_height), (self.buttons_width, self.buttons_height),
), ),
text="Back to Start", text="Back to Start",
manager=self.manager, manager=self.manager,
...@@ -570,10 +584,10 @@ class PyGameGUI: ...@@ -570,10 +584,10 @@ class PyGameGUI:
self.score_rect = pygame.Rect( self.score_rect = pygame.Rect(
( (
(self.window_width // 2) - button_width // 2, (self.window_width // 2) - self.buttons_width // 2,
(self.window_height / 2) - button_height // 2, (self.window_height / 2) - self.buttons_height // 2,
), ),
(button_width, button_height), (self.buttons_width, self.buttons_height),
) )
self.score_label = pygame_gui.elements.UILabel( self.score_label = pygame_gui.elements.UILabel(
...@@ -606,7 +620,7 @@ class PyGameGUI: ...@@ -606,7 +620,7 @@ class PyGameGUI:
text="GAMETIME", text="GAMETIME",
relative_rect=pygame.Rect( relative_rect=pygame.Rect(
(0, 0), (0, 0),
(button_width * 1.5, button_height), (self.buttons_width * 1.5, self.buttons_height),
), ),
manager=self.manager, manager=self.manager,
object_id="#timer_label", object_id="#timer_label",
...@@ -627,11 +641,11 @@ class PyGameGUI: ...@@ -627,11 +641,11 @@ class PyGameGUI:
) )
def reset_window_size(self): def reset_window_size(self):
self.window_width = self.init_width self.window_width = self.min_width
self.window_height = self.init_height self.window_height = self.min_height
self.game_width = 0 self.game_width = 0
self.game_height = 0 self.game_height = 0
self.set_window_size(self.init_width, self.init_height, 0, 0) self.set_window_size(self.min_width, self.min_height, 0, 0)
self.init_ui_elements() self.init_ui_elements()
def setup_simulation(self, config_path, layout_path): def setup_simulation(self, config_path, layout_path):
...@@ -694,10 +708,9 @@ class PyGameGUI: ...@@ -694,10 +708,9 @@ class PyGameGUI:
log.debug("Pressed start button") log.debug("Pressed start button")
def back_button_press(self): def back_button_press(self):
self.menu_state = MenuStates.Start
self.reset_window_size() self.reset_window_size()
self.simulator.stop() self.simulator.stop()
self.menu_state = MenuStates.Start
log.debug("Pressed back button") log.debug("Pressed back button")
def quit_button_press(self): def quit_button_press(self):
...@@ -706,9 +719,9 @@ class PyGameGUI: ...@@ -706,9 +719,9 @@ class PyGameGUI:
log.debug("Pressed quit button") log.debug("Pressed quit button")
def finished_button_press(self): def finished_button_press(self):
self.menu_state = MenuStates.End
self.reset_window_size() self.reset_window_size()
self.simulator.stop() self.simulator.stop()
self.menu_state = MenuStates.End
log.debug("Pressed finished button") log.debug("Pressed finished button")
def start_pygame(self): def start_pygame(self):
...@@ -729,7 +742,6 @@ class PyGameGUI: ...@@ -729,7 +742,6 @@ class PyGameGUI:
while self.running: while self.running:
try: try:
time_delta = clock.tick(self.FPS) / 1000.0 time_delta = clock.tick(self.FPS) / 1000.0
state = self.simulator.get_state()
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == pygame.QUIT: if event.type == pygame.QUIT:
...@@ -759,6 +771,8 @@ class PyGameGUI: ...@@ -759,6 +771,8 @@ class PyGameGUI:
# drawing: # drawing:
state = self.simulator.get_state()
self.main_window.fill(colors["lemonchiffon1"]) self.main_window.fill(colors["lemonchiffon1"])
self.manager.draw_ui(self.main_window) self.manager.draw_ui(self.main_window)
...@@ -773,6 +787,7 @@ class PyGameGUI: ...@@ -773,6 +787,7 @@ class PyGameGUI:
if state["ended"]: if state["ended"]:
self.finished_button_press() self.finished_button_press()
self.manage_button_visibility() self.manage_button_visibility()
self.draw(state) self.draw(state)
game_screen_rect = self.game_screen.get_rect() game_screen_rect = self.game_screen.get_rect()
......
# colors: https://www.webucator.com/article/python-color-constants-module/ # colors: https://www.webucator.com/article/python-color-constants-module/
GameWindow: GameWindow:
WhatIsFixed: grid # grid or window_width or window_height WhatIsFixed: window_height # grid or window_width or window_height
size: 40 size: 400
screen_margin: 100 screen_margin: 100
init_width: 600 min_width: 700
init_height: 600 min_height: 600
buttons_width: 180
buttons_height: 60
Kitchen: Kitchen:
ground_tiles_color: sgigray76 ground_tiles_color: sgigray76
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment