diff --git a/apps/openmw/mwbase/windowmanager.hpp b/apps/openmw/mwbase/windowmanager.hpp index 2e0e9a7b7d..101bbd2390 100644 --- a/apps/openmw/mwbase/windowmanager.hpp +++ b/apps/openmw/mwbase/windowmanager.hpp @@ -391,7 +391,7 @@ namespace MWBase virtual int getControllerMenuHeight() = 0; /// Cycle to the next window to receive controller events virtual void cycleActiveControllerWindow(bool next) = 0; - virtual void setActiveControllerWindow(MWGui::GuiMode mode, int activeIndex) = 0; + virtual void setActiveControllerWindow(MWGui::GuiMode mode, size_t activeIndex) = 0; virtual bool getControllerTooltipVisible() const = 0; virtual void setControllerTooltipVisible(bool visible) = 0; virtual bool getControllerTooltipEnabled() const = 0; diff --git a/apps/openmw/mwgui/bookpage.cpp b/apps/openmw/mwgui/bookpage.cpp index ebc4045524..a32733efd0 100644 --- a/apps/openmw/mwgui/bookpage.cpp +++ b/apps/openmw/mwgui/bookpage.cpp @@ -135,7 +135,7 @@ namespace MWGui mSections[section].mLines[line].mRuns[run].mStyle->mNormalColour = colour; } - virtual ~TypesetBookImpl() {} + virtual ~TypesetBookImpl() = default; Range addContent(const BookTypesetter::Utf8Span& text) { @@ -285,7 +285,7 @@ namespace MWGui Book::Content const* mCurrentContent; Alignment mCurrentAlignment; - Typesetter(size_t width, size_t height) + Typesetter(int width, int height) : mPageWidth(width) , mPageHeight(height) , mSection(nullptr) @@ -297,7 +297,7 @@ namespace MWGui mBook = std::make_shared(); } - virtual ~Typesetter() {} + virtual ~Typesetter() = default; Style* createStyle(const std::string& fontName, const Colour& fontColour, bool useBookFont) override { diff --git a/apps/openmw/mwgui/bookwindow.cpp b/apps/openmw/mwgui/bookwindow.cpp index 12a40a27b9..56ae70ac8c 100644 --- a/apps/openmw/mwgui/bookwindow.cpp +++ b/apps/openmw/mwgui/bookwindow.cpp @@ -62,8 +62,8 @@ namespace MWGui { // english button has a 7 pixel wide strip of garbage on its right edge mNextPageButton->setSize(64 - 7, mNextPageButton->getSize().height); - mNextPageButton->setImageCoord( - MyGUI::IntCoord(0, 0, (64 - 7) * scale, mNextPageButton->getSize().height * scale)); + mNextPageButton->setImageCoord(MyGUI::IntCoord( + 0, 0, static_cast((64 - 7) * scale), static_cast(mNextPageButton->getSize().height * scale))); } mControllerButtons.mL1 = "#{Interface:Prev}"; diff --git a/apps/openmw/mwgui/companionitemmodel.cpp b/apps/openmw/mwgui/companionitemmodel.cpp index 6bae8aef52..c438dbb822 100644 --- a/apps/openmw/mwgui/companionitemmodel.cpp +++ b/apps/openmw/mwgui/companionitemmodel.cpp @@ -28,7 +28,7 @@ namespace MWGui MWWorld::Ptr CompanionItemModel::addItem(const ItemStack& item, size_t count, bool allowAutoEquip) { if (hasProfit(mActor)) - modifyProfit(mActor, item.mBase.getClass().getValue(item.mBase) * count); + modifyProfit(mActor, static_cast(item.mBase.getClass().getValue(item.mBase) * count)); return InventoryItemModel::addItem(item, count, allowAutoEquip); } @@ -36,7 +36,7 @@ namespace MWGui MWWorld::Ptr CompanionItemModel::copyItem(const ItemStack& item, size_t count, bool allowAutoEquip) { if (hasProfit(mActor)) - modifyProfit(mActor, item.mBase.getClass().getValue(item.mBase) * count); + modifyProfit(mActor, static_cast(item.mBase.getClass().getValue(item.mBase) * count)); return InventoryItemModel::copyItem(item, count, allowAutoEquip); } @@ -44,7 +44,7 @@ namespace MWGui void CompanionItemModel::removeItem(const ItemStack& item, size_t count) { if (hasProfit(mActor)) - modifyProfit(mActor, -item.mBase.getClass().getValue(item.mBase) * count); + modifyProfit(mActor, -static_cast(item.mBase.getClass().getValue(item.mBase) * count)); InventoryItemModel::removeItem(item, count); } diff --git a/apps/openmw/mwgui/containeritemmodel.cpp b/apps/openmw/mwgui/containeritemmodel.cpp index ff50431d86..2c13157751 100644 --- a/apps/openmw/mwgui/containeritemmodel.cpp +++ b/apps/openmw/mwgui/containeritemmodel.cpp @@ -90,7 +90,7 @@ namespace MWGui ItemModel::ModelIndex ContainerItemModel::getIndex(const ItemStack& item) { - size_t i = 0; + ModelIndex i = 0; for (ItemStack& itemStack : mItems) { if (itemStack == item) @@ -106,7 +106,7 @@ namespace MWGui MWWorld::ContainerStore& store = source.first.getClass().getContainerStore(source.first); if (item.mBase.getContainerStore() == &store) throw std::runtime_error("Item to add needs to be from a different container!"); - return *store.add(item.mBase, count, allowAutoEquip); + return *store.add(item.mBase, static_cast(count), allowAutoEquip); } MWWorld::Ptr ContainerItemModel::copyItem(const ItemStack& item, size_t count, bool allowAutoEquip) @@ -115,8 +115,8 @@ namespace MWGui MWWorld::ContainerStore& store = source.first.getClass().getContainerStore(source.first); if (item.mBase.getContainerStore() == &store) throw std::runtime_error("Item to copy needs to be from a different container!"); - MWWorld::ManualRef newRef(*MWBase::Environment::get().getESMStore(), item.mBase, count); - return *store.add(newRef.getPtr(), count, allowAutoEquip); + MWWorld::ManualRef newRef(*MWBase::Environment::get().getESMStore(), item.mBase, static_cast(count)); + return *store.add(newRef.getPtr(), static_cast(count), allowAutoEquip); } void ContainerItemModel::removeItem(const ItemStack& item, size_t count) diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index 8de39ca4ff..a142bf034d 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -186,13 +186,13 @@ namespace MWGui else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP) { setControllerFocus(mButtons, mControllerFocus, false); - mControllerFocus = wrap(mControllerFocus - 1, mButtons.size()); + mControllerFocus = wrap(mControllerFocus, mButtons.size(), -1); setControllerFocus(mButtons, mControllerFocus, true); } else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) { setControllerFocus(mButtons, mControllerFocus, false); - mControllerFocus = wrap(mControllerFocus + 1, mButtons.size()); + mControllerFocus = wrap(mControllerFocus, mButtons.size(), 1); setControllerFocus(mButtons, mControllerFocus, true); } @@ -428,8 +428,8 @@ namespace MWGui { if (!mScrollBar->getVisible()) return; - mScrollBar->setScrollPosition( - std::clamp(mScrollBar->getScrollPosition() - rel * 0.3, 0, mScrollBar->getScrollRange() - 1)); + mScrollBar->setScrollPosition(std::clamp( + static_cast(mScrollBar->getScrollPosition() - rel * 0.3), 0, mScrollBar->getScrollRange() - 1)); onScrollbarMoved(mScrollBar, mScrollBar->getScrollPosition()); } @@ -441,7 +441,7 @@ namespace MWGui } } - void DialogueWindow::onSelectListItem(const std::string& topic, int id) + void DialogueWindow::onSelectListItem(const std::string& topic, int /*id*/) { MWBase::DialogueManager* dialogueManager = MWBase::Environment::get().getDialogueManager(); @@ -607,7 +607,7 @@ namespace MWGui void DialogueWindow::updateTopicsPane() { std::string focusedTopic; - if (Settings::gui().mControllerMenus && mControllerFocus < static_cast(mTopicsList->getItemCount())) + if (Settings::gui().mControllerMenus && mControllerFocus < mTopicsList->getItemCount()) focusedTopic = mTopicsList->getItemNameAt(mControllerFocus); mTopicsList->clear(); @@ -970,10 +970,10 @@ namespace MWGui else if (mControllerChoice >= 0 && mControllerChoice < static_cast(mChoices.size())) onChoiceActivated(mChoices[mControllerChoice].second); } - else if (mControllerFocus == static_cast(mTopicsList->getItemCount())) + else if (mControllerFocus == mTopicsList->getItemCount()) onGoodbyeActivated(); else - onSelectListItem(mTopicsList->getItemNameAt(mControllerFocus), mControllerFocus); + onSelectListItem(mTopicsList->getItemNameAt(mControllerFocus), static_cast(mControllerFocus)); MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click")); } else if (arg.button == SDL_CONTROLLER_BUTTON_B && mChoices.empty()) @@ -1013,9 +1013,9 @@ namespace MWGui { // Number of items is mTopicsList.length+1 because of "Goodbye" button. setControllerFocus(mControllerFocus, false); - if (mControllerFocus >= static_cast(mTopicsList->getItemCount())) + if (mControllerFocus >= mTopicsList->getItemCount()) mControllerFocus = 0; - else if (mControllerFocus == static_cast(mTopicsList->getItemCount()) - 1) + else if (mControllerFocus == mTopicsList->getItemCount() - 1) mControllerFocus = mTopicsList->getItemCount(); // "Goodbye" button else if (mTopicsList->getItemNameAt(mControllerFocus + 1).empty()) mControllerFocus += 2; // Skip separator @@ -1027,13 +1027,13 @@ namespace MWGui else if (arg.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER && mChoices.size() == 0) { setControllerFocus(mControllerFocus, false); - mControllerFocus = std::max(mControllerFocus - 5, 0); + mControllerFocus = mControllerFocus > 5 ? mControllerFocus - 5 : 0; setControllerFocus(mControllerFocus, true); } else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER && mChoices.size() == 0) { setControllerFocus(mControllerFocus, false); - mControllerFocus = std::min(mControllerFocus + 5, static_cast(mTopicsList->getItemCount())); + mControllerFocus = std::min(mControllerFocus + 5, mTopicsList->getItemCount()); setControllerFocus(mControllerFocus, true); } diff --git a/apps/openmw/mwgui/dialogue.hpp b/apps/openmw/mwgui/dialogue.hpp index bb0fcd6f0e..b95a20ddab 100644 --- a/apps/openmw/mwgui/dialogue.hpp +++ b/apps/openmw/mwgui/dialogue.hpp @@ -69,7 +69,7 @@ namespace MWGui Gui::AutoSizedTextBox* mGoldLabel; std::vector mButtons; - int mControllerFocus = 0; + size_t mControllerFocus = 0; void adjustAction(MyGUI::Widget* action, int& totalHeight); @@ -230,7 +230,7 @@ namespace MWGui std::unique_ptr mGreetingCallback; void setControllerFocus(size_t index, bool focused); - int mControllerFocus = 0; + size_t mControllerFocus = 0; int mControllerChoice = -1; void updateTopicFormat(); diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index 56f18e9b0e..9c929f309c 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -349,7 +349,7 @@ namespace MWGui if (mIsDrowning) { - mDrowningFlashTheta += dt * osg::PI * 2; + mDrowningFlashTheta += dt * osg::PIf * 2; float intensity = (cos(mDrowningFlashTheta) + 2.0f) / 3.0f; diff --git a/apps/openmw/mwgui/inventoryitemmodel.cpp b/apps/openmw/mwgui/inventoryitemmodel.cpp index 7464290947..97d8ac8921 100644 --- a/apps/openmw/mwgui/inventoryitemmodel.cpp +++ b/apps/openmw/mwgui/inventoryitemmodel.cpp @@ -37,7 +37,7 @@ namespace MWGui ItemModel::ModelIndex InventoryItemModel::getIndex(const ItemStack& item) { - size_t i = 0; + ModelIndex i = 0; for (ItemStack& itemStack : mItems) { if (itemStack == item) @@ -51,7 +51,7 @@ namespace MWGui { if (item.mBase.getContainerStore() == &mActor.getClass().getContainerStore(mActor)) throw std::runtime_error("Item to add needs to be from a different container!"); - return *mActor.getClass().getContainerStore(mActor).add(item.mBase, count, allowAutoEquip); + return *mActor.getClass().getContainerStore(mActor).add(item.mBase, static_cast(count), allowAutoEquip); } MWWorld::Ptr InventoryItemModel::copyItem(const ItemStack& item, size_t count, bool allowAutoEquip) @@ -59,8 +59,9 @@ namespace MWGui if (item.mBase.getContainerStore() == &mActor.getClass().getContainerStore(mActor)) throw std::runtime_error("Item to copy needs to be from a different container!"); - MWWorld::ManualRef newRef(*MWBase::Environment::get().getESMStore(), item.mBase, count); - return *mActor.getClass().getContainerStore(mActor).add(newRef.getPtr(), count, allowAutoEquip); + MWWorld::ManualRef newRef(*MWBase::Environment::get().getESMStore(), item.mBase, static_cast(count)); + return *mActor.getClass().getContainerStore(mActor).add( + newRef.getPtr(), static_cast(count), allowAutoEquip); } void InventoryItemModel::removeItem(const ItemStack& item, size_t count) @@ -70,12 +71,12 @@ namespace MWGui if (mActor.getClass().hasInventoryStore(mActor)) { MWWorld::InventoryStore& store = mActor.getClass().getInventoryStore(mActor); - removed = store.remove(item.mBase, count, true); + removed = store.remove(item.mBase, static_cast(count), true); } else { MWWorld::ContainerStore& store = mActor.getClass().getContainerStore(mActor); - removed = store.remove(item.mBase, count); + removed = store.remove(item.mBase, static_cast(count)); } std::stringstream error; diff --git a/apps/openmw/mwgui/itemchargeview.cpp b/apps/openmw/mwgui/itemchargeview.cpp index 59731717e1..2f49c8a4f3 100644 --- a/apps/openmw/mwgui/itemchargeview.cpp +++ b/apps/openmw/mwgui/itemchargeview.cpp @@ -161,7 +161,7 @@ namespace MWGui mScrollView->setVisibleVScroll(true); if (Settings::gui().mControllerMenus) - updateControllerFocus(-1, mControllerFocus); + updateControllerFocus(mLines.size(), mControllerFocus); } void ItemChargeView::resetScrollbars() @@ -242,37 +242,37 @@ namespace MWGui if (mLines.empty()) return; - int prevFocus = mControllerFocus; + size_t prevFocus = mControllerFocus; if (button == SDL_CONTROLLER_BUTTON_A) { // Select the focused item, if any. - if (mControllerFocus >= 0 && mControllerFocus < static_cast(mLines.size())) + if (mControllerFocus < mLines.size()) onIconClicked(mLines[mControllerFocus].mIcon); } else if (button == SDL_CONTROLLER_BUTTON_DPAD_UP) - mControllerFocus = wrap(mControllerFocus - 1, mLines.size()); + mControllerFocus = wrap(mControllerFocus, mLines.size(), -1); else if (button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) - mControllerFocus = wrap(mControllerFocus + 1, mLines.size()); + mControllerFocus = wrap(mControllerFocus, mLines.size(), 1); if (prevFocus != mControllerFocus) updateControllerFocus(prevFocus, mControllerFocus); } - void ItemChargeView::updateControllerFocus(int prevFocus, int newFocus) + void ItemChargeView::updateControllerFocus(size_t prevFocus, size_t newFocus) { if (mLines.empty()) return; const TextColours& textColours{ MWBase::Environment::get().getWindowManager()->getTextColours() }; - if (prevFocus >= 0 && prevFocus < static_cast(mLines.size())) + if (prevFocus < mLines.size()) { mLines[prevFocus].mText->setTextColour(textColours.normal); mLines[prevFocus].mIcon->setControllerFocus(false); } - if (newFocus >= 0 && newFocus < static_cast(mLines.size())) + if (newFocus >= 0 && newFocus < mLines.size()) { mLines[newFocus].mText->setTextColour(textColours.link); mLines[newFocus].mIcon->setControllerFocus(true); @@ -281,7 +281,7 @@ namespace MWGui if (newFocus <= 3) mScrollView->setViewOffset(MyGUI::IntPoint(0, 0)); else - mScrollView->setViewOffset(MyGUI::IntPoint(0, -55 * (newFocus - 3))); + mScrollView->setViewOffset(MyGUI::IntPoint(0, -55 * static_cast(newFocus - 3))); } } } diff --git a/apps/openmw/mwgui/itemchargeview.hpp b/apps/openmw/mwgui/itemchargeview.hpp index fd0388d83a..ecfefc1a34 100644 --- a/apps/openmw/mwgui/itemchargeview.hpp +++ b/apps/openmw/mwgui/itemchargeview.hpp @@ -75,8 +75,8 @@ namespace MWGui MyGUI::ScrollView* mScrollView; DisplayMode mDisplayMode; - int mControllerFocus = 0; - void updateControllerFocus(int prevFocus, int newFocus); + size_t mControllerFocus = 0; + void updateControllerFocus(size_t prevFocus, size_t newFocus); }; } diff --git a/apps/openmw/mwgui/itemmodel.cpp b/apps/openmw/mwgui/itemmodel.cpp index a4cf48fcbe..617014303e 100644 --- a/apps/openmw/mwgui/itemmodel.cpp +++ b/apps/openmw/mwgui/itemmodel.cpp @@ -109,9 +109,9 @@ namespace MWGui const ItemStack& itemToSearch = getItem(index); for (size_t i = 0; i < mSourceModel->getItemCount(); ++i) { - const ItemStack& item = mSourceModel->getItem(i); + const ItemStack& item = mSourceModel->getItem(static_cast(i)); if (item.mBase == itemToSearch.mBase) - return i; + return static_cast(i); } return -1; } @@ -121,9 +121,9 @@ namespace MWGui const ItemStack& itemToSearch = mSourceModel->getItem(index); for (size_t i = 0; i < getItemCount(); ++i) { - const ItemStack& item = getItem(i); + const ItemStack& item = getItem(static_cast(i)); if (item.mBase == itemToSearch.mBase) - return i; + return static_cast(i); } return -1; } diff --git a/apps/openmw/mwgui/itemtransfer.hpp b/apps/openmw/mwgui/itemtransfer.hpp index fbd37bf136..31f489f751 100644 --- a/apps/openmw/mwgui/itemtransfer.hpp +++ b/apps/openmw/mwgui/itemtransfer.hpp @@ -55,7 +55,7 @@ namespace MWGui WorldItemModel worldItemModel(0.5f, 0.5f); ItemModel* const targetModel = targetView == nullptr ? &worldItemModel : targetView->getModel(); - if (!targetModel->onDropItem(item.mBase, count)) + if (!targetModel->onDropItem(item.mBase, static_cast(count))) return; sourceView.getModel()->moveItem(item, count, targetModel); diff --git a/apps/openmw/mwgui/journalwindow.cpp b/apps/openmw/mwgui/journalwindow.cpp index c1fba27cfb..fe2e2156b6 100644 --- a/apps/openmw/mwgui/journalwindow.cpp +++ b/apps/openmw/mwgui/journalwindow.cpp @@ -49,7 +49,7 @@ namespace { struct DisplayState { - unsigned int mPage; + size_t mPage; Book mBook; }; @@ -159,8 +159,8 @@ namespace { // english button has a 7 pixel wide strip of garbage on its right edge nextButton->setSize(64 - 7, nextButton->getSize().height); - nextButton->setImageCoord( - MyGUI::IntCoord(0, 0, (64 - 7) * nextButtonScale, nextButton->getSize().height * nextButtonScale)); + nextButton->setImageCoord(MyGUI::IntCoord(0, 0, static_cast((64 - 7) * nextButtonScale), + static_cast(nextButton->getSize().height * nextButtonScale))); } if (!questList) @@ -246,12 +246,12 @@ namespace else journalBook = createJournalBook(); - pushBook(journalBook, 0); + pushBook(journalBook); // fast forward to the last page if (!mStates.empty()) { - unsigned int& page = mStates.top().mPage; + size_t& page = mStates.top().mPage; page = mStates.top().mBook->pageCount() - 1; if (page % 2) --page; @@ -326,21 +326,21 @@ namespace MWBase::Environment::get().getWindowManager()->updateControllerButtonsOverlay(); } - void pushBook(Book& book, unsigned int page) + void pushBook(Book& book) { DisplayState bs; - bs.mPage = page; + bs.mPage = 0; bs.mBook = book; mStates.push(bs); updateShowingPages(); updateCloseJournalButton(); } - void replaceBook(Book& book, unsigned int page) + void replaceBook(Book& book) { assert(!mStates.empty()); mStates.top().mBook = book; - mStates.top().mPage = page; + mStates.top().mPage = 0; updateShowingPages(); } @@ -361,8 +361,8 @@ namespace void updateShowingPages() { Book book; - unsigned int page; - unsigned int relPages; + size_t page; + size_t relPages; if (!mStates.empty()) { @@ -415,9 +415,9 @@ namespace Book topicBook = createTopicBook(linkId); if (mStates.size() > 1) - replaceBook(topicBook, 0); + replaceBook(topicBook); else - pushBook(topicBook, 0); + pushBook(topicBook); setVisible(OptionsOverlay, false); setVisible(OptionsBTN, true); @@ -447,9 +447,9 @@ namespace Book book = createQuestBook(name); if (mStates.size() > 1) - replaceBook(book, 0); + replaceBook(book); else - pushBook(book, 0); + pushBook(book); setVisible(OptionsOverlay, false); setVisible(OptionsBTN, true); @@ -604,7 +604,7 @@ namespace if (Settings::gui().mControllerMenus) { addControllerButtons(list, mSelectedQuest); - setControllerFocusedQuest(MWGui::wrap(mSelectedQuest, mButtons.size())); + setControllerFocusedQuest(std::min(mSelectedQuest, mButtons.size())); } if (mAllQuests) @@ -663,7 +663,7 @@ namespace return; if (!mStates.empty()) { - unsigned int& page = mStates.top().mPage; + size_t& page = mStates.top().mPage; Book book = mStates.top().mBook; if (page + 2 < book->pageCount()) @@ -682,7 +682,7 @@ namespace return; if (!mStates.empty()) { - unsigned int& page = mStates.top().mPage; + size_t& page = mStates.top().mPage; if (page >= 2) { @@ -718,8 +718,8 @@ namespace void setIndexControllerFocus(bool focused) { - int col = mSelectedIndex / mIndexRowCount; - int row = mSelectedIndex % mIndexRowCount; + size_t col = mSelectedIndex / mIndexRowCount; + size_t row = mSelectedIndex % mIndexRowCount; mTopicIndexBook->setColour(col, row, 0, focused ? MWGui::journalHeaderColour : MyGUI::Colour::Black); } @@ -728,7 +728,7 @@ namespace setIndexControllerFocus(false); int numChars = mEncoding == ToUTF8::WINDOWS_1251 ? 30 : 26; - int col = mSelectedIndex / mIndexRowCount; + size_t col = mSelectedIndex / mIndexRowCount; if (offset == -1) // Up { @@ -836,7 +836,7 @@ namespace return true; // Scroll through the list of quests or topics - setControllerFocusedQuest(MWGui::wrap(mSelectedQuest - 1, mButtons.size())); + setControllerFocusedQuest(MWGui::wrap(mSelectedQuest, mButtons.size(), -1)); } else moveSelectedIndex(-1); @@ -849,19 +849,19 @@ namespace return true; // Scroll through the list of quests or topics - setControllerFocusedQuest(MWGui::wrap(mSelectedQuest + 1, mButtons.size())); + setControllerFocusedQuest(MWGui::wrap(mSelectedQuest, mButtons.size(), 1)); } else moveSelectedIndex(1); } else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT && !mQuestMode && !mTopicsMode) - moveSelectedIndex(-mIndexRowCount); + moveSelectedIndex(-static_cast(mIndexRowCount)); else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT && !mQuestMode && !mTopicsMode) - moveSelectedIndex(mIndexRowCount); + moveSelectedIndex(static_cast(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)); + setControllerFocusedQuest(mSelectedQuest >= 5 ? mSelectedQuest - 5 : 0); } else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER && (mQuestMode || mTopicsMode)) { diff --git a/apps/openmw/mwgui/journalwindow.hpp b/apps/openmw/mwgui/journalwindow.hpp index 472065d565..ec8fae2106 100644 --- a/apps/openmw/mwgui/journalwindow.hpp +++ b/apps/openmw/mwgui/journalwindow.hpp @@ -36,10 +36,6 @@ namespace MWGui size_t mIndexRowCount = 1; 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); }; } diff --git a/apps/openmw/mwgui/levelupdialog.cpp b/apps/openmw/mwgui/levelupdialog.cpp index 149489e798..e4fa4fb95a 100644 --- a/apps/openmw/mwgui/levelupdialog.cpp +++ b/apps/openmw/mwgui/levelupdialog.cpp @@ -111,7 +111,7 @@ namespace MWGui for (const ESM::Attribute& attribute : MWBase::Environment::get().getESMStore()->get()) { - int val = creatureStats.getAttribute(attribute.mId).getBase(); + int val = static_cast(creatureStats.getAttribute(attribute.mId).getBase()); if (std::find(mSpentAttributes.begin(), mSpentAttributes.end(), attribute.mId) != mSpentAttributes.end()) { val += pcStats.getLevelupAttributeMultiplier(attribute.mId); @@ -202,8 +202,8 @@ namespace MWGui widgets.mValue->setEnabled(true); availableAttributes++; - float mult = pcStats.getLevelupAttributeMultiplier(attribute.mId); - mult = std::min(mult, 100 - pcStats.getAttribute(attribute.mId).getBase()); + int mult = pcStats.getLevelupAttributeMultiplier(attribute.mId); + mult = std::min(mult, static_cast(100 - pcStats.getAttribute(attribute.mId).getBase())); if (mult <= 1) widgets.mMultiplier->setCaption({}); else @@ -231,7 +231,7 @@ namespace MWGui { mControllerFocus = 0; for (size_t i = 0; i < mAttributeButtons.size(); i++) - setControllerFocus(mAttributeButtons, i, i == 0); + mAttributeButtons[i]->setStateSelected(i == 0); } // Play LevelUp Music diff --git a/apps/openmw/mwgui/loadingscreen.cpp b/apps/openmw/mwgui/loadingscreen.cpp index cae195e9aa..4695ae6054 100644 --- a/apps/openmw/mwgui/loadingscreen.cpp +++ b/apps/openmw/mwgui/loadingscreen.cpp @@ -120,8 +120,9 @@ namespace MWGui void operator()(osg::RenderInfo& renderInfo) const override { - int w = renderInfo.getCurrentCamera()->getViewport()->width(); - int h = renderInfo.getCurrentCamera()->getViewport()->height(); + const osg::Viewport* viewPort = renderInfo.getCurrentCamera()->getViewport(); + int w = static_cast(viewPort->width()); + int h = static_cast(viewPort->height()); mTexture->copyTexImage2D(*renderInfo.getState(), 0, 0, w, h); mOneshot = false; @@ -208,7 +209,8 @@ namespace MWGui { if (!mSplashScreens.empty()) { - std::string const& randomSplash = mSplashScreens.at(Misc::Rng::rollDice(mSplashScreens.size())); + std::string const& randomSplash + = mSplashScreens.at(Misc::Rng::rollDice(static_cast(mSplashScreens.size()))); // TODO: add option (filename pattern?) to use image aspect ratio instead of 4:3 // we can't do this by default, because the Morrowind splash screens are 1024x1024, but should be displayed @@ -259,10 +261,10 @@ namespace MWGui return false; // the minimal delay before a loading screen shows - const float initialDelay = 0.05; + constexpr float initialDelay = 0.05f; bool alreadyShown = (mLastRenderTime > mLoadingOnTime); - float diff = (mTimer.time_m() - mLoadingOnTime); + double diff = (mTimer.time_m() - mLoadingOnTime); if (!alreadyShown) { diff --git a/apps/openmw/mwgui/loadingscreen.hpp b/apps/openmw/mwgui/loadingscreen.hpp index 35de331ee0..268e676b01 100644 --- a/apps/openmw/mwgui/loadingscreen.hpp +++ b/apps/openmw/mwgui/loadingscreen.hpp @@ -71,7 +71,7 @@ namespace MWGui size_t mProgress; bool mShowWallpaper; - float mOldIcoMin = 0.f; + double mOldIcoMin = 0.0; unsigned int mOldIcoMax = 0; MyGUI::Widget* mLoadingBox; diff --git a/apps/openmw/mwgui/mainmenu.cpp b/apps/openmw/mwgui/mainmenu.cpp index d9d5b5c33b..1e1a9e72cb 100644 --- a/apps/openmw/mwgui/mainmenu.cpp +++ b/apps/openmw/mwgui/mainmenu.cpp @@ -364,10 +364,10 @@ namespace MWGui // Trim off some of the excessive padding // TODO: perhaps do this within ImageButton? int height = requested.height; - button->setImageTile(MyGUI::IntSize(requested.width, requested.height - 16 * scale)); - button->setCoord( - (maxwidth - requested.width / scale) / 2, curH, requested.width / scale, height / scale - 16); - curH += height / scale - 16; + button->setImageTile(MyGUI::IntSize(requested.width, static_cast(requested.height - 16 * scale))); + button->setCoord(static_cast((maxwidth - requested.width / scale) / 2), curH, + static_cast(requested.width / scale), static_cast(height / scale - 16)); + curH += static_cast(height / scale - 16); } if (state == MWBase::StateManager::State_NoGame) diff --git a/apps/openmw/mwgui/mapwindow.cpp b/apps/openmw/mwgui/mapwindow.cpp index f80871d3ef..094c348981 100644 --- a/apps/openmw/mwgui/mapwindow.cpp +++ b/apps/openmw/mwgui/mapwindow.cpp @@ -92,7 +92,8 @@ namespace return Constants::CellGridRadius; if (!Settings::terrain().mDistantTerrain) return Constants::CellGridRadius; - const int viewingDistanceInCells = Settings::camera().mViewingDistance / Constants::CellSizeInUnits; + const int viewingDistanceInCells + = static_cast(Settings::camera().mViewingDistance / Constants::CellSizeInUnits); return std::clamp( viewingDistanceInCells, Constants::CellGridRadius, Settings::map().mMaxLocalViewingDistance.get()); } @@ -255,8 +256,8 @@ namespace MWGui { // normalized cell coordinates auto mapWidgetSize = getWidgetSize(); - return MyGUI::IntPoint(std::round((nX + cellX - mGrid.left) * mapWidgetSize), - std::round((nY - cellY + mGrid.bottom) * mapWidgetSize)); + return MyGUI::IntPoint(static_cast(std::round((nX + cellX - mGrid.left) * mapWidgetSize)), + static_cast(std::round((nY - cellY + mGrid.bottom) * mapWidgetSize))); } MyGUI::IntPoint LocalMapBase::getMarkerPosition(float worldX, float worldY, MarkerUserData& markerPos) const @@ -286,7 +287,7 @@ namespace MWGui } MyGUI::IntCoord LocalMapBase::getMarkerCoordinates( - float worldX, float worldY, MarkerUserData& markerPos, size_t markerSize) const + float worldX, float worldY, MarkerUserData& markerPos, unsigned short markerSize) const { int halfMarkerSize = markerSize / 2; auto position = getMarkerPosition(worldX, worldY, markerPos); @@ -320,7 +321,7 @@ namespace MWGui mLocalMap->setViewOffset(viewOffset); } - MyGUI::IntCoord LocalMapBase::getMarkerCoordinates(MyGUI::Widget* widget, size_t markerSize) const + MyGUI::IntCoord LocalMapBase::getMarkerCoordinates(MyGUI::Widget* widget, unsigned short markerSize) const { MarkerUserData& markerPos(*widget->getUserData()); auto position = getPosition(markerPos.cellX, markerPos.cellY, markerPos.nX, markerPos.nY); @@ -453,7 +454,7 @@ namespace MWGui } if (oldSize != MyGUI::IntSize{ mGrid.width(), mGrid.height() }) - setCanvasSize(mLocalMap, mGrid, getWidgetSize()); + setCanvasSize(mLocalMap, mGrid, static_cast(getWidgetSize())); // Delay the door markers update until scripts have been given a chance to run. // If we don't do this, door markers that should be disabled will still appear on the map. @@ -665,8 +666,7 @@ namespace MWGui { std::vector destNotes; CustomMarkerCollection::RangeType markers = mCustomMarkers.getMarkers(marker.dest); - for (CustomMarkerCollection::ContainerType::const_iterator iter = markers.first; iter != markers.second; - ++iter) + for (auto iter = markers.first; iter != markers.second; ++iter) destNotes.push_back(iter->second.mNote); MyGUI::Widget* markerWidget = nullptr; @@ -733,9 +733,10 @@ namespace MWGui void LocalMapBase::updateLocalMap() { auto mapWidgetSize = getWidgetSize(); - setCanvasSize(mLocalMap, mGrid, getWidgetSize()); + setCanvasSize(mLocalMap, mGrid, static_cast(getWidgetSize())); - const auto size = MyGUI::IntSize(std::ceil(mapWidgetSize), std::ceil(mapWidgetSize)); + const auto size + = MyGUI::IntSize(static_cast(std::ceil(mapWidgetSize)), static_cast(std::ceil(mapWidgetSize))); for (auto& entry : mMaps) { const auto position = getPosition(entry.mCellX, entry.mCellY, 0, 0); @@ -1570,7 +1571,7 @@ namespace MWGui { if (getDeleteButtonShown()) { - mControllerFocus = wrap(mControllerFocus - 1, 3); + mControllerFocus = wrap(mControllerFocus, 3, -1); mDeleteButton->setStateSelected(mControllerFocus == 0); mOkButton->setStateSelected(mControllerFocus == 1); mCancelButton->setStateSelected(mControllerFocus == 2); @@ -1586,7 +1587,7 @@ namespace MWGui { if (getDeleteButtonShown()) { - mControllerFocus = wrap(mControllerFocus + 1, 3); + mControllerFocus = wrap(mControllerFocus, 3, 1); mDeleteButton->setStateSelected(mControllerFocus == 0); mOkButton->setStateSelected(mControllerFocus == 1); mCancelButton->setStateSelected(mControllerFocus == 2); diff --git a/apps/openmw/mwgui/mapwindow.hpp b/apps/openmw/mwgui/mapwindow.hpp index eb49f8673e..c4e9998e5a 100644 --- a/apps/openmw/mwgui/mapwindow.hpp +++ b/apps/openmw/mwgui/mapwindow.hpp @@ -163,9 +163,9 @@ namespace MWGui MyGUI::IntPoint getPosition(int cellX, int cellY, float nx, float ny) const; MyGUI::IntPoint getMarkerPosition(float worldX, float worldY, MarkerUserData& markerPos) const; MyGUI::IntCoord getMarkerCoordinates( - float worldX, float worldY, MarkerUserData& markerPos, size_t markerSize) const; + float worldX, float worldY, MarkerUserData& markerPos, unsigned short markerSize) const; MyGUI::Widget* createDoorMarker(const std::string& name, float x, float y) const; - MyGUI::IntCoord getMarkerCoordinates(MyGUI::Widget* widget, size_t markerSize) const; + MyGUI::IntCoord getMarkerCoordinates(MyGUI::Widget* widget, unsigned short markerSize) const; virtual void notifyPlayerUpdate() {} virtual void centerView(); @@ -225,7 +225,7 @@ namespace MWGui MyGUI::Button* mDeleteButton; bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; - int mControllerFocus = 0; + size_t mControllerFocus = 0; }; class MapWindow : public MWGui::WindowPinnableBase, public LocalMapBase, public NoDrop diff --git a/apps/openmw/mwgui/merchantrepair.cpp b/apps/openmw/mwgui/merchantrepair.cpp index 20c17aa701..dcd9b6b615 100644 --- a/apps/openmw/mwgui/merchantrepair.cpp +++ b/apps/openmw/mwgui/merchantrepair.cpp @@ -191,7 +191,7 @@ namespace MWGui return true; mButtons[mControllerFocus].first->setStateSelected(false); - mControllerFocus = wrap(mControllerFocus - 1, mButtons.size()); + mControllerFocus = wrap(mControllerFocus, mButtons.size(), -1); mButtons[mControllerFocus].first->setStateSelected(true); } else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) @@ -200,7 +200,7 @@ namespace MWGui return true; mButtons[mControllerFocus].first->setStateSelected(false); - mControllerFocus = wrap(mControllerFocus + 1, mButtons.size()); + mControllerFocus = wrap(mControllerFocus, mButtons.size(), 1); mButtons[mControllerFocus].first->setStateSelected(true); } @@ -213,7 +213,7 @@ namespace MWGui else { const int lineHeight = Settings::gui().mFontSize + 2; - mList->setViewOffset(MyGUI::IntPoint(0, -lineHeight * (line - 5))); + mList->setViewOffset(MyGUI::IntPoint(0, -lineHeight * static_cast(line - 5))); } } diff --git a/apps/openmw/mwgui/messagebox.cpp b/apps/openmw/mwgui/messagebox.cpp index 1e2c7aa0d7..986f77b6ee 100644 --- a/apps/openmw/mwgui/messagebox.cpp +++ b/apps/openmw/mwgui/messagebox.cpp @@ -473,7 +473,7 @@ namespace MWGui return true; setControllerFocus(mButtons, mControllerFocus, false); - mControllerFocus = wrap(mControllerFocus - 1, mButtons.size()); + mControllerFocus = wrap(mControllerFocus, mButtons.size(), -1); setControllerFocus(mButtons, mControllerFocus, true); } else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN || arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT) @@ -484,7 +484,7 @@ namespace MWGui return true; setControllerFocus(mButtons, mControllerFocus, false); - mControllerFocus = wrap(mControllerFocus + 1, mButtons.size()); + mControllerFocus = wrap(mControllerFocus, mButtons.size(), 1); setControllerFocus(mButtons, mControllerFocus, true); } diff --git a/apps/openmw/mwgui/quickkeysmenu.cpp b/apps/openmw/mwgui/quickkeysmenu.cpp index 0b33c6fa0f..e7a0c4ca8b 100644 --- a/apps/openmw/mwgui/quickkeysmenu.cpp +++ b/apps/openmw/mwgui/quickkeysmenu.cpp @@ -290,8 +290,8 @@ namespace MWGui if (texture) scale = texture->getHeight() / 64.f; - mSelected->button->setFrame( - "textures\\menu_icon_select_magic_magic.dds", MyGUI::IntCoord(0, 0, 44 * scale, 44 * scale)); + mSelected->button->setFrame("textures\\menu_icon_select_magic_magic.dds", + MyGUI::IntCoord(0, 0, static_cast(44 * scale), static_cast(44 * scale))); mSelected->button->setIcon(item); mSelected->button->setUserString("ToolTipType", "ItemPtr"); @@ -562,9 +562,9 @@ namespace MWGui else if (arg.button == SDL_CONTROLLER_BUTTON_B) mParent->onCancelButtonClicked(mCancelButton); else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP) - mControllerFocus = wrap(mControllerFocus - 1, 4); + mControllerFocus = wrap(mControllerFocus, 4, -1); else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) - mControllerFocus = wrap(mControllerFocus + 1, 4); + mControllerFocus = wrap(mControllerFocus, 4, 1); mItemButton->setStateSelected(mControllerFocus == 0); mMagicButton->setStateSelected(mControllerFocus == 1); diff --git a/apps/openmw/mwgui/quickkeysmenu.hpp b/apps/openmw/mwgui/quickkeysmenu.hpp index db20f13ad8..cfb75388d7 100644 --- a/apps/openmw/mwgui/quickkeysmenu.hpp +++ b/apps/openmw/mwgui/quickkeysmenu.hpp @@ -96,7 +96,7 @@ namespace MWGui QuickKeysMenu* mParent; bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; - int mControllerFocus = 0; + size_t mControllerFocus = 0; }; class MagicSelectionDialog : public WindowModal @@ -117,7 +117,7 @@ namespace MWGui void onModelIndexSelected(SpellModel::ModelIndex index); bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; - int mControllerFocus = 0; + size_t mControllerFocus = 0; }; } diff --git a/apps/openmw/mwgui/race.cpp b/apps/openmw/mwgui/race.cpp index c9a591ddc1..ded68b39ac 100644 --- a/apps/openmw/mwgui/race.cpp +++ b/apps/openmw/mwgui/race.cpp @@ -256,7 +256,7 @@ namespace MWGui void RaceDialog::onSelectPreviousGender(MyGUI::Widget*) { - mGenderIndex = wrap(mGenderIndex - 1, 2); + mGenderIndex = wrap(mGenderIndex, 2, -1); recountParts(); updatePreview(); @@ -264,7 +264,7 @@ namespace MWGui void RaceDialog::onSelectNextGender(MyGUI::Widget*) { - mGenderIndex = wrap(mGenderIndex + 1, 2); + mGenderIndex = wrap(mGenderIndex, 2, 1); recountParts(); updatePreview(); @@ -272,25 +272,25 @@ namespace MWGui void RaceDialog::onSelectPreviousFace(MyGUI::Widget*) { - mFaceIndex = wrap(mFaceIndex - 1, mAvailableHeads.size()); + mFaceIndex = wrap(mFaceIndex, mAvailableHeads.size(), -1); updatePreview(); } void RaceDialog::onSelectNextFace(MyGUI::Widget*) { - mFaceIndex = wrap(mFaceIndex + 1, mAvailableHeads.size()); + mFaceIndex = wrap(mFaceIndex, mAvailableHeads.size(), 1); updatePreview(); } void RaceDialog::onSelectPreviousHair(MyGUI::Widget*) { - mHairIndex = wrap(mHairIndex - 1, mAvailableHairs.size()); + mHairIndex = wrap(mHairIndex, mAvailableHairs.size(), -1); updatePreview(); } void RaceDialog::onSelectNextHair(MyGUI::Widget*) { - mHairIndex = wrap(mHairIndex + 1, mAvailableHairs.size()); + mHairIndex = wrap(mHairIndex, mAvailableHairs.size(), 1); updatePreview(); } @@ -359,10 +359,10 @@ namespace MWGui record.mRace = mCurrentRaceId; record.setIsMale(mGenderIndex == 0); - if (mFaceIndex >= 0 && mFaceIndex < int(mAvailableHeads.size())) + if (mFaceIndex >= 0 && mFaceIndex < mAvailableHeads.size()) record.mHead = mAvailableHeads[mFaceIndex]; - if (mHairIndex >= 0 && mHairIndex < int(mAvailableHairs.size())) + if (mHairIndex >= 0 && mHairIndex < mAvailableHairs.size()) record.mHair = mAvailableHairs[mHairIndex]; try diff --git a/apps/openmw/mwgui/race.hpp b/apps/openmw/mwgui/race.hpp index e825bc4f72..71509f69ec 100644 --- a/apps/openmw/mwgui/race.hpp +++ b/apps/openmw/mwgui/race.hpp @@ -110,7 +110,7 @@ namespace MWGui MyGUI::Widget* mSpellPowerList; std::vector mSpellPowerItems; - int mGenderIndex, mFaceIndex, mHairIndex; + size_t mGenderIndex, mFaceIndex, mHairIndex; ESM::RefId mCurrentRaceId; diff --git a/apps/openmw/mwgui/review.cpp b/apps/openmw/mwgui/review.cpp index 53e5020dcf..08b9b80677 100644 --- a/apps/openmw/mwgui/review.cpp +++ b/apps/openmw/mwgui/review.cpp @@ -381,8 +381,8 @@ namespace MWGui } const MWMechanics::SkillValue& stat = skillValue->second; - int base = stat.getBase(); - int modified = stat.getModified(); + float base = stat.getBase(); + float modified = stat.getModified(); std::string state = "normal"; if (modified > base) @@ -577,13 +577,13 @@ namespace MWGui else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP || arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT) { setControllerFocus(mButtons, mControllerFocus, false); - mControllerFocus = wrap(mControllerFocus - 1, mButtons.size()); + mControllerFocus = wrap(mControllerFocus, mButtons.size(), -1); setControllerFocus(mButtons, mControllerFocus, true); } else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN || arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT) { setControllerFocus(mButtons, mControllerFocus, false); - mControllerFocus = wrap(mControllerFocus + 1, mButtons.size()); + mControllerFocus = wrap(mControllerFocus, mButtons.size(), 1); setControllerFocus(mButtons, mControllerFocus, true); } diff --git a/apps/openmw/mwgui/review.hpp b/apps/openmw/mwgui/review.hpp index c3912606bc..91f808548e 100644 --- a/apps/openmw/mwgui/review.hpp +++ b/apps/openmw/mwgui/review.hpp @@ -104,7 +104,7 @@ namespace MWGui // 0 = Name, 1 = Race, 2 = Class, 3 = BirthSign, 4 = Back, 5 = OK std::vector mButtons; - int mControllerFocus = 0; + size_t mControllerFocus = 0; }; } #endif diff --git a/apps/openmw/mwgui/savegamedialog.cpp b/apps/openmw/mwgui/savegamedialog.cpp index b5bcc2c334..edd0949fb3 100644 --- a/apps/openmw/mwgui/savegamedialog.cpp +++ b/apps/openmw/mwgui/savegamedialog.cpp @@ -549,7 +549,7 @@ namespace MWGui else if (arg.button == SDL_CONTROLLER_BUTTON_Y) { size_t index = mCharacterSelection->getIndexSelected(); - index = wrap(index + 1, mCharacterSelection->getItemCount()); + index = wrap(index, mCharacterSelection->getItemCount(), 1); mCharacterSelection->setIndexSelected(index); onCharacterSelected(mCharacterSelection, index); MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click")); diff --git a/apps/openmw/mwgui/settingswindow.cpp b/apps/openmw/mwgui/settingswindow.cpp index d292c84a74..71b0cf40ca 100644 --- a/apps/openmw/mwgui/settingswindow.cpp +++ b/apps/openmw/mwgui/settingswindow.cpp @@ -1144,7 +1144,7 @@ namespace MWGui else if (arg.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER) { size_t index = mSettingsTab->getIndexSelected(); - index = wrap(index - 1, mSettingsTab->getItemCount()); + index = wrap(index, mSettingsTab->getItemCount(), -1); mSettingsTab->setIndexSelected(index); MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click")); return true; @@ -1152,7 +1152,7 @@ namespace MWGui else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER) { size_t index = mSettingsTab->getIndexSelected(); - index = wrap(index + 1, mSettingsTab->getItemCount()); + index = wrap(index, mSettingsTab->getItemCount(), 1); mSettingsTab->setIndexSelected(index); MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click")); return true; diff --git a/apps/openmw/mwgui/sortfilteritemmodel.cpp b/apps/openmw/mwgui/sortfilteritemmodel.cpp index 8c6277db4d..c660feb171 100644 --- a/apps/openmw/mwgui/sortfilteritemmodel.cpp +++ b/apps/openmw/mwgui/sortfilteritemmodel.cpp @@ -79,8 +79,6 @@ namespace if (mSortByType && left.mType != right.mType) return left.mType < right.mType; - float result = 0; - // compare items by type auto leftType = left.mBase.getType(); auto rightType = right.mBase.getType(); @@ -92,9 +90,11 @@ namespace std::string leftName = Utf8Stream::lowerCaseUtf8(left.mBase.getClass().getName(left.mBase)); std::string rightName = Utf8Stream::lowerCaseUtf8(right.mBase.getClass().getName(right.mBase)); - result = leftName.compare(rightName); - if (result != 0) - return result < 0; + { + int result = leftName.compare(rightName); + if (result != 0) + return result < 0; + } // compare items by enchantment: // 1. enchanted items showed before non-enchanted @@ -133,32 +133,38 @@ namespace } } - result = leftChargePercent - rightChargePercent; - if (result != 0) - return result > 0; + { + int result = leftChargePercent - rightChargePercent; + if (result != 0) + return result > 0; + } // compare items by condition if (left.mBase.getClass().hasItemHealth(left.mBase) && right.mBase.getClass().hasItemHealth(right.mBase)) { - result = left.mBase.getClass().getItemHealth(left.mBase) + int result = left.mBase.getClass().getItemHealth(left.mBase) - right.mBase.getClass().getItemHealth(right.mBase); if (result != 0) return result > 0; } // compare items by remaining usage time - result = left.mBase.getClass().getRemainingUsageTime(left.mBase) - - right.mBase.getClass().getRemainingUsageTime(right.mBase); - if (result != 0) - return result > 0; + { + float result = left.mBase.getClass().getRemainingUsageTime(left.mBase) + - right.mBase.getClass().getRemainingUsageTime(right.mBase); + if (result != 0) + return result > 0; + } // compare items by value - result = left.mBase.getClass().getValue(left.mBase) - right.mBase.getClass().getValue(right.mBase); - if (result != 0) - return result > 0; + { + int result = left.mBase.getClass().getValue(left.mBase) - right.mBase.getClass().getValue(right.mBase); + if (result != 0) + return result > 0; + } // compare items by weight - result = left.mBase.getClass().getWeight(left.mBase) - right.mBase.getClass().getWeight(right.mBase); + float result = left.mBase.getClass().getWeight(left.mBase) - right.mBase.getClass().getWeight(right.mBase); if (result != 0) return result > 0; @@ -377,16 +383,15 @@ namespace MWGui mItems.clear(); for (size_t i = 0; i < count; ++i) { - ItemStack item = mSourceModel->getItem(i); + ItemStack item = mSourceModel->getItem(static_cast(i)); - for (std::vector>::iterator it = mDragItems.begin(); it != mDragItems.end(); - ++it) + for (const std::pair& drag : mDragItems) { - if (item.mBase == it->first) + if (item.mBase == drag.first) { - if (item.mCount < it->second) + if (item.mCount < drag.second) throw std::runtime_error("Dragging more than present in the model"); - item.mCount -= it->second; + item.mCount -= drag.second; } } diff --git a/apps/openmw/mwgui/spellbuyingwindow.cpp b/apps/openmw/mwgui/spellbuyingwindow.cpp index a1e5fecd1e..0b9e5e3391 100644 --- a/apps/openmw/mwgui/spellbuyingwindow.cpp +++ b/apps/openmw/mwgui/spellbuyingwindow.cpp @@ -254,7 +254,7 @@ namespace MWGui return true; mSpellButtons[mControllerFocus].first->setStateSelected(false); - mControllerFocus = wrap(mControllerFocus - 1, mSpellButtons.size()); + mControllerFocus = wrap(mControllerFocus, mSpellButtons.size(), -1); mSpellButtons[mControllerFocus].first->setStateSelected(true); } else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) @@ -265,7 +265,7 @@ namespace MWGui return true; mSpellButtons[mControllerFocus].first->setStateSelected(false); - mControllerFocus = wrap(mControllerFocus + 1, mSpellButtons.size()); + mControllerFocus = wrap(mControllerFocus, mSpellButtons.size(), 1); mSpellButtons[mControllerFocus].first->setStateSelected(true); } else @@ -280,7 +280,7 @@ namespace MWGui else { const int lineHeight = Settings::gui().mFontSize + 2; - mSpellsView->setViewOffset(MyGUI::IntPoint(0, -lineHeight * (line - 5))); + mSpellsView->setViewOffset(MyGUI::IntPoint(0, -lineHeight * static_cast(line - 5))); } // Warp the mouse to the selected spell to show the tooltip diff --git a/apps/openmw/mwgui/spellcreationdialog.cpp b/apps/openmw/mwgui/spellcreationdialog.cpp index bd4728928b..f2571a01d5 100644 --- a/apps/openmw/mwgui/spellcreationdialog.cpp +++ b/apps/openmw/mwgui/spellcreationdialog.cpp @@ -224,7 +224,7 @@ namespace MWGui mEffectName->setCaptionWithReplacing("#{" + ESM::MagicEffect::indexToGmstString(effect->mIndex) + "}"); - mEffect.mEffectID = effect->mIndex; + mEffect.mEffectID = static_cast(effect->mIndex); mMagicEffect = effect; @@ -333,13 +333,13 @@ namespace MWGui void EditEffectDialog::setSkill(ESM::RefId skill) { - mEffect.mSkill = ESM::Skill::refIdToIndex(skill); + mEffect.mSkill = static_cast(ESM::Skill::refIdToIndex(skill)); eventEffectModified(mEffect); } void EditEffectDialog::setAttribute(ESM::RefId attribute) { - mEffect.mAttribute = ESM::Attribute::refIdToIndex(attribute); + mEffect.mAttribute = static_cast(ESM::Attribute::refIdToIndex(attribute)); eventEffectModified(mEffect); } @@ -772,7 +772,7 @@ namespace MWGui mAddEffectDialog.setVisible(false); } - EffectEditorBase::~EffectEditorBase() {} + EffectEditorBase::~EffectEditorBase() = default; void EffectEditorBase::startEditing() { @@ -1044,12 +1044,12 @@ namespace MWGui if (arg.button == SDL_CONTROLLER_BUTTON_A) { - if (!mRightColumn && mAvailableFocus >= 0 && mAvailableFocus < static_cast(mAvailableButtons.size())) + if (!mRightColumn && mAvailableFocus < mAvailableButtons.size()) { onAvailableEffectClicked(mAvailableButtons[mAvailableFocus]); winMgr->playSound(ESM::RefId::stringRefId("Menu Click")); } - else if (mRightColumn && mEffectFocus >= 0 && mEffectFocus < static_cast(mEffectButtons.size())) + else if (mRightColumn && mEffectFocus < mEffectButtons.size()) { onEditEffect(mEffectButtons[mEffectFocus].second); winMgr->playSound(ESM::RefId::stringRefId("Menu Click")); @@ -1062,44 +1062,44 @@ namespace MWGui } else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP) { - if (mRightColumn && mEffectButtons.size() > 0) + if (mRightColumn && !mEffectButtons.empty()) { - if (mEffectFocus >= 0 && mEffectFocus < static_cast(mEffectButtons.size())) + if (mEffectFocus < mEffectButtons.size()) mEffectButtons[mEffectFocus].first->setStateSelected(false); - mEffectFocus = wrap(mEffectFocus - 1, mEffectButtons.size()); + mEffectFocus = wrap(mEffectFocus, mEffectButtons.size(), -1); mEffectButtons[mEffectFocus].first->setStateSelected(true); } - else if (!mRightColumn && mAvailableButtons.size() > 0) + else if (!mRightColumn && !mAvailableButtons.empty()) { - if (mAvailableFocus >= 0 && mAvailableFocus < static_cast(mAvailableButtons.size())) + if (mAvailableFocus < mAvailableButtons.size()) mAvailableButtons[mAvailableFocus]->setStateSelected(false); - mAvailableFocus = wrap(mAvailableFocus - 1, mAvailableButtons.size()); + mAvailableFocus = wrap(mAvailableFocus, mAvailableButtons.size(), -1); mAvailableButtons[mAvailableFocus]->setStateSelected(true); } } else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) { - if (mRightColumn && mEffectButtons.size() > 0) + if (mRightColumn && !mEffectButtons.empty()) { - if (mEffectFocus >= 0 && mEffectFocus < static_cast(mEffectButtons.size())) + if (mEffectFocus < mEffectButtons.size()) mEffectButtons[mEffectFocus].first->setStateSelected(false); - mEffectFocus = wrap(mEffectFocus + 1, mEffectButtons.size()); + mEffectFocus = wrap(mEffectFocus, mEffectButtons.size(), 1); mEffectButtons[mEffectFocus].first->setStateSelected(true); } - else if (!mRightColumn && mAvailableButtons.size() > 0) + else if (!mRightColumn && !mAvailableButtons.empty()) { - if (mAvailableFocus >= 0 && mAvailableFocus < static_cast(mAvailableButtons.size())) + if (mAvailableFocus < mAvailableButtons.size()) mAvailableButtons[mAvailableFocus]->setStateSelected(false); - mAvailableFocus = wrap(mAvailableFocus + 1, mAvailableButtons.size()); + mAvailableFocus = wrap(mAvailableFocus, mAvailableButtons.size(), 1); mAvailableButtons[mAvailableFocus]->setStateSelected(true); } } else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT && mRightColumn) { mRightColumn = false; - if (mEffectFocus >= 0 && mEffectFocus < static_cast(mEffectButtons.size())) + if (mEffectFocus < mEffectButtons.size()) mEffectButtons[mEffectFocus].first->setStateSelected(false); - if (mAvailableFocus >= 0 && mAvailableFocus < static_cast(mAvailableButtons.size())) + if (mAvailableFocus < mAvailableButtons.size()) mAvailableButtons[mAvailableFocus]->setStateSelected(true); winMgr->setControllerTooltipVisible(Settings::gui().mControllerTooltips); @@ -1107,9 +1107,9 @@ namespace MWGui else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT && !mRightColumn && mEffectButtons.size() > 0) { mRightColumn = true; - if (mAvailableFocus >= 0 && mAvailableFocus < static_cast(mAvailableButtons.size())) + if (mAvailableFocus < mAvailableButtons.size()) mAvailableButtons[mAvailableFocus]->setStateSelected(false); - if (mEffectFocus >= 0 && mEffectFocus < static_cast(mEffectButtons.size())) + if (mEffectFocus < mEffectButtons.size()) mEffectButtons[mEffectFocus].first->setStateSelected(true); winMgr->setControllerTooltipVisible(false); @@ -1123,10 +1123,10 @@ namespace MWGui else { const int lineHeight = Settings::gui().mFontSize + 3; - mAvailableEffectsList->setViewOffset(-lineHeight * (mAvailableFocus - 5)); + mAvailableEffectsList->setViewOffset(-lineHeight * static_cast(mAvailableFocus - 5)); } - if (!mRightColumn && mAvailableFocus >= 0 && mAvailableFocus < static_cast(mAvailableButtons.size())) + if (!mRightColumn && mAvailableFocus < mAvailableButtons.size()) { // Warp the mouse to the selected spell to show the tooltip if (winMgr->getControllerTooltipVisible()) diff --git a/apps/openmw/mwgui/spellcreationdialog.hpp b/apps/openmw/mwgui/spellcreationdialog.hpp index 8d96a9727d..f3382817e7 100644 --- a/apps/openmw/mwgui/spellcreationdialog.hpp +++ b/apps/openmw/mwgui/spellcreationdialog.hpp @@ -153,9 +153,9 @@ namespace MWGui private: Type mType; - int mAvailableFocus; - int mEffectFocus; - bool mRightColumn; + size_t mAvailableFocus = 0; + size_t mEffectFocus = 0; + bool mRightColumn = false; std::vector mAvailableButtons; std::vector> mEffectButtons; }; diff --git a/apps/openmw/mwgui/spellview.cpp b/apps/openmw/mwgui/spellview.cpp index 8c64c92ce6..57ba077f6e 100644 --- a/apps/openmw/mwgui/spellview.cpp +++ b/apps/openmw/mwgui/spellview.cpp @@ -19,8 +19,6 @@ namespace MWGui { - const char* SpellView::sSpellModelIndex = "SpellModelIndex"; - SpellView::LineInfo::LineInfo( MyGUI::Widget* leftWidget, MyGUI::Widget* rightWidget, SpellModel::ModelIndex spellIndex) : mLeftWidget(leftWidget) @@ -29,15 +27,6 @@ namespace MWGui { } - SpellView::SpellView() - : mScrollView(nullptr) - , mShowCostColumn(true) - , mHighlightSelected(true) - , mControllerActiveWindow(false) - , mControllerFocus(0) - { - } - void SpellView::initialiseOverride() { Base::initialiseOverride(); @@ -126,7 +115,7 @@ namespace MWGui t->setCaption(spell.mName + captionSuffix); t->setTextAlign(MyGUI::Align::Left); adjustSpellWidget(spell, i, t); - mButtons.emplace_back(std::make_pair(t, i)); + mButtons.emplace_back(t, i); if (!spell.mCostColumn.empty() && mShowCostColumn) { @@ -235,8 +224,8 @@ namespace MWGui if (Settings::gui().mControllerMenus) { - mControllerFocus = wrap(mControllerFocus, mButtons.size()); - updateControllerFocus(-1, mControllerFocus); + mControllerFocus = std::min(mControllerFocus, mButtons.size()); + updateControllerFocus(mButtons.size(), mControllerFocus); } // Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the @@ -307,7 +296,7 @@ namespace MWGui widget->setUserString("Spell", spell.mId.serialize()); } - widget->setUserString(sSpellModelIndex, MyGUI::utility::toString(index)); + widget->setUserString("SpellModelIndex", MyGUI::utility::toString(index)); widget->eventMouseWheel += MyGUI::newDelegate(this, &SpellView::onMouseWheelMoved); widget->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellView::onSpellSelected); @@ -315,7 +304,7 @@ namespace MWGui SpellModel::ModelIndex SpellView::getSpellModelIndex(MyGUI::Widget* widget) { - return MyGUI::utility::parseInt(widget->getUserString(sSpellModelIndex)); + return MyGUI::utility::parseInt(widget->getUserString("SpellModelIndex")); } void SpellView::onSpellSelected(MyGUI::Widget* sender) @@ -349,14 +338,14 @@ namespace MWGui if (mButtons.empty()) return; - int prevFocus = mControllerFocus; + size_t prevFocus = mControllerFocus; MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager(); - + int delta = 0; switch (button) { case SDL_CONTROLLER_BUTTON_A: // Select the focused item, if any. - if (mControllerFocus >= 0 && mControllerFocus < static_cast(mButtons.size())) + if (mControllerFocus < mButtons.size()) { onSpellSelected(mButtons[mControllerFocus].first); MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click")); @@ -368,25 +357,25 @@ namespace MWGui break; case SDL_CONTROLLER_BUTTON_DPAD_UP: winMgr->restoreControllerTooltips(); - mControllerFocus--; + delta = -1; break; case SDL_CONTROLLER_BUTTON_DPAD_DOWN: winMgr->restoreControllerTooltips(); - mControllerFocus++; + delta = 1; break; case SDL_CONTROLLER_BUTTON_DPAD_LEFT: winMgr->restoreControllerTooltips(); - mControllerFocus = std::max(0, mControllerFocus - 10); + delta = -10; break; case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: winMgr->restoreControllerTooltips(); - mControllerFocus = std::min(mControllerFocus + 10, static_cast(mButtons.size()) - 1); + delta = 10; break; case SDL_CONTROLLER_BUTTON_LEFTSHOULDER: { // Jump to first item in previous group - int prevGroupIndex = 0; - for (int groupIndex : mGroupIndices) + size_t prevGroupIndex = 0; + for (size_t groupIndex : mGroupIndices) { if (groupIndex >= mControllerFocus) break; @@ -399,8 +388,8 @@ namespace MWGui case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: { // Jump to first item in next group - int newFocus = mControllerFocus; - for (int groupIndex : mGroupIndices) + size_t newFocus = mControllerFocus; + for (size_t groupIndex : mGroupIndices) { if (groupIndex > mControllerFocus) { @@ -418,27 +407,27 @@ namespace MWGui return; } - mControllerFocus = wrap(mControllerFocus, mButtons.size()); + mControllerFocus = wrap(mControllerFocus, mButtons.size(), delta); if (prevFocus != mControllerFocus) updateControllerFocus(prevFocus, mControllerFocus); else - updateControllerFocus(-1, mControllerFocus); + updateControllerFocus(mButtons.size(), mControllerFocus); } - void SpellView::updateControllerFocus(int prevFocus, int newFocus) + void SpellView::updateControllerFocus(size_t prevFocus, size_t newFocus) { if (mButtons.empty()) return; - if (prevFocus >= 0 && prevFocus < static_cast(mButtons.size())) + if (prevFocus < mButtons.size()) { Gui::SharedStateButton* prev = mButtons[prevFocus].first; if (prev) prev->onMouseLostFocus(nullptr); } - if (mControllerActiveWindow && newFocus >= 0 && newFocus < static_cast(mButtons.size())) + if (mControllerActiveWindow && newFocus < mButtons.size()) { Gui::SharedStateButton* focused = mButtons[newFocus].first; if (focused) diff --git a/apps/openmw/mwgui/spellview.hpp b/apps/openmw/mwgui/spellview.hpp index d1b9b53f7d..b7f46896a4 100644 --- a/apps/openmw/mwgui/spellview.hpp +++ b/apps/openmw/mwgui/spellview.hpp @@ -28,7 +28,7 @@ namespace MWGui { MYGUI_RTTI_DERIVED(SpellView) public: - SpellView(); + SpellView() {}; /// Register needed components with MyGUI's factory manager static void registerComponents(); @@ -63,8 +63,6 @@ namespace MWGui void onControllerButton(const unsigned char button); private: - MyGUI::ScrollView* mScrollView; - std::unique_ptr mModel; /// tracks a row in the spell view @@ -90,28 +88,27 @@ namespace MWGui std::vector mLines; - bool mShowCostColumn; - bool mHighlightSelected; + /// Keep a list of buttons for controller navigation and their index in the full list. + std::vector> mButtons; + /// Keep a list of group offsets for controller navigation + std::vector mGroupIndices; + MyGUI::ScrollView* mScrollView = nullptr; + size_t mControllerFocus = 0; + + bool mShowCostColumn = true; + bool mHighlightSelected = true; + bool mControllerActiveWindow = false; void layoutWidgets(); void addGroup(const std::string& label1, const std::string& label2); void adjustSpellWidget(const Spell& spell, SpellModel::ModelIndex index, MyGUI::Widget* widget); - /// Keep a list of buttons for controller navigation and their index in the full list. - std::vector> mButtons; - /// Keep a list of group offsets for controller navigation - std::vector mGroupIndices; - - bool mControllerActiveWindow; - int mControllerFocus; - void updateControllerFocus(int prevFocus, int newFocus); + void updateControllerFocus(size_t prevFocus, size_t newFocus); void onSpellSelected(MyGUI::Widget* sender); void onMouseWheelMoved(MyGUI::Widget* sender, int rel); SpellModel::ModelIndex getSpellModelIndex(MyGUI::Widget* sender); - - static const char* sSpellModelIndex; }; } diff --git a/apps/openmw/mwgui/spellwindow.cpp b/apps/openmw/mwgui/spellwindow.cpp index 01b4a94e93..dfbb863795 100644 --- a/apps/openmw/mwgui/spellwindow.cpp +++ b/apps/openmw/mwgui/spellwindow.cpp @@ -255,7 +255,7 @@ namespace MWGui return; mSpellView->setModel(new SpellModel(MWMechanics::getPlayer())); - int itemCount = mSpellView->getModel()->getItemCount(); + int itemCount = static_cast(mSpellView->getModel()->getItemCount()); if (itemCount == 0) return; diff --git a/apps/openmw/mwgui/statswindow.cpp b/apps/openmw/mwgui/statswindow.cpp index 656adcb4b7..4323e7f25f 100644 --- a/apps/openmw/mwgui/statswindow.cpp +++ b/apps/openmw/mwgui/statswindow.cpp @@ -258,8 +258,8 @@ namespace MWGui MyGUI::TextBox* nameWidget = widgets.first; if (valueWidget && nameWidget) { - int modified = value.getModified(), base = value.getBase(); - std::string text = MyGUI::utility::toString(modified); + float modified = value.getModified(), base = value.getBase(); + std::string text = MyGUI::utility::toString(static_cast(modified)); std::string state = "normal"; if (modified > base) state = "increased"; @@ -341,8 +341,8 @@ namespace MWGui bool first = true; for (const auto& attribute : store->get()) { - float mult = playerStats.getLevelupAttributeMultiplier(attribute.mId); - mult = std::min(mult, 100 - playerStats.getAttribute(attribute.mId).getBase()); + int mult = playerStats.getLevelupAttributeMultiplier(attribute.mId); + mult = std::min(mult, static_cast(100 - playerStats.getAttribute(attribute.mId).getBase())); if (mult > 1) { if (!first) diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index d238db70c9..259b6ab36c 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -298,7 +298,7 @@ namespace MWGui const ItemStack& item = mSortModel->getItem(index); MWWorld::Ptr object = item.mBase; - int count = item.mCount; + size_t count = item.mCount; bool shift = MyGUI::InputManager::getInstance().isShiftPressed(); if (MyGUI::InputManager::getInstance().isControlPressed()) count = 1; @@ -309,7 +309,7 @@ namespace MWGui std::string message = "#{sQuanityMenuMessage02}"; std::string name{ object.getClass().getName(object) }; name += MWGui::ToolTips::getSoulString(object.getCellRef()); - dialog->openCountDialog(name, message, count); + dialog->openCountDialog(name, message, static_cast(count)); dialog->eventOkClicked.clear(); dialog->eventOkClicked += MyGUI::newDelegate(this, &TradeWindow::sellItem); mItemToSell = mSortModel->mapToSource(index); @@ -335,14 +335,14 @@ namespace MWGui // this was an item borrowed to us by the player mTradeModel->returnItemBorrowedToUs(mItemToSell, count); playerTradeModel->returnItemBorrowedFromUs(mItemToSell, mTradeModel, count); - buyFromNpc(item.mBase, count, true); + updateOffer(); } else { // borrow item to player playerTradeModel->borrowItemToUs(mItemToSell, mTradeModel, count); mTradeModel->borrowItemFromUs(mItemToSell, count); - buyFromNpc(item.mBase, count, false); + updateOffer(); } MWBase::Environment::get().getWindowManager()->getInventoryWindow()->updateItemView(); @@ -355,17 +355,16 @@ namespace MWGui = MWBase::Environment::get().getWindowManager()->getInventoryWindow()->getTradeModel(); mTradeModel->borrowItemToUs(index, playerTradeModel, count); mItemView->update(); - sellToNpc(playerTradeModel->getItem(index).mBase, count, false); + updateOffer(); } void TradeWindow::returnItem(int index, size_t count) { TradeItemModel* playerTradeModel = MWBase::Environment::get().getWindowManager()->getInventoryWindow()->getTradeModel(); - const ItemStack& item = playerTradeModel->getItem(index); mTradeModel->returnItemBorrowedFromUs(index, playerTradeModel, count); mItemView->update(); - sellToNpc(item.mBase, count, true); + updateOffer(); } void TradeWindow::addOrRemoveGold(int amount, const MWWorld::Ptr& actor) @@ -648,16 +647,6 @@ namespace MWGui updateLabels(); } - void TradeWindow::sellToNpc(const MWWorld::Ptr& item, int count, bool boughtItem) - { - updateOffer(); - } - - void TradeWindow::buyFromNpc(const MWWorld::Ptr& item, int count, bool soldItem) - { - updateOffer(); - } - void TradeWindow::onReferenceUnavailable() { // remove both Trade and Dialogue (since you always trade with the NPC/creature that you have previously talked diff --git a/apps/openmw/mwgui/tradewindow.hpp b/apps/openmw/mwgui/tradewindow.hpp index 938246a345..ab7b965cd8 100644 --- a/apps/openmw/mwgui/tradewindow.hpp +++ b/apps/openmw/mwgui/tradewindow.hpp @@ -90,11 +90,6 @@ namespace MWGui bool mUpdateNextFrame; - void sellToNpc( - const MWWorld::Ptr& item, int count, bool boughtItem); ///< only used for adjusting the gold balance - void buyFromNpc( - const MWWorld::Ptr& item, int count, bool soldItem); ///< only used for adjusting the gold balance - void updateOffer(); void onItemSelected(int index); diff --git a/apps/openmw/mwgui/trainingwindow.cpp b/apps/openmw/mwgui/trainingwindow.cpp index 0d60e20e67..01b552b720 100644 --- a/apps/openmw/mwgui/trainingwindow.cpp +++ b/apps/openmw/mwgui/trainingwindow.cpp @@ -123,7 +123,7 @@ namespace MWGui MyGUI::Button* button = mTrainingOptions->createWidget(price <= playerGold ? "SandTextButton" : "SandTextButtonDisabled", // can't use setEnabled since that removes tooltip - MyGUI::IntCoord(4, 3 + i * lineHeight, mTrainingOptions->getWidth() - 10, lineHeight), + MyGUI::IntCoord(4, static_cast(3 + i * lineHeight), mTrainingOptions->getWidth() - 10, lineHeight), MyGUI::Align::Default); button->setUserData(skills[i].first); @@ -169,8 +169,8 @@ namespace MWGui const MWWorld::ESMStore& store = *MWBase::Environment::get().getESMStore(); - int price = pcStats.getSkill(skill->mId).getBase() - * store.get().find("iTrainingMod")->mValue.getInteger(); + int price = static_cast(pcStats.getSkill(skill->mId).getBase() + * store.get().find("iTrainingMod")->mValue.getInteger()); price = MWBase::Environment::get().getMechanicsManager()->getBarterOffer(mPtr, price, true); if (price > player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId)) @@ -263,7 +263,7 @@ namespace MWGui return true; setControllerFocus(mTrainingButtons, mControllerFocus, false); - mControllerFocus = wrap(mControllerFocus - 1, mTrainingButtons.size()); + mControllerFocus = wrap(mControllerFocus, mTrainingButtons.size(), -1); setControllerFocus(mTrainingButtons, mControllerFocus, true); } else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) @@ -272,7 +272,7 @@ namespace MWGui return true; setControllerFocus(mTrainingButtons, mControllerFocus, false); - mControllerFocus = wrap(mControllerFocus + 1, mTrainingButtons.size()); + mControllerFocus = wrap(mControllerFocus, mTrainingButtons.size(), 1); setControllerFocus(mTrainingButtons, mControllerFocus, true); } diff --git a/apps/openmw/mwgui/travelwindow.cpp b/apps/openmw/mwgui/travelwindow.cpp index e83c327125..708fa724c3 100644 --- a/apps/openmw/mwgui/travelwindow.cpp +++ b/apps/openmw/mwgui/travelwindow.cpp @@ -63,8 +63,8 @@ namespace MWGui else { const ESM::Position playerPos = player.getRefData().getPosition(); - float d = sqrt(pow(pos.pos[0] - playerPos.pos[0], 2) + pow(pos.pos[1] - playerPos.pos[1], 2) - + pow(pos.pos[2] - playerPos.pos[2], 2)); + double d = std::sqrt(std::pow(pos.pos[0] - playerPos.pos[0], 2) + std::pow(pos.pos[1] - playerPos.pos[1], 2) + + std::pow(pos.pos[2] - playerPos.pos[2], 2)); float fTravelMult = gmst.find("fTravelMult")->mValue.getFloat(); if (fTravelMult != 0) price = static_cast(d / fTravelMult); @@ -207,10 +207,10 @@ namespace MWGui = (osg::Vec3f(pos.pos[0], pos.pos[1], 0) - osg::Vec3f(playerPos.pos[0], playerPos.pos[1], 0)).length(); int hours = static_cast(d / MWBase::Environment::get() - .getESMStore() - ->get() - .find("fTravelTimeMult") - ->mValue.getFloat()); + .getESMStore() + ->get() + .find("fTravelTimeMult") + ->mValue.getFloat()); MWBase::Environment::get().getMechanicsManager()->rest(hours, true); MWBase::Environment::get().getWorld()->advanceTime(hours); } @@ -279,7 +279,7 @@ namespace MWGui return true; setControllerFocus(mDestinationButtons, mControllerFocus, false); - mControllerFocus = wrap(mControllerFocus - 1, mDestinationButtons.size()); + mControllerFocus = wrap(mControllerFocus, mDestinationButtons.size(), -1); setControllerFocus(mDestinationButtons, mControllerFocus, true); } else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) @@ -288,7 +288,7 @@ namespace MWGui return true; setControllerFocus(mDestinationButtons, mControllerFocus, false); - mControllerFocus = wrap(mControllerFocus + 1, mDestinationButtons.size()); + mControllerFocus = wrap(mControllerFocus, mDestinationButtons.size(), 1); setControllerFocus(mDestinationButtons, mControllerFocus, true); } @@ -298,7 +298,7 @@ namespace MWGui else { const int lineHeight = Settings::gui().mFontSize + 2; - mDestinationsView->setViewOffset(MyGUI::IntPoint(0, -lineHeight * (mControllerFocus - 5))); + mDestinationsView->setViewOffset(MyGUI::IntPoint(0, -lineHeight * static_cast(mControllerFocus - 5))); } return true; diff --git a/apps/openmw/mwgui/waitdialog.cpp b/apps/openmw/mwgui/waitdialog.cpp index 8663ea1071..3f41a78d38 100644 --- a/apps/openmw/mwgui/waitdialog.cpp +++ b/apps/openmw/mwgui/waitdialog.cpp @@ -239,7 +239,7 @@ namespace MWGui void WaitDialog::onHourSliderChangedPosition(MyGUI::ScrollBar* sender, size_t position) { mHourText->setCaptionWithReplacing(MyGUI::utility::toString(position + 1) + " #{sRestMenu2}"); - mManualHours = position + 1; + mManualHours = static_cast(position + 1); MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mWaitButton); } diff --git a/apps/openmw/mwgui/windowbase.cpp b/apps/openmw/mwgui/windowbase.cpp index 89a27c5eef..a3acd81db8 100644 --- a/apps/openmw/mwgui/windowbase.cpp +++ b/apps/openmw/mwgui/windowbase.cpp @@ -15,19 +15,28 @@ using namespace MWGui; -int MWGui::wrap(int index, int max) +size_t MWGui::wrap(size_t index, size_t max, int delta) { - if (index < 0) - return max - 1; - else if (index >= max) + if (delta >= 0) + { + unsigned absDelta = static_cast(delta); + if (absDelta >= max) + return 0; + else if (index >= max - absDelta) + return 0; + return index + absDelta; + } + unsigned absDelta = static_cast(-delta); + if (index >= absDelta) + return index - absDelta; + else if (max == 0) return 0; - else - return index; + return max - 1; } -void MWGui::setControllerFocus(const std::vector& buttons, int index, bool focused) +void MWGui::setControllerFocus(const std::vector& buttons, size_t index, bool focused) { - if (index >= 0 && index < static_cast(buttons.size())) + if (index < buttons.size()) buttons[index]->setStateSelected(focused); } @@ -199,16 +208,14 @@ float BookWindowBase::adjustButton(std::string_view name) WindowBase::getWidget(button, name); MyGUI::IntSize requested = button->getRequestedSize(); float scale = float(requested.height) / button->getSize().height; - MyGUI::IntSize newSize = requested; - newSize.width /= scale; - newSize.height /= scale; + MyGUI::IntSize newSize(static_cast(requested.width / scale), static_cast(requested.height / scale)); button->setSize(newSize); if (button->getAlign().isRight()) { MyGUI::IntSize diff = (button->getSize() - requested); - diff.width /= scale; - diff.height /= scale; + diff.width = static_cast(diff.width / scale); + diff.height = static_cast(diff.height / scale); button->setPosition(button->getPosition() + MyGUI::IntPoint(diff.width, 0)); } diff --git a/apps/openmw/mwgui/windowbase.hpp b/apps/openmw/mwgui/windowbase.hpp index 2a091c303d..0ba05aeb79 100644 --- a/apps/openmw/mwgui/windowbase.hpp +++ b/apps/openmw/mwgui/windowbase.hpp @@ -14,8 +14,8 @@ namespace MWGui { class DragAndDrop; - int wrap(int index, int max); - void setControllerFocus(const std::vector& buttons, int index, bool selected); + size_t wrap(size_t index, size_t max, int delta); + void setControllerFocus(const std::vector& buttons, size_t index, bool selected); struct ControllerButtons { diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 15b5b20258..f88bb3e9d9 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -903,11 +903,11 @@ namespace MWGui { GuiMode mode = mGuiModes.back(); GuiModeState& state = mGuiModeStates[mode]; - if (state.mWindows.size() == 0) + if (state.mWindows.empty()) return nullptr; - int activeIndex - = std::clamp(mActiveControllerWindows[mode], 0, static_cast(state.mWindows.size()) - 1); + size_t activeIndex + = std::clamp(mActiveControllerWindows[mode], 0, state.mWindows.size() - 1); // If the active window is no longer visible, find the next visible window. if (!state.mWindows[activeIndex]->isVisible()) @@ -925,18 +925,18 @@ namespace MWGui return; GuiMode mode = mGuiModes.back(); - int winCount = mGuiModeStates[mode].mWindows.size(); + size_t winCount = mGuiModeStates[mode].mWindows.size(); - int activeIndex = 0; + size_t activeIndex = 0; if (winCount > 1) { // Find next/previous visible window activeIndex = mActiveControllerWindows[mode]; int delta = next ? 1 : -1; - for (int i = 0; i < winCount; i++) + for (size_t i = 0; i < winCount; ++i) { - activeIndex = wrap(activeIndex + delta, winCount); + activeIndex = wrap(activeIndex, winCount, delta); if (mGuiModeStates[mode].mWindows[activeIndex]->isVisible()) break; } @@ -952,9 +952,9 @@ namespace MWGui return; const GuiMode mode = mGuiModes.back(); - int winCount = mGuiModeStates[mode].mWindows.size(); + size_t winCount = mGuiModeStates[mode].mWindows.size(); - for (int i = 0; i < winCount; i++) + for (size_t i = 0; i < winCount; i++) { // Set active window last so inactive windows don't stomp on changes it makes, e.g. to tooltips. if (i != mActiveControllerWindows[mode]) @@ -964,16 +964,16 @@ namespace MWGui mGuiModeStates[mode].mWindows[mActiveControllerWindows[mode]]->setActiveControllerWindow(true); } - void WindowManager::setActiveControllerWindow(GuiMode mode, int activeIndex) + void WindowManager::setActiveControllerWindow(GuiMode mode, size_t activeIndex) { if (!Settings::gui().mControllerMenus) return; - int winCount = mGuiModeStates[mode].mWindows.size(); + size_t winCount = mGuiModeStates[mode].mWindows.size(); if (winCount == 0) return; - activeIndex = std::clamp(activeIndex, 0, winCount - 1); + activeIndex = std::clamp(activeIndex, 0, winCount - 1); mActiveControllerWindows[mode] = activeIndex; reapplyActiveControllerWindow(); @@ -1437,7 +1437,8 @@ namespace MWGui if (mode == GM_Container) mActiveControllerWindows[mode] = 0; // Ensure controller focus is on container // Activate first visible window. This needs to be called after updateVisible. - mActiveControllerWindows[mode] = std::max(mActiveControllerWindows[mode] - 1, -1); + if (mActiveControllerWindows[mode] != 0) + mActiveControllerWindows[mode] = mActiveControllerWindows[mode] - 1; cycleActiveControllerWindow(true); } } diff --git a/apps/openmw/mwgui/windowmanagerimp.hpp b/apps/openmw/mwgui/windowmanagerimp.hpp index a9acaffcf0..c763a433f9 100644 --- a/apps/openmw/mwgui/windowmanagerimp.hpp +++ b/apps/openmw/mwgui/windowmanagerimp.hpp @@ -394,7 +394,7 @@ namespace MWGui WindowBase* getActiveControllerWindow() override; int getControllerMenuHeight() override; void cycleActiveControllerWindow(bool next) override; - void setActiveControllerWindow(GuiMode mode, int activeIndex) override; + void setActiveControllerWindow(GuiMode mode, size_t activeIndex) override; bool getControllerTooltipVisible() const override { return mControllerTooltipVisible; } void setControllerTooltipVisible(bool visible) override; bool getControllerTooltipEnabled() const override { return mControllerTooltipEnabled; } @@ -513,7 +513,7 @@ namespace MWGui // The currently active stack of GUI modes (top mode is the one we are in). std::vector mGuiModes; // The active window for controller mode for each GUI mode. - std::map mActiveControllerWindows; + std::map mActiveControllerWindows; // Current tooltip visibility state (can be disabled by mouse movement) bool mControllerTooltipVisible = false; // User preference for tooltips (persists across mouse/controller switches) diff --git a/apps/openmw/mwmechanics/alchemy.cpp b/apps/openmw/mwmechanics/alchemy.cpp index e2edf5f9cf..9fdae5d66a 100644 --- a/apps/openmw/mwmechanics/alchemy.cpp +++ b/apps/openmw/mwmechanics/alchemy.cpp @@ -604,7 +604,7 @@ std::string MWMechanics::Alchemy::suggestPotionName() return effects.begin()->toString(); } -std::vector MWMechanics::Alchemy::effectsDescription(const MWWorld::ConstPtr& ptr, const int alchemySkill) +std::vector MWMechanics::Alchemy::effectsDescription(const MWWorld::ConstPtr& ptr, const float alchemySkill) { std::vector effects; diff --git a/apps/openmw/mwmechanics/alchemy.hpp b/apps/openmw/mwmechanics/alchemy.hpp index 373ca8b887..cf5c25a600 100644 --- a/apps/openmw/mwmechanics/alchemy.hpp +++ b/apps/openmw/mwmechanics/alchemy.hpp @@ -135,7 +135,7 @@ namespace MWMechanics /// adjust the skills of the alchemist accordingly. /// \param name must not be an empty string, or Result_NoName is returned - static std::vector effectsDescription(const MWWorld::ConstPtr& ptr, const int alchemySKill); + static std::vector effectsDescription(const MWWorld::ConstPtr& ptr, const float alchemySKill); }; }