Skip to content
Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
ItemExchangeModel Class Reference

Item<->item exchange for the Market's Exchange tab (Healing + Custom). More...

#include <itemexchangemodel.h>

Inheritance diagram for ItemExchangeModel:
Collaboration diagram for ItemExchangeModel:

Public Member Functions

 ItemExchangeModel (ItemStorageBox *bag, ItemStorageBox *storage, PlayerBasics *basics)
int itemAInd () const
int itemBInd () const
void setItemAInd (int v)
void setItemBInd (int v)
int net () const
int revision () const
bool valid () const
QString aName () const
QString bName () const
int aBuy () const
int bBuy () const
int aStart () const
int bStart () const
int moneyStart () const
int aAfter () const
int bAfter () const
int moneyAfter () const
int giveFor (int dir, int steps) const
 How many of the OTHER item steps of this direction consume, priced as ONE whole trade rather than steps separate ones: dir > 0 gains A (consuming B), dir < 0 gains B (consuming A).
int refundFor (int dir, int steps) const
 The leftover value of steps in direction dir, refunded as money – i.e.
bool canAddA () const
bool canAddB () const
QVariantList sourceItems (bool healingOnly, int excludeInd) const
 LEFT list – what you can GIVE: items you actually own (amount > 0) and that are exchangeable (buy price > 0), optionally healing-only, excluding excludeInd.
QVariantList targetItems (bool healingOnly, int excludeInd) const
 RIGHT list – what you can GET: EVERY exchangeable item (owned or not), optionally healing-only, excluding excludeInd.
bool canGainTarget (int bInd) const
 Can we gain at least one of item bInd right now, paying with the selected source?
void pickDefaults (bool healingOnly)
 Choose a sensible starting pair.
void adjust (int dir)
 +1 = one gained-A step, -1 = one gained-B step (gated).
void reset ()
 Clear the net axis.
void refresh ()
 Re-read counts/money + re-emit (tab open / external edit).
void checkout ()
 Apply the previewed trade to the save.
protected::void selectionChanged ()
 A or B selection changed.
void changed ()
 Any derived value changed.

Static Public Attributes

static constexpr int MoneyCap = 999999
 < Both picked, distinct, both have a buy price.
static constexpr int StackCap = 99
 Gen 1 per-stack cap.

Detailed Description

Item<->item exchange for the Market's Exchange tab (Healing + Custom).

Powers the two item-trading sub-tabs. Two items are selected (A and B); a single net axis (net) drives the trade the same way the money<->coins converter drives one coin axis. Each "+A" step gains one more of item A; the WHOLE trade is then priced as one transaction – the minimum whole number of item B whose BUY value covers the total value being bought, with only the single leftover refunded as money (money only ever goes up). "+B" is the mirror. Rounding up the TOTAL, not each step, is the point: 3 Fresh Water (₽600) is paid for by exactly 2 Potions (₽600) with NO refund, where pricing each Fresh Water on its own would have wasted 3 Potions and handed back ₽300. Everything is previewed (the after counts + money) and only written on checkout(). Values come from each item's money buy price; the traded items are counted across the bag + PC storage combined.

The two dropdowns are asymmetric: the LEFT one is what you GIVE, so it lists the items you actually own (sourceItems); the RIGHT one is what you GET, so it lists EVERY exchangeable item (targetItems) with the ones your stock can't cover flagged unaffordable and greyed. That greying is what keeps a selected pair always tradeable in at least one direction – the two "+" buttons are never both disabled. Healing filters both lists to healing/drink items and starts on Potion <=> Fresh Water (pickDefaults). Exposed as brg.itemExchangeModel.

See also
ItemStorageBox (addAmount/removeAmount/capacityForInd), ItemMarketModel (the money<->coins exchange this mirrors).

Definition at line 50 of file itemexchangemodel.h.

Constructor & Destructor Documentation

◆ ItemExchangeModel()

ItemExchangeModel::ItemExchangeModel ( ItemStorageBox * bag,
ItemStorageBox * storage,
PlayerBasics * basics )

Member Function Documentation

◆ aAfter()

int ItemExchangeModel::aAfter ( ) const
inline

Definition at line 104 of file itemexchangemodel.h.

◆ aBuy()

int ItemExchangeModel::aBuy ( ) const
inline

Definition at line 98 of file itemexchangemodel.h.

Referenced by giveFor(), refundFor(), and valid().

◆ adjust()

void ItemExchangeModel::adjust ( int dir)

+1 = one gained-A step, -1 = one gained-B step (gated).

Definition at line 276 of file itemexchangemodel.cpp.

References canAddA(), and canAddB().

◆ aName()

QString ItemExchangeModel::aName ( ) const
inline

Definition at line 96 of file itemexchangemodel.h.

◆ aStart()

int ItemExchangeModel::aStart ( ) const
inline

Definition at line 101 of file itemexchangemodel.h.

◆ bAfter()

int ItemExchangeModel::bAfter ( ) const
inline

Definition at line 105 of file itemexchangemodel.h.

◆ bBuy()

int ItemExchangeModel::bBuy ( ) const
inline

Definition at line 99 of file itemexchangemodel.h.

Referenced by giveFor(), refundFor(), and valid().

◆ bName()

QString ItemExchangeModel::bName ( ) const
inline

Definition at line 97 of file itemexchangemodel.h.

◆ bStart()

int ItemExchangeModel::bStart ( ) const
inline

Definition at line 102 of file itemexchangemodel.h.

◆ canAddA()

bool ItemExchangeModel::canAddA ( ) const
inline

Definition at line 120 of file itemexchangemodel.h.

References valid().

Referenced by adjust().

◆ canAddB()

bool ItemExchangeModel::canAddB ( ) const
inline

Definition at line 121 of file itemexchangemodel.h.

References valid().

Referenced by adjust().

◆ canGainTarget()

bool ItemExchangeModel::canGainTarget ( int bInd) const

Can we gain at least one of item bInd right now, paying with the selected source?

Definition at line 358 of file itemexchangemodel.cpp.

References MoneyCap, and moneyStart().

Referenced by pickDefaults(), and targetItems().

◆ changed()

void ItemExchangeModel::changed ( )

Any derived value changed.

◆ checkout()

void ItemExchangeModel::checkout ( )

Apply the previewed trade to the save.

Definition at line 433 of file itemexchangemodel.cpp.

References giveFor(), MoneyCap, refundFor(), and valid().

◆ giveFor()

int ItemExchangeModel::giveFor ( int dir,
int steps ) const

How many of the OTHER item steps of this direction consume, priced as ONE whole trade rather than steps separate ones: dir > 0 gains A (consuming B), dir < 0 gains B (consuming A).

Because the total is what's rounded up, a trade that divides evenly costs nothing extra – 3 Fresh Water (₽600) is exactly 2 Potions (₽600), not 3 Potions with three separate leftovers.

Definition at line 186 of file itemexchangemodel.cpp.

References aBuy(), bBuy(), and valid().

Referenced by checkout(), and refundFor().

◆ itemAInd()

int ItemExchangeModel::itemAInd ( ) const
inline

Definition at line 87 of file itemexchangemodel.h.

◆ itemBInd()

int ItemExchangeModel::itemBInd ( ) const
inline

Definition at line 88 of file itemexchangemodel.h.

◆ moneyAfter()

int ItemExchangeModel::moneyAfter ( ) const
inline

Definition at line 106 of file itemexchangemodel.h.

◆ moneyStart()

int ItemExchangeModel::moneyStart ( ) const

Definition at line 169 of file itemexchangemodel.cpp.

Referenced by canGainTarget().

◆ net()

int ItemExchangeModel::net ( ) const
inline

Definition at line 92 of file itemexchangemodel.h.

◆ pickDefaults()

void ItemExchangeModel::pickDefaults ( bool healingOnly)

Choose a sensible starting pair.

Healing prefers a potion-family source the player owns (Potion > Super > Hyper > Max > Full Restore, then any healing item) and Fresh Water as the target – i.e. Potion <=> Fresh Water by default. Always lands on a pair with a usable "+" when one exists.

Definition at line 377 of file itemexchangemodel.cpp.

References canGainTarget(), selectionChanged(), sourceItems(), and targetItems().

◆ refresh()

void ItemExchangeModel::refresh ( )

Re-read counts/money + re-emit (tab open / external edit).

Definition at line 295 of file itemexchangemodel.cpp.

Referenced by ItemExchangeModel().

◆ refundFor()

int ItemExchangeModel::refundFor ( int dir,
int steps ) const

The leftover value of steps in direction dir, refunded as money – i.e.

giveFor() * (given item's buy price) minus the value actually being bought. Zero when the trade divides evenly (nothing to refund).

Definition at line 194 of file itemexchangemodel.cpp.

References aBuy(), bBuy(), giveFor(), and valid().

Referenced by checkout().

◆ reset()

void ItemExchangeModel::reset ( )

Clear the net axis.

Definition at line 287 of file itemexchangemodel.cpp.

◆ revision()

int ItemExchangeModel::revision ( ) const
inline

Definition at line 93 of file itemexchangemodel.h.

◆ selectionChanged()

protected::void ItemExchangeModel::selectionChanged ( )

A or B selection changed.

Referenced by pickDefaults(), setItemAInd(), and setItemBInd().

◆ setItemAInd()

void ItemExchangeModel::setItemAInd ( int v)

Definition at line 256 of file itemexchangemodel.cpp.

References selectionChanged().

◆ setItemBInd()

void ItemExchangeModel::setItemBInd ( int v)

Definition at line 266 of file itemexchangemodel.cpp.

References selectionChanged().

◆ sourceItems()

QVariantList ItemExchangeModel::sourceItems ( bool healingOnly,
int excludeInd ) const

LEFT list – what you can GIVE: items you actually own (amount > 0) and that are exchangeable (buy price > 0), optionally healing-only, excluding excludeInd.

Returns [{name, ind}] sorted by display name.

Definition at line 306 of file itemexchangemodel.cpp.

Referenced by pickDefaults().

◆ targetItems()

QVariantList ItemExchangeModel::targetItems ( bool healingOnly,
int excludeInd ) const

RIGHT list – what you can GET: EVERY exchangeable item (owned or not), optionally healing-only, excluding excludeInd.

Each entry carries an affordable flag – false when your current source stock can't cover even one of it (or there's no room / money would overflow). The dropdown greys those, which is what guarantees the selected pair always has at least one usable "+" (never both disabled). Returns [{name, ind, affordable}] sorted by display name.

Definition at line 334 of file itemexchangemodel.cpp.

References canGainTarget().

Referenced by pickDefaults().

◆ valid()

bool ItemExchangeModel::valid ( ) const

Definition at line 176 of file itemexchangemodel.cpp.

References aBuy(), and bBuy().

Referenced by canAddA(), canAddB(), checkout(), giveFor(), and refundFor().

Member Data Documentation

◆ MoneyCap

int ItemExchangeModel::MoneyCap = 999999
staticconstexpr

< Both picked, distinct, both have a buy price.

Net axis (+N = N gained-A steps, -N = gained-B). < Item A display name. Item B display name. Item A buy price (money). Item B buy price (money). < Item A owned (bag+storage) before. Item A owned after the previewed trade. Item B owned before. Item B owned after. Money before. Money after (refunds only). < "+A" enabled (one more gained-A step is legal). "+B" enabled. Bumped on every change. sourceItems()/targetItems() are Q_INVOKABLE calls, so a QML model: binding on them has no dependency to re-run on – read this in the binding and the lists (and their affordable flags) rebuild whenever the state moves. Gen 1 money cap.

Definition at line 82 of file itemexchangemodel.h.

Referenced by canGainTarget(), and checkout().

◆ StackCap

int ItemExchangeModel::StackCap = 99
staticconstexpr

Gen 1 per-stack cap.

Definition at line 83 of file itemexchangemodel.h.


The documentation for this class was generated from the following files: