Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
Added buy menu bindings to get cart info
Browse files Browse the repository at this point in the history
  • Loading branch information
Causeless committed Oct 26, 2023
1 parent ef29fec commit 9bc6044
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 15 deletions.
6 changes: 6 additions & 0 deletions Lua/LuaAdapterDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,12 @@ namespace RTE {
};
#pragma endregion

#pragma region BuyMenuGUI Lua Adapters
struct LuaAdaptersBuyMenuGUI {
static std::list<const SceneObject *> * GetOrderList(const BuyMenuGUI *luaSelfObject);
};
#pragma endregion

#pragma region PieMenu Lua Adapters
struct LuaAdaptersPieMenu {
static bool AddPieSlice(PieMenu *luaSelfObject, PieSlice *pieSliceToAdd, const Entity *pieSliceOriginalSource);
Expand Down
8 changes: 8 additions & 0 deletions Lua/LuaAdapters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,14 @@ namespace RTE {
}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

std::list<const SceneObject *> * LuaAdaptersBuyMenuGUI::GetOrderList(const BuyMenuGUI *luaSelfObject) {
auto* orderList = new std::list<const SceneObject *>();
luaSelfObject->GetOrderList(*orderList);
return orderList;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Attachable * LuaAdaptersAttachable::RemoveFromParent1(Attachable *luaSelfObject) {
Expand Down
7 changes: 6 additions & 1 deletion Lua/LuaBindingsGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ namespace RTE {
.def("SetBannerImage", &BuyMenuGUI::SetBannerImage)
.def("SetLogoImage", &BuyMenuGUI::SetLogoImage)
.def("ClearCartList", &BuyMenuGUI::ClearCartList)
.def("LoadDefaultLoadoutToCart", &BuyMenuGUI::LoadDefaultLoadoutToCart);
.def("LoadDefaultLoadoutToCart", &BuyMenuGUI::LoadDefaultLoadoutToCart)
.def("GetOrderList", &LuaAdaptersBuyMenuGUI::GetOrderList, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator)
.def("GetTotalCartCost", &BuyMenuGUI::GetTotalCartCost)
.def("GetTotalOrderCost", &BuyMenuGUI::GetTotalOrderCost)
.def("GetTotalOrderMass", &BuyMenuGUI::GetTotalOrderMass)
.def("GetTotalOrderPassengers", &BuyMenuGUI::GetTotalOrderPassengers);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
19 changes: 8 additions & 11 deletions Menus/BuyMenuGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ void BuyMenuGUI::SetModuleExpanded(int whichModule, bool expanded)
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Return the list of things currently in the purchase order list box.

bool BuyMenuGUI::GetOrderList(std::list<const SceneObject *> &listToFill)
bool BuyMenuGUI::GetOrderList(std::list<const SceneObject *> &listToFill) const
{
if (m_pCartList->GetItemList()->empty())
return false;
Expand Down Expand Up @@ -736,12 +736,7 @@ bool BuyMenuGUI::CommitPurchase(std::string presetName)
return false;
}

//////////////////////////////////////////////////////////////////////////////////////////
// Method: GetTotalOrderCost
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Return teh total cost of everything listed in the order box.

float BuyMenuGUI::GetTotalOrderCost()
float BuyMenuGUI::GetTotalCost(bool includeDelivery) const
{
float totalCost = 0;

Expand All @@ -759,7 +754,8 @@ float BuyMenuGUI::GetTotalOrderCost()
else
orderedItems[presetName] += 1;

if (m_OwnedItems.find(presetName) != m_OwnedItems.end() && m_OwnedItems[presetName] >= orderedItems[presetName])
auto itrFound = m_OwnedItems.find(presetName);
if (itrFound != m_OwnedItems.end() && itrFound->second >= orderedItems[presetName])
needsToBePaid = false;

if (needsToBePaid)
Expand All @@ -768,7 +764,7 @@ float BuyMenuGUI::GetTotalOrderCost()
}
}

if (m_pSelectedCraft)
if (m_pSelectedCraft && includeDelivery)
{
bool needsToBePaid = true;
std::string presetName = m_pSelectedCraft->GetModuleAndPresetName();
Expand All @@ -778,7 +774,8 @@ float BuyMenuGUI::GetTotalOrderCost()
else
orderedItems[presetName] += 1;

if (m_OwnedItems.find(presetName) != m_OwnedItems.end() && m_OwnedItems[presetName] >= orderedItems[presetName])
auto itrFound = m_OwnedItems.find(presetName);
if (itrFound != m_OwnedItems.end() && itrFound->second >= orderedItems[presetName])
needsToBePaid = false;

if (needsToBePaid)
Expand All @@ -793,7 +790,7 @@ float BuyMenuGUI::GetTotalOrderCost()
totalCost += dynamic_cast<const MOSprite *>((*itr)->m_pEntity)->GetGoldValue(m_NativeTechModule, m_ForeignCostMult);

// Add the delivery craft's cost
if (m_pSelectedCraft)
if (m_pSelectedCraft && includeDelivery)
{
totalCost += dynamic_cast<const MOSprite *>(m_pSelectedCraft)->GetGoldValue(m_NativeTechModule, m_ForeignCostMult);
}
Expand Down
24 changes: 21 additions & 3 deletions Menus/BuyMenuGUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class BuyMenuGUI {
// Return value: Whetehr any items were put in the list at all. false if there are no
// items in the order listbox.

bool GetOrderList(std::list<const SceneObject *> &listToFill);
bool GetOrderList(std::list<const SceneObject *> &listToFill) const;


//////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -295,14 +295,32 @@ class BuyMenuGUI {
const SceneObject * GetDeliveryCraftPreset() { return m_pSelectedCraft; }


//////////////////////////////////////////////////////////////////////////////////////////
// Method: GetTotalCost
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Return the total cost of everything listed in the order box.
// Arguments: Whether or not to include delivery cost.
// Return value: The total cost in ounces of gold.

float GetTotalCost(bool includeDelivery = true) const;

//////////////////////////////////////////////////////////////////////////////////////////
// Method: GetTotalOrderCost
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Return teh total cost of everything listed in the order box.
// Description: Return the total cost of everything listed in the order box, including delivery costs.
// Arguments: None.
// Return value: The total cost in ounces of gold.

float GetTotalOrderCost() const { return GetTotalCost(true); };

//////////////////////////////////////////////////////////////////////////////////////////
// Method: GetTotalCartCost
//////////////////////////////////////////////////////////////////////////////////////////
// Description: Return the total cost of everything listed in the order box, excluding delivery costs.
// Arguments: None.
// Return value: The total cost in ounces of gold.

float GetTotalOrderCost();
float GetTotalCartCost() const { return GetTotalCost(false); }


/// <summary>
Expand Down

0 comments on commit 9bc6044

Please sign in to comment.