|
Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
|
The Poke-mart / Game Corner "market" model – buy and sell with a cart. More...
#include <itemmarketmodel.h>
Public Types | |
| enum | ItemRoles { NameRole = Qt::UserRole + 1 , InStockCountRole , CanSellRole , ItemWorthRole , WhichTypeRole , StackCountRole , OnCartLeftRole , CartCountRole , CartWorthRole , TotalStackCountRole , TotalWorthRole , CanCheckoutRole , ValidItemRole , ExcludeItemRole , MoneyLeftRole , BuyModeRole , MoneyCurrencyRole , ViewTagRole , CartSignRole , MoneyDirRole , InfoRole } |
| Columns (mapped in roleNames()); comments describe each. More... | |
| enum | { SelBuyMoney = 0 , SelBuyCoins , SelSellMoney , SelSellCoins } |
| The four combined modes (returned by whichMode()). More... | |
| enum | { ViewBuy = 0 , ViewSell = 1 } |
| Left-list view tags for the unified buy+sell list (see viewTag). More... | |
Public Member Functions | |
| ItemMarketModel (ItemStorageBox *itemBag, ItemStorageBox *itemStorage, PlayerBasics *basics, Router *router, PlayerPokemon *playerPokemon, Storage *storage, SaveFile *file) | |
| virtual int | rowCount (const QModelIndex &parent) const override |
| Row count. | |
| virtual QVariant | data (const QModelIndex &index, int role) const override |
| Row+role value. | |
| virtual QHash< int, QByteArray > | roleNames () const override |
| Role -> QML name. | |
| bool | setData (const QModelIndex &index, const QVariant &value, int role) override |
| Edit a row (cart count). | |
| int | totalCartWorth () |
| int | totalCartCount () |
| int | whichMode () |
| int | moneyStart () |
| int | moneyLeftover () |
| bool | anyNotEnoughSpace () |
| bool | canAnyCheckout () |
| int | exchangeMoneyStart () |
| int | exchangeMoneyAfter () |
| int | exchangeCoinsStart () |
| int | exchangeCoinsAfter () |
| int | exchangeBuyRate () |
| int | exchangeSellRate () |
| int | exchangeNet () |
| +N buying N coins / -N selling N coins. | |
| void | exchangeAdjust (int deltaCoins) |
| Nudge the net (+Coins = +1, +Money = -1). | |
| void | onReUpdateValues () |
| Recompute the derived totals. | |
| bool | vendorListItem (ItemDBEntry *el) |
Should el appear in the store list (has a price here)? | |
| bool | buyableInGame (ItemDBEntry *el) const |
Is el sold by a reachable Gen-1 vendor (Normal vs Special)? | |
| bool | isVendingItem (ItemDBEntry *el) const |
Is el a Celadon vending-machine drink (its own group)? | |
| void | clearList () |
| Empty the row cache. | |
| void | buildList () |
| Build the rows for the current mode. | |
| void | buildPlayerItemList () |
| Build rows from the player's items. | |
| void | buildMartItemList () |
| Build rows from the store stock. | |
| void | buildExchangeList () |
| Build the money<->coins exchange rows (both directions). | |
| void | pageOpening (QString path) |
| Hook when the market page opens. | |
| void | checkout () |
| Apply the cart transaction to the save. | |
| void | reUpdateAll () |
| Rebuild + recompute everything. | |
Public Attributes | |
| QVector< ItemMarketEntry * > | itemListCache |
| The current market rows. | |
| bool | isBuyMode = true |
| bool | isMoneyCurrency = true |
| bool | isExchangeMode = false |
| ItemStorageBox * | itemBag = nullptr |
| The player's bag. | |
| ItemStorageBox * | itemStorage = nullptr |
| The PC item box. | |
| Router * | router = nullptr |
| For page hooks. | |
| PlayerBasics * | basics = nullptr |
| Player money/coins. | |
| PlayerPokemon * | playerPokemon = nullptr |
| Party (for received Pokemon). | |
| Storage * | storage = nullptr |
| PC storage (for received Pokemon). | |
| SaveFile * | file = nullptr |
| The live save. | |
The Poke-mart / Game Corner "market" model – buy and sell with a cart.
The most complex model in the app. It presents a unified buy/sell market with a cart, switching between four modes (buy/sell x money/coins) and between viewing the player's items and the store's stock. Rows are ItemMarketEntry objects (a small class hierarchy – player item, store item, money, message, Game Corner Pokemon). It computes cart totals, leftover money, and space checks, and applies the transaction in checkout(). Exposed as brg.marketModel.
Definition at line 44 of file itemmarketmodel.h.
| anonymous enum |
The four combined modes (returned by whichMode()).
| Enumerator | |
|---|---|
| SelBuyMoney | |
| SelBuyCoins | |
| SelSellMoney | |
| SelSellCoins | |
Definition at line 146 of file itemmarketmodel.h.
| anonymous enum |
Left-list view tags for the unified buy+sell list (see viewTag).
| Enumerator | |
|---|---|
| ViewBuy | |
| ViewSell | |
Definition at line 154 of file itemmarketmodel.h.
Columns (mapped in roleNames()); comments describe each.
Definition at line 77 of file itemmarketmodel.h.
| ItemMarketModel::ItemMarketModel | ( | ItemStorageBox * | itemBag, |
| ItemStorageBox * | itemStorage, | ||
| PlayerBasics * | basics, | ||
| Router * | router, | ||
| PlayerPokemon * | playerPokemon, | ||
| Storage * | storage, | ||
| SaveFile * | file ) |
Definition at line 45 of file itemmarketmodel.cpp.
References basics, buildList(), SaveFile::dataExpandedChanged(), file, ItemMarketEntry::isBuyMode, isBuyMode, ItemMarketEntry::isMoneyCurrency, isMoneyCurrency, itemBag, itemStorage, onReUpdateValues(), pageOpening(), ItemMarketEntry::player, playerPokemon, reUpdateAll(), router, and storage.
| bool ItemMarketModel::anyNotEnoughSpace | ( | ) |
Definition at line 282 of file itemmarketmodel.cpp.
References itemListCache.
| void ItemMarketModel::buildExchangeList | ( | ) |
Build the money<->coins exchange rows (both directions).
Definition at line 542 of file itemmarketmodel.cpp.
References ItemMarketEntryMoney::DirToCoins, ItemMarketEntryMoney::DirToMoney, and itemListCache.
Referenced by buildList().
| void ItemMarketModel::buildList | ( | ) |
Build the rows for the current mode.
Definition at line 516 of file itemmarketmodel.cpp.
References ItemMarketEntry::activeList, buildExchangeList(), buildMartItemList(), buildPlayerItemList(), clearList(), isExchangeMode, and itemListCache.
Referenced by ItemMarketModel(), pageOpening(), and reUpdateAll().
| void ItemMarketModel::buildMartItemList | ( | ) |
Build rows from the store stock.
Definition at line 584 of file itemmarketmodel.cpp.
References buyableInGame(), GameCornerDB::inst(), ItemsDB::inst(), isMoneyCurrency, isVendingItem(), itemBag, itemListCache, itemStorage, playerPokemon, storage, vendorListItem(), and ViewBuy.
Referenced by buildList().
| void ItemMarketModel::buildPlayerItemList | ( | ) |
Build rows from the player's items.
Definition at line 551 of file itemmarketmodel.cpp.
References itemBag, itemListCache, itemStorage, and ViewSell.
Referenced by buildList().
| bool ItemMarketModel::buyableInGame | ( | ItemDBEntry * | el | ) | const |
Is el sold by a reachable Gen-1 vendor (Normal vs Special)?
Definition at line 428 of file itemmarketmodel.cpp.
References ItemDBEntry::getInd().
Referenced by buildMartItemList().
| bool ItemMarketModel::canAnyCheckout | ( | ) |
Definition at line 300 of file itemmarketmodel.cpp.
References itemListCache.
| void ItemMarketModel::checkout | ( | ) |
Apply the cart transaction to the save.
Definition at line 494 of file itemmarketmodel.cpp.
References itemListCache, and reUpdateAll().
| void ItemMarketModel::clearList | ( | ) |
Empty the row cache.
Definition at line 508 of file itemmarketmodel.cpp.
References itemListCache.
Referenced by buildList().
|
overridevirtual |
Row+role value.
Definition at line 101 of file itemmarketmodel.cpp.
References BuyModeRole, CanCheckoutRole, CanSellRole, CartCountRole, CartSignRole, CartWorthRole, ExcludeItemRole, InfoRole, InStockCountRole, isBuyMode, isMoneyCurrency, itemListCache, ItemWorthRole, MoneyCurrencyRole, MoneyDirRole, NameRole, OnCartLeftRole, StackCountRole, TotalStackCountRole, TotalWorthRole, ValidItemRole, ViewTagRole, and WhichTypeRole.
| void ItemMarketModel::exchangeAdjust | ( | int | deltaCoins | ) |
Nudge the net (+Coins = +1, +Money = -1).
Definition at line 371 of file itemmarketmodel.cpp.
References itemListCache, ItemMarketEntry::onCart, and ItemMarketEntryMoney::onCartLeft().
| int ItemMarketModel::exchangeBuyRate | ( | ) |
Definition at line 347 of file itemmarketmodel.cpp.
References GameCornerDB::getBuyPrice(), and GameCornerDB::inst().
| int ItemMarketModel::exchangeCoinsAfter | ( | ) |
Definition at line 334 of file itemmarketmodel.cpp.
References basics, and itemListCache.
| int ItemMarketModel::exchangeCoinsStart | ( | ) |
Definition at line 313 of file itemmarketmodel.cpp.
References basics.
| int ItemMarketModel::exchangeMoneyAfter | ( | ) |
Definition at line 321 of file itemmarketmodel.cpp.
References basics, and itemListCache.
| int ItemMarketModel::exchangeMoneyStart | ( | ) |
Definition at line 308 of file itemmarketmodel.cpp.
References basics.
| int ItemMarketModel::exchangeNet | ( | ) |
+N buying N coins / -N selling N coins.
Definition at line 359 of file itemmarketmodel.cpp.
References itemListCache.
| int ItemMarketModel::exchangeSellRate | ( | ) |
Definition at line 352 of file itemmarketmodel.cpp.
References GameCornerDB::getSellPrice(), and GameCornerDB::inst().
| bool ItemMarketModel::isVendingItem | ( | ItemDBEntry * | el | ) | const |
Is el a Celadon vending-machine drink (its own group)?
Definition at line 488 of file itemmarketmodel.cpp.
References ItemDBEntry::getInd().
Referenced by buildMartItemList().
| int ItemMarketModel::moneyLeftover | ( | ) |
Definition at line 273 of file itemmarketmodel.cpp.
References itemListCache, and moneyStart().
| int ItemMarketModel::moneyStart | ( | ) |
Definition at line 265 of file itemmarketmodel.cpp.
References basics, and isMoneyCurrency.
Referenced by moneyLeftover().
| void ItemMarketModel::onReUpdateValues | ( | ) |
Recompute the derived totals.
Definition at line 403 of file itemmarketmodel.cpp.
References itemListCache.
Referenced by ItemMarketModel().
| void ItemMarketModel::pageOpening | ( | QString | path | ) |
Hook when the market page opens.
Definition at line 693 of file itemmarketmodel.cpp.
References buildList().
Referenced by ItemMarketModel().
| void ItemMarketModel::reUpdateAll | ( | ) |
Rebuild + recompute everything.
Definition at line 686 of file itemmarketmodel.cpp.
References buildList().
Referenced by checkout(), and ItemMarketModel().
|
overridevirtual |
Role -> QML name.
Definition at line 171 of file itemmarketmodel.cpp.
References BuyModeRole, CanCheckoutRole, CanSellRole, CartCountRole, CartSignRole, CartWorthRole, ExcludeItemRole, InfoRole, InStockCountRole, ItemWorthRole, MoneyCurrencyRole, MoneyDirRole, MoneyLeftRole, NameRole, OnCartLeftRole, StackCountRole, TotalStackCountRole, TotalWorthRole, ValidItemRole, ViewTagRole, and WhichTypeRole.
|
overridevirtual |
|
override |
Edit a row (cart count).
Definition at line 200 of file itemmarketmodel.cpp.
References CartCountRole, and itemListCache.
| int ItemMarketModel::totalCartCount | ( | ) |
Definition at line 232 of file itemmarketmodel.cpp.
References itemListCache.
| int ItemMarketModel::totalCartWorth | ( | ) |
Definition at line 224 of file itemmarketmodel.cpp.
References itemListCache.
| bool ItemMarketModel::vendorListItem | ( | ItemDBEntry * | el | ) |
Should el appear in the store list (has a price here)?
Definition at line 408 of file itemmarketmodel.cpp.
References ItemDBEntry::buyPriceCoins(), ItemDBEntry::buyPriceMoney(), ItemDBEntry::canSell(), ItemDBEntry::isGameCornerExclusive(), and isMoneyCurrency.
Referenced by buildMartItemList().
| int ItemMarketModel::whichMode | ( | ) |
Definition at line 251 of file itemmarketmodel.cpp.
References isBuyMode, isMoneyCurrency, SelBuyCoins, SelBuyMoney, SelSellCoins, and SelSellMoney.
| PlayerBasics* ItemMarketModel::basics = nullptr |
Player money/coins.
Definition at line 234 of file itemmarketmodel.h.
Referenced by exchangeCoinsAfter(), exchangeCoinsStart(), exchangeMoneyAfter(), exchangeMoneyStart(), ItemMarketModel(), and moneyStart().
| SaveFile* ItemMarketModel::file = nullptr |
| bool ItemMarketModel::isBuyMode = true |
Definition at line 218 of file itemmarketmodel.h.
Referenced by data(), ItemMarketModel(), and whichMode().
| bool ItemMarketModel::isExchangeMode = false |
Definition at line 228 of file itemmarketmodel.h.
Referenced by buildList().
| bool ItemMarketModel::isMoneyCurrency = true |
Definition at line 223 of file itemmarketmodel.h.
Referenced by buildMartItemList(), data(), ItemMarketModel(), moneyStart(), vendorListItem(), and whichMode().
| ItemStorageBox* ItemMarketModel::itemBag = nullptr |
The player's bag.
Definition at line 231 of file itemmarketmodel.h.
Referenced by buildMartItemList(), buildPlayerItemList(), and ItemMarketModel().
| QVector<ItemMarketEntry*> ItemMarketModel::itemListCache |
The current market rows.
Definition at line 214 of file itemmarketmodel.h.
Referenced by anyNotEnoughSpace(), buildExchangeList(), buildList(), buildMartItemList(), buildPlayerItemList(), canAnyCheckout(), checkout(), clearList(), data(), exchangeAdjust(), exchangeCoinsAfter(), exchangeMoneyAfter(), exchangeNet(), moneyLeftover(), onReUpdateValues(), rowCount(), setData(), totalCartCount(), and totalCartWorth().
| ItemStorageBox* ItemMarketModel::itemStorage = nullptr |
The PC item box.
Definition at line 232 of file itemmarketmodel.h.
Referenced by buildMartItemList(), buildPlayerItemList(), and ItemMarketModel().
| PlayerPokemon* ItemMarketModel::playerPokemon = nullptr |
Party (for received Pokemon).
Definition at line 235 of file itemmarketmodel.h.
Referenced by buildMartItemList(), and ItemMarketModel().
| Router* ItemMarketModel::router = nullptr |
| Storage* ItemMarketModel::storage = nullptr |
PC storage (for received Pokemon).
Definition at line 236 of file itemmarketmodel.h.
Referenced by buildMartItemList(), and ItemMarketModel().