From fb6cb8d4be608b420faaea96dafa344571176850 Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Fri, 25 Sep 2020 00:24:25 -0400 Subject: [PATCH] Apply the deprecation standard to the new GUI2 API This also removes backwards-compatibility.lua altogether. It's no longer correct in the general case to add backwards compatibility code to this file, so removing it entirely avoids situations where compatibility code is incorrectly added there. --- data/core/_main.cfg | 1 - data/lua/backwards-compatibility.lua | 96 ------------------------- data/lua/core.lua | 102 +++++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 97 deletions(-) delete mode 100644 data/lua/backwards-compatibility.lua diff --git a/data/core/_main.cfg b/data/core/_main.cfg index c2612d1a4b514..25c4b6fdcf43c 100644 --- a/data/core/_main.cfg +++ b/data/core/_main.cfg @@ -8,7 +8,6 @@ wesnoth.dofile 'lua/wml-tags.lua' wesnoth.dofile 'lua/feeding.lua' wesnoth.dofile 'lua/diversion.lua' -wesnoth.dofile 'lua/backwards-compatibility.lua' >> [/lua] diff --git a/data/lua/backwards-compatibility.lua b/data/lua/backwards-compatibility.lua deleted file mode 100644 index 72ba23e897bb7..0000000000000 --- a/data/lua/backwards-compatibility.lua +++ /dev/null @@ -1,96 +0,0 @@ ---! #textdomain wesnoth - --- This file may provide an implementation of Lua functions removed from the engine. - -wesnoth.set_music = wesnoth.deprecate_api('wesnoth.set_music', 'wesnoth.music_list', 1, nil, wesnoth.wml_actions.music) - --- Calling wesnoth.fire isn't the same as calling wesnoth.wml_actions[name] due to the passed vconfig userdata --- which also provides "constness" of the passed wml object from the point of view of the caller. --- So please don't remove since it's not deprecated. -function wesnoth.fire(name, cfg) - wesnoth.wml_actions[name](wml.tovconfig(cfg or {})) -end - -local open_dialogs = {} - -local function reorder_dialog_args(t, n) - local res = {} - for i = 1, n do - table.insert( res, t[1]) - table.remove( t, 1 ) - end - local w = open_dialogs[1]:find(unpack(t)) - return w, res -end - -function wesnoth.set_dialog_callback(...) - local w, args = reorder_dialog_args({...}, 1) - w.callback = args[1] -end - -function wesnoth.set_dialog_tooltip(...) - local w, args = reorder_dialog_args({...}, 1) - w.tooltip = args[1] -end - -function wesnoth.set_dialog_markup(...) - local w, args = reorder_dialog_args({...}, 1) - w.use_markup = args[1] -end - -function wesnoth.set_dialog_canvas(...) - local w, args = reorder_dialog_args({...}, 2) - w:set_canvas(unpack(args)) -end - -function wesnoth.set_dialog_focus(...) - local w, args = reorder_dialog_args({...}, 0) - w:focus() -end - -function wesnoth.set_dialog_active(...) - local w, args = reorder_dialog_args({...}, 1) - w.enabled = args[1] -end - -function wesnoth.set_dialog_visible(...) - local w, args = reorder_dialog_args({...}, 1) - w.visible = args[1] -end - -function wesnoth.set_dialog_value(...) - local w, args = reorder_dialog_args({...}, 1) - w.value_compat = args[1] -end - -function wesnoth.get_dialog_value(...) - local w, args = reorder_dialog_args({...}, 0) - return w.value_compat -end - -function wesnoth.add_dialog_tree_node(...) - local w, args = reorder_dialog_args({...}, 2) - w:add_item_of_type(unpack(args)) -end - -function wesnoth.remove_dialog_item(...) - local w, args = reorder_dialog_args({...}, 2) - w:remove_items_at(unpack(args)) -end - -local old_show_dialog = wesnoth.show_dialog -function wesnoth.show_dialog(dialog_wml, preshow, postshow) - - local res = old_show_dialog( - dialog_wml, - function(dialog) - table.insert(open_dialogs, 1, dialog) - if preshow then - preshow(dialog) - end - end, - postshow - ) - table.remove( open_dialogs, 1 ) - return res -end diff --git a/data/lua/core.lua b/data/lua/core.lua index f210e6d93a88f..dfb2df67994d1 100644 --- a/data/lua/core.lua +++ b/data/lua/core.lua @@ -681,6 +681,91 @@ function gui.get_user_choice(attr, options) return result end +-- These functions are initially declared local, then assigned into the wesnoth table. +local open_dialogs = {} + +local function reorder_dialog_args(t, n) + local res = {} + for i = 1, n do + table.insert( res, t[1]) + table.remove( t, 1 ) + end + local w = open_dialogs[1]:find(unpack(t)) + return w, res +end + +local function set_dialog_callback(...) + local w, args = reorder_dialog_args({...}, 1) + w.callback = args[1] +end + +local function set_dialog_tooltip(...) + local w, args = reorder_dialog_args({...}, 1) + w.tooltip = args[1] +end + +local function set_dialog_markup(...) + local w, args = reorder_dialog_args({...}, 1) + w.use_markup = args[1] +end + +local function set_dialog_canvas(...) + local w, args = reorder_dialog_args({...}, 2) + w:set_canvas(unpack(args)) +end + +local function set_dialog_focus(...) + local w, args = reorder_dialog_args({...}, 0) + w:focus() +end + +local function set_dialog_active(...) + local w, args = reorder_dialog_args({...}, 1) + w.enabled = args[1] +end + +local function set_dialog_visible(...) + local w, args = reorder_dialog_args({...}, 1) + w.visible = args[1] +end + +local function set_dialog_value(...) + local w, args = reorder_dialog_args({...}, 1) + w.value_compat = args[1] +end + +local function get_dialog_value(...) + local w, args = reorder_dialog_args({...}, 0) + return w.value_compat +end + +local function add_dialog_tree_node(...) + local w, args = reorder_dialog_args({...}, 2) + w:add_item_of_type(unpack(args)) +end + +local function remove_dialog_item(...) + local w, args = reorder_dialog_args({...}, 2) + w:remove_items_at(unpack(args)) +end + +local old_show_dialog = wesnoth.show_dialog +function gui.show_dialog(dialog_wml, preshow, postshow) + + local res = old_show_dialog( + dialog_wml, + function(dialog) + table.insert(open_dialogs, 1, dialog) + if preshow then + preshow(dialog) + end + end, + postshow + ) + table.remove( open_dialogs, 1 ) + return res +end + -- Some C++ functions are deprecated; apply the messages here. -- Note: It must happen AFTER the C++ functions are reassigned above to their new location. -- These deprecated functions will probably never be removed. @@ -752,6 +837,10 @@ if wesnoth.kernel_type() == "Game Lua Kernel" then wesnoth.delete_ai_component = wesnoth.deprecate_api('wesnoth.delete_ai_component', 'wesnoth.sides.delete_ai_component', 1, nil, wesnoth.sides.delete_ai_component) wesnoth.change_ai_component = wesnoth.deprecate_api('wesnoth.change_ai_component', 'wesnoth.sides.change_ai_component', 1, nil, wesnoth.sides.change_ai_component) wesnoth.get_sides = wesnoth.deprecate_api('wesnoth.get_sides', 'wesnoth.sides.find', 1, nil, wesnoth.sides.find) + wesnoth.set_music = wesnoth.deprecate_api('wesnoth.set_music', 'wesnoth.music_list', 1, nil, wesnoth.wml_actions.music) + wesnoth.fire = wesnoth.deprecate_api('wesnoth.fire', 'wesnoth.wml_actions', 1, nil, function(name, cfg) + wesnoth.wml_actions[name](wml.tovconfig(cfg or {})) + end); end wesnoth.tovconfig = wesnoth.deprecate_api('wesnoth.tovconfig', 'wml.tovconfig', 1, nil, wml.tovconfig) wesnoth.debug = wesnoth.deprecate_api('wesnoth.debug', 'wml.tostring', 1, nil, wml.tostring) @@ -765,6 +854,19 @@ wesnoth.alert = wesnoth.deprecate_api('wesnoth.alert', 'gui.alert', 1, nil, gui. wesnoth.confirm = wesnoth.deprecate_api('wesnoth.confirm', 'gui.confirm', 1, nil, gui.confirm) wesnoth.show_lua_console = wesnoth.deprecate_api('wesnoth.show_lua_console', 'gui.show_lua_console', 1, nil, gui.show_lua_console) wesnoth.add_widget_definition = wesnoth.deprecate_api('wesnoth.add_widget_definition', 'gui.add_widget_definition', 1, nil, gui.add_widget_definition) +wesnoth.set_dialog_callback = wesnoth.deprecate_api('wesnoth.set_dialog_callback', '.callback', 1, nil, set_dialog_callback) +wesnoth.set_dialog_tooltip = wesnoth.deprecate_api('wesnoth.set_dialog_tooltip', '.tooltip', 1, nil, set_dialog_tooltip) +wesnoth.set_dialog_markup = wesnoth.deprecate_api('wesnoth.set_dialog_markup', '.use_markup', 1, nil, set_dialog_markup) +wesnoth.set_dialog_canvas = wesnoth.deprecate_api('wesnoth.set_dialog_canvas', ':set_canvas', 1, nil, set_dialog_canvas) +wesnoth.set_dialog_focus = wesnoth.deprecate_api('wesnoth.set_dialog_focus', ':focus', 1, nil, set_dialog_focus) +wesnoth.set_dialog_active = wesnoth.deprecate_api('wesnoth.set_dialog_active', ':enabled', 1, nil, set_dialog_active) +wesnoth.set_dialog_visible = wesnoth.deprecate_api('wesnoth.set_dialog_visible', '.visible', 1, nil, set_dialog_visible) +local value_attributes = '.selected_index or .selected or .text or .value or .percentage or .selected_item_path or .unfolded or .unit or .label' +wesnoth.set_dialog_value = wesnoth.deprecate_api('wesnoth.set_dialog_value', value_attributes, 1, nil, set_dialog_value) +wesnoth.get_dialog_value = wesnoth.deprecate_api('wesnoth.get_dialog_value', value_attributes, 1, nil, get_dialog_value) +wesnoth.add_dialog_tree_node = wesnoth.deprecate_api('wesnoth.add_dialog_tree_node', ':add_item_of_type', 1, nil, add_dialog_tree_node) +wesnoth.remove_dialog_item = wesnoth.deprecate_api('wesnoth.remove_dialog_item', ':remove_items_at', 1, nil, remove_dialog_item) +wesnoth.show_dialog = wesnoth.deprecate_api('wesnoth.show_dialog', 'gui.show_dialog', 1, nil, gui.show_dialog) -- StringX module wesnoth.format = wesnoth.deprecate_api('wesnoth.format', 'stringx.vformat', 1, nil, stringx.vformat) wesnoth.format_conjunct_list = wesnoth.deprecate_api('wesnoth.format_conjunct_list', 'stringx.format_conjunct_list', 1, nil, stringx.format_conjunct_list)