Skip to content

Commit

Permalink
Theming proof of concept working, started market layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
RPINerd committed Aug 20, 2024
1 parent dba5622 commit 1ee883c
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 75 deletions.
20 changes: 11 additions & 9 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

Whenever I think of something to improve but don't need another rabit hole, it goes here.

- [ ] Make a single class to handle all the possible shortcut keys for each state.
- [ ] Combine the header and title bar rendering together
- [ ] See if the canvas fill can be done once and not every frame per gamestate
- [x] Combine the header and title bar rendering together
- [ ] Rendering the bank account can be a single renderer function
- [ ] Maybe a nicer way of even spacing that doesn't rely on i = 0 loops
- [ ] Header is universal height, could be a constant for alignment use
- [ ] Import all the src.interface files at once, maybe with the init py file?
- [ ] Create a dict of pygame shortcuts in the interface init file
- [ ] Import all the src.screens files at once, maybe with the init py file?
- [ ] Look into pre-commit and pre-commmit-ci and dependabot
- [ ] Maybe have state -> corestates -> gamestates where the core states are just the BSYW states that share the button bar
- [ ] Lock window to 160x160, but have a scale int that allows for 2x, 3x, 4x, etc. scaling
- [x] Lock window to 160x160, but have a scale int that allows for 2x, 3x, 4x, etc. scaling
- [ ] Need to also have some sort of scaling for the font
- [ ] AsyncIO to update all planets while player is interacting with the current planet
- [ ] Have the core functionality and backend code in src/core?

- [ ] ~~Create a dict of pygame shortcuts in the interface init file~~
- [ ] ~~Maybe a nicer way of even spacing that doesn't rely on i = 0 loops~~
- [ ] ~~Header is universal height, could be a constant for alignment use~~
- [ ] ~~Maybe have state -> corestates -> gamestates where the core states are just the BSYW states that share the button bar~~
- [ ] ~~Make a single class to handle all the possible shortcut keys for each state.~~
- [ ] ~~See if the canvas fill can be done once and not every frame per gamestate~~
47 changes: 28 additions & 19 deletions src/screens/char_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, parent, label_text, initial_value, row, column, **kwargs) ->

global points_pool
self.value = tk.IntVar(value=initial_value)
self.label = ttk.Label(self, text=label_text, font=("Palm Pilot Small", 42))
self.label = ttk.Label(self, text=label_text)
self.decrement = ttk.Button(self, text="-", command=self.decrement_value)
self.value_label = ttk.Label(self, textvariable=self.value)
self.increment = ttk.Button(self, text="+", command=self.increment_value)
Expand Down Expand Up @@ -52,7 +52,7 @@ class CreateCommander(ttk.Frame):
def __init__(self, parent) -> None:
self.parent = parent
super().__init__(parent)
self.pack(expand=True, fill="both")
self.place(x=0, y=0, relwidth=1, relheight=1)
self.create_widgets()

def create_widgets(self):
Expand All @@ -61,7 +61,7 @@ def create_widgets(self):
self.cmdr_name = tk.StringVar(value="Jameson")
self.diff_current_value = 2
global points_pool
points_pool = tk.IntVar(value=16)
points_pool = tk.IntVar(value=0)

# Title Bar
self.header = ttk.Label(
Expand All @@ -84,7 +84,7 @@ def create_widgets(self):
# Game difficulty selection
self.difficulty_frame = ttk.Frame(self)
self.difficulty_label = ttk.Label(self.difficulty_frame, text="Difficulty:")
self.difficulty_dec = ttk.Button(self.difficulty_frame, text="-", command=self.dec_difficulty)
self.difficulty_dec = ttk.Button(self.difficulty_frame, style="TButton", text="-", command=self.dec_difficulty)
self.difficulty_current = ttk.Label(
self.difficulty_frame,
text="Normal",
Expand All @@ -99,10 +99,10 @@ def create_widgets(self):
self.skills_frame = ttk.Frame(self)
self.points_label = ttk.Label(self.skills_frame, text="Skill Points:")
self.points_current = ttk.Label(self.skills_frame, textvariable=points_pool)
self.pilot_skill = StatAdjuster(self.skills_frame, "Pilot:", 1, 0, 0)
self.fighter_skill = StatAdjuster(self.skills_frame, "Fighter:", 1, 1, 0)
self.trader_skill = StatAdjuster(self.skills_frame, "Trader:", 1, 2, 0)
self.engineer_skill = StatAdjuster(self.skills_frame, "Engineer:", 1, 3, 0)
self.pilot_skill = StatAdjuster(self.skills_frame, "Pilot:", 5, 0, 0)
self.fighter_skill = StatAdjuster(self.skills_frame, "Fighter:", 5, 1, 0)
self.trader_skill = StatAdjuster(self.skills_frame, "Trader:", 5, 2, 0)
self.engineer_skill = StatAdjuster(self.skills_frame, "Engineer:", 5, 3, 0)

self.points_label.pack(expand=True, fill="x")
self.points_current.pack(expand=True, fill="x")
Expand Down Expand Up @@ -135,14 +135,23 @@ def inc_difficulty(self) -> None:
self.difficulty_dec["state"] = "enabled"
self.difficulty_current["text"] = Difficulty.name(diff_current_value)

def cmdr_create(self):
cmdr = Commander(
self.cmdr_name.get(),
self.pilot_skill.get_value(),
self.fighter_skill.get_value(),
self.trader_skill.get_value(),
self.engineer_skill.get_value(),
)
print(cmdr.pprint())
self.destroy()
self.parent.manager.go_to_screen("I")
def cmdr_create(self) -> None:

# TODO Show a message box for invalid submissions
if points_pool.get() != 0:
print("You have unspent skill points!")
return
elif self.cmdr_name.get() == "":
print("You must enter a name!")
return
else:
cmdr = Commander(
self.cmdr_name.get(),
self.pilot_skill.get_value(),
self.fighter_skill.get_value(),
self.trader_skill.get_value(),
self.engineer_skill.get_value(),
)
print(cmdr.pprint())
self.destroy()
self.parent.manager.go_to_screen("I")
1 change: 1 addition & 0 deletions src/screens/commander_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Shows your stats, time played, etc.
"""

import tkinter as tk
from tkinter import ttk

# from ..constants import BKG_COLOR, GameStateID
Expand Down
24 changes: 23 additions & 1 deletion src/screens/markets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
Buy Cargo Screen
"""

import tkinter as tk
from random import randint
from tkinter import ttk

import src.ui_actions as actions

# from ..constants import BKG_COLOR, GameStateID
# from ..economy import TradeItemId
from ..economy import TradeItemId
from .screens import Screen


Expand All @@ -16,12 +20,30 @@ class BuyCargo(Screen):
def __init__(self, parent, screen_title, manager) -> None:
super().__init__(parent, screen_title, manager)

def create_widgets(self):
self.table_frame = ttk.Frame(self)
for i, value in enumerate(TradeItemId.lst()):
ttk.Button(self.table_frame, text=randint(0, 42)).grid(row=i, column=0)
ttk.Label(self.table_frame, text=value).grid(row=i, column=1)
ttk.Button(self.table_frame, text="Max", command=actions.buy_good).grid(row=i, column=2)
ttk.Label(self.table_frame, text="1234 cr.").grid(row=i, column=3)
self.table_frame.pack(fill="both", expand=True)


class SellCargo(Screen):

def __init__(self, parent, screen_title, manager) -> None:
super().__init__(parent, screen_title, manager)

def create_widgets(self):
self.table_frame = ttk.Frame(self)
for i, value in enumerate(TradeItemId.lst()):
ttk.Button(self.table_frame, text="0").grid(row=i, column=0)
ttk.Label(self.table_frame, text=value).grid(row=i, column=1)
ttk.Button(self.table_frame, text="All", command=actions.sell_good).grid(row=i, column=2)
ttk.Label(self.table_frame, text="15cr").grid(row=i, column=3)
self.table_frame.pack(fill="both", expand=True)


class BuyEquipment(Screen):

Expand Down
2 changes: 1 addition & 1 deletion src/screens/screen_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ScreenManager:
def __init__(self, window):
self.window = window
self.screens = self.build_screens()
print(f"Screens: {self.screens}")
# print(f"Screens: {self.screens}")
self.current_screen = "I"
self.go_to_screen(self.current_screen)

Expand Down
59 changes: 21 additions & 38 deletions src/screens/screens.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,49 @@
from src.constants import BKG_HEX, FRG_HEX, INTERNAL_RES, SCALAR


class Heading(tk.Frame):
class Heading(ttk.Frame):

def __init__(self, parent, heading: str):
super().__init__(parent)
self.parent = parent
super().__init__(parent)
self.heading = heading
self.pack()
self.create_widgets()
self.pack()

def create_widgets(self):

self.heading = tk.Label(self, text=self.heading, font=("Palm Pilot Bold", 16), fg=BKG_HEX, bg=FRG_HEX)
self.heading = ttk.Label(self, text=self.heading, style="Title.TLabel")
self.heading.pack(side="left")

self.b = tk.Button(
self.b = ttk.Button(
self,
text="B",
font=("Palm Pilot Small", 14),
fg=FRG_HEX,
bg=BKG_HEX,
width=2,
height=1,
# height=1,
command=lambda: self.shortcut_trigger(self, "B"),
)
self.b.pack(side="right")
self.s = tk.Button(
self.s = ttk.Button(
self,
text="S",
font=("Palm Pilot Small", 14),
fg=FRG_HEX,
bg=BKG_HEX,
width=2,
height=1,
# height=1,
command=lambda: self.shortcut_trigger(self, "S"),
)
self.s.pack(side="right")
self.y = tk.Button(
self.y = ttk.Button(
self,
text="Y",
font=("Palm Pilot Small", 14),
fg=FRG_HEX,
bg=BKG_HEX,
width=2,
height=1,
# height=1,
command=lambda: self.shortcut_trigger(self, "Y"),
)
self.y.pack(side="right")
self.w = tk.Button(
self.w = ttk.Button(
self,
text="W",
font=("Palm Pilot Small", 14),
fg=FRG_HEX,
bg=BKG_HEX,
width=2,
height=1,
# height=1,
command=lambda: self.shortcut_trigger(self, "W"),
)
self.w.pack(side="right")
Expand All @@ -75,20 +63,17 @@ def shortcut_trigger(event, self, key):
self.parent.manager.go_to_screen(key)


class Screen(tk.Frame):
class Screen(ttk.Frame):

def __init__(self, parent, screen_title: str, manager) -> None:
self.manager = manager
self.screen_title = screen_title
s = ttk.Style()
s.configure("TFrame", background=BKG_HEX)
super().__init__(parent, background=BKG_HEX, height=INTERNAL_RES * SCALAR, width=INTERNAL_RES * SCALAR)
super().__init__(parent)
self.place(x=0, y=0, relwidth=1, relheight=1)

self.header = Heading(self, self.screen_title)

# Bind the game shortcut keys
self.bind_all("<Escape>", self.quit)
self.bind_all("<KeyPress-b>", self.change_screen)
self.bind_all("<KeyPress-s>", self.change_screen)
self.bind_all("<KeyPress-y>", self.change_screen)
Expand All @@ -104,33 +89,31 @@ def __init__(self, parent, screen_title: str, manager) -> None:

self.create_widgets()

def quit(self, event):
self.destroy()

def change_screen(self, event):
print(f"Changing screen to {event.keysym}")
self.manager.go_to_screen(event.keysym.upper())

def create_widgets(self):
#! Placeholder id frame
self.id_frame = ttk.Frame(self)
ttk.Label(self.id_frame, text=self.screen_title, font=("Palm Pilot Small", 24)).pack(fill="both", expand=True)
ttk.Label(self.id_frame, text=self.screen_title, justify="center").pack(fill="x", expand=True)
ttk.Label(self.id_frame, text="Not Implemented", justify="center").pack(fill="x", expand=True)
self.id_frame.pack(fill="both", expand=True)


class Popup(tk.Frame):
class Popup(ttk.Frame):

def __init__(self, parent, title, content: tk.Frame, height: int = INTERNAL_RES * SCALAR):
def __init__(self, parent, title, content: ttk.Frame, height: int = INTERNAL_RES * SCALAR):
super().__init__(parent, bg=BKG_HEX, height=height, width=INTERNAL_RES * SCALAR)
self.pack(expand=True, fill="both")
self.title = title
self.content = content
self.create_widgets()

def create_widgets(self):
self.title = tk.Label(self, text=self.title)
self.title = ttk.Label(self, text=self.title)
self.title.pack()
self.message = tk.Label(self, text=self.message)
self.message = ttk.Label(self, text=self.message)
self.message.pack()
self.ok = tk.Button(self, text="OK", command=self.destroy)
self.ok = ttk.Button(self, text="OK", command=self.destroy)
self.ok.pack()
29 changes: 29 additions & 0 deletions src/screens/shipyard.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
Houses refuel, repair, escape pod purchase and then link to ship sales.
"""

import tkinter as tk
from tkinter import ttk

# from ..constants import BKG_COLOR
# from ..game_data import ShipID
import src.ui_actions as actions

from .screens import Screen

FUEL_STATUS = "You have fuel to fly {0} parsecs."
Expand All @@ -25,6 +28,32 @@ class Shipyard(Screen):
def __init__(self, parent, screen_title, manager) -> None:
super().__init__(parent, screen_title, manager)

def create_widgets(self):

# Fuel Frame
self.fuel_frame = ttk.Frame(self)
ttk.Label(self.fuel_frame, text=FUEL_STATUS.format(0), font=("Palm Pilot Small", 14)).pack()
ttk.Button(self.fuel_frame, text="Refuel", command=actions.buy_fuel).pack()
self.fuel_frame.pack(side="top", fill="both", expand=True)

# Hull Frame
self.hull_frame = ttk.Frame(self)
ttk.Label(self.hull_frame, text=HULL_STATUS.format(0), font=("Palm Pilot Small", 14)).pack()
ttk.Button(self.hull_frame, text="Repair", command=actions.repair).pack()
self.hull_frame.pack(side="top", fill="both", expand=True)

# Escape Pod Frame
self.escape_pod_frame = ttk.Frame(self)
ttk.Label(self.escape_pod_frame, text=ESCAPE_POD, font=("Palm Pilot Small", 14)).pack()
ttk.Button(self.escape_pod_frame, text="Buy Escape Pod", command=actions.buy_pod).pack()
self.escape_pod_frame.pack(side="top", fill="both", expand=True)

# Ship Sales Frame
self.ship_sales_frame = ttk.Frame(self)
ttk.Label(self.ship_sales_frame, text=SHIP_SALES, font=("Palm Pilot Small", 14)).pack()
ttk.Button(self.ship_sales_frame, text="Buy Ship", command=actions.buy_ship).pack()
self.ship_sales_frame.pack(side="top", fill="both", expand=True)


class BuyShip(Screen):

Expand Down
11 changes: 4 additions & 7 deletions src/screens/system_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Basic system information screen
"""

import tkinter as tk
from tkinter import ttk

import src.ui_actions as actions
Expand All @@ -24,21 +25,17 @@ def create_widgets(self):
self.info_frame.columnconfigure(1, weight=1)
info_headings = ["Name:", "Size:", "Tech Level:", "Government:", "Resources:", "Police:", "Pirates:"]
for i, heading in enumerate(info_headings):
ttk.Label(self.info_frame, text=heading, font=("Palm Pilot Bold", 14), justify="left").grid(
ttk.Label(self.info_frame, text=heading, style="Heading.TLabel", justify="left").grid(
row=i, column=0, sticky="ew"
)
#! Placeholder content
for i in range(0, 7):
ttk.Label(self.info_frame, text="Placeholder", font=("Palm Pilot Small", 14), justify="left").grid(
row=i, column=1, sticky="ew"
)
ttk.Label(self.info_frame, text="Placeholder", justify="left").grid(row=i, column=1, sticky="ew")
self.info_frame.pack(fill="x", expand=True)

# Pressure Frame
self.pressure_frame = ttk.Frame(self)
ttk.Label(self.pressure_frame, text=actions.get_system_info(), font=("Palm Pilot Small", 14)).grid(
row=0, column=0
)
ttk.Label(self.pressure_frame, text=actions.get_system_info()).grid(row=0, column=0)
self.pressure_frame.pack(side="top", fill="both", expand=True)

# Shortcut Frame
Expand Down
Loading

0 comments on commit 1ee883c

Please sign in to comment.