mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-02 16:38:41 +00:00
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
This commit is contained in:
parent
3068853e8a
commit
81c66d6efb
20 changed files with 470 additions and 144 deletions
|
@ -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);
|
||||
m_minimap->setModeIndex(0);
|
||||
|
||||
// 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);
|
||||
// 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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue