From 5a7abd38106e96f9c08301b8da082aa549aaa996 Mon Sep 17 00:00:00 2001 From: nimetu Date: Thu, 27 Jan 2022 15:57:56 +0200 Subject: [PATCH] Sort resource selection in craft window --- .../src/interface_v3/action_phrase_faber.cpp | 68 +++++++++++++++++++ .../src/interface_v3/action_phrase_faber.h | 13 ++++ 2 files changed, 81 insertions(+) diff --git a/ryzom/client/src/interface_v3/action_phrase_faber.cpp b/ryzom/client/src/interface_v3/action_phrase_faber.cpp index 05e5735e1..b004dfad2 100644 --- a/ryzom/client/src/interface_v3/action_phrase_faber.cpp +++ b/ryzom/client/src/interface_v3/action_phrase_faber.cpp @@ -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 &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 &mps) const +{ + std::vector 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: diff --git a/ryzom/client/src/interface_v3/action_phrase_faber.h b/ryzom/client/src/interface_v3/action_phrase_faber.h index 5f10c0c51..f3f3747fd 100644 --- a/ryzom/client/src/interface_v3/action_phrase_faber.h +++ b/ryzom/client/src/interface_v3/action_phrase_faber.h @@ -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 &mps, RM_FABER_TYPE::TRMFType itemPartFilter, ITEM_ORIGIN::EItemOrigin originFilter); void filterSelectionItemSpecific(std::vector &mps, NLMISC::CSheetId specificItemWanted); + void sortSelection(std::vector &mps) const; + uint getMaxQuantityChange(uint itemReqLine, uint mpSlot) const; uint getTotalQuantitySetuped(uint itemReqLine) const;