@@ -100,7 +100,7 @@ void BuyMenuGUI::Clear() {
100
100
m_pBuyButton = 0 ;
101
101
m_ClearOrderButton = nullptr ;
102
102
m_pSaveButton = 0 ;
103
- m_pClearButton = 0 ;
103
+ m_pDeleteButton = 0 ;
104
104
m_Loadouts.clear ();
105
105
m_SelectedLoadoutIndex = -1 ;
106
106
m_PurchaseMade = false ;
@@ -119,7 +119,7 @@ void BuyMenuGUI::Clear() {
119
119
m_LastEquipmentScrollPosition = -1 ;
120
120
m_LastMainScrollPosition = -1 ;
121
121
m_FirstMainTab = CRAFT;
122
- m_LastMainTab = PRESETS ;
122
+ m_LastMainTab = LOADOUTS ;
123
123
m_FirstEquipmentTab = TOOLS;
124
124
m_LastEquipmentTab = SHIELDS;
125
125
}
@@ -184,7 +184,7 @@ int BuyMenuGUI::Create(Controller* pController) {
184
184
m_pCategoryTabs[GUNS] = dynamic_cast <GUITab*>(m_pGUIController->GetControl (" GunsTab" ));
185
185
m_pCategoryTabs[BOMBS] = dynamic_cast <GUITab*>(m_pGUIController->GetControl (" BombsTab" ));
186
186
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 " ));
188
188
RefreshTabDisabledStates ();
189
189
190
190
m_pShopList = dynamic_cast <GUIListBox*>(m_pGUIController->GetControl (" CatalogLB" ));
@@ -204,9 +204,9 @@ int BuyMenuGUI::Create(Controller* pController) {
204
204
m_pBuyButton = dynamic_cast <GUIButton*>(m_pGUIController->GetControl (" BuyButton" ));
205
205
m_ClearOrderButton = dynamic_cast <GUIButton*>(m_pGUIController->GetControl (" OrderClearButton" ));
206
206
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 " ));
208
208
m_pSaveButton->SetVisible (false );
209
- m_pClearButton ->SetVisible (false );
209
+ m_pDeleteButton ->SetVisible (false );
210
210
211
211
// If we're not split screen horizontally, then stretch out the layout for all the relevant controls
212
212
int stretchAmount = g_WindowMan.GetResY () / 2 ;
@@ -726,7 +726,7 @@ void BuyMenuGUI::RefreshTabDisabledStates() {
726
726
m_pCategoryTabs[GUNS]->SetEnabled (smartBuyMenuNavigationDisabled || m_SelectingEquipment);
727
727
m_pCategoryTabs[BOMBS]->SetEnabled (smartBuyMenuNavigationDisabled || m_SelectingEquipment);
728
728
m_pCategoryTabs[SHIELDS]->SetEnabled (smartBuyMenuNavigationDisabled || m_SelectingEquipment);
729
- m_pCategoryTabs[PRESETS ]->SetEnabled (smartBuyMenuNavigationDisabled || !m_SelectingEquipment);
729
+ m_pCategoryTabs[LOADOUTS ]->SetEnabled (smartBuyMenuNavigationDisabled || !m_SelectingEquipment);
730
730
}
731
731
732
732
void BuyMenuGUI::Update () {
@@ -1022,12 +1022,12 @@ void BuyMenuGUI::Update() {
1022
1022
}
1023
1023
1024
1024
// ///////////////////////////////////////
1025
- // PRESETS BUTTONS focus
1025
+ // LOADOUTS BUTTONS focus
1026
1026
1027
1027
if (m_MenuFocus == SETBUTTONS) {
1028
1028
if (m_FocusChange) {
1029
1029
// Set the correct special Sets category so the sets buttons show up
1030
- m_MenuCategory = PRESETS ;
1030
+ m_MenuCategory = LOADOUTS ;
1031
1031
CategoryChange ();
1032
1032
m_pSaveButton->SetFocus ();
1033
1033
m_FocusChange = 0 ;
@@ -1036,12 +1036,12 @@ void BuyMenuGUI::Update() {
1036
1036
if (m_pController->IsState (PRESS_FACEBUTTON)) {
1037
1037
if (m_pSaveButton->HasFocus ())
1038
1038
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 ) {
1040
1040
m_Loadouts.erase (m_Loadouts.begin () + m_SelectedLoadoutIndex);
1041
1041
// Update the list of loadout presets so the removal shows up
1042
1042
CategoryChange ();
1043
1043
// Set focus back on the save button (CatChange changed it)
1044
- m_pClearButton ->SetFocus ();
1044
+ m_pDeleteButton ->SetFocus ();
1045
1045
m_SelectedLoadoutIndex = -1 ;
1046
1046
}
1047
1047
g_GUISound.ItemChangeSound ()->Play (m_pController->GetPlayer ());
@@ -1052,15 +1052,15 @@ void BuyMenuGUI::Update() {
1052
1052
if (m_pSaveButton->HasFocus ()) {
1053
1053
m_MenuFocus = CATEGORIES;
1054
1054
m_FocusChange = 1 ;
1055
- } else if (m_pClearButton ->HasFocus ()) {
1055
+ } else if (m_pDeleteButton ->HasFocus ()) {
1056
1056
m_pSaveButton->SetFocus ();
1057
1057
g_GUISound.SelectionChangeSound ()->Play (m_pController->GetPlayer ());
1058
1058
}
1059
1059
} else if (pressDown) {
1060
1060
if (m_pSaveButton->HasFocus ()) {
1061
- m_pClearButton ->SetFocus ();
1061
+ m_pDeleteButton ->SetFocus ();
1062
1062
g_GUISound.SelectionChangeSound ()->Play (m_pController->GetPlayer ());
1063
- } else if (m_pClearButton ->HasFocus ())
1063
+ } else if (m_pDeleteButton ->HasFocus ())
1064
1064
g_GUISound.UserErrorSound ()->Play (m_pController->GetPlayer ());
1065
1065
}
1066
1066
}
@@ -1115,7 +1115,25 @@ void BuyMenuGUI::Update() {
1115
1115
}
1116
1116
1117
1117
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) {
1119
1137
m_ListItemIndex++;
1120
1138
// Loop around
1121
1139
if (m_ListItemIndex >= listSize)
@@ -1187,7 +1205,7 @@ void BuyMenuGUI::Update() {
1187
1205
}
1188
1206
}
1189
1207
} else if (pItem->m_ExtraIndex != -1 ) {
1190
- if (m_MenuCategory == PRESETS ) {
1208
+ if (m_MenuCategory == LOADOUTS ) {
1191
1209
// This is a loadout preset, so get the description from the preset
1192
1210
// Add preset name at the begining to differentiate loadouts from user-defined presets
1193
1211
Loadout& loadout = m_Loadouts[pItem->m_ExtraIndex ];
@@ -1261,7 +1279,7 @@ void BuyMenuGUI::Update() {
1261
1279
}
1262
1280
1263
1281
// 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 ) {
1265
1283
// User pressed on a module group item; toggle its expansion!
1266
1284
if (pItem && pItem->m_ExtraIndex >= 0 ) {
1267
1285
// Make appropriate sound
@@ -1277,7 +1295,7 @@ void BuyMenuGUI::Update() {
1277
1295
CategoryChange (false );
1278
1296
}
1279
1297
// 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 ) {
1281
1299
// Beep if there's an error
1282
1300
if (!DeployLoadout (m_ListItemIndex))
1283
1301
g_GUISound.UserErrorSound ()->Play (m_pController->GetPlayer ());
@@ -1314,6 +1332,19 @@ void BuyMenuGUI::Update() {
1314
1332
UpdateTotalPassengersLabel (dynamic_cast <const ACraft*>(m_pSelectedCraft), m_pCraftPassengersLabel);
1315
1333
UpdateTotalMassLabel (dynamic_cast <const ACraft*>(m_pSelectedCraft), m_pCraftMassLabel);
1316
1334
}
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
+ }
1317
1348
}
1318
1349
1319
1350
// ///////////////////////////////////////
@@ -1559,8 +1590,8 @@ void BuyMenuGUI::Update() {
1559
1590
}
1560
1591
1561
1592
// CLEAR button clicks
1562
- if (anEvent.GetControl () == m_pClearButton ) {
1563
- m_pClearButton ->SetFocus ();
1593
+ if (anEvent.GetControl () == m_pDeleteButton ) {
1594
+ m_pDeleteButton ->SetFocus ();
1564
1595
if (m_SelectedLoadoutIndex != -1 ) {
1565
1596
m_Loadouts.erase (m_Loadouts.begin () + m_SelectedLoadoutIndex);
1566
1597
// Update the list of loadout presets so the removal shows up
@@ -1570,7 +1601,7 @@ void BuyMenuGUI::Update() {
1570
1601
m_SelectedLoadoutIndex = -1 ;
1571
1602
}
1572
1603
// Set focus back on the clear button (CatChange changed it)
1573
- m_pClearButton ->SetFocus ();
1604
+ m_pDeleteButton ->SetFocus ();
1574
1605
m_MenuFocus = SETBUTTONS;
1575
1606
// m_FocusChange = -1;
1576
1607
g_GUISound.ItemChangeSound ()->Play (m_pController->GetPlayer ());
@@ -1614,14 +1645,14 @@ void BuyMenuGUI::Update() {
1614
1645
// Events on the Shop List
1615
1646
1616
1647
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 ) {
1618
1649
m_pShopList->SetFocus ();
1619
1650
m_MenuFocus = ITEMS;
1620
1651
1621
1652
GUIListPanel::Item* pItem = m_pShopList->GetItem (mousePosX, mousePosY);
1622
1653
1623
1654
// If the player clicked on a loadout preset, deploy it
1624
- if (pItem && m_MenuCategory == PRESETS ) {
1655
+ if (pItem && m_MenuCategory == LOADOUTS ) {
1625
1656
// Beep if there's an error
1626
1657
if (!DeployLoadout (m_ListItemIndex)) {
1627
1658
g_GUISound.UserErrorSound ()->Play (m_pController->GetPlayer ());
@@ -1703,6 +1734,24 @@ void BuyMenuGUI::Update() {
1703
1734
GUIListPanel::Item* pItem = m_pShopList->GetItem (mousePosX, mousePosY);
1704
1735
if (pItem) {
1705
1736
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
+
1706
1755
// Don't let mouse movement change the index if it's still hovering inside the same item.
1707
1756
// This is to avoid erratic selection curosr if using both mouse and keyboard to work the menu
1708
1757
m_LastHoveredMouseIndex = pItem->m_ID ;
@@ -1716,6 +1765,17 @@ void BuyMenuGUI::Update() {
1716
1765
}
1717
1766
}
1718
1767
}
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
+ }
1719
1779
}
1720
1780
1721
1781
// /////////////////////////////////////////////
@@ -1821,17 +1881,25 @@ void BuyMenuGUI::Update() {
1821
1881
}
1822
1882
}
1823
1883
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.
1825
1885
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
+ }
1826
1890
m_DraggedItemIndex = -1 ;
1827
1891
m_IsDragging = false ;
1828
1892
}
1829
1893
}
1830
1894
}
1831
1895
1832
- if (m_MenuCategory == PRESETS ) {
1896
+ if (m_MenuCategory == LOADOUTS ) {
1833
1897
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
+ }
1835
1903
}
1836
1904
}
1837
1905
@@ -1901,10 +1969,10 @@ void BuyMenuGUI::CategoryChange(bool focusOnCategoryTabs) {
1901
1969
m_pShopList->ClearList ();
1902
1970
1903
1971
// 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 ) {
1905
1973
m_Logo->SetVisible (false );
1906
1974
m_pSaveButton->SetVisible (true );
1907
- m_pClearButton ->SetVisible (true );
1975
+ m_pDeleteButton ->SetVisible (true );
1908
1976
m_pShopList->SetHighlightAsIfAlwaysFocused (true );
1909
1977
// Add and done!
1910
1978
AddPresetsToItemList ();
@@ -1914,7 +1982,7 @@ void BuyMenuGUI::CategoryChange(bool focusOnCategoryTabs) {
1914
1982
else {
1915
1983
m_Logo->SetVisible (true );
1916
1984
m_pSaveButton->SetVisible (false );
1917
- m_pClearButton ->SetVisible (false );
1985
+ m_pDeleteButton ->SetVisible (false );
1918
1986
m_pShopList->SetHighlightAsIfAlwaysFocused (false );
1919
1987
}
1920
1988
0 commit comments