diff --git a/apps/openmw/mwgui/journalwindow.cpp b/apps/openmw/mwgui/journalwindow.cpp index 90db26a519..1ce9f8b024 100644 --- a/apps/openmw/mwgui/journalwindow.cpp +++ b/apps/openmw/mwgui/journalwindow.cpp @@ -712,25 +712,57 @@ namespace mTopicIndexBook->setColour(col, row, 0, focused ? MWGui::journalHeaderColour : MyGUI::Colour::Black); } - bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override + void moveSelectedIndex(int offset) { - bool isRussian = (mEncoding == ToUTF8::WINDOWS_1251); + setIndexControllerFocus(false); + int numChars = mEncoding == ToUTF8::WINDOWS_1251 ? 30 : 26; + int col = mSelectedIndex / mIndexRowCount; + + if (offset == -1) // Up + { + if (mSelectedIndex % mIndexRowCount == 0) + mSelectedIndex = (col * mIndexRowCount) + mIndexRowCount - 1; + else + mSelectedIndex--; + } + else if (offset == 1) // Down + { + if (mSelectedIndex % mIndexRowCount == mIndexRowCount - 1) + mSelectedIndex = col * mIndexRowCount; + else + mSelectedIndex++; + } + else + { + // mSelectedIndex is unsigned, so we have to be careful with our math. + if (offset < 0) + offset += numChars; + + mSelectedIndex = (mSelectedIndex + offset) % numChars; + } + + setIndexControllerFocus(true); + setText(PageOneNum, 1); // Redraw the list + } + + bool optionsModeButtonHandler(const SDL_ControllerButtonEvent& arg) + { if (arg.button == SDL_CONTROLLER_BUTTON_A) // A: Mouse click or Select { - if (mOptionsMode && mQuestMode) + if (mQuestMode) { // Choose a quest Gui::MWList* list = getWidget(QuestsList); notifyQuestClicked(list->getItemNameAt(mSelectedQuest), 0); } - else if (mOptionsMode && mTopicsMode) + else if (mTopicsMode) { // Choose a topic Gui::MWList* list = getWidget(TopicsList); notifyTopicSelected(list->getItemNameAt(mSelectedQuest), 0); } - else if (mOptionsMode) + else { // Choose an index. Cyrillic capital A is a 0xd090 in UTF-8. // Words can not be started with characters 26 or 28. @@ -739,19 +771,105 @@ namespace russianOffset++; if (mSelectedIndex >= 27) russianOffset++; // 27, not 28, because of skipping char 26 + bool isRussian = (mEncoding == ToUTF8::WINDOWS_1251); notifyIndexLinkClicked(isRussian ? mSelectedIndex + russianOffset : mSelectedIndex + 'A'); } - return true; } else if (arg.button == SDL_CONTROLLER_BUTTON_B) // B: Back { - if (mOptionsMode) + // Hide the options overlay + notifyCancel(getWidget(CancelBTN)); + mQuestMode = false; + } + else if (arg.button == SDL_CONTROLLER_BUTTON_X) // X: Quests + { + if (mQuestMode) { - // Hide the options overlay + // Hide the quest overlay if visible notifyCancel(getWidget(CancelBTN)); mQuestMode = false; } - else if (mStates.size() > 1) + else + { + // Show the quest overlay if viewing the topics list + notifyQuests(getWidget(QuestsBTN)); + } + } + else if (arg.button == SDL_CONTROLLER_BUTTON_Y) // Y: Topics + { + if (!mQuestMode) + { + // Hide the topics overlay if visible + notifyCancel(getWidget(CancelBTN)); + } + else + { + // Show the topics overlay if viewing the quest list + notifyTopics(getWidget(TopicsBTN)); + } + } + else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSTICK && mQuestMode) // R3: Show All/Some + { + if (mAllQuests) + notifyShowActive(getWidget(ShowActiveBTN)); + else + notifyShowAll(getWidget(ShowAllBTN)); + } + else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP) + { + if (mQuestMode || mTopicsMode) + { + if (mButtons.size() <= 1) + return true; + + // Scroll through the list of quests or topics + setControllerFocusedQuest(MWGui::wrap(mSelectedQuest - 1, mButtons.size())); + } + else + moveSelectedIndex(-1); + } + else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) + { + if (mQuestMode || mTopicsMode) + { + if (mButtons.size() <= 1) + return true; + + // Scroll through the list of quests or topics + setControllerFocusedQuest(MWGui::wrap(mSelectedQuest + 1, mButtons.size())); + } + else + moveSelectedIndex(1); + } + else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT && !mQuestMode && !mTopicsMode) + moveSelectedIndex(-mIndexRowCount); + else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT && !mQuestMode && !mTopicsMode) + moveSelectedIndex(mIndexRowCount); + else if (arg.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER && (mQuestMode || mTopicsMode)) + { + // Scroll up 5 items in the list of quests or topics + setControllerFocusedQuest(std::max(static_cast(mSelectedQuest) - 5, 0)); + } + else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER && (mQuestMode || mTopicsMode)) + { + // Scroll down 5 items in the list of quests or topics + setControllerFocusedQuest(std::min(mSelectedQuest + 5, mButtons.size() - 1)); + } + + return true; + } + + bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override + { + // If the topics or quest list is open, it should handle the buttons. + if (mOptionsMode) + return optionsModeButtonHandler(arg); + + if (arg.button == SDL_CONTROLLER_BUTTON_A) + return false; + else if (arg.button == SDL_CONTROLLER_BUTTON_B) // B: Back + { + if (mStates.size() > 1) { // Pop the current book. If in quest mode, reopen the quest list. notifyJournal(getWidget(JournalBTN)); @@ -766,171 +884,27 @@ namespace // Close the journal window notifyClose(getWidget(CloseBTN)); } - return true; } else if (arg.button == SDL_CONTROLLER_BUTTON_X) // X: Quests { - if (mOptionsMode && mQuestMode) - { - // Hide the quest overlay if visible - notifyCancel(getWidget(CancelBTN)); - mQuestMode = false; - } - else - { - // Show the quest overlay if viewing a journal entry or the topics - if (!mOptionsMode) - notifyOptions(getWidget(OptionsBTN)); - if (!mQuestMode) - notifyQuests(getWidget(QuestsBTN)); - } - return true; + // Show the quest overlay + notifyOptions(getWidget(OptionsBTN)); + if (!mQuestMode) + notifyQuests(getWidget(QuestsBTN)); } else if (arg.button == SDL_CONTROLLER_BUTTON_Y) // Y: Topics { - if (mOptionsMode && !mQuestMode) - { - // Hide the topics overlay if visible - notifyCancel(getWidget(CancelBTN)); - mQuestMode = false; - } - else - { - // Show the topics overlay if viewing a journal entry or the quest list - if (!mOptionsMode) - notifyOptions(getWidget(OptionsBTN)); - if (mQuestMode) - notifyTopics(getWidget(TopicsBTN)); - } - return true; + // Show the topics overlay + notifyOptions(getWidget(OptionsBTN)); + if (mQuestMode) + notifyTopics(getWidget(TopicsBTN)); } - else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSTICK) // R3: Show All/Some - { - if (mAllQuests) - notifyShowActive(getWidget(ShowActiveBTN)); - else - notifyShowAll(getWidget(ShowAllBTN)); - } - else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP) - { - if (mOptionsMode && (mQuestMode || mTopicsMode)) - { - if (mButtons.size() <= 1) - return true; + else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT || arg.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER) + notifyPrevPage(getWidget(PrevPageBTN)); + else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT || arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER) + notifyNextPage(getWidget(NextPageBTN)); - // Scroll through the list of quests or topics - setControllerFocusedQuest(MWGui::wrap(mSelectedQuest - 1, mButtons.size())); - } - else if (mOptionsMode) - { - setIndexControllerFocus(false); - if (mSelectedIndex % mIndexRowCount == 0) - { - int col = mSelectedIndex / mIndexRowCount; - mSelectedIndex = (col * mIndexRowCount) + mIndexRowCount - 1; - } - else - mSelectedIndex--; - setIndexControllerFocus(true); - setText(PageOneNum, 1); // Redraw the list - } - return true; - } - else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) - { - if (mOptionsMode && (mQuestMode || mTopicsMode)) - { - if (mButtons.size() <= 1) - return true; - - // Scroll through the list of quests or topics - setControllerFocusedQuest(MWGui::wrap(mSelectedQuest + 1, mButtons.size())); - } - else if (mOptionsMode) - { - setIndexControllerFocus(false); - if (mSelectedIndex % mIndexRowCount == mIndexRowCount - 1) - { - int col = mSelectedIndex / mIndexRowCount; - mSelectedIndex = col * mIndexRowCount; - } - else - mSelectedIndex++; - setIndexControllerFocus(true); - setText(PageOneNum, 1); // Redraw the list - } - return true; - } - else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT) - { - if (!mOptionsMode) - notifyPrevPage(getWidget(PrevPageBTN)); - else if (mOptionsMode && !mQuestMode && !mTopicsMode) - { - setIndexControllerFocus(false); - if (isRussian) - { - // Cyrillic = 30 (10 + 10 + 10) - if (mIndexRowCount == 10) - mSelectedIndex = (mSelectedIndex + 20) % 30; - // or Cyrillic = 30 (15 + 15) - else - mSelectedIndex = (mSelectedIndex + 15) % 30; - } - else - { - // Latin = 26 (13 + 13) - mSelectedIndex = (mSelectedIndex + 13) % 26; - } - setIndexControllerFocus(true); - setText(PageOneNum, 1); // Redraw the list - } - return true; - } - else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT) - { - if (!mOptionsMode) - notifyNextPage(getWidget(NextPageBTN)); - else if (mOptionsMode && !mQuestMode && !mTopicsMode) - { - setIndexControllerFocus(false); - if (isRussian) - { - // Cyrillic = 30 (10 + 10 + 10) or (15 + 15) - mSelectedIndex = (mSelectedIndex + mIndexRowCount) % 30; - } - else - { - // Latin = 26 (13 + 13) - mSelectedIndex = (mSelectedIndex + 13) % 26; - } - setIndexControllerFocus(true); - setText(PageOneNum, 1); // Redraw the list - } - return true; - } - else if (arg.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER) // LB: Previous Page - { - // Scroll through the list of quests or topics - if (mOptionsMode && (mQuestMode || mTopicsMode)) - setControllerFocusedQuest(std::max(static_cast(mSelectedQuest) - 5, 0)); - // Page through the journal - else if (!mOptionsMode) - notifyPrevPage(getWidget(PrevPageBTN)); - return true; - } - else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER) // RB: Next Page - { - // Scroll through the list of quests or topics - if (mOptionsMode && (mQuestMode || mTopicsMode)) - setControllerFocusedQuest(std::min(mSelectedQuest + 5, mButtons.size() - 1)); - // Page through the journal - else if (!mOptionsMode) - notifyNextPage(getWidget(NextPageBTN)); - return true; - } - - return false; + return true; } void setControllerFocusedQuest(size_t index) diff --git a/apps/openmw/mwgui/journalwindow.hpp b/apps/openmw/mwgui/journalwindow.hpp index ca0893fdd4..6122bf70c7 100644 --- a/apps/openmw/mwgui/journalwindow.hpp +++ b/apps/openmw/mwgui/journalwindow.hpp @@ -37,8 +37,10 @@ namespace MWGui std::vector mButtons; size_t mSelectedQuest = 0; size_t mSelectedIndex = 0; + void moveSelectedIndex(int offset); void setIndexControllerFocus(bool focused); void setControllerFocusedQuest(size_t index); + bool optionsModeButtonHandler(const SDL_ControllerButtonEvent& arg); }; }