Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
itemmarketmodel.h
Go to the documentation of this file.
1/*
2 * Copyright 2020 Twilight
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15*/
16#pragma once
17#include <QObject>
18#include <QString>
19#include <QAbstractListModel>
20#include <QVector>
21#include <QVariant>
22
23class ItemStorageBox;
24class Router;
25class PlayerBasics;
26class Storage;
27class PlayerPokemon;
28class ItemMarketEntry;
29class SaveFile;
30class ItemDBEntry;
31
44class ItemMarketModel : public QAbstractListModel
45{
46 Q_OBJECT
47
48 Q_PROPERTY(bool isBuyMode MEMBER isBuyMode NOTIFY isBuyModeChanged)
49 Q_PROPERTY(bool isMoneyCurrency MEMBER isMoneyCurrency NOTIFY isMoneyCurrencyChanged)
50 Q_PROPERTY(bool isExchangeMode MEMBER isExchangeMode NOTIFY isExchangeModeChanged)
51 Q_PROPERTY(int whichMode READ whichMode NOTIFY isAnyChanged)
52
53 // Dual-currency totals for the Exchange receipt (money AND coins both move).
54 Q_PROPERTY(int exchangeMoneyStart READ exchangeMoneyStart NOTIFY reUpdateValues)
55 Q_PROPERTY(int exchangeMoneyAfter READ exchangeMoneyAfter NOTIFY reUpdateValues)
56 Q_PROPERTY(int exchangeCoinsStart READ exchangeCoinsStart NOTIFY reUpdateValues)
57 Q_PROPERTY(int exchangeCoinsAfter READ exchangeCoinsAfter NOTIFY reUpdateValues)
58 Q_PROPERTY(int exchangeBuyRate READ exchangeBuyRate NOTIFY reUpdateValues)
59 Q_PROPERTY(int exchangeSellRate READ exchangeSellRate NOTIFY reUpdateValues)
60
61 Q_PROPERTY(int totalCartWorth READ totalCartWorth NOTIFY reUpdateValues)
62 Q_PROPERTY(int totalCartCount READ totalCartCount NOTIFY reUpdateValues)
63 Q_PROPERTY(int moneyStart READ moneyStart NOTIFY reUpdateValues)
64 Q_PROPERTY(int moneyLeftover READ moneyLeftover NOTIFY reUpdateValues)
65 Q_PROPERTY(bool anyNotEnoughSpace READ anyNotEnoughSpace NOTIFY reUpdateValues)
66 Q_PROPERTY(bool canAnyCheckout READ canAnyCheckout NOTIFY reUpdateValues)
67
68signals:
69 void isBuyModeChanged();
70 void isMoneyCurrencyChanged();
71 void isExchangeModeChanged();
72 void isAnyChanged();
73 void reUpdateValues();
74
75public:
77 enum ItemRoles {
78 // Name of item
79 NameRole = Qt::UserRole + 1,
80
81 // Amount of item to sell (When in sell mode)
83
84 // If the item can be sold (When in sell mode)
86
87 // Value of item individually to buy or sell
89
90 // Item Type, There are 5 types
91 // * An item the player has which may or may not be sellable
92 // * An item the player can buy
93 // * A Game Corner Pokemon
94 // * Player Money / Coins
95 // * A Message
97
98 // Stack count of this item
100
101 // Items left that can be placed on the cart
103
104 // Amount of items on cart
106
107 // Value of item total on cart to buy or sell
109
110 // Stack count of this item
113
114 // Can a checkout be done?
116
117 // For this setup, is the item valid?
119
120 // Exclude this item from most totals, it's not to be mixed in with other
121 // items
123
124 // How much money is left after all is said and done
126
127 // Which modes we're in
130
131 // Which left-list VIEW this row belongs to (ViewBuy / ViewSell); -1 = unfiltered
133
134 // Sign this row contributes to the net (+1 sell, -1 buy)
136
137 // For a money/exchange row: its fixed direction (1 = Money=>Coins, 0 = Coins=>
138 // Money); -1 for non-money rows. Lets the Exchange converter label each lane.
140
141 // Detailed-tooltip text for the row (what the item is / how it's obtained).
143 };
144
146 enum {
151 };
152
154 enum {
157 };
158
162 Router* router,
165 SaveFile* file);
166
167 virtual int rowCount(const QModelIndex& parent) const override;
168 virtual QVariant data(const QModelIndex& index, int role) const override;
169 virtual QHash<int, QByteArray> roleNames() const override;
170 bool setData(const QModelIndex& index, const QVariant& value, int role) override;
171
172 // Value of total on cart
173 // Uses -/+ to indicate buy/sell
174 int totalCartWorth();
175 int totalCartCount();
176 int whichMode();
177 int moneyStart();
178 int moneyLeftover();
179 bool anyNotEnoughSpace();
180 bool canAnyCheckout();
181
182 // Exchange totals (mirror the money rows' checkout deltas exactly).
183 int exchangeMoneyStart();
184 int exchangeMoneyAfter();
185 int exchangeCoinsStart();
186 int exchangeCoinsAfter();
187 int exchangeBuyRate();
188 int exchangeSellRate();
189
190 // The Exchange converter drives one net coin axis via two buttons.
191 Q_INVOKABLE int exchangeNet();
192 Q_INVOKABLE void exchangeAdjust(int deltaCoins);
193
194 void onReUpdateValues();
195
196 // Re-create list cache methods
197 bool vendorListItem(ItemDBEntry* el);
198 bool buyableInGame(ItemDBEntry* el) const;
199 bool isVendingItem(ItemDBEntry* el) const;
200 void clearList();
201 void buildList();
202 void buildPlayerItemList();
203 void buildMartItemList();
204 void buildExchangeList();
205
206 // Respodning to events and signals
207 void pageOpening(QString path);
208
209public slots:
210 void checkout();
211 void reUpdateAll();
212
213public:
214 QVector<ItemMarketEntry*> itemListCache;
215
216 // Buy or Sell, do we view the store's items or our own?
217 // Default to Buy (the Market opens on Buy + Pokemart).
218 bool isBuyMode = true;
219
220 // Money or Coins, do we sell your items to money/coins or do we look at the
221 // Pokemart or Game Corner Mart to buy with money and coins
222 // Default to dealing with money
223 bool isMoneyCurrency = true;
224
225 // The money<->coins exchange as its own list (pulled out of the buy/sell lists).
226 // When true the buy/sell + currency choice is irrelevant; the list is the two
227 // swap rows.
228 bool isExchangeMode = false;
229
230 // Connections to the Sav Data
233 Router* router = nullptr;
234 PlayerBasics* basics = nullptr;
236 Storage* storage = nullptr;
237 SaveFile* file = nullptr;
238};
Abstract base for one row of the item market – the row-type hierarchy root.
Storage * storage
PC storage (for received Pokemon).
void buildExchangeList()
Build the money<->coins exchange rows (both directions).
ItemRoles
Columns (mapped in roleNames()); comments describe each.
bool setData(const QModelIndex &index, const QVariant &value, int role) override
Edit a row (cart count).
ItemStorageBox * itemStorage
The PC item box.
bool buyableInGame(ItemDBEntry *el) const
Is el sold by a reachable Gen-1 vendor (Normal vs Special)?
virtual QHash< int, QByteArray > roleNames() const override
Role -> QML name.
PlayerBasics * basics
Player money/coins.
void exchangeAdjust(int deltaCoins)
Nudge the net (+Coins = +1, +Money = -1).
void clearList()
Empty the row cache.
bool vendorListItem(ItemDBEntry *el)
Should el appear in the store list (has a price here)?
virtual int rowCount(const QModelIndex &parent) const override
Row count.
bool isVendingItem(ItemDBEntry *el) const
Is el a Celadon vending-machine drink (its own group)?
void checkout()
Apply the cart transaction to the save.
virtual QVariant data(const QModelIndex &index, int role) const override
Row+role value.
ItemStorageBox * itemBag
The player's bag.
void buildPlayerItemList()
Build rows from the player's items.
ItemMarketModel(ItemStorageBox *itemBag, ItemStorageBox *itemStorage, PlayerBasics *basics, Router *router, PlayerPokemon *playerPokemon, Storage *storage, SaveFile *file)
void buildList()
Build the rows for the current mode.
void pageOpening(QString path)
Hook when the market page opens.
void reUpdateAll()
Rebuild + recompute everything.
Router * router
For page hooks.
void onReUpdateValues()
Recompute the derived totals.
QVector< ItemMarketEntry * > itemListCache
The current market rows.
void buildMartItemList()
Build rows from the store stock.
PlayerPokemon * playerPokemon
Party (for received Pokemon).
int exchangeNet()
+N buying N coins / -N selling N coins.
SaveFile * file
The live save.
A container of Items – either the trainer's bag or a PC item box.
The trainer's headline values: name, ID, money, coins, badges, starter.
The player's active party – a specialized PokemonStorageBox.
Screen navigation for the UI – the QML StackView's controller.
Definition router.h:74
One loaded save: the raw 32 KB bytes, their expanded object tree, and the tools that move between the...
Definition savefile.h:46
The PC: the item storage box and all 12 Pokemon boxes.
Definition storage.h:49
One item's static data: name/flags, pricing, and where it's used.
Definition itemdbentry.h:46