forked from Mirrorlandia_minetest/minetest
Fix hud_change and hud_remove after hud_add (#10997)
This commit is contained in:
parent
1c89a07226
commit
ae1d82c325
@ -415,11 +415,6 @@ public:
|
|||||||
return m_csm_restriction_flags & flag;
|
return m_csm_restriction_flags & flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::unordered_map<u32, u32> &getHUDTranslationMap()
|
|
||||||
{
|
|
||||||
return m_hud_server_to_client;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool joinModChannel(const std::string &channel) override;
|
bool joinModChannel(const std::string &channel) override;
|
||||||
bool leaveModChannel(const std::string &channel) override;
|
bool leaveModChannel(const std::string &channel) override;
|
||||||
bool sendModChannelMessage(const std::string &channel,
|
bool sendModChannelMessage(const std::string &channel,
|
||||||
@ -556,9 +551,6 @@ private:
|
|||||||
// Relation of client id to object id
|
// Relation of client id to object id
|
||||||
std::unordered_map<int, u16> m_sounds_to_objects;
|
std::unordered_map<int, u16> m_sounds_to_objects;
|
||||||
|
|
||||||
// Map server hud ids to client hud ids
|
|
||||||
std::unordered_map<u32, u32> m_hud_server_to_client;
|
|
||||||
|
|
||||||
// Privileges
|
// Privileges
|
||||||
std::unordered_set<std::string> m_privileges;
|
std::unordered_set<std::string> m_privileges;
|
||||||
|
|
||||||
|
@ -859,6 +859,9 @@ private:
|
|||||||
Hud *hud = nullptr;
|
Hud *hud = nullptr;
|
||||||
Minimap *mapper = nullptr;
|
Minimap *mapper = nullptr;
|
||||||
|
|
||||||
|
// Map server hud ids to client hud ids
|
||||||
|
std::unordered_map<u32, u32> m_hud_server_to_client;
|
||||||
|
|
||||||
GameRunData runData;
|
GameRunData runData;
|
||||||
Flags m_flags;
|
Flags m_flags;
|
||||||
|
|
||||||
@ -2605,12 +2608,11 @@ void Game::handleClientEvent_HandleParticleEvent(ClientEvent *event,
|
|||||||
void Game::handleClientEvent_HudAdd(ClientEvent *event, CameraOrientation *cam)
|
void Game::handleClientEvent_HudAdd(ClientEvent *event, CameraOrientation *cam)
|
||||||
{
|
{
|
||||||
LocalPlayer *player = client->getEnv().getLocalPlayer();
|
LocalPlayer *player = client->getEnv().getLocalPlayer();
|
||||||
auto &hud_server_to_client = client->getHUDTranslationMap();
|
|
||||||
|
|
||||||
u32 server_id = event->hudadd.server_id;
|
u32 server_id = event->hudadd.server_id;
|
||||||
// ignore if we already have a HUD with that ID
|
// ignore if we already have a HUD with that ID
|
||||||
auto i = hud_server_to_client.find(server_id);
|
auto i = m_hud_server_to_client.find(server_id);
|
||||||
if (i != hud_server_to_client.end()) {
|
if (i != m_hud_server_to_client.end()) {
|
||||||
delete event->hudadd.pos;
|
delete event->hudadd.pos;
|
||||||
delete event->hudadd.name;
|
delete event->hudadd.name;
|
||||||
delete event->hudadd.scale;
|
delete event->hudadd.scale;
|
||||||
@ -2638,7 +2640,7 @@ void Game::handleClientEvent_HudAdd(ClientEvent *event, CameraOrientation *cam)
|
|||||||
e->size = *event->hudadd.size;
|
e->size = *event->hudadd.size;
|
||||||
e->z_index = event->hudadd.z_index;
|
e->z_index = event->hudadd.z_index;
|
||||||
e->text2 = *event->hudadd.text2;
|
e->text2 = *event->hudadd.text2;
|
||||||
hud_server_to_client[server_id] = player->addHud(e);
|
m_hud_server_to_client[server_id] = player->addHud(e);
|
||||||
|
|
||||||
delete event->hudadd.pos;
|
delete event->hudadd.pos;
|
||||||
delete event->hudadd.name;
|
delete event->hudadd.name;
|
||||||
@ -2654,18 +2656,28 @@ void Game::handleClientEvent_HudAdd(ClientEvent *event, CameraOrientation *cam)
|
|||||||
void Game::handleClientEvent_HudRemove(ClientEvent *event, CameraOrientation *cam)
|
void Game::handleClientEvent_HudRemove(ClientEvent *event, CameraOrientation *cam)
|
||||||
{
|
{
|
||||||
LocalPlayer *player = client->getEnv().getLocalPlayer();
|
LocalPlayer *player = client->getEnv().getLocalPlayer();
|
||||||
HudElement *e = player->removeHud(event->hudrm.id);
|
|
||||||
delete e;
|
auto i = m_hud_server_to_client.find(event->hudrm.id);
|
||||||
|
if (i != m_hud_server_to_client.end()) {
|
||||||
|
HudElement *e = player->removeHud(i->second);
|
||||||
|
delete e;
|
||||||
|
m_hud_server_to_client.erase(i);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::handleClientEvent_HudChange(ClientEvent *event, CameraOrientation *cam)
|
void Game::handleClientEvent_HudChange(ClientEvent *event, CameraOrientation *cam)
|
||||||
{
|
{
|
||||||
LocalPlayer *player = client->getEnv().getLocalPlayer();
|
LocalPlayer *player = client->getEnv().getLocalPlayer();
|
||||||
|
|
||||||
u32 id = event->hudchange.id;
|
HudElement *e = nullptr;
|
||||||
HudElement *e = player->getHud(id);
|
|
||||||
|
|
||||||
if (e == NULL) {
|
auto i = m_hud_server_to_client.find(event->hudchange.id);
|
||||||
|
if (i != m_hud_server_to_client.end()) {
|
||||||
|
e = player->getHud(i->second);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e == nullptr) {
|
||||||
delete event->hudchange.v3fdata;
|
delete event->hudchange.v3fdata;
|
||||||
delete event->hudchange.v2fdata;
|
delete event->hudchange.v2fdata;
|
||||||
delete event->hudchange.sdata;
|
delete event->hudchange.sdata;
|
||||||
|
@ -1095,16 +1095,10 @@ void Client::handleCommand_HudRemove(NetworkPacket* pkt)
|
|||||||
|
|
||||||
*pkt >> server_id;
|
*pkt >> server_id;
|
||||||
|
|
||||||
auto i = m_hud_server_to_client.find(server_id);
|
ClientEvent *event = new ClientEvent();
|
||||||
if (i != m_hud_server_to_client.end()) {
|
event->type = CE_HUDRM;
|
||||||
int client_id = i->second;
|
event->hudrm.id = server_id;
|
||||||
m_hud_server_to_client.erase(i);
|
m_client_event_queue.push(event);
|
||||||
|
|
||||||
ClientEvent *event = new ClientEvent();
|
|
||||||
event->type = CE_HUDRM;
|
|
||||||
event->hudrm.id = client_id;
|
|
||||||
m_client_event_queue.push(event);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::handleCommand_HudChange(NetworkPacket* pkt)
|
void Client::handleCommand_HudChange(NetworkPacket* pkt)
|
||||||
@ -1131,19 +1125,16 @@ void Client::handleCommand_HudChange(NetworkPacket* pkt)
|
|||||||
else
|
else
|
||||||
*pkt >> intdata;
|
*pkt >> intdata;
|
||||||
|
|
||||||
std::unordered_map<u32, u32>::const_iterator i = m_hud_server_to_client.find(server_id);
|
ClientEvent *event = new ClientEvent();
|
||||||
if (i != m_hud_server_to_client.end()) {
|
event->type = CE_HUDCHANGE;
|
||||||
ClientEvent *event = new ClientEvent();
|
event->hudchange.id = server_id;
|
||||||
event->type = CE_HUDCHANGE;
|
event->hudchange.stat = (HudElementStat)stat;
|
||||||
event->hudchange.id = i->second;
|
event->hudchange.v2fdata = new v2f(v2fdata);
|
||||||
event->hudchange.stat = (HudElementStat)stat;
|
event->hudchange.v3fdata = new v3f(v3fdata);
|
||||||
event->hudchange.v2fdata = new v2f(v2fdata);
|
event->hudchange.sdata = new std::string(sdata);
|
||||||
event->hudchange.v3fdata = new v3f(v3fdata);
|
event->hudchange.data = intdata;
|
||||||
event->hudchange.sdata = new std::string(sdata);
|
event->hudchange.v2s32data = new v2s32(v2s32data);
|
||||||
event->hudchange.data = intdata;
|
m_client_event_queue.push(event);
|
||||||
event->hudchange.v2s32data = new v2s32(v2s32data);
|
|
||||||
m_client_event_queue.push(event);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::handleCommand_HudSetFlags(NetworkPacket* pkt)
|
void Client::handleCommand_HudSetFlags(NetworkPacket* pkt)
|
||||||
|
Loading…
Reference in New Issue
Block a user