Compare commits

..

No commits in common. "b8959a0bac410cfe116ea13442248d470fac9b90" and "1f52edb14ce7cbc468dfd51c4f52976cbacdbd2f" have entirely different histories.

7 changed files with 67 additions and 201 deletions

@ -88,29 +88,9 @@ Menu/inventory open:
end
function core.show_pause_menu(is_singleplayer, is_touchscreen, address)
minetest.show_formspec("builtin:MT_PAUSE_MENU", menu_formspec(is_singleplayer, is_touchscreen, address))
minetest.show_formspec("MT_PAUSE_MENU", menu_formspec(is_singleplayer, is_touchscreen, address))
end
core.register_on_formspec_input(function(formname, fields)
if formname ~= "builtin:MT_PAUSE_MENU" then return end
if fields.btn_continue then
core.unpause()
elseif fields.btn_key_config then
core.key_config() -- Don't want this
elseif fields.btn_change_password then
core.change_password()
elseif fields.btn_settings then
core.show_settings()
elseif fields.btn_exit_menu then
core.disconnect()
elseif fields.btn_exit_os then
core.exit_to_os()
end
return
end)
local scriptpath = core.get_builtin_path()
local path = scriptpath.."mainmenu"..DIR_DELIM.."settings"
@ -127,134 +107,12 @@ function dialog_create(name, spec, buttonhandler, eventhandler)
minetest.show_formspec(name, spec({}))
end
local settings_data = {}
settings_data.data = {
leftscroll = 0,
query = "",
rightscroll = 0,
components = {},
page_id = "accessibility"
}
core.register_on_formspec_input(function(formname, fields)
if formname ~= "builtin:MT_PAUSE_MENU_SETTINGS" then return true end
--local this = data
--buttonhandler(settings_data, fields)
local dialogdata = settings_data.data
dialogdata.leftscroll = core.explode_scrollbar_event(fields.leftscroll).value or dialogdata.leftscroll
dialogdata.rightscroll = core.explode_scrollbar_event(fields.rightscroll).value or dialogdata.rightscroll
dialogdata.query = fields.search_query
local update = false
if fields.back then
this:delete()
return true
end
if fields.show_technical_names ~= nil then
local value = core.is_yes(fields.show_technical_names)
core.settings:set_bool("show_technical_names", value)
write_settings_early()
update = true
--return true
end
if fields.show_advanced ~= nil then
local value = core.is_yes(fields.show_advanced)
core.settings:set_bool("show_advanced", value)
write_settings_early()
core.show_settings()
update = true
end
-- enable_touch is a checkbox in a setting component. We handle this
-- setting differently so we can hide/show pages using the next if-statement
if fields.enable_touch ~= nil then
local value = core.is_yes(fields.enable_touch)
core.settings:set_bool("enable_touch", value)
write_settings_early()
core.show_settings()
update = true
end
if fields.show_advanced ~= nil or fields.enable_touch ~= nil then
local suggested_page_id = update_filtered_pages(dialogdata.query)
dialogdata.components = nil
if not filtered_page_by_id[dialogdata.page_id] then
dialogdata.leftscroll = 0
dialogdata.rightscroll = 0
dialogdata.page_id = suggested_page_id
end
return true
end
if fields.search or fields.key_enter_field == "search_query" then
dialogdata.components = nil
dialogdata.leftscroll = 0
dialogdata.rightscroll = 0
dialogdata.page_id = update_filtered_pages(dialogdata.query)
return true
end
if fields.search_clear then
dialogdata.query = ""
dialogdata.components = nil
dialogdata.leftscroll = 0
dialogdata.rightscroll = 0
dialogdata.page_id = update_filtered_pages("")
return true
end
for _, page in ipairs(all_pages) do
if fields["page_" .. page.id] then
dialogdata.page_id = page.id
dialogdata.components = nil
dialogdata.rightscroll = 0
core.show_settings()
return true
end
end
if dialogdata.components then
for i, comp in ipairs(dialogdata.components) do
if comp.on_submit and comp:on_submit(fields, this) then
write_settings_early()
core.show_settings()
-- Clear components so they regenerate
--dialogdata.components = nil
return true
end
if comp.setting and fields["reset_" .. i] then
core.settings:remove(comp.setting.name)
write_settings_early()
core.show_settings()
-- Clear components so they regenerate
--dialogdata.components = nil
return true
end
end
end
if update then
core.show_settings()
end
return false
end)
load(true, false)
--settings_data.data.page_id = update_filtered_pages("")
function core.show_settings()
show_settings_client_formspec("builtin:MT_PAUSE_MENU_SETTINGS", settings_data.data)
core.unpause()
function core.show_settings(page_id)
if not page_id then
show_settings_client_formspec("MT_PAUSE_MENU_SETTINGS", {})
else
show_settings_client_formspec("MT_PAUSE_MENU_SETTINGS", {page_id = page_id})
end
end

@ -23,13 +23,13 @@ local shadows_component = dofile(core.get_mainmenu_path() .. DIR_DELIM ..
"settings" .. DIR_DELIM .. "shadows_component.lua")
local loaded = false
full_settings = {}
local full_settings
local info_icon_path = core.formspec_escape(defaulttexturedir .. "settings_info.png")
local reset_icon_path = core.formspec_escape(defaulttexturedir .. "settings_reset.png")
all_pages = {}
page_by_id = {}
filtered_pages = all_pages
filtered_page_by_id = page_by_id
local all_pages = {}
local page_by_id = {}
local filtered_pages = all_pages
local filtered_page_by_id = page_by_id
local function get_setting_info(name)
@ -288,7 +288,7 @@ local function filter_page_content(page, query_keywords)
end
function update_filtered_pages(query)
local function update_filtered_pages(query)
filtered_pages = {}
filtered_page_by_id = {}
@ -633,13 +633,11 @@ function write_settings_early()
end
function buttonhandler(this, fields)
local function buttonhandler(this, fields)
local dialogdata = this.data
dialogdata.leftscroll = core.explode_scrollbar_event(fields.leftscroll).value or dialogdata.leftscroll
dialogdata.rightscroll = core.explode_scrollbar_event(fields.rightscroll).value or dialogdata.rightscroll
dialogdata.query = fields.search_query
minetest.log(dump(fields))
if fields.back then
this:delete()
@ -711,7 +709,6 @@ function buttonhandler(this, fields)
end
end
if dialogdata.components then
for i, comp in ipairs(dialogdata.components) do
if comp.on_submit and comp:on_submit(fields, this) then
write_settings_early()
@ -729,7 +726,6 @@ function buttonhandler(this, fields)
return true
end
end
end
return false
end

@ -149,7 +149,48 @@ struct LocalFormspecHandler : public TextDest
void gotText(const StringMap &fields)
{
if (m_formname == "MT_PAUSE_MENU_SETTINGS" && false)
if (m_formname == "MT_PAUSE_MENU") {
if (fields.find("btn_sound") != fields.end()) {
g_gamecallback->changeVolume();
return;
}
else if (fields.find("btn_key_config") != fields.end()) {
g_gamecallback->keyConfig();
return;
}
else if (fields.find("btn_settings") != fields.end()) {
g_gamecallback->showSettings();
}
else if (fields.find("btn_exit_menu") != fields.end()) {
g_gamecallback->disconnect();
return;
}
else if (fields.find("btn_exit_os") != fields.end()) {
g_gamecallback->exitToOS();
#ifndef __ANDROID__
RenderingEngine::get_raw_device()->closeDevice();
#endif
return;
}
else if (fields.find("btn_change_password") != fields.end()) {
g_gamecallback->changePassword();
return;
}
else {
g_gamecallback->unpause();
return;
}
return;
}
if (m_formname == "MT_PAUSE_MENU_SETTINGS")
{
// Loop through settings
for (auto i : fields)
@ -160,7 +201,7 @@ struct LocalFormspecHandler : public TextDest
}
if (i.first.rfind("page_", 0) == 0)
{
//m_client->getScript()->show_settings(i.first.substr(5));
m_client->getScript()->show_settings(i.first.substr(5));
}
//std::cout << "Setting " << i.first << " set!" << std::endl;

@ -310,7 +310,7 @@ void ScriptApiClient::show_pause_menu(bool is_singleplayer, bool is_touchscreen,
lua_pop(L, 1);
}
void ScriptApiClient::show_settings()
void ScriptApiClient::show_settings(const std::string& page)
{
SCRIPTAPI_PRECHECKHEADER
@ -319,7 +319,14 @@ void ScriptApiClient::show_settings()
lua_getglobal(L, "core");
lua_getfield(L, -1, "show_settings");
PCALL_RES(lua_pcall(L, 0, 0, error_handler));
if (page != "")
{
lua_pushstring(L, page.c_str());
}
else
lua_pushnil(L);
PCALL_RES(lua_pcall(L, 1, 0, error_handler));
lua_pop(L, 1);
}

@ -61,7 +61,7 @@ class ScriptApiClient : virtual public ScriptApiBase
bool on_inventory_open(Inventory *inventory);
void show_pause_menu(bool is_singleplayer, bool is_touchscreen, const std::string& server_address);
void show_settings();
void show_settings(const std::string& page = "");
void setEnv(ClientEnvironment *env);
};

@ -23,7 +23,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client/client.h"
#include "client/clientevent.h"
#include "client/sound.h"
#include "client/renderingengine.h"
#include "client/clientenvironment.h"
#include "common/c_content.h"
#include "common/c_converter.h"
@ -179,29 +178,6 @@ int ModApiClient::l_disconnect(lua_State *L)
return 1;
}
// unpause()
int ModApiClient::l_unpause(lua_State *L)
{
g_gamecallback->unpause();
//lua_pushboolean(L, true);
return 1;
}
int ModApiClient::l_exit_to_os(lua_State *L)
{
g_gamecallback->exitToOS();
#ifndef __ANDROID__
RenderingEngine::get_raw_device()->closeDevice();
#endif
return 1;
}
int ModApiClient::l_key_config(lua_State *L)
{
g_gamecallback->keyConfig();
return 1;
}
// gettext(text)
int ModApiClient::l_gettext(lua_State *L)
{
@ -390,9 +366,6 @@ void ModApiClient::Initialize(lua_State *L, int top)
API_FCT(gettext);
API_FCT(get_node_or_nil);
API_FCT(disconnect);
API_FCT(unpause);
API_FCT(exit_to_os);
API_FCT(key_config);
API_FCT(get_meta);
API_FCT(get_server_info);
API_FCT(get_item_def);

@ -50,15 +50,6 @@ class ModApiClient : public ModApiBase
// show_formspec(name, formspec)
static int l_show_formspec(lua_State *L);
// unpause()
static int l_unpause(lua_State *L);
// exit_to_os()
static int l_exit_to_os(lua_State *L);
// key_config()
static int l_key_config(lua_State *L);
// send_respawn()
static int l_send_respawn(lua_State *L);