mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-31 13:26:38 +00:00 
			
		
		
		
	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).
This commit is contained in:
		
							parent
							
								
									91a377df86
								
							
						
					
					
						commit
						ef0a185e11
					
				
					 11 changed files with 122 additions and 24 deletions
				
			
		|  | @ -31,6 +31,11 @@ HUD::HUD(int width, int height, int fpsLevel) | |||
|     , fpscounter(NULL) | ||||
|     , trianglecounter(NULL) | ||||
|     , batchcounter(NULL) | ||||
|     , hmsBaseLeft(0) | ||||
|     , weapBoxBaseLeft(0) | ||||
|     , spellBoxBaseLeft(0) | ||||
|     , effectBoxBaseRight(0) | ||||
|     , minimapBoxBaseRight(0) | ||||
| { | ||||
|     setCoord(0,0, width, height); | ||||
| 
 | ||||
|  | @ -38,16 +43,25 @@ HUD::HUD(int width, int height, int fpsLevel) | |||
|     getWidget(health, "Health"); | ||||
|     getWidget(magicka, "Magicka"); | ||||
|     getWidget(stamina, "Stamina"); | ||||
|     hmsBaseLeft = health->getLeft(); | ||||
| 
 | ||||
|     // Item and spell images and status bars
 | ||||
|     getWidget(weapBox, "WeapBox"); | ||||
|     getWidget(weapImage, "WeapImage"); | ||||
|     getWidget(weapStatus, "WeapStatus"); | ||||
|     weapBoxBaseLeft = weapBox->getLeft(); | ||||
| 
 | ||||
|     getWidget(spellBox, "SpellBox"); | ||||
|     getWidget(spellImage, "SpellImage"); | ||||
|     getWidget(spellStatus, "SpellStatus"); | ||||
|     spellBoxBaseLeft = spellBox->getLeft(); | ||||
| 
 | ||||
|     getWidget(effectBox, "EffectBox"); | ||||
|     getWidget(effect1, "Effect1"); | ||||
|     effectBoxBaseRight = effectBox->getRight(); | ||||
| 
 | ||||
|     getWidget(minimapBox, "MiniMapBox"); | ||||
|     minimapBoxBaseRight = minimapBox->getRight(); | ||||
|     getWidget(minimap, "MiniMap"); | ||||
|     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) | ||||
| { | ||||
|     if (!minimapBox->getVisible() || (x == mLastPositionX && y == mLastPositionY)) return; | ||||
| 
 | ||||
|     MyGUI::ISubWidget* main = compass->getSubWidgetMain(); | ||||
|     MyGUI::RotatingSkin* rotatingSubskin = main->castType<MyGUI::RotatingSkin>(); | ||||
|     rotatingSubskin->setCenter(MyGUI::IntPoint(16,16)); | ||||
|     float angle = std::atan2(x,y); | ||||
|     rotatingSubskin->setAngle(angle); | ||||
|     mLastPositionX = x; | ||||
|     mLastPositionY = y; | ||||
| } | ||||
| 
 | ||||
| void HUD::setPlayerPos(const float x, const float y) | ||||
| { | ||||
|     if (!minimapBox->getVisible() || (x == mLastDirectionX && y == mLastDirectionY)) return; | ||||
| 
 | ||||
|     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::IntCoord viewsize = minimap->getCoord(); | ||||
|  | @ -179,6 +199,39 @@ void HUD::setPlayerPos(const float x, const float y) | |||
| 
 | ||||
|     minimap->setViewOffset(pos); | ||||
|     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() | ||||
|  | @ -189,6 +242,10 @@ LocalMapBase::LocalMapBase() | |||
|     , mPrefix() | ||||
|     , mChanged(true) | ||||
|     , mLayout(NULL) | ||||
|     , mLastPositionX(0.0f) | ||||
|     , mLastPositionY(0.0f) | ||||
|     , mLastDirectionX(0.0f) | ||||
|     , mLastDirectionY(0.0f) | ||||
| { | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -48,6 +48,11 @@ namespace MWGui | |||
|     bool mChanged; | ||||
| 
 | ||||
|     OEngine::GUI::Layout* mLayout; | ||||
| 
 | ||||
|     float mLastPositionX; | ||||
|     float mLastPositionY; | ||||
|     float mLastDirectionX; | ||||
|     float mLastDirectionY; | ||||
|   }; | ||||
|    | ||||
|   class HUD : public OEngine::GUI::Layout, public LocalMapBase | ||||
|  | @ -66,11 +71,14 @@ namespace MWGui | |||
|     void setBatchCount(size_t count); | ||||
|     void setPlayerDir(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::Widget *weapBox, *spellBox; | ||||
|     MyGUI::ImageBox *weapImage, *spellImage; | ||||
|     MyGUI::ProgressPtr weapStatus, spellStatus; | ||||
|     MyGUI::WidgetPtr effectBox; | ||||
|     MyGUI::Widget *effectBox, *minimapBox; | ||||
|     MyGUI::ImageBox* effect1; | ||||
|     MyGUI::ScrollView* minimap; | ||||
|     MyGUI::ImageBox* compass; | ||||
|  | @ -80,6 +88,12 @@ namespace MWGui | |||
|     MyGUI::TextBox* fpscounter; | ||||
|     MyGUI::TextBox* trianglecounter; | ||||
|     MyGUI::TextBox* batchcounter; | ||||
| 
 | ||||
|   private: | ||||
|     // bottom left elements
 | ||||
|     int hmsBaseLeft, weapBoxBaseLeft, spellBoxBaseLeft; | ||||
|     // bottom right elements
 | ||||
|     int minimapBoxBaseRight, effectBoxBaseRight; | ||||
|   }; | ||||
| 
 | ||||
|   class MainMenu : public OEngine::GUI::Layout | ||||
|  |  | |||
|  | @ -1,7 +1,7 @@ | |||
| #include "map_window.hpp" | ||||
| #include "window_manager.hpp" | ||||
| /*
 | ||||
| #include "../mwmechanics/mechanicsmanager.hpp" | ||||
| #include "window_manager.hpp" | ||||
| 
 | ||||
| #include <cmath> | ||||
| #include <algorithm> | ||||
|  | @ -14,11 +14,7 @@ using namespace MWGui; | |||
| 
 | ||||
| MapWindow::MapWindow(WindowManager& parWindowManager) :  | ||||
|     MWGui::WindowPinnableBase("openmw_map_window_layout.xml", parWindowManager), | ||||
|     mGlobal(false), | ||||
|     mLastPositionX(0.0f), | ||||
|     mLastPositionY(0.0f), | ||||
|     mLastDirectionX(0.0f), | ||||
|     mLastDirectionY(0.0f) | ||||
|     mGlobal(false) | ||||
| { | ||||
|     setCoord(500,0,320,300); | ||||
|     setText("WorldButton", "World"); | ||||
|  | @ -104,3 +100,7 @@ void MapWindow::onWorldButtonClicked(MyGUI::Widget* _sender) | |||
|     mButton->setCaption( mGlobal ? "Local" : "World" ); | ||||
| } | ||||
| 
 | ||||
| void MapWindow::onPinToggled() | ||||
| { | ||||
|     mWindowManager.setMinimapVisibility(!mPinned); | ||||
| } | ||||
|  |  | |||
|  | @ -26,10 +26,9 @@ namespace MWGui | |||
|         MyGUI::Button* mButton; | ||||
|         MyGUI::IntPoint mLastDragPos; | ||||
|         bool mGlobal; | ||||
|         float mLastPositionX; | ||||
|         float mLastPositionY; | ||||
|         float mLastDirectionX; | ||||
|         float mLastDirectionY; | ||||
| 
 | ||||
|     protected: | ||||
|         virtual void onPinToggled(); | ||||
|     }; | ||||
| } | ||||
| #endif | ||||
|  |  | |||
|  | @ -381,3 +381,8 @@ void StatsWindow::updateScroller() | |||
|     skillScrollerWidget->setScrollRange(std::max(clientHeight - skillClientWidget->getHeight(), 0)); | ||||
|     skillScrollerWidget->setScrollPage(std::max(skillClientWidget->getHeight() - lineHeight, 0)); | ||||
| } | ||||
| 
 | ||||
| void StatsWindow::onPinToggled() | ||||
| { | ||||
|     mWindowManager.setHMSVisibility(!mPinned); | ||||
| } | ||||
|  |  | |||
|  | @ -74,6 +74,9 @@ namespace MWGui | |||
|             std::string birthSignId; | ||||
|             int reputation, bounty; | ||||
|             std::vector<MyGUI::WidgetPtr> skillWidgets; //< Skills and other information
 | ||||
| 
 | ||||
|         protected: | ||||
|             virtual void onPinToggled(); | ||||
|     }; | ||||
| } | ||||
| #endif | ||||
|  |  | |||
|  | @ -456,3 +456,13 @@ void WindowManager::setPlayerDir(const float x, const float y) | |||
|     map->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); | ||||
|     ///< 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> | ||||
|     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.
 | ||||
|  |  | |||
|  | @ -25,6 +25,7 @@ void WindowPinnableBase::onWindowButtonPressed(MyGUI::Window* sender, const std: | |||
|     if ("PinToggle" == eventName) | ||||
|     { | ||||
|         mPinned = !mPinned; | ||||
|         onPinToggled(); | ||||
|     } | ||||
| 
 | ||||
|     eventDone(this); | ||||
|  |  | |||
|  | @ -17,6 +17,8 @@ namespace MWGui | |||
|         void onWindowButtonPressed(MyGUI::Window* sender, const std::string& eventName); | ||||
|          | ||||
|     protected: | ||||
|         virtual void onPinToggled() = 0; | ||||
| 
 | ||||
|         bool mPinned; | ||||
|         bool mVisible; | ||||
|     }; | ||||
|  |  | |||
|  | @ -11,22 +11,24 @@ | |||
|             align="Left Bottom" name="Stamina"/> | ||||
| 
 | ||||
|         <!-- Equipped weapon box --> | ||||
|         <Widget type="Widget" skin="HUD_Box" position="82 146 36 36" | ||||
|             align="Left Bottom"> | ||||
|             <Widget type="ImageBox" skin="ImageBox" position="2 2 32 32" align="Left Top" | ||||
|                 name="WeapImage"/> | ||||
|         <Widget type="Widget" position="82 146 36 41" align="Left Bottom" name="WeapBox"> | ||||
|             <Widget type="Widget" skin="HUD_Box" position="0 0 36 36"> | ||||
|                 <Widget type="ImageBox" skin="ImageBox" position="2 2 32 32" align="Left Top" | ||||
|                     name="WeapImage"/> | ||||
|             </Widget> | ||||
|             <Widget type="ProgressBar" skin="MW_EnergyBar_Red" position="0 36 36 6" | ||||
|                 align="Left Bottom" name="WeapStatus"/> | ||||
|         </Widget> | ||||
|         <Widget type="ProgressBar" skin="MW_EnergyBar_Red" position="82 182 36 6" | ||||
|             align="Left Bottom" name="WeapStatus"/> | ||||
| 
 | ||||
|         <!-- Selected spell box --> | ||||
|         <Widget type="Widget" skin="HUD_Box" position="122 146 36 36" | ||||
|             align="Left Bottom"> | ||||
|             <Widget type="ImageBox" skin="ImageBox" position="2 2 32 32" align="Left Top" | ||||
|                 name="SpellImage"/> | ||||
|         <Widget type="Widget" position="122 146 36 41" align="Left Bottom" name="SpellBox"> | ||||
|             <Widget type="Widget" skin="HUD_Box" position="0 0 36 36"> | ||||
|                 <Widget type="ImageBox" skin="ImageBox" position="2 2 32 32" align="Left Top" | ||||
|                     name="SpellImage"/> | ||||
|             </Widget> | ||||
|             <Widget type="ProgressBar" skin="MW_EnergyBar_Red" position="0 36 36 6" | ||||
|                 align="Left Bottom" name="SpellStatus"/> | ||||
|         </Widget> | ||||
|         <Widget type="ProgressBar" skin="MW_EnergyBar_Red" position="122 182 36 6" | ||||
|             align="Left Bottom" name="SpellStatus"/> | ||||
| 
 | ||||
|         <!-- Spell effects box --> | ||||
|         <Widget type="Widget" skin="HUD_Box" position="199 168 20 20" | ||||
|  | @ -36,7 +38,7 @@ | |||
|         </Widget> | ||||
| 
 | ||||
|         <!-- 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"> | ||||
| 
 | ||||
|             <Widget type="ScrollView" skin="MW_MapView" position="2 2 61 61" align="Left Bottom" name="MiniMap"> | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue