forked from teamnwah/openmw-tes3coop
Merge branch 'master' into water
commit
044d649edd
@ -0,0 +1,106 @@
|
|||||||
|
#include "map_window.hpp"
|
||||||
|
#include "window_manager.hpp"
|
||||||
|
/*
|
||||||
|
#include "../mwmechanics/mechanicsmanager.hpp"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
|
#undef min
|
||||||
|
#undef max
|
||||||
|
*/
|
||||||
|
using namespace MWGui;
|
||||||
|
|
||||||
|
MapWindow::MapWindow(WindowManager& parWindowManager) :
|
||||||
|
MWGui::WindowPinnableBase("openmw_map_window_layout.xml", parWindowManager),
|
||||||
|
mGlobal(false)
|
||||||
|
{
|
||||||
|
setCoord(500,0,320,300);
|
||||||
|
setText("WorldButton", "World");
|
||||||
|
setImage("Compass", "textures\\compass.dds");
|
||||||
|
|
||||||
|
// Obviously you should override this later on
|
||||||
|
setCellName("No Cell Loaded");
|
||||||
|
|
||||||
|
getWidget(mLocalMap, "LocalMap");
|
||||||
|
getWidget(mGlobalMap, "GlobalMap");
|
||||||
|
getWidget(mPlayerArrow, "Compass");
|
||||||
|
|
||||||
|
getWidget(mButton, "WorldButton");
|
||||||
|
mButton->eventMouseButtonClick += MyGUI::newDelegate(this, &MapWindow::onWorldButtonClicked);
|
||||||
|
|
||||||
|
MyGUI::Button* eventbox;
|
||||||
|
getWidget(eventbox, "EventBox");
|
||||||
|
eventbox->eventMouseDrag += MyGUI::newDelegate(this, &MapWindow::onMouseDrag);
|
||||||
|
eventbox->eventMouseButtonPressed += MyGUI::newDelegate(this, &MapWindow::onDragStart);
|
||||||
|
|
||||||
|
LocalMapBase::init(mLocalMap, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapWindow::setCellName(const std::string& cellName)
|
||||||
|
{
|
||||||
|
static_cast<MyGUI::Window*>(mMainWidget)->setCaption(cellName);
|
||||||
|
adjustWindowCaption();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapWindow::setPlayerPos(const float x, const float y)
|
||||||
|
{
|
||||||
|
if (mGlobal || !mVisible || (x == mLastPositionX && y == mLastPositionY)) return;
|
||||||
|
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::IntCoord viewsize = mLocalMap->getCoord();
|
||||||
|
MyGUI::IntPoint pos(0.5*viewsize.width - middle.left, 0.5*viewsize.height - middle.top);
|
||||||
|
mLocalMap->setViewOffset(pos);
|
||||||
|
|
||||||
|
mPlayerArrow->setPosition(MyGUI::IntPoint(x*512-16, y*512-16));
|
||||||
|
mLastPositionX = x;
|
||||||
|
mLastPositionY = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapWindow::setPlayerDir(const float x, const float y)
|
||||||
|
{
|
||||||
|
if (!mVisible || (x == mLastDirectionX && y == mLastDirectionY)) return;
|
||||||
|
MyGUI::ISubWidget* main = mPlayerArrow->getSubWidgetMain();
|
||||||
|
MyGUI::RotatingSkin* rotatingSubskin = main->castType<MyGUI::RotatingSkin>();
|
||||||
|
rotatingSubskin->setCenter(MyGUI::IntPoint(16,16));
|
||||||
|
float angle = std::atan2(x,y);
|
||||||
|
rotatingSubskin->setAngle(angle);
|
||||||
|
|
||||||
|
mLastDirectionX = x;
|
||||||
|
mLastDirectionY = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapWindow::onDragStart(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id)
|
||||||
|
{
|
||||||
|
if (_id!=MyGUI::MouseButton::Left) return;
|
||||||
|
if (!mGlobal)
|
||||||
|
mLastDragPos = MyGUI::IntPoint(_left, _top);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapWindow::onMouseDrag(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id)
|
||||||
|
{
|
||||||
|
if (_id!=MyGUI::MouseButton::Left) return;
|
||||||
|
|
||||||
|
if (!mGlobal)
|
||||||
|
{
|
||||||
|
MyGUI::IntPoint diff = MyGUI::IntPoint(_left, _top) - mLastDragPos;
|
||||||
|
mLocalMap->setViewOffset( mLocalMap->getViewOffset() + diff );
|
||||||
|
|
||||||
|
mLastDragPos = MyGUI::IntPoint(_left, _top);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapWindow::onWorldButtonClicked(MyGUI::Widget* _sender)
|
||||||
|
{
|
||||||
|
mGlobal = !mGlobal;
|
||||||
|
mGlobalMap->setVisible(mGlobal);
|
||||||
|
mLocalMap->setVisible(!mGlobal);
|
||||||
|
|
||||||
|
mButton->setCaption( mGlobal ? "Local" : "World" );
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapWindow::onPinToggled()
|
||||||
|
{
|
||||||
|
mWindowManager.setMinimapVisibility(!mPinned);
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
#ifndef MWGUI_MAPWINDOW_H
|
||||||
|
#define MWGUI_MAPWINDOW_H
|
||||||
|
|
||||||
|
#include "layouts.hpp"
|
||||||
|
#include "window_pinnable_base.hpp"
|
||||||
|
|
||||||
|
namespace MWGui
|
||||||
|
{
|
||||||
|
class MapWindow : public MWGui::WindowPinnableBase, public LocalMapBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MapWindow(WindowManager& parWindowManager);
|
||||||
|
virtual ~MapWindow(){}
|
||||||
|
|
||||||
|
void setPlayerPos(const float x, const float y);
|
||||||
|
void setPlayerDir(const float x, const float y);
|
||||||
|
void setCellName(const std::string& cellName);
|
||||||
|
|
||||||
|
private:
|
||||||
|
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 onWorldButtonClicked(MyGUI::Widget* _sender);
|
||||||
|
|
||||||
|
MyGUI::ScrollView* mGlobalMap;
|
||||||
|
MyGUI::ImageBox* mPlayerArrow;
|
||||||
|
MyGUI::Button* mButton;
|
||||||
|
MyGUI::IntPoint mLastDragPos;
|
||||||
|
bool mGlobal;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void onPinToggled();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif
|
@ -0,0 +1,33 @@
|
|||||||
|
#include "window_pinnable_base.hpp"
|
||||||
|
#include "window_manager.hpp"
|
||||||
|
|
||||||
|
using namespace MWGui;
|
||||||
|
|
||||||
|
WindowPinnableBase::WindowPinnableBase(const std::string& parLayout, WindowManager& parWindowManager)
|
||||||
|
: WindowBase(parLayout, parWindowManager), mPinned(false), mVisible(false)
|
||||||
|
{
|
||||||
|
MyGUI::WindowPtr t = static_cast<MyGUI::WindowPtr>(mMainWidget);
|
||||||
|
t->eventWindowButtonPressed += MyGUI::newDelegate(this, &WindowPinnableBase::onWindowButtonPressed);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowPinnableBase::setVisible(bool b)
|
||||||
|
{
|
||||||
|
// Pinned windows can not be hidden
|
||||||
|
if (mPinned && !b)
|
||||||
|
return;
|
||||||
|
|
||||||
|
WindowBase::setVisible(b);
|
||||||
|
mVisible = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowPinnableBase::onWindowButtonPressed(MyGUI::Window* sender, const std::string& eventName)
|
||||||
|
{
|
||||||
|
if ("PinToggle" == eventName)
|
||||||
|
{
|
||||||
|
mPinned = !mPinned;
|
||||||
|
onPinToggled();
|
||||||
|
}
|
||||||
|
|
||||||
|
eventDone(this);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,28 @@
|
|||||||
|
#ifndef MWGUI_WINDOW_PINNABLE_BASE_H
|
||||||
|
#define MWGUI_WINDOW_PINNABLE_BASE_H
|
||||||
|
|
||||||
|
#include "window_base.hpp"
|
||||||
|
|
||||||
|
namespace MWGui
|
||||||
|
{
|
||||||
|
class WindowManager;
|
||||||
|
|
||||||
|
class WindowPinnableBase: public WindowBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
WindowPinnableBase(const std::string& parLayout, WindowManager& parWindowManager);
|
||||||
|
void setVisible(bool b);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void onWindowButtonPressed(MyGUI::Window* sender, const std::string& eventName);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void onPinToggled() = 0;
|
||||||
|
|
||||||
|
bool mPinned;
|
||||||
|
bool mVisible;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue