Skip to content

Commit

Permalink
Purged a bunch of dead code from tkinter char_create
Browse files Browse the repository at this point in the history
  • Loading branch information
RPINerd committed Aug 15, 2024
1 parent 05926aa commit bd43c3c
Showing 1 changed file with 1 addition and 140 deletions.
141 changes: 1 addition & 140 deletions src/screens/char_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@
import tkinter as tk
from tkinter import ttk

import pygame

from ..commander import Commander
from ..constants import BKG_COLOR, CIRCLE_XY, FRG_COLOR, HALF_RES, INTERNAL_RES, Difficulty, GameStateID
from .renderer import Button, TextInput, TextRender
from .state import State
from ..constants import Difficulty


class StatAdjuster(ttk.Frame):
Expand Down Expand Up @@ -139,138 +135,3 @@ def cmdr_create(self):
)
print(cmdr.pprint())
self.destroy()


class CharacterCreation(State):

def __init__(self, game) -> None:
self.game = game
self.head_font: pygame.font.Font = game.font_sm_bold
self.font: pygame.font.Font = game.font_sm
super().__init__(game)

self._cmdr_name = "Jameson"
self._cmdr_input = TextInput(55, 20, 80, self.font)
self.sprite_group = pygame.sprite.Group(self._cmdr_input)
self._curr_difficulty = 2
self._curr_points = 16
self._curr_pilot = 1
self._curr_fighter = 1
self._curr_trader = 1
self._curr_engineer = 1

self._inc_difficulty = Button("+", (HALF_RES + 40, 48), CIRCLE_XY, self.font)
self._dec_difficulty = Button("-", (HALF_RES - 20, 48), CIRCLE_XY, self.font)

self._inc_pilot = Button("+", (HALF_RES + 10, 80), CIRCLE_XY, self.font)
self._dec_pilot = Button("-", (HALF_RES - 20, 80), CIRCLE_XY, self.font)
self._inc_fighter = Button("+", (HALF_RES + 10, 92), CIRCLE_XY, self.font)
self._dec_fighter = Button("-", (HALF_RES - 20, 92), CIRCLE_XY, self.font)
self._inc_trader = Button("+", (HALF_RES + 10, 104), CIRCLE_XY, self.font)
self._dec_trader = Button("-", (HALF_RES - 20, 104), CIRCLE_XY, self.font)
self._inc_engineer = Button("+", (HALF_RES + 10, 116), CIRCLE_XY, self.font)
self._dec_engineer = Button("-", (HALF_RES - 20, 116), CIRCLE_XY, self.font)

self._buttons = [
self._inc_difficulty,
self._dec_difficulty,
self._inc_pilot,
self._dec_pilot,
self._inc_fighter,
self._dec_fighter,
self._inc_trader,
self._dec_trader,
self._inc_engineer,
self._dec_engineer,
]
self._curr_values = [
self._curr_points,
self._curr_pilot,
self._curr_fighter,
self._curr_trader,
self._curr_engineer,
]

def handle_events(self, event: pygame.event) -> None:
if event.type == pygame.QUIT:
self.game.running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_q:
self.game.running = False
if event.key == pygame.K_ESCAPE:
self.game.current_state = GameStateID.SPLASH
if event.key == pygame.K_RETURN:
self.game.current_state = GameStateID.SYSTEM_INFO
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
for index, button in enumerate(self._buttons):
if button.is_clicked(event.pos) and index < 2:
if button.text == "+":
self._curr_difficulty += 1
elif button.text == "-":
self._curr_difficulty -= 1
else:
raise ValueError(f"Invalid button text! Expected '+' or '-' but got {button.text}")
elif button.is_clicked(event.pos) and index >= 2:
if button.text == "+":
self._curr_points -= 1
self._curr_values[index // 2] += 1
elif button.text == "-":
self._curr_points += 1
self._curr_values[index // 2] -= 1
else:
raise ValueError(f"Invalid button text! Expected '+' or '-' but got {button.text}")
self.sprite_group.update(event)

def update(self, actions) -> None:
pass

def render(self, canvas: pygame.Surface) -> pygame.Surface:

# Background
canvas.fill(BKG_COLOR)

# Border
pygame.draw.rect(
canvas,
FRG_COLOR,
pygame.Rect(1, 1, INTERNAL_RES - 2, INTERNAL_RES - 2),
2,
border_radius=3,
)

# Header
pygame.draw.rect(
canvas,
FRG_COLOR,
pygame.Rect(3, 1, INTERNAL_RES - 6, 14),
)
header_text = TextRender(
"New Commander", (INTERNAL_RES // 2, 8), self.head_font, ref="center", fontcolor=BKG_COLOR
)
header_text.draw(canvas)

prompt_text: list[TextRender] = []
prompt_text.append(TextRender("Name:", (10, 20), self.font))
prompt_text.append(TextRender("Difficulty:", (10, 40), self.font))
prompt_text.append(TextRender("Skill Points:", (10, 65 + 14 * 0), self.font))
prompt_text.append(TextRender("Pilot:", (10, 65 + 14 * 1), self.font))
prompt_text.append(TextRender("Fighter:", (10, 65 + 14 * 2), self.font))
prompt_text.append(TextRender("Trader:", (10, 65 + 14 * 3), self.font))
prompt_text.append(TextRender("Engineer:", (10, 65 + 14 * 4), self.font))

for text in prompt_text:
text.draw(canvas)

# Buttons
for button in self._buttons:
button.draw(canvas)

# Draw the current values
self.sprite_group.draw(canvas)
difficulty_text = TextRender(Difficulty.name(self._curr_difficulty), (HALF_RES, 40), self.font)
difficulty_text.draw(canvas)
for idx, value in enumerate(self._curr_values):
value_text = TextRender(str(value), (HALF_RES, 65 + (idx * 14)), self.font)
value_text.draw(canvas)

return canvas

0 comments on commit bd43c3c

Please sign in to comment.