This commit is contained in:
Yoruma 2024-12-24 02:49:55 +08:00 committed by GitHub
commit 13311cfa28
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 81 additions and 0 deletions

View file

@ -1,5 +1,6 @@
--[========[Game Interface Control]========]
local queued_movements = {}
if wesnoth.kernel_type() == "Game Lua Kernel" then
print("Loading interface module...")
@ -36,6 +37,44 @@ if wesnoth.kernel_type() == "Game Lua Kernel" then
moving_unit:to_map(to_x, to_y)
wesnoth.wml_actions.redraw{}
end
---@param u unit
---@param to_x integer
---@param to_y integer
---@param queued boolean
---@param scroll boolean
function wesnoth.interface.move_unit_fake_queue(u, to_x, to_y, queued, scroll)
if to_x and to_y and u then
if scroll == nil then
scroll = true
end
table.insert(queued_movements, { to_x = to_x, to_y = to_y, u = u, scroll = scroll })
end
if queued then
return
end
for _index, move in ipairs(queued_movements) do
local moving_unit = move.u
local from_x, from_y = moving_unit.x, moving_unit.y
if move.scroll then
wesnoth.interface.scroll_to_hex(from_x, from_y)
end
to_x, to_y = wesnoth.paths.find_vacant_hex(move.to_x, move.to_y, moving_unit)
moving_unit.facing = wesnoth.map.get_relative_dir(from_x, from_y, to_x, to_y)
moving_unit.hidden = true;
wesnoth.wml_actions.move_unit_fake {
type = moving_unit.type,
gender = moving_unit.gender,
variation = moving_unit.variation,
side = moving_unit.side,
x = from_x .. ',' .. to_x,
y = from_y .. ',' .. to_y
}
wesnoth.wml_actions.redraw {}
moving_unit.hidden = false;
end
queued_movements = {}
end
wesnoth.delay = wesnoth.deprecate_api('wesnoth.delay', 'wesnoth.interface.delay', 1, nil, wesnoth.interface.delay)
wesnoth.float_label = wesnoth.deprecate_api('wesnoth.float_label', 'wesnoth.interface.float_label', 1, nil, wesnoth.interface.float_label)

View file

@ -371,6 +371,28 @@ static int impl_add_animation(lua_State* L)
return 0;
}
// Todo: make a C++ impl to replace this method.
int game_lua_kernel::impl_add_movement(lua_State* L)
{
lua_getglobal(L, "wesnoth");
lua_getfield(L, -1, "interface");
lua_getfield(L, -1, "move_unit_fake_queue");
luaW_pushunit(L, luaW_checkunit_ptr(L, 2, false));
{
map_location temp = luaW_checklocation(L, 3);
lua_pushinteger(L, temp.wml_x());
lua_pushinteger(L, temp.wml_y());
}
lua_pushboolean(L, true);
if(lua_isnoneornil(L, 4)) {
lua_pushnil(L);
} else {
lua_pushboolean(L, luaW_toboolean(L, 4));
}
lua_call(L, 5, 0);
return 0;
}
int game_lua_kernel::impl_run_animation(lua_State* L)
{
if(video::headless() || resources::controller->is_skipping_replay()) {
@ -379,6 +401,16 @@ int game_lua_kernel::impl_run_animation(lua_State* L)
events::command_disabler command_disabler;
unit_animator& anim = *static_cast<unit_animator*>(luaL_checkudata(L, 1, animatorKey));
play_controller_.play_slice();
lua_getglobal(L, "wesnoth");
lua_getfield(L, -1, "interface");
lua_getfield(L, -1, "move_unit_fake_queue");
lua_pushnil(L);
lua_pushnil(L);
lua_pushnil(L);
lua_pushboolean(L, false);
lua_pushnil(L);
lua_call(L, 5, 0);
anim.start_animations();
anim.wait_for_end();
anim.set_all_standing();
@ -407,6 +439,7 @@ int game_lua_kernel::intf_create_animator(lua_State* L)
{"__gc", impl_animator_collect},
{"__index", impl_animator_get},
{"add", impl_add_animation},
{"add_movement", &dispatch<&game_lua_kernel::impl_add_movement>},
{"run", &dispatch<&game_lua_kernel::impl_run_animation>},
{"clear", impl_clear_animation},
{nullptr, nullptr},

View file

@ -83,6 +83,7 @@ class game_lua_kernel : public lua_kernel_base
int intf_animate_unit(lua_State *);
int intf_gamestate_inspector(lua_State *);
int impl_run_animation(lua_State *);
int impl_add_movement(lua_State* L);
int intf_create_animator(lua_State *);
int intf_get_unit(lua_State *);
int intf_get_units(lua_State *);

View file

@ -247,6 +247,14 @@ function animator:clear() end
---@param params unit_animator_params
function animator:add(unit, flag, hits, params) end
---Add a unit to the movement animation queue
---@param unit unit
---@param to_x integer
---@param to_y integer
---@param scroll boolean
---@overload fun(u:unit, target:location, scroll:boolean)
function animator:add_movement(unit, to_x, to_y, scroll) end
---@return unit_animator
function wesnoth.units.create_animator() end