From f9358df2b9ec466a2a5cd860693b1bd0550d8e9d Mon Sep 17 00:00:00 2001 From: csd4ni3l Date: Wed, 5 Nov 2025 20:22:22 +0100 Subject: [PATCH] Add textured lines and fix directions, add back buttons, remove unused imports --- .../graphics/connected_lines/horizontal.png | Bin 0 -> 170 bytes assets/graphics/connected_lines/vertical.png | Bin 0 -> 163 bytes .../graphics/unconnected_lines/horizontal.png | Bin 0 -> 158 bytes .../graphics/unconnected_lines/vertical.png | Bin 0 -> 159 bytes game/play.py | 14 ++++++-- game/power_line.py | 33 +++++++----------- menus/difficulty_selector.py | 21 ++++++----- utils/preload.py | 6 ++++ 8 files changed, 43 insertions(+), 31 deletions(-) create mode 100644 assets/graphics/connected_lines/horizontal.png create mode 100644 assets/graphics/connected_lines/vertical.png create mode 100644 assets/graphics/unconnected_lines/horizontal.png create mode 100644 assets/graphics/unconnected_lines/vertical.png diff --git a/assets/graphics/connected_lines/horizontal.png b/assets/graphics/connected_lines/horizontal.png new file mode 100644 index 0000000000000000000000000000000000000000..7056e7ef2424b2dd799f4272b245f62c3b51566f GIT binary patch literal 170 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1SD0tpLGJMLQfaRkcv5PFJ9zqFc4vJR2Gxd zzOMAi(B{U<2h*af-)C=%=C=rK2*U}@>=J6{&nrm#!_1m-{&(KqhbMlpb6vm%kFo!; Xj$&zopr E0Bz7T-~a#s literal 0 HcmV?d00001 diff --git a/assets/graphics/unconnected_lines/horizontal.png b/assets/graphics/unconnected_lines/horizontal.png new file mode 100644 index 0000000000000000000000000000000000000000..5d309532a84c40882d256433f3c39637659e8e50 GIT binary patch literal 158 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1SD0tpLGJMR8JSjkcv5PZ*CN9Fc4sN^m!U@ zbP0l+XkKunR6a literal 0 HcmV?d00001 diff --git a/assets/graphics/unconnected_lines/vertical.png b/assets/graphics/unconnected_lines/vertical.png new file mode 100644 index 0000000000000000000000000000000000000000..b05ccd5d2e6ba7db7dd46fde7c27ddfb7d3d202d GIT binary patch literal 159 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1SD0tpLGJMG*1`Dkcv5P&u3WKMspUXO@geCxd-8B{f literal 0 HcmV?d00001 diff --git a/game/play.py b/game/play.py index 08e92b6..02cc741 100644 --- a/game/play.py +++ b/game/play.py @@ -1,7 +1,8 @@ -import arcade, arcade.gui, pyglet +import arcade, arcade.gui from utils.constants import button_style from utils.preload import button_texture, button_hovered_texture + from game.power_line import PowerLine class Game(arcade.gui.UIView): @@ -9,7 +10,7 @@ class Game(arcade.gui.UIView): super().__init__() self.pypresence_client = pypresence_client - self.pypresence_client.update(state="In Game") + self.pypresence_client.update(state='In Game', start=self.pypresence_client.start_time) self.difficulty = difficulty @@ -17,10 +18,17 @@ class Game(arcade.gui.UIView): self.grid_size = list(map(int, difficulty.split("x"))) self.power_grid = self.anchor.add(arcade.gui.UIGridLayout(horizontal_spacing=0, vertical_spacing=0, row_count=self.grid_size[0], column_count=self.grid_size[1])) - def on_show_view(self): super().on_show_view() + self.back_button = arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text='<--', style=button_style, width=100, height=50) + self.back_button.on_click = lambda event: self.main_exit() + self.anchor.add(self.back_button, anchor_x="left", anchor_y="top", align_x=5, align_y=-5) + for row in range(self.grid_size[0]): for col in range(self.grid_size[1]): self.power_grid.add(PowerLine(), row=row, column=col) + + def main_exit(self): + from menus.main import Main + self.window.show_view(Main(self.pypresence_client)) \ No newline at end of file diff --git a/game/power_line.py b/game/power_line.py index 4782834..55cd131 100644 --- a/game/power_line.py +++ b/game/power_line.py @@ -1,33 +1,26 @@ import arcade, arcade.gui -from utils.preload import button_texture, button_hovered_texture -from utils.constants import button_style +from utils.preload import vertical_connected, vertical_unconnected, horizontal_connected, horizontal_unconnected from typing import Literal -ROTATIONS = ["right", "down", "left", "up"] - class PowerLine(arcade.gui.UITextureButton): def __init__(self): - super().__init__(text="--->", style=button_style, texture=button_texture, texture_hovered=button_hovered_texture) + super().__init__(texture=vertical_unconnected) - self.rotation: Literal["right", "down", "left", "up"] = "right" + self.rotation: Literal["vertical", "horizontal"] = "vertical" + self.connected = False self.on_click = lambda e: self.next_rotation() def next_rotation(self): - current_index = ROTATIONS.index(self.rotation) + if self.rotation == "vertical": + self.rotation = "horizontal" + self.texture = horizontal_connected if self.connected else horizontal_unconnected + self.texture_hovered = horizontal_connected if self.connected else horizontal_unconnected + elif self.rotation == "horizontal": + self.rotation = "vertical" + self.texture = vertical_connected if self.connected else vertical_unconnected + self.texture_hovered = vertical_connected if self.connected else vertical_unconnected - if current_index + 1 == len(ROTATIONS): - self.rotation = ROTATIONS[0] - else: - self.rotation = ROTATIONS[current_index + 1] - - if self.rotation == "up": - self.text = "^" - elif self.rotation == "down": - self.text = "ˇ" - elif self.rotation == "left": - self.text = "<---" - elif self.rotation == "right": - self.text = "--->" \ No newline at end of file + self._requires_render = True \ No newline at end of file diff --git a/menus/difficulty_selector.py b/menus/difficulty_selector.py index faa0c1f..c1d93ab 100644 --- a/menus/difficulty_selector.py +++ b/menus/difficulty_selector.py @@ -1,6 +1,7 @@ -import arcade, arcade.gui, asyncio, pypresence, time, copy, json +import arcade, arcade.gui + from utils.preload import button_texture, button_hovered_texture -from utils.constants import big_button_style, discord_presence_id +from utils.constants import big_button_style, button_style class DifficultySelector(arcade.gui.UIView): def __init__(self, pypresence_client): @@ -10,15 +11,15 @@ class DifficultySelector(arcade.gui.UIView): self.box = self.anchor.add(arcade.gui.UIBoxLayout(space_between=10), anchor_x='center', anchor_y='center') self.pypresence_client = pypresence_client - - with open("settings.json", "r") as file: - self.settings_dict = json.load(file) - - self.pypresence_client.update(state='In Menu', details='In Main Menu', start=self.pypresence_client.start_time) + self.pypresence_client.update(state='In Menu', details='In Difficulty Selector', start=self.pypresence_client.start_time) def on_show_view(self): super().on_show_view() + self.back_button = arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text='<--', style=button_style, width=100, height=50) + self.back_button.on_click = lambda event: self.main_exit() + self.anchor.add(self.back_button, anchor_x="left", anchor_y="top", align_x=5, align_y=-5) + self.box.add(arcade.gui.UILabel(text="Difficulty Selector", font_size=32)) for difficulty in ["3x3", "4x4", "5x5", "6x6", "9x9"]: @@ -27,4 +28,8 @@ class DifficultySelector(arcade.gui.UIView): def play(self, difficulty): from game.play import Game - self.window.show_view(Game(self.pypresence_client, difficulty)) \ No newline at end of file + self.window.show_view(Game(self.pypresence_client, difficulty)) + + def main_exit(self): + from menus.main import Main + self.window.show_view(Main(self.pypresence_client)) \ No newline at end of file diff --git a/utils/preload.py b/utils/preload.py index 18b76e3..ac065b3 100644 --- a/utils/preload.py +++ b/utils/preload.py @@ -2,3 +2,9 @@ import arcade.gui, arcade button_texture = arcade.gui.NinePatchTexture(64 // 4, 64 // 4, 64 // 4, 64 // 4, arcade.load_texture("assets/graphics/button.png")) button_hovered_texture = arcade.gui.NinePatchTexture(64 // 4, 64 // 4, 64 // 4, 64 // 4, arcade.load_texture("assets/graphics/button_hovered.png")) + +vertical_connected = arcade.load_texture("assets/graphics/connected_lines/vertical.png") +horizontal_connected = arcade.load_texture("assets/graphics/connected_lines/horizontal.png") + +vertical_unconnected = arcade.load_texture("assets/graphics/unconnected_lines/vertical.png") +horizontal_unconnected = arcade.load_texture("assets/graphics/unconnected_lines/horizontal.png") \ No newline at end of file