Skip to content

Commit 237679c

Browse files
authored
Merge pull request #348 from lxgr-linux/fix/mousability_bugfix
Fix/mousability bugfix
2 parents 6a5caa0 + 022c10b commit 237679c

10 files changed

Lines changed: 105 additions & 59 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
dist/
33
build/
44
**/*.egg-info
5+
.DS_Store
56

67
.idea
78
scrap_engine.py

pkg/server/.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
POKETE_SERVER_CLIENT_VERSION="0.10.0-rc3"
1+
POKETE_SERVER_CLIENT_VERSION="0.10.0-rc4"
22
POKETE_SERVER_HOST="localhost"
33
POKETE_SERVER_PORT="9988"
44
POKETE_API_PORT="9989"

src/pokete/base/ui/views/choose_box.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,15 @@ def __init__(
7878
self.elems: list[HasArea] = []
7979
self.up_down_switch = UpDownSwitch(self)
8080
self.__special_ret: Optional[T] = None
81-
self.add_ob(
82-
self.up_down_switch,
83-
self.width - 3 - self.up_down_switch.width,
84-
self.height - 1,
85-
)
81+
self.__add_up_down_switch()
82+
83+
def __add_up_down_switch(self):
84+
if len(self.elems) / (self.height - 2) > 1:
85+
self.add_ob(
86+
self.up_down_switch,
87+
self.width - 3 - self.up_down_switch.width,
88+
self.height - 1,
89+
)
8690

8791
@override
8892
def get_partial_interactors(self) -> list[MouseInteractor]:
@@ -145,19 +149,13 @@ def add_elems(self):
145149
@abstractmethod
146150
def new_size(self) -> tuple[int, int]: ...
147151

148-
def resize(self, height, width):
149-
super().resize(height, width)
150-
self.add_ob(
151-
self.up_down_switch,
152-
self.width - 3 - self.up_down_switch.width,
153-
self.height - 1,
154-
)
155-
156152
def resize_view(self):
157153
"""Manages recursive view resizing"""
158154
self.remove()
159155
self.overview.resize_view()
156+
self.rem_ob(self.up_down_switch)
160157
self.resize(*self.new_size())
158+
self.__add_up_down_switch()
161159
self.rem_elems()
162160
self.add_elems()
163161
if len(self.c_obs) == 0:
@@ -193,6 +191,7 @@ def change_page(self, add_page, n_idx):
193191
def __call__(self, ctx: Context) -> Optional[T]:
194192
self.set_ctx(ctx)
195193
ctx = change_ctx(ctx, self)
194+
self.__add_up_down_switch()
196195

197196
while True:
198197
action, _ = get_action()

src/pokete/classes/interactions/multi_text_choose_box.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from .. import movemap as mvp
99

1010

11-
class MultiTextChooseBox(ChooseBoxView[str]):
11+
class MultiTextChooseBox(ChooseBoxView[tuple[int, str]]):
1212
"""ChooseBox wrapper for multitext conversations"""
1313

1414
def __init__(self, keys: list[str], name: str):
@@ -26,13 +26,13 @@ def __init__(self, keys: list[str], name: str):
2626
def new_size(self) -> tuple[int, int]:
2727
return self.height, self.width
2828

29-
def choose(self, ctx: Context, idx: int) -> Optional[str]:
29+
def choose(self, ctx: Context, idx: int) -> Optional[tuple[int, str]]:
3030
if idx >= 0:
31-
return self.keys[idx]
31+
return idx, self.keys[idx]
3232
else:
3333
return None
3434

35-
def add(self, _map, x, y):
35+
def add_relative(self, _map, x, y):
3636
assert self.fig
3737
mvp.movemap.assure_distance(
3838
self.fig.x, self.fig.y, self.width + 2, self.height + 2
@@ -41,9 +41,12 @@ def add(self, _map, x, y):
4141
_map, self.fig.x - mvp.movemap.x, self.fig.y - mvp.movemap.y + 1
4242
)
4343

44-
def __call__(self, ctx: Context) -> Optional[str]:
44+
def __call__(self, ctx: Context) -> tuple[int, str]:
4545
self.fig = ctx.figure
46-
self.add_elems()
46+
ret: Optional[tuple[int, str]] = None
4747

48-
with self.add(ctx.map, -1, -1):
49-
return super().__call__(ctx)
48+
while ret is None:
49+
self.add_elems()
50+
with self.add_relative(ctx.map, -1, -1):
51+
ret = super().__call__(ctx)
52+
return ret

src/pokete/classes/map_additions/center.py

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
1+
import random
12
import time
23

34
import scrap_engine as se
45

5-
from pokete.base import loops
6-
from pokete.base.input import Action, _ev, get_action
6+
from pokete.base.input import _ev
77
from pokete.classes import deck
88
from pokete.classes import movemap as mvp
99
from pokete.classes.classes import PlayMap
1010
from pokete.classes.doors import CenterDoor
11+
from pokete.classes.interactions.multi_text_choose_box import MultiTextChooseBox
1112
from pokete.classes.inv import buy
1213
from pokete.classes.landscape import MapInteract
1314
from pokete.release import SPEED_OF_TIME
1415

16+
CUDDLE_MESSAGES = [
17+
"{name} nuzzles against you affectionately!",
18+
"{name} nuzzles against you lovingly!",
19+
"{name} nuzzles against you happily!",
20+
"{name} purrs contentedly in your arms!",
21+
"{name} looks up at you with adoring eyes!",
22+
"{name} snuggles closer to you!",
23+
]
24+
1525

1626
class CenterMap(PlayMap):
1727
"""Contains all relevant objects for centermap
@@ -87,6 +97,22 @@ def __init__(self, _he, _wi):
8797
class CenterInteract(se.Object, MapInteract):
8898
"""Triggers a conversation in the Pokete center"""
8999

100+
def __init__(self, *args, **kwargs):
101+
super().__init__(*args, **kwargs)
102+
self.menu = MultiTextChooseBox(
103+
[
104+
"See your full deck",
105+
"Heal all your Poketes",
106+
"Cuddle with the Poketes",
107+
"Quit",
108+
],
109+
"Select",
110+
)
111+
112+
def __normalize_pokes(self, ob):
113+
while "__fallback__" in [p.identifier for p in ob.pokes]:
114+
ob.pokes.pop([p.identifier for p in ob.pokes].index("__fallback__"))
115+
90116
def action(self, ob):
91117
"""Triggers the interaction in the Pokete center
92118
ARGS:
@@ -100,21 +126,15 @@ def action(self, ob):
100126
[
101127
"Welcome to the Pokete-Center",
102128
"What do you want to do?",
103-
"1: See your full deck\n 2: Heal all your Poketes\n 3: Cuddle with the Poketes",
104129
],
105-
passthrough=True,
106130
)
107-
while True:
108-
action, _ = get_action()
109-
if action.triggers(Action.ACT_1):
110-
while "__fallback__" in [p.identifier for p in ob.pokes]:
111-
ob.pokes.pop(
112-
[p.identifier for p in ob.pokes].index("__fallback__")
113-
)
131+
132+
match self.menu(self.ctx)[0]:
133+
case 0:
134+
self.__normalize_pokes(ob)
114135
ob.balls_label_rechar()
115136
deck.deck(self.ctx, len(ob.pokes))
116-
break
117-
elif action.triggers(Action.ACT_2):
137+
case 1:
118138
ob.heal()
119139
time.sleep(SPEED_OF_TIME * 0.5)
120140
mvp.movemap.text(
@@ -123,10 +143,33 @@ def action(self, ob):
123143
3,
124144
["...", "Your Poketes are now healed!"],
125145
)
126-
break
127-
elif action.triggers(Action.CANCEL, Action.ACT_3):
128-
break
129-
loops.std(self.ctx)
146+
case 2:
147+
self.__normalize_pokes(ob)
148+
if ob.pokes:
149+
selected_idx = deck.deck(
150+
self.ctx,
151+
len(ob.pokes),
152+
label="Choose a Pokete to cuddle",
153+
in_fight=True,
154+
)
155+
if selected_idx is not None:
156+
poke = ob.pokes[selected_idx]
157+
message = random.choice(CUDDLE_MESSAGES).format(
158+
name=poke.name
159+
)
160+
mvp.movemap.text(
161+
self.ctx,
162+
mvp.movemap.bmap.inner.x - mvp.movemap.x + 8,
163+
3,
164+
["...", message],
165+
)
166+
else:
167+
mvp.movemap.text(
168+
self.ctx,
169+
mvp.movemap.bmap.inner.x - mvp.movemap.x + 8,
170+
3,
171+
["You don't have any Poketes to cuddle with!"],
172+
)
130173
mvp.movemap.full_show(init=True)
131174

132175

src/pokete/classes/movemap.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def assure_distance(self, _x: int, _y: int, width: int, height: int):
100100
self.show()
101101
time.sleep(SPEED_OF_TIME * 0.045)
102102

103-
def text(self, ctx: Context, _x, _y, inp_arr, passthrough=False):
103+
def text(self, ctx: Context, _x, _y, inp_arr):
104104
"""Shows dialog text on movemap
105105
ARGS:
106106
_x: The message's X
@@ -133,8 +133,7 @@ def text(self, ctx: Context, _x, _y, inp_arr, passthrough=False):
133133
loops.std(ctx.with_overview(self))
134134
self.full_show()
135135
self.multitext.remove()
136-
if not passthrough:
137-
_ev.clear()
136+
_ev.clear()
138137

139138
def resize_view(self):
140139
"""Manages recursive view resizing"""

src/pokete/classes/multiplayer/interactions/context_menu.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ def __call__(self, ctx: Context):
2020
rmtpl = pc_manager.get_interactable(ctx.figure)
2121
if rmtpl is None:
2222
return
23-
match self.menu(ctx):
24-
case "Fight":
23+
match self.menu(ctx)[0]:
24+
case 0:
2525
resp = com_service.request_fight(rmtpl.name)
2626
# ask_ok(ctx, f"{resp}")
2727
if resp:
2828
remote_fight_controller.start(rmtpl.ctx, rmtpl.name)
29-
case "Trade":
29+
case 1:
30+
# TODO impl trading
3031
pass
31-
case "Quit...":
32+
case 2:
3233
pass

src/pokete/classes/multiplayer/pc_manager/pc_manager.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"""Manages remote players"""
2+
23
import logging
34

4-
from .remote_player import RemotePlayer
5-
from ..interactions import movemap_deco
6-
from ...multiplayer.msg.position.update import UpdateDict
75
from ... import ob_maps as obmp
6+
from ...multiplayer.msg.position.update import UpdateDict
7+
from ..interactions import movemap_deco
8+
from .remote_player import RemotePlayer
89

910

1011
class PCManager:
@@ -48,7 +49,8 @@ def remove(self, name):
4849
logging.warning(
4950
"[PCManager] Trying to remove player with name `%s`, "
5051
"but is not present",
51-
name)
52+
name,
53+
)
5254
return
5355
pc.remove()
5456
del self.reg[name]
@@ -62,9 +64,9 @@ def movemap_move(self):
6264
def get_interactable(self, figure) -> RemotePlayer | None:
6365
for _, rmtpl in self.reg.items():
6466
if (
65-
rmtpl.map == figure.map and
66-
(figure.x - 2 <= rmtpl.x <= figure.x + 2) and
67-
(figure.y - 2 <= rmtpl.y <= figure.y + 2)
67+
rmtpl.map == figure.map
68+
and (figure.x - 2 <= rmtpl.x <= figure.x + 2)
69+
and (figure.y - 2 <= rmtpl.y <= figure.y + 2)
6870
):
6971
return rmtpl
7072
return None

src/pokete/classes/multiplayer/pc_manager/remote_player.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import scrap_engine as se
22

33
from pokete.base.color import Color
4-
from ...interactions import Interactor, MultiTextChooseBox
4+
5+
from ...interactions import Interactor
56
from ...landscape import MapInteract
67

78

@@ -14,9 +15,6 @@ def __init__(self, name):
1415
super().__init__("a", "float")
1516
self.name = name
1617
self.name_tag = NameTag(name)
17-
self.interaction_choose_box = MultiTextChooseBox(
18-
["fight", "cancel"],
19-
"Interact")
2018

2119
def add(self, _map, x, y):
2220
"""Adds the player remoteplayer to the map

src/pokete/classes/npcs/npcs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@ def chat(self):
117117
return
118118
while True:
119119
self.text(q_a.q)
120-
while get_action() is None:
120+
while get_action()[0] is None:
121121
loops.std(self.ctx)
122122
if q_a.a == {}:
123123
break
124124
q_a = q_a.a[
125-
MultiTextChooseBox(list(q_a.a.keys()), "Answer")(self.ctx)
125+
MultiTextChooseBox(list(q_a.a.keys()), "Answer")(self.ctx)[1]
126126
]
127127

128128

0 commit comments

Comments
 (0)