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

A container of Items – either the trainer's bag or a PC item box. More...

#include <itemstoragebox.h>

Inheritance diagram for ItemStorageBox:
Collaboration diagram for ItemStorageBox:

Public Member Functions

 ItemStorageBox (bool isBag, int maxSize, SaveFile *saveFile=nullptr, int offset=0)
 How many items are there.
virtual ~ItemStorageBox ()
void load (SaveFile *saveFile=nullptr, int offset=0)
 Expand the box from the save.
void save (SaveFile *saveFile, int offset)
 Flatten the box to the save.
int itemsCount ()
 Distinct item count.
int itemsCountBulk ()
 Item count including stack amounts.
int itemsMax ()
 Capacity.
bool getIsBag ()
 Is this the bag?
bool relocateFull ()
 Is relocation blocked because the paired box is full?
ItemStorageBoxdestBox ()
 The paired box for relocation.
int itemsAllBuyMoney ()
int itemsAllBuyCoins ()
int itemsAllSellMoney ()
int itemsAllSellCoins ()
ItemitemAt (int ind)
 Item slot ind (GC-protected return).
void randomizeStorage ()
 Randomizer path for a PC item box.
void randomizeBag ()
 Randomizer path for the bag.
bool hasItemInd (int ind)
 Does this box already contain an item with index ind? (Q_INVOKABLE: the SelectItem dropdown greys out already-present names.).
int amountOfInd (int ind)
 Total amount of item ind across all rows in this box (Q_INVOKABLE: the SelectItem dropdown shows the cross-pane owned total).
int randomUniqueInd ()
 A random non-glitch/non-once item index absent from this box, or -1 if none remain.
void reset ()
 Empty the box.
void randomize ()
 Randomize (dispatches to bag/storage path); sorts afterward.
bool itemMove (int from, int to)
 Reorder an item.
void itemRemove (int ind)
 Remove item ind.
void itemNew ()
 Add a fresh random item (never a duplicate of one already here).
bool relocateAll ()
 Move every item to the paired box.
bool relocateOne (int ind)
 Move one item to the paired box.
void sort ()
 Sort the box contents.

Public Attributes

QVector< Item * > items
 The stored items.
int maxSize
 Capacity (set at construction; treat as read-only).
bool isBag
 Bag vs PC (set at construction; treat as read-only).
SaveFilefile
 Owning save.

Protected Member Functions

void itemsChanged ()
 Box contents changed.
void itemMoveChange (int from, int to)
 An item moved slot.
void itemRemoveChange (int ind)
 An item was removed.
void itemInsertChange ()
 An item was inserted.
void itemsResetChange ()
 The box was reset.

Protected Attributes

 : void beforeItemRelocate(Item* item)
 Emitted before a relocate so models can clean up.

Detailed Description

A container of Items – either the trainer's bag or a PC item box.

Holds a vector of items up to maxSize. The isBag flag chooses bag vs PC behaviour (and drives which randomizer runs). Exposes live counts and total worth to QML, supports add/remove/move/sort, and can relocate items to its paired box (bag <-> PC) via destBox.

See also
Item (slot type), Player (owns the bag), Storage (owns the PC box).

Definition at line 35 of file itemstoragebox.h.

Constructor & Destructor Documentation

◆ ItemStorageBox()

ItemStorageBox::ItemStorageBox ( bool isBag,
int maxSize,
SaveFile * saveFile = nullptr,
int offset = 0 )

How many items are there.

How many items including item amounts are there. Maximum number of items. Is this the players bag or PC storage. Can we relocate? If the other box is full then we cannot. What's the worth of all the items? < Total buy value in money. Total buy value in coins. Total sell value in money. Total sell value in coins. Get destination box (the paired bag/PC box for relocation).

Parameters
isBagbag vs PC;
maxSizecapacity;
offsetbox location in the save.

Definition at line 41 of file itemstoragebox.cpp.

References isBag, load(), and maxSize.

Referenced by destBox().

◆ ~ItemStorageBox()

ItemStorageBox::~ItemStorageBox ( )
virtual

Definition at line 48 of file itemstoragebox.cpp.

References items.

Member Function Documentation

◆ amountOfInd()

int ItemStorageBox::amountOfInd ( int ind)

Total amount of item ind across all rows in this box (Q_INVOKABLE: the SelectItem dropdown shows the cross-pane owned total).

Definition at line 204 of file itemstoragebox.cpp.

References items.

◆ destBox()

ItemStorageBox * ItemStorageBox::destBox ( )

The paired box for relocation.

Definition at line 360 of file itemstoragebox.cpp.

References file, isBag, and ItemStorageBox().

Referenced by relocateAll(), relocateFull(), and relocateOne().

◆ getIsBag()

bool ItemStorageBox::getIsBag ( )

Is this the bag?

Definition at line 75 of file itemstoragebox.cpp.

References isBag.

◆ hasItemInd()

bool ItemStorageBox::hasItemInd ( int ind)

Does this box already contain an item with index ind? (Q_INVOKABLE: the SelectItem dropdown greys out already-present names.).

Definition at line 194 of file itemstoragebox.cpp.

References items.

Referenced by randomUniqueInd().

◆ itemAt()

Item * ItemStorageBox::itemAt ( int ind)

Item slot ind (GC-protected return).

Definition at line 90 of file itemstoragebox.cpp.

References items, and qmlCppOwned().

◆ itemInsertChange()

void ItemStorageBox::itemInsertChange ( )
protected

An item was inserted.

Referenced by itemNew(), ItemStorageModel::ItemStorageModel(), load(), and randomizeBag().

◆ itemMove()

bool ItemStorageBox::itemMove ( int from,
int to )

Reorder an item.

Definition at line 158 of file itemstoragebox.cpp.

References itemMoveChange(), items, and itemsChanged().

Referenced by itemsResetChange().

◆ itemMoveChange()

void ItemStorageBox::itemMoveChange ( int from,
int to )
protected

An item moved slot.

Referenced by itemMove(), and ItemStorageModel::ItemStorageModel().

◆ itemNew()

void ItemStorageBox::itemNew ( )

Add a fresh random item (never a duplicate of one already here).

Definition at line 241 of file itemstoragebox.cpp.

References Random::inst(), itemInsertChange(), items, itemsChanged(), maxSize, and randomUniqueInd().

Referenced by itemsResetChange(), randomizeBag(), and randomizeStorage().

◆ itemRemove()

void ItemStorageBox::itemRemove ( int ind)

Remove item ind.

Definition at line 181 of file itemstoragebox.cpp.

References itemRemoveChange(), items, and itemsChanged().

Referenced by itemsResetChange().

◆ itemRemoveChange()

void ItemStorageBox::itemRemoveChange ( int ind)
protected

An item was removed.

Referenced by itemRemove(), ItemStorageModel::ItemStorageModel(), and relocateOne().

◆ itemsAllBuyCoins()

int ItemStorageBox::itemsAllBuyCoins ( )
See also
itemsAllBuyCoins property.

Definition at line 378 of file itemstoragebox.cpp.

References items.

◆ itemsAllBuyMoney()

int ItemStorageBox::itemsAllBuyMoney ( )
See also
itemsAllBuyMoney property.

Definition at line 367 of file itemstoragebox.cpp.

References items.

◆ itemsAllSellCoins()

int ItemStorageBox::itemsAllSellCoins ( )
See also
itemsAllSellCoins property.

Definition at line 400 of file itemstoragebox.cpp.

References items.

◆ itemsAllSellMoney()

int ItemStorageBox::itemsAllSellMoney ( )
See also
itemsAllSellMoney property.

Definition at line 389 of file itemstoragebox.cpp.

References items.

◆ itemsChanged()

void ItemStorageBox::itemsChanged ( )
protected

◆ itemsCount()

int ItemStorageBox::itemsCount ( )

Distinct item count.

Definition at line 54 of file itemstoragebox.cpp.

References items.

◆ itemsCountBulk()

int ItemStorageBox::itemsCountBulk ( )

Item count including stack amounts.

Definition at line 59 of file itemstoragebox.cpp.

References items.

◆ itemsMax()

int ItemStorageBox::itemsMax ( )

Capacity.

Definition at line 70 of file itemstoragebox.cpp.

References maxSize.

◆ itemsResetChange()

void ItemStorageBox::itemsResetChange ( )
protected

◆ load()

void ItemStorageBox::load ( SaveFile * saveFile = nullptr,
int offset = 0 )

◆ randomize()

void ItemStorageBox::randomize ( )

Randomize (dispatches to bag/storage path); sorts afterward.

Definition at line 422 of file itemstoragebox.cpp.

References isBag, itemsChanged(), randomizeBag(), randomizeStorage(), reset(), and sort().

Referenced by itemsResetChange().

◆ randomizeBag()

void ItemStorageBox::randomizeBag ( )

Randomizer path for the bag.

Definition at line 109 of file itemstoragebox.cpp.

References Random::chanceSuccess(), Random::inst(), itemInsertChange(), itemNew(), items, and Random::rangeInclusive().

Referenced by randomize().

◆ randomizeStorage()

void ItemStorageBox::randomizeStorage ( )

Randomizer path for a PC item box.

Definition at line 98 of file itemstoragebox.cpp.

References Random::inst(), itemNew(), maxSize, and Random::rangeInclusive().

Referenced by randomize().

◆ randomUniqueInd()

int ItemStorageBox::randomUniqueInd ( )

A random non-glitch/non-once item index absent from this box, or -1 if none remain.

Definition at line 218 of file itemstoragebox.cpp.

References hasItemInd(), ItemsDB::inst(), and Random::inst().

Referenced by itemNew().

◆ relocateAll()

bool ItemStorageBox::relocateAll ( )

Move every item to the paired box.

Definition at line 258 of file itemstoragebox.cpp.

References destBox(), items, and relocateOne().

Referenced by itemsResetChange().

◆ relocateFull()

bool ItemStorageBox::relocateFull ( )

Is relocation blocked because the paired box is full?

Definition at line 80 of file itemstoragebox.cpp.

References destBox().

◆ relocateOne()

bool ItemStorageBox::relocateOne ( int ind)

Move one item to the paired box.

Definition at line 272 of file itemstoragebox.cpp.

References destBox(), itemRemoveChange(), items, and itemsChanged().

Referenced by itemsResetChange(), and relocateAll().

◆ reset()

void ItemStorageBox::reset ( )

Empty the box.

Definition at line 411 of file itemstoragebox.cpp.

References items, itemsChanged(), and itemsResetChange().

Referenced by itemsResetChange(), load(), and randomize().

◆ save()

void ItemStorageBox::save ( SaveFile * saveFile,
int offset )

Flatten the box to the save.

Definition at line 347 of file itemstoragebox.cpp.

References items, SaveFile::iterator(), maxSize, SaveFileIterator::offsetTo(), and SaveFileIterator::setByte().

◆ sort()

void ItemStorageBox::sort ( )

Sort the box contents.

Definition at line 296 of file itemstoragebox.cpp.

References items, itemsChanged(), and itemsResetChange().

Referenced by itemsResetChange(), and randomize().

Member Data Documentation

◆ __pad0__

ItemStorageBox::__pad0__
protected

Emitted before a relocate so models can clean up.

Definition at line 96 of file itemstoragebox.h.

◆ file

SaveFile* ItemStorageBox::file

Owning save.

Definition at line 129 of file itemstoragebox.h.

Referenced by destBox(), and load().

◆ isBag

bool ItemStorageBox::isBag

Bag vs PC (set at construction; treat as read-only).

Definition at line 128 of file itemstoragebox.h.

Referenced by destBox(), getIsBag(), ItemStorageBox(), and randomize().

◆ items

◆ maxSize

int ItemStorageBox::maxSize

Capacity (set at construction; treat as read-only).

Definition at line 127 of file itemstoragebox.h.

Referenced by itemNew(), itemsMax(), ItemStorageBox(), load(), randomizeStorage(), and save().


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