From 2e81034e534b85a18377cdd4b9ff27fac6f8e442 Mon Sep 17 00:00:00 2001 From: Koncord Date: Fri, 7 Oct 2016 13:17:19 +0800 Subject: [PATCH 1/4] Started work on the map markers --- apps/openmw/CMakeLists.txt | 2 +- apps/openmw/mwgui/mapwindow.cpp | 17 +++ apps/openmw/mwgui/mapwindow.hpp | 9 ++ apps/openmw/mwmp/GUIController.cpp | 152 +++++++++++++++++++- apps/openmw/mwmp/GUIController.hpp | 17 +++ apps/openmw/mwmp/PlayerMarkerCollection.cpp | 74 ++++++++++ apps/openmw/mwmp/PlayerMarkerCollection.hpp | 47 ++++++ 7 files changed, 316 insertions(+), 2 deletions(-) create mode 100644 apps/openmw/mwmp/PlayerMarkerCollection.cpp create mode 100644 apps/openmw/mwmp/PlayerMarkerCollection.hpp 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 From 07acd7a721c367bb8538b529faf5c0b7331f92f1 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sun, 9 Oct 2016 10:29:30 +0300 Subject: [PATCH 2/4] Make player markers work in interiors and make them easier to test --- apps/openmw/mwmp/GUIController.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwmp/GUIController.cpp b/apps/openmw/mwmp/GUIController.cpp index 0d93a2e37..2ee4c91c2 100644 --- a/apps/openmw/mwmp/GUIController.cpp +++ b/apps/openmw/mwmp/GUIController.cpp @@ -150,14 +150,17 @@ 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) + else if(key == SDLK_BACKSPACE) { + /* static bool test = true; if(test) { test = false; SetMapVisibility(0, true); } + */ + SetMapVisibility(0, true); } return false; } @@ -242,7 +245,18 @@ void mwmp::GUIController::SetMapVisibility(int pid, bool state) mEditingMarker.mWorldX = world->getPlayerPtr().getRefData().getPosition().pos[0]; mEditingMarker.mWorldY = world->getPlayerPtr().getRefData().getPosition().pos[1]; - mEditingMarker.mCell.mWorldspace = ESM::CellId::sDefaultWorldspace; + + mEditingMarker.mCell.mPaged = ptrCell->isExterior(); + + if (!ptrCell->isExterior()) + mEditingMarker.mCell.mWorldspace = ptrCell->mName; + else + { + mEditingMarker.mCell.mWorldspace = ESM::CellId::sDefaultWorldspace; + mEditingMarker.mCell.mIndex.mX = ptrCell->getGridX(); + mEditingMarker.mCell.mIndex.mY = ptrCell->getGridY(); + } + mPlayerMarkers.addMarker(mEditingMarker, true); } From 14bac1e53338aaa522d624671fc3fd3d954939c3 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sun, 9 Oct 2016 13:41:00 +0300 Subject: [PATCH 3/4] Make player markers appear on inventory map --- apps/openmw/mwgui/mapwindow.hpp | 1 + apps/openmw/mwmp/GUIController.cpp | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwgui/mapwindow.hpp b/apps/openmw/mwgui/mapwindow.hpp index bdb6ee00c..79684217e 100644 --- a/apps/openmw/mwgui/mapwindow.hpp +++ b/apps/openmw/mwgui/mapwindow.hpp @@ -139,6 +139,7 @@ namespace MWGui std::vector mDoorMarkerWidgets; std::vector mMagicMarkerWidgets; std::vector mCustomMarkerWidgets; + std::vector mPlayerMarkerWidgets; virtual void updateCustomMarkers(); virtual void updatePlayerMarkers(); diff --git a/apps/openmw/mwmp/GUIController.cpp b/apps/openmw/mwmp/GUIController.cpp index 2ee4c91c2..84561d307 100644 --- a/apps/openmw/mwmp/GUIController.cpp +++ b/apps/openmw/mwmp/GUIController.cpp @@ -263,9 +263,10 @@ void mwmp::GUIController::SetMapVisibility(int pid, bool state) void mwmp::GUIController::updatePlayersMarkers(MWGui::LocalMapBase *localMapBase) { printf("updatePlayersMarkers!!!\n"); - for (std::vector::iterator it = mPlayerMarkerWidgets.begin(); it != mPlayerMarkerWidgets.end(); ++it) + for (std::vector::iterator it = localMapBase->mPlayerMarkerWidgets.begin(); it != localMapBase->mPlayerMarkerWidgets.end(); ++it) + MyGUI::Gui::getInstance().destroyWidget(*it); - mPlayerMarkerWidgets.clear(); + localMapBase->mPlayerMarkerWidgets.clear(); for (int dX = -localMapBase->mCellDistance; dX <= localMapBase->mCellDistance; ++dX) { @@ -288,6 +289,7 @@ void mwmp::GUIController::updatePlayersMarkers(MWGui::LocalMapBase *localMapBase 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"); @@ -297,7 +299,7 @@ void mwmp::GUIController::updatePlayersMarkers(MWGui::LocalMapBase *localMapBase markerWidget->setUserData(marker); markerWidget->setNeedMouseFocus(true); //localMapBase->customMarkerCreated(markerWidget); - mPlayerMarkerWidgets.push_back(markerWidget); + localMapBase->mPlayerMarkerWidgets.push_back(markerWidget); } } } From b704519078a41220726bc0c7e240646113cd3670 Mon Sep 17 00:00:00 2001 From: Koncord Date: Sat, 22 Oct 2016 17:06:26 +0800 Subject: [PATCH 4/4] Show dedicated players on minimap --- apps/openmw/mwgui/mapwindow.cpp | 2 - apps/openmw/mwmp/DedicatedPlayer.cpp | 44 +++++++++++++++++ apps/openmw/mwmp/DedicatedPlayer.hpp | 7 +++ apps/openmw/mwmp/GUIController.cpp | 54 ++++++++------------- apps/openmw/mwmp/GUIController.hpp | 3 +- apps/openmw/mwmp/PlayerMarkerCollection.cpp | 7 ++- apps/openmw/mwmp/PlayerMarkerCollection.hpp | 1 + 7 files changed, 79 insertions(+), 39 deletions(-) diff --git a/apps/openmw/mwgui/mapwindow.cpp b/apps/openmw/mwgui/mapwindow.cpp index ab568eee4..f091e2961 100644 --- a/apps/openmw/mwgui/mapwindow.cpp +++ b/apps/openmw/mwgui/mapwindow.cpp @@ -366,11 +366,9 @@ namespace MWGui 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) diff --git a/apps/openmw/mwmp/DedicatedPlayer.cpp b/apps/openmw/mwmp/DedicatedPlayer.cpp index 271b556ae..c8bca3777 100644 --- a/apps/openmw/mwmp/DedicatedPlayer.cpp +++ b/apps/openmw/mwmp/DedicatedPlayer.cpp @@ -17,6 +17,7 @@ #include "../mwmechanics/mechanicsmanagerimp.hpp" #include "../mwworld/cellstore.hpp" #include "../mwworld/action.hpp" +#include "Main.hpp" #include #include #include @@ -107,6 +108,10 @@ void Players::CreatePlayer(RakNet::RakNetGUID id) dedicPlayer->state = 2; world->enable(players[id]->ptr); + + ESM::CustomMarker mEditingMarker = Main::get().getGUIController()->CreateMarker(id); + dedicPlayer->marker = mEditingMarker; + dedicPlayer->markerEnabled = true; } @@ -211,6 +216,8 @@ void DedicatedPlayer::Move(float dt) void Players::Update(float dt) { + static float timer = 0; + timer += dt; for (std::map ::iterator it = players.begin(); it != players.end(); it++) { DedicatedPlayer *pl = it->second; @@ -251,7 +258,12 @@ void Players::Update(float dt) ptrNpcStats->setBaseDisposition(255); pl->Move(dt); pl->UpdateDrawState(); + + if (timer >= 0.2) // call every 200 msec + pl->updateMarker(); } + if (timer >= 0.2) + timer = 0; } void DedicatedPlayer::UpdatePtr(MWWorld::Ptr newPtr) @@ -450,3 +462,35 @@ void DedicatedPlayer::updateCell() ptr.getBase()->canChangeCell = true; UpdatePtr(world->moveObject(ptr, cellStore, pos.pos[0], pos.pos[1], pos.pos[2])); } + + +void DedicatedPlayer::updateMarker() +{ + if (!markerEnabled) + return; + GUIController *gui = Main::get().getGUIController(); + if (gui->mPlayerMarkers.isExists(marker)) + { + gui->mPlayerMarkers.deleteMarker(marker); + marker = gui->CreateMarker(guid); + gui->mPlayerMarkers.addMarker(marker); + } + else + gui->mPlayerMarkers.addMarker(marker, true); +} + +void DedicatedPlayer::removeMarker() +{ + if (!markerEnabled) + return; + markerEnabled = false; + Main::get().getGUIController()->mPlayerMarkers.deleteMarker(marker); +} + +void DedicatedPlayer::enableMarker(bool enable) +{ + if (enable) + updateMarker(); + else + removeMarker(); +} diff --git a/apps/openmw/mwmp/DedicatedPlayer.hpp b/apps/openmw/mwmp/DedicatedPlayer.hpp index 69ffeba3e..dfcbb5f97 100644 --- a/apps/openmw/mwmp/DedicatedPlayer.hpp +++ b/apps/openmw/mwmp/DedicatedPlayer.hpp @@ -12,6 +12,7 @@ #include #include +#include namespace mwmp @@ -46,6 +47,9 @@ namespace mwmp void updateCell(); + void updateMarker(); + void removeMarker(); + void enableMarker(bool enable); private: DedicatedPlayer(RakNet::RakNetGUID guid); virtual ~DedicatedPlayer(); @@ -55,6 +59,9 @@ namespace mwmp MWWorld::ManualRef* reference; MWWorld::Ptr ptr; + + ESM::CustomMarker marker; + bool markerEnabled; }; } #endif //OPENMW_PLAYER_HPP diff --git a/apps/openmw/mwmp/GUIController.cpp b/apps/openmw/mwmp/GUIController.cpp index 84561d307..6dc5858d5 100644 --- a/apps/openmw/mwmp/GUIController.cpp +++ b/apps/openmw/mwmp/GUIController.cpp @@ -21,11 +21,13 @@ #include #include #include +#include #include "GUIController.hpp" #include "Main.hpp" #include "PlayerMarkerCollection.hpp" +#include "DedicatedPlayer.hpp" mwmp::GUIController::GUIController(): mInputBox(0) @@ -143,25 +145,9 @@ bool mwmp::GUIController::pressedKey(int key) } else if (key == keySay) { - //MyGUI::Widget *oldFocus = MyGUI::InputManager::getInstance().getKeyFocusWidget(); mChat->PressedSay(); - /*MyGUI::Widget *newFocus = MyGUI::InputManager::getInstance().getKeyFocusWidget(); - printf("mwmp::GUIController::pressedKey. oldFocus: %s.\n", oldFocus ? oldFocus->getName().c_str() : "nil"); - printf("mwmp::GUIController::pressedKey.newFocus: %s.\n", newFocus ? newFocus->getName().c_str() : "nil");*/ return true; } - else if(key == SDLK_BACKSPACE) - { - /* - static bool test = true; - if(test) - { - test = false; - SetMapVisibility(0, true); - } - */ - SetMapVisibility(0, true); - } return false; } @@ -233,38 +219,38 @@ private: } }; - -void mwmp::GUIController::SetMapVisibility(int pid, bool state) +ESM::CustomMarker mwmp::GUIController::CreateMarker(const RakNet::RakNetGUID &guid) { + DedicatedPlayer *player = Players::GetPlayer(guid); ESM::CustomMarker mEditingMarker; - mEditingMarker.mNote = "TEST"; - MWBase::World *world = MWBase::Environment::get().getWorld(); - const ESM::Cell *ptrCell = world->getPlayerPtr().getCell()->getCell(); + if (!player) + { + LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Unknown player guid: %lu", guid.g); + return mEditingMarker; + } - mEditingMarker.mCell = ptrCell->mCellId; + mEditingMarker.mNote = player->Npc()->mName; - mEditingMarker.mWorldX = world->getPlayerPtr().getRefData().getPosition().pos[0]; - mEditingMarker.mWorldY = world->getPlayerPtr().getRefData().getPosition().pos[1]; + const ESM::Cell *ptrCell = player->GetCell(); - mEditingMarker.mCell.mPaged = ptrCell->isExterior(); + mEditingMarker.mCell = player->GetCell()->mCellId; + mEditingMarker.mWorldX = player->Position()->pos[0]; + mEditingMarker.mWorldY = player->Position()->pos[1]; + + mEditingMarker.mCell.mPaged = ptrCell->isExterior(); if (!ptrCell->isExterior()) mEditingMarker.mCell.mWorldspace = ptrCell->mName; else - { mEditingMarker.mCell.mWorldspace = ESM::CellId::sDefaultWorldspace; - mEditingMarker.mCell.mIndex.mX = ptrCell->getGridX(); - mEditingMarker.mCell.mIndex.mY = ptrCell->getGridY(); - } - - mPlayerMarkers.addMarker(mEditingMarker, true); + return mEditingMarker; } + void mwmp::GUIController::updatePlayersMarkers(MWGui::LocalMapBase *localMapBase) { - printf("updatePlayersMarkers!!!\n"); - for (std::vector::iterator it = localMapBase->mPlayerMarkerWidgets.begin(); it != localMapBase->mPlayerMarkerWidgets.end(); ++it) - + std::vector::iterator it = localMapBase->mPlayerMarkerWidgets.begin(); + for (; it != localMapBase->mPlayerMarkerWidgets.end(); ++it) MyGUI::Gui::getInstance().destroyWidget(*it); localMapBase->mPlayerMarkerWidgets.clear(); diff --git a/apps/openmw/mwmp/GUIController.hpp b/apps/openmw/mwmp/GUIController.hpp index fee3b43af..c09a918f9 100644 --- a/apps/openmw/mwmp/GUIController.hpp +++ b/apps/openmw/mwmp/GUIController.hpp @@ -47,13 +47,12 @@ namespace mwmp void updatePlayersMarkers(MWGui::LocalMapBase *localMapBase); void updateGlobalMapMarkerTooltips(MWGui::MapWindow *pWindow); - void SetMapVisibility(int pid, bool state); + ESM::CustomMarker CreateMarker(const RakNet::RakNetGUID &guid); 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 index c92d31cec..d6c670d9e 100644 --- a/apps/openmw/mwmp/PlayerMarkerCollection.cpp +++ b/apps/openmw/mwmp/PlayerMarkerCollection.cpp @@ -71,4 +71,9 @@ PlayerMarkerCollection::RangeType PlayerMarkerCollection::getMarkers(const ESM:: size_t PlayerMarkerCollection::size() const { return mMarkers.size(); -} \ No newline at end of file +} + +bool PlayerMarkerCollection::isExists(const ESM::CustomMarker &marker) +{ + return mMarkers.find(marker.mCell) != mMarkers.end(); +} diff --git a/apps/openmw/mwmp/PlayerMarkerCollection.hpp b/apps/openmw/mwmp/PlayerMarkerCollection.hpp index 2358e0553..add80cbb9 100644 --- a/apps/openmw/mwmp/PlayerMarkerCollection.hpp +++ b/apps/openmw/mwmp/PlayerMarkerCollection.hpp @@ -39,6 +39,7 @@ namespace mwmp typedef MyGUI::delegates::CMultiDelegate0 EventHandle_Void; EventHandle_Void eventMarkersChanged; + bool isExists(const ESM::CustomMarker &marker); private: ContainerType mMarkers; };