Skip to content

Commit

Permalink
Created a header class to cover the title bar and bsyw buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
RPINerd committed Aug 15, 2024
1 parent bd43c3c commit 894035d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 77 deletions.
31 changes: 31 additions & 0 deletions src/screens/header.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
Space Trader (PalmOS) | RPINerd, 2024
Renders the core header for vast majority of screens in the game.
This includes the underline, as well as the BSYW button
outlines for the top right.
"""

import tkinter as tk


class Heading(tk.Frame):
def __init__(self, parent, heading: str):
super().__init__(parent)
self.heading = heading
self.pack()
self.create_widgets()

def create_widgets(self):
self.heading = tk.Label(self, text=self.heading)
self.heading.pack()
self.underline = tk.Canvas(self, width=160, height=2, bg="#000000")
self.underline.pack()
self.b = tk.Button(self, text="B", width=2, height=1)
self.b.pack(side="right")
self.s = tk.Button(self, text="S", width=2, height=1)
self.s.pack(side="right")
self.y = tk.Button(self, text="Y", width=2, height=1)
self.y.pack(side="right")
self.w = tk.Button(self, text="W", width=2, height=1)
self.w.pack(side="right")
78 changes: 1 addition & 77 deletions src/screens/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import pygame

from ..constants import BKG_COLOR, FRG_COLOR, INTERNAL_RES
from ..constants import FRG_COLOR, INTERNAL_RES


class Button:
Expand Down Expand Up @@ -119,82 +119,6 @@ def draw(self, canvas: pygame.Surface) -> None:
canvas.blit(self.img, self.rect)


class Header:
"""
Renders the core header for vast majority of screens in the game.
This includes the underline, as well as the BSYW button
outlines for the top right.
Underline - 2px thick, starts 14px from the top of the screen
BSYW Button - 14px by 13px squares, 1px from the top right corner
"""

def __init__(self, canvas: pygame.Surface, font: pygame.font.Font) -> None:
self.canvas = canvas
self.underline = pygame.Rect(1, 14, 158, 2)

self.buttonW = Button("W", (INTERNAL_RES - 1, 1), (14, 13), font, reference="topright")
self.buttonY = Button(
"Y",
(self.buttonW.border.topleft[0] + 1, self.buttonW.border.topleft[1]),
(14, 13),
font,
reference="topright",
)
self.buttonS = Button(
"S",
(self.buttonY.border.topleft[0] + 1, self.buttonY.border.topleft[1]),
(14, 13),
font,
reference="topright",
)
self.buttonB = Button(
"B",
(self.buttonS.border.topleft[0] + 1, self.buttonS.border.topleft[1]),
(14, 13),
font,
reference="topright",
)
self.render()

def get_buttons(self) -> tuple[Button, Button, Button, Button]:
return self.buttonB, self.buttonS, self.buttonY, self.buttonW

def render(self) -> None:
pygame.draw.rect(self.canvas, FRG_COLOR, self.underline)
self.buttonW.draw(self.canvas)
self.buttonY.draw(self.canvas)
self.buttonS.draw(self.canvas)
self.buttonB.draw(self.canvas)


class TitleBar:
"""
Renders the title bar for the top of the screen (e.g. Sell Cargo, System Info, etc.)
"""

def __init__(self, title: str, font: pygame.font.Font, canvas: pygame.Surface) -> None:
self.canvas = canvas
self.title = title
self.font = font
self.text = TextRender(title, (4, 3), font, fontcolor=BKG_COLOR)
self.text_width = self.text.rect.size[0]
self.bar = pygame.Rect(1, 2, self.text_width + 5, 14)
self.top_bar = pygame.Rect(2, 1, self.text_width + 3, 1)
self.render()

def render(self) -> None:
pygame.draw.rect(self.canvas, FRG_COLOR, self.bar)
pygame.draw.rect(self.canvas, FRG_COLOR, self.top_bar)
self.text.draw(self.canvas)


class RoundedButton(Button):
"""This will be a button with the roughly rounded corners."""

pass


class TextInput(pygame.sprite.Sprite):
"""A text input box for the player to enter a custom value"""

Expand Down

0 comments on commit 894035d

Please sign in to comment.