-
-
Notifications
You must be signed in to change notification settings - Fork 994
/
backwards-compatibility.lua
96 lines (78 loc) · 2.35 KB
/
backwards-compatibility.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
--! #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