Skip to content

An OpenMW mod that lets you play the whole Elder Scrolls III: Morrowind as a top-down isometric game — with full online co-op or MMO modes.

C++

Quick bar: the current key framed grey-white and the others dimmed; keys whose item is gone are emptied

pw-tf825a4a6be640
diff --git a/apps/openmw/mwgui/actionbar.cpp b/apps/openmw/mwgui/actionbar.cpp
index ea08d21..7075ca2 100644
--- a/apps/openmw/mwgui/actionbar.cpp
+++ b/apps/openmw/mwgui/actionbar.cpp
@@ -1,6 +1,9 @@
#include "actionbar.hpp"
+#include <algorithm>
+
#include <MyGUI_Button.h>
+#include <MyGUI_ImageBox.h>
#include <MyGUI_ProgressBar.h>
#include <MyGUI_RenderManager.h>
#include <MyGUI_TextBox.h>
@@ -35,6 +38,12 @@ namespace MWGui
constexpr int sBoxSize = 36;
constexpr int sSpacing = 4;
constexpr int sStatusHeight = 6;
+ // The key ready to use: its border's width and colour; while one is, how far the others dim (empty ones more)
+ constexpr int sBorderWidth = 2;
+ const MyGUI::Colour sBorderColour(0.88f, 0.88f, 0.85f);
+ constexpr float sDimmed = 0.55f;
+ constexpr float sEmptyDimmed = 0.35f;
+ constexpr float sEmpty = 0.5f;
// Frames are drawn on 64 pixel textures at 44 pixels; bigger texture packs scale that
int frameSize(const std::string& texture)
@@ -104,6 +113,22 @@ namespace MWGui
(*bar)->setVisible(false);
}
+ // The border, over the box's own edge
+ const int far = sBoxSize - sBorderWidth;
+ const std::array<MyGUI::IntCoord, 4> edges = { MyGUI::IntCoord(0, 0, sBoxSize, sBorderWidth),
+ MyGUI::IntCoord(0, far, sBoxSize, sBorderWidth), MyGUI::IntCoord(0, 0, sBorderWidth, sBoxSize),
+ MyGUI::IntCoord(far, 0, sBorderWidth, sBoxSize) };
+ for (size_t e = 0; e < edges.size(); ++e)
+ {
+ MyGUI::ImageBox* edge
+ = slot.mButton->createWidget<MyGUI::ImageBox>("ImageBox", edges[e], MyGUI::Align::Default);
+ edge->setImageTexture("white");
+ edge->setColour(sBorderColour);
+ edge->setNeedMouseFocus(false);
+ edge->setVisible(false);
+ slot.mBorder[e] = edge;
+ }
+
// How many there are, in the corner like the inventory shows it
slot.mCountText = slot.mButton->createWidget<MyGUI::TextBox>(
"CountText", MyGUI::IntCoord(2, sBoxSize - 18, sBoxSize - 5, 16), MyGUI::Align::Default);
@@ -133,6 +158,23 @@ namespace MWGui
return;
for (int i = 0; i < sSlots; ++i)
showSlot(i, mSlots[i]);
+
+ // The current key stands out (the one used last, stepping counts from it: QuickKeysMenu::getCurrentKey): a
+ // border, a brighter number, and the others dim (while there is none, none dims)
+ const int current = mQuickKeysMenu->getCurrentKey();
+ for (int i = 0; i < sSlots; ++i)
+ {
+ Slot& slot = mSlots[i];
+ const bool isCurrent = i == current;
+ for (MyGUI::ImageBox* edge : slot.mBorder)
+ edge->setVisible(isCurrent);
+ slot.mLabel->setTextColour(
+ isCurrent ? MyGUI::Colour(1.f, 0.94f, 0.75f) : MyGUI::Colour(0.79f, 0.65f, 0.38f));
+ float alpha = slot.mEmpty ? sEmpty : 1.f;
+ if (current >= 0 && !isCurrent)
+ alpha = slot.mEmpty ? sEmptyDimmed : sDimmed;
+ slot.mButton->setAlpha(alpha);
+ }
}
void ActionBar::showSlot(int index, Slot& slot)
@@ -198,8 +240,8 @@ namespace MWGui
case ESM::QuickKeys::Type::Item:
if (!key.item.isEmpty())
{
- // The gold frame of equipped items, as in the inventory
- slot.mIcon->setItem(key.item, active ? ItemWidget::Equip : ItemWidget::None);
+ // (No gold frame when equipped: the border shows the key ready to use)
+ slot.mIcon->setItem(key.item, ItemWidget::None);
slot.mButton->setUserString("ToolTipType", "ItemPtr");
slot.mButton->setUserData(MWWorld::Ptr(key.item));
}
@@ -207,8 +249,7 @@ namespace MWGui
case ESM::QuickKeys::Type::MagicItem:
if (!key.item.isEmpty())
{
- const std::string frame
- = active ? "textures\\menu_icon_equip.dds" : "textures\\menu_icon_select_magic_magic.dds";
+ const std::string frame = "textures\\menu_icon_select_magic_magic.dds";
const int size = frameSize(frame);
slot.mIcon->setFrame(frame, MyGUI::IntCoord(0, 0, size, size));
slot.mIcon->setIcon(key.item);
@@ -226,8 +267,7 @@ namespace MWGui
= esmStore.get<ESM::MagicEffect>().search(spell->mEffects.mList.front().mData.mEffectID);
if (!effect)
break;
- const std::string frame
- = active ? "textures\\menu_icon_equip.dds" : "textures\\menu_icon_select_magic.dds";
+ const std::string frame = "textures\\menu_icon_select_magic.dds";
const int size = frameSize(frame);
slot.mIcon->setFrame(frame, MyGUI::IntCoord(0, 0, size, size));
slot.mIcon->setIcon(Misc::ResourceHelpers::correctBigIconPath(VFS::Path::toNormalized(effect->mIcon),
@@ -238,9 +278,7 @@ namespace MWGui
}
case ESM::QuickKeys::Type::HandToHand:
{
- const std::string frame = active ? "textures\\menu_icon_equip.dds" : "";
- const int size = frame.empty() ? 0 : frameSize(frame);
- slot.mIcon->setFrame(frame, MyGUI::IntCoord(0, 0, size, size));
+ slot.mIcon->setFrame({}, MyGUI::IntCoord());
slot.mIcon->setIcon("icons\\k\\stealth_handtohand.dds");
break;
}
@@ -257,14 +295,11 @@ namespace MWGui
if (status >= 0)
bar->setProgressPosition(std::clamp(status, 0, 100));
- // The number of the key ready to use shows brighter
- slot.mLabel->setTextColour(active ? MyGUI::Colour(1.f, 0.94f, 0.75f) : MyGUI::Colour(0.79f, 0.65f, 0.38f));
- // Keys with nothing on them stay in the background
- const bool empty = key.type == ESM::QuickKeys::Type::Unassigned
+ // Keys with nothing on them stay in the background (update() sets how much)
+ slot.mEmpty = key.type == ESM::QuickKeys::Type::Unassigned
|| ((key.type == ESM::QuickKeys::Type::Item || key.type == ESM::QuickKeys::Type::MagicItem)
&& key.item.isEmpty());
- slot.mButton->setAlpha(empty ? 0.5f : 1.f);
}
int ActionBar::indexOf(MyGUI::Widget* sender) const
diff --git a/apps/openmw/mwgui/actionbar.hpp b/apps/openmw/mwgui/actionbar.hpp
index f5dbb92..039ffaa 100644
--- a/apps/openmw/mwgui/actionbar.hpp
+++ b/apps/openmw/mwgui/actionbar.hpp
@@ -14,6 +14,7 @@
namespace MyGUI
{
class Button;
+ class ImageBox;
class ProgressBar;
class TextBox;
class Widget;
@@ -26,8 +27,9 @@ namespace MWGui
class QuickKeysMenu;
/// Isowind: the quick keys (1 to 0) as a row of HUD boxes at the bottom of the screen, showing what each holds
- /// (the item or spell, whether it's equipped or selected, its condition or charge). In menus a slot can be
- /// clicked to use it, an item dragged from the inventory dropped on it to assign it, and right-clicked for
+ /// (the item or spell, its condition or charge). The current one (used last, by its key, the bumpers or a click;
+ /// else the one in use: QuickKeysMenu::getCurrentKey) has a grey-white border and the others dim. In menus a slot
+ /// can be clicked to use it, an item dragged from the inventory dropped on it to assign it, and right-clicked for
/// Morrowind's own assign dialog.
class ActionBar
{
@@ -53,6 +55,8 @@ namespace MWGui
MyGUI::ProgressBar* mCharge = nullptr;
MyGUI::TextBox* mLabel = nullptr;
MyGUI::TextBox* mCountText = nullptr;
+ // The grey-white border of the key ready to use
+ std::array<MyGUI::ImageBox*, 4> mBorder{};
// What it shows, to update only when that changes
ESM::QuickKeys::Type mType = ESM::QuickKeys::Type::Unassigned;
@@ -61,6 +65,7 @@ namespace MWGui
int mCount = -1;
int mStatusValue = -1;
bool mActive = false;
+ bool mEmpty = true;
bool mInitialised = false;
};
diff --git a/apps/openmw/mwgui/quickkeysmenu.cpp b/apps/openmw/mwgui/quickkeysmenu.cpp
index 0c93242..5c48411 100644
--- a/apps/openmw/mwgui/quickkeysmenu.cpp
+++ b/apps/openmw/mwgui/quickkeysmenu.cpp
@@ -104,10 +104,28 @@ namespace MWGui
item = store.findReplacement(mKey[index].id);
if (!item.isEmpty())
+ {
mKey[index].button->setUserData(MWWorld::Ptr(item));
+ mKey[index].missingSince.reset();
+ }
+ else
+ {
+ // Isowind: with none left in the inventory, the key no longer holds it (the action bar shows
+ // it empty; the bumpers skip it at once). After a moment: in multiplayer an item used goes to
+ // the server and back, and may be away from the inventory in between.
+ const auto now = std::chrono::steady_clock::now();
+ if (!mKey[index].missingSince)
+ mKey[index].missingSince = now;
+ else if (now - *mKey[index].missingSince > std::chrono::seconds(1))
+ {
+ mKey[index].missingSince.reset();
+ unassign(&mKey[index]);
+ }
+ }
break;
}
+ mKey[index].missingSince.reset();
}
}
}
@@ -489,27 +507,44 @@ namespace MWGui
case ESM::QuickKeys::Type::Magic:
return store.getSelectedEnchantItem() == store.end()
&& MWBase::Environment::get().getWindowManager()->getSelectedSpell() == key.id;
+ case ESM::QuickKeys::Type::HandToHand:
+ return store.getSlot(MWWorld::InventoryStore::Slot_CarriedRight) == store.end();
default:
return false;
}
}
- void QuickKeysMenu::stepQuickKey(int direction)
+ // Whether a key holds something to use (an item key's item still being carried)
+ bool QuickKeysMenu::holdsSomething(int index)
{
- // From the key in use (the weapon in hand, the spell or enchanted item ready), the one stepped to last
- // otherwise
- int current = mLastStepped;
- if (current < 0 || !isKeyInUse(current))
+ const keyData& key = mKey[index];
+ if (key.type == ESM::QuickKeys::Type::Unassigned)
+ return false;
+ if (key.type == ESM::QuickKeys::Type::Item || key.type == ESM::QuickKeys::Type::MagicItem)
{
- for (int i = 0; i < static_cast<int>(mKey.size()); ++i)
- {
- if (isKeyInUse(i))
- {
- current = i;
- break;
- }
- }
+ const MWWorld::Ptr* item = key.button->getUserData<MWWorld::Ptr>(false);
+ return item && !item->isEmpty() && item->getCellRef().getCount() >= 1;
+ }
+ return true;
+ }
+
+ int QuickKeysMenu::getCurrentKey()
+ {
+ if (mLastStepped >= 0 && mLastStepped < static_cast<int>(mKey.size()) && holdsSomething(mLastStepped))
+ return mLastStepped;
+ for (int i = 0; i < static_cast<int>(mKey.size()); ++i)
+ {
+ if (isKeyInUse(i))
+ return i;
}
+ return -1;
+ }
+
+ void QuickKeysMenu::stepQuickKey(int direction)
+ {
+ // From the current key: the one used last (not only while it is in use, or stepping from bare hands or a
+ // potion would start over from a spell still selected and skip keys), else the one in use
+ int current = getCurrentKey();
const int count = static_cast<int>(mKey.size());
if (current < 0)
current = direction > 0 ? -1 : count;
@@ -517,16 +552,8 @@ namespace MWGui
{
const int index = ((current + direction * step) % count + count) % count;
validate(index);
- const keyData& key = mKey[index];
- if (key.type == ESM::QuickKeys::Type::Unassigned)
+ if (!holdsSomething(index))
continue;
- if (key.type == ESM::QuickKeys::Type::Item || key.type == ESM::QuickKeys::Type::MagicItem)
- {
- const MWWorld::Ptr* item = key.button->getUserData<MWWorld::Ptr>(false);
- if (!item || item->isEmpty() || item->getCellRef().getCount() < 1)
- continue;
- }
- mLastStepped = index;
activateQuickKey(index + 1);
return;
}
@@ -537,6 +564,8 @@ namespace MWGui
assert(index >= 1 && index <= 10);
keyData* key = &mKey[index - 1];
+ // Isowind: the current key now, however it was used (see getCurrentKey)
+ mLastStepped = index - 1;
MWWorld::Ptr player = MWMechanics::getPlayer();
MWWorld::InventoryStore& store = player.getClass().getInventoryStore(player);
diff --git a/apps/openmw/mwgui/quickkeysmenu.hpp b/apps/openmw/mwgui/quickkeysmenu.hpp
index b48b16c..be6470c 100644
--- a/apps/openmw/mwgui/quickkeysmenu.hpp
+++ b/apps/openmw/mwgui/quickkeysmenu.hpp
@@ -1,7 +1,9 @@
#ifndef MWGUI_QUICKKEYS_H
#define MWGUI_QUICKKEYS_H
+#include <chrono>
#include <memory>
+#include <optional>
#include "components/esm3/quickkeys.hpp"
@@ -40,9 +42,14 @@ namespace MWGui
void onClose() override;
void activateQuickKey(int index);
- /// Isowind: uses the next (1) or previous (-1) key that holds something, counting from the one in use
+ /// Isowind: uses the next (1) or previous (-1) key that holds something, counting from the current one
void stepQuickKey(int direction);
+ /// Isowind: the current key (0-based), or -1: the one used last (stepped to, pressed or clicked) while it
+ /// still holds something, else the one in use (the weapon in hand or bare hands, the spell or enchanted item
+ /// ready). The action bar highlights it, and stepping counts from it.
+ int getCurrentKey();
+
/// Isowind's action bar: what a key (1-based) holds; item is the inventory item of an item key, if any.
struct QuickKeyInfo
{
@@ -82,6 +89,8 @@ namespace MWGui
ESM::QuickKeys::Type type = ESM::QuickKeys::Type::Unassigned;
ESM::RefId id;
std::string name;
+ // Isowind: since when the item has been gone from the inventory (none to replace it), if it is
+ std::optional<std::chrono::steady_clock::time_point> missingSince;
};
std::vector<keyData> mKey;
@@ -89,6 +98,7 @@ namespace MWGui
keyData* mSelected;
int mLastStepped = -1;
bool isKeyInUse(int index);
+ bool holdsSomething(int index);
keyData* mActivated;
MyGUI::EditBox* mInstructionLabel;