forked from teamnwah/openmw-tes3coop
Fix behaviour of the MapWindow
The map now will track player's position/rotation when pinned, and will not update if position/rotation didn't change since last frame.
This commit is contained in:
parent
911ca4be89
commit
91a377df86
4 changed files with 23 additions and 16 deletions
|
@ -15,7 +15,10 @@ 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),
|
||||||
mVisible(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");
|
||||||
|
@ -39,12 +42,6 @@ MapWindow::MapWindow(WindowManager& parWindowManager) :
|
||||||
LocalMapBase::init(mLocalMap, this);
|
LocalMapBase::init(mLocalMap, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWindow::setVisible(bool b)
|
|
||||||
{
|
|
||||||
WindowPinnableBase::setVisible(b);
|
|
||||||
mVisible = b;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MapWindow::setCellName(const std::string& cellName)
|
void MapWindow::setCellName(const std::string& cellName)
|
||||||
{
|
{
|
||||||
static_cast<MyGUI::Window*>(mMainWidget)->setCaption(cellName);
|
static_cast<MyGUI::Window*>(mMainWidget)->setCaption(cellName);
|
||||||
|
@ -53,7 +50,7 @@ void MapWindow::setCellName(const std::string& cellName)
|
||||||
|
|
||||||
void MapWindow::setPlayerPos(const float x, const float y)
|
void MapWindow::setPlayerPos(const float x, const float y)
|
||||||
{
|
{
|
||||||
if (mGlobal || mVisible) return;
|
if (mGlobal || !mVisible || (x == mLastPositionX && y == mLastPositionY)) return;
|
||||||
MyGUI::IntSize size = mLocalMap->getCanvasSize();
|
MyGUI::IntSize size = mLocalMap->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 = mLocalMap->getCoord();
|
MyGUI::IntCoord viewsize = mLocalMap->getCoord();
|
||||||
|
@ -61,16 +58,21 @@ void MapWindow::setPlayerPos(const float x, const float y)
|
||||||
mLocalMap->setViewOffset(pos);
|
mLocalMap->setViewOffset(pos);
|
||||||
|
|
||||||
mPlayerArrow->setPosition(MyGUI::IntPoint(x*512-16, y*512-16));
|
mPlayerArrow->setPosition(MyGUI::IntPoint(x*512-16, y*512-16));
|
||||||
|
mLastPositionX = x;
|
||||||
|
mLastPositionY = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWindow::setPlayerDir(const float x, const float y)
|
void MapWindow::setPlayerDir(const float x, const float y)
|
||||||
{
|
{
|
||||||
if (!mVisible) return;
|
if (!mVisible || (x == mLastDirectionX && y == mLastDirectionY)) return;
|
||||||
MyGUI::ISubWidget* main = mPlayerArrow->getSubWidgetMain();
|
MyGUI::ISubWidget* main = mPlayerArrow->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);
|
||||||
|
|
||||||
|
mLastDirectionX = x;
|
||||||
|
mLastDirectionY = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWindow::onDragStart(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id)
|
void MapWindow::onDragStart(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id)
|
||||||
|
|
|
@ -12,7 +12,6 @@ namespace MWGui
|
||||||
MapWindow(WindowManager& parWindowManager);
|
MapWindow(WindowManager& parWindowManager);
|
||||||
virtual ~MapWindow(){}
|
virtual ~MapWindow(){}
|
||||||
|
|
||||||
void setVisible(bool b);
|
|
||||||
void setPlayerPos(const float x, const float y);
|
void setPlayerPos(const float x, const float y);
|
||||||
void setPlayerDir(const float x, const float y);
|
void setPlayerDir(const float x, const float y);
|
||||||
void setCellName(const std::string& cellName);
|
void setCellName(const std::string& cellName);
|
||||||
|
@ -26,8 +25,11 @@ namespace MWGui
|
||||||
MyGUI::ImageBox* mPlayerArrow;
|
MyGUI::ImageBox* mPlayerArrow;
|
||||||
MyGUI::Button* mButton;
|
MyGUI::Button* mButton;
|
||||||
MyGUI::IntPoint mLastDragPos;
|
MyGUI::IntPoint mLastDragPos;
|
||||||
bool mVisible;
|
|
||||||
bool mGlobal;
|
bool mGlobal;
|
||||||
|
float mLastPositionX;
|
||||||
|
float mLastPositionY;
|
||||||
|
float mLastDirectionX;
|
||||||
|
float mLastDirectionY;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
using namespace MWGui;
|
using namespace MWGui;
|
||||||
|
|
||||||
WindowPinnableBase::WindowPinnableBase(const std::string& parLayout, WindowManager& parWindowManager)
|
WindowPinnableBase::WindowPinnableBase(const std::string& parLayout, WindowManager& parWindowManager)
|
||||||
: WindowBase(parLayout, parWindowManager), mIsPinned(false)
|
: WindowBase(parLayout, parWindowManager), mPinned(false), mVisible(false)
|
||||||
{
|
{
|
||||||
MyGUI::WindowPtr t = static_cast<MyGUI::WindowPtr>(mMainWidget);
|
MyGUI::WindowPtr t = static_cast<MyGUI::WindowPtr>(mMainWidget);
|
||||||
t->eventWindowButtonPressed += MyGUI::newDelegate(this, &WindowPinnableBase::onWindowButtonPressed);
|
t->eventWindowButtonPressed += MyGUI::newDelegate(this, &WindowPinnableBase::onWindowButtonPressed);
|
||||||
|
@ -13,17 +13,18 @@ WindowPinnableBase::WindowPinnableBase(const std::string& parLayout, WindowManag
|
||||||
void WindowPinnableBase::setVisible(bool b)
|
void WindowPinnableBase::setVisible(bool b)
|
||||||
{
|
{
|
||||||
// Pinned windows can not be hidden
|
// Pinned windows can not be hidden
|
||||||
if (mIsPinned && !b)
|
if (mPinned && !b)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
WindowBase::setVisible(b);
|
WindowBase::setVisible(b);
|
||||||
|
mVisible = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowPinnableBase::onWindowButtonPressed(MyGUI::Window* sender, const std::string& eventName)
|
void WindowPinnableBase::onWindowButtonPressed(MyGUI::Window* sender, const std::string& eventName)
|
||||||
{
|
{
|
||||||
if ("PinToggle" == eventName)
|
if ("PinToggle" == eventName)
|
||||||
{
|
{
|
||||||
mIsPinned = !mIsPinned;
|
mPinned = !mPinned;
|
||||||
}
|
}
|
||||||
|
|
||||||
eventDone(this);
|
eventDone(this);
|
||||||
|
|
|
@ -16,7 +16,9 @@ namespace MWGui
|
||||||
private:
|
private:
|
||||||
void onWindowButtonPressed(MyGUI::Window* sender, const std::string& eventName);
|
void onWindowButtonPressed(MyGUI::Window* sender, const std::string& eventName);
|
||||||
|
|
||||||
bool mIsPinned;
|
protected:
|
||||||
|
bool mPinned;
|
||||||
|
bool mVisible;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue