mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 21:23:52 +00:00
show/hide crosshair correctly
This commit is contained in:
parent
61923349e5
commit
9af0b48ad6
7 changed files with 134 additions and 85 deletions
|
@ -177,6 +177,8 @@ namespace MWBase
|
|||
virtual void unsetSelectedSpell() = 0;
|
||||
virtual void unsetSelectedWeapon() = 0;
|
||||
|
||||
virtual void showCrosshair(bool show) = 0;
|
||||
|
||||
virtual void disallowMouse() = 0;
|
||||
virtual void allowMouse() = 0;
|
||||
virtual void notifyInputActionBound() = 0;
|
||||
|
|
|
@ -24,9 +24,9 @@ using namespace MWGui;
|
|||
|
||||
HUD::HUD(int width, int height, int fpsLevel, DragAndDrop* dragAndDrop)
|
||||
: Layout("openmw_hud.layout")
|
||||
, health(NULL)
|
||||
, magicka(NULL)
|
||||
, stamina(NULL)
|
||||
, mHealth(NULL)
|
||||
, mMagicka(NULL)
|
||||
, mStamina(NULL)
|
||||
, mWeapImage(NULL)
|
||||
, mSpellImage(NULL)
|
||||
, mWeapStatus(NULL)
|
||||
|
@ -36,10 +36,10 @@ HUD::HUD(int width, int height, int fpsLevel, DragAndDrop* dragAndDrop)
|
|||
, mMinimap(NULL)
|
||||
, mCompass(NULL)
|
||||
, mCrosshair(NULL)
|
||||
, fpsbox(NULL)
|
||||
, fpscounter(NULL)
|
||||
, trianglecounter(NULL)
|
||||
, batchcounter(NULL)
|
||||
, mFpsBox(NULL)
|
||||
, mFpsCounter(NULL)
|
||||
, mTriangleCounter(NULL)
|
||||
, mBatchCounter(NULL)
|
||||
, mHealthManaStaminaBaseLeft(0)
|
||||
, mWeapBoxBaseLeft(0)
|
||||
, mSpellBoxBaseLeft(0)
|
||||
|
@ -57,9 +57,9 @@ HUD::HUD(int width, int height, int fpsLevel, DragAndDrop* dragAndDrop)
|
|||
|
||||
// Energy bars
|
||||
getWidget(mHealthFrame, "HealthFrame");
|
||||
getWidget(health, "Health");
|
||||
getWidget(magicka, "Magicka");
|
||||
getWidget(stamina, "Stamina");
|
||||
getWidget(mHealth, "Health");
|
||||
getWidget(mMagicka, "Magicka");
|
||||
getWidget(mStamina, "Stamina");
|
||||
|
||||
mHealthManaStaminaBaseLeft = mHealthFrame->getLeft();
|
||||
|
||||
|
@ -104,8 +104,8 @@ HUD::HUD(int width, int height, int fpsLevel, DragAndDrop* dragAndDrop)
|
|||
|
||||
setFpsLevel(fpsLevel);
|
||||
|
||||
getWidget(trianglecounter, "TriangleCounter");
|
||||
getWidget(batchcounter, "BatchCounter");
|
||||
getWidget(mTriangleCounter, "TriangleCounter");
|
||||
getWidget(mBatchCounter, "BatchCounter");
|
||||
|
||||
setEffect("icons\\s\\tx_s_chameleon.dds");
|
||||
|
||||
|
@ -118,7 +118,7 @@ HUD::HUD(int width, int height, int fpsLevel, DragAndDrop* dragAndDrop)
|
|||
|
||||
void HUD::setFpsLevel(int level)
|
||||
{
|
||||
fpscounter = 0;
|
||||
mFpsCounter = 0;
|
||||
|
||||
MyGUI::Widget* fps;
|
||||
getWidget(fps, "FPSBoxAdv");
|
||||
|
@ -128,32 +128,32 @@ void HUD::setFpsLevel(int level)
|
|||
|
||||
if (level == 2)
|
||||
{
|
||||
getWidget(fpsbox, "FPSBoxAdv");
|
||||
fpsbox->setVisible(true);
|
||||
getWidget(fpscounter, "FPSCounterAdv");
|
||||
getWidget(mFpsBox, "FPSBoxAdv");
|
||||
mFpsBox->setVisible(true);
|
||||
getWidget(mFpsCounter, "FPSCounterAdv");
|
||||
}
|
||||
else if (level == 1)
|
||||
{
|
||||
getWidget(fpsbox, "FPSBox");
|
||||
fpsbox->setVisible(true);
|
||||
getWidget(fpscounter, "FPSCounter");
|
||||
getWidget(mFpsBox, "FPSBox");
|
||||
mFpsBox->setVisible(true);
|
||||
getWidget(mFpsCounter, "FPSCounter");
|
||||
}
|
||||
}
|
||||
|
||||
void HUD::setFPS(float fps)
|
||||
{
|
||||
if (fpscounter)
|
||||
fpscounter->setCaption(boost::lexical_cast<std::string>((int)fps));
|
||||
if (mFpsCounter)
|
||||
mFpsCounter->setCaption(boost::lexical_cast<std::string>((int)fps));
|
||||
}
|
||||
|
||||
void HUD::setTriangleCount(unsigned int count)
|
||||
{
|
||||
trianglecounter->setCaption(boost::lexical_cast<std::string>(count));
|
||||
mTriangleCounter->setCaption(boost::lexical_cast<std::string>(count));
|
||||
}
|
||||
|
||||
void HUD::setBatchCount(unsigned int count)
|
||||
{
|
||||
batchcounter->setCaption(boost::lexical_cast<std::string>(count));
|
||||
mBatchCounter->setCaption(boost::lexical_cast<std::string>(count));
|
||||
}
|
||||
|
||||
void HUD::setEffect(const char *img)
|
||||
|
@ -176,20 +176,20 @@ void HUD::setValue(const std::string& id, const MWMechanics::DynamicStat<int>& v
|
|||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
health->setProgressRange (value.getModified());
|
||||
health->setProgressPosition (value.getCurrent());
|
||||
mHealth->setProgressRange (value.getModified());
|
||||
mHealth->setProgressPosition (value.getCurrent());
|
||||
getWidget(w, "HealthFrame");
|
||||
w->setUserString("Caption_HealthDescription", "#{sHealthDesc}\n" + valStr);
|
||||
break;
|
||||
case 1:
|
||||
magicka->setProgressRange (value.getModified());
|
||||
magicka->setProgressPosition (value.getCurrent());
|
||||
mMagicka->setProgressRange (value.getModified());
|
||||
mMagicka->setProgressPosition (value.getCurrent());
|
||||
getWidget(w, "MagickaFrame");
|
||||
w->setUserString("Caption_HealthDescription", "#{sIntDesc}\n" + valStr);
|
||||
break;
|
||||
case 2:
|
||||
stamina->setProgressRange (value.getModified());
|
||||
stamina->setProgressPosition (value.getCurrent());
|
||||
mStamina->setProgressRange (value.getModified());
|
||||
mStamina->setProgressPosition (value.getCurrent());
|
||||
getWidget(w, "FatigueFrame");
|
||||
w->setUserString("Caption_HealthDescription", "#{sFatDesc}\n" + valStr);
|
||||
break;
|
||||
|
@ -197,44 +197,6 @@ void HUD::setValue(const std::string& id, const MWMechanics::DynamicStat<int>& v
|
|||
}
|
||||
}
|
||||
|
||||
void HUD::setBottomLeftVisibility(bool hmsVisible, bool weapVisible, bool spellVisible)
|
||||
{
|
||||
int weapDx = 0, spellDx = 0;
|
||||
if (!hmsVisible)
|
||||
spellDx = weapDx = mWeapBoxBaseLeft - mHealthManaStaminaBaseLeft;
|
||||
|
||||
if (!weapVisible)
|
||||
spellDx += mSpellBoxBaseLeft - mWeapBoxBaseLeft;
|
||||
|
||||
mWeaponVisible = weapVisible;
|
||||
mSpellVisible = spellVisible;
|
||||
if (!mWeaponVisible && !mSpellVisible)
|
||||
mWeaponSpellBox->setVisible(false);
|
||||
|
||||
health->setVisible(hmsVisible);
|
||||
stamina->setVisible(hmsVisible);
|
||||
magicka->setVisible(hmsVisible);
|
||||
mWeapBox->setPosition(mWeapBoxBaseLeft - weapDx, mWeapBox->getTop());
|
||||
mWeapBox->setVisible(weapVisible);
|
||||
mSpellBox->setPosition(mSpellBoxBaseLeft - spellDx, mSpellBox->getTop());
|
||||
mSpellBox->setVisible(spellVisible);
|
||||
}
|
||||
|
||||
void HUD::setBottomRightVisibility(bool effectBoxVisible, bool minimapBoxVisible)
|
||||
{
|
||||
const MyGUI::IntSize& viewSize = MyGUI::RenderManager::getInstance().getViewSize();
|
||||
|
||||
// effect box can have variable width -> variable left coordinate
|
||||
int effectsDx = 0;
|
||||
if (!minimapBoxVisible)
|
||||
effectsDx = (viewSize.width - mMinimapBoxBaseRight) - (viewSize.width - mEffectBoxBaseRight);
|
||||
|
||||
mMapVisible = minimapBoxVisible;
|
||||
mMinimapBox->setVisible(minimapBoxVisible);
|
||||
mEffectBox->setPosition((viewSize.width - mEffectBoxBaseRight) - mEffectBox->getWidth() + effectsDx, mEffectBox->getTop());
|
||||
mEffectBox->setVisible(effectBoxVisible);
|
||||
}
|
||||
|
||||
void HUD::onWorldClicked(MyGUI::Widget* _sender)
|
||||
{
|
||||
if (!MWBase::Environment::get().getWindowManager ()->isGuiMode ())
|
||||
|
@ -520,3 +482,68 @@ void HUD::unsetSelectedWeapon()
|
|||
mWeapImage->setImageTexture("icons\\k\\stealth_handtohand.dds");
|
||||
mWeapBox->clearUserStrings();
|
||||
}
|
||||
|
||||
void HUD::setCrosshairVisible(bool visible)
|
||||
{
|
||||
mCrosshair->setVisible (visible);
|
||||
}
|
||||
|
||||
void HUD::setHmsVisible(bool visible)
|
||||
{
|
||||
mHealth->setVisible(visible);
|
||||
mMagicka->setVisible(visible);
|
||||
mStamina->setVisible(visible);
|
||||
updatePositions();
|
||||
}
|
||||
|
||||
void HUD::setWeapVisible(bool visible)
|
||||
{
|
||||
mWeapBox->setVisible(visible);
|
||||
updatePositions();
|
||||
}
|
||||
|
||||
void HUD::setSpellVisible(bool visible)
|
||||
{
|
||||
mSpellBox->setVisible(visible);
|
||||
updatePositions();
|
||||
}
|
||||
|
||||
void HUD::setEffectVisible(bool visible)
|
||||
{
|
||||
mEffectBox->setVisible (visible);
|
||||
updatePositions();
|
||||
}
|
||||
|
||||
void HUD::setMinimapVisible(bool visible)
|
||||
{
|
||||
mMinimapBox->setVisible (visible);
|
||||
updatePositions();
|
||||
}
|
||||
|
||||
void HUD::updatePositions()
|
||||
{
|
||||
int weapDx = 0, spellDx = 0;
|
||||
if (!mHealth->getVisible())
|
||||
spellDx = weapDx = mWeapBoxBaseLeft - mHealthManaStaminaBaseLeft;
|
||||
|
||||
if (!mWeapBox->getVisible())
|
||||
spellDx += mSpellBoxBaseLeft - mWeapBoxBaseLeft;
|
||||
|
||||
mWeaponVisible = mWeapBox->getVisible();
|
||||
mSpellVisible = mSpellBox->getVisible();
|
||||
if (!mWeaponVisible && !mSpellVisible)
|
||||
mWeaponSpellBox->setVisible(false);
|
||||
|
||||
mWeapBox->setPosition(mWeapBoxBaseLeft - weapDx, mWeapBox->getTop());
|
||||
mSpellBox->setPosition(mSpellBoxBaseLeft - spellDx, mSpellBox->getTop());
|
||||
|
||||
const MyGUI::IntSize& viewSize = MyGUI::RenderManager::getInstance().getViewSize();
|
||||
|
||||
// effect box can have variable width -> variable left coordinate
|
||||
int effectsDx = 0;
|
||||
if (!mMinimapBox->getVisible ())
|
||||
effectsDx = (viewSize.width - mMinimapBoxBaseRight) - (viewSize.width - mEffectBoxBaseRight);
|
||||
|
||||
mMapVisible = mMinimapBox->getVisible ();
|
||||
mEffectBox->setPosition((viewSize.width - mEffectBoxBaseRight) - mEffectBox->getWidth() + effectsDx, mEffectBox->getTop());
|
||||
}
|
||||
|
|
|
@ -18,8 +18,14 @@ namespace MWGui
|
|||
void setFPS(float fps);
|
||||
void setTriangleCount(unsigned int count);
|
||||
void setBatchCount(unsigned int count);
|
||||
void setBottomLeftVisibility(bool hmsVisible, bool weapVisible, bool spellVisible);
|
||||
void setBottomRightVisibility(bool effectBoxVisible, bool minimapVisible);
|
||||
|
||||
void setHmsVisible(bool visible);
|
||||
void setWeapVisible(bool visible);
|
||||
void setSpellVisible(bool visible);
|
||||
|
||||
void setEffectVisible(bool visible);
|
||||
void setMinimapVisible(bool visible);
|
||||
|
||||
void setFpsLevel(const int level);
|
||||
|
||||
void setSelectedSpell(const std::string& spellId, int successChancePercent);
|
||||
|
@ -28,6 +34,8 @@ namespace MWGui
|
|||
void unsetSelectedSpell();
|
||||
void unsetSelectedWeapon();
|
||||
|
||||
void setCrosshairVisible(bool visible);
|
||||
|
||||
void onFrame(float dt);
|
||||
void onResChange(int width, int height);
|
||||
|
||||
|
@ -35,7 +43,8 @@ namespace MWGui
|
|||
|
||||
bool getWorldMouseOver() { return mWorldMouseOver; }
|
||||
|
||||
MyGUI::ProgressPtr health, magicka, stamina;
|
||||
private:
|
||||
MyGUI::ProgressPtr mHealth, mMagicka, mStamina;
|
||||
MyGUI::Widget* mHealthFrame;
|
||||
MyGUI::Widget *mWeapBox, *mSpellBox;
|
||||
MyGUI::ImageBox *mWeapImage, *mSpellImage;
|
||||
|
@ -50,12 +59,11 @@ namespace MWGui
|
|||
|
||||
MyGUI::Widget* mDummy;
|
||||
|
||||
MyGUI::WidgetPtr fpsbox;
|
||||
MyGUI::TextBox* fpscounter;
|
||||
MyGUI::TextBox* trianglecounter;
|
||||
MyGUI::TextBox* batchcounter;
|
||||
MyGUI::WidgetPtr mFpsBox;
|
||||
MyGUI::TextBox* mFpsCounter;
|
||||
MyGUI::TextBox* mTriangleCounter;
|
||||
MyGUI::TextBox* mBatchCounter;
|
||||
|
||||
private:
|
||||
// bottom left elements
|
||||
int mHealthManaStaminaBaseLeft, mWeapBoxBaseLeft, mSpellBoxBaseLeft;
|
||||
// bottom right elements
|
||||
|
@ -83,5 +91,7 @@ namespace MWGui
|
|||
void onWeaponClicked(MyGUI::Widget* _sender);
|
||||
void onMagicClicked(MyGUI::Widget* _sender);
|
||||
void onMapClicked(MyGUI::Widget* _sender);
|
||||
|
||||
void updatePositions();
|
||||
};
|
||||
}
|
||||
|
|
|
@ -559,12 +559,12 @@ void WindowManager::setPlayerDir(const float x, const float y)
|
|||
|
||||
void WindowManager::setHMSVisibility(bool visible)
|
||||
{
|
||||
mHud->setBottomLeftVisibility(visible, mHud->mWeapBox->getVisible(), mHud->mSpellBox->getVisible());
|
||||
mHud->setHmsVisible (visible);
|
||||
}
|
||||
|
||||
void WindowManager::setMinimapVisibility(bool visible)
|
||||
{
|
||||
mHud->setBottomRightVisibility(mHud->mEffectBox->getVisible(), visible);
|
||||
mHud->setMinimapVisible (visible);
|
||||
}
|
||||
|
||||
void WindowManager::toggleFogOfWar()
|
||||
|
@ -595,13 +595,13 @@ bool WindowManager::getFullHelp() const
|
|||
|
||||
void WindowManager::setWeaponVisibility(bool visible)
|
||||
{
|
||||
mHud->setBottomLeftVisibility(mHud->health->getVisible(), visible, mHud->mSpellBox->getVisible());
|
||||
mHud->setWeapVisible (visible);
|
||||
}
|
||||
|
||||
void WindowManager::setSpellVisibility(bool visible)
|
||||
{
|
||||
mHud->setBottomLeftVisibility(mHud->health->getVisible(), mHud->mWeapBox->getVisible(), visible);
|
||||
mHud->setBottomRightVisibility(visible, mHud->mMinimapBox->getVisible());
|
||||
mHud->setSpellVisible (visible);
|
||||
mHud->setEffectVisible (visible);
|
||||
}
|
||||
|
||||
void WindowManager::setMouseVisible(bool visible)
|
||||
|
@ -847,3 +847,8 @@ void WindowManager::notifyInputActionBound ()
|
|||
mSettingsWindow->updateControlsBox ();
|
||||
allowMouse();
|
||||
}
|
||||
|
||||
void WindowManager::showCrosshair (bool show)
|
||||
{
|
||||
mHud->setCrosshairVisible (show);
|
||||
}
|
||||
|
|
|
@ -157,6 +157,8 @@ namespace MWGui
|
|||
virtual void unsetSelectedSpell();
|
||||
virtual void unsetSelectedWeapon();
|
||||
|
||||
virtual void showCrosshair(bool show);
|
||||
|
||||
virtual void disallowMouse();
|
||||
virtual void allowMouse();
|
||||
virtual void notifyInputActionBound();
|
||||
|
|
|
@ -176,23 +176,18 @@ namespace MWInput
|
|||
toggleJournal ();
|
||||
break;
|
||||
case A_AutoMove:
|
||||
resetIdleTime();
|
||||
toggleAutoMove ();
|
||||
break;
|
||||
case A_ToggleSneak:
|
||||
/// \todo implement
|
||||
resetIdleTime();
|
||||
break;
|
||||
case A_ToggleWalk:
|
||||
resetIdleTime();
|
||||
toggleWalking ();
|
||||
break;
|
||||
case A_ToggleWeapon:
|
||||
resetIdleTime();
|
||||
toggleWeapon ();
|
||||
break;
|
||||
case A_ToggleSpell:
|
||||
resetIdleTime();
|
||||
toggleSpell ();
|
||||
break;
|
||||
}
|
||||
|
@ -303,6 +298,8 @@ namespace MWInput
|
|||
// Disable mouse look
|
||||
mMouseLookEnabled = false;
|
||||
|
||||
mWindows.showCrosshair (false);
|
||||
|
||||
// Enable GUI events
|
||||
mGuiCursorEnabled = true;
|
||||
}
|
||||
|
@ -311,6 +308,8 @@ namespace MWInput
|
|||
// Enable mouse look
|
||||
mMouseLookEnabled = true;
|
||||
|
||||
mWindows.showCrosshair (false);
|
||||
|
||||
// Disable GUI events
|
||||
mGuiCursorEnabled = false;
|
||||
}
|
||||
|
|
|
@ -116,6 +116,10 @@ namespace MWRender
|
|||
|
||||
void Player::update(float duration)
|
||||
{
|
||||
// only show the crosshair in game mode and in first person mode.
|
||||
MWBase::Environment::get().getWindowManager ()->showCrosshair
|
||||
(!MWBase::Environment::get().getWindowManager ()->isGuiMode () && (mFirstPersonView && !mVanity.enabled && !mPreviewMode));
|
||||
|
||||
if (mAnimation) {
|
||||
mAnimation->runAnimation(duration);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue