From 40ce538aad9af8f7634c4ba7e9f12246fb23b31c Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Thu, 16 Mar 2017 10:34:54 +0100 Subject: [CSM] Add minimap API modifiers (#5399) * Rename Mapper (too generic) to Minimap * Add lua functions to get/set position, angle, mode for minimap * Client: rename m_mapper to m_minimap * Add minimap to core.ui namespace (core.ui.minimap) * Add various functions to manage minimap (show, hide, toggle_shape) * Cleanup trivial declaration in client --- src/script/lua_api/l_minimap.cpp | 196 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 src/script/lua_api/l_minimap.cpp (limited to 'src/script/lua_api/l_minimap.cpp') diff --git a/src/script/lua_api/l_minimap.cpp b/src/script/lua_api/l_minimap.cpp new file mode 100644 index 000000000..bbe9aef82 --- /dev/null +++ b/src/script/lua_api/l_minimap.cpp @@ -0,0 +1,196 @@ +/* +Minetest +Copyright (C) 2017 Loic Blot + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + + +#include "lua_api/l_minimap.h" +#include "lua_api/l_internal.h" +#include "common/c_converter.h" +#include "minimap.h" + +LuaMinimap::LuaMinimap(Minimap *m) +{ + m_minimap = m; +} + +void LuaMinimap::create(lua_State *L, Minimap *m) +{ + LuaMinimap *o = new LuaMinimap(m); + *(void **)(lua_newuserdata(L, sizeof(void *))) = o; + luaL_getmetatable(L, className); + lua_setmetatable(L, -2); + + // Keep minimap object stack id + int minimap_object = lua_gettop(L); + + lua_getglobal(L, "core"); + lua_getfield(L, -1, "ui"); + luaL_checktype(L, -1, LUA_TTABLE); + int uitable = lua_gettop(L); + + lua_pushvalue(L, minimap_object); // Copy object to top of stack + lua_setfield(L, uitable, "minimap"); +} + +int LuaMinimap::l_get_pos(lua_State *L) +{ + LuaMinimap *ref = checkobject(L, 1); + Minimap *m = getobject(ref); + + push_v3s16(L, m->getPos()); + return 1; +} + +int LuaMinimap::l_set_pos(lua_State *L) +{ + LuaMinimap *ref = checkobject(L, 1); + Minimap *m = getobject(ref); + + m->setPos(read_v3s16(L, 2)); + return 1; +} + +int LuaMinimap::l_get_angle(lua_State *L) +{ + LuaMinimap *ref = checkobject(L, 1); + Minimap *m = getobject(ref); + + lua_pushinteger(L, m->getAngle()); + return 1; +} + +int LuaMinimap::l_set_angle(lua_State *L) +{ + LuaMinimap *ref = checkobject(L, 1); + Minimap *m = getobject(ref); + + m->setAngle(lua_tointeger(L, 2)); + return 1; +} + +int LuaMinimap::l_get_mode(lua_State *L) +{ + LuaMinimap *ref = checkobject(L, 1); + Minimap *m = getobject(ref); + + lua_pushinteger(L, m->getMinimapMode()); + return 1; +} + +int LuaMinimap::l_set_mode(lua_State *L) +{ + LuaMinimap *ref = checkobject(L, 1); + Minimap *m = getobject(ref); + + s32 mode = lua_tointeger(L, 2); + if (mode < MINIMAP_MODE_OFF || + mode >= MINIMAP_MODE_COUNT) { + return 0; + } + + m->setMinimapMode((MinimapMode) mode); + return 1; +} + +int LuaMinimap::l_toggle_shape(lua_State *L) +{ + LuaMinimap *ref = checkobject(L, 1); + Minimap *m = getobject(ref); + + m->toggleMinimapShape(); + return 1; +} + +int LuaMinimap::l_show(lua_State *L) +{ + Client *client = getClient(L); + assert(client); + client->setMinimapShownByMod(true); + return 1; +} + +int LuaMinimap::l_hide(lua_State *L) +{ + Client *client = getClient(L); + assert(client); + client->setMinimapShownByMod(false); + return 1; +} + +LuaMinimap *LuaMinimap::checkobject(lua_State *L, int narg) +{ + NO_MAP_LOCK_REQUIRED; + + luaL_checktype(L, narg, LUA_TUSERDATA); + + void *ud = luaL_checkudata(L, narg, className); + if (!ud) + luaL_typerror(L, narg, className); + + return *(LuaMinimap **)ud; // unbox pointer +} + +Minimap* LuaMinimap::getobject(LuaMinimap *ref) +{ + return ref->m_minimap; +} + +int LuaMinimap::gc_object(lua_State *L) { + LuaMinimap *o = *(LuaMinimap **)(lua_touserdata(L, 1)); + delete o; + return 0; +} + +void LuaMinimap::Register(lua_State *L) +{ + lua_newtable(L); + int methodtable = lua_gettop(L); + luaL_newmetatable(L, className); + int metatable = lua_gettop(L); + + lua_pushliteral(L, "__metatable"); + lua_pushvalue(L, methodtable); + lua_settable(L, metatable); // hide metatable from Lua getmetatable() + + lua_pushliteral(L, "__index"); + lua_pushvalue(L, methodtable); + lua_settable(L, metatable); + + lua_pushliteral(L, "__gc"); + lua_pushcfunction(L, gc_object); + lua_settable(L, metatable); + + lua_pop(L, 1); // drop metatable + + luaL_openlib(L, 0, methods, 0); // fill methodtable + lua_pop(L, 1); // drop methodtable +} + +const char LuaMinimap::className[] = "Minimap"; +const luaL_reg LuaMinimap::methods[] = { + luamethod(LuaMinimap, show), + luamethod(LuaMinimap, hide), + luamethod(LuaMinimap, get_pos), + luamethod(LuaMinimap, set_pos), + luamethod(LuaMinimap, get_angle), + luamethod(LuaMinimap, set_angle), + luamethod(LuaMinimap, get_mode), + luamethod(LuaMinimap, set_mode), + luamethod(LuaMinimap, toggle_shape), + {0,0} +}; -- cgit v1.2.3 From 7b74f04a611ddaf36d79c0c9ebbf7f2b89c12a64 Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Fri, 17 Mar 2017 07:54:49 +0100 Subject: [CSM] Fix minimap problems (#5405) This fixes issue #5404 --- clientmods/preview/init.lua | 8 ++++++-- src/client.cpp | 7 +------ src/client.h | 2 -- src/game.cpp | 2 +- src/script/lua_api/l_minimap.cpp | 16 ++++++++++------ 5 files changed, 18 insertions(+), 17 deletions(-) (limited to 'src/script/lua_api/l_minimap.cpp') diff --git a/clientmods/preview/init.lua b/clientmods/preview/init.lua index 3f85d576d..25a61da51 100644 --- a/clientmods/preview/init.lua +++ b/clientmods/preview/init.lua @@ -49,8 +49,8 @@ core.register_chatcommand("test_node", { local function preview_minimap() local minimap = core.ui.minimap - minimap:show() minimap:set_mode(4) + minimap:show() minimap:set_pos({x=5, y=50, z=5}) minimap:toggle_shape() @@ -61,9 +61,13 @@ end core.after(2, function() print("[PREVIEW] loaded " .. modname .. " mod") - preview_minimap() modstorage:set_string("current_mod", modname) print(modstorage:get_string("current_mod")) + preview_minimap() +end) + +core.after(5, function() + core.ui.minimap:show() print("[PREVIEW] Day count: " .. core.get_day_count() .. " time of day " .. core.get_timeofday()) diff --git a/src/client.cpp b/src/client.cpp index b355fa617..e87c0ff94 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -224,7 +224,6 @@ Client::Client( m_device(device), m_camera(NULL), m_minimap_disabled_by_server(false), - m_minimap_shown_by_mod(false), m_server_ser_ver(SER_FMT_VER_INVALID), m_proto_ver(0), m_playeritem(0), @@ -1933,11 +1932,7 @@ void Client::makeScreenshot(IrrlichtDevice *device) bool Client::shouldShowMinimap() const { - if (m_minimap_disabled_by_server) { - return false; - } - - return m_minimap_shown_by_mod; + return !m_minimap_disabled_by_server; } // IGameDef interface diff --git a/src/client.h b/src/client.h index 5c8a0ae25..fc1cbe310 100644 --- a/src/client.h +++ b/src/client.h @@ -532,7 +532,6 @@ public: { return m_camera; } bool shouldShowMinimap() const; - void setMinimapShownByMod(bool state) { m_minimap_shown_by_mod = state; } // IGameDef interface virtual IItemDefManager* getItemDefManager(); @@ -634,7 +633,6 @@ private: Camera *m_camera; Minimap *m_minimap; bool m_minimap_disabled_by_server; - bool m_minimap_shown_by_mod; // Server serialization version u8 m_server_ser_ver; diff --git a/src/game.cpp b/src/game.cpp index 386267017..4a3acf493 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1769,7 +1769,7 @@ void Game::run() updateProfilerGraphs(&graph); // Update if minimap has been disabled by the server - flags.show_minimap = client->shouldShowMinimap(); + flags.show_minimap &= client->shouldShowMinimap(); } } diff --git a/src/script/lua_api/l_minimap.cpp b/src/script/lua_api/l_minimap.cpp index bbe9aef82..cb0245576 100644 --- a/src/script/lua_api/l_minimap.cpp +++ b/src/script/lua_api/l_minimap.cpp @@ -118,17 +118,21 @@ int LuaMinimap::l_toggle_shape(lua_State *L) int LuaMinimap::l_show(lua_State *L) { - Client *client = getClient(L); - assert(client); - client->setMinimapShownByMod(true); + LuaMinimap *ref = checkobject(L, 1); + Minimap *m = getobject(ref); + + if (m->getMinimapMode() == MINIMAP_MODE_OFF) + m->setMinimapMode(MINIMAP_MODE_SURFACEx1); return 1; } int LuaMinimap::l_hide(lua_State *L) { - Client *client = getClient(L); - assert(client); - client->setMinimapShownByMod(false); + LuaMinimap *ref = checkobject(L, 1); + Minimap *m = getobject(ref); + + if (m->getMinimapMode() != MINIMAP_MODE_OFF) + m->setMinimapMode(MINIMAP_MODE_OFF); return 1; } -- cgit v1.2.3 From 3c4ac70348db5375118d1e714a6d4681c3cfcd05 Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Sun, 19 Mar 2017 13:18:52 +0100 Subject: Refactor Game class (part 2) (#5422) * showPauseMenu is now part of game * remove many flags parameters passed to game functions, use the member. * rename VolatileRunFlags to GameUIFlags (this will permit to share structure with client and CSM * updatePointedThing: remove pointer ref, we already have the pointer in rundata * move some attributes outside of VolatileRunFlags after renaming, to game class * rename statustext to m_statustext * make some const variables static * All those changes permit to reduce a little bit function class cost and will permit to interface CSM with some interesting Game flags * Expose GameUIFlags to client * Client now have GameUIFlags parameter and setters for other classes * Fix minimap show/hide in Lua because we now have access to the real flag --- src/client.cpp | 37 ++- src/client.h | 12 +- src/game.cpp | 478 ++++++++++++++++++--------------------- src/game.h | 12 + src/guiFormSpecMenu.h | 2 +- src/script/lua_api/l_minimap.cpp | 10 + 6 files changed, 285 insertions(+), 266 deletions(-) (limited to 'src/script/lua_api/l_minimap.cpp') diff --git a/src/client.cpp b/src/client.cpp index e87c0ff94..0c4819bc5 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -46,6 +46,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "serialization.h" #include "guiscalingfilter.h" #include "script/clientscripting.h" +#include "game.h" extern gui::IGUIEnvironment* guienv; @@ -198,7 +199,8 @@ Client::Client( IWritableNodeDefManager *nodedef, ISoundManager *sound, MtEventManager *event, - bool ipv6 + bool ipv6, + GameUIFlags *game_ui_flags ): m_packetcounter_timer(0.0), m_connection_reinit_timer(0.1), @@ -250,7 +252,8 @@ Client::Client( m_state(LC_Created), m_localdb(NULL), m_script(NULL), - m_mod_storage_save_timer(10.0f) + m_mod_storage_save_timer(10.0f), + m_game_ui_flags(game_ui_flags) { // Add local player m_env.setLocalPlayer(new LocalPlayer(this, playername)); @@ -1935,6 +1938,36 @@ bool Client::shouldShowMinimap() const return !m_minimap_disabled_by_server; } +void Client::showGameChat(const bool show) +{ + m_game_ui_flags->show_chat = show; +} + +void Client::showGameHud(const bool show) +{ + m_game_ui_flags->show_hud = show; +} + +void Client::showMinimap(const bool show) +{ + m_game_ui_flags->show_minimap = show; +} + +void Client::showProfiler(const bool show) +{ + m_game_ui_flags->show_profiler_graph = show; +} + +void Client::showGameFog(const bool show) +{ + m_game_ui_flags->force_fog_off = !show; +} + +void Client::showGameDebug(const bool show) +{ + m_game_ui_flags->show_debug = show; +} + // IGameDef interface // Under envlock IItemDefManager* Client::getItemDefManager() diff --git a/src/client.h b/src/client.h index fc1cbe310..b1310424d 100644 --- a/src/client.h +++ b/src/client.h @@ -307,6 +307,7 @@ private: }; class ClientScripting; +class GameUIFlags; class Client : public con::PeerHandler, public InventoryManager, public IGameDef { @@ -326,7 +327,8 @@ public: IWritableNodeDefManager *nodedef, ISoundManager *sound, MtEventManager *event, - bool ipv6 + bool ipv6, + GameUIFlags *game_ui_flags ); ~Client(); @@ -578,6 +580,13 @@ public: m_client_event_queue.push(event); } + void showGameChat(const bool show = true); + void showGameHud(const bool show = true); + void showMinimap(const bool show = true); + void showProfiler(const bool show = true); + void showGameFog(const bool show = true); + void showGameDebug(const bool show = true); + private: // Virtual methods from con::PeerHandler @@ -725,6 +734,7 @@ private: bool m_modding_enabled; UNORDERED_MAP m_mod_storages; float m_mod_storage_save_timer; + GameUIFlags *m_game_ui_flags; DISABLE_CLASS_COPY(Client); }; diff --git a/src/game.cpp b/src/game.cpp index 12c81bf2f..7d7da35e8 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -123,16 +123,15 @@ struct TextDestPlayerInventory : public TextDest { Client *m_client; }; -struct LocalFormspecHandler : public TextDest { - LocalFormspecHandler(); - - LocalFormspecHandler(std::string formname) : +struct LocalFormspecHandler : public TextDest +{ + LocalFormspecHandler(std::string formname): m_client(0) { m_formname = formname; } - LocalFormspecHandler(std::string formname, Client *client) : + LocalFormspecHandler(std::string formname, Client *client): m_client(client) { m_formname = formname; @@ -927,81 +926,6 @@ static inline void create_formspec_menu(GUIFormSpecMenu **cur_formspec, #define SIZE_TAG "size[11,5.5,true]" // Fixed size on desktop #endif -/******************************************************************************/ -static void show_pause_menu(GUIFormSpecMenu **cur_formspec, - Client *client, - IWritableTextureSource *tsrc, IrrlichtDevice *device, - JoystickController *joystick, bool singleplayermode) -{ -#ifdef __ANDROID__ - std::string control_text = strgettext("Default Controls:\n" - "No menu visible:\n" - "- single tap: button activate\n" - "- double tap: place/use\n" - "- slide finger: look around\n" - "Menu/Inventory visible:\n" - "- double tap (outside):\n" - " -->close\n" - "- touch stack, touch slot:\n" - " --> move stack\n" - "- touch&drag, tap 2nd finger\n" - " --> place single item to slot\n" - ); -#else - std::string control_text = strgettext("Default Controls:\n" - "- WASD: move\n" - "- Space: jump/climb\n" - "- Shift: sneak/go down\n" - "- Q: drop item\n" - "- I: inventory\n" - "- Mouse: turn/look\n" - "- Mouse left: dig/punch\n" - "- Mouse right: place/use\n" - "- Mouse wheel: select item\n" - "- T: chat\n" - ); -#endif - - float ypos = singleplayermode ? 0.5 : 0.1; - std::ostringstream os; - - os << FORMSPEC_VERSION_STRING << SIZE_TAG - << "button_exit[4," << (ypos++) << ";3,0.5;btn_continue;" - << strgettext("Continue") << "]"; - - if (!singleplayermode) { - os << "button_exit[4," << (ypos++) << ";3,0.5;btn_change_password;" - << strgettext("Change Password") << "]"; - } - -#ifndef __ANDROID__ - os << "button_exit[4," << (ypos++) << ";3,0.5;btn_sound;" - << strgettext("Sound Volume") << "]"; - os << "button_exit[4," << (ypos++) << ";3,0.5;btn_key_config;" - << strgettext("Change Keys") << "]"; -#endif - os << "button_exit[4," << (ypos++) << ";3,0.5;btn_exit_menu;" - << strgettext("Exit to Menu") << "]"; - os << "button_exit[4," << (ypos++) << ";3,0.5;btn_exit_os;" - << strgettext("Exit to OS") << "]" - << "textarea[7.5,0.25;3.9,6.25;;" << control_text << ";]" - << "textarea[0.4,0.25;3.5,6;;" << PROJECT_NAME_C "\n" - << g_build_info << "\n" - << "path_user = " << wrap_rows(porting::path_user, 20) - << "\n;]"; - - /* Create menu */ - /* Note: FormspecFormSource and LocalFormspecHandler * - * are deleted by guiFormSpecMenu */ - FormspecFormSource *fs_src = new FormspecFormSource(os.str()); - LocalFormspecHandler *txt_dst = new LocalFormspecHandler("MT_PAUSE_MENU"); - - create_formspec_menu(cur_formspec, client, device, joystick, fs_src, txt_dst); - std::string con("btn_continue"); - (*cur_formspec)->setFocus(con); - (*cur_formspec)->doPause = true; -} - /******************************************************************************/ static void updateChat(Client &client, f32 dtime, bool show_debug, const v2u32 &screensize, bool show_chat, u32 show_profiler, @@ -1219,28 +1143,10 @@ struct Jitter { struct RunStats { u32 drawtime; - u32 beginscenetime; - u32 endscenetime; Jitter dtime_jitter, busy_time_jitter; }; -/* Flags that can, or may, change during main game loop - */ -struct VolatileRunFlags { - bool invert_mouse; - bool show_chat; - bool show_hud; - bool show_minimap; - bool force_fog_off; - bool show_debug; - bool show_profiler_graph; - bool disable_camera_update; - bool first_loop_after_window_activation; - bool camera_offset_changed; -}; - - /**************************************************************************** THE GAME ****************************************************************************/ @@ -1322,29 +1228,24 @@ protected: void toggleCinematic(); void toggleAutorun(); - void toggleChat(bool *flag); - void toggleHud(bool *flag); - void toggleMinimap(bool *flag, bool show_hud, - bool shift_pressed); - void toggleFog(bool *flag); - void toggleDebug(bool *show_debug, - bool *show_profiler_graph, bool *show_wireframe); - void toggleUpdateCamera(bool *flag); - void toggleProfiler(u32 *profiler_current_page, - u32 profiler_max_page); + void toggleChat(); + void toggleHud(); + void toggleMinimap(bool shift_pressed); + void toggleFog(); + void toggleDebug(); + void toggleUpdateCamera(); + void toggleProfiler(); void increaseViewRange(); void decreaseViewRange(); void toggleFullViewRange(); - void updateCameraDirection(CameraOrientation *cam, VolatileRunFlags *flags, - float dtime); - void updateCameraOrientation(CameraOrientation *cam, - const VolatileRunFlags &flags, float dtime); + void updateCameraDirection(CameraOrientation *cam, float dtime); + void updateCameraOrientation(CameraOrientation *cam, float dtime); void updatePlayerControl(const CameraOrientation &cam); void step(f32 *dtime); void processClientEvents(CameraOrientation *cam); - void updateCamera(VolatileRunFlags *flags, u32 busy_time, f32 dtime); + void updateCamera(u32 busy_time, f32 dtime); void updateSound(f32 dtime); void processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug); /*! @@ -1362,8 +1263,7 @@ protected: */ PointedThing updatePointedThing( const core::line3d &shootline, bool liquids_pointable, - bool look_for_object, const v3s16 &camera_offset, - ClientActiveObject *&selected_object); + bool look_for_object, const v3s16 &camera_offset); void handlePointingAtNothing(const ItemStack &playerItem); void handlePointingAtNode(const PointedThing &pointed, const ItemDefinition &playeritem_def, const ToolCapabilities &playeritem_toolcap, f32 dtime); @@ -1372,9 +1272,8 @@ protected: void handleDigging(const PointedThing &pointed, const v3s16 &nodepos, const ToolCapabilities &playeritem_toolcap, f32 dtime); void updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, - const VolatileRunFlags &flags, const CameraOrientation &cam); - void updateGui(const RunStats &stats, f32 dtime, - const VolatileRunFlags &flags, const CameraOrientation &cam); + const CameraOrientation &cam); + void updateGui(const RunStats &stats, f32 dtime, const CameraOrientation &cam); void updateProfilerGraphs(ProfilerGraph *graph); // Misc @@ -1426,6 +1325,8 @@ protected: #endif private: + void showPauseMenu(); + InputHandler *input; Client *client; @@ -1462,7 +1363,7 @@ private: Minimap *mapper; GameRunData runData; - VolatileRunFlags flags; + GameUIFlags flags; /* 'cache' This class does take ownership/responsibily for cleaning up etc of any of @@ -1494,7 +1395,7 @@ private: gui::IGUIStaticText *guitext_profiler; // Profiler text std::wstring infotext; - std::wstring statustext; + std::wstring m_statustext; KeyCache keycache; @@ -1519,6 +1420,10 @@ private: f32 m_cache_cam_smoothing; f32 m_cache_fog_start; + bool m_invert_mouse; + bool m_first_loop_after_window_activation; + bool m_camera_offset_changed; + #ifdef __ANDROID__ bool m_cache_hold_aux1; bool m_android_chat_open; @@ -1547,7 +1452,10 @@ Game::Game() : sky(NULL), local_inventory(NULL), hud(NULL), - mapper(NULL) + mapper(NULL), + m_invert_mouse(false), + m_first_loop_after_window_activation(false), + m_camera_offset_changed(false) { g_settings->registerChangedCallback("doubletap_jump", &settingChangedCallback, this); @@ -1678,8 +1586,8 @@ bool Game::startup(bool *kill, flags.show_chat = true; flags.show_hud = true; flags.show_debug = g_settings->getBool("show_debug"); - flags.invert_mouse = g_settings->getBool("invert_mouse"); - flags.first_loop_after_window_activation = true; + m_invert_mouse = g_settings->getBool("invert_mouse"); + m_first_loop_after_window_activation = true; if (!init(map_dir, address, port, gamespec)) return false; @@ -1738,7 +1646,7 @@ void Game::run() updateProfilers(stats, draw_times, dtime); processUserInput(dtime); // Update camera before player movement to avoid camera lag of one frame - updateCameraDirection(&cam_view_target, &flags, dtime); + updateCameraDirection(&cam_view_target, dtime); cam_view.camera_yaw += (cam_view_target.camera_yaw - cam_view.camera_yaw) * m_cache_cam_smoothing; cam_view.camera_pitch += (cam_view_target.camera_pitch - @@ -1746,10 +1654,10 @@ void Game::run() updatePlayerControl(cam_view); step(&dtime); processClientEvents(&cam_view_target); - updateCamera(&flags, draw_times.busy_time, dtime); + updateCamera(draw_times.busy_time, dtime); updateSound(dtime); processPlayerInteraction(dtime, flags.show_hud, flags.show_debug); - updateFrame(&graph, &stats, dtime, flags, cam_view); + updateFrame(&graph, &stats, dtime, cam_view); updateProfilerGraphs(&graph); // Update if minimap has been disabled by the server @@ -2130,7 +2038,7 @@ bool Game::connectToServer(const std::string &playername, playername.c_str(), password, *draw_control, texture_src, shader_src, itemdef_manager, nodedef_manager, sound, eventmgr, - connect_address.isIPv6()); + connect_address.isIPv6(), &flags); if (!client) return false; @@ -2535,22 +2443,18 @@ void Game::processKeyInput() openInventory(); } else if (wasKeyDown(KeyType::ESC) || input->wasKeyDown(CancelKey)) { if (!gui_chat_console->isOpenInhibited()) { - show_pause_menu(¤t_formspec, client, - texture_src, device, &input->joystick, - simple_singleplayer_mode); + showPauseMenu(); } } else if (wasKeyDown(KeyType::CHAT)) { openConsole(0.2, L""); } else if (wasKeyDown(KeyType::CMD)) { openConsole(0.2, L"/"); } else if (wasKeyDown(KeyType::CONSOLE)) { - openConsole(core::clamp( - g_settings->getFloat("console_height"), 0.1f, 1.0f)); + openConsole(core::clamp(g_settings->getFloat("console_height"), 0.1f, 1.0f)); } else if (wasKeyDown(KeyType::FREEMOVE)) { toggleFreeMove(); } else if (wasKeyDown(KeyType::JUMP)) { toggleFreeMoveAlt(); - runData.reset_jump_timer = true; } else if (wasKeyDown(KeyType::FASTMOVE)) { toggleFast(); } else if (wasKeyDown(KeyType::NOCLIP)) { @@ -2560,21 +2464,19 @@ void Game::processKeyInput() } else if (wasKeyDown(KeyType::SCREENSHOT)) { client->makeScreenshot(device); } else if (wasKeyDown(KeyType::TOGGLE_HUD)) { - toggleHud(&flags.show_hud); + toggleHud(); } else if (wasKeyDown(KeyType::MINIMAP)) { - toggleMinimap(&flags.show_minimap, flags.show_hud, isKeyDown(KeyType::SNEAK)); + toggleMinimap(isKeyDown(KeyType::SNEAK)); } else if (wasKeyDown(KeyType::TOGGLE_CHAT)) { - toggleChat(&flags.show_chat); + toggleChat(); } else if (wasKeyDown(KeyType::TOGGLE_FORCE_FOG_OFF)) { - toggleFog(&flags.force_fog_off); + toggleFog(); } else if (wasKeyDown(KeyType::TOGGLE_UPDATE_CAMERA)) { - toggleUpdateCamera(&flags.disable_camera_update); + toggleUpdateCamera(); } else if (wasKeyDown(KeyType::TOGGLE_DEBUG)) { - toggleDebug(&flags.show_debug, &flags.show_profiler_graph, - &draw_control->show_wireframe); + toggleDebug(); } else if (wasKeyDown(KeyType::TOGGLE_PROFILER)) { - toggleProfiler(&runData.profiler_current_page, - runData.profiler_max_page); + toggleProfiler(); } else if (wasKeyDown(KeyType::INCREASE_VIEWING_RANGE)) { increaseViewRange(); } else if (wasKeyDown(KeyType::DECREASE_VIEWING_RANGE)) { @@ -2605,7 +2507,7 @@ void Game::processKeyInput() } if (quicktune->hasMessage()) { - statustext = utf8_to_wide(quicktune->getMessage()); + m_statustext = utf8_to_wide(quicktune->getMessage()); runData.statustext_time = 0.0f; } } @@ -2731,9 +2633,9 @@ void Game::toggleFreeMove() g_settings->set("free_move", bool_to_cstr(free_move)); runData.statustext_time = 0; - statustext = msg[free_move]; + m_statustext = msg[free_move]; if (free_move && !client->checkPrivilege("fly")) - statustext += L" (note: no 'fly' privilege)"; + m_statustext += L" (note: no 'fly' privilege)"; } @@ -2741,6 +2643,8 @@ void Game::toggleFreeMoveAlt() { if (m_cache_doubletap_jump && runData.jump_timer < 0.2f) toggleFreeMove(); + + runData.reset_jump_timer = true; } @@ -2751,12 +2655,12 @@ void Game::toggleFast() g_settings->set("fast_move", bool_to_cstr(fast_move)); runData.statustext_time = 0; - statustext = msg[fast_move]; + m_statustext = msg[fast_move]; bool has_fast_privs = client->checkPrivilege("fast"); if (fast_move && !has_fast_privs) - statustext += L" (note: no 'fast' privilege)"; + m_statustext += L" (note: no 'fast' privilege)"; #ifdef __ANDROID__ m_cache_hold_aux1 = fast_move && has_fast_privs; @@ -2771,10 +2675,10 @@ void Game::toggleNoClip() g_settings->set("noclip", bool_to_cstr(noclip)); runData.statustext_time = 0; - statustext = msg[noclip]; + m_statustext = msg[noclip]; if (noclip && !client->checkPrivilege("noclip")) - statustext += L" (note: no 'noclip' privilege)"; + m_statustext += L" (note: no 'noclip' privilege)"; } void Game::toggleCinematic() @@ -2784,7 +2688,7 @@ void Game::toggleCinematic() g_settings->set("cinematic", bool_to_cstr(cinematic)); runData.statustext_time = 0; - statustext = msg[cinematic]; + m_statustext = msg[cinematic]; } // Add WoW-style autorun by toggling continuous forward. @@ -2795,32 +2699,31 @@ void Game::toggleAutorun() g_settings->set("continuous_forward", bool_to_cstr(autorun_enabled)); runData.statustext_time = 0; - statustext = msg[autorun_enabled ? 1 : 0]; + m_statustext = msg[autorun_enabled ? 1 : 0]; } -void Game::toggleChat(bool *flag) +void Game::toggleChat() { static const wchar_t *msg[] = { L"Chat hidden", L"Chat shown" }; - *flag = !*flag; + flags.show_chat = !flags.show_chat; runData.statustext_time = 0; - statustext = msg[*flag]; + m_statustext = msg[flags.show_chat]; } -void Game::toggleHud(bool *flag) +void Game::toggleHud() { static const wchar_t *msg[] = { L"HUD hidden", L"HUD shown" }; - *flag = !*flag; + flags.show_hud = !flags.show_hud; runData.statustext_time = 0; - statustext = msg[*flag]; + m_statustext = msg[flags.show_hud]; } -void Game::toggleMinimap(bool *flag, - bool show_hud, bool shift_pressed) +void Game::toggleMinimap(bool shift_pressed) { - if (!show_hud || !g_settings->getBool("enable_minimap")) + if (!flags.show_hud || !g_settings->getBool("enable_minimap")) return; if (shift_pressed) { @@ -2836,30 +2739,30 @@ void Game::toggleMinimap(bool *flag, mode = (MinimapMode)((int)mode + 1); } - *flag = true; + flags.show_minimap = true; switch (mode) { case MINIMAP_MODE_SURFACEx1: - statustext = L"Minimap in surface mode, Zoom x1"; + m_statustext = L"Minimap in surface mode, Zoom x1"; break; case MINIMAP_MODE_SURFACEx2: - statustext = L"Minimap in surface mode, Zoom x2"; + m_statustext = L"Minimap in surface mode, Zoom x2"; break; case MINIMAP_MODE_SURFACEx4: - statustext = L"Minimap in surface mode, Zoom x4"; + m_statustext = L"Minimap in surface mode, Zoom x4"; break; case MINIMAP_MODE_RADARx1: - statustext = L"Minimap in radar mode, Zoom x1"; + m_statustext = L"Minimap in radar mode, Zoom x1"; break; case MINIMAP_MODE_RADARx2: - statustext = L"Minimap in radar mode, Zoom x2"; + m_statustext = L"Minimap in radar mode, Zoom x2"; break; case MINIMAP_MODE_RADARx4: - statustext = L"Minimap in radar mode, Zoom x4"; + m_statustext = L"Minimap in radar mode, Zoom x4"; break; default: mode = MINIMAP_MODE_OFF; - *flag = false; - statustext = (hud_flags & HUD_FLAG_MINIMAP_VISIBLE) ? + flags.show_minimap = false; + m_statustext = (hud_flags & HUD_FLAG_MINIMAP_VISIBLE) ? L"Minimap hidden" : L"Minimap disabled by server"; } @@ -2867,76 +2770,77 @@ void Game::toggleMinimap(bool *flag, mapper->setMinimapMode(mode); } -void Game::toggleFog(bool *flag) +void Game::toggleFog() { static const wchar_t *msg[] = { L"Fog enabled", L"Fog disabled" }; - *flag = !*flag; + flags.force_fog_off = !flags.force_fog_off; runData.statustext_time = 0; - statustext = msg[*flag]; + m_statustext = msg[flags.force_fog_off]; } -void Game::toggleDebug(bool *show_debug, bool *show_profiler_graph, bool *show_wireframe) +void Game::toggleDebug() { // Initial / 4x toggle: Chat only // 1x toggle: Debug text with chat // 2x toggle: Debug text with profiler graph // 3x toggle: Debug text and wireframe - if (!*show_debug) { - *show_debug = true; - *show_profiler_graph = false; - *show_wireframe = false; - statustext = L"Debug info shown"; - } else if (!*show_profiler_graph && !*show_wireframe) { - *show_profiler_graph = true; - statustext = L"Profiler graph shown"; - } else if (!*show_wireframe && client->checkPrivilege("debug")) { - *show_profiler_graph = false; - *show_wireframe = true; - statustext = L"Wireframe shown"; + if (!flags.show_debug) { + flags.show_debug = true; + flags.show_profiler_graph = false; + draw_control->show_wireframe = false; + m_statustext = L"Debug info shown"; + } else if (!flags.show_profiler_graph && !draw_control->show_wireframe) { + flags.show_profiler_graph = true; + m_statustext = L"Profiler graph shown"; + } else if (!draw_control->show_wireframe && client->checkPrivilege("debug")) { + flags.show_profiler_graph = false; + draw_control->show_wireframe = true; + m_statustext = L"Wireframe shown"; } else { - *show_debug = false; - *show_profiler_graph = false; - *show_wireframe = false; + flags.show_debug = false; + flags.show_profiler_graph = false; + draw_control->show_wireframe = false; if (client->checkPrivilege("debug")) { - statustext = L"Debug info, profiler graph, and wireframe hidden"; + m_statustext = L"Debug info, profiler graph, and wireframe hidden"; } else { - statustext = L"Debug info and profiler graph hidden"; + m_statustext = L"Debug info and profiler graph hidden"; } } runData.statustext_time = 0; } -void Game::toggleUpdateCamera(bool *flag) +void Game::toggleUpdateCamera() { static const wchar_t *msg[] = { L"Camera update enabled", L"Camera update disabled" }; - *flag = !*flag; + flags.disable_camera_update = !flags.disable_camera_update; runData.statustext_time = 0; - statustext = msg[*flag]; + m_statustext = msg[flags.disable_camera_update]; } -void Game::toggleProfiler(u32 *profiler_current_page, u32 profiler_max_page) +void Game::toggleProfiler() { - *profiler_current_page = (*profiler_current_page + 1) % (profiler_max_page + 1); + runData.profiler_current_page = + (runData.profiler_current_page + 1) % (runData.profiler_max_page + 1); // FIXME: This updates the profiler with incomplete values - update_profiler_gui(guitext_profiler, g_fontengine, *profiler_current_page, - profiler_max_page, driver->getScreenSize().Height); + update_profiler_gui(guitext_profiler, g_fontengine, runData.profiler_current_page, + runData.profiler_max_page, driver->getScreenSize().Height); - if (*profiler_current_page != 0) { + if (runData.profiler_current_page != 0) { std::wstringstream sstr; - sstr << "Profiler shown (page " << *profiler_current_page - << " of " << profiler_max_page << ")"; - statustext = sstr.str(); + sstr << "Profiler shown (page " << runData.profiler_current_page + << " of " << runData.profiler_max_page << ")"; + m_statustext = sstr.str(); } else { - statustext = L"Profiler hidden"; + m_statustext = L"Profiler hidden"; } runData.statustext_time = 0; } @@ -2949,10 +2853,10 @@ void Game::increaseViewRange() if (range_new > 4000) { range_new = 4000; - statustext = utf8_to_wide("Viewing range is at maximum: " + m_statustext = utf8_to_wide("Viewing range is at maximum: " + itos(range_new)); } else { - statustext = utf8_to_wide("Viewing range changed to " + m_statustext = utf8_to_wide("Viewing range changed to " + itos(range_new)); } g_settings->set("viewing_range", itos(range_new)); @@ -2967,10 +2871,10 @@ void Game::decreaseViewRange() if (range_new < 20) { range_new = 20; - statustext = utf8_to_wide("Viewing range is at minimum: " + m_statustext = utf8_to_wide("Viewing range is at minimum: " + itos(range_new)); } else { - statustext = utf8_to_wide("Viewing range changed to " + m_statustext = utf8_to_wide("Viewing range changed to " + itos(range_new)); } g_settings->set("viewing_range", itos(range_new)); @@ -2987,13 +2891,12 @@ void Game::toggleFullViewRange() draw_control->range_all = !draw_control->range_all; infostream << msg[draw_control->range_all] << std::endl; - statustext = msg[draw_control->range_all]; + m_statustext = msg[draw_control->range_all]; runData.statustext_time = 0; } -void Game::updateCameraDirection(CameraOrientation *cam, - VolatileRunFlags *flags, float dtime) +void Game::updateCameraDirection(CameraOrientation *cam, float dtime) { if ((device->isWindowActive() && noMenuActive()) || random_input) { @@ -3005,10 +2908,10 @@ void Game::updateCameraDirection(CameraOrientation *cam, } #endif - if (flags->first_loop_after_window_activation) - flags->first_loop_after_window_activation = false; + if (m_first_loop_after_window_activation) + m_first_loop_after_window_activation = false; else - updateCameraOrientation(cam, *flags, dtime); + updateCameraOrientation(cam, dtime); input->setMousePos((driver->getScreenSize().Width / 2), (driver->getScreenSize().Height / 2)); @@ -3016,18 +2919,17 @@ void Game::updateCameraDirection(CameraOrientation *cam, #ifndef ANDROID // Mac OSX gets upset if this is set every frame - if (device->getCursorControl()->isVisible() == false) + if (!device->getCursorControl()->isVisible()) device->getCursorControl()->setVisible(true); #endif - if (!flags->first_loop_after_window_activation) - flags->first_loop_after_window_activation = true; + if (!m_first_loop_after_window_activation) + m_first_loop_after_window_activation = true; } } -void Game::updateCameraOrientation(CameraOrientation *cam, - const VolatileRunFlags &flags, float dtime) +void Game::updateCameraOrientation(CameraOrientation *cam, float dtime) { #ifdef HAVE_TOUCHSCREENGUI if (g_touchscreengui) { @@ -3039,8 +2941,7 @@ void Game::updateCameraOrientation(CameraOrientation *cam, s32 dx = input->getMousePos().X - (driver->getScreenSize().Width / 2); s32 dy = input->getMousePos().Y - (driver->getScreenSize().Height / 2); - if (flags.invert_mouse - || camera->getCameraMode() == CAMERA_MODE_THIRD_FRONT) { + if (m_invert_mouse || camera->getCameraMode() == CAMERA_MODE_THIRD_FRONT) { dy = -dy; } @@ -3053,10 +2954,8 @@ void Game::updateCameraOrientation(CameraOrientation *cam, if (m_cache_enable_joysticks) { f32 c = m_cache_joystick_frustum_sensitivity * (1.f / 32767.f) * dtime; - cam->camera_yaw -= input->joystick.getAxisWithoutDead(JA_FRUSTUM_HORIZONTAL) * - c; - cam->camera_pitch += input->joystick.getAxisWithoutDead(JA_FRUSTUM_VERTICAL) * - c; + cam->camera_yaw -= input->joystick.getAxisWithoutDead(JA_FRUSTUM_HORIZONTAL) * c; + cam->camera_pitch += input->joystick.getAxisWithoutDead(JA_FRUSTUM_VERTICAL) * c; } cam->camera_pitch = rangelim(cam->camera_pitch, -89.5, 89.5); @@ -3355,7 +3254,7 @@ void Game::processClientEvents(CameraOrientation *cam) } -void Game::updateCamera(VolatileRunFlags *flags, u32 busy_time, f32 dtime) +void Game::updateCamera(u32 busy_time, f32 dtime) { LocalPlayer *player = client->getEnv().getLocalPlayer(); @@ -3411,13 +3310,13 @@ void Game::updateCamera(VolatileRunFlags *flags, u32 busy_time, f32 dtime) f32 camera_fov = camera->getFovMax(); v3s16 camera_offset = camera->getOffset(); - flags->camera_offset_changed = (camera_offset != old_camera_offset); + m_camera_offset_changed = (camera_offset != old_camera_offset); - if (!flags->disable_camera_update) { + if (!flags.disable_camera_update) { client->getEnv().getClientMap().updateCamera(camera_position, camera_direction, camera_fov, camera_offset); - if (flags->camera_offset_changed) { + if (m_camera_offset_changed) { client->updateCameraOffset(camera_offset); client->getEnv().updateCameraOffset(camera_offset); @@ -3511,9 +3410,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug) PointedThing pointed = updatePointedThing(shootline, playeritem_def.liquids_pointable, !runData.ldown_for_dig, - camera_offset, - // output - runData.selected_object); + camera_offset); if (pointed != runData.pointed_old) { infostream << "Pointing at " << pointed.dump() << std::endl; @@ -3604,8 +3501,7 @@ PointedThing Game::updatePointedThing( const core::line3d &shootline, bool liquids_pointable, bool look_for_object, - const v3s16 &camera_offset, - ClientActiveObject *&selected_object) + const v3s16 &camera_offset) { std::vector *selectionboxes = hud->getSelectionBoxes(); selectionboxes->clear(); @@ -3616,21 +3512,21 @@ PointedThing Game::updatePointedThing( ClientMap &map = client->getEnv().getClientMap(); INodeDefManager *nodedef=client->getNodeDefManager(); - selected_object = NULL; + runData.selected_object = NULL; PointedThing result=client->getEnv().getPointedThing( shootline, liquids_pointable, look_for_object); if (result.type == POINTEDTHING_OBJECT) { - selected_object = client->getEnv().getActiveObject(result.object_id); - if (show_entity_selectionbox && selected_object->doShowSelectionBox()) { - aabb3f *selection_box = selected_object->getSelectionBox(); + runData.selected_object = client->getEnv().getActiveObject(result.object_id); + if (show_entity_selectionbox && runData.selected_object->doShowSelectionBox()) { + aabb3f *selection_box = runData.selected_object->getSelectionBox(); // Box should exist because object was // returned in the first place assert(selection_box); - v3f pos = selected_object->getPosition(); + v3f pos = runData.selected_object->getPosition(); selectionboxes->push_back(aabb3f( selection_box->MinEdge, selection_box->MaxEdge)); selectionboxes->push_back( @@ -3981,7 +3877,7 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos, void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, - const VolatileRunFlags &flags, const CameraOrientation &cam) + const CameraOrientation &cam) { LocalPlayer *player = client->getEnv().getLocalPlayer(); @@ -4015,13 +3911,11 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, / 255.0; } - float time_of_day = runData.time_of_day; float time_of_day_smooth = runData.time_of_day_smooth; + float time_of_day = client->getEnv().getTimeOfDayF(); - time_of_day = client->getEnv().getTimeOfDayF(); - - const float maxsm = 0.05; - const float todsm = 0.05; + static const float maxsm = 0.05; + static const float todsm = 0.05; if (fabs(time_of_day - time_of_day_smooth) > maxsm && fabs(time_of_day - time_of_day_smooth + 1.0) > maxsm && @@ -4138,13 +4032,13 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, v3f camera_direction = camera->getDirection(); if (runData.update_draw_list_timer >= 0.2 || runData.update_draw_list_last_cam_dir.getDistanceFrom(camera_direction) > 0.2 - || flags.camera_offset_changed) { + || m_camera_offset_changed) { runData.update_draw_list_timer = 0; client->getEnv().getClientMap().updateDrawList(driver); runData.update_draw_list_last_cam_dir = camera_direction; } - updateGui(*stats, dtime, flags, cam); + updateGui(*stats, dtime, cam); /* make sure menu is on top @@ -4167,11 +4061,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, video::SColor skycolor = sky->getSkyColor(); TimeTaker tt_draw("mainloop: draw"); - { - TimeTaker timer("beginScene"); - driver->beginScene(true, true, skycolor); - stats->beginscenetime = timer.stop(true); - } + driver->beginScene(true, true, skycolor); draw_scene(driver, smgr, *camera, *client, player, *hud, *mapper, guienv, screensize, skycolor, flags.show_hud, @@ -4216,11 +4106,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, /* End scene */ - { - TimeTaker timer("endScene"); - driver->endScene(); - stats->endscenetime = timer.stop(true); - } + driver->endScene(); stats->drawtime = tt_draw.stop(true); g_profiler->graphAdd("mainloop_draw", stats->drawtime / 1000.0f); @@ -4238,8 +4124,7 @@ inline static const char *yawToDirectionString(int yaw) } -void Game::updateGui(const RunStats &stats, f32 dtime, const VolatileRunFlags &flags, - const CameraOrientation &cam) +void Game::updateGui(const RunStats &stats, f32 dtime, const CameraOrientation &cam) { v2u32 screensize = driver->getScreenSize(); LocalPlayer *player = client->getEnv().getLocalPlayer(); @@ -4319,19 +4204,19 @@ void Game::updateGui(const RunStats &stats, f32 dtime, const VolatileRunFlags &f float statustext_time_max = 1.5; - if (!statustext.empty()) { + if (!m_statustext.empty()) { runData.statustext_time += dtime; if (runData.statustext_time >= statustext_time_max) { - statustext = L""; + m_statustext = L""; runData.statustext_time = 0; } } - setStaticText(guitext_status, statustext.c_str()); - guitext_status->setVisible(!statustext.empty()); + setStaticText(guitext_status, m_statustext.c_str()); + guitext_status->setVisible(!m_statustext.empty()); - if (!statustext.empty()) { + if (!m_statustext.empty()) { s32 status_width = guitext_status->getTextWidth(); s32 status_height = guitext_status->getTextHeight(); s32 status_y = screensize.Y - 150; @@ -4485,6 +4370,75 @@ void Game::extendedResourceCleanup() << " (note: irrlicht doesn't support removing renderers)" << std::endl; } +void Game::showPauseMenu() +{ +#ifdef __ANDROID__ + static const std::string control_text = strgettext("Default Controls:\n" + "No menu visible:\n" + "- single tap: button activate\n" + "- double tap: place/use\n" + "- slide finger: look around\n" + "Menu/Inventory visible:\n" + "- double tap (outside):\n" + " -->close\n" + "- touch stack, touch slot:\n" + " --> move stack\n" + "- touch&drag, tap 2nd finger\n" + " --> place single item to slot\n" + ); +#else + static const std::string control_text = strgettext("Default Controls:\n" + "- WASD: move\n" + "- Space: jump/climb\n" + "- Shift: sneak/go down\n" + "- Q: drop item\n" + "- I: inventory\n" + "- Mouse: turn/look\n" + "- Mouse left: dig/punch\n" + "- Mouse right: place/use\n" + "- Mouse wheel: select item\n" + "- T: chat\n" + ); +#endif + + float ypos = simple_singleplayer_mode ? 0.5 : 0.1; + std::ostringstream os; + + os << FORMSPEC_VERSION_STRING << SIZE_TAG + << "button_exit[4," << (ypos++) << ";3,0.5;btn_continue;" + << strgettext("Continue") << "]"; + + if (!simple_singleplayer_mode) { + os << "button_exit[4," << (ypos++) << ";3,0.5;btn_change_password;" + << strgettext("Change Password") << "]"; + } + +#ifndef __ANDROID__ + os << "button_exit[4," << (ypos++) << ";3,0.5;btn_sound;" + << strgettext("Sound Volume") << "]"; + os << "button_exit[4," << (ypos++) << ";3,0.5;btn_key_config;" + << strgettext("Change Keys") << "]"; +#endif + os << "button_exit[4," << (ypos++) << ";3,0.5;btn_exit_menu;" + << strgettext("Exit to Menu") << "]"; + os << "button_exit[4," << (ypos++) << ";3,0.5;btn_exit_os;" + << strgettext("Exit to OS") << "]" + << "textarea[7.5,0.25;3.9,6.25;;" << control_text << ";]" + << "textarea[0.4,0.25;3.5,6;;" << PROJECT_NAME_C "\n" + << g_build_info << "\n" + << "path_user = " << wrap_rows(porting::path_user, 20) + << "\n;]"; + + /* Create menu */ + /* Note: FormspecFormSource and LocalFormspecHandler * + * are deleted by guiFormSpecMenu */ + FormspecFormSource *fs_src = new FormspecFormSource(os.str()); + LocalFormspecHandler *txt_dst = new LocalFormspecHandler("MT_PAUSE_MENU"); + + create_formspec_menu(¤t_formspec, client, device, &input->joystick, fs_src, txt_dst); + current_formspec->setFocus("btn_continue"); + current_formspec->doPause = true; +} /****************************************************************************/ /**************************************************************************** diff --git a/src/game.h b/src/game.h index df32e3397..19992ce3d 100644 --- a/src/game.h +++ b/src/game.h @@ -143,6 +143,18 @@ public: class ChatBackend; /* to avoid having to include chat.h */ struct SubgameSpec; +// Flags that can, or may, change during main game loop +struct GameUIFlags +{ + bool show_chat; + bool show_hud; + bool show_minimap; + bool force_fog_off; + bool show_debug; + bool show_profiler_graph; + bool disable_camera_update; +}; + void the_game(bool *kill, bool random_input, InputHandler *input, diff --git a/src/guiFormSpecMenu.h b/src/guiFormSpecMenu.h index 35365a94b..f4383e987 100644 --- a/src/guiFormSpecMenu.h +++ b/src/guiFormSpecMenu.h @@ -335,7 +335,7 @@ public: void removeChildren(); void setInitialFocus(); - void setFocus(std::string &elementname) + void setFocus(const std::string &elementname) { m_focused_element = elementname; } diff --git a/src/script/lua_api/l_minimap.cpp b/src/script/lua_api/l_minimap.cpp index cb0245576..8e03936a7 100644 --- a/src/script/lua_api/l_minimap.cpp +++ b/src/script/lua_api/l_minimap.cpp @@ -118,21 +118,31 @@ int LuaMinimap::l_toggle_shape(lua_State *L) int LuaMinimap::l_show(lua_State *L) { + Client *client = getClient(L); + assert(client); + LuaMinimap *ref = checkobject(L, 1); Minimap *m = getobject(ref); if (m->getMinimapMode() == MINIMAP_MODE_OFF) m->setMinimapMode(MINIMAP_MODE_SURFACEx1); + + client->showMinimap(true); return 1; } int LuaMinimap::l_hide(lua_State *L) { + Client *client = getClient(L); + assert(client); + LuaMinimap *ref = checkobject(L, 1); Minimap *m = getobject(ref); if (m->getMinimapMode() != MINIMAP_MODE_OFF) m->setMinimapMode(MINIMAP_MODE_OFF); + + client->showMinimap(false); return 1; } -- cgit v1.2.3 From fbc1432fe8e821f58e97a5f35340efb2f46f93e4 Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Wed, 29 Mar 2017 15:50:22 +0200 Subject: l_minimap: don't show minimap if configuration doesn't allow it --- src/script/lua_api/l_minimap.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/script/lua_api/l_minimap.cpp') diff --git a/src/script/lua_api/l_minimap.cpp b/src/script/lua_api/l_minimap.cpp index 8e03936a7..182894f4f 100644 --- a/src/script/lua_api/l_minimap.cpp +++ b/src/script/lua_api/l_minimap.cpp @@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "lua_api/l_internal.h" #include "common/c_converter.h" #include "minimap.h" +#include "settings.h" LuaMinimap::LuaMinimap(Minimap *m) { @@ -118,6 +119,10 @@ int LuaMinimap::l_toggle_shape(lua_State *L) int LuaMinimap::l_show(lua_State *L) { + // If minimap is disabled by config, don't show it. + if (!g_settings->getBool("enable_minimap")) + return 1; + Client *client = getClient(L); assert(client); -- cgit v1.2.3 From 41c54830242269de073e4a0c10d1775dfdf6811d Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Sat, 8 Apr 2017 09:28:37 +0200 Subject: Replace luaL_reg with luaL_Reg as recent LuaJIT dropped the Lua 5.0 compat (#5541) We are bundling Lua5.1 which has same macro --- src/script/lua_api/l_areastore.cpp | 4 ++-- src/script/lua_api/l_areastore.h | 2 +- src/script/lua_api/l_inventory.cpp | 2 +- src/script/lua_api/l_inventory.h | 2 +- src/script/lua_api/l_item.cpp | 2 +- src/script/lua_api/l_item.h | 2 +- src/script/lua_api/l_itemstackmeta.cpp | 2 +- src/script/lua_api/l_itemstackmeta.h | 2 +- src/script/lua_api/l_minimap.cpp | 2 +- src/script/lua_api/l_minimap.h | 2 +- src/script/lua_api/l_nodemeta.cpp | 4 ++-- src/script/lua_api/l_nodemeta.h | 4 ++-- src/script/lua_api/l_nodetimer.cpp | 2 +- src/script/lua_api/l_nodetimer.h | 2 +- src/script/lua_api/l_noise.cpp | 10 +++++----- src/script/lua_api/l_noise.h | 10 +++++----- src/script/lua_api/l_object.cpp | 2 +- src/script/lua_api/l_object.h | 2 +- src/script/lua_api/l_settings.cpp | 2 +- src/script/lua_api/l_settings.h | 2 +- src/script/lua_api/l_storage.cpp | 2 +- src/script/lua_api/l_storage.h | 2 +- src/script/lua_api/l_vmanip.cpp | 2 +- src/script/lua_api/l_vmanip.h | 2 +- 24 files changed, 35 insertions(+), 35 deletions(-) (limited to 'src/script/lua_api/l_minimap.cpp') diff --git a/src/script/lua_api/l_areastore.cpp b/src/script/lua_api/l_areastore.cpp index 09a5c78f9..b81985a7f 100644 --- a/src/script/lua_api/l_areastore.cpp +++ b/src/script/lua_api/l_areastore.cpp @@ -74,7 +74,7 @@ static inline void push_areas(lua_State *L, const std::vector &areas, static int deserialization_helper(lua_State *L, AreaStore *as, std::istream &is) { - try { + try { as->deserialize(is); } catch (const SerializationError &e) { lua_pushboolean(L, false); @@ -380,7 +380,7 @@ void LuaAreaStore::Register(lua_State *L) } const char LuaAreaStore::className[] = "AreaStore"; -const luaL_reg LuaAreaStore::methods[] = { +const luaL_Reg LuaAreaStore::methods[] = { luamethod(LuaAreaStore, get_area), luamethod(LuaAreaStore, get_areas_for_pos), luamethod(LuaAreaStore, get_areas_in_area), diff --git a/src/script/lua_api/l_areastore.h b/src/script/lua_api/l_areastore.h index 7dea08df4..8292e7712 100644 --- a/src/script/lua_api/l_areastore.h +++ b/src/script/lua_api/l_areastore.h @@ -28,7 +28,7 @@ class LuaAreaStore : public ModApiBase { private: static const char className[]; - static const luaL_reg methods[]; + static const luaL_Reg methods[]; static int gc_object(lua_State *L); diff --git a/src/script/lua_api/l_inventory.cpp b/src/script/lua_api/l_inventory.cpp index 9a4aa845d..f5e76a7b6 100644 --- a/src/script/lua_api/l_inventory.cpp +++ b/src/script/lua_api/l_inventory.cpp @@ -463,7 +463,7 @@ void InvRef::Register(lua_State *L) } const char InvRef::className[] = "InvRef"; -const luaL_reg InvRef::methods[] = { +const luaL_Reg InvRef::methods[] = { luamethod(InvRef, is_empty), luamethod(InvRef, get_size), luamethod(InvRef, set_size), diff --git a/src/script/lua_api/l_inventory.h b/src/script/lua_api/l_inventory.h index cc5333965..91d41c0d0 100644 --- a/src/script/lua_api/l_inventory.h +++ b/src/script/lua_api/l_inventory.h @@ -36,7 +36,7 @@ private: InventoryLocation m_loc; static const char className[]; - static const luaL_reg methods[]; + static const luaL_Reg methods[]; static InvRef *checkobject(lua_State *L, int narg); diff --git a/src/script/lua_api/l_item.cpp b/src/script/lua_api/l_item.cpp index 7e6f457e1..19b5b0955 100644 --- a/src/script/lua_api/l_item.cpp +++ b/src/script/lua_api/l_item.cpp @@ -462,7 +462,7 @@ void LuaItemStack::Register(lua_State *L) } const char LuaItemStack::className[] = "ItemStack"; -const luaL_reg LuaItemStack::methods[] = { +const luaL_Reg LuaItemStack::methods[] = { luamethod(LuaItemStack, is_empty), luamethod(LuaItemStack, get_name), luamethod(LuaItemStack, set_name), diff --git a/src/script/lua_api/l_item.h b/src/script/lua_api/l_item.h index 1ba5d79e0..b4efaefc8 100644 --- a/src/script/lua_api/l_item.h +++ b/src/script/lua_api/l_item.h @@ -28,7 +28,7 @@ private: ItemStack m_stack; static const char className[]; - static const luaL_reg methods[]; + static const luaL_Reg methods[]; // Exported functions diff --git a/src/script/lua_api/l_itemstackmeta.cpp b/src/script/lua_api/l_itemstackmeta.cpp index 304a7cdf3..efdd77b51 100644 --- a/src/script/lua_api/l_itemstackmeta.cpp +++ b/src/script/lua_api/l_itemstackmeta.cpp @@ -102,7 +102,7 @@ void ItemStackMetaRef::Register(lua_State *L) } const char ItemStackMetaRef::className[] = "ItemStackMetaRef"; -const luaL_reg ItemStackMetaRef::methods[] = { +const luaL_Reg ItemStackMetaRef::methods[] = { luamethod(MetaDataRef, get_string), luamethod(MetaDataRef, set_string), luamethod(MetaDataRef, get_int), diff --git a/src/script/lua_api/l_itemstackmeta.h b/src/script/lua_api/l_itemstackmeta.h index 6f9b2016c..4ef64a91e 100644 --- a/src/script/lua_api/l_itemstackmeta.h +++ b/src/script/lua_api/l_itemstackmeta.h @@ -31,7 +31,7 @@ private: ItemStack *istack; static const char className[]; - static const luaL_reg methods[]; + static const luaL_Reg methods[]; static ItemStackMetaRef *checkobject(lua_State *L, int narg); diff --git a/src/script/lua_api/l_minimap.cpp b/src/script/lua_api/l_minimap.cpp index 182894f4f..c68602909 100644 --- a/src/script/lua_api/l_minimap.cpp +++ b/src/script/lua_api/l_minimap.cpp @@ -201,7 +201,7 @@ void LuaMinimap::Register(lua_State *L) } const char LuaMinimap::className[] = "Minimap"; -const luaL_reg LuaMinimap::methods[] = { +const luaL_Reg LuaMinimap::methods[] = { luamethod(LuaMinimap, show), luamethod(LuaMinimap, hide), luamethod(LuaMinimap, get_pos), diff --git a/src/script/lua_api/l_minimap.h b/src/script/lua_api/l_minimap.h index 9a299b4fd..8be72b8e7 100644 --- a/src/script/lua_api/l_minimap.h +++ b/src/script/lua_api/l_minimap.h @@ -28,7 +28,7 @@ class LuaMinimap : public ModApiBase { private: static const char className[]; - static const luaL_reg methods[]; + static const luaL_Reg methods[]; // garbage collector static int gc_object(lua_State *L); diff --git a/src/script/lua_api/l_nodemeta.cpp b/src/script/lua_api/l_nodemeta.cpp index 4368a8c50..55d11fc13 100644 --- a/src/script/lua_api/l_nodemeta.cpp +++ b/src/script/lua_api/l_nodemeta.cpp @@ -215,7 +215,7 @@ void NodeMetaRef::Register(lua_State *L) } -const luaL_reg NodeMetaRef::methodsServer[] = { +const luaL_Reg NodeMetaRef::methodsServer[] = { luamethod(MetaDataRef, get_string), luamethod(MetaDataRef, set_string), luamethod(MetaDataRef, get_int), @@ -237,7 +237,7 @@ void NodeMetaRef::RegisterClient(lua_State *L) } -const luaL_reg NodeMetaRef::methodsClient[] = { +const luaL_Reg NodeMetaRef::methodsClient[] = { luamethod(MetaDataRef, get_string), luamethod(MetaDataRef, get_int), luamethod(MetaDataRef, get_float), diff --git a/src/script/lua_api/l_nodemeta.h b/src/script/lua_api/l_nodemeta.h index 6d146416b..2ac028079 100644 --- a/src/script/lua_api/l_nodemeta.h +++ b/src/script/lua_api/l_nodemeta.h @@ -39,8 +39,8 @@ private: bool m_is_local; static const char className[]; - static const luaL_reg methodsServer[]; - static const luaL_reg methodsClient[]; + static const luaL_Reg methodsServer[]; + static const luaL_Reg methodsClient[]; static NodeMetaRef *checkobject(lua_State *L, int narg); diff --git a/src/script/lua_api/l_nodetimer.cpp b/src/script/lua_api/l_nodetimer.cpp index ed11cc58e..17b275c46 100644 --- a/src/script/lua_api/l_nodetimer.cpp +++ b/src/script/lua_api/l_nodetimer.cpp @@ -162,7 +162,7 @@ void NodeTimerRef::Register(lua_State *L) } const char NodeTimerRef::className[] = "NodeTimerRef"; -const luaL_reg NodeTimerRef::methods[] = { +const luaL_Reg NodeTimerRef::methods[] = { luamethod(NodeTimerRef, start), luamethod(NodeTimerRef, set), luamethod(NodeTimerRef, stop), diff --git a/src/script/lua_api/l_nodetimer.h b/src/script/lua_api/l_nodetimer.h index 239112037..ae362d8b3 100644 --- a/src/script/lua_api/l_nodetimer.h +++ b/src/script/lua_api/l_nodetimer.h @@ -32,7 +32,7 @@ private: ServerEnvironment *m_env; static const char className[]; - static const luaL_reg methods[]; + static const luaL_Reg methods[]; static int gc_object(lua_State *L); diff --git a/src/script/lua_api/l_noise.cpp b/src/script/lua_api/l_noise.cpp index e0039371f..e3e76191f 100644 --- a/src/script/lua_api/l_noise.cpp +++ b/src/script/lua_api/l_noise.cpp @@ -135,7 +135,7 @@ void LuaPerlinNoise::Register(lua_State *L) const char LuaPerlinNoise::className[] = "PerlinNoise"; -const luaL_reg LuaPerlinNoise::methods[] = { +const luaL_Reg LuaPerlinNoise::methods[] = { luamethod(LuaPerlinNoise, get2d), luamethod(LuaPerlinNoise, get3d), {0,0} @@ -393,7 +393,7 @@ void LuaPerlinNoiseMap::Register(lua_State *L) const char LuaPerlinNoiseMap::className[] = "PerlinNoiseMap"; -const luaL_reg LuaPerlinNoiseMap::methods[] = { +const luaL_Reg LuaPerlinNoiseMap::methods[] = { luamethod(LuaPerlinNoiseMap, get2dMap), luamethod(LuaPerlinNoiseMap, get2dMap_flat), luamethod(LuaPerlinNoiseMap, calc2dMap), @@ -498,7 +498,7 @@ void LuaPseudoRandom::Register(lua_State *L) const char LuaPseudoRandom::className[] = "PseudoRandom"; -const luaL_reg LuaPseudoRandom::methods[] = { +const luaL_Reg LuaPseudoRandom::methods[] = { luamethod(LuaPseudoRandom, next), {0,0} }; @@ -597,7 +597,7 @@ void LuaPcgRandom::Register(lua_State *L) const char LuaPcgRandom::className[] = "PcgRandom"; -const luaL_reg LuaPcgRandom::methods[] = { +const luaL_Reg LuaPcgRandom::methods[] = { luamethod(LuaPcgRandom, next), luamethod(LuaPcgRandom, rand_normal_dist), {0,0} @@ -711,7 +711,7 @@ void LuaSecureRandom::Register(lua_State *L) } const char LuaSecureRandom::className[] = "SecureRandom"; -const luaL_reg LuaSecureRandom::methods[] = { +const luaL_Reg LuaSecureRandom::methods[] = { luamethod(LuaSecureRandom, next_bytes), {0,0} }; diff --git a/src/script/lua_api/l_noise.h b/src/script/lua_api/l_noise.h index 11ec348bf..f252b5ba2 100644 --- a/src/script/lua_api/l_noise.h +++ b/src/script/lua_api/l_noise.h @@ -32,7 +32,7 @@ class LuaPerlinNoise : public ModApiBase private: NoiseParams np; static const char className[]; - static const luaL_reg methods[]; + static const luaL_Reg methods[]; // Exported functions @@ -64,7 +64,7 @@ class LuaPerlinNoiseMap : public ModApiBase Noise *noise; bool m_is3d; static const char className[]; - static const luaL_reg methods[]; + static const luaL_Reg methods[]; // Exported functions @@ -103,7 +103,7 @@ private: PseudoRandom m_pseudo; static const char className[]; - static const luaL_reg methods[]; + static const luaL_Reg methods[]; // Exported functions @@ -134,7 +134,7 @@ private: PcgRandom m_rnd; static const char className[]; - static const luaL_reg methods[]; + static const luaL_Reg methods[]; // Exported functions @@ -169,7 +169,7 @@ class LuaSecureRandom : public ModApiBase private: static const size_t RAND_BUF_SIZE = 2048; static const char className[]; - static const luaL_reg methods[]; + static const luaL_Reg methods[]; u32 m_rand_idx; char m_rand_buf[RAND_BUF_SIZE]; diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index d5681b809..f9d2754e7 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -1823,7 +1823,7 @@ void ObjectRef::Register(lua_State *L) } const char ObjectRef::className[] = "ObjectRef"; -const luaL_reg ObjectRef::methods[] = { +const luaL_Reg ObjectRef::methods[] = { // ServerActiveObject luamethod(ObjectRef, remove), luamethod_aliased(ObjectRef, get_pos, getpos), diff --git a/src/script/lua_api/l_object.h b/src/script/lua_api/l_object.h index 2c9aa559a..b6fc35bc2 100644 --- a/src/script/lua_api/l_object.h +++ b/src/script/lua_api/l_object.h @@ -37,7 +37,7 @@ private: ServerActiveObject *m_object; static const char className[]; - static const luaL_reg methods[]; + static const luaL_Reg methods[]; public: static ObjectRef *checkobject(lua_State *L, int narg); diff --git a/src/script/lua_api/l_settings.cpp b/src/script/lua_api/l_settings.cpp index d3fe03005..809f7d115 100644 --- a/src/script/lua_api/l_settings.cpp +++ b/src/script/lua_api/l_settings.cpp @@ -214,7 +214,7 @@ LuaSettings* LuaSettings::checkobject(lua_State* L, int narg) } const char LuaSettings::className[] = "Settings"; -const luaL_reg LuaSettings::methods[] = { +const luaL_Reg LuaSettings::methods[] = { luamethod(LuaSettings, get), luamethod(LuaSettings, get_bool), luamethod(LuaSettings, set), diff --git a/src/script/lua_api/l_settings.h b/src/script/lua_api/l_settings.h index d5edd32ce..b90f0a8f2 100644 --- a/src/script/lua_api/l_settings.h +++ b/src/script/lua_api/l_settings.h @@ -28,7 +28,7 @@ class LuaSettings : public ModApiBase { private: static const char className[]; - static const luaL_reg methods[]; + static const luaL_Reg methods[]; // garbage collector static int gc_object(lua_State *L); diff --git a/src/script/lua_api/l_storage.cpp b/src/script/lua_api/l_storage.cpp index 867ab9c8d..59906dda5 100644 --- a/src/script/lua_api/l_storage.cpp +++ b/src/script/lua_api/l_storage.cpp @@ -129,7 +129,7 @@ void StorageRef::clearMeta() } const char StorageRef::className[] = "StorageRef"; -const luaL_reg StorageRef::methods[] = { +const luaL_Reg StorageRef::methods[] = { luamethod(MetaDataRef, get_string), luamethod(MetaDataRef, set_string), luamethod(MetaDataRef, get_int), diff --git a/src/script/lua_api/l_storage.h b/src/script/lua_api/l_storage.h index e09b8b391..ec6f8d941 100644 --- a/src/script/lua_api/l_storage.h +++ b/src/script/lua_api/l_storage.h @@ -41,7 +41,7 @@ private: ModMetadata *m_object; static const char className[]; - static const luaL_reg methods[]; + static const luaL_Reg methods[]; virtual Metadata *getmeta(bool auto_create); virtual void clearMeta(); diff --git a/src/script/lua_api/l_vmanip.cpp b/src/script/lua_api/l_vmanip.cpp index 5f129d2af..7316fb200 100644 --- a/src/script/lua_api/l_vmanip.cpp +++ b/src/script/lua_api/l_vmanip.cpp @@ -452,7 +452,7 @@ void LuaVoxelManip::Register(lua_State *L) } const char LuaVoxelManip::className[] = "VoxelManip"; -const luaL_reg LuaVoxelManip::methods[] = { +const luaL_Reg LuaVoxelManip::methods[] = { luamethod(LuaVoxelManip, read_from_map), luamethod(LuaVoxelManip, get_data), luamethod(LuaVoxelManip, set_data), diff --git a/src/script/lua_api/l_vmanip.h b/src/script/lua_api/l_vmanip.h index 65fc0d97a..b6a69f36a 100644 --- a/src/script/lua_api/l_vmanip.h +++ b/src/script/lua_api/l_vmanip.h @@ -38,7 +38,7 @@ private: bool is_mapgen_vm; static const char className[]; - static const luaL_reg methods[]; + static const luaL_Reg methods[]; static int gc_object(lua_State *L); -- cgit v1.2.3 From e80a83d1cb9d01273ddca1c075c25cd01c291ca7 Mon Sep 17 00:00:00 2001 From: bigfoot547 Date: Fri, 14 Apr 2017 02:04:41 -0500 Subject: [CSM] Add function to set minimap shape (#5569) * [CSM] Add function to set minimap shape Also deprecates `toggle_shape`. * Oh fish, I messed that one up! * Fix Style * Sorry, I missed something I still had the `luamethod` call in there! * Add getters * Remove extra line * Remove useless variable Please review again @nerzhul . Thanks! * Satisfy nerzhul --- clientmods/preview/init.lua | 2 +- doc/client_lua_api.md | 3 ++- src/minimap.cpp | 22 ++++++++++++++++++++++ src/minimap.h | 7 +++++++ src/script/lua_api/l_minimap.cpp | 18 +++++++++++++++--- src/script/lua_api/l_minimap.h | 3 ++- 6 files changed, 49 insertions(+), 6 deletions(-) (limited to 'src/script/lua_api/l_minimap.cpp') diff --git a/clientmods/preview/init.lua b/clientmods/preview/init.lua index df07f8c3f..4b31fa323 100644 --- a/clientmods/preview/init.lua +++ b/clientmods/preview/init.lua @@ -62,7 +62,7 @@ local function preview_minimap() minimap:set_mode(4) minimap:show() minimap:set_pos({x=5, y=50, z=5}) - minimap:toggle_shape() + minimap:set_shape(math.random(0, 1)) print("[PREVIEW] Minimap: mode => " .. dump(minimap:get_mode()) .. " position => " .. dump(minimap:get_pos()) .. diff --git a/doc/client_lua_api.md b/doc/client_lua_api.md index 43a317a84..b2aeb3f25 100644 --- a/doc/client_lua_api.md +++ b/doc/client_lua_api.md @@ -779,7 +779,8 @@ An interface to manipulate minimap on client UI * `get_angle()`: returns the current minimap angle in degrees * `set_mode(mode)`: sets the minimap mode (0 to 6) * `get_mode()`: returns the current minimap mode -* `toggle_shape()`: toggles minimap shape to round or square. +* `set_shape(shape)`: Sets the minimap shape. (0 = square, 1 = round) +* `get_shape()`: Gets the minimap shape. (0 = square, 1 = round) ### LocalPlayer An interface to retrieve information about the player. The player is diff --git a/src/minimap.cpp b/src/minimap.cpp index a7f4822c9..500f49828 100644 --- a/src/minimap.cpp +++ b/src/minimap.cpp @@ -272,6 +272,28 @@ void Minimap::toggleMinimapShape() m_minimap_update_thread->deferUpdate(); } +void Minimap::setMinimapShape(MinimapShape shape) +{ + MutexAutoLock lock(m_mutex); + + if (shape == MINIMAP_SHAPE_SQUARE) + data->minimap_shape_round = false; + else if (shape == MINIMAP_SHAPE_ROUND) + data->minimap_shape_round = true; + + g_settings->setBool("minimap_shape_round", data->minimap_shape_round); + m_minimap_update_thread->deferUpdate(); +} + +MinimapShape Minimap::getMinimapShape() +{ + if (data->minimap_shape_round) { + return MINIMAP_SHAPE_ROUND; + } else { + return MINIMAP_SHAPE_SQUARE; + } +} + void Minimap::setMinimapMode(MinimapMode mode) { static const MinimapModeDef modedefs[MINIMAP_MODE_COUNT] = { diff --git a/src/minimap.h b/src/minimap.h index eb0ae1cf4..c50530335 100644 --- a/src/minimap.h +++ b/src/minimap.h @@ -45,6 +45,11 @@ enum MinimapMode { MINIMAP_MODE_COUNT, }; +enum MinimapShape { + MINIMAP_SHAPE_SQUARE, + MINIMAP_SHAPE_ROUND, +}; + struct MinimapModeDef { bool is_radar; u16 scan_height; @@ -128,6 +133,8 @@ public: void setMinimapMode(MinimapMode mode); MinimapMode getMinimapMode() const { return data->mode; } void toggleMinimapShape(); + void setMinimapShape(MinimapShape shape); + MinimapShape getMinimapShape(); video::ITexture *getMinimapTexture(); diff --git a/src/script/lua_api/l_minimap.cpp b/src/script/lua_api/l_minimap.cpp index c68602909..f32a07ce8 100644 --- a/src/script/lua_api/l_minimap.cpp +++ b/src/script/lua_api/l_minimap.cpp @@ -108,12 +108,23 @@ int LuaMinimap::l_set_mode(lua_State *L) return 1; } -int LuaMinimap::l_toggle_shape(lua_State *L) +int LuaMinimap::l_set_shape(lua_State *L) +{ + LuaMinimap *ref = checkobject(L, 1); + Minimap *m = getobject(ref); + if (!lua_isnumber(L, 2)) + return 0; + + m->setMinimapShape((MinimapShape)lua_tonumber(L, 2)); + return 0; +} + +int LuaMinimap::l_get_shape(lua_State *L) { LuaMinimap *ref = checkobject(L, 1); Minimap *m = getobject(ref); - m->toggleMinimapShape(); + lua_pushnumber(L, (int)m->getMinimapShape()); return 1; } @@ -210,6 +221,7 @@ const luaL_Reg LuaMinimap::methods[] = { luamethod(LuaMinimap, set_angle), luamethod(LuaMinimap, get_mode), luamethod(LuaMinimap, set_mode), - luamethod(LuaMinimap, toggle_shape), + luamethod(LuaMinimap, set_shape), + luamethod(LuaMinimap, get_shape), {0,0} }; diff --git a/src/script/lua_api/l_minimap.h b/src/script/lua_api/l_minimap.h index 8be72b8e7..ba702b0b1 100644 --- a/src/script/lua_api/l_minimap.h +++ b/src/script/lua_api/l_minimap.h @@ -45,7 +45,8 @@ private: static int l_show(lua_State *L); static int l_hide(lua_State *L); - static int l_toggle_shape(lua_State *L); + static int l_set_shape(lua_State *L); + static int l_get_shape(lua_State *L); Minimap *m_minimap; -- cgit v1.2.3 From 0f955bf7fa7a1376acdbc06a617c0f15f9fad467 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sat, 15 Apr 2017 14:30:27 +0200 Subject: Minimap: Do a double-typecast to fix compiling with MSVC --- src/script/lua_api/l_minimap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/script/lua_api/l_minimap.cpp') diff --git a/src/script/lua_api/l_minimap.cpp b/src/script/lua_api/l_minimap.cpp index f32a07ce8..afb3766fb 100644 --- a/src/script/lua_api/l_minimap.cpp +++ b/src/script/lua_api/l_minimap.cpp @@ -115,7 +115,7 @@ int LuaMinimap::l_set_shape(lua_State *L) if (!lua_isnumber(L, 2)) return 0; - m->setMinimapShape((MinimapShape)lua_tonumber(L, 2)); + m->setMinimapShape((MinimapShape)((int)lua_tonumber(L, 2))); return 0; } -- cgit v1.2.3