From b704519078a41220726bc0c7e240646113cd3670 Mon Sep 17 00:00:00 2001 From: Koncord Date: Sat, 22 Oct 2016 17:06:26 +0800 Subject: [PATCH] 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; };