1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-11-30 16:34:30 +00:00

Resolve various conversion warnings in mwgui

This commit is contained in:
Evil Eye 2025-09-21 15:58:38 +02:00
parent 39f17f5651
commit fc700c61fd
50 changed files with 294 additions and 311 deletions

View file

@ -391,7 +391,7 @@ namespace MWBase
virtual int getControllerMenuHeight() = 0; virtual int getControllerMenuHeight() = 0;
/// Cycle to the next window to receive controller events /// Cycle to the next window to receive controller events
virtual void cycleActiveControllerWindow(bool next) = 0; 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 bool getControllerTooltipVisible() const = 0;
virtual void setControllerTooltipVisible(bool visible) = 0; virtual void setControllerTooltipVisible(bool visible) = 0;
virtual bool getControllerTooltipEnabled() const = 0; virtual bool getControllerTooltipEnabled() const = 0;

View file

@ -135,7 +135,7 @@ namespace MWGui
mSections[section].mLines[line].mRuns[run].mStyle->mNormalColour = colour; mSections[section].mLines[line].mRuns[run].mStyle->mNormalColour = colour;
} }
virtual ~TypesetBookImpl() {} virtual ~TypesetBookImpl() = default;
Range addContent(const BookTypesetter::Utf8Span& text) Range addContent(const BookTypesetter::Utf8Span& text)
{ {
@ -285,7 +285,7 @@ namespace MWGui
Book::Content const* mCurrentContent; Book::Content const* mCurrentContent;
Alignment mCurrentAlignment; Alignment mCurrentAlignment;
Typesetter(size_t width, size_t height) Typesetter(int width, int height)
: mPageWidth(width) : mPageWidth(width)
, mPageHeight(height) , mPageHeight(height)
, mSection(nullptr) , mSection(nullptr)
@ -297,7 +297,7 @@ namespace MWGui
mBook = std::make_shared<Book>(); mBook = std::make_shared<Book>();
} }
virtual ~Typesetter() {} virtual ~Typesetter() = default;
Style* createStyle(const std::string& fontName, const Colour& fontColour, bool useBookFont) override Style* createStyle(const std::string& fontName, const Colour& fontColour, bool useBookFont) override
{ {

View file

@ -62,8 +62,8 @@ namespace MWGui
{ {
// english button has a 7 pixel wide strip of garbage on its right edge // english button has a 7 pixel wide strip of garbage on its right edge
mNextPageButton->setSize(64 - 7, mNextPageButton->getSize().height); mNextPageButton->setSize(64 - 7, mNextPageButton->getSize().height);
mNextPageButton->setImageCoord( mNextPageButton->setImageCoord(MyGUI::IntCoord(
MyGUI::IntCoord(0, 0, (64 - 7) * scale, mNextPageButton->getSize().height * scale)); 0, 0, static_cast<int>((64 - 7) * scale), static_cast<int>(mNextPageButton->getSize().height * scale)));
} }
mControllerButtons.mL1 = "#{Interface:Prev}"; mControllerButtons.mL1 = "#{Interface:Prev}";

View file

@ -28,7 +28,7 @@ namespace MWGui
MWWorld::Ptr CompanionItemModel::addItem(const ItemStack& item, size_t count, bool allowAutoEquip) MWWorld::Ptr CompanionItemModel::addItem(const ItemStack& item, size_t count, bool allowAutoEquip)
{ {
if (hasProfit(mActor)) if (hasProfit(mActor))
modifyProfit(mActor, item.mBase.getClass().getValue(item.mBase) * count); modifyProfit(mActor, static_cast<int>(item.mBase.getClass().getValue(item.mBase) * count));
return InventoryItemModel::addItem(item, count, allowAutoEquip); return InventoryItemModel::addItem(item, count, allowAutoEquip);
} }
@ -36,7 +36,7 @@ namespace MWGui
MWWorld::Ptr CompanionItemModel::copyItem(const ItemStack& item, size_t count, bool allowAutoEquip) MWWorld::Ptr CompanionItemModel::copyItem(const ItemStack& item, size_t count, bool allowAutoEquip)
{ {
if (hasProfit(mActor)) if (hasProfit(mActor))
modifyProfit(mActor, item.mBase.getClass().getValue(item.mBase) * count); modifyProfit(mActor, static_cast<int>(item.mBase.getClass().getValue(item.mBase) * count));
return InventoryItemModel::copyItem(item, count, allowAutoEquip); return InventoryItemModel::copyItem(item, count, allowAutoEquip);
} }
@ -44,7 +44,7 @@ namespace MWGui
void CompanionItemModel::removeItem(const ItemStack& item, size_t count) void CompanionItemModel::removeItem(const ItemStack& item, size_t count)
{ {
if (hasProfit(mActor)) if (hasProfit(mActor))
modifyProfit(mActor, -item.mBase.getClass().getValue(item.mBase) * count); modifyProfit(mActor, -static_cast<int>(item.mBase.getClass().getValue(item.mBase) * count));
InventoryItemModel::removeItem(item, count); InventoryItemModel::removeItem(item, count);
} }

View file

@ -90,7 +90,7 @@ namespace MWGui
ItemModel::ModelIndex ContainerItemModel::getIndex(const ItemStack& item) ItemModel::ModelIndex ContainerItemModel::getIndex(const ItemStack& item)
{ {
size_t i = 0; ModelIndex i = 0;
for (ItemStack& itemStack : mItems) for (ItemStack& itemStack : mItems)
{ {
if (itemStack == item) if (itemStack == item)
@ -106,7 +106,7 @@ namespace MWGui
MWWorld::ContainerStore& store = source.first.getClass().getContainerStore(source.first); MWWorld::ContainerStore& store = source.first.getClass().getContainerStore(source.first);
if (item.mBase.getContainerStore() == &store) if (item.mBase.getContainerStore() == &store)
throw std::runtime_error("Item to add needs to be from a different container!"); 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<int>(count), allowAutoEquip);
} }
MWWorld::Ptr ContainerItemModel::copyItem(const ItemStack& item, size_t count, bool 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); MWWorld::ContainerStore& store = source.first.getClass().getContainerStore(source.first);
if (item.mBase.getContainerStore() == &store) if (item.mBase.getContainerStore() == &store)
throw std::runtime_error("Item to copy needs to be from a different container!"); throw std::runtime_error("Item to copy needs to be from a different container!");
MWWorld::ManualRef newRef(*MWBase::Environment::get().getESMStore(), item.mBase, count); MWWorld::ManualRef newRef(*MWBase::Environment::get().getESMStore(), item.mBase, static_cast<int>(count));
return *store.add(newRef.getPtr(), count, allowAutoEquip); return *store.add(newRef.getPtr(), static_cast<int>(count), allowAutoEquip);
} }
void ContainerItemModel::removeItem(const ItemStack& item, size_t count) void ContainerItemModel::removeItem(const ItemStack& item, size_t count)

View file

@ -186,13 +186,13 @@ namespace MWGui
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP) else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP)
{ {
setControllerFocus(mButtons, mControllerFocus, false); setControllerFocus(mButtons, mControllerFocus, false);
mControllerFocus = wrap(mControllerFocus - 1, mButtons.size()); mControllerFocus = wrap(mControllerFocus, mButtons.size(), -1);
setControllerFocus(mButtons, mControllerFocus, true); setControllerFocus(mButtons, mControllerFocus, true);
} }
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
{ {
setControllerFocus(mButtons, mControllerFocus, false); setControllerFocus(mButtons, mControllerFocus, false);
mControllerFocus = wrap(mControllerFocus + 1, mButtons.size()); mControllerFocus = wrap(mControllerFocus, mButtons.size(), 1);
setControllerFocus(mButtons, mControllerFocus, true); setControllerFocus(mButtons, mControllerFocus, true);
} }
@ -428,8 +428,8 @@ namespace MWGui
{ {
if (!mScrollBar->getVisible()) if (!mScrollBar->getVisible())
return; return;
mScrollBar->setScrollPosition( mScrollBar->setScrollPosition(std::clamp<size_t>(
std::clamp<int>(mScrollBar->getScrollPosition() - rel * 0.3, 0, mScrollBar->getScrollRange() - 1)); static_cast<size_t>(mScrollBar->getScrollPosition() - rel * 0.3), 0, mScrollBar->getScrollRange() - 1));
onScrollbarMoved(mScrollBar, mScrollBar->getScrollPosition()); 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(); MWBase::DialogueManager* dialogueManager = MWBase::Environment::get().getDialogueManager();
@ -607,7 +607,7 @@ namespace MWGui
void DialogueWindow::updateTopicsPane() void DialogueWindow::updateTopicsPane()
{ {
std::string focusedTopic; std::string focusedTopic;
if (Settings::gui().mControllerMenus && mControllerFocus < static_cast<int>(mTopicsList->getItemCount())) if (Settings::gui().mControllerMenus && mControllerFocus < mTopicsList->getItemCount())
focusedTopic = mTopicsList->getItemNameAt(mControllerFocus); focusedTopic = mTopicsList->getItemNameAt(mControllerFocus);
mTopicsList->clear(); mTopicsList->clear();
@ -970,10 +970,10 @@ namespace MWGui
else if (mControllerChoice >= 0 && mControllerChoice < static_cast<int>(mChoices.size())) else if (mControllerChoice >= 0 && mControllerChoice < static_cast<int>(mChoices.size()))
onChoiceActivated(mChoices[mControllerChoice].second); onChoiceActivated(mChoices[mControllerChoice].second);
} }
else if (mControllerFocus == static_cast<int>(mTopicsList->getItemCount())) else if (mControllerFocus == mTopicsList->getItemCount())
onGoodbyeActivated(); onGoodbyeActivated();
else else
onSelectListItem(mTopicsList->getItemNameAt(mControllerFocus), mControllerFocus); onSelectListItem(mTopicsList->getItemNameAt(mControllerFocus), static_cast<int>(mControllerFocus));
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click")); MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
} }
else if (arg.button == SDL_CONTROLLER_BUTTON_B && mChoices.empty()) 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. // Number of items is mTopicsList.length+1 because of "Goodbye" button.
setControllerFocus(mControllerFocus, false); setControllerFocus(mControllerFocus, false);
if (mControllerFocus >= static_cast<int>(mTopicsList->getItemCount())) if (mControllerFocus >= mTopicsList->getItemCount())
mControllerFocus = 0; mControllerFocus = 0;
else if (mControllerFocus == static_cast<int>(mTopicsList->getItemCount()) - 1) else if (mControllerFocus == mTopicsList->getItemCount() - 1)
mControllerFocus = mTopicsList->getItemCount(); // "Goodbye" button mControllerFocus = mTopicsList->getItemCount(); // "Goodbye" button
else if (mTopicsList->getItemNameAt(mControllerFocus + 1).empty()) else if (mTopicsList->getItemNameAt(mControllerFocus + 1).empty())
mControllerFocus += 2; // Skip separator mControllerFocus += 2; // Skip separator
@ -1027,13 +1027,13 @@ namespace MWGui
else if (arg.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER && mChoices.size() == 0) else if (arg.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER && mChoices.size() == 0)
{ {
setControllerFocus(mControllerFocus, false); setControllerFocus(mControllerFocus, false);
mControllerFocus = std::max(mControllerFocus - 5, 0); mControllerFocus = mControllerFocus > 5 ? mControllerFocus - 5 : 0;
setControllerFocus(mControllerFocus, true); setControllerFocus(mControllerFocus, true);
} }
else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER && mChoices.size() == 0) else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER && mChoices.size() == 0)
{ {
setControllerFocus(mControllerFocus, false); setControllerFocus(mControllerFocus, false);
mControllerFocus = std::min(mControllerFocus + 5, static_cast<int>(mTopicsList->getItemCount())); mControllerFocus = std::min(mControllerFocus + 5, mTopicsList->getItemCount());
setControllerFocus(mControllerFocus, true); setControllerFocus(mControllerFocus, true);
} }

View file

@ -69,7 +69,7 @@ namespace MWGui
Gui::AutoSizedTextBox* mGoldLabel; Gui::AutoSizedTextBox* mGoldLabel;
std::vector<MyGUI::Button*> mButtons; std::vector<MyGUI::Button*> mButtons;
int mControllerFocus = 0; size_t mControllerFocus = 0;
void adjustAction(MyGUI::Widget* action, int& totalHeight); void adjustAction(MyGUI::Widget* action, int& totalHeight);
@ -230,7 +230,7 @@ namespace MWGui
std::unique_ptr<ResponseCallback> mGreetingCallback; std::unique_ptr<ResponseCallback> mGreetingCallback;
void setControllerFocus(size_t index, bool focused); void setControllerFocus(size_t index, bool focused);
int mControllerFocus = 0; size_t mControllerFocus = 0;
int mControllerChoice = -1; int mControllerChoice = -1;
void updateTopicFormat(); void updateTopicFormat();

View file

@ -349,7 +349,7 @@ namespace MWGui
if (mIsDrowning) if (mIsDrowning)
{ {
mDrowningFlashTheta += dt * osg::PI * 2; mDrowningFlashTheta += dt * osg::PIf * 2;
float intensity = (cos(mDrowningFlashTheta) + 2.0f) / 3.0f; float intensity = (cos(mDrowningFlashTheta) + 2.0f) / 3.0f;

View file

@ -37,7 +37,7 @@ namespace MWGui
ItemModel::ModelIndex InventoryItemModel::getIndex(const ItemStack& item) ItemModel::ModelIndex InventoryItemModel::getIndex(const ItemStack& item)
{ {
size_t i = 0; ModelIndex i = 0;
for (ItemStack& itemStack : mItems) for (ItemStack& itemStack : mItems)
{ {
if (itemStack == item) if (itemStack == item)
@ -51,7 +51,7 @@ namespace MWGui
{ {
if (item.mBase.getContainerStore() == &mActor.getClass().getContainerStore(mActor)) if (item.mBase.getContainerStore() == &mActor.getClass().getContainerStore(mActor))
throw std::runtime_error("Item to add needs to be from a different container!"); 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<int>(count), allowAutoEquip);
} }
MWWorld::Ptr InventoryItemModel::copyItem(const ItemStack& item, size_t count, bool 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)) if (item.mBase.getContainerStore() == &mActor.getClass().getContainerStore(mActor))
throw std::runtime_error("Item to copy needs to be from a different container!"); throw std::runtime_error("Item to copy needs to be from a different container!");
MWWorld::ManualRef newRef(*MWBase::Environment::get().getESMStore(), item.mBase, count); MWWorld::ManualRef newRef(*MWBase::Environment::get().getESMStore(), item.mBase, static_cast<int>(count));
return *mActor.getClass().getContainerStore(mActor).add(newRef.getPtr(), count, allowAutoEquip); return *mActor.getClass().getContainerStore(mActor).add(
newRef.getPtr(), static_cast<int>(count), allowAutoEquip);
} }
void InventoryItemModel::removeItem(const ItemStack& item, size_t count) void InventoryItemModel::removeItem(const ItemStack& item, size_t count)
@ -70,12 +71,12 @@ namespace MWGui
if (mActor.getClass().hasInventoryStore(mActor)) if (mActor.getClass().hasInventoryStore(mActor))
{ {
MWWorld::InventoryStore& store = mActor.getClass().getInventoryStore(mActor); MWWorld::InventoryStore& store = mActor.getClass().getInventoryStore(mActor);
removed = store.remove(item.mBase, count, true); removed = store.remove(item.mBase, static_cast<int>(count), true);
} }
else else
{ {
MWWorld::ContainerStore& store = mActor.getClass().getContainerStore(mActor); MWWorld::ContainerStore& store = mActor.getClass().getContainerStore(mActor);
removed = store.remove(item.mBase, count); removed = store.remove(item.mBase, static_cast<int>(count));
} }
std::stringstream error; std::stringstream error;

View file

@ -161,7 +161,7 @@ namespace MWGui
mScrollView->setVisibleVScroll(true); mScrollView->setVisibleVScroll(true);
if (Settings::gui().mControllerMenus) if (Settings::gui().mControllerMenus)
updateControllerFocus(-1, mControllerFocus); updateControllerFocus(mLines.size(), mControllerFocus);
} }
void ItemChargeView::resetScrollbars() void ItemChargeView::resetScrollbars()
@ -242,37 +242,37 @@ namespace MWGui
if (mLines.empty()) if (mLines.empty())
return; return;
int prevFocus = mControllerFocus; size_t prevFocus = mControllerFocus;
if (button == SDL_CONTROLLER_BUTTON_A) if (button == SDL_CONTROLLER_BUTTON_A)
{ {
// Select the focused item, if any. // Select the focused item, if any.
if (mControllerFocus >= 0 && mControllerFocus < static_cast<int>(mLines.size())) if (mControllerFocus < mLines.size())
onIconClicked(mLines[mControllerFocus].mIcon); onIconClicked(mLines[mControllerFocus].mIcon);
} }
else if (button == SDL_CONTROLLER_BUTTON_DPAD_UP) 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) else if (button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
mControllerFocus = wrap(mControllerFocus + 1, mLines.size()); mControllerFocus = wrap(mControllerFocus, mLines.size(), 1);
if (prevFocus != mControllerFocus) if (prevFocus != mControllerFocus)
updateControllerFocus(prevFocus, mControllerFocus); updateControllerFocus(prevFocus, mControllerFocus);
} }
void ItemChargeView::updateControllerFocus(int prevFocus, int newFocus) void ItemChargeView::updateControllerFocus(size_t prevFocus, size_t newFocus)
{ {
if (mLines.empty()) if (mLines.empty())
return; return;
const TextColours& textColours{ MWBase::Environment::get().getWindowManager()->getTextColours() }; const TextColours& textColours{ MWBase::Environment::get().getWindowManager()->getTextColours() };
if (prevFocus >= 0 && prevFocus < static_cast<int>(mLines.size())) if (prevFocus < mLines.size())
{ {
mLines[prevFocus].mText->setTextColour(textColours.normal); mLines[prevFocus].mText->setTextColour(textColours.normal);
mLines[prevFocus].mIcon->setControllerFocus(false); mLines[prevFocus].mIcon->setControllerFocus(false);
} }
if (newFocus >= 0 && newFocus < static_cast<int>(mLines.size())) if (newFocus >= 0 && newFocus < mLines.size())
{ {
mLines[newFocus].mText->setTextColour(textColours.link); mLines[newFocus].mText->setTextColour(textColours.link);
mLines[newFocus].mIcon->setControllerFocus(true); mLines[newFocus].mIcon->setControllerFocus(true);
@ -281,7 +281,7 @@ namespace MWGui
if (newFocus <= 3) if (newFocus <= 3)
mScrollView->setViewOffset(MyGUI::IntPoint(0, 0)); mScrollView->setViewOffset(MyGUI::IntPoint(0, 0));
else else
mScrollView->setViewOffset(MyGUI::IntPoint(0, -55 * (newFocus - 3))); mScrollView->setViewOffset(MyGUI::IntPoint(0, -55 * static_cast<int>(newFocus - 3)));
} }
} }
} }

View file

@ -75,8 +75,8 @@ namespace MWGui
MyGUI::ScrollView* mScrollView; MyGUI::ScrollView* mScrollView;
DisplayMode mDisplayMode; DisplayMode mDisplayMode;
int mControllerFocus = 0; size_t mControllerFocus = 0;
void updateControllerFocus(int prevFocus, int newFocus); void updateControllerFocus(size_t prevFocus, size_t newFocus);
}; };
} }

View file

@ -109,9 +109,9 @@ namespace MWGui
const ItemStack& itemToSearch = getItem(index); const ItemStack& itemToSearch = getItem(index);
for (size_t i = 0; i < mSourceModel->getItemCount(); ++i) for (size_t i = 0; i < mSourceModel->getItemCount(); ++i)
{ {
const ItemStack& item = mSourceModel->getItem(i); const ItemStack& item = mSourceModel->getItem(static_cast<ModelIndex>(i));
if (item.mBase == itemToSearch.mBase) if (item.mBase == itemToSearch.mBase)
return i; return static_cast<ModelIndex>(i);
} }
return -1; return -1;
} }
@ -121,9 +121,9 @@ namespace MWGui
const ItemStack& itemToSearch = mSourceModel->getItem(index); const ItemStack& itemToSearch = mSourceModel->getItem(index);
for (size_t i = 0; i < getItemCount(); ++i) for (size_t i = 0; i < getItemCount(); ++i)
{ {
const ItemStack& item = getItem(i); const ItemStack& item = getItem(static_cast<ModelIndex>(i));
if (item.mBase == itemToSearch.mBase) if (item.mBase == itemToSearch.mBase)
return i; return static_cast<ModelIndex>(i);
} }
return -1; return -1;
} }

View file

@ -55,7 +55,7 @@ namespace MWGui
WorldItemModel worldItemModel(0.5f, 0.5f); WorldItemModel worldItemModel(0.5f, 0.5f);
ItemModel* const targetModel = targetView == nullptr ? &worldItemModel : targetView->getModel(); ItemModel* const targetModel = targetView == nullptr ? &worldItemModel : targetView->getModel();
if (!targetModel->onDropItem(item.mBase, count)) if (!targetModel->onDropItem(item.mBase, static_cast<int>(count)))
return; return;
sourceView.getModel()->moveItem(item, count, targetModel); sourceView.getModel()->moveItem(item, count, targetModel);

View file

@ -49,7 +49,7 @@ namespace
{ {
struct DisplayState struct DisplayState
{ {
unsigned int mPage; size_t mPage;
Book mBook; Book mBook;
}; };
@ -159,8 +159,8 @@ namespace
{ {
// english button has a 7 pixel wide strip of garbage on its right edge // english button has a 7 pixel wide strip of garbage on its right edge
nextButton->setSize(64 - 7, nextButton->getSize().height); nextButton->setSize(64 - 7, nextButton->getSize().height);
nextButton->setImageCoord( nextButton->setImageCoord(MyGUI::IntCoord(0, 0, static_cast<int>((64 - 7) * nextButtonScale),
MyGUI::IntCoord(0, 0, (64 - 7) * nextButtonScale, nextButton->getSize().height * nextButtonScale)); static_cast<int>(nextButton->getSize().height * nextButtonScale)));
} }
if (!questList) if (!questList)
@ -246,12 +246,12 @@ namespace
else else
journalBook = createJournalBook(); journalBook = createJournalBook();
pushBook(journalBook, 0); pushBook(journalBook);
// fast forward to the last page // fast forward to the last page
if (!mStates.empty()) if (!mStates.empty())
{ {
unsigned int& page = mStates.top().mPage; size_t& page = mStates.top().mPage;
page = mStates.top().mBook->pageCount() - 1; page = mStates.top().mBook->pageCount() - 1;
if (page % 2) if (page % 2)
--page; --page;
@ -326,21 +326,21 @@ namespace
MWBase::Environment::get().getWindowManager()->updateControllerButtonsOverlay(); MWBase::Environment::get().getWindowManager()->updateControllerButtonsOverlay();
} }
void pushBook(Book& book, unsigned int page) void pushBook(Book& book)
{ {
DisplayState bs; DisplayState bs;
bs.mPage = page; bs.mPage = 0;
bs.mBook = book; bs.mBook = book;
mStates.push(bs); mStates.push(bs);
updateShowingPages(); updateShowingPages();
updateCloseJournalButton(); updateCloseJournalButton();
} }
void replaceBook(Book& book, unsigned int page) void replaceBook(Book& book)
{ {
assert(!mStates.empty()); assert(!mStates.empty());
mStates.top().mBook = book; mStates.top().mBook = book;
mStates.top().mPage = page; mStates.top().mPage = 0;
updateShowingPages(); updateShowingPages();
} }
@ -361,8 +361,8 @@ namespace
void updateShowingPages() void updateShowingPages()
{ {
Book book; Book book;
unsigned int page; size_t page;
unsigned int relPages; size_t relPages;
if (!mStates.empty()) if (!mStates.empty())
{ {
@ -415,9 +415,9 @@ namespace
Book topicBook = createTopicBook(linkId); Book topicBook = createTopicBook(linkId);
if (mStates.size() > 1) if (mStates.size() > 1)
replaceBook(topicBook, 0); replaceBook(topicBook);
else else
pushBook(topicBook, 0); pushBook(topicBook);
setVisible(OptionsOverlay, false); setVisible(OptionsOverlay, false);
setVisible(OptionsBTN, true); setVisible(OptionsBTN, true);
@ -447,9 +447,9 @@ namespace
Book book = createQuestBook(name); Book book = createQuestBook(name);
if (mStates.size() > 1) if (mStates.size() > 1)
replaceBook(book, 0); replaceBook(book);
else else
pushBook(book, 0); pushBook(book);
setVisible(OptionsOverlay, false); setVisible(OptionsOverlay, false);
setVisible(OptionsBTN, true); setVisible(OptionsBTN, true);
@ -604,7 +604,7 @@ namespace
if (Settings::gui().mControllerMenus) if (Settings::gui().mControllerMenus)
{ {
addControllerButtons(list, mSelectedQuest); addControllerButtons(list, mSelectedQuest);
setControllerFocusedQuest(MWGui::wrap(mSelectedQuest, mButtons.size())); setControllerFocusedQuest(std::min(mSelectedQuest, mButtons.size()));
} }
if (mAllQuests) if (mAllQuests)
@ -663,7 +663,7 @@ namespace
return; return;
if (!mStates.empty()) if (!mStates.empty())
{ {
unsigned int& page = mStates.top().mPage; size_t& page = mStates.top().mPage;
Book book = mStates.top().mBook; Book book = mStates.top().mBook;
if (page + 2 < book->pageCount()) if (page + 2 < book->pageCount())
@ -682,7 +682,7 @@ namespace
return; return;
if (!mStates.empty()) if (!mStates.empty())
{ {
unsigned int& page = mStates.top().mPage; size_t& page = mStates.top().mPage;
if (page >= 2) if (page >= 2)
{ {
@ -718,8 +718,8 @@ namespace
void setIndexControllerFocus(bool focused) void setIndexControllerFocus(bool focused)
{ {
int col = mSelectedIndex / mIndexRowCount; size_t col = mSelectedIndex / mIndexRowCount;
int row = mSelectedIndex % mIndexRowCount; size_t row = mSelectedIndex % mIndexRowCount;
mTopicIndexBook->setColour(col, row, 0, focused ? MWGui::journalHeaderColour : MyGUI::Colour::Black); mTopicIndexBook->setColour(col, row, 0, focused ? MWGui::journalHeaderColour : MyGUI::Colour::Black);
} }
@ -728,7 +728,7 @@ namespace
setIndexControllerFocus(false); setIndexControllerFocus(false);
int numChars = mEncoding == ToUTF8::WINDOWS_1251 ? 30 : 26; int numChars = mEncoding == ToUTF8::WINDOWS_1251 ? 30 : 26;
int col = mSelectedIndex / mIndexRowCount; size_t col = mSelectedIndex / mIndexRowCount;
if (offset == -1) // Up if (offset == -1) // Up
{ {
@ -836,7 +836,7 @@ namespace
return true; return true;
// Scroll through the list of quests or topics // Scroll through the list of quests or topics
setControllerFocusedQuest(MWGui::wrap(mSelectedQuest - 1, mButtons.size())); setControllerFocusedQuest(MWGui::wrap(mSelectedQuest, mButtons.size(), -1));
} }
else else
moveSelectedIndex(-1); moveSelectedIndex(-1);
@ -849,19 +849,19 @@ namespace
return true; return true;
// Scroll through the list of quests or topics // Scroll through the list of quests or topics
setControllerFocusedQuest(MWGui::wrap(mSelectedQuest + 1, mButtons.size())); setControllerFocusedQuest(MWGui::wrap(mSelectedQuest, mButtons.size(), 1));
} }
else else
moveSelectedIndex(1); moveSelectedIndex(1);
} }
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT && !mQuestMode && !mTopicsMode) else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT && !mQuestMode && !mTopicsMode)
moveSelectedIndex(-mIndexRowCount); moveSelectedIndex(-static_cast<int>(mIndexRowCount));
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT && !mQuestMode && !mTopicsMode) else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT && !mQuestMode && !mTopicsMode)
moveSelectedIndex(mIndexRowCount); moveSelectedIndex(static_cast<int>(mIndexRowCount));
else if (arg.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER && (mQuestMode || mTopicsMode)) else if (arg.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER && (mQuestMode || mTopicsMode))
{ {
// Scroll up 5 items in the list of quests or topics // Scroll up 5 items in the list of quests or topics
setControllerFocusedQuest(std::max(static_cast<int>(mSelectedQuest) - 5, 0)); setControllerFocusedQuest(mSelectedQuest >= 5 ? mSelectedQuest - 5 : 0);
} }
else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER && (mQuestMode || mTopicsMode)) else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER && (mQuestMode || mTopicsMode))
{ {

View file

@ -36,10 +36,6 @@ namespace MWGui
size_t mIndexRowCount = 1; size_t mIndexRowCount = 1;
size_t mSelectedQuest = 0; size_t mSelectedQuest = 0;
size_t mSelectedIndex = 0; size_t mSelectedIndex = 0;
void moveSelectedIndex(int offset);
void setIndexControllerFocus(bool focused);
void setControllerFocusedQuest(size_t index);
bool optionsModeButtonHandler(const SDL_ControllerButtonEvent& arg);
}; };
} }

View file

@ -111,7 +111,7 @@ namespace MWGui
for (const ESM::Attribute& attribute : MWBase::Environment::get().getESMStore()->get<ESM::Attribute>()) for (const ESM::Attribute& attribute : MWBase::Environment::get().getESMStore()->get<ESM::Attribute>())
{ {
int val = creatureStats.getAttribute(attribute.mId).getBase(); int val = static_cast<int>(creatureStats.getAttribute(attribute.mId).getBase());
if (std::find(mSpentAttributes.begin(), mSpentAttributes.end(), attribute.mId) != mSpentAttributes.end()) if (std::find(mSpentAttributes.begin(), mSpentAttributes.end(), attribute.mId) != mSpentAttributes.end())
{ {
val += pcStats.getLevelupAttributeMultiplier(attribute.mId); val += pcStats.getLevelupAttributeMultiplier(attribute.mId);
@ -202,8 +202,8 @@ namespace MWGui
widgets.mValue->setEnabled(true); widgets.mValue->setEnabled(true);
availableAttributes++; availableAttributes++;
float mult = pcStats.getLevelupAttributeMultiplier(attribute.mId); int mult = pcStats.getLevelupAttributeMultiplier(attribute.mId);
mult = std::min(mult, 100 - pcStats.getAttribute(attribute.mId).getBase()); mult = std::min(mult, static_cast<int>(100 - pcStats.getAttribute(attribute.mId).getBase()));
if (mult <= 1) if (mult <= 1)
widgets.mMultiplier->setCaption({}); widgets.mMultiplier->setCaption({});
else else
@ -231,7 +231,7 @@ namespace MWGui
{ {
mControllerFocus = 0; mControllerFocus = 0;
for (size_t i = 0; i < mAttributeButtons.size(); i++) for (size_t i = 0; i < mAttributeButtons.size(); i++)
setControllerFocus(mAttributeButtons, i, i == 0); mAttributeButtons[i]->setStateSelected(i == 0);
} }
// Play LevelUp Music // Play LevelUp Music

View file

@ -120,8 +120,9 @@ namespace MWGui
void operator()(osg::RenderInfo& renderInfo) const override void operator()(osg::RenderInfo& renderInfo) const override
{ {
int w = renderInfo.getCurrentCamera()->getViewport()->width(); const osg::Viewport* viewPort = renderInfo.getCurrentCamera()->getViewport();
int h = renderInfo.getCurrentCamera()->getViewport()->height(); int w = static_cast<int>(viewPort->width());
int h = static_cast<int>(viewPort->height());
mTexture->copyTexImage2D(*renderInfo.getState(), 0, 0, w, h); mTexture->copyTexImage2D(*renderInfo.getState(), 0, 0, w, h);
mOneshot = false; mOneshot = false;
@ -208,7 +209,8 @@ namespace MWGui
{ {
if (!mSplashScreens.empty()) 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<int>(mSplashScreens.size())));
// TODO: add option (filename pattern?) to use image aspect ratio instead of 4:3 // 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 // 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; return false;
// the minimal delay before a loading screen shows // the minimal delay before a loading screen shows
const float initialDelay = 0.05; constexpr float initialDelay = 0.05f;
bool alreadyShown = (mLastRenderTime > mLoadingOnTime); bool alreadyShown = (mLastRenderTime > mLoadingOnTime);
float diff = (mTimer.time_m() - mLoadingOnTime); double diff = (mTimer.time_m() - mLoadingOnTime);
if (!alreadyShown) if (!alreadyShown)
{ {

View file

@ -71,7 +71,7 @@ namespace MWGui
size_t mProgress; size_t mProgress;
bool mShowWallpaper; bool mShowWallpaper;
float mOldIcoMin = 0.f; double mOldIcoMin = 0.0;
unsigned int mOldIcoMax = 0; unsigned int mOldIcoMax = 0;
MyGUI::Widget* mLoadingBox; MyGUI::Widget* mLoadingBox;

View file

@ -364,10 +364,10 @@ namespace MWGui
// Trim off some of the excessive padding // Trim off some of the excessive padding
// TODO: perhaps do this within ImageButton? // TODO: perhaps do this within ImageButton?
int height = requested.height; int height = requested.height;
button->setImageTile(MyGUI::IntSize(requested.width, requested.height - 16 * scale)); button->setImageTile(MyGUI::IntSize(requested.width, static_cast<int>(requested.height - 16 * scale)));
button->setCoord( button->setCoord(static_cast<int>((maxwidth - requested.width / scale) / 2), curH,
(maxwidth - requested.width / scale) / 2, curH, requested.width / scale, height / scale - 16); static_cast<int>(requested.width / scale), static_cast<int>(height / scale - 16));
curH += height / scale - 16; curH += static_cast<int>(height / scale - 16);
} }
if (state == MWBase::StateManager::State_NoGame) if (state == MWBase::StateManager::State_NoGame)

View file

@ -92,7 +92,8 @@ namespace
return Constants::CellGridRadius; return Constants::CellGridRadius;
if (!Settings::terrain().mDistantTerrain) if (!Settings::terrain().mDistantTerrain)
return Constants::CellGridRadius; return Constants::CellGridRadius;
const int viewingDistanceInCells = Settings::camera().mViewingDistance / Constants::CellSizeInUnits; const int viewingDistanceInCells
= static_cast<int>(Settings::camera().mViewingDistance / Constants::CellSizeInUnits);
return std::clamp( return std::clamp(
viewingDistanceInCells, Constants::CellGridRadius, Settings::map().mMaxLocalViewingDistance.get()); viewingDistanceInCells, Constants::CellGridRadius, Settings::map().mMaxLocalViewingDistance.get());
} }
@ -255,8 +256,8 @@ namespace MWGui
{ {
// normalized cell coordinates // normalized cell coordinates
auto mapWidgetSize = getWidgetSize(); auto mapWidgetSize = getWidgetSize();
return MyGUI::IntPoint(std::round((nX + cellX - mGrid.left) * mapWidgetSize), return MyGUI::IntPoint(static_cast<int>(std::round((nX + cellX - mGrid.left) * mapWidgetSize)),
std::round((nY - cellY + mGrid.bottom) * mapWidgetSize)); static_cast<int>(std::round((nY - cellY + mGrid.bottom) * mapWidgetSize)));
} }
MyGUI::IntPoint LocalMapBase::getMarkerPosition(float worldX, float worldY, MarkerUserData& markerPos) const MyGUI::IntPoint LocalMapBase::getMarkerPosition(float worldX, float worldY, MarkerUserData& markerPos) const
@ -286,7 +287,7 @@ namespace MWGui
} }
MyGUI::IntCoord LocalMapBase::getMarkerCoordinates( 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; int halfMarkerSize = markerSize / 2;
auto position = getMarkerPosition(worldX, worldY, markerPos); auto position = getMarkerPosition(worldX, worldY, markerPos);
@ -320,7 +321,7 @@ namespace MWGui
mLocalMap->setViewOffset(viewOffset); 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<MarkerUserData>()); MarkerUserData& markerPos(*widget->getUserData<MarkerUserData>());
auto position = getPosition(markerPos.cellX, markerPos.cellY, markerPos.nX, markerPos.nY); 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() }) if (oldSize != MyGUI::IntSize{ mGrid.width(), mGrid.height() })
setCanvasSize(mLocalMap, mGrid, getWidgetSize()); setCanvasSize(mLocalMap, mGrid, static_cast<int>(getWidgetSize()));
// Delay the door markers update until scripts have been given a chance to run. // 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. // 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<std::string> destNotes; std::vector<std::string> destNotes;
CustomMarkerCollection::RangeType markers = mCustomMarkers.getMarkers(marker.dest); CustomMarkerCollection::RangeType markers = mCustomMarkers.getMarkers(marker.dest);
for (CustomMarkerCollection::ContainerType::const_iterator iter = markers.first; iter != markers.second; for (auto iter = markers.first; iter != markers.second; ++iter)
++iter)
destNotes.push_back(iter->second.mNote); destNotes.push_back(iter->second.mNote);
MyGUI::Widget* markerWidget = nullptr; MyGUI::Widget* markerWidget = nullptr;
@ -733,9 +733,10 @@ namespace MWGui
void LocalMapBase::updateLocalMap() void LocalMapBase::updateLocalMap()
{ {
auto mapWidgetSize = getWidgetSize(); auto mapWidgetSize = getWidgetSize();
setCanvasSize(mLocalMap, mGrid, getWidgetSize()); setCanvasSize(mLocalMap, mGrid, static_cast<int>(getWidgetSize()));
const auto size = MyGUI::IntSize(std::ceil(mapWidgetSize), std::ceil(mapWidgetSize)); const auto size
= MyGUI::IntSize(static_cast<int>(std::ceil(mapWidgetSize)), static_cast<int>(std::ceil(mapWidgetSize)));
for (auto& entry : mMaps) for (auto& entry : mMaps)
{ {
const auto position = getPosition(entry.mCellX, entry.mCellY, 0, 0); const auto position = getPosition(entry.mCellX, entry.mCellY, 0, 0);
@ -1570,7 +1571,7 @@ namespace MWGui
{ {
if (getDeleteButtonShown()) if (getDeleteButtonShown())
{ {
mControllerFocus = wrap(mControllerFocus - 1, 3); mControllerFocus = wrap(mControllerFocus, 3, -1);
mDeleteButton->setStateSelected(mControllerFocus == 0); mDeleteButton->setStateSelected(mControllerFocus == 0);
mOkButton->setStateSelected(mControllerFocus == 1); mOkButton->setStateSelected(mControllerFocus == 1);
mCancelButton->setStateSelected(mControllerFocus == 2); mCancelButton->setStateSelected(mControllerFocus == 2);
@ -1586,7 +1587,7 @@ namespace MWGui
{ {
if (getDeleteButtonShown()) if (getDeleteButtonShown())
{ {
mControllerFocus = wrap(mControllerFocus + 1, 3); mControllerFocus = wrap(mControllerFocus, 3, 1);
mDeleteButton->setStateSelected(mControllerFocus == 0); mDeleteButton->setStateSelected(mControllerFocus == 0);
mOkButton->setStateSelected(mControllerFocus == 1); mOkButton->setStateSelected(mControllerFocus == 1);
mCancelButton->setStateSelected(mControllerFocus == 2); mCancelButton->setStateSelected(mControllerFocus == 2);

View file

@ -163,9 +163,9 @@ namespace MWGui
MyGUI::IntPoint getPosition(int cellX, int cellY, float nx, float ny) const; MyGUI::IntPoint getPosition(int cellX, int cellY, float nx, float ny) const;
MyGUI::IntPoint getMarkerPosition(float worldX, float worldY, MarkerUserData& markerPos) const; MyGUI::IntPoint getMarkerPosition(float worldX, float worldY, MarkerUserData& markerPos) const;
MyGUI::IntCoord getMarkerCoordinates( 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::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 notifyPlayerUpdate() {}
virtual void centerView(); virtual void centerView();
@ -225,7 +225,7 @@ namespace MWGui
MyGUI::Button* mDeleteButton; MyGUI::Button* mDeleteButton;
bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
int mControllerFocus = 0; size_t mControllerFocus = 0;
}; };
class MapWindow : public MWGui::WindowPinnableBase, public LocalMapBase, public NoDrop class MapWindow : public MWGui::WindowPinnableBase, public LocalMapBase, public NoDrop

View file

@ -191,7 +191,7 @@ namespace MWGui
return true; return true;
mButtons[mControllerFocus].first->setStateSelected(false); mButtons[mControllerFocus].first->setStateSelected(false);
mControllerFocus = wrap(mControllerFocus - 1, mButtons.size()); mControllerFocus = wrap(mControllerFocus, mButtons.size(), -1);
mButtons[mControllerFocus].first->setStateSelected(true); mButtons[mControllerFocus].first->setStateSelected(true);
} }
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
@ -200,7 +200,7 @@ namespace MWGui
return true; return true;
mButtons[mControllerFocus].first->setStateSelected(false); mButtons[mControllerFocus].first->setStateSelected(false);
mControllerFocus = wrap(mControllerFocus + 1, mButtons.size()); mControllerFocus = wrap(mControllerFocus, mButtons.size(), 1);
mButtons[mControllerFocus].first->setStateSelected(true); mButtons[mControllerFocus].first->setStateSelected(true);
} }
@ -213,7 +213,7 @@ namespace MWGui
else else
{ {
const int lineHeight = Settings::gui().mFontSize + 2; const int lineHeight = Settings::gui().mFontSize + 2;
mList->setViewOffset(MyGUI::IntPoint(0, -lineHeight * (line - 5))); mList->setViewOffset(MyGUI::IntPoint(0, -lineHeight * static_cast<int>(line - 5)));
} }
} }

View file

@ -473,7 +473,7 @@ namespace MWGui
return true; return true;
setControllerFocus(mButtons, mControllerFocus, false); setControllerFocus(mButtons, mControllerFocus, false);
mControllerFocus = wrap(mControllerFocus - 1, mButtons.size()); mControllerFocus = wrap(mControllerFocus, mButtons.size(), -1);
setControllerFocus(mButtons, mControllerFocus, true); setControllerFocus(mButtons, mControllerFocus, true);
} }
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN || arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT) else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN || arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
@ -484,7 +484,7 @@ namespace MWGui
return true; return true;
setControllerFocus(mButtons, mControllerFocus, false); setControllerFocus(mButtons, mControllerFocus, false);
mControllerFocus = wrap(mControllerFocus + 1, mButtons.size()); mControllerFocus = wrap(mControllerFocus, mButtons.size(), 1);
setControllerFocus(mButtons, mControllerFocus, true); setControllerFocus(mButtons, mControllerFocus, true);
} }

View file

@ -290,8 +290,8 @@ namespace MWGui
if (texture) if (texture)
scale = texture->getHeight() / 64.f; scale = texture->getHeight() / 64.f;
mSelected->button->setFrame( mSelected->button->setFrame("textures\\menu_icon_select_magic_magic.dds",
"textures\\menu_icon_select_magic_magic.dds", MyGUI::IntCoord(0, 0, 44 * scale, 44 * scale)); MyGUI::IntCoord(0, 0, static_cast<int>(44 * scale), static_cast<int>(44 * scale)));
mSelected->button->setIcon(item); mSelected->button->setIcon(item);
mSelected->button->setUserString("ToolTipType", "ItemPtr"); mSelected->button->setUserString("ToolTipType", "ItemPtr");
@ -562,9 +562,9 @@ namespace MWGui
else if (arg.button == SDL_CONTROLLER_BUTTON_B) else if (arg.button == SDL_CONTROLLER_BUTTON_B)
mParent->onCancelButtonClicked(mCancelButton); mParent->onCancelButtonClicked(mCancelButton);
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP) 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) else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
mControllerFocus = wrap(mControllerFocus + 1, 4); mControllerFocus = wrap(mControllerFocus, 4, 1);
mItemButton->setStateSelected(mControllerFocus == 0); mItemButton->setStateSelected(mControllerFocus == 0);
mMagicButton->setStateSelected(mControllerFocus == 1); mMagicButton->setStateSelected(mControllerFocus == 1);

View file

@ -96,7 +96,7 @@ namespace MWGui
QuickKeysMenu* mParent; QuickKeysMenu* mParent;
bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
int mControllerFocus = 0; size_t mControllerFocus = 0;
}; };
class MagicSelectionDialog : public WindowModal class MagicSelectionDialog : public WindowModal
@ -117,7 +117,7 @@ namespace MWGui
void onModelIndexSelected(SpellModel::ModelIndex index); void onModelIndexSelected(SpellModel::ModelIndex index);
bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override; bool onControllerButtonEvent(const SDL_ControllerButtonEvent& arg) override;
int mControllerFocus = 0; size_t mControllerFocus = 0;
}; };
} }

View file

@ -256,7 +256,7 @@ namespace MWGui
void RaceDialog::onSelectPreviousGender(MyGUI::Widget*) void RaceDialog::onSelectPreviousGender(MyGUI::Widget*)
{ {
mGenderIndex = wrap(mGenderIndex - 1, 2); mGenderIndex = wrap(mGenderIndex, 2, -1);
recountParts(); recountParts();
updatePreview(); updatePreview();
@ -264,7 +264,7 @@ namespace MWGui
void RaceDialog::onSelectNextGender(MyGUI::Widget*) void RaceDialog::onSelectNextGender(MyGUI::Widget*)
{ {
mGenderIndex = wrap(mGenderIndex + 1, 2); mGenderIndex = wrap(mGenderIndex, 2, 1);
recountParts(); recountParts();
updatePreview(); updatePreview();
@ -272,25 +272,25 @@ namespace MWGui
void RaceDialog::onSelectPreviousFace(MyGUI::Widget*) void RaceDialog::onSelectPreviousFace(MyGUI::Widget*)
{ {
mFaceIndex = wrap(mFaceIndex - 1, mAvailableHeads.size()); mFaceIndex = wrap(mFaceIndex, mAvailableHeads.size(), -1);
updatePreview(); updatePreview();
} }
void RaceDialog::onSelectNextFace(MyGUI::Widget*) void RaceDialog::onSelectNextFace(MyGUI::Widget*)
{ {
mFaceIndex = wrap(mFaceIndex + 1, mAvailableHeads.size()); mFaceIndex = wrap(mFaceIndex, mAvailableHeads.size(), 1);
updatePreview(); updatePreview();
} }
void RaceDialog::onSelectPreviousHair(MyGUI::Widget*) void RaceDialog::onSelectPreviousHair(MyGUI::Widget*)
{ {
mHairIndex = wrap(mHairIndex - 1, mAvailableHairs.size()); mHairIndex = wrap(mHairIndex, mAvailableHairs.size(), -1);
updatePreview(); updatePreview();
} }
void RaceDialog::onSelectNextHair(MyGUI::Widget*) void RaceDialog::onSelectNextHair(MyGUI::Widget*)
{ {
mHairIndex = wrap(mHairIndex + 1, mAvailableHairs.size()); mHairIndex = wrap(mHairIndex, mAvailableHairs.size(), 1);
updatePreview(); updatePreview();
} }
@ -359,10 +359,10 @@ namespace MWGui
record.mRace = mCurrentRaceId; record.mRace = mCurrentRaceId;
record.setIsMale(mGenderIndex == 0); record.setIsMale(mGenderIndex == 0);
if (mFaceIndex >= 0 && mFaceIndex < int(mAvailableHeads.size())) if (mFaceIndex >= 0 && mFaceIndex < mAvailableHeads.size())
record.mHead = mAvailableHeads[mFaceIndex]; record.mHead = mAvailableHeads[mFaceIndex];
if (mHairIndex >= 0 && mHairIndex < int(mAvailableHairs.size())) if (mHairIndex >= 0 && mHairIndex < mAvailableHairs.size())
record.mHair = mAvailableHairs[mHairIndex]; record.mHair = mAvailableHairs[mHairIndex];
try try

View file

@ -110,7 +110,7 @@ namespace MWGui
MyGUI::Widget* mSpellPowerList; MyGUI::Widget* mSpellPowerList;
std::vector<MyGUI::Widget*> mSpellPowerItems; std::vector<MyGUI::Widget*> mSpellPowerItems;
int mGenderIndex, mFaceIndex, mHairIndex; size_t mGenderIndex, mFaceIndex, mHairIndex;
ESM::RefId mCurrentRaceId; ESM::RefId mCurrentRaceId;

View file

@ -381,8 +381,8 @@ namespace MWGui
} }
const MWMechanics::SkillValue& stat = skillValue->second; const MWMechanics::SkillValue& stat = skillValue->second;
int base = stat.getBase(); float base = stat.getBase();
int modified = stat.getModified(); float modified = stat.getModified();
std::string state = "normal"; std::string state = "normal";
if (modified > base) 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) else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP || arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT)
{ {
setControllerFocus(mButtons, mControllerFocus, false); setControllerFocus(mButtons, mControllerFocus, false);
mControllerFocus = wrap(mControllerFocus - 1, mButtons.size()); mControllerFocus = wrap(mControllerFocus, mButtons.size(), -1);
setControllerFocus(mButtons, mControllerFocus, true); setControllerFocus(mButtons, mControllerFocus, true);
} }
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN || arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT) else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN || arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
{ {
setControllerFocus(mButtons, mControllerFocus, false); setControllerFocus(mButtons, mControllerFocus, false);
mControllerFocus = wrap(mControllerFocus + 1, mButtons.size()); mControllerFocus = wrap(mControllerFocus, mButtons.size(), 1);
setControllerFocus(mButtons, mControllerFocus, true); setControllerFocus(mButtons, mControllerFocus, true);
} }

View file

@ -104,7 +104,7 @@ namespace MWGui
// 0 = Name, 1 = Race, 2 = Class, 3 = BirthSign, 4 = Back, 5 = OK // 0 = Name, 1 = Race, 2 = Class, 3 = BirthSign, 4 = Back, 5 = OK
std::vector<MyGUI::Button*> mButtons; std::vector<MyGUI::Button*> mButtons;
int mControllerFocus = 0; size_t mControllerFocus = 0;
}; };
} }
#endif #endif

View file

@ -549,7 +549,7 @@ namespace MWGui
else if (arg.button == SDL_CONTROLLER_BUTTON_Y) else if (arg.button == SDL_CONTROLLER_BUTTON_Y)
{ {
size_t index = mCharacterSelection->getIndexSelected(); size_t index = mCharacterSelection->getIndexSelected();
index = wrap(index + 1, mCharacterSelection->getItemCount()); index = wrap(index, mCharacterSelection->getItemCount(), 1);
mCharacterSelection->setIndexSelected(index); mCharacterSelection->setIndexSelected(index);
onCharacterSelected(mCharacterSelection, index); onCharacterSelected(mCharacterSelection, index);
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click")); MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));

View file

@ -1144,7 +1144,7 @@ namespace MWGui
else if (arg.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER) else if (arg.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER)
{ {
size_t index = mSettingsTab->getIndexSelected(); size_t index = mSettingsTab->getIndexSelected();
index = wrap(index - 1, mSettingsTab->getItemCount()); index = wrap(index, mSettingsTab->getItemCount(), -1);
mSettingsTab->setIndexSelected(index); mSettingsTab->setIndexSelected(index);
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click")); MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
return true; return true;
@ -1152,7 +1152,7 @@ namespace MWGui
else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER) else if (arg.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER)
{ {
size_t index = mSettingsTab->getIndexSelected(); size_t index = mSettingsTab->getIndexSelected();
index = wrap(index + 1, mSettingsTab->getItemCount()); index = wrap(index, mSettingsTab->getItemCount(), 1);
mSettingsTab->setIndexSelected(index); mSettingsTab->setIndexSelected(index);
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click")); MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
return true; return true;

View file

@ -79,8 +79,6 @@ namespace
if (mSortByType && left.mType != right.mType) if (mSortByType && left.mType != right.mType)
return left.mType < right.mType; return left.mType < right.mType;
float result = 0;
// compare items by type // compare items by type
auto leftType = left.mBase.getType(); auto leftType = left.mBase.getType();
auto rightType = right.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 leftName = Utf8Stream::lowerCaseUtf8(left.mBase.getClass().getName(left.mBase));
std::string rightName = Utf8Stream::lowerCaseUtf8(right.mBase.getClass().getName(right.mBase)); std::string rightName = Utf8Stream::lowerCaseUtf8(right.mBase.getClass().getName(right.mBase));
result = leftName.compare(rightName); {
if (result != 0) int result = leftName.compare(rightName);
return result < 0; if (result != 0)
return result < 0;
}
// compare items by enchantment: // compare items by enchantment:
// 1. enchanted items showed before non-enchanted // 1. enchanted items showed before non-enchanted
@ -133,32 +133,38 @@ namespace
} }
} }
result = leftChargePercent - rightChargePercent; {
if (result != 0) int result = leftChargePercent - rightChargePercent;
return result > 0; if (result != 0)
return result > 0;
}
// compare items by condition // compare items by condition
if (left.mBase.getClass().hasItemHealth(left.mBase) && right.mBase.getClass().hasItemHealth(right.mBase)) 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); - right.mBase.getClass().getItemHealth(right.mBase);
if (result != 0) if (result != 0)
return result > 0; return result > 0;
} }
// compare items by remaining usage time // compare items by remaining usage time
result = left.mBase.getClass().getRemainingUsageTime(left.mBase) {
- right.mBase.getClass().getRemainingUsageTime(right.mBase); float result = left.mBase.getClass().getRemainingUsageTime(left.mBase)
if (result != 0) - right.mBase.getClass().getRemainingUsageTime(right.mBase);
return result > 0; if (result != 0)
return result > 0;
}
// compare items by value // compare items by value
result = left.mBase.getClass().getValue(left.mBase) - right.mBase.getClass().getValue(right.mBase); {
if (result != 0) int result = left.mBase.getClass().getValue(left.mBase) - right.mBase.getClass().getValue(right.mBase);
return result > 0; if (result != 0)
return result > 0;
}
// compare items by weight // 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) if (result != 0)
return result > 0; return result > 0;
@ -377,16 +383,15 @@ namespace MWGui
mItems.clear(); mItems.clear();
for (size_t i = 0; i < count; ++i) for (size_t i = 0; i < count; ++i)
{ {
ItemStack item = mSourceModel->getItem(i); ItemStack item = mSourceModel->getItem(static_cast<ModelIndex>(i));
for (std::vector<std::pair<MWWorld::Ptr, size_t>>::iterator it = mDragItems.begin(); it != mDragItems.end(); for (const std::pair<MWWorld::Ptr, size_t>& drag : mDragItems)
++it)
{ {
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"); throw std::runtime_error("Dragging more than present in the model");
item.mCount -= it->second; item.mCount -= drag.second;
} }
} }

View file

@ -254,7 +254,7 @@ namespace MWGui
return true; return true;
mSpellButtons[mControllerFocus].first->setStateSelected(false); mSpellButtons[mControllerFocus].first->setStateSelected(false);
mControllerFocus = wrap(mControllerFocus - 1, mSpellButtons.size()); mControllerFocus = wrap(mControllerFocus, mSpellButtons.size(), -1);
mSpellButtons[mControllerFocus].first->setStateSelected(true); mSpellButtons[mControllerFocus].first->setStateSelected(true);
} }
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
@ -265,7 +265,7 @@ namespace MWGui
return true; return true;
mSpellButtons[mControllerFocus].first->setStateSelected(false); mSpellButtons[mControllerFocus].first->setStateSelected(false);
mControllerFocus = wrap(mControllerFocus + 1, mSpellButtons.size()); mControllerFocus = wrap(mControllerFocus, mSpellButtons.size(), 1);
mSpellButtons[mControllerFocus].first->setStateSelected(true); mSpellButtons[mControllerFocus].first->setStateSelected(true);
} }
else else
@ -280,7 +280,7 @@ namespace MWGui
else else
{ {
const int lineHeight = Settings::gui().mFontSize + 2; const int lineHeight = Settings::gui().mFontSize + 2;
mSpellsView->setViewOffset(MyGUI::IntPoint(0, -lineHeight * (line - 5))); mSpellsView->setViewOffset(MyGUI::IntPoint(0, -lineHeight * static_cast<int>(line - 5)));
} }
// Warp the mouse to the selected spell to show the tooltip // Warp the mouse to the selected spell to show the tooltip

View file

@ -224,7 +224,7 @@ namespace MWGui
mEffectName->setCaptionWithReplacing("#{" + ESM::MagicEffect::indexToGmstString(effect->mIndex) + "}"); mEffectName->setCaptionWithReplacing("#{" + ESM::MagicEffect::indexToGmstString(effect->mIndex) + "}");
mEffect.mEffectID = effect->mIndex; mEffect.mEffectID = static_cast<int16_t>(effect->mIndex);
mMagicEffect = effect; mMagicEffect = effect;
@ -333,13 +333,13 @@ namespace MWGui
void EditEffectDialog::setSkill(ESM::RefId skill) void EditEffectDialog::setSkill(ESM::RefId skill)
{ {
mEffect.mSkill = ESM::Skill::refIdToIndex(skill); mEffect.mSkill = static_cast<signed char>(ESM::Skill::refIdToIndex(skill));
eventEffectModified(mEffect); eventEffectModified(mEffect);
} }
void EditEffectDialog::setAttribute(ESM::RefId attribute) void EditEffectDialog::setAttribute(ESM::RefId attribute)
{ {
mEffect.mAttribute = ESM::Attribute::refIdToIndex(attribute); mEffect.mAttribute = static_cast<signed char>(ESM::Attribute::refIdToIndex(attribute));
eventEffectModified(mEffect); eventEffectModified(mEffect);
} }
@ -772,7 +772,7 @@ namespace MWGui
mAddEffectDialog.setVisible(false); mAddEffectDialog.setVisible(false);
} }
EffectEditorBase::~EffectEditorBase() {} EffectEditorBase::~EffectEditorBase() = default;
void EffectEditorBase::startEditing() void EffectEditorBase::startEditing()
{ {
@ -1044,12 +1044,12 @@ namespace MWGui
if (arg.button == SDL_CONTROLLER_BUTTON_A) if (arg.button == SDL_CONTROLLER_BUTTON_A)
{ {
if (!mRightColumn && mAvailableFocus >= 0 && mAvailableFocus < static_cast<int>(mAvailableButtons.size())) if (!mRightColumn && mAvailableFocus < mAvailableButtons.size())
{ {
onAvailableEffectClicked(mAvailableButtons[mAvailableFocus]); onAvailableEffectClicked(mAvailableButtons[mAvailableFocus]);
winMgr->playSound(ESM::RefId::stringRefId("Menu Click")); winMgr->playSound(ESM::RefId::stringRefId("Menu Click"));
} }
else if (mRightColumn && mEffectFocus >= 0 && mEffectFocus < static_cast<int>(mEffectButtons.size())) else if (mRightColumn && mEffectFocus < mEffectButtons.size())
{ {
onEditEffect(mEffectButtons[mEffectFocus].second); onEditEffect(mEffectButtons[mEffectFocus].second);
winMgr->playSound(ESM::RefId::stringRefId("Menu Click")); winMgr->playSound(ESM::RefId::stringRefId("Menu Click"));
@ -1062,44 +1062,44 @@ namespace MWGui
} }
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP) else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_UP)
{ {
if (mRightColumn && mEffectButtons.size() > 0) if (mRightColumn && !mEffectButtons.empty())
{ {
if (mEffectFocus >= 0 && mEffectFocus < static_cast<int>(mEffectButtons.size())) if (mEffectFocus < mEffectButtons.size())
mEffectButtons[mEffectFocus].first->setStateSelected(false); mEffectButtons[mEffectFocus].first->setStateSelected(false);
mEffectFocus = wrap(mEffectFocus - 1, mEffectButtons.size()); mEffectFocus = wrap(mEffectFocus, mEffectButtons.size(), -1);
mEffectButtons[mEffectFocus].first->setStateSelected(true); mEffectButtons[mEffectFocus].first->setStateSelected(true);
} }
else if (!mRightColumn && mAvailableButtons.size() > 0) else if (!mRightColumn && !mAvailableButtons.empty())
{ {
if (mAvailableFocus >= 0 && mAvailableFocus < static_cast<int>(mAvailableButtons.size())) if (mAvailableFocus < mAvailableButtons.size())
mAvailableButtons[mAvailableFocus]->setStateSelected(false); mAvailableButtons[mAvailableFocus]->setStateSelected(false);
mAvailableFocus = wrap(mAvailableFocus - 1, mAvailableButtons.size()); mAvailableFocus = wrap(mAvailableFocus, mAvailableButtons.size(), -1);
mAvailableButtons[mAvailableFocus]->setStateSelected(true); mAvailableButtons[mAvailableFocus]->setStateSelected(true);
} }
} }
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
{ {
if (mRightColumn && mEffectButtons.size() > 0) if (mRightColumn && !mEffectButtons.empty())
{ {
if (mEffectFocus >= 0 && mEffectFocus < static_cast<int>(mEffectButtons.size())) if (mEffectFocus < mEffectButtons.size())
mEffectButtons[mEffectFocus].first->setStateSelected(false); mEffectButtons[mEffectFocus].first->setStateSelected(false);
mEffectFocus = wrap(mEffectFocus + 1, mEffectButtons.size()); mEffectFocus = wrap(mEffectFocus, mEffectButtons.size(), 1);
mEffectButtons[mEffectFocus].first->setStateSelected(true); mEffectButtons[mEffectFocus].first->setStateSelected(true);
} }
else if (!mRightColumn && mAvailableButtons.size() > 0) else if (!mRightColumn && !mAvailableButtons.empty())
{ {
if (mAvailableFocus >= 0 && mAvailableFocus < static_cast<int>(mAvailableButtons.size())) if (mAvailableFocus < mAvailableButtons.size())
mAvailableButtons[mAvailableFocus]->setStateSelected(false); mAvailableButtons[mAvailableFocus]->setStateSelected(false);
mAvailableFocus = wrap(mAvailableFocus + 1, mAvailableButtons.size()); mAvailableFocus = wrap(mAvailableFocus, mAvailableButtons.size(), 1);
mAvailableButtons[mAvailableFocus]->setStateSelected(true); mAvailableButtons[mAvailableFocus]->setStateSelected(true);
} }
} }
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT && mRightColumn) else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT && mRightColumn)
{ {
mRightColumn = false; mRightColumn = false;
if (mEffectFocus >= 0 && mEffectFocus < static_cast<int>(mEffectButtons.size())) if (mEffectFocus < mEffectButtons.size())
mEffectButtons[mEffectFocus].first->setStateSelected(false); mEffectButtons[mEffectFocus].first->setStateSelected(false);
if (mAvailableFocus >= 0 && mAvailableFocus < static_cast<int>(mAvailableButtons.size())) if (mAvailableFocus < mAvailableButtons.size())
mAvailableButtons[mAvailableFocus]->setStateSelected(true); mAvailableButtons[mAvailableFocus]->setStateSelected(true);
winMgr->setControllerTooltipVisible(Settings::gui().mControllerTooltips); winMgr->setControllerTooltipVisible(Settings::gui().mControllerTooltips);
@ -1107,9 +1107,9 @@ namespace MWGui
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT && !mRightColumn && mEffectButtons.size() > 0) else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT && !mRightColumn && mEffectButtons.size() > 0)
{ {
mRightColumn = true; mRightColumn = true;
if (mAvailableFocus >= 0 && mAvailableFocus < static_cast<int>(mAvailableButtons.size())) if (mAvailableFocus < mAvailableButtons.size())
mAvailableButtons[mAvailableFocus]->setStateSelected(false); mAvailableButtons[mAvailableFocus]->setStateSelected(false);
if (mEffectFocus >= 0 && mEffectFocus < static_cast<int>(mEffectButtons.size())) if (mEffectFocus < mEffectButtons.size())
mEffectButtons[mEffectFocus].first->setStateSelected(true); mEffectButtons[mEffectFocus].first->setStateSelected(true);
winMgr->setControllerTooltipVisible(false); winMgr->setControllerTooltipVisible(false);
@ -1123,10 +1123,10 @@ namespace MWGui
else else
{ {
const int lineHeight = Settings::gui().mFontSize + 3; const int lineHeight = Settings::gui().mFontSize + 3;
mAvailableEffectsList->setViewOffset(-lineHeight * (mAvailableFocus - 5)); mAvailableEffectsList->setViewOffset(-lineHeight * static_cast<int>(mAvailableFocus - 5));
} }
if (!mRightColumn && mAvailableFocus >= 0 && mAvailableFocus < static_cast<int>(mAvailableButtons.size())) if (!mRightColumn && mAvailableFocus < mAvailableButtons.size())
{ {
// Warp the mouse to the selected spell to show the tooltip // Warp the mouse to the selected spell to show the tooltip
if (winMgr->getControllerTooltipVisible()) if (winMgr->getControllerTooltipVisible())

View file

@ -153,9 +153,9 @@ namespace MWGui
private: private:
Type mType; Type mType;
int mAvailableFocus; size_t mAvailableFocus = 0;
int mEffectFocus; size_t mEffectFocus = 0;
bool mRightColumn; bool mRightColumn = false;
std::vector<MyGUI::Button*> mAvailableButtons; std::vector<MyGUI::Button*> mAvailableButtons;
std::vector<std::pair<Widgets::MWSpellEffectPtr, MyGUI::Button*>> mEffectButtons; std::vector<std::pair<Widgets::MWSpellEffectPtr, MyGUI::Button*>> mEffectButtons;
}; };

View file

@ -19,8 +19,6 @@
namespace MWGui namespace MWGui
{ {
const char* SpellView::sSpellModelIndex = "SpellModelIndex";
SpellView::LineInfo::LineInfo( SpellView::LineInfo::LineInfo(
MyGUI::Widget* leftWidget, MyGUI::Widget* rightWidget, SpellModel::ModelIndex spellIndex) MyGUI::Widget* leftWidget, MyGUI::Widget* rightWidget, SpellModel::ModelIndex spellIndex)
: mLeftWidget(leftWidget) : mLeftWidget(leftWidget)
@ -29,15 +27,6 @@ namespace MWGui
{ {
} }
SpellView::SpellView()
: mScrollView(nullptr)
, mShowCostColumn(true)
, mHighlightSelected(true)
, mControllerActiveWindow(false)
, mControllerFocus(0)
{
}
void SpellView::initialiseOverride() void SpellView::initialiseOverride()
{ {
Base::initialiseOverride(); Base::initialiseOverride();
@ -126,7 +115,7 @@ namespace MWGui
t->setCaption(spell.mName + captionSuffix); t->setCaption(spell.mName + captionSuffix);
t->setTextAlign(MyGUI::Align::Left); t->setTextAlign(MyGUI::Align::Left);
adjustSpellWidget(spell, i, t); adjustSpellWidget(spell, i, t);
mButtons.emplace_back(std::make_pair(t, i)); mButtons.emplace_back(t, i);
if (!spell.mCostColumn.empty() && mShowCostColumn) if (!spell.mCostColumn.empty() && mShowCostColumn)
{ {
@ -235,8 +224,8 @@ namespace MWGui
if (Settings::gui().mControllerMenus) if (Settings::gui().mControllerMenus)
{ {
mControllerFocus = wrap(mControllerFocus, mButtons.size()); mControllerFocus = std::min(mControllerFocus, mButtons.size());
updateControllerFocus(-1, mControllerFocus); updateControllerFocus(mButtons.size(), mControllerFocus);
} }
// Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the // 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("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->eventMouseWheel += MyGUI::newDelegate(this, &SpellView::onMouseWheelMoved);
widget->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellView::onSpellSelected); widget->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellView::onSpellSelected);
@ -315,7 +304,7 @@ namespace MWGui
SpellModel::ModelIndex SpellView::getSpellModelIndex(MyGUI::Widget* widget) 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) void SpellView::onSpellSelected(MyGUI::Widget* sender)
@ -349,14 +338,14 @@ namespace MWGui
if (mButtons.empty()) if (mButtons.empty())
return; return;
int prevFocus = mControllerFocus; size_t prevFocus = mControllerFocus;
MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager(); MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager();
int delta = 0;
switch (button) switch (button)
{ {
case SDL_CONTROLLER_BUTTON_A: case SDL_CONTROLLER_BUTTON_A:
// Select the focused item, if any. // Select the focused item, if any.
if (mControllerFocus >= 0 && mControllerFocus < static_cast<int>(mButtons.size())) if (mControllerFocus < mButtons.size())
{ {
onSpellSelected(mButtons[mControllerFocus].first); onSpellSelected(mButtons[mControllerFocus].first);
MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click")); MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click"));
@ -368,25 +357,25 @@ namespace MWGui
break; break;
case SDL_CONTROLLER_BUTTON_DPAD_UP: case SDL_CONTROLLER_BUTTON_DPAD_UP:
winMgr->restoreControllerTooltips(); winMgr->restoreControllerTooltips();
mControllerFocus--; delta = -1;
break; break;
case SDL_CONTROLLER_BUTTON_DPAD_DOWN: case SDL_CONTROLLER_BUTTON_DPAD_DOWN:
winMgr->restoreControllerTooltips(); winMgr->restoreControllerTooltips();
mControllerFocus++; delta = 1;
break; break;
case SDL_CONTROLLER_BUTTON_DPAD_LEFT: case SDL_CONTROLLER_BUTTON_DPAD_LEFT:
winMgr->restoreControllerTooltips(); winMgr->restoreControllerTooltips();
mControllerFocus = std::max(0, mControllerFocus - 10); delta = -10;
break; break;
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: case SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
winMgr->restoreControllerTooltips(); winMgr->restoreControllerTooltips();
mControllerFocus = std::min(mControllerFocus + 10, static_cast<int>(mButtons.size()) - 1); delta = 10;
break; break;
case SDL_CONTROLLER_BUTTON_LEFTSHOULDER: case SDL_CONTROLLER_BUTTON_LEFTSHOULDER:
{ {
// Jump to first item in previous group // Jump to first item in previous group
int prevGroupIndex = 0; size_t prevGroupIndex = 0;
for (int groupIndex : mGroupIndices) for (size_t groupIndex : mGroupIndices)
{ {
if (groupIndex >= mControllerFocus) if (groupIndex >= mControllerFocus)
break; break;
@ -399,8 +388,8 @@ namespace MWGui
case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER:
{ {
// Jump to first item in next group // Jump to first item in next group
int newFocus = mControllerFocus; size_t newFocus = mControllerFocus;
for (int groupIndex : mGroupIndices) for (size_t groupIndex : mGroupIndices)
{ {
if (groupIndex > mControllerFocus) if (groupIndex > mControllerFocus)
{ {
@ -418,27 +407,27 @@ namespace MWGui
return; return;
} }
mControllerFocus = wrap(mControllerFocus, mButtons.size()); mControllerFocus = wrap(mControllerFocus, mButtons.size(), delta);
if (prevFocus != mControllerFocus) if (prevFocus != mControllerFocus)
updateControllerFocus(prevFocus, mControllerFocus); updateControllerFocus(prevFocus, mControllerFocus);
else 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()) if (mButtons.empty())
return; return;
if (prevFocus >= 0 && prevFocus < static_cast<int>(mButtons.size())) if (prevFocus < mButtons.size())
{ {
Gui::SharedStateButton* prev = mButtons[prevFocus].first; Gui::SharedStateButton* prev = mButtons[prevFocus].first;
if (prev) if (prev)
prev->onMouseLostFocus(nullptr); prev->onMouseLostFocus(nullptr);
} }
if (mControllerActiveWindow && newFocus >= 0 && newFocus < static_cast<int>(mButtons.size())) if (mControllerActiveWindow && newFocus < mButtons.size())
{ {
Gui::SharedStateButton* focused = mButtons[newFocus].first; Gui::SharedStateButton* focused = mButtons[newFocus].first;
if (focused) if (focused)

View file

@ -28,7 +28,7 @@ namespace MWGui
{ {
MYGUI_RTTI_DERIVED(SpellView) MYGUI_RTTI_DERIVED(SpellView)
public: public:
SpellView(); SpellView() {};
/// Register needed components with MyGUI's factory manager /// Register needed components with MyGUI's factory manager
static void registerComponents(); static void registerComponents();
@ -63,8 +63,6 @@ namespace MWGui
void onControllerButton(const unsigned char button); void onControllerButton(const unsigned char button);
private: private:
MyGUI::ScrollView* mScrollView;
std::unique_ptr<SpellModel> mModel; std::unique_ptr<SpellModel> mModel;
/// tracks a row in the spell view /// tracks a row in the spell view
@ -90,28 +88,27 @@ namespace MWGui
std::vector<LineInfo> mLines; std::vector<LineInfo> mLines;
bool mShowCostColumn; /// Keep a list of buttons for controller navigation and their index in the full list.
bool mHighlightSelected; std::vector<std::pair<Gui::SharedStateButton*, int>> mButtons;
/// Keep a list of group offsets for controller navigation
std::vector<size_t> mGroupIndices;
MyGUI::ScrollView* mScrollView = nullptr;
size_t mControllerFocus = 0;
bool mShowCostColumn = true;
bool mHighlightSelected = true;
bool mControllerActiveWindow = false;
void layoutWidgets(); void layoutWidgets();
void addGroup(const std::string& label1, const std::string& label2); void addGroup(const std::string& label1, const std::string& label2);
void adjustSpellWidget(const Spell& spell, SpellModel::ModelIndex index, MyGUI::Widget* widget); 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. void updateControllerFocus(size_t prevFocus, size_t newFocus);
std::vector<std::pair<Gui::SharedStateButton*, int>> mButtons;
/// Keep a list of group offsets for controller navigation
std::vector<int> mGroupIndices;
bool mControllerActiveWindow;
int mControllerFocus;
void updateControllerFocus(int prevFocus, int newFocus);
void onSpellSelected(MyGUI::Widget* sender); void onSpellSelected(MyGUI::Widget* sender);
void onMouseWheelMoved(MyGUI::Widget* sender, int rel); void onMouseWheelMoved(MyGUI::Widget* sender, int rel);
SpellModel::ModelIndex getSpellModelIndex(MyGUI::Widget* sender); SpellModel::ModelIndex getSpellModelIndex(MyGUI::Widget* sender);
static const char* sSpellModelIndex;
}; };
} }

View file

@ -255,7 +255,7 @@ namespace MWGui
return; return;
mSpellView->setModel(new SpellModel(MWMechanics::getPlayer())); mSpellView->setModel(new SpellModel(MWMechanics::getPlayer()));
int itemCount = mSpellView->getModel()->getItemCount(); int itemCount = static_cast<int>(mSpellView->getModel()->getItemCount());
if (itemCount == 0) if (itemCount == 0)
return; return;

View file

@ -258,8 +258,8 @@ namespace MWGui
MyGUI::TextBox* nameWidget = widgets.first; MyGUI::TextBox* nameWidget = widgets.first;
if (valueWidget && nameWidget) if (valueWidget && nameWidget)
{ {
int modified = value.getModified(), base = value.getBase(); float modified = value.getModified(), base = value.getBase();
std::string text = MyGUI::utility::toString(modified); std::string text = MyGUI::utility::toString(static_cast<int>(modified));
std::string state = "normal"; std::string state = "normal";
if (modified > base) if (modified > base)
state = "increased"; state = "increased";
@ -341,8 +341,8 @@ namespace MWGui
bool first = true; bool first = true;
for (const auto& attribute : store->get<ESM::Attribute>()) for (const auto& attribute : store->get<ESM::Attribute>())
{ {
float mult = playerStats.getLevelupAttributeMultiplier(attribute.mId); int mult = playerStats.getLevelupAttributeMultiplier(attribute.mId);
mult = std::min(mult, 100 - playerStats.getAttribute(attribute.mId).getBase()); mult = std::min(mult, static_cast<int>(100 - playerStats.getAttribute(attribute.mId).getBase()));
if (mult > 1) if (mult > 1)
{ {
if (!first) if (!first)

View file

@ -298,7 +298,7 @@ namespace MWGui
const ItemStack& item = mSortModel->getItem(index); const ItemStack& item = mSortModel->getItem(index);
MWWorld::Ptr object = item.mBase; MWWorld::Ptr object = item.mBase;
int count = item.mCount; size_t count = item.mCount;
bool shift = MyGUI::InputManager::getInstance().isShiftPressed(); bool shift = MyGUI::InputManager::getInstance().isShiftPressed();
if (MyGUI::InputManager::getInstance().isControlPressed()) if (MyGUI::InputManager::getInstance().isControlPressed())
count = 1; count = 1;
@ -309,7 +309,7 @@ namespace MWGui
std::string message = "#{sQuanityMenuMessage02}"; std::string message = "#{sQuanityMenuMessage02}";
std::string name{ object.getClass().getName(object) }; std::string name{ object.getClass().getName(object) };
name += MWGui::ToolTips::getSoulString(object.getCellRef()); name += MWGui::ToolTips::getSoulString(object.getCellRef());
dialog->openCountDialog(name, message, count); dialog->openCountDialog(name, message, static_cast<int>(count));
dialog->eventOkClicked.clear(); dialog->eventOkClicked.clear();
dialog->eventOkClicked += MyGUI::newDelegate(this, &TradeWindow::sellItem); dialog->eventOkClicked += MyGUI::newDelegate(this, &TradeWindow::sellItem);
mItemToSell = mSortModel->mapToSource(index); mItemToSell = mSortModel->mapToSource(index);
@ -335,14 +335,14 @@ namespace MWGui
// this was an item borrowed to us by the player // this was an item borrowed to us by the player
mTradeModel->returnItemBorrowedToUs(mItemToSell, count); mTradeModel->returnItemBorrowedToUs(mItemToSell, count);
playerTradeModel->returnItemBorrowedFromUs(mItemToSell, mTradeModel, count); playerTradeModel->returnItemBorrowedFromUs(mItemToSell, mTradeModel, count);
buyFromNpc(item.mBase, count, true); updateOffer();
} }
else else
{ {
// borrow item to player // borrow item to player
playerTradeModel->borrowItemToUs(mItemToSell, mTradeModel, count); playerTradeModel->borrowItemToUs(mItemToSell, mTradeModel, count);
mTradeModel->borrowItemFromUs(mItemToSell, count); mTradeModel->borrowItemFromUs(mItemToSell, count);
buyFromNpc(item.mBase, count, false); updateOffer();
} }
MWBase::Environment::get().getWindowManager()->getInventoryWindow()->updateItemView(); MWBase::Environment::get().getWindowManager()->getInventoryWindow()->updateItemView();
@ -355,17 +355,16 @@ namespace MWGui
= MWBase::Environment::get().getWindowManager()->getInventoryWindow()->getTradeModel(); = MWBase::Environment::get().getWindowManager()->getInventoryWindow()->getTradeModel();
mTradeModel->borrowItemToUs(index, playerTradeModel, count); mTradeModel->borrowItemToUs(index, playerTradeModel, count);
mItemView->update(); mItemView->update();
sellToNpc(playerTradeModel->getItem(index).mBase, count, false); updateOffer();
} }
void TradeWindow::returnItem(int index, size_t count) void TradeWindow::returnItem(int index, size_t count)
{ {
TradeItemModel* playerTradeModel TradeItemModel* playerTradeModel
= MWBase::Environment::get().getWindowManager()->getInventoryWindow()->getTradeModel(); = MWBase::Environment::get().getWindowManager()->getInventoryWindow()->getTradeModel();
const ItemStack& item = playerTradeModel->getItem(index);
mTradeModel->returnItemBorrowedFromUs(index, playerTradeModel, count); mTradeModel->returnItemBorrowedFromUs(index, playerTradeModel, count);
mItemView->update(); mItemView->update();
sellToNpc(item.mBase, count, true); updateOffer();
} }
void TradeWindow::addOrRemoveGold(int amount, const MWWorld::Ptr& actor) void TradeWindow::addOrRemoveGold(int amount, const MWWorld::Ptr& actor)
@ -648,16 +647,6 @@ namespace MWGui
updateLabels(); 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() void TradeWindow::onReferenceUnavailable()
{ {
// remove both Trade and Dialogue (since you always trade with the NPC/creature that you have previously talked // remove both Trade and Dialogue (since you always trade with the NPC/creature that you have previously talked

View file

@ -90,11 +90,6 @@ namespace MWGui
bool mUpdateNextFrame; 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 updateOffer();
void onItemSelected(int index); void onItemSelected(int index);

View file

@ -123,7 +123,7 @@ namespace MWGui
MyGUI::Button* button = mTrainingOptions->createWidget<MyGUI::Button>(price <= playerGold MyGUI::Button* button = mTrainingOptions->createWidget<MyGUI::Button>(price <= playerGold
? "SandTextButton" ? "SandTextButton"
: "SandTextButtonDisabled", // can't use setEnabled since that removes tooltip : "SandTextButtonDisabled", // can't use setEnabled since that removes tooltip
MyGUI::IntCoord(4, 3 + i * lineHeight, mTrainingOptions->getWidth() - 10, lineHeight), MyGUI::IntCoord(4, static_cast<int>(3 + i * lineHeight), mTrainingOptions->getWidth() - 10, lineHeight),
MyGUI::Align::Default); MyGUI::Align::Default);
button->setUserData(skills[i].first); button->setUserData(skills[i].first);
@ -169,8 +169,8 @@ namespace MWGui
const MWWorld::ESMStore& store = *MWBase::Environment::get().getESMStore(); const MWWorld::ESMStore& store = *MWBase::Environment::get().getESMStore();
int price = pcStats.getSkill(skill->mId).getBase() int price = static_cast<int>(pcStats.getSkill(skill->mId).getBase()
* store.get<ESM::GameSetting>().find("iTrainingMod")->mValue.getInteger(); * store.get<ESM::GameSetting>().find("iTrainingMod")->mValue.getInteger());
price = MWBase::Environment::get().getMechanicsManager()->getBarterOffer(mPtr, price, true); price = MWBase::Environment::get().getMechanicsManager()->getBarterOffer(mPtr, price, true);
if (price > player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId)) if (price > player.getClass().getContainerStore(player).count(MWWorld::ContainerStore::sGoldId))
@ -263,7 +263,7 @@ namespace MWGui
return true; return true;
setControllerFocus(mTrainingButtons, mControllerFocus, false); setControllerFocus(mTrainingButtons, mControllerFocus, false);
mControllerFocus = wrap(mControllerFocus - 1, mTrainingButtons.size()); mControllerFocus = wrap(mControllerFocus, mTrainingButtons.size(), -1);
setControllerFocus(mTrainingButtons, mControllerFocus, true); setControllerFocus(mTrainingButtons, mControllerFocus, true);
} }
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
@ -272,7 +272,7 @@ namespace MWGui
return true; return true;
setControllerFocus(mTrainingButtons, mControllerFocus, false); setControllerFocus(mTrainingButtons, mControllerFocus, false);
mControllerFocus = wrap(mControllerFocus + 1, mTrainingButtons.size()); mControllerFocus = wrap(mControllerFocus, mTrainingButtons.size(), 1);
setControllerFocus(mTrainingButtons, mControllerFocus, true); setControllerFocus(mTrainingButtons, mControllerFocus, true);
} }

View file

@ -63,8 +63,8 @@ namespace MWGui
else else
{ {
const ESM::Position playerPos = player.getRefData().getPosition(); 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) double d = std::sqrt(std::pow(pos.pos[0] - playerPos.pos[0], 2) + std::pow(pos.pos[1] - playerPos.pos[1], 2)
+ pow(pos.pos[2] - playerPos.pos[2], 2)); + std::pow(pos.pos[2] - playerPos.pos[2], 2));
float fTravelMult = gmst.find("fTravelMult")->mValue.getFloat(); float fTravelMult = gmst.find("fTravelMult")->mValue.getFloat();
if (fTravelMult != 0) if (fTravelMult != 0)
price = static_cast<int>(d / fTravelMult); price = static_cast<int>(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(); = (osg::Vec3f(pos.pos[0], pos.pos[1], 0) - osg::Vec3f(playerPos.pos[0], playerPos.pos[1], 0)).length();
int hours = static_cast<int>(d int hours = static_cast<int>(d
/ MWBase::Environment::get() / MWBase::Environment::get()
.getESMStore() .getESMStore()
->get<ESM::GameSetting>() ->get<ESM::GameSetting>()
.find("fTravelTimeMult") .find("fTravelTimeMult")
->mValue.getFloat()); ->mValue.getFloat());
MWBase::Environment::get().getMechanicsManager()->rest(hours, true); MWBase::Environment::get().getMechanicsManager()->rest(hours, true);
MWBase::Environment::get().getWorld()->advanceTime(hours); MWBase::Environment::get().getWorld()->advanceTime(hours);
} }
@ -279,7 +279,7 @@ namespace MWGui
return true; return true;
setControllerFocus(mDestinationButtons, mControllerFocus, false); setControllerFocus(mDestinationButtons, mControllerFocus, false);
mControllerFocus = wrap(mControllerFocus - 1, mDestinationButtons.size()); mControllerFocus = wrap(mControllerFocus, mDestinationButtons.size(), -1);
setControllerFocus(mDestinationButtons, mControllerFocus, true); setControllerFocus(mDestinationButtons, mControllerFocus, true);
} }
else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) else if (arg.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
@ -288,7 +288,7 @@ namespace MWGui
return true; return true;
setControllerFocus(mDestinationButtons, mControllerFocus, false); setControllerFocus(mDestinationButtons, mControllerFocus, false);
mControllerFocus = wrap(mControllerFocus + 1, mDestinationButtons.size()); mControllerFocus = wrap(mControllerFocus, mDestinationButtons.size(), 1);
setControllerFocus(mDestinationButtons, mControllerFocus, true); setControllerFocus(mDestinationButtons, mControllerFocus, true);
} }
@ -298,7 +298,7 @@ namespace MWGui
else else
{ {
const int lineHeight = Settings::gui().mFontSize + 2; const int lineHeight = Settings::gui().mFontSize + 2;
mDestinationsView->setViewOffset(MyGUI::IntPoint(0, -lineHeight * (mControllerFocus - 5))); mDestinationsView->setViewOffset(MyGUI::IntPoint(0, -lineHeight * static_cast<int>(mControllerFocus - 5)));
} }
return true; return true;

View file

@ -239,7 +239,7 @@ namespace MWGui
void WaitDialog::onHourSliderChangedPosition(MyGUI::ScrollBar* sender, size_t position) void WaitDialog::onHourSliderChangedPosition(MyGUI::ScrollBar* sender, size_t position)
{ {
mHourText->setCaptionWithReplacing(MyGUI::utility::toString(position + 1) + " #{sRestMenu2}"); mHourText->setCaptionWithReplacing(MyGUI::utility::toString(position + 1) + " #{sRestMenu2}");
mManualHours = position + 1; mManualHours = static_cast<int>(position + 1);
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mWaitButton); MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mWaitButton);
} }

View file

@ -15,19 +15,28 @@
using namespace MWGui; 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) if (delta >= 0)
return max - 1; {
else if (index >= max) unsigned absDelta = static_cast<unsigned>(delta);
if (absDelta >= max)
return 0;
else if (index >= max - absDelta)
return 0;
return index + absDelta;
}
unsigned absDelta = static_cast<unsigned>(-delta);
if (index >= absDelta)
return index - absDelta;
else if (max == 0)
return 0; return 0;
else return max - 1;
return index;
} }
void MWGui::setControllerFocus(const std::vector<MyGUI::Button*>& buttons, int index, bool focused) void MWGui::setControllerFocus(const std::vector<MyGUI::Button*>& buttons, size_t index, bool focused)
{ {
if (index >= 0 && index < static_cast<int>(buttons.size())) if (index < buttons.size())
buttons[index]->setStateSelected(focused); buttons[index]->setStateSelected(focused);
} }
@ -199,16 +208,14 @@ float BookWindowBase::adjustButton(std::string_view name)
WindowBase::getWidget(button, name); WindowBase::getWidget(button, name);
MyGUI::IntSize requested = button->getRequestedSize(); MyGUI::IntSize requested = button->getRequestedSize();
float scale = float(requested.height) / button->getSize().height; float scale = float(requested.height) / button->getSize().height;
MyGUI::IntSize newSize = requested; MyGUI::IntSize newSize(static_cast<int>(requested.width / scale), static_cast<int>(requested.height / scale));
newSize.width /= scale;
newSize.height /= scale;
button->setSize(newSize); button->setSize(newSize);
if (button->getAlign().isRight()) if (button->getAlign().isRight())
{ {
MyGUI::IntSize diff = (button->getSize() - requested); MyGUI::IntSize diff = (button->getSize() - requested);
diff.width /= scale; diff.width = static_cast<int>(diff.width / scale);
diff.height /= scale; diff.height = static_cast<int>(diff.height / scale);
button->setPosition(button->getPosition() + MyGUI::IntPoint(diff.width, 0)); button->setPosition(button->getPosition() + MyGUI::IntPoint(diff.width, 0));
} }

View file

@ -14,8 +14,8 @@ namespace MWGui
{ {
class DragAndDrop; class DragAndDrop;
int wrap(int index, int max); size_t wrap(size_t index, size_t max, int delta);
void setControllerFocus(const std::vector<MyGUI::Button*>& buttons, int index, bool selected); void setControllerFocus(const std::vector<MyGUI::Button*>& buttons, size_t index, bool selected);
struct ControllerButtons struct ControllerButtons
{ {

View file

@ -903,11 +903,11 @@ namespace MWGui
{ {
GuiMode mode = mGuiModes.back(); GuiMode mode = mGuiModes.back();
GuiModeState& state = mGuiModeStates[mode]; GuiModeState& state = mGuiModeStates[mode];
if (state.mWindows.size() == 0) if (state.mWindows.empty())
return nullptr; return nullptr;
int activeIndex size_t activeIndex
= std::clamp(mActiveControllerWindows[mode], 0, static_cast<int>(state.mWindows.size()) - 1); = std::clamp<size_t>(mActiveControllerWindows[mode], 0, state.mWindows.size() - 1);
// If the active window is no longer visible, find the next visible window. // If the active window is no longer visible, find the next visible window.
if (!state.mWindows[activeIndex]->isVisible()) if (!state.mWindows[activeIndex]->isVisible())
@ -925,18 +925,18 @@ namespace MWGui
return; return;
GuiMode mode = mGuiModes.back(); 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) if (winCount > 1)
{ {
// Find next/previous visible window // Find next/previous visible window
activeIndex = mActiveControllerWindows[mode]; activeIndex = mActiveControllerWindows[mode];
int delta = next ? 1 : -1; 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()) if (mGuiModeStates[mode].mWindows[activeIndex]->isVisible())
break; break;
} }
@ -952,9 +952,9 @@ namespace MWGui
return; return;
const GuiMode mode = mGuiModes.back(); 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. // Set active window last so inactive windows don't stomp on changes it makes, e.g. to tooltips.
if (i != mActiveControllerWindows[mode]) if (i != mActiveControllerWindows[mode])
@ -964,16 +964,16 @@ namespace MWGui
mGuiModeStates[mode].mWindows[mActiveControllerWindows[mode]]->setActiveControllerWindow(true); 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) if (!Settings::gui().mControllerMenus)
return; return;
int winCount = mGuiModeStates[mode].mWindows.size(); size_t winCount = mGuiModeStates[mode].mWindows.size();
if (winCount == 0) if (winCount == 0)
return; return;
activeIndex = std::clamp(activeIndex, 0, winCount - 1); activeIndex = std::clamp<size_t>(activeIndex, 0, winCount - 1);
mActiveControllerWindows[mode] = activeIndex; mActiveControllerWindows[mode] = activeIndex;
reapplyActiveControllerWindow(); reapplyActiveControllerWindow();
@ -1437,7 +1437,8 @@ namespace MWGui
if (mode == GM_Container) if (mode == GM_Container)
mActiveControllerWindows[mode] = 0; // Ensure controller focus is on container mActiveControllerWindows[mode] = 0; // Ensure controller focus is on container
// Activate first visible window. This needs to be called after updateVisible. // 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); cycleActiveControllerWindow(true);
} }
} }

View file

@ -394,7 +394,7 @@ namespace MWGui
WindowBase* getActiveControllerWindow() override; WindowBase* getActiveControllerWindow() override;
int getControllerMenuHeight() override; int getControllerMenuHeight() override;
void cycleActiveControllerWindow(bool next) 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; } bool getControllerTooltipVisible() const override { return mControllerTooltipVisible; }
void setControllerTooltipVisible(bool visible) override; void setControllerTooltipVisible(bool visible) override;
bool getControllerTooltipEnabled() const override { return mControllerTooltipEnabled; } 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). // The currently active stack of GUI modes (top mode is the one we are in).
std::vector<GuiMode> mGuiModes; std::vector<GuiMode> mGuiModes;
// The active window for controller mode for each GUI mode. // The active window for controller mode for each GUI mode.
std::map<GuiMode, int> mActiveControllerWindows; std::map<GuiMode, size_t> mActiveControllerWindows;
// Current tooltip visibility state (can be disabled by mouse movement) // Current tooltip visibility state (can be disabled by mouse movement)
bool mControllerTooltipVisible = false; bool mControllerTooltipVisible = false;
// User preference for tooltips (persists across mouse/controller switches) // User preference for tooltips (persists across mouse/controller switches)

View file

@ -604,7 +604,7 @@ std::string MWMechanics::Alchemy::suggestPotionName()
return effects.begin()->toString(); return effects.begin()->toString();
} }
std::vector<std::string> MWMechanics::Alchemy::effectsDescription(const MWWorld::ConstPtr& ptr, const int alchemySkill) std::vector<std::string> MWMechanics::Alchemy::effectsDescription(const MWWorld::ConstPtr& ptr, const float alchemySkill)
{ {
std::vector<std::string> effects; std::vector<std::string> effects;

View file

@ -135,7 +135,7 @@ namespace MWMechanics
/// adjust the skills of the alchemist accordingly. /// adjust the skills of the alchemist accordingly.
/// \param name must not be an empty string, or Result_NoName is returned /// \param name must not be an empty string, or Result_NoName is returned
static std::vector<std::string> effectsDescription(const MWWorld::ConstPtr& ptr, const int alchemySKill); static std::vector<std::string> effectsDescription(const MWWorld::ConstPtr& ptr, const float alchemySKill);
}; };
} }