diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 15950e00e..cf48731c5 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -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 diff --git a/apps/openmw/mwgui/mapwindow.cpp b/apps/openmw/mwgui/mapwindow.cpp index d51af87d9..ab568eee4 100644 --- a/apps/openmw/mwgui/mapwindow.cpp +++ b/apps/openmw/mwgui/mapwindow.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #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) diff --git a/apps/openmw/mwgui/mapwindow.hpp b/apps/openmw/mwgui/mapwindow.hpp index 977773179..bdb6ee00c 100644 --- a/apps/openmw/mwgui/mapwindow.hpp +++ b/apps/openmw/mwgui/mapwindow.hpp @@ -11,6 +11,11 @@ #include +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 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(); diff --git a/apps/openmw/mwmp/GUIController.cpp b/apps/openmw/mwmp/GUIController.cpp index 087f22d8d..0d93a2e37 100644 --- a/apps/openmw/mwmp/GUIController.cpp +++ b/apps/openmw/mwmp/GUIController.cpp @@ -4,14 +4,28 @@ #include #include +#include #include #include -#include +#include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #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::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("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 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, 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); + } +} diff --git a/apps/openmw/mwmp/GUIController.hpp b/apps/openmw/mwmp/GUIController.hpp index fa5ec3ac9..fee3b43af 100644 --- a/apps/openmw/mwmp/GUIController.hpp +++ b/apps/openmw/mwmp/GUIController.hpp @@ -10,6 +10,13 @@ #include #include #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 mPlayerMarkerWidgets; GUIChat *mChat; int keySay; int keyChatMode; diff --git a/apps/openmw/mwmp/PlayerMarkerCollection.cpp b/apps/openmw/mwmp/PlayerMarkerCollection.cpp new file mode 100644 index 000000000..c92d31cec --- /dev/null +++ b/apps/openmw/mwmp/PlayerMarkerCollection.cpp @@ -0,0 +1,74 @@ +// +// Created by koncord on 30.09.16. +// + +#include +#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 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 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(); +} \ No newline at end of file diff --git a/apps/openmw/mwmp/PlayerMarkerCollection.hpp b/apps/openmw/mwmp/PlayerMarkerCollection.hpp new file mode 100644 index 000000000..2358e0553 --- /dev/null +++ b/apps/openmw/mwmp/PlayerMarkerCollection.hpp @@ -0,0 +1,47 @@ +// +// Created by koncord on 30.09.16. +// + +// Copied from MWGui::CustomMarkerCollection + +#ifndef OPENMW_PLAYERMARKERCOLLECTION_HPP +#define OPENMW_PLAYERMARKERCOLLECTION_HPP + +#include +#include +#include +#include +#include + +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 ContainerType; + + typedef std::pair 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