Skip to content

Commit 6690c81

Browse files
committed
Fixed to make keyboard work properly
1 parent 5f37234 commit 6690c81

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

Source/Menus/BuyMenuGUI.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,7 @@ void BuyMenuGUI::Update() {
854854
/////////////////////////////////////////////
855855
// Repeating input logic
856856

857+
bool isKeyboardControlled = !m_pController->IsMouseControlled() && !m_pController->IsGamepadControlled();
857858
bool pressLeft = m_pController->IsState(PRESS_LEFT);
858859
bool pressRight = m_pController->IsState(PRESS_RIGHT);
859860
bool pressUp = m_pController->IsState(PRESS_UP);
@@ -1028,7 +1029,6 @@ void BuyMenuGUI::Update() {
10281029
if (m_FocusChange) {
10291030
// Set the correct special Sets category so the sets buttons show up
10301031
m_MenuCategory = LOADOUTS;
1031-
CategoryChange();
10321032
m_pSaveButton->SetFocus();
10331033
m_FocusChange = 0;
10341034
}
@@ -1120,6 +1120,7 @@ void BuyMenuGUI::Update() {
11201120
m_IsDragging = true;
11211121
std::swap((*m_pShopList->GetItemList())[m_DraggedItemIndex], (*m_pShopList->GetItemList())[m_DraggedItemIndex + 1]);
11221122
std::swap((*m_pShopList->GetItemList())[m_DraggedItemIndex]->m_ID, (*m_pShopList->GetItemList())[m_DraggedItemIndex + 1]->m_ID);
1123+
std::swap((*m_pShopList->GetItemList())[m_DraggedItemIndex]->m_ExtraIndex, (*m_pShopList->GetItemList())[m_DraggedItemIndex + 1]->m_ExtraIndex);
11231124
std::swap(m_Loadouts[m_DraggedItemIndex], m_Loadouts[m_DraggedItemIndex + 1]);
11241125
m_ListItemIndex = ++m_DraggedItemIndex;
11251126
m_SelectedLoadoutIndex = -1;
@@ -1129,6 +1130,7 @@ void BuyMenuGUI::Update() {
11291130
m_IsDragging = true;
11301131
std::swap((*m_pShopList->GetItemList())[m_DraggedItemIndex], (*m_pShopList->GetItemList())[m_DraggedItemIndex - 1]);
11311132
std::swap((*m_pShopList->GetItemList())[m_DraggedItemIndex]->m_ID, (*m_pShopList->GetItemList())[m_DraggedItemIndex - 1]->m_ID);
1133+
std::swap((*m_pShopList->GetItemList())[m_DraggedItemIndex]->m_ExtraIndex, (*m_pShopList->GetItemList())[m_DraggedItemIndex - 1]->m_ExtraIndex);
11321134
std::swap(m_Loadouts[m_DraggedItemIndex], m_Loadouts[m_DraggedItemIndex - 1]);
11331135
m_ListItemIndex = --m_DraggedItemIndex;
11341136
m_SelectedLoadoutIndex = -1;
@@ -1281,12 +1283,14 @@ void BuyMenuGUI::Update() {
12811283
}
12821284

12831285
// User selected to add an item to cart list!
1284-
if (m_pController->IsState(RELEASE_FACEBUTTON) && !m_IsDragging) {
1286+
if (isKeyboardControlled ? (m_pController->IsState(PRESS_FACEBUTTON) && !m_pController->IsState(AIM_SHARP)) : (m_pController->IsState(RELEASE_FACEBUTTON) && !m_IsDragging)) {
12851287
// User pressed on a loadout set, so load it into the menu
12861288
if (pItem && m_MenuCategory == LOADOUTS) {
12871289
// Beep if there's an error
12881290
if (!DeployLoadout(m_ListItemIndex)) {
12891291
g_GUISound.UserErrorSound()->Play(m_pController->GetPlayer());
1292+
} else {
1293+
g_GUISound.ItemChangeSound()->Play(m_pController->GetPlayer());
12901294
}
12911295
}
12921296
// User pressed on a module group item; toggle its expansion!
@@ -1336,15 +1340,13 @@ void BuyMenuGUI::Update() {
13361340
UpdateTotalMassLabel(dynamic_cast<const ACraft*>(m_pSelectedCraft), m_pCraftMassLabel);
13371341
}
13381342

1339-
if (m_MenuCategory == LOADOUTS) {
1340-
bool isKeyboardControlled = !m_pController->IsMouseControlled() && !m_pController->IsGamepadControlled();
1341-
if (isKeyboardControlled ? m_pController->IsState(AIM_SHARP) : m_pController->IsState(PRESS_FACEBUTTON)) {
1342-
m_DraggedItemIndex = m_pCartList->GetSelectedIndex();
1343-
} else if (m_pController->IsState(RELEASE_FACEBUTTON)) {
1344-
m_DraggedItemIndex = -1;
1345-
m_IsDragging = false;
1343+
if (isKeyboardControlled ? m_pController->IsState(AIM_SHARP) : m_pController->IsState(PRESS_FACEBUTTON)) {
1344+
m_DraggedItemIndex = m_pShopList->GetSelectedIndex();
1345+
} else if (m_pController->IsState(RELEASE_FACEBUTTON)) {
1346+
if (m_MenuCategory == LOADOUTS) {
1347+
// Might've reordered the loadout list, so we need to save the new order
1348+
SaveAllLoadoutsToFile();
13461349
}
1347-
} else {
13481350
m_DraggedItemIndex = -1;
13491351
m_IsDragging = false;
13501352
}
@@ -1456,7 +1458,6 @@ void BuyMenuGUI::Update() {
14561458
}
14571459

14581460
// Fire button removes items from the order list, including equipment on AHumans
1459-
bool isKeyboardControlled = !m_pController->IsMouseControlled() && !m_pController->IsGamepadControlled();
14601461
if (isKeyboardControlled ? (m_pController->IsState(PRESS_FACEBUTTON) && !m_pController->IsState(AIM_SHARP)) : (m_pController->IsState(RELEASE_FACEBUTTON) && !m_IsDragging)) {
14611462
if (g_UInputMan.FlagShiftState()) {
14621463
ClearCartList();
@@ -1902,7 +1903,8 @@ void BuyMenuGUI::Update() {
19021903
m_pDeleteButton->SetEnabled(m_SelectedLoadoutIndex != -1);
19031904
if (m_SelectedLoadoutIndex != -1) {
19041905
// Always highlight the currently selected loadout as if it's focused
1905-
m_pShopList->SetSelectedIndex(m_SelectedLoadoutIndex);
1906+
// TODO- need something better than this, like a dedicated highlight control
1907+
//m_pShopList->SetSelectedIndex(m_SelectedLoadoutIndex);
19061908
}
19071909
}
19081910
}
@@ -2271,6 +2273,7 @@ void BuyMenuGUI::AddPresetsToItemList() {
22712273
m_SelectedLoadoutIndex = -1;
22722274

22732275
// Go through all the presets, making intelligible list items from then for the GUI item list
2276+
m_pShopList->ClearList();
22742277
for (int i = 0; i < m_Loadouts.size(); ++i) {
22752278
Loadout& loadout = m_Loadouts[i];
22762279

0 commit comments

Comments
 (0)