Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split out UI stuff #294

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
508 changes: 62 additions & 446 deletions pokete.py

Large diffs are not rendered by default.

38 changes: 19 additions & 19 deletions pokete_classes/achievements.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import logging
import scrap_engine as se
from util import liner
from .hotkeys import ACTION_DIRECTIONS, Action, get_action
from .loops import std_loop, easy_exit_loop
from .ui_elements import BetterChooseBox, LabelBox
from .context import Context
from .input import ACTION_DIRECTIONS, Action, get_action
from .ui.elements import BetterChooseBox, LabelBox
from .ui.notify import notifier
from .color import Color
from .notify import notifier
from . import movemap as mvp
from . import loops


class Achievement:
Expand Down Expand Up @@ -75,12 +75,13 @@ def __init__(self, ach, ach_ob, overview):
is_ach = ach_ob.is_achieved(ach.identifier)
date = [i[-1] for i in ach_ob.achieved if i[0] ==
ach.identifier][0] if is_ach else ""
label = se.Text("Achieved: ", state="float")\
label = se.Text("Achieved: ", state="float") \
+ se.Text("Yes" if is_ach else "No",
esccode=Color.thicc
+ (Color.green if is_ach
else Color.grey), state="float")\
+ (se.Text("\nAt: " + date, state="float") if is_ach else se.Text(""))\
+ (Color.green if is_ach
else Color.grey), state="float") \
+ (se.Text("\nAt: " + date,
state="float") if is_ach else se.Text("")) \
+ se.Text("\n" + liner(ach.desc, 30), state="float")
super().__init__(label, name=ach.title,
info=f"{Action.CANCEL.mapping}:close",
Expand All @@ -93,19 +94,17 @@ class AchievementOverview(BetterChooseBox):
def __init__(self):
super().__init__(
3, [se.Text(" ")], name="Achievements",
overview=mvp.movemap.menu
)

def __call__(self, _map):
"""Input loop
ARGS:
_map: se.Map to show this on"""
def __call__(self, ctx: Context):
"""Input loop"""
self.set_items(3, [se.Text(i.title,
esccode=Color.thicc + Color.green
if achievements.is_achieved(i.identifier)
else "", state="float")
for i in achievements.achievements])
self.map = _map
self.map = ctx.map
self.overview = ctx.overview
with self:
while True:
action = get_action()
Expand All @@ -122,10 +121,11 @@ def __call__(self, _map):
ach,
achievements,
self
).center_add(_map) as achbox:
easy_exit_loop(box=achbox)
std_loop(box=self)
self.map.show()
).center_add(ctx.map) as achbox:
loops.easy_exit(
box=achbox, pevm=ctx.pevm)
loops.std(box=self, pevm=ctx.pevm)
self.map.full_show()


achievements = Achievements()
9 changes: 6 additions & 3 deletions pokete_classes/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import scrap_engine as se
import pokete_classes.game_map as gm
from .game import PeriodicEvent
from .weather import Weather


Expand All @@ -19,7 +20,8 @@ class PlayMap(gm.GameMap):

def __init__(self, height=se.screen_height - 1, width=se.screen_width,
trainers=None, name="", pretty_name="", poke_args=None,
w_poke_args=None, extra_actions=None, weather=None,
w_poke_args=None,
extra_actions: list[PeriodicEvent] | None = None, weather=None,
song="03 Chibi Ninja.mp3"):
super().__init__(height, width, name=name)
self.song = song
Expand Down Expand Up @@ -52,10 +54,11 @@ def get_obj(self, name):
name: Name in registry"""
return self.registry.get(name, None)

def extra_actions(self):
def extra_actions(self) -> list[PeriodicEvent]:
"""Executes the extra action"""
if self.__extra_actions is not None:
self.__extra_actions()
return self.__extra_actions
return []


class OutP(se.Text):
Expand Down
21 changes: 21 additions & 0 deletions pokete_classes/context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from copy import copy

from .movemap import Movemap
from .game import PeriodicEventManager
from .ui import Overview


class Context:
def __init__(
self, pevm: PeriodicEventManager, _map: Movemap,
overview: Overview, figure
):
self.pevm = pevm
self.map = _map
self.overview = overview
self.figure = figure

def with_overview(self, overview: Overview) -> "Context":
ctx = copy(self)
ctx.overview = overview
return ctx
21 changes: 10 additions & 11 deletions pokete_classes/deck.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
import scrap_engine as se
from pokete_classes import detail
import pokete_classes.game_map as gm
from pokete_classes.hotkeys import (
ACTION_DIRECTIONS, Action, get_action
from .input import (
ACTION_DIRECTIONS, Action, get_action, _ev
)
import pokete_classes.movemap as mvp
from .event import _ev
from .input import ask_bool, ask_ok
from .loops import std_loop
from .ui import ask_bool, ask_ok
from .color import Color
from .poke import Poke
from .ui_elements import StdFrame2
from .ui.elements import StdFrame2
from .tss import tss
from . import loops


class Deck(detail.Informer):
Expand Down Expand Up @@ -164,7 +163,7 @@ def __call__(self, overview, p_len, label="Your full deck", in_fight=False):
{self.figure.pokes[self.index.index].name}?", self):
self.rem_pokes()
self.figure.pokes[self.index.index] = Poke("__fallback__",
10, 0)
10, 0)
self.pokes = self.figure.pokes[:len(self.pokes)]
self.add_all()
self.index.set(
Expand All @@ -175,7 +174,7 @@ def __call__(self, overview, p_len, label="Your full deck", in_fight=False):
mvp.movemap.balls_label_rechar(self.figure.pokes)
elif action.triggers(Action.ACCEPT):
if len(self.pokes) == 0 or \
self.pokes[self.index.index].identifier == "__fallback__":
self.pokes[self.index.index].identifier == "__fallback__":
continue
if in_fight:
if self.pokes[self.index.index].hp > 0:
Expand All @@ -200,9 +199,9 @@ def __call__(self, overview, p_len, label="Your full deck", in_fight=False):
_ev.set(Action.CANCEL.mapping)
continue
self.submap.full_show(init=True)
std_loop(False, box=self)
if len(self.pokes) > 0 and\
self.index.y - self.submap.y + 6 > self.submap.height:
loops.std(False, box=self)
if len(self.pokes) > 0 and \
self.index.y - self.submap.y + 6 > self.submap.height:
self.submap.set(self.submap.x, self.submap.y + 1)
elif len(self.pokes) > 0 and self.index.y - 1 < self.submap.y:
self.submap.set(self.submap.x, self.submap.y - 1)
Expand Down
31 changes: 16 additions & 15 deletions pokete_classes/detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import scrap_engine as se
import pokete_classes.game_map as gm
from util import liner
from .hotkeys import Action, get_action
from .input import Action, get_action, _ev
from .ui.elements import StdFrame2, ChooseBox
from .pokestats import PokeStatsInfoBox
from .loops import std_loop
from .event import _ev
from .ui_elements import StdFrame2, ChooseBox
from .color import Color
from .tss import tss
from . import loops


class Informer:
Expand All @@ -35,8 +34,8 @@ def add(poke, figure, _map, _x, _y, in_deck=True):
obj.add(_map, _x + __x, _y + __y)
if in_deck and figure.pokes.index(poke) < 6:
poke.pball_small.add(_map, round(_map.width / 2) - 1
if figure.pokes.index(poke) % 2 == 0
else _map.width - 2, _y)
if figure.pokes.index(poke) % 2 == 0
else _map.width - 2, _y)
for eff in poke.effects:
eff.add_label()

Expand Down Expand Up @@ -178,7 +177,8 @@ def __call__(self, poke, abb=True, overview=None):
self.attack_defense.rechar(f"Attack:{self.poke.atc}\
{(4 - len(str(self.poke.atc))) * ' '}Defense:{self.poke.defense}")
self.initiative_label.rechar(f"Initiative:{self.poke.initiative}")
for obj, _x, _y in zip([self.poke.desc, self.poke.text_type], [34, 41], [2, 5]):
for obj, _x, _y in zip([self.poke.desc, self.poke.text_type], [34, 41],
[2, 5]):
obj.add(self.map, _x, _y)
self.add_attack_labels()
if (tss.height - 1, tss.width) != (self.map.height, self.map.width):
Expand Down Expand Up @@ -209,30 +209,31 @@ def __call__(self, poke, abb=True, overview=None):
for i in abb_obs
],
overview=self
).center_add(self.map)\
as box:
).center_add(self.map) \
as box:
while True:
action = get_action()
if action.triggers(Action.UP, Action.DOWN):
box.input(action)
self.map.show()
elif action.triggers(Action.ACCEPT):
ret_action = abb_obs[box.index.index].world_action
ret_action = abb_obs[
box.index.index].world_action
_ev.set(Action.CANCEL.mapping)
break
elif action.triggers(Action.CANCEL):
break
std_loop(False, box=box)
std_loop(False, box=self)
loops.std(False, box=box)
loops.std(False, box=self)
# This section generates the Text effect for attack labels
for atc in self.poke.attack_obs:
if len(atc.desc) > int((self.map.width - 3) / 2 - 1):
if atc.temp_j == 5:
atc.temp_i += 1
atc.temp_j = 0
if atc.temp_i == len(atc.desc)\
- int(self.map.width / 2 - 1)\
+ 10:
if atc.temp_i == len(atc.desc) \
- int(self.map.width / 2 - 1) \
+ 10:
atc.temp_i = 0
atc.temp_j = -30
atc.label_desc.rechar(atc.desc[atc.temp_i:
Expand Down
Loading
Loading