mirror of
https://github.com/rr-/pq-cli.git
synced 2026-09-29 06:44:00 -06:00
ui: add plot view
This commit is contained in:
+2
-1
@@ -239,7 +239,7 @@ class PlotTask(RegularTask):
|
|||||||
|
|
||||||
|
|
||||||
class Player(SignalMixin):
|
class Player(SignalMixin):
|
||||||
signals = ["new_task", "level_up"]
|
signals = ["new_task", "level_up", "complete_act"]
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@@ -521,6 +521,7 @@ class Simulation:
|
|||||||
if self.player.act > 1:
|
if self.player.act > 1:
|
||||||
self.player.win_item()
|
self.player.win_item()
|
||||||
self.player.win_equipment()
|
self.player.win_equipment()
|
||||||
|
self.player.emit("complete_act")
|
||||||
|
|
||||||
def complete_quest(self) -> None:
|
def complete_quest(self) -> None:
|
||||||
self.player.quest_book.quest_bar.reset(50 + random.below_low(1000))
|
self.player.quest_book.quest_bar.reset(50 + random.below_low(1000))
|
||||||
|
|||||||
+51
-1
@@ -4,10 +4,11 @@ import typing as T
|
|||||||
import urwid
|
import urwid
|
||||||
|
|
||||||
from pqcli.config import EquipmentType, StatType
|
from pqcli.config import EquipmentType, StatType
|
||||||
from pqcli.lingo import to_roman
|
from pqcli.lingo import act_name, to_roman
|
||||||
from pqcli.mechanic import InventoryItem, Player, Simulation, Spell
|
from pqcli.mechanic import InventoryItem, Player, Simulation, Spell
|
||||||
from pqcli.ui.custom_line_box import CustomLineBox
|
from pqcli.ui.custom_line_box import CustomLineBox
|
||||||
from pqcli.ui.custom_progress_bar import CustomProgressBar
|
from pqcli.ui.custom_progress_bar import CustomProgressBar
|
||||||
|
from pqcli.ui.read_only_check_box import ReadOnlyCheckBox
|
||||||
|
|
||||||
|
|
||||||
class CharacterSheetView(CustomLineBox):
|
class CharacterSheetView(CustomLineBox):
|
||||||
@@ -202,6 +203,53 @@ class InventoryView(urwid.Pile):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
class PlotView(urwid.Pile):
|
||||||
|
cutoff = 100
|
||||||
|
|
||||||
|
def __init__(self, player: Player) -> None:
|
||||||
|
self.player = player
|
||||||
|
|
||||||
|
self.list_box = urwid.ListBox([])
|
||||||
|
self.plot_bar = CustomProgressBar()
|
||||||
|
|
||||||
|
self.player.connect("complete_act", self.sync_act_add)
|
||||||
|
self.player.plot_bar.connect("change", self.sync_position)
|
||||||
|
self.sync_acts()
|
||||||
|
self.sync_position()
|
||||||
|
|
||||||
|
super().__init__(
|
||||||
|
[
|
||||||
|
CustomLineBox(self.list_box, title="Plot Development"),
|
||||||
|
(1, urwid.Filler(self.plot_bar)),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
def sync_acts(self) -> None:
|
||||||
|
del self.list_box.body[:]
|
||||||
|
for act_number in range(
|
||||||
|
max(0, self.player.act - self.cutoff), self.player.act
|
||||||
|
):
|
||||||
|
self.list_box.body.append(
|
||||||
|
ReadOnlyCheckBox(act_name(act_number), state=True)
|
||||||
|
)
|
||||||
|
self.list_box.body.append(
|
||||||
|
ReadOnlyCheckBox(act_name(self.player.act), state=False)
|
||||||
|
)
|
||||||
|
|
||||||
|
def sync_act_add(self):
|
||||||
|
del self.list_box.body[: -self.cutoff]
|
||||||
|
if self.list_box.body:
|
||||||
|
self.list_box.body[-1].set_state(True)
|
||||||
|
self.list_box.body.append(
|
||||||
|
ReadOnlyCheckBox(act_name(self.player.act), state=False)
|
||||||
|
)
|
||||||
|
self.list_box.set_focus(len(self.list_box.body) - 1)
|
||||||
|
|
||||||
|
def sync_position(self) -> None:
|
||||||
|
self.plot_bar.set_completion(self.player.plot_bar.position)
|
||||||
|
self.plot_bar.set_max(self.player.plot_bar.max_)
|
||||||
|
|
||||||
|
|
||||||
class TaskView(urwid.Pile):
|
class TaskView(urwid.Pile):
|
||||||
def __init__(self, player: Player) -> None:
|
def __init__(self, player: Player) -> None:
|
||||||
self.player = player
|
self.player = player
|
||||||
@@ -243,6 +291,7 @@ class GameView(urwid.Pile):
|
|||||||
self.spell_book_view = SpellBookView(player)
|
self.spell_book_view = SpellBookView(player)
|
||||||
self.equipment_view = EquipmentView(player)
|
self.equipment_view = EquipmentView(player)
|
||||||
self.inventory_view = InventoryView(player)
|
self.inventory_view = InventoryView(player)
|
||||||
|
self.plot_view = PlotView(player)
|
||||||
self.task_view = TaskView(player)
|
self.task_view = TaskView(player)
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
@@ -267,6 +316,7 @@ class GameView(urwid.Pile):
|
|||||||
[self.equipment_view, self.inventory_view]
|
[self.equipment_view, self.inventory_view]
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
("weight", 2, urwid.Pile([self.plot_view])),
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
("pack", self.task_view),
|
("pack", self.task_view),
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import urwid
|
||||||
|
|
||||||
|
|
||||||
|
class ReadOnlyCheckBox(urwid.Text):
|
||||||
|
def __init__(self, text, state: bool = False) -> None:
|
||||||
|
self.icons = {
|
||||||
|
key: widget.text for key, widget in urwid.CheckBox.states.items()
|
||||||
|
}
|
||||||
|
self._caption = text
|
||||||
|
|
||||||
|
super().__init__("")
|
||||||
|
|
||||||
|
self.set_state(state)
|
||||||
|
|
||||||
|
def set_state(self, state: bool) -> None:
|
||||||
|
self.set_text(self.icons[state] + " " + self._caption)
|
||||||
Reference in New Issue
Block a user