From e88a49414b710fcda2b92a7232d73e380868fcdd Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 5 Sep 2024 11:41:23 -0400 Subject: [PATCH] Prototyped equipment buy screen --- src/screens/gamescreens.py | 32 ++++++++++++++++++++++++++++++-- src/ui_actions.py | 15 +++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/screens/gamescreens.py b/src/screens/gamescreens.py index bfc8dd2..77b3c45 100644 --- a/src/screens/gamescreens.py +++ b/src/screens/gamescreens.py @@ -83,7 +83,7 @@ class BuyCargo(Screen): def __init__(self, parent, screen_title, manager) -> None: super().__init__(parent, screen_title, manager) - def create_widgets(self): + def create_widgets(self) -> None: self.table_frame = ttk.Frame(self) for i, value in enumerate(actions.get_ware_list()): ttk.Button(self.table_frame, text=randint(0, 42)).grid(row=i, column=0) @@ -106,7 +106,7 @@ class SellCargo(Screen): def __init__(self, parent, screen_title, manager) -> None: super().__init__(parent, screen_title, manager) - def create_widgets(self): + def create_widgets(self) -> None: self.table_frame = ttk.Frame(self) for i, value in enumerate(actions.get_ware_list()): ttk.Button(self.table_frame, text="0").grid(row=i, column=0) @@ -129,6 +129,34 @@ class BuyEquipment(Screen): def __init__(self, parent, screen_title, manager) -> None: super().__init__(parent, screen_title, manager) + def create_widgets(self) -> None: + self.table_frame = ttk.Frame(self) + + sold_equipment = actions.get_equip_sold() + for i, value in enumerate(sold_equipment): + + sold = value[0] == "" + # First column are Buy buttons for each equipment + if sold: + ttk.Button(self.table_frame, text="Buy", command=actions.buy_equipment).grid(row=i, column=0) + else: + ttk.Label(self.table_frame, text=" ").grid( + row=i, + column=0, + ) + + # Second column is the equipment name + ttk.Label(self.table_frame, text=value[1]).grid(row=i, column=1, sticky="w") + + # Third column is the cost for each equipment + ttk.Label(self.table_frame, text=value[2]).grid(row=i, column=2) + + self.table_frame.pack(fill="x", expand=True) + + # Current credits + self.credits_label = ttk.Label(self, text=actions.get_credits()) + self.credits_label.place(relx=1, rely=1, anchor="se") + class SellEquipment(Screen): diff --git a/src/ui_actions.py b/src/ui_actions.py index 2bfc28b..8f86277 100644 --- a/src/ui_actions.py +++ b/src/ui_actions.py @@ -114,6 +114,21 @@ def buy_ship(): pass +def get_equip_sold() -> list[str]: + # Make an list of equipment sold by the current system, with 'x' for ones not sold + current_system_tech = c.GAME["universe"].planets[c.GAME["commander"].currentSystem].tech_level + sold_equipment: list[tuple[str, str, str]] = [] + for equips in [e.WEAPONS, e.SHIELDS, e.GADGETS]: + for _, equip in equips.items(): + if equip.tech_level == e.TechLevel.UNAVAILABLE: + continue + elif equip.tech_level <= current_system_tech: + sold_equipment.append(("", equip.name, f"{equip.price} cr.")) + else: + sold_equipment.append(("x", equip.name, "not sold")) + return sold_equipment + + def buy_equipment(): pass