Started work on the map markers

coverity_scan^2
Koncord 8 years ago
parent 6eae017561
commit 2e81034e53

@ -96,7 +96,7 @@ add_openmw_dir (mwbase
inputmanager windowmanager statemanager
)
add_openmw_dir (mwmp DedicatedPlayer LocalPlayer Networking Main GUIChat GUILogin GUIController)
add_openmw_dir (mwmp DedicatedPlayer LocalPlayer Networking Main GUIChat GUILogin GUIController PlayerMarkerCollection)
# Main executable

@ -15,6 +15,7 @@
#include <components/esm/esmwriter.hpp>
#include <components/settings/settings.hpp>
#include <components/myguiplatform/myguitexture.hpp>
#include <apps/openmw/mwmp/Main.hpp>
#include "../mwbase/windowmanager.hpp"
#include "../mwbase/world.hpp"
@ -176,11 +177,13 @@ namespace MWGui
, mNeedDoorMarkersUpdate(false)
{
mCustomMarkers.eventMarkersChanged += MyGUI::newDelegate(this, &LocalMapBase::updateCustomMarkers);
mwmp::Main::get().getGUIController()->mPlayerMarkers.eventMarkersChanged += MyGUI::newDelegate(this, &LocalMapBase::updatePlayerMarkers);
}
LocalMapBase::~LocalMapBase()
{
mCustomMarkers.eventMarkersChanged -= MyGUI::newDelegate(this, &LocalMapBase::updateCustomMarkers);
mwmp::Main::get().getGUIController()->mPlayerMarkers.eventMarkersChanged -= MyGUI::newDelegate(this, &LocalMapBase::updatePlayerMarkers);
}
void LocalMapBase::init(MyGUI::ScrollView* widget, MyGUI::ImageBox* compass, int mapWidgetSize, int cellDistance)
@ -356,6 +359,20 @@ namespace MWGui
redraw();
}
void LocalMapBase::updatePlayerMarkers()
{
mwmp::Main::get().getGUIController()->updatePlayersMarkers(this);
}
void MapWindow::updatePlayerMarkers()
{
printf("MapWindow::updatePlayerMarkers!!\n");
LocalMapBase::updatePlayerMarkers();
mwmp::Main::get().getGUIController()->updateGlobalMapMarkerTooltips(this);
printf("End of MapWindow::updatePlayerMarkers!!\n");
}
void LocalMapBase::setActiveCell(const int x, const int y, bool interior)
{
if (x==mCurX && y==mCurY && mInterior==interior && !mChanged)

@ -11,6 +11,11 @@
#include <components/esm/custommarkerstate.hpp>
namespace mwmp
{
class GUIController;
}
namespace MWRender
{
class GlobalMap;
@ -65,6 +70,7 @@ namespace MWGui
class LocalMapBase
{
friend class mwmp::GUIController;
public:
LocalMapBase(CustomMarkerCollection& markers, MWRender::LocalMap* localMapRender, bool fogOfWarEnabled = true);
virtual ~LocalMapBase();
@ -135,6 +141,7 @@ namespace MWGui
std::vector<MyGUI::Widget*> mCustomMarkerWidgets;
virtual void updateCustomMarkers();
virtual void updatePlayerMarkers();
void applyFogOfWar();
@ -192,6 +199,7 @@ namespace MWGui
class MapWindow : public MWGui::WindowPinnableBase, public LocalMapBase, public NoDrop
{
friend class mwmp::GUIController;
public:
MapWindow(CustomMarkerCollection& customMarkers, DragAndDrop* drag, MWRender::LocalMap* localMapRender);
virtual ~MapWindow();
@ -217,6 +225,7 @@ namespace MWGui
void onFrame(float dt);
virtual void updateCustomMarkers();
virtual void updatePlayerMarkers();
/// Clear all savegame-specific data
void clear();

@ -4,14 +4,28 @@
#include <SDL_system.h>
#include <MyGUI_InputManager.h>
#include <apps/openmw/mwbase/environment.hpp>
#include <apps/openmw/mwbase/windowmanager.hpp>
#include <apps/openmw/mwbase/inputmanager.hpp>
#include <apps/openmw/mwbase/environment.hpp>
#include <apps/openmw/mwworld/worldimp.hpp>
#include <apps/openmw/mwworld/player.hpp>
#include <apps/openmw/mwworld/cellstore.hpp>
#include <components/openmw-mp/Base/BasePlayer.hpp>
#include <MyGUI_ScrollView.h>
#include <MyGUI_ImageBox.h>
#include <MyGUI_RenderManager.h>
#include <MyGUI_Gui.h>
#include <MyGUI_LanguageManager.h>
#include <MyGUI_InputManager.h>
#include <MyGUI_RotatingSkin.h>
#include <MyGUI_FactoryManager.h>
#include <apps/openmw/mwgui/mapwindow.hpp>
#include <MyGUI_TextIterator.h>
#include "GUIController.hpp"
#include "Main.hpp"
#include "PlayerMarkerCollection.hpp"
mwmp::GUIController::GUIController(): mInputBox(0)
@ -29,6 +43,7 @@ mwmp::GUIController::~GUIController()
void mwmp::GUIController::cleanup()
{
mPlayerMarkers.clear();
if (mChat != nullptr)
delete mChat;
mChat = nullptr;
@ -135,6 +150,15 @@ bool mwmp::GUIController::pressedKey(int key)
printf("mwmp::GUIController::pressedKey.newFocus: %s.\n", newFocus ? newFocus->getName().c_str() : "nil");*/
return true;
}
else if(key == SDLK_RETURN)
{
static bool test = true;
if(test)
{
test = false;
SetMapVisibility(0, true);
}
}
return false;
}
@ -175,4 +199,130 @@ void mwmp::GUIController::WM_UpdateVisible(MWGui::GuiMode mode)
}
}
class MarkerWidget: public MyGUI::Widget
{
MYGUI_RTTI_DERIVED(MarkerWidget)
public:
void setNormalColour(const MyGUI::Colour& colour)
{
mNormalColour = colour;
setColour(colour);
}
void setHoverColour(const MyGUI::Colour& colour)
{
mHoverColour = colour;
}
private:
MyGUI::Colour mNormalColour;
MyGUI::Colour mHoverColour;
void onMouseLostFocus(MyGUI::Widget* _new)
{
setColour(mNormalColour);
}
void onMouseSetFocus(MyGUI::Widget* _old)
{
setColour(mHoverColour);
}
};
void mwmp::GUIController::SetMapVisibility(int pid, bool state)
{
ESM::CustomMarker mEditingMarker;
mEditingMarker.mNote = "TEST";
MWBase::World *world = MWBase::Environment::get().getWorld();
const ESM::Cell *ptrCell = world->getPlayerPtr().getCell()->getCell();
mEditingMarker.mCell = ptrCell->mCellId;
mEditingMarker.mWorldX = world->getPlayerPtr().getRefData().getPosition().pos[0];
mEditingMarker.mWorldY = world->getPlayerPtr().getRefData().getPosition().pos[1];
mEditingMarker.mCell.mWorldspace = ESM::CellId::sDefaultWorldspace;
mPlayerMarkers.addMarker(mEditingMarker, true);
}
void mwmp::GUIController::updatePlayersMarkers(MWGui::LocalMapBase *localMapBase)
{
printf("updatePlayersMarkers!!!\n");
for (std::vector<MyGUI::Widget*>::iterator it = mPlayerMarkerWidgets.begin(); it != mPlayerMarkerWidgets.end(); ++it)
MyGUI::Gui::getInstance().destroyWidget(*it);
mPlayerMarkerWidgets.clear();
for (int dX = -localMapBase->mCellDistance; dX <= localMapBase->mCellDistance; ++dX)
{
for (int dY =-localMapBase->mCellDistance; dY <= localMapBase->mCellDistance; ++dY)
{
ESM::CellId cellId;
cellId.mPaged = !localMapBase->mInterior;
cellId.mWorldspace = (localMapBase->mInterior ? localMapBase->mPrefix : ESM::CellId::sDefaultWorldspace);
cellId.mIndex.mX = localMapBase->mCurX+dX;
cellId.mIndex.mY = localMapBase->mCurY+dY;
PlayerMarkerCollection::RangeType markers = mPlayerMarkers.getMarkers(cellId);
for (PlayerMarkerCollection::ContainerType::const_iterator it = markers.first; it != markers.second; ++it)
{
const ESM::CustomMarker &marker = it->second;
MWGui::LocalMapBase::MarkerUserData markerPos (localMapBase->mLocalMapRender);
MyGUI::IntPoint widgetPos = localMapBase->getMarkerPosition(marker.mWorldX, marker.mWorldY, markerPos);
MyGUI::IntCoord widgetCoord(widgetPos.left - 8, widgetPos.top - 8, 16, 16);
MarkerWidget* markerWidget = localMapBase->mLocalMap->createWidget<MarkerWidget>("CustomMarkerButton",
widgetCoord, MyGUI::Align::Default);
markerWidget->setDepth(0); // Local_MarkerAboveFogLayer
markerWidget->setUserString("ToolTipType", "Layout");
markerWidget->setUserString("ToolTipLayout", "TextToolTipOneLine");
markerWidget->setUserString("Caption_TextOneLine", MyGUI::TextIterator::toTagsString(marker.mNote));
markerWidget->setNormalColour(MyGUI::Colour(0.6f, 0.6f, 0.6f));
markerWidget->setHoverColour(MyGUI::Colour(1.0f, 1.0f, 1.0f));
markerWidget->setUserData(marker);
markerWidget->setNeedMouseFocus(true);
//localMapBase->customMarkerCreated(markerWidget);
mPlayerMarkerWidgets.push_back(markerWidget);
}
}
}
localMapBase->redraw();
}
void mwmp::GUIController::setGlobalMapMarkerTooltip(MWGui::MapWindow *mapWindow, MyGUI::Widget *markerWidget, int x, int y)
{
ESM::CellId cellId;
cellId.mIndex.mX = x;
cellId.mIndex.mY = y;
cellId.mWorldspace = ESM::CellId::sDefaultWorldspace;
cellId.mPaged = true;
PlayerMarkerCollection::RangeType markers = mPlayerMarkers.getMarkers(cellId);
std::vector<std::string> destNotes;
for (PlayerMarkerCollection::ContainerType::const_iterator it = markers.first; it != markers.second; ++it)
destNotes.push_back(it->second.mNote);
if (!destNotes.empty())
{
MWGui::LocalMapBase::MarkerUserData data (NULL);
data.notes = destNotes;
data.caption = markerWidget->getUserString("Caption_TextOneLine");
markerWidget->setUserData(data);
markerWidget->setUserString("ToolTipType", "MapMarker");
}
else
markerWidget->setUserString("ToolTipType", "Layout");
}
void mwmp::GUIController::updateGlobalMapMarkerTooltips(MWGui::MapWindow *mapWindow)
{
std::map<std::pair<int, int>, MyGUI::Widget*>::iterator widgetIt = mapWindow->mGlobalMapMarkers.begin();
for (; widgetIt != mapWindow->mGlobalMapMarkers.end(); ++widgetIt)
{
int x = widgetIt->first.first;
int y = widgetIt->first.second;
MyGUI::Widget* markerWidget = widgetIt->second;
setGlobalMapMarkerTooltip(mapWindow, markerWidget, x, y);
}
}

@ -10,6 +10,13 @@
#include <apps/openmw/mwgui/mode.hpp>
#include <components/openmw-mp/Base/BasePlayer.hpp>
#include "GUIChat.hpp"
#include "PlayerMarkerCollection.hpp"
namespace MWGui
{
class LocalMapBase;
class MapWindow;
}
namespace mwmp
{
@ -36,7 +43,17 @@ namespace mwmp
void update(float dt);
void WM_UpdateVisible(MWGui::GuiMode mode);
void updatePlayersMarkers(MWGui::LocalMapBase *localMapBase);
void updateGlobalMapMarkerTooltips(MWGui::MapWindow *pWindow);
void SetMapVisibility(int pid, bool state);
PlayerMarkerCollection mPlayerMarkers;
private:
void setGlobalMapMarkerTooltip(MWGui::MapWindow *mapWindow ,MyGUI::Widget* markerWidget, int x, int y);
private:
std::vector<MyGUI::Widget*> mPlayerMarkerWidgets;
GUIChat *mChat;
int keySay;
int keyChatMode;

@ -0,0 +1,74 @@
//
// Created by koncord on 30.09.16.
//
#include <stdexcept>
#include "PlayerMarkerCollection.hpp"
using namespace mwmp;
void PlayerMarkerCollection::addMarker(const ESM::CustomMarker &marker, bool triggerEvent)
{
mMarkers.insert(std::make_pair(marker.mCell, marker));
if (triggerEvent)
eventMarkersChanged();
}
void PlayerMarkerCollection::deleteMarker(const ESM::CustomMarker &marker)
{
std::pair<ContainerType::iterator, ContainerType::iterator> range = mMarkers.equal_range(marker.mCell);
for (ContainerType::iterator it = range.first; it != range.second; ++it)
{
if (it->second == marker)
{
mMarkers.erase(it);
eventMarkersChanged();
return;
}
}
throw std::runtime_error("can't find marker to delete");
}
void PlayerMarkerCollection::updateMarker(const ESM::CustomMarker &marker, const std::string &newNote)
{
std::pair<ContainerType::iterator, ContainerType::iterator> range = mMarkers.equal_range(marker.mCell);
for (ContainerType::iterator it = range.first; it != range.second; ++it)
{
if (it->second == marker)
{
it->second.mNote = newNote;
eventMarkersChanged();
return;
}
}
throw std::runtime_error("can't find marker to update");
}
void PlayerMarkerCollection::clear()
{
mMarkers.clear();
eventMarkersChanged();
}
PlayerMarkerCollection::ContainerType::const_iterator PlayerMarkerCollection::begin() const
{
return mMarkers.begin();
}
PlayerMarkerCollection::ContainerType::const_iterator PlayerMarkerCollection::end() const
{
return mMarkers.end();
}
PlayerMarkerCollection::RangeType PlayerMarkerCollection::getMarkers(const ESM::CellId &cellId) const
{
return mMarkers.equal_range(cellId);
}
size_t PlayerMarkerCollection::size() const
{
return mMarkers.size();
}

@ -0,0 +1,47 @@
//
// Created by koncord on 30.09.16.
//
// Copied from MWGui::CustomMarkerCollection
#ifndef OPENMW_PLAYERMARKERCOLLECTION_HPP
#define OPENMW_PLAYERMARKERCOLLECTION_HPP
#include <components/esm/cellid.hpp>
#include <components/esm/custommarkerstate.hpp>
#include <map>
#include <MyGUI_Common.h>
#include <MyGUI_Colour.h>
namespace mwmp
{
class PlayerMarkerCollection
{
public:
void addMarker(const ESM::CustomMarker &marker, bool triggerEvent = true);
void deleteMarker(const ESM::CustomMarker &marker);
void updateMarker(const ESM::CustomMarker &marker, const std::string &newNote);
void clear();
size_t size() const;
typedef std::multimap <ESM::CellId, ESM::CustomMarker> ContainerType;
typedef std::pair <ContainerType::const_iterator, ContainerType::const_iterator> RangeType;
ContainerType::const_iterator begin() const;
ContainerType::const_iterator end() const;
RangeType getMarkers(const ESM::CellId &cellId) const;
typedef MyGUI::delegates::CMultiDelegate0 EventHandle_Void;
EventHandle_Void eventMarkersChanged;
private:
ContainerType mMarkers;
};
}
#endif //OPENMW_PLAYERMARKERCOLLECTION_HPP
Loading…
Cancel
Save