1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-20 07:23:51 +00:00

Drag&Drop: auto-hide windows that can't be drop targets on mouseover

This commit is contained in:
scrawl 2014-01-26 14:47:01 +01:00
parent 3a5da7e6e8
commit 365ae15532
9 changed files with 77 additions and 16 deletions

View file

@ -373,8 +373,9 @@ namespace MWGui
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
MapWindow::MapWindow(const std::string& cacheDir) MapWindow::MapWindow(DragAndDrop* drag, const std::string& cacheDir)
: MWGui::WindowPinnableBase("openmw_map_window.layout") : WindowPinnableBase("openmw_map_window.layout")
, NoDrop(drag, mMainWidget)
, mGlobal(false) , mGlobal(false)
, mGlobalMap(0) , mGlobalMap(0)
, mGlobalMapRender(0) , mGlobalMapRender(0)

View file

@ -75,10 +75,10 @@ namespace MWGui
float mLastDirectionY; float mLastDirectionY;
}; };
class MapWindow : public MWGui::WindowPinnableBase, public LocalMapBase class MapWindow : public MWGui::WindowPinnableBase, public LocalMapBase, public NoDrop
{ {
public: public:
MapWindow(const std::string& cacheDir); MapWindow(DragAndDrop* drag, const std::string& cacheDir);
virtual ~MapWindow(); virtual ~MapWindow();
void setCellName(const std::string& cellName); void setCellName(const std::string& cellName);
@ -92,6 +92,8 @@ namespace MWGui
virtual void open(); virtual void open();
void onFrame(float dt) { NoDrop::onFrame(dt); }
private: private:
void onDragStart(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id); void onDragStart(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id);
void onMouseDrag(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id); void onMouseDrag(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id);

View file

@ -42,8 +42,9 @@ namespace
namespace MWGui namespace MWGui
{ {
SpellWindow::SpellWindow() SpellWindow::SpellWindow(DragAndDrop* drag)
: WindowPinnableBase("openmw_spell_window.layout") : WindowPinnableBase("openmw_spell_window.layout")
, NoDrop(drag, mMainWidget)
, mHeight(0) , mHeight(0)
, mWidth(0) , mWidth(0)
{ {

View file

@ -7,14 +7,16 @@ namespace MWGui
{ {
class SpellIcons; class SpellIcons;
class SpellWindow : public WindowPinnableBase class SpellWindow : public WindowPinnableBase, public NoDrop
{ {
public: public:
SpellWindow(); SpellWindow(DragAndDrop* drag);
virtual ~SpellWindow(); virtual ~SpellWindow();
void updateSpells(); void updateSpells();
void onFrame(float dt) { NoDrop::onFrame(dt); }
protected: protected:
MyGUI::ScrollView* mSpellView; MyGUI::ScrollView* mSpellView;
MyGUI::Widget* mEffectBox; MyGUI::Widget* mEffectBox;

View file

@ -18,8 +18,9 @@ namespace MWGui
const int StatsWindow::sLineHeight = 18; const int StatsWindow::sLineHeight = 18;
StatsWindow::StatsWindow () StatsWindow::StatsWindow (DragAndDrop* drag)
: WindowPinnableBase("openmw_stats_window.layout") : WindowPinnableBase("openmw_stats_window.layout")
, NoDrop(drag, mMainWidget)
, mSkillView(NULL) , mSkillView(NULL)
, mMajorSkills() , mMajorSkills()
, mMinorSkills() , mMinorSkills()
@ -219,11 +220,13 @@ namespace MWGui
updateSkillArea(); updateSkillArea();
} }
void StatsWindow::onFrame () void StatsWindow::onFrame (float dt)
{ {
if (!mMainWidget->getVisible()) if (!mMainWidget->getVisible())
return; return;
NoDrop::onFrame(dt);
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
const MWMechanics::NpcStats &PCstats = MWWorld::Class::get(player).getNpcStats(player); const MWMechanics::NpcStats &PCstats = MWWorld::Class::get(player).getNpcStats(player);

View file

@ -10,17 +10,17 @@ namespace MWGui
{ {
class WindowManager; class WindowManager;
class StatsWindow : public WindowPinnableBase class StatsWindow : public WindowPinnableBase, public NoDrop
{ {
public: public:
typedef std::map<std::string, int> FactionList; typedef std::map<std::string, int> FactionList;
typedef std::vector<int> SkillList; typedef std::vector<int> SkillList;
StatsWindow(); StatsWindow(DragAndDrop* drag);
/// automatically updates all the data in the stats window, but only if it has changed. /// automatically updates all the data in the stats window, but only if it has changed.
void onFrame(); void onFrame(float dt);
void setBar(const std::string& name, const std::string& tname, int val, int max); void setBar(const std::string& name, const std::string& tname, int val, int max);
void setPlayerName(const std::string& playerName); void setPlayerName(const std::string& playerName);

View file

@ -1,6 +1,7 @@
#include "windowbase.hpp" #include "windowbase.hpp"
#include "../mwbase/windowmanager.hpp" #include "../mwbase/windowmanager.hpp"
#include "container.hpp"
using namespace MWGui; using namespace MWGui;
@ -50,3 +51,36 @@ void WindowModal::close()
{ {
MyGUI::InputManager::getInstance ().removeWidgetModal (mMainWidget); MyGUI::InputManager::getInstance ().removeWidgetModal (mMainWidget);
} }
NoDrop::NoDrop(DragAndDrop *drag, MyGUI::Widget *widget)
: mDrag(drag), mWidget(widget), mTransparent(false)
{
}
void NoDrop::onFrame(float dt)
{
MyGUI::IntPoint mousePos = MyGUI::InputManager::getInstance().getMousePosition();
if (mDrag->mIsOnDragAndDrop)
{
MyGUI::Widget* focus = MyGUI::InputManager::getInstance().getMouseFocusWidget();
while (focus && focus != mWidget)
focus = focus->getParent();
if (focus == mWidget)
mTransparent = true;
}
if (!mWidget->getAbsoluteCoord().inside(mousePos))
mTransparent = false;
if (mTransparent)
{
mWidget->setNeedMouseFocus(false); // Allow click-through
mWidget->setAlpha(std::max(0.13f, mWidget->getAlpha() - dt*5));
}
else
{
mWidget->setNeedMouseFocus(true);
mWidget->setAlpha(std::min(1.0f, mWidget->getAlpha() + dt*5));
}
}

View file

@ -11,6 +11,7 @@ namespace MWBase
namespace MWGui namespace MWGui
{ {
class WindowManager; class WindowManager;
class DragAndDrop;
class WindowBase: public OEngine::GUI::Layout class WindowBase: public OEngine::GUI::Layout
{ {
@ -42,6 +43,21 @@ namespace MWGui
virtual void open(); virtual void open();
virtual void close(); virtual void close();
}; };
/// A window that cannot be the target of a drag&drop action.
/// When hovered with a drag item, the window will become transparent and allow click-through.
class NoDrop
{
public:
NoDrop(DragAndDrop* drag, MyGUI::Widget* widget);
void onFrame(float dt);
private:
MyGUI::Widget* mWidget;
DragAndDrop* mDrag;
bool mTransparent;
};
} }
#endif #endif

View file

@ -200,9 +200,9 @@ namespace MWGui
mRecharge = new Recharge(); mRecharge = new Recharge();
mMenu = new MainMenu(w,h); mMenu = new MainMenu(w,h);
mMap = new MapWindow(""); mMap = new MapWindow(mDragAndDrop, "");
trackWindow(mMap, "map"); trackWindow(mMap, "map");
mStatsWindow = new StatsWindow(); mStatsWindow = new StatsWindow(mDragAndDrop);
trackWindow(mStatsWindow, "stats"); trackWindow(mStatsWindow, "stats");
mConsole = new Console(w,h, mConsoleOnlyScripts); mConsole = new Console(w,h, mConsoleOnlyScripts);
trackWindow(mConsole, "console"); trackWindow(mConsole, "console");
@ -227,7 +227,7 @@ namespace MWGui
mConfirmationDialog = new ConfirmationDialog(); mConfirmationDialog = new ConfirmationDialog();
mAlchemyWindow = new AlchemyWindow(); mAlchemyWindow = new AlchemyWindow();
trackWindow(mAlchemyWindow, "alchemy"); trackWindow(mAlchemyWindow, "alchemy");
mSpellWindow = new SpellWindow(); mSpellWindow = new SpellWindow(mDragAndDrop);
trackWindow(mSpellWindow, "spells"); trackWindow(mSpellWindow, "spells");
mQuickKeysMenu = new QuickKeysMenu(); mQuickKeysMenu = new QuickKeysMenu();
mLevelupDialog = new LevelupDialog(); mLevelupDialog = new LevelupDialog();
@ -709,7 +709,9 @@ namespace MWGui
mInventoryWindow->onFrame(); mInventoryWindow->onFrame();
mStatsWindow->onFrame(); mStatsWindow->onFrame(frameDuration);
mMap->onFrame(frameDuration);
mSpellWindow->onFrame(frameDuration);
mWaitDialog->onFrame(frameDuration); mWaitDialog->onFrame(frameDuration);