Skip to content
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
4 changes: 4 additions & 0 deletions myning/changelog.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
- name: Disable Purchase Confirmation
description: Add option to disable purchase confirmation screen.
date: 09-08-2023

- name: Research Species Stats
description: Ever wanted to know the EXACT stats of a species? It's possible now thanks to research!
date: 08-30-23
Expand Down
34 changes: 31 additions & 3 deletions myning/chapters/base_store.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from abc import ABC, abstractmethod
from functools import partial
from typing import TYPE_CHECKING

from rich.text import Text

from myning.chapters import Option, PickArgs, main_menu
from myning.chapters import DynamicArgs, Option, PickArgs, main_menu
from myning.config import UPGRADES
from myning.objects.buying_option import BuyingOption
from myning.objects.equipment import EQUIPMENT_TYPES
Expand All @@ -15,6 +16,9 @@
from myning.utilities.file_manager import FileManager
from myning.utilities.formatter import Formatter

if TYPE_CHECKING:
from myning.tui.chapter import ChapterWidget

player = Player()
stats = Stats()
settings = Settings()
Expand Down Expand Up @@ -117,6 +121,9 @@ def confirm_buy(self, item: Item):
message="Not enough gold!",
options=[Option("Bummer!", self.pick_buy)],
)
if not settings.purchase_confirmation:
self.buy(item)
return self.pick_preserve_cursor(self.pick_buy())
return PickArgs(
message=f"Are you sure you want to buy {item} for {Formatter.gold(item.value)}?", # pylint: disable=line-too-long
options=[
Expand All @@ -134,7 +141,11 @@ def buy(self, item: Item):
elif item.type in EQUIPMENT_TYPES:
stats.increment_int_stat(IntegerStatKeys.ARMOR_PURCHASED)
FileManager.multi_save(player, item, stats, inventory)
return self.enter()

if settings.purchase_confirmation:
return self.enter()

return self.pick_buy()

def confirm_multi_buy(self, items: list[Item]):
assert self.buying_option
Expand All @@ -144,6 +155,9 @@ def confirm_multi_buy(self, items: list[Item]):
message="Not enough gold!",
options=[Option("Bummer!", self.pick_buy)],
)
if not settings.purchase_confirmation:
self.multi_buy(items)
return self.pick_preserve_cursor(self.pick_buy())
return PickArgs(
message=f"Are you sure you want to buy {self.buying_option.name} for {Formatter.gold(cost)}?", # pylint: disable=line-too-long
options=[
Expand All @@ -158,7 +172,9 @@ def multi_buy(self, items: list[Item]):
inventory.add_items(items)
self.remove_items(*items)
FileManager.multi_save(player, *items, inventory)
return self.enter()
if settings.purchase_confirmation:
return self.enter()
return self.pick_buy()

def hint_symbol(self, item: Item) -> str:
if item.type not in EQUIPMENT_TYPES:
Expand All @@ -185,3 +201,15 @@ def is_useful_item(self, item: Item):
if equipped is None or item.main_affect > equipped.main_affect:
return True
return False

def pick_preserve_cursor(self, args: PickArgs):
def callback(chapter: "ChapterWidget"):
highlighted_index = chapter.option_table.cursor_row
chapter.pick(args)
last_index = len(chapter.option_table.rows) - 1
if highlighted_index >= last_index:
chapter.option_table.move_cursor(row=last_index - 1)
else:
chapter.option_table.move_cursor(row=highlighted_index)

return DynamicArgs(callback)
21 changes: 21 additions & 0 deletions myning/chapters/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def enter():
options = [
Option(["Minigames", f"({settings.mini_games_status})"], toggle_minigames),
Option(["Compact Mode", f"({settings.compact_status})"], toggle_compact_mode),
Option(
["Purchase Confirmation", f"({settings.purchase_confirmation_status})"],
toggle_purchase_confirmation,
),
]

if player.has_upgrade("sort_by_value"):
Expand Down Expand Up @@ -63,3 +67,20 @@ def toggle_sort_order():
message=f"Sort Order is now {settings.sort_order}",
options=[Option("Done", enter)],
)


@confirm(
lambda: f"Are you sure you want to {'disable' if settings.purchase_confirmation else 'enable'} "
"purchase confirmation?\n"
+ Formatter.locked(
"If disabled, you will not be prompted to confirm before purchasing items from a store and will stay on the items screen."
),
enter,
)
def toggle_purchase_confirmation():
settings.toggle_purchase_confirmation()
FileManager.save(settings)
return PickArgs(
message=f"Purchase confirmation is now {settings.purchase_confirmation_status}",
options=[Option("Done", enter)],
)
10 changes: 10 additions & 0 deletions myning/objects/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ def __init__(
hard_combat_disabled=True,
compact_mode=False,
sort_order=SortOrder.TYPE,
purchase_confirmation=True,
) -> None:
self.army_columns = army_columns
self.mini_games_disabled = mini_games_disabled
self.hard_combat_disabled = hard_combat_disabled
self.compact_mode = compact_mode
self.sort_order: SortOrder = sort_order
self.purchase_confirmation = purchase_confirmation

@classmethod
def from_dict(cls, attrs: dict):
Expand All @@ -43,6 +45,7 @@ def to_dict(self) -> dict:
"hard_combat_disabled": self.hard_combat_disabled,
"compact_mode": self.compact_mode,
"sort_order": self.sort_order,
"purchase_confirmation": self.purchase_confirmation,
}

@classmethod
Expand All @@ -66,6 +69,9 @@ def toggle_compact_mode(self):
def toggle_sort_order(self):
self.sort_order = SortOrder.TYPE if self.sort_order == SortOrder.VALUE else SortOrder.VALUE

def toggle_purchase_confirmation(self):
self.purchase_confirmation = not self.purchase_confirmation

@property
def mini_games_status(self) -> str:
return "disabled" if self.mini_games_disabled else "enabled"
Expand All @@ -77,3 +83,7 @@ def hard_combat_status(self) -> str:
@property
def compact_status(self) -> str:
return "enabled" if self.compact_mode else "disabled"

@property
def purchase_confirmation_status(self) -> str:
return "enabled" if self.purchase_confirmation else "disabled"