Skip to content

Commit 9bc6044

Browse files
committed
Added buy menu bindings to get cart info
1 parent ef29fec commit 9bc6044

File tree

5 files changed

+49
-15
lines changed

5 files changed

+49
-15
lines changed

Lua/LuaAdapterDefinitions.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,12 @@ namespace RTE {
360360
};
361361
#pragma endregion
362362

363+
#pragma region BuyMenuGUI Lua Adapters
364+
struct LuaAdaptersBuyMenuGUI {
365+
static std::list<const SceneObject *> * GetOrderList(const BuyMenuGUI *luaSelfObject);
366+
};
367+
#pragma endregion
368+
363369
#pragma region PieMenu Lua Adapters
364370
struct LuaAdaptersPieMenu {
365371
static bool AddPieSlice(PieMenu *luaSelfObject, PieSlice *pieSliceToAdd, const Entity *pieSliceOriginalSource);

Lua/LuaAdapters.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,14 @@ namespace RTE {
422422
}
423423
}
424424

425+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
426+
427+
std::list<const SceneObject *> * LuaAdaptersBuyMenuGUI::GetOrderList(const BuyMenuGUI *luaSelfObject) {
428+
auto* orderList = new std::list<const SceneObject *>();
429+
luaSelfObject->GetOrderList(*orderList);
430+
return orderList;
431+
}
432+
425433
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
426434

427435
Attachable * LuaAdaptersAttachable::RemoveFromParent1(Attachable *luaSelfObject) {

Lua/LuaBindingsGUI.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,12 @@ namespace RTE {
6767
.def("SetBannerImage", &BuyMenuGUI::SetBannerImage)
6868
.def("SetLogoImage", &BuyMenuGUI::SetLogoImage)
6969
.def("ClearCartList", &BuyMenuGUI::ClearCartList)
70-
.def("LoadDefaultLoadoutToCart", &BuyMenuGUI::LoadDefaultLoadoutToCart);
70+
.def("LoadDefaultLoadoutToCart", &BuyMenuGUI::LoadDefaultLoadoutToCart)
71+
.def("GetOrderList", &LuaAdaptersBuyMenuGUI::GetOrderList, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator)
72+
.def("GetTotalCartCost", &BuyMenuGUI::GetTotalCartCost)
73+
.def("GetTotalOrderCost", &BuyMenuGUI::GetTotalOrderCost)
74+
.def("GetTotalOrderMass", &BuyMenuGUI::GetTotalOrderMass)
75+
.def("GetTotalOrderPassengers", &BuyMenuGUI::GetTotalOrderPassengers);
7176
}
7277

7378
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Menus/BuyMenuGUI.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ void BuyMenuGUI::SetModuleExpanded(int whichModule, bool expanded)
706706
//////////////////////////////////////////////////////////////////////////////////////////
707707
// Description: Return the list of things currently in the purchase order list box.
708708

709-
bool BuyMenuGUI::GetOrderList(std::list<const SceneObject *> &listToFill)
709+
bool BuyMenuGUI::GetOrderList(std::list<const SceneObject *> &listToFill) const
710710
{
711711
if (m_pCartList->GetItemList()->empty())
712712
return false;
@@ -736,12 +736,7 @@ bool BuyMenuGUI::CommitPurchase(std::string presetName)
736736
return false;
737737
}
738738

739-
//////////////////////////////////////////////////////////////////////////////////////////
740-
// Method: GetTotalOrderCost
741-
//////////////////////////////////////////////////////////////////////////////////////////
742-
// Description: Return teh total cost of everything listed in the order box.
743-
744-
float BuyMenuGUI::GetTotalOrderCost()
739+
float BuyMenuGUI::GetTotalCost(bool includeDelivery) const
745740
{
746741
float totalCost = 0;
747742

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

762-
if (m_OwnedItems.find(presetName) != m_OwnedItems.end() && m_OwnedItems[presetName] >= orderedItems[presetName])
757+
auto itrFound = m_OwnedItems.find(presetName);
758+
if (itrFound != m_OwnedItems.end() && itrFound->second >= orderedItems[presetName])
763759
needsToBePaid = false;
764760

765761
if (needsToBePaid)
@@ -768,7 +764,7 @@ float BuyMenuGUI::GetTotalOrderCost()
768764
}
769765
}
770766

771-
if (m_pSelectedCraft)
767+
if (m_pSelectedCraft && includeDelivery)
772768
{
773769
bool needsToBePaid = true;
774770
std::string presetName = m_pSelectedCraft->GetModuleAndPresetName();
@@ -778,7 +774,8 @@ float BuyMenuGUI::GetTotalOrderCost()
778774
else
779775
orderedItems[presetName] += 1;
780776

781-
if (m_OwnedItems.find(presetName) != m_OwnedItems.end() && m_OwnedItems[presetName] >= orderedItems[presetName])
777+
auto itrFound = m_OwnedItems.find(presetName);
778+
if (itrFound != m_OwnedItems.end() && itrFound->second >= orderedItems[presetName])
782779
needsToBePaid = false;
783780

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

795792
// Add the delivery craft's cost
796-
if (m_pSelectedCraft)
793+
if (m_pSelectedCraft && includeDelivery)
797794
{
798795
totalCost += dynamic_cast<const MOSprite *>(m_pSelectedCraft)->GetGoldValue(m_NativeTechModule, m_ForeignCostMult);
799796
}

Menus/BuyMenuGUI.h

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ class BuyMenuGUI {
261261
// Return value: Whetehr any items were put in the list at all. false if there are no
262262
// items in the order listbox.
263263

264-
bool GetOrderList(std::list<const SceneObject *> &listToFill);
264+
bool GetOrderList(std::list<const SceneObject *> &listToFill) const;
265265

266266

267267
//////////////////////////////////////////////////////////////////////////////////////////
@@ -295,14 +295,32 @@ class BuyMenuGUI {
295295
const SceneObject * GetDeliveryCraftPreset() { return m_pSelectedCraft; }
296296

297297

298+
//////////////////////////////////////////////////////////////////////////////////////////
299+
// Method: GetTotalCost
300+
//////////////////////////////////////////////////////////////////////////////////////////
301+
// Description: Return the total cost of everything listed in the order box.
302+
// Arguments: Whether or not to include delivery cost.
303+
// Return value: The total cost in ounces of gold.
304+
305+
float GetTotalCost(bool includeDelivery = true) const;
306+
298307
//////////////////////////////////////////////////////////////////////////////////////////
299308
// Method: GetTotalOrderCost
300309
//////////////////////////////////////////////////////////////////////////////////////////
301-
// Description: Return teh total cost of everything listed in the order box.
310+
// Description: Return the total cost of everything listed in the order box, including delivery costs.
311+
// Arguments: None.
312+
// Return value: The total cost in ounces of gold.
313+
314+
float GetTotalOrderCost() const { return GetTotalCost(true); };
315+
316+
//////////////////////////////////////////////////////////////////////////////////////////
317+
// Method: GetTotalCartCost
318+
//////////////////////////////////////////////////////////////////////////////////////////
319+
// Description: Return the total cost of everything listed in the order box, excluding delivery costs.
302320
// Arguments: None.
303321
// Return value: The total cost in ounces of gold.
304322

305-
float GetTotalOrderCost();
323+
float GetTotalCartCost() const { return GetTotalCost(false); }
306324

307325

308326
/// <summary>

0 commit comments

Comments
 (0)