|
|
|
@ -11,6 +11,7 @@ LocalMapBase::LocalMapBase()
|
|
|
|
|
, mInterior(false)
|
|
|
|
|
, mFogOfWar(true)
|
|
|
|
|
, mLocalMap(NULL)
|
|
|
|
|
, mMapDragAndDrop(false)
|
|
|
|
|
, mPrefix()
|
|
|
|
|
, mChanged(true)
|
|
|
|
|
, mLayout(NULL)
|
|
|
|
@ -18,13 +19,41 @@ LocalMapBase::LocalMapBase()
|
|
|
|
|
, mLastPositionY(0.0f)
|
|
|
|
|
, mLastDirectionX(0.0f)
|
|
|
|
|
, mLastDirectionY(0.0f)
|
|
|
|
|
, mCompass(NULL)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LocalMapBase::init(MyGUI::ScrollView* widget, OEngine::GUI::Layout* layout)
|
|
|
|
|
void LocalMapBase::init(MyGUI::ScrollView* widget, MyGUI::ImageBox* compass, OEngine::GUI::Layout* layout, bool mapDragAndDrop)
|
|
|
|
|
{
|
|
|
|
|
mLocalMap = widget;
|
|
|
|
|
mLayout = layout;
|
|
|
|
|
mMapDragAndDrop = mapDragAndDrop;
|
|
|
|
|
mCompass = compass;
|
|
|
|
|
|
|
|
|
|
// create 3x3 map widgets, 512x512 each, holding a 1024x1024 texture each
|
|
|
|
|
const int widgetSize = 512;
|
|
|
|
|
for (int mx=0; mx<3; ++mx)
|
|
|
|
|
{
|
|
|
|
|
for (int my=0; my<3; ++my)
|
|
|
|
|
{
|
|
|
|
|
MyGUI::ImageBox* map = mLocalMap->createWidget<MyGUI::ImageBox>("ImageBox",
|
|
|
|
|
MyGUI::IntCoord(mx*widgetSize, my*widgetSize, widgetSize, widgetSize),
|
|
|
|
|
MyGUI::Align::Top | MyGUI::Align::Left, "Map_" + boost::lexical_cast<std::string>(mx) + "_" + boost::lexical_cast<std::string>(my));
|
|
|
|
|
|
|
|
|
|
MyGUI::ImageBox* fog = map->createWidget<MyGUI::ImageBox>("ImageBox",
|
|
|
|
|
MyGUI::IntCoord(0, 0, widgetSize, widgetSize),
|
|
|
|
|
MyGUI::Align::Top | MyGUI::Align::Left, "Map_" + boost::lexical_cast<std::string>(mx) + "_" + boost::lexical_cast<std::string>(my) + "_fog");
|
|
|
|
|
|
|
|
|
|
if (!mMapDragAndDrop)
|
|
|
|
|
{
|
|
|
|
|
map->setNeedMouseFocus(false);
|
|
|
|
|
fog->setNeedMouseFocus(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mMapWidgets.push_back(map);
|
|
|
|
|
mFogWidgets.push_back(fog);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LocalMapBase::setCellPrefix(const std::string& prefix)
|
|
|
|
@ -47,10 +76,10 @@ void LocalMapBase::applyFogOfWar()
|
|
|
|
|
{
|
|
|
|
|
std::string name = "Map_" + boost::lexical_cast<std::string>(mx) + "_"
|
|
|
|
|
+ boost::lexical_cast<std::string>(my);
|
|
|
|
|
|
|
|
|
|
std::string image = mPrefix+"_"+ boost::lexical_cast<std::string>(mCurX + (mx-1)) + "_"
|
|
|
|
|
+ boost::lexical_cast<std::string>(mCurY + (mInterior ? (my-1) : -1*(my-1)));
|
|
|
|
|
MyGUI::ImageBox* fog;
|
|
|
|
|
mLayout->getWidget(fog, name+"_fog");
|
|
|
|
|
MyGUI::ImageBox* fog = mFogWidgets[my + 3*mx];
|
|
|
|
|
fog->setImageTexture(mFogOfWar ?
|
|
|
|
|
((MyGUI::RenderManager::getInstance().getTexture(image+"_fog") != 0) ? image+"_fog"
|
|
|
|
|
: "black.png" )
|
|
|
|
@ -66,14 +95,13 @@ void LocalMapBase::setActiveCell(const int x, const int y, bool interior)
|
|
|
|
|
{
|
|
|
|
|
for (int my=0; my<3; ++my)
|
|
|
|
|
{
|
|
|
|
|
std::string name = "Map_" + boost::lexical_cast<std::string>(mx) + "_"
|
|
|
|
|
+ boost::lexical_cast<std::string>(my);
|
|
|
|
|
|
|
|
|
|
std::string image = mPrefix+"_"+ boost::lexical_cast<std::string>(x + (mx-1)) + "_"
|
|
|
|
|
+ boost::lexical_cast<std::string>(y + (interior ? (my-1) : -1*(my-1)));
|
|
|
|
|
|
|
|
|
|
MyGUI::ImageBox* box;
|
|
|
|
|
mLayout->getWidget(box, name);
|
|
|
|
|
std::string name = "Map_" + boost::lexical_cast<std::string>(mx) + "_"
|
|
|
|
|
+ boost::lexical_cast<std::string>(my);
|
|
|
|
|
|
|
|
|
|
MyGUI::ImageBox* box = mMapWidgets[my + 3*mx];
|
|
|
|
|
|
|
|
|
|
if (MyGUI::RenderManager::getInstance().getTexture(image) != 0)
|
|
|
|
|
box->setImageTexture(image);
|
|
|
|
@ -86,6 +114,42 @@ void LocalMapBase::setActiveCell(const int x, const int y, bool interior)
|
|
|
|
|
mCurY = y;
|
|
|
|
|
mChanged = false;
|
|
|
|
|
applyFogOfWar();
|
|
|
|
|
|
|
|
|
|
// set the compass texture again, because MyGUI determines sorting of ImageBox widgets
|
|
|
|
|
// based on the last setImageTexture call
|
|
|
|
|
std::string tex = "textures\\compass.dds";
|
|
|
|
|
mCompass->setImageTexture("");
|
|
|
|
|
mCompass->setImageTexture(tex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LocalMapBase::setPlayerPos(const float x, const float y)
|
|
|
|
|
{
|
|
|
|
|
if (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);
|
|
|
|
|
|
|
|
|
|
mCompass->setPosition(MyGUI::IntPoint(512+x*512-16, 512+y*512-16));
|
|
|
|
|
mLastPositionX = x;
|
|
|
|
|
mLastPositionY = y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LocalMapBase::setPlayerDir(const float x, const float y)
|
|
|
|
|
{
|
|
|
|
|
if (x == mLastDirectionX && y == mLastDirectionY)
|
|
|
|
|
return;
|
|
|
|
|
MyGUI::ISubWidget* main = mCompass->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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------
|
|
|
|
@ -111,7 +175,7 @@ MapWindow::MapWindow(WindowManager& parWindowManager) :
|
|
|
|
|
eventbox->eventMouseDrag += MyGUI::newDelegate(this, &MapWindow::onMouseDrag);
|
|
|
|
|
eventbox->eventMouseButtonPressed += MyGUI::newDelegate(this, &MapWindow::onDragStart);
|
|
|
|
|
|
|
|
|
|
LocalMapBase::init(mLocalMap, this);
|
|
|
|
|
LocalMapBase::init(mLocalMap, mPlayerArrow, this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MapWindow::setCellName(const std::string& cellName)
|
|
|
|
@ -119,33 +183,6 @@ void MapWindow::setCellName(const std::string& cellName)
|
|
|
|
|
setTitle(cellName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|