Skip to content
Fairy Fox
Home
Projects
Games
Docs
Updates
About
A
a
Pokered Save Editor 2
Overview
Notes
API
Screenshots
Repository ↗
Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
Loading...
Searching...
No Matches
itemexchangemodel.h
Go to the documentation of this file.
1
/*
2
* Copyright 2026 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 <QHash>
20
#include <QVariantList>
21
22
class
ItemStorageBox
;
23
class
PlayerBasics
;
24
50
class
ItemExchangeModel
:
public
QObject
51
{
52
Q_OBJECT
53
54
// The two selected item indices (-1 = none). The dropdowns write these.
55
Q_PROPERTY(
int
itemAInd
READ
itemAInd
WRITE
setItemAInd
NOTIFY
selectionChanged
)
56
Q_PROPERTY(
int
itemBInd
READ
itemBInd
WRITE
setItemBInd
NOTIFY
selectionChanged
)
57
58
Q_PROPERTY(
bool
valid
READ
valid
NOTIFY
changed
)
59
Q_PROPERTY(
int
net
READ
net
NOTIFY
changed
)
60
61
Q_PROPERTY(QString
aName
READ
aName
NOTIFY
changed
)
62
Q_PROPERTY(QString
bName
READ
bName
NOTIFY
changed
)
63
Q_PROPERTY(
int
aBuy
READ
aBuy
NOTIFY
changed
)
64
Q_PROPERTY(
int
bBuy
READ
bBuy
NOTIFY
changed
)
65
66
Q_PROPERTY(
int
aStart
READ
aStart
NOTIFY
changed
)
67
Q_PROPERTY(
int
aAfter
READ
aAfter
NOTIFY
changed
)
68
Q_PROPERTY(
int
bStart
READ
bStart
NOTIFY
changed
)
69
Q_PROPERTY(
int
bAfter
READ
bAfter
NOTIFY
changed
)
70
Q_PROPERTY(
int
moneyStart
READ
moneyStart
NOTIFY
changed
)
71
Q_PROPERTY(
int
moneyAfter
READ
moneyAfter
NOTIFY
changed
)
72
73
Q_PROPERTY(
bool
canAddA
READ
canAddA
NOTIFY
changed
)
74
Q_PROPERTY(
bool
canAddB
READ
canAddB
NOTIFY
changed
)
75
76
79
Q_PROPERTY(
int
revision
READ
revision
NOTIFY
changed
)
80
81
public
:
82
static
constexpr
int
MoneyCap
= 999999;
83
static
constexpr
int
StackCap
= 99;
84
85
ItemExchangeModel
(
ItemStorageBox
* bag,
ItemStorageBox
* storage,
PlayerBasics
* basics);
86
87
int
itemAInd
()
const
{
return
m_itemAInd; }
88
int
itemBInd
()
const
{
return
m_itemBInd; }
89
void
setItemAInd
(
int
v);
90
void
setItemBInd
(
int
v);
91
92
int
net
()
const
{
return
m_net; }
93
int
revision
()
const
{
return
m_revision; }
94
bool
valid
()
const
;
95
96
QString
aName
()
const
{
return
readableOf(m_itemAInd); }
97
QString
bName
()
const
{
return
readableOf(m_itemBInd); }
98
int
aBuy
()
const
{
return
buyOf(m_itemAInd); }
99
int
bBuy
()
const
{
return
buyOf(m_itemBInd); }
100
101
int
aStart
()
const
{
return
combinedAmount(m_itemAInd); }
102
int
bStart
()
const
{
return
combinedAmount(m_itemBInd); }
103
int
moneyStart
()
const
;
104
int
aAfter
()
const
{
return
aAfterFor(m_net); }
105
int
bAfter
()
const
{
return
bAfterFor(m_net); }
106
int
moneyAfter
()
const
{
return
moneyAfterFor(m_net); }
107
113
Q_INVOKABLE
int
giveFor
(
int
dir,
int
steps)
const
;
114
118
Q_INVOKABLE
int
refundFor
(
int
dir,
int
steps)
const
;
119
120
bool
canAddA
()
const
{
return
valid
() && stateValid(m_net + 1); }
121
bool
canAddB
()
const
{
return
valid
() && stateValid(m_net - 1); }
122
126
Q_INVOKABLE QVariantList
sourceItems
(
bool
healingOnly,
int
excludeInd)
const
;
127
134
Q_INVOKABLE QVariantList
targetItems
(
bool
healingOnly,
int
excludeInd)
const
;
135
137
Q_INVOKABLE
bool
canGainTarget
(
int
bInd)
const
;
138
143
Q_INVOKABLE
void
pickDefaults
(
bool
healingOnly);
144
145
Q_INVOKABLE
void
adjust
(
int
dir);
146
Q_INVOKABLE
void
reset
();
147
Q_INVOKABLE
void
refresh
();
148
149
public
slots:
150
void
checkout
();
151
152
signals:
153
void
selectionChanged
();
154
void
changed
();
155
156
private
:
157
int
combinedAmount(
int
ind)
const
;
158
int
combinedCapacity(
int
ind)
const
;
159
int
buyOf(
int
ind)
const
;
160
QString readableOf(
int
ind)
const
;
161
bool
isHealing(
int
ind)
const
;
162
int
indOfName(
const
QString& name)
const
;
163
static
void
sortByName(QVariantList& list);
164
165
static
int
nA(
int
m) {
return
m > 0 ? m : 0; }
166
static
int
nB(
int
m) {
return
m < 0 ? -m : 0; }
167
int
aAfterFor(
int
m)
const
;
168
int
bAfterFor(
int
m)
const
;
169
int
moneyAfterFor(
int
m)
const
;
170
bool
stateValid(
int
m)
const
;
171
void
clampNet();
172
void
emitChanged();
173
174
ItemStorageBox* bag =
nullptr
;
175
ItemStorageBox* storage =
nullptr
;
176
PlayerBasics* basics =
nullptr
;
177
178
int
m_itemAInd = -1;
179
int
m_itemBInd = -1;
180
int
m_net = 0;
181
int
m_revision = 0;
182
184
struct
Info { QString name; QString readable;
int
buy = 0;
bool
healing =
false
; };
185
QHash<int, Info> m_info;
186
};
ItemExchangeModel::canAddB
bool canAddB() const
Definition
itemexchangemodel.h:121
ItemExchangeModel::valid
bool valid() const
Definition
itemexchangemodel.cpp:176
ItemExchangeModel::targetItems
QVariantList targetItems(bool healingOnly, int excludeInd) const
RIGHT list – what you can GET: EVERY exchangeable item (owned or not), optionally healing-only,...
Definition
itemexchangemodel.cpp:334
ItemExchangeModel::moneyAfter
int moneyAfter() const
Definition
itemexchangemodel.h:106
ItemExchangeModel::canGainTarget
bool canGainTarget(int bInd) const
Can we gain at least one of item bInd right now, paying with the selected source?
Definition
itemexchangemodel.cpp:358
ItemExchangeModel::aBuy
int aBuy() const
Definition
itemexchangemodel.h:98
ItemExchangeModel::changed
void changed()
Any derived value changed.
ItemExchangeModel::setItemBInd
void setItemBInd(int v)
Definition
itemexchangemodel.cpp:266
ItemExchangeModel::ItemExchangeModel
ItemExchangeModel(ItemStorageBox *bag, ItemStorageBox *storage, PlayerBasics *basics)
Definition
itemexchangemodel.cpp:80
ItemExchangeModel::bName
QString bName() const
Definition
itemexchangemodel.h:97
ItemExchangeModel::giveFor
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 ste...
Definition
itemexchangemodel.cpp:186
ItemExchangeModel::refresh
void refresh()
Re-read counts/money + re-emit (tab open / external edit).
Definition
itemexchangemodel.cpp:295
ItemExchangeModel::pickDefaults
void pickDefaults(bool healingOnly)
Choose a sensible starting pair.
Definition
itemexchangemodel.cpp:377
ItemExchangeModel::StackCap
static constexpr int StackCap
Gen 1 per-stack cap.
Definition
itemexchangemodel.h:83
ItemExchangeModel::revision
int revision() const
Definition
itemexchangemodel.h:93
ItemExchangeModel::aAfter
int aAfter() const
Definition
itemexchangemodel.h:104
ItemExchangeModel::net
int net() const
Definition
itemexchangemodel.h:92
ItemExchangeModel::adjust
void adjust(int dir)
+1 = one gained-A step, -1 = one gained-B step (gated).
Definition
itemexchangemodel.cpp:276
ItemExchangeModel::itemAInd
int itemAInd() const
Definition
itemexchangemodel.h:87
ItemExchangeModel::bBuy
int bBuy() const
Definition
itemexchangemodel.h:99
ItemExchangeModel::sourceItems
QVariantList sourceItems(bool healingOnly, int excludeInd) const
LEFT list – what you can GIVE: items you actually own (amount > 0) and that are exchangeable (buy pri...
Definition
itemexchangemodel.cpp:306
ItemExchangeModel::MoneyCap
static constexpr int MoneyCap
< Both picked, distinct, both have a buy price.
Definition
itemexchangemodel.h:82
ItemExchangeModel::canAddA
bool canAddA() const
Definition
itemexchangemodel.h:120
ItemExchangeModel::aStart
int aStart() const
Definition
itemexchangemodel.h:101
ItemExchangeModel::aName
QString aName() const
Definition
itemexchangemodel.h:96
ItemExchangeModel::bStart
int bStart() const
Definition
itemexchangemodel.h:102
ItemExchangeModel::reset
void reset()
Clear the net axis.
Definition
itemexchangemodel.cpp:287
ItemExchangeModel::bAfter
int bAfter() const
Definition
itemexchangemodel.h:105
ItemExchangeModel::setItemAInd
void setItemAInd(int v)
Definition
itemexchangemodel.cpp:256
ItemExchangeModel::selectionChanged
protected::void selectionChanged()
A or B selection changed.
ItemExchangeModel::checkout
void checkout()
Apply the previewed trade to the save.
Definition
itemexchangemodel.cpp:433
ItemExchangeModel::moneyStart
int moneyStart() const
Definition
itemexchangemodel.cpp:169
ItemExchangeModel::refundFor
int refundFor(int dir, int steps) const
The leftover value of steps in direction dir, refunded as money – i.e.
Definition
itemexchangemodel.cpp:194
ItemExchangeModel::itemBInd
int itemBInd() const
Definition
itemexchangemodel.h:88
ItemStorageBox
A container of Items – either the trainer's bag or a PC item box.
Definition
itemstoragebox.h:36
PlayerBasics
The trainer's headline values: name, ID, money, coins, badges, starter.
Definition
playerbasics.h:67
projects
app
src
mvc
itemexchangemodel.h
Generated by
1.17.0