Skip to content

Commit d992d0c

Browse files
committed
Preset clear now deletes the currently selected preset instead of the last one in the list. Needs better UI but works in principle
1 parent e9907d7 commit d992d0c

File tree

4 files changed

+40
-18
lines changed

4 files changed

+40
-18
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
155155
- All vanilla scenario activities have had their settings polished, respecting settings which make sense and disabling settings which don't.
156156
You can now have fog of war in the test scene, and can no longer require path to orbit in Zero-G Diggers-Only One Man Army.
157157

158+
- The "Clear" Preset button in the Buy Menu now clears the currently selected loadout, instead of the last one in the list.
159+
158160
- Conquest activities will once again fall-back to using base dropships and rockets if a random selection of the selected tech's craft can't find one capable of carrying passengers and/or cargo.
159161

160162
- `MovableMan:OpenAllDoors()`, when passed `NOTEAM`, will now open/close doors specifically for `NOTEAM` (instead of all doors).

Source/Entities/Loadout.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ int Loadout::Create(const Loadout& reference) {
2929
m_Complete = reference.m_Complete;
3030
// These are preset instances, not owned by the reference or this.
3131
m_pDeliveryCraft = reference.m_pDeliveryCraft;
32+
33+
m_CargoItems.clear();
3234
for (std::list<const SceneObject*>::const_iterator itr = reference.m_CargoItems.begin(); itr != reference.m_CargoItems.end(); ++itr)
3335
m_CargoItems.push_back(*itr);
3436

Source/Menus/BuyMenuGUI.cpp

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ void BuyMenuGUI::Clear() {
102102
m_pSaveButton = 0;
103103
m_pClearButton = 0;
104104
m_Loadouts.clear();
105+
m_SelectedLoadoutIndex = -1;
105106
m_PurchaseMade = false;
106107

107108
m_EnforceMaxPassengersConstraint = true;
@@ -118,7 +119,7 @@ void BuyMenuGUI::Clear() {
118119
m_LastEquipmentScrollPosition = -1;
119120
m_LastMainScrollPosition = -1;
120121
m_FirstMainTab = CRAFT;
121-
m_LastMainTab = SETS;
122+
m_LastMainTab = PRESETS;
122123
m_FirstEquipmentTab = TOOLS;
123124
m_LastEquipmentTab = SHIELDS;
124125
}
@@ -183,7 +184,7 @@ int BuyMenuGUI::Create(Controller* pController) {
183184
m_pCategoryTabs[GUNS] = dynamic_cast<GUITab*>(m_pGUIController->GetControl("GunsTab"));
184185
m_pCategoryTabs[BOMBS] = dynamic_cast<GUITab*>(m_pGUIController->GetControl("BombsTab"));
185186
m_pCategoryTabs[SHIELDS] = dynamic_cast<GUITab*>(m_pGUIController->GetControl("ShieldsTab"));
186-
m_pCategoryTabs[SETS] = dynamic_cast<GUITab*>(m_pGUIController->GetControl("SetsTab"));
187+
m_pCategoryTabs[PRESETS] = dynamic_cast<GUITab*>(m_pGUIController->GetControl("SetsTab"));
187188
RefreshTabDisabledStates();
188189

189190
m_pShopList = dynamic_cast<GUIListBox*>(m_pGUIController->GetControl("CatalogLB"));
@@ -332,6 +333,7 @@ void BuyMenuGUI::DuplicateCartItem(const int itemIndex) {
332333
bool BuyMenuGUI::LoadAllLoadoutsFromFile() {
333334
// First clear out all loadouts
334335
m_Loadouts.clear();
336+
m_SelectedLoadoutIndex = -1;
335337
// Try to load the player's loadout settings from file, if there is one
336338
char loadoutPath[256];
337339

@@ -724,7 +726,7 @@ void BuyMenuGUI::RefreshTabDisabledStates() {
724726
m_pCategoryTabs[GUNS]->SetEnabled(smartBuyMenuNavigationDisabled || m_SelectingEquipment);
725727
m_pCategoryTabs[BOMBS]->SetEnabled(smartBuyMenuNavigationDisabled || m_SelectingEquipment);
726728
m_pCategoryTabs[SHIELDS]->SetEnabled(smartBuyMenuNavigationDisabled || m_SelectingEquipment);
727-
m_pCategoryTabs[SETS]->SetEnabled(smartBuyMenuNavigationDisabled || !m_SelectingEquipment);
729+
m_pCategoryTabs[PRESETS]->SetEnabled(smartBuyMenuNavigationDisabled || !m_SelectingEquipment);
728730
}
729731

730732
void BuyMenuGUI::Update() {
@@ -1020,12 +1022,12 @@ void BuyMenuGUI::Update() {
10201022
}
10211023

10221024
/////////////////////////////////////////
1023-
// SETS BUTTONS focus
1025+
// PRESETS BUTTONS focus
10241026

10251027
if (m_MenuFocus == SETBUTTONS) {
10261028
if (m_FocusChange) {
10271029
// Set the correct special Sets category so the sets buttons show up
1028-
m_MenuCategory = SETS;
1030+
m_MenuCategory = PRESETS;
10291031
CategoryChange();
10301032
m_pSaveButton->SetFocus();
10311033
m_FocusChange = 0;
@@ -1034,12 +1036,13 @@ void BuyMenuGUI::Update() {
10341036
if (m_pController->IsState(PRESS_FACEBUTTON)) {
10351037
if (m_pSaveButton->HasFocus())
10361038
SaveCurrentLoadout();
1037-
else if (m_pClearButton->HasFocus() && m_Loadouts.size() != 0) {
1038-
m_Loadouts.pop_back();
1039+
else if (m_pClearButton->HasFocus() && m_Loadouts.size() != 0 && m_SelectedLoadoutIndex != -1) {
1040+
m_Loadouts.erase(m_Loadouts.begin() + m_SelectedLoadoutIndex);
10391041
// Update the list of loadout presets so the removal shows up
10401042
CategoryChange();
10411043
// Set focus back on the save button (CatChange changed it)
10421044
m_pClearButton->SetFocus();
1045+
m_SelectedLoadoutIndex = -1;
10431046
}
10441047
g_GUISound.ItemChangeSound()->Play(m_pController->GetPlayer());
10451048
}
@@ -1222,7 +1225,7 @@ void BuyMenuGUI::Update() {
12221225
CategoryChange(false);
12231226
}
12241227
// User pressed on a loadout set, so load it into the menu
1225-
else if (pItem && m_MenuCategory == SETS) {
1228+
else if (pItem && m_MenuCategory == PRESETS) {
12261229
// Beep if there's an error
12271230
if (!DeployLoadout(m_ListItemIndex))
12281231
g_GUISound.UserErrorSound()->Play(m_pController->GetPlayer());
@@ -1506,12 +1509,14 @@ void BuyMenuGUI::Update() {
15061509
// CLEAR button clicks
15071510
if (anEvent.GetControl() == m_pClearButton) {
15081511
m_pClearButton->SetFocus();
1509-
if (!m_Loadouts.empty())
1510-
m_Loadouts.pop_back();
1511-
// Update the list of loadout presets so the removal shows up
1512-
CategoryChange();
1513-
// Save new loadout config to file
1514-
SaveAllLoadoutsToFile();
1512+
if (m_SelectedLoadoutIndex != -1) {
1513+
m_Loadouts.erase(m_Loadouts.begin() + m_SelectedLoadoutIndex);
1514+
// Update the list of loadout presets so the removal shows up
1515+
CategoryChange();
1516+
// Save new loadout config to file
1517+
SaveAllLoadoutsToFile();
1518+
m_SelectedLoadoutIndex = -1;
1519+
}
15151520
// Set focus back on the clear button (CatChange changed it)
15161521
m_pClearButton->SetFocus();
15171522
m_MenuFocus = SETBUTTONS;
@@ -1577,7 +1582,7 @@ void BuyMenuGUI::Update() {
15771582
CategoryChange(false);
15781583
}
15791584
// Special case: user clicked on a loadout set, so load it into the menu
1580-
else if (pItem && m_MenuCategory == SETS) {
1585+
else if (pItem && m_MenuCategory == PRESETS) {
15811586
// Beep if there's an error
15821587
if (!DeployLoadout(m_ListItemIndex))
15831588
g_GUISound.UserErrorSound()->Play(m_pController->GetPlayer());
@@ -1769,6 +1774,11 @@ void BuyMenuGUI::Update() {
17691774
}
17701775
}
17711776
}
1777+
1778+
if (m_MenuCategory == PRESETS) {
1779+
m_pSaveButton->SetEnabled(!m_pCartList->GetItemList()->empty());
1780+
m_pClearButton->SetEnabled(m_SelectedLoadoutIndex != -1);
1781+
}
17721782
}
17731783

17741784
void BuyMenuGUI::Draw(BITMAP* drawBitmap) const {
@@ -1837,7 +1847,7 @@ void BuyMenuGUI::CategoryChange(bool focusOnCategoryTabs) {
18371847
m_pShopList->ClearList();
18381848

18391849
// Hide/show the logo and special sets category buttons, and add all current presets to the list, and we're done.
1840-
if (m_MenuCategory == SETS) {
1850+
if (m_MenuCategory == PRESETS) {
18411851
m_Logo->SetVisible(false);
18421852
m_pSaveButton->SetVisible(true);
18431853
m_pClearButton->SetVisible(true);
@@ -1963,8 +1973,12 @@ void BuyMenuGUI::SaveCurrentLoadout() {
19631973
}
19641974

19651975
bool BuyMenuGUI::DeployLoadout(int index) {
1966-
if (index < 0 || index >= m_Loadouts.size())
1976+
if (index < 0 || index >= m_Loadouts.size()) {
1977+
m_SelectedLoadoutIndex = -1;
19671978
return false;
1979+
}
1980+
1981+
m_SelectedLoadoutIndex = index;
19681982

19691983
// Clear the cart, we're going to refill it with the selected loadout
19701984
m_pCartList->ClearList();
@@ -2138,6 +2152,8 @@ void BuyMenuGUI::AddObjectsToItemList(std::vector<std::list<Entity*>>& moduleLis
21382152
}
21392153

21402154
void BuyMenuGUI::AddPresetsToItemList() {
2155+
m_SelectedLoadoutIndex = -1;
2156+
21412157
GUIBitmap* pItemBitmap = 0;
21422158
std::string loadoutLabel;
21432159
float loadoutCost;

Source/Menus/BuyMenuGUI.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ namespace RTE {
364364
GUNS,
365365
BOMBS,
366366
SHIELDS,
367-
SETS,
367+
PRESETS,
368368
CATEGORYCOUNT
369369
};
370370

@@ -485,6 +485,8 @@ namespace RTE {
485485
GUIButton* m_pClearButton;
486486
// Sets of user-defined loadouts that can be selected quickly.
487487
std::vector<Loadout> m_Loadouts;
488+
// The selected loadout index, -1 if no loadout is selected
489+
int m_SelectedLoadoutIndex;
488490
// Purchase has been made
489491
bool m_PurchaseMade;
490492
int m_DeliveryWidth; //!< The width of the currently selected delivery craft, which will determine the width of the LZ marker.

0 commit comments

Comments
 (0)