From bd3cdbb23d48bdfd41d1178583ad052e7c0e588f Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Mon, 13 Sep 2021 04:08:11 +0200 Subject: [PATCH] Some fixes --- src/client/game/ui_scripting/lua/context.cpp | 1 + src/client/game/ui_scripting/lua/engine.cpp | 4 +- src/client/resources/animation.lua | 115 ++++++++++--------- 3 files changed, 63 insertions(+), 57 deletions(-) diff --git a/src/client/game/ui_scripting/lua/context.cpp b/src/client/game/ui_scripting/lua/context.cpp index 6ee57f9a..77d8971f 100644 --- a/src/client/game/ui_scripting/lua/context.cpp +++ b/src/client/game/ui_scripting/lua/context.cpp @@ -757,6 +757,7 @@ namespace ui_scripting::lua { this->state_.collect_garbage(); this->scheduler_.clear(); + this->event_handler_.clear(); this->state_ = {}; } diff --git a/src/client/game/ui_scripting/lua/engine.cpp b/src/client/game/ui_scripting/lua/engine.cpp index cdc60b94..eee59987 100644 --- a/src/client/game/ui_scripting/lua/engine.cpp +++ b/src/client/game/ui_scripting/lua/engine.cpp @@ -358,15 +358,15 @@ namespace ui_scripting::lua::engine void start() { - clear_menus(); get_scripts().clear(); + clear_menus(); load_scripts(); } void stop() { - clear_menus(); get_scripts().clear(); + clear_menus(); } void ui_event(const std::string& type, const std::vector& arguments) diff --git a/src/client/resources/animation.lua b/src/client/resources/animation.lua index 3bff9bea..0294c264 100644 --- a/src/client/resources/animation.lua +++ b/src/client/resources/animation.lua @@ -1,86 +1,91 @@ -function element:animate(state, animationtime) - self:notify("cancel_animation") +function element:animate(name, state, animationtime) + local start = { + x = self.x, + y = self.y, + w = self.w, + h = self.h, + color = self.color, + backcolor = self.backcolor, + bordercolor = self.bordercolor, + borderwidth = self.borderwidth, + fontsize = self.fontsize + } - local doanimation = function() - local start = { - x = self.x, - y = self.y, - w = self.w, - h = self.h, - color = self.color, - backcolor = self.backcolor, - bordercolor = self.bordercolor, - borderwidth = self.borderwidth, - fontsize = self.fontsize - } - - local _end = {} - for k, v in pairs(start) do - _end[k] = state[k] or v - end + local _end = {} + for k, v in pairs(start) do + _end[k] = state[k] or v + end - local diffs = {} - for k, v in pairs(_end) do - if (type(v) == "table") then - local value = {} + local diffs = {} + for k, v in pairs(_end) do + if (type(v) == "table") then + local value = {} + local different = false - for _k, _v in pairs(v) do - value[_k] = _v - start[k][_k] + for _k, _v in pairs(v) do + value[_k] = _v - start[k][_k] + if (value[_k] ~= 0) then + different = true end + end + if (different) then diffs[k] = value - else + end + else + local value = v - start[k] + if (value ~= 0) then diffs[k] = v - start[k] end end - - local timeout = nil - local interval = nil - local starttime = game:time() + end - interval = game:onframe(function() - local time = game:time() - local percentage = (time - starttime) / animationtime - if (percentage >= 1) then - for k, v in pairs(_end) do - self[k] = v - end - return + local timeout = nil + local interval = nil + local starttime = game:time() + + interval = game:onframe(function() + local time = game:time() + local percentage = (time - starttime) / animationtime + + if (percentage >= 1) then + for k, v in pairs(diffs) do + self[k] = _end[k] end - + else for k, v in pairs(diffs) do if (type(v) == "table") then local value = {} - + for _k, _v in pairs(v) do value[_k] = start[k][_k] + _v * percentage end - + self[k] = value else self[k] = start[k] + v * percentage end end - end) + end + end) - timeout = game:ontimeout(function() - interval:clear() - for k, v in pairs(_end) do - self[k] = v - end - end, animationtime) + timeout = game:ontimeout(function() + interval:clear() + for k, v in pairs(diffs) do + self[k] = _end[k] + end + end, animationtime) - self:onnotifyonce("cancel_animation", function() + self:onnotifyonce("cancel_animation", function(_name) + if (name == _name) then timeout:clear() interval:clear() - end) - end - - game:ontimeout(doanimation, 0) + end + end) end -function element:cancelanimations(callback) - self:notify("cancel_animation") +function element:cancelanimations(name, callback) + self:notify("cancel_animation", name) if (type(callback) == "function") then game:ontimeout(callback, 0) end