Show dedicated players on minimap

coverity_scan^2
Koncord 8 years ago
parent 14bac1e533
commit b704519078

@ -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)

@ -17,6 +17,7 @@
#include "../mwmechanics/mechanicsmanagerimp.hpp"
#include "../mwworld/cellstore.hpp"
#include "../mwworld/action.hpp"
#include "Main.hpp"
#include <apps/openmw/mwworld/inventorystore.hpp>
#include <boost/algorithm/clamp.hpp>
#include <components/openmw-mp/Log.hpp>
@ -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 <RakNet::RakNetGUID, DedicatedPlayer *>::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();
}

@ -12,6 +12,7 @@
#include <RakNetTypes.h>
#include <components/openmw-mp/Base/BasePlayer.hpp>
#include <components/esm/custommarkerstate.hpp>
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

@ -21,11 +21,13 @@
#include <MyGUI_FactoryManager.h>
#include <apps/openmw/mwgui/mapwindow.hpp>
#include <MyGUI_TextIterator.h>
#include <components/openmw-mp/Log.hpp>
#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<MyGUI::Widget*>::iterator it = localMapBase->mPlayerMarkerWidgets.begin(); it != localMapBase->mPlayerMarkerWidgets.end(); ++it)
std::vector<MyGUI::Widget*>::iterator it = localMapBase->mPlayerMarkerWidgets.begin();
for (; it != localMapBase->mPlayerMarkerWidgets.end(); ++it)
MyGUI::Gui::getInstance().destroyWidget(*it);
localMapBase->mPlayerMarkerWidgets.clear();

@ -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<MyGUI::Widget*> mPlayerMarkerWidgets;
GUIChat *mChat;
int keySay;
int keyChatMode;

@ -71,4 +71,9 @@ PlayerMarkerCollection::RangeType PlayerMarkerCollection::getMarkers(const ESM::
size_t PlayerMarkerCollection::size() const
{
return mMarkers.size();
}
}
bool PlayerMarkerCollection::isExists(const ESM::CustomMarker &marker)
{
return mMarkers.find(marker.mCell) != mMarkers.end();
}

@ -39,6 +39,7 @@ namespace mwmp
typedef MyGUI::delegates::CMultiDelegate0 EventHandle_Void;
EventHandle_Void eventMarkersChanged;
bool isExists(const ESM::CustomMarker &marker);
private:
ContainerType mMarkers;
};

Loading…
Cancel
Save