Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
itemstoragebox.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 <QVector>
19#include <pse-common/types.h>
21
22class SaveFile;
23class Item;
24
35class SAVEFILE_AUTOPORT ItemStorageBox : public QObject
36{
37 Q_OBJECT
38
40 Q_PROPERTY(int itemsCount READ itemsCount NOTIFY itemsChanged STORED false)
41
42
43 Q_PROPERTY(int itemsCountBulk READ itemsCountBulk NOTIFY itemsChanged STORED false)
44
45
46 Q_PROPERTY(int itemsMax READ itemsMax STORED false CONSTANT)
47
48
49 Q_PROPERTY(bool isBag READ getIsBag CONSTANT)
50
51
52 Q_PROPERTY(bool relocateFull READ relocateFull NOTIFY itemsChanged STORED false)
53
54
55 Q_PROPERTY(int itemsAllBuyMoney READ itemsAllBuyMoney NOTIFY itemsChanged STORED false)
56 Q_PROPERTY(int itemsAllBuyCoins READ itemsAllBuyCoins NOTIFY itemsChanged STORED false)
57 Q_PROPERTY(int itemsAllSellMoney READ itemsAllSellMoney NOTIFY itemsChanged STORED false)
58 Q_PROPERTY(int itemsAllSellCoins READ itemsAllSellCoins NOTIFY itemsChanged STORED false)
59
60
61 Q_PROPERTY(ItemStorageBox* destBox READ destBox STORED false CONSTANT)
62
63public:
65 ItemStorageBox(bool isBag, int maxSize, SaveFile* saveFile = nullptr, int offset = 0);
66 virtual ~ItemStorageBox();
67
68 void load(SaveFile* saveFile = nullptr, int offset = 0);
69 void save(SaveFile* saveFile, int offset);
70
71 // These are provided as properties
72 int itemsCount();
73 int itemsCountBulk();
74 int itemsMax();
75 bool getIsBag();
76 bool relocateFull();
78
79 int itemsAllBuyMoney();
80 int itemsAllBuyCoins();
81 int itemsAllSellMoney();
82 int itemsAllSellCoins();
83
84 // Methods that can be called from QML which cannot be properties and make no
85 // sense as slots
86 Q_INVOKABLE Item* itemAt(int ind);
87
88 // Auto-called from randomize function depending on box type
89 void randomizeStorage();
90 void randomizeBag();
91
92 // Item RNG never duplicates within a single box (uniqueness is per-list: the
93 // bag and the PC box are independent).
94 Q_INVOKABLE bool hasItemInd(int ind);
95 Q_INVOKABLE int amountOfInd(int ind);
97
98signals:
99 // When moving an item away from the box to another box, allow the model to
100 // perform cleanup actions
101 void beforeItemRelocate(Item* item);
102
103 // Alert the model on changes
105 void itemMoveChange(int from, int to);
106 void itemRemoveChange(int ind);
109
110public slots:
111
112 // These alow the model or QML to interact with the box
113 void reset();
114 void randomize();
115 bool itemMove(int from, int to);
116 void itemRemove(int ind);
117 void itemNew();
118 bool relocateAll();
119 bool relocateOne(int ind);
120 void sort();
121
122public:
123 QVector<Item*> items;
124
125 // These are set from the creating class SAVEFILE_AUTOPORT indicating details of the box
126 // It's crucial they are read-only
128 bool isBag;
130};
void sort()
Sort the box contents.
QVector< Item * > items
The stored items.
void save(SaveFile *saveFile, int offset)
Flatten the box to the save.
void reset()
Empty the box.
bool getIsBag()
Is this the bag?
void itemsResetChange()
The box was reset.
void randomizeBag()
Randomizer path for the bag.
bool isBag
Bag vs PC (set at construction; treat as read-only).
void load(SaveFile *saveFile=nullptr, int offset=0)
Expand the box from the save.
ItemStorageBox * destBox()
The paired box for relocation.
int maxSize
Capacity (set at construction; treat as read-only).
void itemNew()
Add a fresh random item (never a duplicate of one already here).
ItemStorageBox(bool isBag, int maxSize, SaveFile *saveFile=nullptr, int offset=0)
How many items are there.
int itemsCountBulk()
Item count including stack amounts.
void itemInsertChange()
An item was inserted.
void itemMoveChange(int from, int to)
An item moved slot.
bool relocateAll()
Move every item to the paired box.
int randomUniqueInd()
A random non-glitch/non-once item index absent from this box, or -1 if none remain.
bool itemMove(int from, int to)
Reorder an item.
bool relocateOne(int ind)
Move one item to the paired box.
void randomizeStorage()
Randomizer path for a PC item box.
int itemsMax()
Capacity.
bool relocateFull()
Is relocation blocked because the paired box is full?
Item * itemAt(int ind)
Item slot ind (GC-protected return).
bool hasItemInd(int ind)
Does this box already contain an item with index ind? (Q_INVOKABLE: the SelectItem dropdown greys out...
void randomize()
Randomize (dispatches to bag/storage path); sorts afterward.
SaveFile * file
Owning save.
int amountOfInd(int ind)
Total amount of item ind across all rows in this box (Q_INVOKABLE: the SelectItem dropdown shows the ...
int itemsCount()
Distinct item count.
void itemRemoveChange(int ind)
An item was removed.
void itemsChanged()
Box contents changed.
void itemRemove(int ind)
Remove item ind.
One inventory slot: an item index and an amount, with live pricing.
Definition item.h:36
One loaded save: the raw 32 KB bytes, their expanded object tree, and the tools that move between the...
Definition savefile.h:46
Project-wide fixed-width integer aliases (var8, var16, ...).
Import/export macro for the savefile library, plus the central list of QObject types kept deliberatel...
#define SAVEFILE_AUTOPORT
Expands to the correct dllexport/dllimport decoration for this library.