Skip to content

Commit 78f0603

Browse files
committed
Click-drag to reorder loadouts
Renamed PRESETS -> Loadouts Renamed Clear -> Delete
1 parent e3a322c commit 78f0603

File tree

3 files changed

+104
-36
lines changed

3 files changed

+104
-36
lines changed

Data/Base.rte/GUIs/BuyMenuGUI.ini

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ Anchor = Left, Top
211211
Text = Shields
212212
Checked = False
213213

214-
[SetsTab]
214+
[LoadoutsTab]
215215
ControlType = TAB
216216
Parent = BuyGUIBox
217217
X = 2
@@ -220,9 +220,9 @@ Width = 57
220220
Height = 17
221221
Visible = True
222222
Enabled = True
223-
Name = SetsTab
223+
Name = LoadoutsTab
224224
Anchor = Left, Top
225-
Text = Presets
225+
Text = Loadouts
226226
Checked = False
227227

228228
[CargoLabel]
@@ -439,7 +439,7 @@ Name = SaveButton
439439
Anchor = Left, Top
440440
Text = Save
441441

442-
[ClearButton]
442+
[DeleteButton]
443443
ControlType = BUTTON
444444
Parent = BuyGUIBox
445445
X = 4
@@ -448,6 +448,6 @@ Width = 48
448448
Height = 18
449449
Visible = True
450450
Enabled = True
451-
Name = ClearButton
451+
Name = DeleteButton
452452
Anchor = Left, Top
453-
Text = Clear
453+
Text = Delete

Source/Menus/BuyMenuGUI.cpp

Lines changed: 96 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void BuyMenuGUI::Clear() {
100100
m_pBuyButton = 0;
101101
m_ClearOrderButton = nullptr;
102102
m_pSaveButton = 0;
103-
m_pClearButton = 0;
103+
m_pDeleteButton = 0;
104104
m_Loadouts.clear();
105105
m_SelectedLoadoutIndex = -1;
106106
m_PurchaseMade = false;
@@ -119,7 +119,7 @@ void BuyMenuGUI::Clear() {
119119
m_LastEquipmentScrollPosition = -1;
120120
m_LastMainScrollPosition = -1;
121121
m_FirstMainTab = CRAFT;
122-
m_LastMainTab = PRESETS;
122+
m_LastMainTab = LOADOUTS;
123123
m_FirstEquipmentTab = TOOLS;
124124
m_LastEquipmentTab = SHIELDS;
125125
}
@@ -184,7 +184,7 @@ int BuyMenuGUI::Create(Controller* pController) {
184184
m_pCategoryTabs[GUNS] = dynamic_cast<GUITab*>(m_pGUIController->GetControl("GunsTab"));
185185
m_pCategoryTabs[BOMBS] = dynamic_cast<GUITab*>(m_pGUIController->GetControl("BombsTab"));
186186
m_pCategoryTabs[SHIELDS] = dynamic_cast<GUITab*>(m_pGUIController->GetControl("ShieldsTab"));
187-
m_pCategoryTabs[PRESETS] = dynamic_cast<GUITab*>(m_pGUIController->GetControl("SetsTab"));
187+
m_pCategoryTabs[LOADOUTS] = dynamic_cast<GUITab*>(m_pGUIController->GetControl("LoadoutsTab"));
188188
RefreshTabDisabledStates();
189189

190190
m_pShopList = dynamic_cast<GUIListBox*>(m_pGUIController->GetControl("CatalogLB"));
@@ -204,9 +204,9 @@ int BuyMenuGUI::Create(Controller* pController) {
204204
m_pBuyButton = dynamic_cast<GUIButton*>(m_pGUIController->GetControl("BuyButton"));
205205
m_ClearOrderButton = dynamic_cast<GUIButton*>(m_pGUIController->GetControl("OrderClearButton"));
206206
m_pSaveButton = dynamic_cast<GUIButton*>(m_pGUIController->GetControl("SaveButton"));
207-
m_pClearButton = dynamic_cast<GUIButton*>(m_pGUIController->GetControl("ClearButton"));
207+
m_pDeleteButton = dynamic_cast<GUIButton*>(m_pGUIController->GetControl("DeleteButton"));
208208
m_pSaveButton->SetVisible(false);
209-
m_pClearButton->SetVisible(false);
209+
m_pDeleteButton->SetVisible(false);
210210

211211
// If we're not split screen horizontally, then stretch out the layout for all the relevant controls
212212
int stretchAmount = g_WindowMan.GetResY() / 2;
@@ -726,7 +726,7 @@ void BuyMenuGUI::RefreshTabDisabledStates() {
726726
m_pCategoryTabs[GUNS]->SetEnabled(smartBuyMenuNavigationDisabled || m_SelectingEquipment);
727727
m_pCategoryTabs[BOMBS]->SetEnabled(smartBuyMenuNavigationDisabled || m_SelectingEquipment);
728728
m_pCategoryTabs[SHIELDS]->SetEnabled(smartBuyMenuNavigationDisabled || m_SelectingEquipment);
729-
m_pCategoryTabs[PRESETS]->SetEnabled(smartBuyMenuNavigationDisabled || !m_SelectingEquipment);
729+
m_pCategoryTabs[LOADOUTS]->SetEnabled(smartBuyMenuNavigationDisabled || !m_SelectingEquipment);
730730
}
731731

732732
void BuyMenuGUI::Update() {
@@ -1022,12 +1022,12 @@ void BuyMenuGUI::Update() {
10221022
}
10231023

10241024
/////////////////////////////////////////
1025-
// PRESETS BUTTONS focus
1025+
// LOADOUTS BUTTONS focus
10261026

10271027
if (m_MenuFocus == SETBUTTONS) {
10281028
if (m_FocusChange) {
10291029
// Set the correct special Sets category so the sets buttons show up
1030-
m_MenuCategory = PRESETS;
1030+
m_MenuCategory = LOADOUTS;
10311031
CategoryChange();
10321032
m_pSaveButton->SetFocus();
10331033
m_FocusChange = 0;
@@ -1036,12 +1036,12 @@ void BuyMenuGUI::Update() {
10361036
if (m_pController->IsState(PRESS_FACEBUTTON)) {
10371037
if (m_pSaveButton->HasFocus())
10381038
SaveCurrentLoadout();
1039-
else if (m_pClearButton->HasFocus() && m_Loadouts.size() != 0 && m_SelectedLoadoutIndex != -1) {
1039+
else if (m_pDeleteButton->HasFocus() && m_Loadouts.size() != 0 && m_SelectedLoadoutIndex != -1) {
10401040
m_Loadouts.erase(m_Loadouts.begin() + m_SelectedLoadoutIndex);
10411041
// Update the list of loadout presets so the removal shows up
10421042
CategoryChange();
10431043
// Set focus back on the save button (CatChange changed it)
1044-
m_pClearButton->SetFocus();
1044+
m_pDeleteButton->SetFocus();
10451045
m_SelectedLoadoutIndex = -1;
10461046
}
10471047
g_GUISound.ItemChangeSound()->Play(m_pController->GetPlayer());
@@ -1052,15 +1052,15 @@ void BuyMenuGUI::Update() {
10521052
if (m_pSaveButton->HasFocus()) {
10531053
m_MenuFocus = CATEGORIES;
10541054
m_FocusChange = 1;
1055-
} else if (m_pClearButton->HasFocus()) {
1055+
} else if (m_pDeleteButton->HasFocus()) {
10561056
m_pSaveButton->SetFocus();
10571057
g_GUISound.SelectionChangeSound()->Play(m_pController->GetPlayer());
10581058
}
10591059
} else if (pressDown) {
10601060
if (m_pSaveButton->HasFocus()) {
1061-
m_pClearButton->SetFocus();
1061+
m_pDeleteButton->SetFocus();
10621062
g_GUISound.SelectionChangeSound()->Play(m_pController->GetPlayer());
1063-
} else if (m_pClearButton->HasFocus())
1063+
} else if (m_pDeleteButton->HasFocus())
10641064
g_GUISound.UserErrorSound()->Play(m_pController->GetPlayer());
10651065
}
10661066
}
@@ -1115,7 +1115,25 @@ void BuyMenuGUI::Update() {
11151115
}
11161116

11171117
int listSize = m_pShopList->GetItemList()->size();
1118-
if (pressDown) {
1118+
if (m_MenuCategory == LOADOUTS && m_DraggedItemIndex != -1) {
1119+
if (pressDown && m_DraggedItemIndex < listSize - 1) {
1120+
m_IsDragging = true;
1121+
std::swap((*m_pShopList->GetItemList())[m_DraggedItemIndex], (*m_pShopList->GetItemList())[m_DraggedItemIndex + 1]);
1122+
std::swap((*m_pShopList->GetItemList())[m_DraggedItemIndex + 1]->m_ID, (*m_pShopList->GetItemList())[m_DraggedItemIndex]->m_ID);
1123+
m_ListItemIndex = ++m_DraggedItemIndex;
1124+
m_SelectedLoadoutIndex = -1;
1125+
m_pShopList->SetSelectedIndex(m_ListItemIndex);
1126+
g_GUISound.SelectionChangeSound()->Play(m_pController->GetPlayer());
1127+
} else if (pressUp && m_DraggedItemIndex > 0) {
1128+
m_IsDragging = true;
1129+
std::swap((*m_pShopList->GetItemList())[m_DraggedItemIndex], (*m_pShopList->GetItemList())[m_DraggedItemIndex - 1]);
1130+
std::swap((*m_pShopList->GetItemList())[m_DraggedItemIndex - 1]->m_ID, (*m_pShopList->GetItemList())[m_DraggedItemIndex]->m_ID);
1131+
m_ListItemIndex = --m_DraggedItemIndex;
1132+
m_SelectedLoadoutIndex = -1;
1133+
m_pShopList->SetSelectedIndex(m_ListItemIndex);
1134+
g_GUISound.SelectionChangeSound()->Play(m_pController->GetPlayer());
1135+
}
1136+
} else if (pressDown) {
11191137
m_ListItemIndex++;
11201138
// Loop around
11211139
if (m_ListItemIndex >= listSize)
@@ -1187,7 +1205,7 @@ void BuyMenuGUI::Update() {
11871205
}
11881206
}
11891207
} else if (pItem->m_ExtraIndex != -1) {
1190-
if (m_MenuCategory == PRESETS) {
1208+
if (m_MenuCategory == LOADOUTS) {
11911209
// This is a loadout preset, so get the description from the preset
11921210
// Add preset name at the begining to differentiate loadouts from user-defined presets
11931211
Loadout& loadout = m_Loadouts[pItem->m_ExtraIndex];
@@ -1261,7 +1279,7 @@ void BuyMenuGUI::Update() {
12611279
}
12621280

12631281
// User selected to add an item to cart list!
1264-
if (m_pController->IsState(PRESS_FACEBUTTON)) {
1282+
if (m_pController->IsState(PRESS_FACEBUTTON) && !m_IsDragging) {
12651283
// User pressed on a module group item; toggle its expansion!
12661284
if (pItem && pItem->m_ExtraIndex >= 0) {
12671285
// Make appropriate sound
@@ -1277,7 +1295,7 @@ void BuyMenuGUI::Update() {
12771295
CategoryChange(false);
12781296
}
12791297
// User pressed on a loadout set, so load it into the menu
1280-
else if (pItem && m_MenuCategory == PRESETS) {
1298+
else if (pItem && m_MenuCategory == LOADOUTS) {
12811299
// Beep if there's an error
12821300
if (!DeployLoadout(m_ListItemIndex))
12831301
g_GUISound.UserErrorSound()->Play(m_pController->GetPlayer());
@@ -1314,6 +1332,19 @@ void BuyMenuGUI::Update() {
13141332
UpdateTotalPassengersLabel(dynamic_cast<const ACraft*>(m_pSelectedCraft), m_pCraftPassengersLabel);
13151333
UpdateTotalMassLabel(dynamic_cast<const ACraft*>(m_pSelectedCraft), m_pCraftMassLabel);
13161334
}
1335+
1336+
if (m_MenuCategory == LOADOUTS) {
1337+
bool isKeyboardControlled = !m_pController->IsMouseControlled() && !m_pController->IsGamepadControlled();
1338+
if (isKeyboardControlled ? m_pController->IsState(AIM_SHARP) : m_pController->IsState(PRESS_FACEBUTTON)) {
1339+
m_DraggedItemIndex = m_pCartList->GetSelectedIndex();
1340+
} else if (m_pController->IsState(RELEASE_FACEBUTTON)) {
1341+
m_DraggedItemIndex = -1;
1342+
m_IsDragging = false;
1343+
}
1344+
} else {
1345+
m_DraggedItemIndex = -1;
1346+
m_IsDragging = false;
1347+
}
13171348
}
13181349

13191350
/////////////////////////////////////////
@@ -1559,8 +1590,8 @@ void BuyMenuGUI::Update() {
15591590
}
15601591

15611592
// CLEAR button clicks
1562-
if (anEvent.GetControl() == m_pClearButton) {
1563-
m_pClearButton->SetFocus();
1593+
if (anEvent.GetControl() == m_pDeleteButton) {
1594+
m_pDeleteButton->SetFocus();
15641595
if (m_SelectedLoadoutIndex != -1) {
15651596
m_Loadouts.erase(m_Loadouts.begin() + m_SelectedLoadoutIndex);
15661597
// Update the list of loadout presets so the removal shows up
@@ -1570,7 +1601,7 @@ void BuyMenuGUI::Update() {
15701601
m_SelectedLoadoutIndex = -1;
15711602
}
15721603
// Set focus back on the clear button (CatChange changed it)
1573-
m_pClearButton->SetFocus();
1604+
m_pDeleteButton->SetFocus();
15741605
m_MenuFocus = SETBUTTONS;
15751606
// m_FocusChange = -1;
15761607
g_GUISound.ItemChangeSound()->Play(m_pController->GetPlayer());
@@ -1614,14 +1645,14 @@ void BuyMenuGUI::Update() {
16141645
// Events on the Shop List
16151646

16161647
if (anEvent.GetControl() == m_pShopList) {
1617-
if (anEvent.GetMsg() == GUIListBox::MouseDown && (anEvent.GetData() & GUIListBox::MOUSE_LEFT)) {
1648+
if (anEvent.GetMsg() == GUIListBox::MouseUp && (anEvent.GetData() & GUIListBox::MOUSE_LEFT) && !m_IsDragging) {
16181649
m_pShopList->SetFocus();
16191650
m_MenuFocus = ITEMS;
16201651

16211652
GUIListPanel::Item* pItem = m_pShopList->GetItem(mousePosX, mousePosY);
16221653

16231654
// If the player clicked on a loadout preset, deploy it
1624-
if (pItem && m_MenuCategory == PRESETS) {
1655+
if (pItem && m_MenuCategory == LOADOUTS) {
16251656
// Beep if there's an error
16261657
if (!DeployLoadout(m_ListItemIndex)) {
16271658
g_GUISound.UserErrorSound()->Play(m_pController->GetPlayer());
@@ -1703,6 +1734,24 @@ void BuyMenuGUI::Update() {
17031734
GUIListPanel::Item* pItem = m_pShopList->GetItem(mousePosX, mousePosY);
17041735
if (pItem) {
17051736
if (m_LastHoveredMouseIndex != pItem->m_ID) {
1737+
if (m_MenuCategory == LOADOUTS && m_DraggedItemIndex != -1 && m_DraggedItemIndex != pItem->m_ID) {
1738+
m_IsDragging = true;
1739+
int start = std::min(m_DraggedItemIndex, pItem->m_ID);
1740+
int end = std::max(m_DraggedItemIndex, pItem->m_ID);
1741+
int direction = pItem->m_ID > m_DraggedItemIndex ? 1 : -1;
1742+
for (int i = start; i < end; i++) {
1743+
int oldIndex = m_DraggedItemIndex;
1744+
if (oldIndex + direction < 0 || oldIndex + direction >= m_pShopList->GetItemList()->size()) {
1745+
break;
1746+
}
1747+
1748+
m_DraggedItemIndex = oldIndex + direction;
1749+
m_SelectedLoadoutIndex = m_DraggedItemIndex;
1750+
std::swap((*m_pShopList->GetItemList())[oldIndex], (*m_pShopList->GetItemList())[oldIndex + direction]);
1751+
std::swap((*m_pShopList->GetItemList())[oldIndex + direction]->m_ID, (*m_pShopList->GetItemList())[oldIndex]->m_ID);
1752+
}
1753+
}
1754+
17061755
// Don't let mouse movement change the index if it's still hovering inside the same item.
17071756
// This is to avoid erratic selection curosr if using both mouse and keyboard to work the menu
17081757
m_LastHoveredMouseIndex = pItem->m_ID;
@@ -1716,6 +1765,17 @@ void BuyMenuGUI::Update() {
17161765
}
17171766
}
17181767
}
1768+
1769+
if (anEvent.GetMsg() == GUIListBox::MouseDown) {
1770+
m_pShopList->SetFocus();
1771+
m_MenuFocus = ITEMS;
1772+
m_ListItemIndex = m_pShopList->GetSelectedIndex();
1773+
m_pShopList->ScrollToSelected();
1774+
if (m_MenuCategory == LOADOUTS && anEvent.GetData() & GUIListBox::MOUSE_LEFT) {
1775+
m_DraggedItemIndex = m_pShopList->GetSelectedIndex();
1776+
m_SelectedLoadoutIndex = m_ListItemIndex;
1777+
}
1778+
}
17191779
}
17201780

17211781
///////////////////////////////////////////////
@@ -1821,17 +1881,25 @@ void BuyMenuGUI::Update() {
18211881
}
18221882
}
18231883

1824-
// We do this down here, outside the m_pCartList control, because if we have a mouse-up event even outside the cart, we should stop dragging. We also check UInputMan in case the mouse is released entirely outside of the buy menu.
1884+
// We do this down here, because if we have a mouse-up event even outside the cart, we should stop dragging. We also check UInputMan in case the mouse is released entirely outside of the buy menu.
18251885
if ((anEvent.GetMsg() == GUIListBox::MouseUp && (anEvent.GetData() & GUIListBox::MOUSE_LEFT)) || g_UInputMan.MouseButtonReleased(MouseButtons::MOUSE_LEFT, m_pController->GetPlayer())) {
1886+
if (m_MenuCategory == LOADOUTS) {
1887+
// Might've reordered the loadout list, so we need to save the new order
1888+
SaveAllLoadoutsToFile();
1889+
}
18261890
m_DraggedItemIndex = -1;
18271891
m_IsDragging = false;
18281892
}
18291893
}
18301894
}
18311895

1832-
if (m_MenuCategory == PRESETS) {
1896+
if (m_MenuCategory == LOADOUTS) {
18331897
m_pSaveButton->SetEnabled(!m_pCartList->GetItemList()->empty());
1834-
m_pClearButton->SetEnabled(m_SelectedLoadoutIndex != -1);
1898+
m_pDeleteButton->SetEnabled(m_SelectedLoadoutIndex != -1);
1899+
if (m_SelectedLoadoutIndex != -1) {
1900+
// Always highlight the currently selected loadout as if it's focused
1901+
m_pShopList->SetSelectedIndex(m_SelectedLoadoutIndex);
1902+
}
18351903
}
18361904
}
18371905

@@ -1901,10 +1969,10 @@ void BuyMenuGUI::CategoryChange(bool focusOnCategoryTabs) {
19011969
m_pShopList->ClearList();
19021970

19031971
// Hide/show the logo and special sets category buttons, and add all current presets to the list, and we're done.
1904-
if (m_MenuCategory == PRESETS) {
1972+
if (m_MenuCategory == LOADOUTS) {
19051973
m_Logo->SetVisible(false);
19061974
m_pSaveButton->SetVisible(true);
1907-
m_pClearButton->SetVisible(true);
1975+
m_pDeleteButton->SetVisible(true);
19081976
m_pShopList->SetHighlightAsIfAlwaysFocused(true);
19091977
// Add and done!
19101978
AddPresetsToItemList();
@@ -1914,7 +1982,7 @@ void BuyMenuGUI::CategoryChange(bool focusOnCategoryTabs) {
19141982
else {
19151983
m_Logo->SetVisible(true);
19161984
m_pSaveButton->SetVisible(false);
1917-
m_pClearButton->SetVisible(false);
1985+
m_pDeleteButton->SetVisible(false);
19181986
m_pShopList->SetHighlightAsIfAlwaysFocused(false);
19191987
}
19201988

Source/Menus/BuyMenuGUI.h

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

@@ -482,7 +482,7 @@ namespace RTE {
482482
// The save set button
483483
GUIButton* m_pSaveButton;
484484
// The clear set button
485-
GUIButton* m_pClearButton;
485+
GUIButton* m_pDeleteButton;
486486
// Sets of user-defined loadouts that can be selected quickly.
487487
std::vector<Loadout> m_Loadouts;
488488
// The selected loadout index, -1 if no loadout is selected

0 commit comments

Comments
 (0)