forked from Mirrorlandia_minetest/minetest
Move hard coded minimap to builtin (#14071)
This commit is contained in:
parent
f2b99332d9
commit
adaa4cc2f3
@ -24,6 +24,13 @@ local bar_definitions = {
|
||||
size = {x = 24, y = 24},
|
||||
offset = {x = 25, y= -(48 + 24 + 16)},
|
||||
},
|
||||
minimap = {
|
||||
hud_elem_type = "minimap",
|
||||
position = {x = 1, y = 0},
|
||||
alignment = {x = -1, y = 1},
|
||||
offset = {x = -10, y = 10},
|
||||
size = {x = 256 , y = 256},
|
||||
},
|
||||
}
|
||||
|
||||
local hud_ids = {}
|
||||
@ -92,6 +99,16 @@ local function update_builtin_statbars(player)
|
||||
end, name, hud.id_breathbar)
|
||||
hud.id_breathbar = nil
|
||||
end
|
||||
|
||||
-- Don't add a minimap for clients which already have it hardcoded in C++.
|
||||
local show_minimap = flags.minimap and
|
||||
minetest.get_player_information(name).protocol_version >= 44
|
||||
if show_minimap and not hud.id_minimap then
|
||||
hud.id_minimap = player:hud_add(bar_definitions.minimap)
|
||||
elseif not show_minimap and hud.id_minimap then
|
||||
player:hud_remove(hud.id_minimap)
|
||||
hud.id_minimap = nil
|
||||
end
|
||||
end
|
||||
|
||||
local function cleanup_builtin_statbars(player)
|
||||
@ -138,8 +155,7 @@ local function player_event_handler(player,eventname)
|
||||
end
|
||||
|
||||
function core.hud_replace_builtin(hud_name, definition)
|
||||
if type(definition) ~= "table" or
|
||||
(definition.type or definition.hud_elem_type) ~= "statbar" then
|
||||
if type(definition) ~= "table" then
|
||||
return false
|
||||
end
|
||||
|
||||
@ -175,6 +191,20 @@ function core.hud_replace_builtin(hud_name, definition)
|
||||
return true
|
||||
end
|
||||
|
||||
if hud_name == "minimap" then
|
||||
bar_definitions.minimap = definition
|
||||
|
||||
for name, ids in pairs(hud_ids) do
|
||||
local player = core.get_player_by_name(name)
|
||||
if player and ids.id_minimap then
|
||||
player:hud_remove(ids.id_minimap)
|
||||
ids.id_minimap = nil
|
||||
update_builtin_statbars(player)
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
|
@ -6800,7 +6800,7 @@ Misc.
|
||||
(regardless of online status)
|
||||
* `minetest.hud_replace_builtin(name, hud_definition)`
|
||||
* Replaces definition of a builtin hud element
|
||||
* `name`: `"breath"` or `"health"`
|
||||
* `name`: `"breath"`, `"health"` or `"minimap"`
|
||||
* `hud_definition`: definition to replace builtin definition
|
||||
* `minetest.parse_relative_number(arg, relative_to)`: returns number or nil
|
||||
* Helper function for chat commands.
|
||||
|
@ -1971,21 +1971,11 @@ void Client::makeScreenshot()
|
||||
raw_image->drop();
|
||||
}
|
||||
|
||||
bool Client::shouldShowMinimap() const
|
||||
{
|
||||
return !m_minimap_disabled_by_server;
|
||||
}
|
||||
|
||||
void Client::pushToEventQueue(ClientEvent *event)
|
||||
{
|
||||
m_client_event_queue.push(event);
|
||||
}
|
||||
|
||||
void Client::showMinimap(const bool show)
|
||||
{
|
||||
m_game_ui->showMinimap(show);
|
||||
}
|
||||
|
||||
// IGameDef interface
|
||||
// Under envlock
|
||||
IItemDefManager* Client::getItemDefManager()
|
||||
|
@ -369,8 +369,6 @@ public:
|
||||
Camera* getCamera () { return m_camera; }
|
||||
scene::ISceneManager *getSceneManager();
|
||||
|
||||
bool shouldShowMinimap() const;
|
||||
|
||||
// IGameDef interface
|
||||
IItemDefManager* getItemDefManager() override;
|
||||
const NodeDefManager* getNodeDefManager() override;
|
||||
@ -412,8 +410,6 @@ public:
|
||||
|
||||
void pushToEventQueue(ClientEvent *event);
|
||||
|
||||
void showMinimap(bool show = true);
|
||||
|
||||
// IP and port we're connected to
|
||||
const Address getServerAddress();
|
||||
|
||||
@ -498,7 +494,6 @@ private:
|
||||
ELoginRegister m_allow_login_or_register = ELoginRegister::Any;
|
||||
Camera *m_camera = nullptr;
|
||||
Minimap *m_minimap = nullptr;
|
||||
bool m_minimap_disabled_by_server = false;
|
||||
|
||||
// Server serialization version
|
||||
u8 m_server_ser_ver;
|
||||
|
@ -1290,9 +1290,6 @@ void Game::run()
|
||||
updateFrame(&graph, &stats, dtime, cam_view);
|
||||
updateProfilerGraphs(&graph);
|
||||
|
||||
// Update if minimap has been disabled by the server
|
||||
m_game_ui->m_flags.show_minimap &= client->shouldShowMinimap();
|
||||
|
||||
if (m_does_lost_focus_pause_game && !device->isWindowFocused() && !isMenuActive()) {
|
||||
showPauseMenu();
|
||||
}
|
||||
@ -2474,23 +2471,16 @@ void Game::toggleMinimap(bool shift_pressed)
|
||||
// -->
|
||||
u32 hud_flags = client->getEnv().getLocalPlayer()->hud_flags;
|
||||
|
||||
if (!(hud_flags & HUD_FLAG_MINIMAP_VISIBLE)) {
|
||||
m_game_ui->m_flags.show_minimap = false;
|
||||
} else {
|
||||
|
||||
if (hud_flags & HUD_FLAG_MINIMAP_VISIBLE) {
|
||||
// If radar is disabled, try to find a non radar mode or fall back to 0
|
||||
if (!(hud_flags & HUD_FLAG_MINIMAP_RADAR_VISIBLE))
|
||||
while (mapper->getModeIndex() &&
|
||||
mapper->getModeDef().type == MINIMAP_TYPE_RADAR)
|
||||
mapper->nextMode();
|
||||
|
||||
m_game_ui->m_flags.show_minimap = mapper->getModeDef().type !=
|
||||
MINIMAP_TYPE_OFF;
|
||||
}
|
||||
// <--
|
||||
// End of 'not so satifying code'
|
||||
if ((hud_flags & HUD_FLAG_MINIMAP_VISIBLE) ||
|
||||
(hud && hud->hasElementOfType(HUD_ELEM_MINIMAP)))
|
||||
if (hud && hud->hasElementOfType(HUD_ELEM_MINIMAP))
|
||||
m_game_ui->showStatusText(utf8_to_wide(mapper->getModeDef().label));
|
||||
else
|
||||
m_game_ui->showTranslatedStatusText("Minimap currently disabled by game or mod");
|
||||
@ -4358,7 +4348,7 @@ void Game::drawScene(ProfilerGraph *graph, RunStats *stats)
|
||||
draw_crosshair = false;
|
||||
#endif
|
||||
this->m_rendering_engine->draw_scene(sky_color, this->m_game_ui->m_flags.show_hud,
|
||||
this->m_game_ui->m_flags.show_minimap, draw_wield_tool, draw_crosshair);
|
||||
draw_wield_tool, draw_crosshair);
|
||||
|
||||
/*
|
||||
Profiler graph
|
||||
|
@ -219,11 +219,6 @@ void GameUI::initFlags()
|
||||
m_flags.show_minimal_debug = g_settings->getBool("show_debug");
|
||||
}
|
||||
|
||||
void GameUI::showMinimap(bool show)
|
||||
{
|
||||
m_flags.show_minimap = show;
|
||||
}
|
||||
|
||||
void GameUI::showTranslatedStatusText(const char *str)
|
||||
{
|
||||
showStatusText(wstrgettext(str));
|
||||
|
@ -57,7 +57,6 @@ public:
|
||||
{
|
||||
bool show_chat = true;
|
||||
bool show_hud = true;
|
||||
bool show_minimap = false;
|
||||
bool show_minimal_debug = false;
|
||||
bool show_basic_debug = false;
|
||||
bool show_profiler_graph = false;
|
||||
@ -71,8 +70,6 @@ public:
|
||||
void initFlags();
|
||||
const Flags &getFlags() const { return m_flags; }
|
||||
|
||||
void showMinimap(bool show);
|
||||
|
||||
inline void setInfoText(const std::wstring &str) { m_infotext = str; }
|
||||
inline void clearInfoText() { m_infotext.clear(); }
|
||||
|
||||
|
@ -340,6 +340,14 @@ void Hud::drawLuaElements(const v3s16 &camera_offset)
|
||||
std::vector<HudElement*> elems;
|
||||
elems.reserve(player->maxHudId());
|
||||
|
||||
// Add builtin minimap if the server doesn't send it.
|
||||
HudElement minimap;
|
||||
if (client->getProtoVersion() < 44 && (player->hud_flags & HUD_FLAG_MINIMAP_VISIBLE)) {
|
||||
minimap = {HUD_ELEM_MINIMAP, v2f(1, 0), "", v2f(), "", 0 , 0, 0, v2f(-1, 1),
|
||||
v2f(-10, 10), v3f(), v2s32(256, 256), 0, "", 0};
|
||||
elems.push_back(&minimap);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i != player->maxHudId(); i++) {
|
||||
HudElement *e = player->getHud(i);
|
||||
if (!e)
|
||||
|
@ -571,17 +571,6 @@ scene::SMeshBuffer *Minimap::getMinimapMeshBuffer()
|
||||
return buf;
|
||||
}
|
||||
|
||||
void Minimap::drawMinimap()
|
||||
{
|
||||
// Non hud managed minimap drawing (legacy minimap)
|
||||
v2u32 screensize = RenderingEngine::getWindowSize();
|
||||
const u32 size = 0.25 * screensize.Y;
|
||||
|
||||
drawMinimap(core::rect<s32>(
|
||||
screensize.X - size - 10, 10,
|
||||
screensize.X - 10, size + 10));
|
||||
}
|
||||
|
||||
void Minimap::drawMinimap(core::rect<s32> rect) {
|
||||
|
||||
video::ITexture *minimap_texture = getMinimapTexture();
|
||||
|
@ -152,7 +152,6 @@ public:
|
||||
void removeMarker(MinimapMarker **marker);
|
||||
|
||||
void updateActiveMarkers();
|
||||
void drawMinimap();
|
||||
void drawMinimap(core::rect<s32> rect);
|
||||
|
||||
video::IVideoDriver *driver;
|
||||
|
@ -36,7 +36,7 @@ RenderingCore::~RenderingCore()
|
||||
delete shadow_renderer;
|
||||
}
|
||||
|
||||
void RenderingCore::draw(video::SColor _skycolor, bool _show_hud, bool _show_minimap,
|
||||
void RenderingCore::draw(video::SColor _skycolor, bool _show_hud,
|
||||
bool _draw_wield_tool, bool _draw_crosshair)
|
||||
{
|
||||
v2u32 screensize = device->getVideoDriver()->getScreenSize();
|
||||
@ -46,7 +46,6 @@ void RenderingCore::draw(video::SColor _skycolor, bool _show_hud, bool _show_min
|
||||
context.draw_crosshair = _draw_crosshair;
|
||||
context.draw_wield_tool = _draw_wield_tool;
|
||||
context.show_hud = _show_hud;
|
||||
context.show_minimap = _show_minimap;
|
||||
|
||||
pipeline->reset(context);
|
||||
pipeline->run(context);
|
||||
|
@ -53,7 +53,7 @@ public:
|
||||
RenderingCore &operator=(const RenderingCore &) = delete;
|
||||
RenderingCore &operator=(RenderingCore &&) = delete;
|
||||
|
||||
void draw(video::SColor _skycolor, bool _show_hud, bool _show_minimap,
|
||||
void draw(video::SColor _skycolor, bool _show_hud,
|
||||
bool _draw_wield_tool, bool _draw_crosshair);
|
||||
|
||||
v2u32 getVirtualSize() const;
|
||||
|
@ -46,7 +46,6 @@ struct PipelineContext
|
||||
v2u32 target_size;
|
||||
|
||||
bool show_hud {true};
|
||||
bool show_minimap {true};
|
||||
bool draw_wield_tool {true};
|
||||
bool draw_crosshair {true};
|
||||
};
|
||||
|
@ -64,9 +64,6 @@ void DrawHUD::run(PipelineContext &context)
|
||||
context.hud->drawHotbar(context.client->getEnv().getLocalPlayer()->getWieldIndex());
|
||||
context.hud->drawLuaElements(context.client->getCamera()->getOffset());
|
||||
context.client->getCamera()->drawNametags();
|
||||
auto mapper = context.client->getMinimap();
|
||||
if (mapper && context.show_minimap)
|
||||
mapper->drawMinimap();
|
||||
}
|
||||
context.device->getGUIEnvironment()->drawAll();
|
||||
}
|
||||
|
@ -319,9 +319,9 @@ void RenderingEngine::finalize()
|
||||
}
|
||||
|
||||
void RenderingEngine::draw_scene(video::SColor skycolor, bool show_hud,
|
||||
bool show_minimap, bool draw_wield_tool, bool draw_crosshair)
|
||||
bool draw_wield_tool, bool draw_crosshair)
|
||||
{
|
||||
core->draw(skycolor, show_hud, show_minimap, draw_wield_tool, draw_crosshair);
|
||||
core->draw(skycolor, show_hud, draw_wield_tool, draw_crosshair);
|
||||
}
|
||||
|
||||
const VideoDriverInfo &RenderingEngine::getVideoDriverInfo(irr::video::E_DRIVER_TYPE type)
|
||||
|
@ -118,7 +118,7 @@ public:
|
||||
float dtime = 0, int percent = 0, bool sky = true);
|
||||
|
||||
void draw_scene(video::SColor skycolor, bool show_hud,
|
||||
bool show_minimap, bool draw_wield_tool, bool draw_crosshair);
|
||||
bool draw_wield_tool, bool draw_crosshair);
|
||||
|
||||
void initialize(Client *client, Hud *hud);
|
||||
void finalize();
|
||||
|
@ -1281,24 +1281,15 @@ void Client::handleCommand_HudSetFlags(NetworkPacket* pkt)
|
||||
LocalPlayer *player = m_env.getLocalPlayer();
|
||||
assert(player != NULL);
|
||||
|
||||
bool was_minimap_visible = player->hud_flags & HUD_FLAG_MINIMAP_VISIBLE;
|
||||
bool was_minimap_radar_visible = player->hud_flags & HUD_FLAG_MINIMAP_RADAR_VISIBLE;
|
||||
|
||||
player->hud_flags &= ~mask;
|
||||
player->hud_flags |= flags;
|
||||
|
||||
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->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) {
|
||||
|
@ -222,6 +222,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
PROTOCOL VERSION 44:
|
||||
AO_CMD_SET_BONE_POSITION extended
|
||||
Add TOCLIENT_MOVE_PLAYER_REL
|
||||
Move default minimap from client-side C++ to server-side builtin Lua
|
||||
[scheduled bump for 5.9.0]
|
||||
*/
|
||||
|
||||
|
@ -144,7 +144,6 @@ int LuaMinimap::l_show(lua_State *L)
|
||||
if (m->getModeIndex() == 0 && m->getMaxModeIndex() > 0)
|
||||
m->setModeIndex(1);
|
||||
|
||||
client->showMinimap(true);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -162,7 +161,6 @@ int LuaMinimap::l_hide(lua_State *L)
|
||||
if (m->getModeIndex() != 0)
|
||||
m->setModeIndex(0);
|
||||
|
||||
client->showMinimap(false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,6 @@ public:
|
||||
void runTests(IGameDef *gamedef);
|
||||
|
||||
void testInit();
|
||||
void testFlagSetters();
|
||||
void testInfoText();
|
||||
void testStatusText();
|
||||
};
|
||||
@ -40,7 +39,6 @@ static TestGameUI g_test_instance;
|
||||
void TestGameUI::runTests(IGameDef *gamedef)
|
||||
{
|
||||
TEST(testInit);
|
||||
TEST(testFlagSetters);
|
||||
TEST(testInfoText);
|
||||
TEST(testStatusText);
|
||||
}
|
||||
@ -51,30 +49,18 @@ void TestGameUI::testInit()
|
||||
// Ensure flags on GameUI init
|
||||
UASSERT(gui.getFlags().show_chat)
|
||||
UASSERT(gui.getFlags().show_hud)
|
||||
UASSERT(!gui.getFlags().show_minimap)
|
||||
UASSERT(!gui.getFlags().show_profiler_graph)
|
||||
|
||||
// And after the initFlags init stage
|
||||
gui.initFlags();
|
||||
UASSERT(gui.getFlags().show_chat)
|
||||
UASSERT(gui.getFlags().show_hud)
|
||||
UASSERT(!gui.getFlags().show_minimap)
|
||||
UASSERT(!gui.getFlags().show_profiler_graph)
|
||||
|
||||
// @TODO verify if we can create non UI nulldevice to test this function
|
||||
// gui.init();
|
||||
}
|
||||
|
||||
void TestGameUI::testFlagSetters()
|
||||
{
|
||||
GameUI gui{};
|
||||
gui.showMinimap(true);
|
||||
UASSERT(gui.getFlags().show_minimap);
|
||||
|
||||
gui.showMinimap(false);
|
||||
UASSERT(!gui.getFlags().show_minimap);
|
||||
}
|
||||
|
||||
void TestGameUI::testStatusText()
|
||||
{
|
||||
GameUI gui{};
|
||||
|
Loading…
Reference in New Issue
Block a user