Compare commits

...

1 Commits

Author SHA1 Message Date
nimetu 5a7abd3810 Sort resource selection in craft window 3 years ago

@ -502,6 +502,10 @@ void CActionPhraseFaber::validateFaberPlanSelection(CSBrickSheet *itemPlanBrick
// Bkup original quantity from inventory
_InventoryMirror[i].OriginalQuantity= _InventoryMirror[i].Quantity;
_InventoryMirror[i].LockedByOwner= bLockedByOwner;
// remember these for sorting
_InventoryMirror[i].MpFamily = mpSheet->Mp.Family;
_InventoryMirror[i].Ecosystem = mpSheet->Mp.Ecosystem;
_InventoryMirror[i].StatEnergy = mpSheet->Mp.StatEnergy;
}
}
}
@ -696,6 +700,63 @@ void CActionPhraseFaber::filterSelectionItemSpecific(std::vector<uint> &mps, N
mps= res;
}
// ***************************************************************************
struct SItemSortData
{
uint Index;
RM_FAMILY::TRMFamily MpFamily;
ECOSYSTEM::EECosystem Ecosystem;
uint16 StatEnergy;
uint16 Quality;
uint16 Quantity;
SItemSortData(uint i, RM_FAMILY::TRMFamily mpfam, ECOSYSTEM::EECosystem eco, uint16 stat, uint16 quality, uint16 quantity)
: Index(i), MpFamily(mpfam), Ecosystem(eco), StatEnergy(stat), Quality(quality), Quantity(quantity)
{}
bool operator<(const SItemSortData &other) const
{
// anete, shu
if (MpFamily < other.MpFamily) return true;
if (MpFamily > other.MpFamily) return false;
// desert, lake
if (Ecosystem < other.Ecosystem) return true;
if (Ecosystem > other.Ecosystem) return false;
// basic, choice
if (StatEnergy < other.StatEnergy) return true;
if (StatEnergy > other.StatEnergy) return false;
// q10, q200
if (Quality < other.Quality) return true;
if (Quality > other.Quality) return false;
// x10, x200
if (Quantity < other.Quantity) return true;
if (Quantity > other.Quantity) return false;
return false;
}
};
// ***************************************************************************
void CActionPhraseFaber::sortSelection(std::vector<uint> &mps) const
{
std::vector<SItemSortData> items;
items.reserve(mps.size());
for(uint i = 0; i < mps.size(); i++)
{
const CItem &item = _InventoryMirror[mps[i]];
items.push_back(SItemSortData(mps[i], item.MpFamily, item.Ecosystem, item.StatEnergy, item.Quality, item.Quantity));
}
std::sort(items.begin(), items.end());
// overwrite previous values
for(uint i = 0; i< items.size(); i++)
mps[i] = items[i].Index;
}
// ***************************************************************************
void CActionPhraseFaber::startMpSelection(uint itemReqLine, uint mpSlot)
@ -785,6 +846,9 @@ void CActionPhraseFaber::startMpSelection(uint itemReqLine, uint mpSlot)
nlstop;
}
// Sort before displaying
sortSelection(selectMps);
// Reset the DB selection
resetSelection();
fillSelection(selectMps);
@ -1415,6 +1479,10 @@ void CActionPhraseFaber::onInventoryChange()
newInvItem.Weight= itemImage->getWeight();
newInvItem.OriginalQuantity= newInvItem.Quantity;
newInvItem.LockedByOwner = bLockedByOwner;
// remember these for sorting
newInvItem.MpFamily = mpSheet->Mp.Family;
newInvItem.Ecosystem = mpSheet->Mp.Ecosystem;
newInvItem.StatEnergy = mpSheet->Mp.StatEnergy;
}
/* There is 5 cases:

@ -27,6 +27,7 @@
#include "inventory_manager.h"
#include "game_share/crafting_tool_type.h"
#include "game_share/rm_family.h"
#include "game_share/ecosystem.h"
#include "game_share/brick_families.h"
#include "game_share/item_origin.h"
#include "skill_change_callback.h"
@ -98,6 +99,10 @@ private:
// This is the original quantity in inventory
sint32 OriginalQuantity;
bool LockedByOwner;
// for sorting
RM_FAMILY::TRMFamily MpFamily;
ECOSYSTEM::EECosystem Ecosystem;
uint16 StatEnergy;
CItem() : Sheet(0)
{
@ -107,6 +112,9 @@ private:
Weight= 0;
Selected= 0;
OriginalQuantity= 0;
MpFamily = RM_FAMILY::Unknown;
Ecosystem = ECOSYSTEM::common_ecosystem;
StatEnergy = 0;
}
void reset()
@ -120,6 +128,9 @@ private:
Weight= 0;
Selected= 0;
OriginalQuantity= 0;
MpFamily = RM_FAMILY::Unknown;
Ecosystem = ECOSYSTEM::common_ecosystem;
StatEnergy = 0;
}
};
@ -225,6 +236,8 @@ private:
void filterSelectionItemPart(std::vector<uint> &mps, RM_FABER_TYPE::TRMFType itemPartFilter, ITEM_ORIGIN::EItemOrigin originFilter);
void filterSelectionItemSpecific(std::vector<uint> &mps, NLMISC::CSheetId specificItemWanted);
void sortSelection(std::vector<uint> &mps) const;
uint getMaxQuantityChange(uint itemReqLine, uint mpSlot) const;
uint getTotalQuantitySetuped(uint itemReqLine) const;

Loading…
Cancel
Save