summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorPierre-Yves Rollo <dev@pyrollo.com>2020-10-04 15:24:29 +0200
committerSmallJoker <mk939@ymail.com>2020-10-04 15:24:34 +0200
commit81c66d6efb9fb0ab8a03b40e2bc22aa49eff9a04 (patch)
tree0f1c256eb6f24eb95df60804d9db82cead0f91e2 /src/network
parent3068853e8a58ccc7370a5ce977c08223601c497a (diff)
downloadminetest-81c66d6efb9fb0ab8a03b40e2bc22aa49eff9a04.tar.gz
minetest-81c66d6efb9fb0ab8a03b40e2bc22aa49eff9a04.tar.bz2
minetest-81c66d6efb9fb0ab8a03b40e2bc22aa49eff9a04.zip
Minimap as HUD element with API control
Features: * Define Minimap available modes (surface/radar, scale) from Lua, using player:set_minimap_modes() * New HUD elements for displaying minimap with custom size and placing * New minimap mode for displaying a texture instead of the map
Diffstat (limited to 'src/network')
-rw-r--r--src/network/clientopcodes.cpp1
-rw-r--r--src/network/clientpackethandler.cpp46
-rw-r--r--src/network/networkprotocol.h14
-rw-r--r--src/network/serveropcodes.cpp1
4 files changed, 56 insertions, 6 deletions
diff --git a/src/network/clientopcodes.cpp b/src/network/clientopcodes.cpp
index f812a08a1..55cfdd4dc 100644
--- a/src/network/clientopcodes.cpp
+++ b/src/network/clientopcodes.cpp
@@ -122,6 +122,7 @@ const ToClientCommandHandler toClientCommandTable[TOCLIENT_NUM_MSG_TYPES] =
null_command_handler,
{ "TOCLIENT_SRP_BYTES_S_B", TOCLIENT_STATE_NOT_CONNECTED, &Client::handleCommand_SrpBytesSandB }, // 0x60
{ "TOCLIENT_FORMSPEC_PREPEND", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_FormspecPrepend }, // 0x61,
+ { "TOCLIENT_MINIMAP_MODES", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_MinimapModes }, // 0x62,
};
const static ServerCommandFactory null_command_factory = { "TOSERVER_NULL", 0, false };
diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp
index 5683564a0..65db02300 100644
--- a/src/network/clientpackethandler.cpp
+++ b/src/network/clientpackethandler.cpp
@@ -1164,15 +1164,24 @@ void Client::handleCommand_HudSetFlags(NetworkPacket* pkt)
m_minimap_disabled_by_server = !(player->hud_flags & HUD_FLAG_MINIMAP_VISIBLE);
bool m_minimap_radar_disabled_by_server = !(player->hud_flags & HUD_FLAG_MINIMAP_RADAR_VISIBLE);
+ // Not so satisying code to keep compatibility with old fixed mode system
+ // -->
+
// Hide minimap if it has been disabled by the server
if (m_minimap && m_minimap_disabled_by_server && was_minimap_visible)
// defers a minimap update, therefore only call it if really
// needed, by checking that minimap was visible before
- m_minimap->setMinimapMode(MINIMAP_MODE_OFF);
-
- // Switch to surface mode if radar disabled by server
- if (m_minimap && m_minimap_radar_disabled_by_server && was_minimap_radar_visible)
- m_minimap->setMinimapMode(MINIMAP_MODE_SURFACEx1);
+ m_minimap->setModeIndex(0);
+
+ // If radar has been disabled, try to find a non radar mode or fall back to 0
+ if (m_minimap && m_minimap_radar_disabled_by_server
+ && was_minimap_radar_visible) {
+ while (m_minimap->getModeIndex() > 0 &&
+ m_minimap->getModeDef().type == MINIMAP_TYPE_RADAR)
+ m_minimap->nextMode();
+ }
+ // <--
+ // End of 'not so satifying code'
}
void Client::handleCommand_HudSetParam(NetworkPacket* pkt)
@@ -1611,3 +1620,30 @@ void Client::handleCommand_ModChannelSignal(NetworkPacket *pkt)
if (valid_signal)
m_script->on_modchannel_signal(channel, signal);
}
+
+void Client::handleCommand_MinimapModes(NetworkPacket *pkt)
+{
+ u16 count; // modes
+ u16 mode; // wanted current mode index after change
+
+ *pkt >> count >> mode;
+
+ if (m_minimap)
+ m_minimap->clearModes();
+
+ for (size_t index = 0; index < count; index++) {
+ u16 type;
+ std::string label;
+ u16 size;
+ std::string texture;
+ u16 scale;
+
+ *pkt >> type >> label >> size >> texture >> scale;
+
+ if (m_minimap)
+ m_minimap->addMode(MinimapType(type), size, label, texture, scale);
+ }
+
+ if (m_minimap)
+ m_minimap->setModeIndex(mode);
+}
diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h
index 05600cda9..666e75e45 100644
--- a/src/network/networkprotocol.h
+++ b/src/network/networkprotocol.h
@@ -204,6 +204,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
PROTOCOL VERSION 39:
Updated set_sky packet
Adds new sun, moon and stars packets
+ Minimap modes
*/
#define LATEST_PROTOCOL_VERSION 39
@@ -764,7 +765,18 @@ enum ToClientCommand
u8[len] formspec
*/
- TOCLIENT_NUM_MSG_TYPES = 0x62,
+ TOCLIENT_MINIMAP_MODES = 0x62,
+ /*
+ u16 count // modes
+ u16 mode // wanted current mode index after change
+ for each mode
+ u16 type
+ std::string label
+ u16 size
+ std::string extra
+ */
+
+ TOCLIENT_NUM_MSG_TYPES = 0x63,
};
enum ToServerCommand
diff --git a/src/network/serveropcodes.cpp b/src/network/serveropcodes.cpp
index 2fc3197c2..aea5d7174 100644
--- a/src/network/serveropcodes.cpp
+++ b/src/network/serveropcodes.cpp
@@ -221,4 +221,5 @@ const ClientCommandFactory clientCommandFactoryTable[TOCLIENT_NUM_MSG_TYPES] =
null_command_factory, // 0x5f
{ "TOSERVER_SRP_BYTES_S_B", 0, true }, // 0x60
{ "TOCLIENT_FORMSPEC_PREPEND", 0, true }, // 0x61
+ { "TOCLIENT_MINIMAP_MODES", 0, true }, // 0x62
};