mirror of
https://github.com/minetest/minetest.git
synced 2024-10-02 07:53:09 +02:00
Compare commits
2 Commits
1f52edb14c
...
b8959a0bac
Author | SHA1 | Date | |
---|---|---|---|
|
b8959a0bac | ||
|
4b74e8d071 |
@ -88,9 +88,29 @@ Menu/inventory open:
|
|||||||
end
|
end
|
||||||
|
|
||||||
function core.show_pause_menu(is_singleplayer, is_touchscreen, address)
|
function core.show_pause_menu(is_singleplayer, is_touchscreen, address)
|
||||||
minetest.show_formspec("MT_PAUSE_MENU", menu_formspec(is_singleplayer, is_touchscreen, address))
|
minetest.show_formspec("builtin:MT_PAUSE_MENU", menu_formspec(is_singleplayer, is_touchscreen, address))
|
||||||
end
|
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 scriptpath = core.get_builtin_path()
|
||||||
local path = scriptpath.."mainmenu"..DIR_DELIM.."settings"
|
local path = scriptpath.."mainmenu"..DIR_DELIM.."settings"
|
||||||
|
|
||||||
@ -107,12 +127,134 @@ function dialog_create(name, spec, buttonhandler, eventhandler)
|
|||||||
minetest.show_formspec(name, spec({}))
|
minetest.show_formspec(name, spec({}))
|
||||||
end
|
end
|
||||||
|
|
||||||
load(true, false)
|
|
||||||
|
|
||||||
function core.show_settings(page_id)
|
local settings_data = {}
|
||||||
if not page_id then
|
settings_data.data = {
|
||||||
show_settings_client_formspec("MT_PAUSE_MENU_SETTINGS", {})
|
leftscroll = 0,
|
||||||
else
|
query = "",
|
||||||
show_settings_client_formspec("MT_PAUSE_MENU_SETTINGS", {page_id = page_id})
|
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
|
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()
|
||||||
end
|
end
|
||||||
|
@ -23,13 +23,13 @@ local shadows_component = dofile(core.get_mainmenu_path() .. DIR_DELIM ..
|
|||||||
"settings" .. DIR_DELIM .. "shadows_component.lua")
|
"settings" .. DIR_DELIM .. "shadows_component.lua")
|
||||||
|
|
||||||
local loaded = false
|
local loaded = false
|
||||||
local full_settings
|
full_settings = {}
|
||||||
local info_icon_path = core.formspec_escape(defaulttexturedir .. "settings_info.png")
|
local info_icon_path = core.formspec_escape(defaulttexturedir .. "settings_info.png")
|
||||||
local reset_icon_path = core.formspec_escape(defaulttexturedir .. "settings_reset.png")
|
local reset_icon_path = core.formspec_escape(defaulttexturedir .. "settings_reset.png")
|
||||||
local all_pages = {}
|
all_pages = {}
|
||||||
local page_by_id = {}
|
page_by_id = {}
|
||||||
local filtered_pages = all_pages
|
filtered_pages = all_pages
|
||||||
local filtered_page_by_id = page_by_id
|
filtered_page_by_id = page_by_id
|
||||||
|
|
||||||
|
|
||||||
local function get_setting_info(name)
|
local function get_setting_info(name)
|
||||||
@ -288,7 +288,7 @@ local function filter_page_content(page, query_keywords)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function update_filtered_pages(query)
|
function update_filtered_pages(query)
|
||||||
filtered_pages = {}
|
filtered_pages = {}
|
||||||
filtered_page_by_id = {}
|
filtered_page_by_id = {}
|
||||||
|
|
||||||
@ -633,12 +633,14 @@ function write_settings_early()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function buttonhandler(this, fields)
|
function buttonhandler(this, fields)
|
||||||
local dialogdata = this.data
|
local dialogdata = this.data
|
||||||
dialogdata.leftscroll = core.explode_scrollbar_event(fields.leftscroll).value or dialogdata.leftscroll
|
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.rightscroll = core.explode_scrollbar_event(fields.rightscroll).value or dialogdata.rightscroll
|
||||||
dialogdata.query = fields.search_query
|
dialogdata.query = fields.search_query
|
||||||
|
|
||||||
|
minetest.log(dump(fields))
|
||||||
|
|
||||||
if fields.back then
|
if fields.back then
|
||||||
this:delete()
|
this:delete()
|
||||||
return true
|
return true
|
||||||
@ -709,6 +711,7 @@ local function buttonhandler(this, fields)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if dialogdata.components then
|
||||||
for i, comp in ipairs(dialogdata.components) do
|
for i, comp in ipairs(dialogdata.components) do
|
||||||
if comp.on_submit and comp:on_submit(fields, this) then
|
if comp.on_submit and comp:on_submit(fields, this) then
|
||||||
write_settings_early()
|
write_settings_early()
|
||||||
@ -726,6 +729,7 @@ local function buttonhandler(this, fields)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
@ -149,48 +149,7 @@ struct LocalFormspecHandler : public TextDest
|
|||||||
|
|
||||||
void gotText(const StringMap &fields)
|
void gotText(const StringMap &fields)
|
||||||
{
|
{
|
||||||
if (m_formname == "MT_PAUSE_MENU") {
|
if (m_formname == "MT_PAUSE_MENU_SETTINGS" && false)
|
||||||
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
|
// Loop through settings
|
||||||
for (auto i : fields)
|
for (auto i : fields)
|
||||||
@ -201,7 +160,7 @@ struct LocalFormspecHandler : public TextDest
|
|||||||
}
|
}
|
||||||
if (i.first.rfind("page_", 0) == 0)
|
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;
|
//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);
|
lua_pop(L, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptApiClient::show_settings(const std::string& page)
|
void ScriptApiClient::show_settings()
|
||||||
{
|
{
|
||||||
SCRIPTAPI_PRECHECKHEADER
|
SCRIPTAPI_PRECHECKHEADER
|
||||||
|
|
||||||
@ -319,14 +319,7 @@ void ScriptApiClient::show_settings(const std::string& page)
|
|||||||
lua_getglobal(L, "core");
|
lua_getglobal(L, "core");
|
||||||
lua_getfield(L, -1, "show_settings");
|
lua_getfield(L, -1, "show_settings");
|
||||||
|
|
||||||
if (page != "")
|
PCALL_RES(lua_pcall(L, 0, 0, error_handler));
|
||||||
{
|
|
||||||
lua_pushstring(L, page.c_str());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
lua_pushnil(L);
|
|
||||||
|
|
||||||
PCALL_RES(lua_pcall(L, 1, 0, error_handler));
|
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ public:
|
|||||||
bool on_inventory_open(Inventory *inventory);
|
bool on_inventory_open(Inventory *inventory);
|
||||||
|
|
||||||
void show_pause_menu(bool is_singleplayer, bool is_touchscreen, const std::string& server_address);
|
void show_pause_menu(bool is_singleplayer, bool is_touchscreen, const std::string& server_address);
|
||||||
void show_settings(const std::string& page = "");
|
void show_settings();
|
||||||
|
|
||||||
void setEnv(ClientEnvironment *env);
|
void setEnv(ClientEnvironment *env);
|
||||||
};
|
};
|
||||||
|
@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "client/client.h"
|
#include "client/client.h"
|
||||||
#include "client/clientevent.h"
|
#include "client/clientevent.h"
|
||||||
#include "client/sound.h"
|
#include "client/sound.h"
|
||||||
|
#include "client/renderingengine.h"
|
||||||
#include "client/clientenvironment.h"
|
#include "client/clientenvironment.h"
|
||||||
#include "common/c_content.h"
|
#include "common/c_content.h"
|
||||||
#include "common/c_converter.h"
|
#include "common/c_converter.h"
|
||||||
@ -178,6 +179,29 @@ int ModApiClient::l_disconnect(lua_State *L)
|
|||||||
return 1;
|
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)
|
// gettext(text)
|
||||||
int ModApiClient::l_gettext(lua_State *L)
|
int ModApiClient::l_gettext(lua_State *L)
|
||||||
{
|
{
|
||||||
@ -366,6 +390,9 @@ void ModApiClient::Initialize(lua_State *L, int top)
|
|||||||
API_FCT(gettext);
|
API_FCT(gettext);
|
||||||
API_FCT(get_node_or_nil);
|
API_FCT(get_node_or_nil);
|
||||||
API_FCT(disconnect);
|
API_FCT(disconnect);
|
||||||
|
API_FCT(unpause);
|
||||||
|
API_FCT(exit_to_os);
|
||||||
|
API_FCT(key_config);
|
||||||
API_FCT(get_meta);
|
API_FCT(get_meta);
|
||||||
API_FCT(get_server_info);
|
API_FCT(get_server_info);
|
||||||
API_FCT(get_item_def);
|
API_FCT(get_item_def);
|
||||||
|
@ -51,6 +51,15 @@ private:
|
|||||||
// show_formspec(name, formspec)
|
// show_formspec(name, formspec)
|
||||||
static int l_show_formspec(lua_State *L);
|
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()
|
// send_respawn()
|
||||||
static int l_send_respawn(lua_State *L);
|
static int l_send_respawn(lua_State *L);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user