Pinnable windows: hide hud elements

Hide elements of the HUD (health/magicka/stamina bars,
minimap) when the corresponding windows (stats/map) are pinned.

Rearrange the remaining hud elements in such cases (like in the
original Morrowind).
actorid
Roman Melnik 13 years ago
parent 91a377df86
commit ef0a185e11

@ -31,6 +31,11 @@ HUD::HUD(int width, int height, int fpsLevel)
, fpscounter(NULL) , fpscounter(NULL)
, trianglecounter(NULL) , trianglecounter(NULL)
, batchcounter(NULL) , batchcounter(NULL)
, hmsBaseLeft(0)
, weapBoxBaseLeft(0)
, spellBoxBaseLeft(0)
, effectBoxBaseRight(0)
, minimapBoxBaseRight(0)
{ {
setCoord(0,0, width, height); setCoord(0,0, width, height);
@ -38,16 +43,25 @@ HUD::HUD(int width, int height, int fpsLevel)
getWidget(health, "Health"); getWidget(health, "Health");
getWidget(magicka, "Magicka"); getWidget(magicka, "Magicka");
getWidget(stamina, "Stamina"); getWidget(stamina, "Stamina");
hmsBaseLeft = health->getLeft();
// Item and spell images and status bars // Item and spell images and status bars
getWidget(weapBox, "WeapBox");
getWidget(weapImage, "WeapImage"); getWidget(weapImage, "WeapImage");
getWidget(weapStatus, "WeapStatus"); getWidget(weapStatus, "WeapStatus");
weapBoxBaseLeft = weapBox->getLeft();
getWidget(spellBox, "SpellBox");
getWidget(spellImage, "SpellImage"); getWidget(spellImage, "SpellImage");
getWidget(spellStatus, "SpellStatus"); getWidget(spellStatus, "SpellStatus");
spellBoxBaseLeft = spellBox->getLeft();
getWidget(effectBox, "EffectBox"); getWidget(effectBox, "EffectBox");
getWidget(effect1, "Effect1"); getWidget(effect1, "Effect1");
effectBoxBaseRight = effectBox->getRight();
getWidget(minimapBox, "MiniMapBox");
minimapBoxBaseRight = minimapBox->getRight();
getWidget(minimap, "MiniMap"); getWidget(minimap, "MiniMap");
getWidget(compass, "Compass"); getWidget(compass, "Compass");
@ -163,15 +177,21 @@ void HUD::setValue(const std::string& id, const MWMechanics::DynamicStat<int>& v
void HUD::setPlayerDir(const float x, const float y) void HUD::setPlayerDir(const float x, const float y)
{ {
if (!minimapBox->getVisible() || (x == mLastPositionX && y == mLastPositionY)) return;
MyGUI::ISubWidget* main = compass->getSubWidgetMain(); MyGUI::ISubWidget* main = compass->getSubWidgetMain();
MyGUI::RotatingSkin* rotatingSubskin = main->castType<MyGUI::RotatingSkin>(); MyGUI::RotatingSkin* rotatingSubskin = main->castType<MyGUI::RotatingSkin>();
rotatingSubskin->setCenter(MyGUI::IntPoint(16,16)); rotatingSubskin->setCenter(MyGUI::IntPoint(16,16));
float angle = std::atan2(x,y); float angle = std::atan2(x,y);
rotatingSubskin->setAngle(angle); rotatingSubskin->setAngle(angle);
mLastPositionX = x;
mLastPositionY = y;
} }
void HUD::setPlayerPos(const float x, const float y) void HUD::setPlayerPos(const float x, const float y)
{ {
if (!minimapBox->getVisible() || (x == mLastDirectionX && y == mLastDirectionY)) return;
MyGUI::IntSize size = minimap->getCanvasSize(); MyGUI::IntSize size = minimap->getCanvasSize();
MyGUI::IntPoint middle = MyGUI::IntPoint((1/3.f + x/3.f)*size.width,(1/3.f + y/3.f)*size.height); MyGUI::IntPoint middle = MyGUI::IntPoint((1/3.f + x/3.f)*size.width,(1/3.f + y/3.f)*size.height);
MyGUI::IntCoord viewsize = minimap->getCoord(); MyGUI::IntCoord viewsize = minimap->getCoord();
@ -179,6 +199,39 @@ void HUD::setPlayerPos(const float x, const float y)
minimap->setViewOffset(pos); minimap->setViewOffset(pos);
compass->setPosition(MyGUI::IntPoint(x*512-16, y*512-16)); compass->setPosition(MyGUI::IntPoint(x*512-16, y*512-16));
mLastDirectionX = x;
mLastDirectionY = y;
}
void HUD::setBottomLeftVisibility(bool hmsVisible, bool weapVisible, bool spellVisible)
{
int weapDx = 0, spellDx = 0;
if (!hmsVisible)
spellDx = weapDx = weapBoxBaseLeft - hmsBaseLeft;
if (!weapVisible)
spellDx -= spellBoxBaseLeft - weapBoxBaseLeft;
health->setVisible(hmsVisible);
stamina->setVisible(hmsVisible);
magicka->setVisible(hmsVisible);
weapBox->setPosition(weapBoxBaseLeft - weapDx, weapBox->getTop());
weapBox->setVisible(weapVisible);
spellBox->setPosition(spellBoxBaseLeft - spellDx, spellBox->getTop());
spellBox->setVisible(spellVisible);
}
void HUD::setBottomRightVisibility(bool effectBoxVisible, bool minimapBoxVisible)
{
// effect box can have variable width -> variable left coordinate
int effectsDx = 0;
if (!minimapBoxVisible)
effectsDx = minimapBoxBaseRight - effectBoxBaseRight;
minimapBox->setVisible(minimapBoxVisible);
effectBox->setPosition(effectBoxBaseRight - effectBox->getWidth() + effectsDx, effectBox->getTop());
effectBox->setVisible(effectBoxVisible);
} }
LocalMapBase::LocalMapBase() LocalMapBase::LocalMapBase()
@ -189,6 +242,10 @@ LocalMapBase::LocalMapBase()
, mPrefix() , mPrefix()
, mChanged(true) , mChanged(true)
, mLayout(NULL) , mLayout(NULL)
, mLastPositionX(0.0f)
, mLastPositionY(0.0f)
, mLastDirectionX(0.0f)
, mLastDirectionY(0.0f)
{ {
} }

@ -48,6 +48,11 @@ namespace MWGui
bool mChanged; bool mChanged;
OEngine::GUI::Layout* mLayout; OEngine::GUI::Layout* mLayout;
float mLastPositionX;
float mLastPositionY;
float mLastDirectionX;
float mLastDirectionY;
}; };
class HUD : public OEngine::GUI::Layout, public LocalMapBase class HUD : public OEngine::GUI::Layout, public LocalMapBase
@ -66,11 +71,14 @@ namespace MWGui
void setBatchCount(size_t count); void setBatchCount(size_t count);
void setPlayerDir(const float x, const float y); void setPlayerDir(const float x, const float y);
void setPlayerPos(const float x, const float y); void setPlayerPos(const float x, const float y);
void setBottomLeftVisibility(bool hmsVisible, bool weapVisible, bool spellVisible);
void setBottomRightVisibility(bool effectBoxVisible, bool minimapVisible);
MyGUI::ProgressPtr health, magicka, stamina; MyGUI::ProgressPtr health, magicka, stamina;
MyGUI::Widget *weapBox, *spellBox;
MyGUI::ImageBox *weapImage, *spellImage; MyGUI::ImageBox *weapImage, *spellImage;
MyGUI::ProgressPtr weapStatus, spellStatus; MyGUI::ProgressPtr weapStatus, spellStatus;
MyGUI::WidgetPtr effectBox; MyGUI::Widget *effectBox, *minimapBox;
MyGUI::ImageBox* effect1; MyGUI::ImageBox* effect1;
MyGUI::ScrollView* minimap; MyGUI::ScrollView* minimap;
MyGUI::ImageBox* compass; MyGUI::ImageBox* compass;
@ -80,6 +88,12 @@ namespace MWGui
MyGUI::TextBox* fpscounter; MyGUI::TextBox* fpscounter;
MyGUI::TextBox* trianglecounter; MyGUI::TextBox* trianglecounter;
MyGUI::TextBox* batchcounter; MyGUI::TextBox* batchcounter;
private:
// bottom left elements
int hmsBaseLeft, weapBoxBaseLeft, spellBoxBaseLeft;
// bottom right elements
int minimapBoxBaseRight, effectBoxBaseRight;
}; };
class MainMenu : public OEngine::GUI::Layout class MainMenu : public OEngine::GUI::Layout

@ -1,7 +1,7 @@
#include "map_window.hpp" #include "map_window.hpp"
#include "window_manager.hpp"
/* /*
#include "../mwmechanics/mechanicsmanager.hpp" #include "../mwmechanics/mechanicsmanager.hpp"
#include "window_manager.hpp"
#include <cmath> #include <cmath>
#include <algorithm> #include <algorithm>
@ -14,11 +14,7 @@ using namespace MWGui;
MapWindow::MapWindow(WindowManager& parWindowManager) : MapWindow::MapWindow(WindowManager& parWindowManager) :
MWGui::WindowPinnableBase("openmw_map_window_layout.xml", parWindowManager), MWGui::WindowPinnableBase("openmw_map_window_layout.xml", parWindowManager),
mGlobal(false), mGlobal(false)
mLastPositionX(0.0f),
mLastPositionY(0.0f),
mLastDirectionX(0.0f),
mLastDirectionY(0.0f)
{ {
setCoord(500,0,320,300); setCoord(500,0,320,300);
setText("WorldButton", "World"); setText("WorldButton", "World");
@ -104,3 +100,7 @@ void MapWindow::onWorldButtonClicked(MyGUI::Widget* _sender)
mButton->setCaption( mGlobal ? "Local" : "World" ); mButton->setCaption( mGlobal ? "Local" : "World" );
} }
void MapWindow::onPinToggled()
{
mWindowManager.setMinimapVisibility(!mPinned);
}

@ -26,10 +26,9 @@ namespace MWGui
MyGUI::Button* mButton; MyGUI::Button* mButton;
MyGUI::IntPoint mLastDragPos; MyGUI::IntPoint mLastDragPos;
bool mGlobal; bool mGlobal;
float mLastPositionX;
float mLastPositionY; protected:
float mLastDirectionX; virtual void onPinToggled();
float mLastDirectionY;
}; };
} }
#endif #endif

@ -381,3 +381,8 @@ void StatsWindow::updateScroller()
skillScrollerWidget->setScrollRange(std::max(clientHeight - skillClientWidget->getHeight(), 0)); skillScrollerWidget->setScrollRange(std::max(clientHeight - skillClientWidget->getHeight(), 0));
skillScrollerWidget->setScrollPage(std::max(skillClientWidget->getHeight() - lineHeight, 0)); skillScrollerWidget->setScrollPage(std::max(skillClientWidget->getHeight() - lineHeight, 0));
} }
void StatsWindow::onPinToggled()
{
mWindowManager.setHMSVisibility(!mPinned);
}

@ -74,6 +74,9 @@ namespace MWGui
std::string birthSignId; std::string birthSignId;
int reputation, bounty; int reputation, bounty;
std::vector<MyGUI::WidgetPtr> skillWidgets; //< Skills and other information std::vector<MyGUI::WidgetPtr> skillWidgets; //< Skills and other information
protected:
virtual void onPinToggled();
}; };
} }
#endif #endif

@ -456,3 +456,13 @@ void WindowManager::setPlayerDir(const float x, const float y)
map->setPlayerDir(x,y); map->setPlayerDir(x,y);
hud->setPlayerDir(x,y); hud->setPlayerDir(x,y);
} }
void WindowManager::setHMSVisibility(bool visible)
{
hud->setBottomLeftVisibility(visible, hud->weapBox->getVisible(), hud->spellBox->getVisible());
}
void WindowManager::setMinimapVisibility(bool visible)
{
hud->setBottomRightVisibility(hud->effectBox->getVisible(), visible);
}

@ -160,6 +160,11 @@ namespace MWGui
void setInteriorMapTexture(const int x, const int y); void setInteriorMapTexture(const int x, const int y);
///< set the index of the map texture that should be used (for interiors) ///< set the index of the map texture that should be used (for interiors)
// sets the visibility of the hud health/magicka/stamina bars
void setHMSVisibility(bool visible);
// sets the visibility of the hud minimap
void setMinimapVisibility(bool visible);
template<typename T> template<typename T>
void removeDialog(T*& dialog); ///< Casts to OEngine::GUI::Layout and calls removeDialog, then resets pointer to nullptr. void removeDialog(T*& dialog); ///< Casts to OEngine::GUI::Layout and calls removeDialog, then resets pointer to nullptr.
void removeDialog(OEngine::GUI::Layout* dialog); ///< Hides dialog and schedules dialog to be deleted. void removeDialog(OEngine::GUI::Layout* dialog); ///< Hides dialog and schedules dialog to be deleted.

@ -25,6 +25,7 @@ void WindowPinnableBase::onWindowButtonPressed(MyGUI::Window* sender, const std:
if ("PinToggle" == eventName) if ("PinToggle" == eventName)
{ {
mPinned = !mPinned; mPinned = !mPinned;
onPinToggled();
} }
eventDone(this); eventDone(this);

@ -17,6 +17,8 @@ namespace MWGui
void onWindowButtonPressed(MyGUI::Window* sender, const std::string& eventName); void onWindowButtonPressed(MyGUI::Window* sender, const std::string& eventName);
protected: protected:
virtual void onPinToggled() = 0;
bool mPinned; bool mPinned;
bool mVisible; bool mVisible;
}; };

@ -11,22 +11,24 @@
align="Left Bottom" name="Stamina"/> align="Left Bottom" name="Stamina"/>
<!-- Equipped weapon box --> <!-- Equipped weapon box -->
<Widget type="Widget" skin="HUD_Box" position="82 146 36 36" <Widget type="Widget" position="82 146 36 41" align="Left Bottom" name="WeapBox">
align="Left Bottom"> <Widget type="Widget" skin="HUD_Box" position="0 0 36 36">
<Widget type="ImageBox" skin="ImageBox" position="2 2 32 32" align="Left Top" <Widget type="ImageBox" skin="ImageBox" position="2 2 32 32" align="Left Top"
name="WeapImage"/> name="WeapImage"/>
</Widget>
<Widget type="ProgressBar" skin="MW_EnergyBar_Red" position="0 36 36 6"
align="Left Bottom" name="WeapStatus"/>
</Widget> </Widget>
<Widget type="ProgressBar" skin="MW_EnergyBar_Red" position="82 182 36 6"
align="Left Bottom" name="WeapStatus"/>
<!-- Selected spell box --> <!-- Selected spell box -->
<Widget type="Widget" skin="HUD_Box" position="122 146 36 36" <Widget type="Widget" position="122 146 36 41" align="Left Bottom" name="SpellBox">
align="Left Bottom"> <Widget type="Widget" skin="HUD_Box" position="0 0 36 36">
<Widget type="ImageBox" skin="ImageBox" position="2 2 32 32" align="Left Top" <Widget type="ImageBox" skin="ImageBox" position="2 2 32 32" align="Left Top"
name="SpellImage"/> name="SpellImage"/>
</Widget>
<Widget type="ProgressBar" skin="MW_EnergyBar_Red" position="0 36 36 6"
align="Left Bottom" name="SpellStatus"/>
</Widget> </Widget>
<Widget type="ProgressBar" skin="MW_EnergyBar_Red" position="122 182 36 6"
align="Left Bottom" name="SpellStatus"/>
<!-- Spell effects box --> <!-- Spell effects box -->
<Widget type="Widget" skin="HUD_Box" position="199 168 20 20" <Widget type="Widget" skin="HUD_Box" position="199 168 20 20"
@ -36,7 +38,7 @@
</Widget> </Widget>
<!-- Map box --> <!-- Map box -->
<Widget type="Widget" skin="HUD_Box" position="223 123 65 65" <Widget type="Widget" skin="HUD_Box" position="223 123 65 65" name="MiniMapBox"
align="Right Bottom"> align="Right Bottom">
<Widget type="ScrollView" skin="MW_MapView" position="2 2 61 61" align="Left Bottom" name="MiniMap"> <Widget type="ScrollView" skin="MW_MapView" position="2 2 61 61" align="Left Bottom" name="MiniMap">

Loading…
Cancel
Save