mirror of
https://github.com/Insality/druid
synced 2025-06-27 10:27:48 +02:00
Update
This commit is contained in:
parent
d182bcef7c
commit
c4694b421b
@ -1,7 +1,7 @@
|
|||||||
name: "repeat"
|
name: "repeat"
|
||||||
tags: "gui"
|
tags: "gui"
|
||||||
vertex_program: "/druid/materials/gui_tiling_node/gui_tiling_node.vp"
|
vertex_program: "/druid/custom/tiling_node/gui_tiling_node.vp"
|
||||||
fragment_program: "/druid/materials/gui_tiling_node/gui_tiling_node.fp"
|
fragment_program: "/druid/custom/tiling_node/gui_tiling_node.fp"
|
||||||
vertex_constants {
|
vertex_constants {
|
||||||
name: "view_proj"
|
name: "view_proj"
|
||||||
type: CONSTANT_TYPE_VIEWPROJ
|
type: CONSTANT_TYPE_VIEWPROJ
|
@ -24,6 +24,10 @@ function M:init(node)
|
|||||||
|
|
||||||
self.params = gui.get(self.node, "params") --[[@as vector4]]
|
self.params = gui.get(self.node, "params") --[[@as vector4]]
|
||||||
|
|
||||||
|
self.timer_no_init = timer.delay(0.1, false, function()
|
||||||
|
print("The druid.script is not found, please add it nearby to the GUI collection", msg.url())
|
||||||
|
end)
|
||||||
|
|
||||||
defer.push("druid.get_atlas_path", {
|
defer.push("druid.get_atlas_path", {
|
||||||
texture_name = gui.get_texture(self.node),
|
texture_name = gui.get_texture(self.node),
|
||||||
sender = msg.url(),
|
sender = msg.url(),
|
||||||
@ -31,26 +35,30 @@ function M:init(node)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
---@param atlas_path string
|
||||||
function M:on_get_atlas_path(atlas_path)
|
function M:on_get_atlas_path(atlas_path)
|
||||||
|
timer.cancel(self.timer_no_init)
|
||||||
self.is_inited = self:init_tiling_animation(atlas_path)
|
self.is_inited = self:init_tiling_animation(atlas_path)
|
||||||
local repeat_x, repeat_y = self:get_repeat()
|
local repeat_x, repeat_y = self:get_repeat_count_from_node()
|
||||||
self:refresh(repeat_x, repeat_y)
|
self:start_animation(repeat_x, repeat_y)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
---@param node node
|
||||||
|
---@param property string
|
||||||
function M:on_node_property_changed(node, property)
|
function M:on_node_property_changed(node, property)
|
||||||
if not self.is_inited or node ~= self.node then
|
if not self.is_inited or node ~= self.node then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if property == "size" or property == "scale" then
|
if property == "size" or property == "scale" then
|
||||||
local repeat_x, repeat_y = self:get_repeat()
|
local repeat_x, repeat_y = self:get_repeat_count_from_node()
|
||||||
self:set_repeat(repeat_x, repeat_y)
|
self:set_repeat(repeat_x, repeat_y)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function M:get_repeat()
|
function M:get_repeat_count_from_node()
|
||||||
if not self.is_inited then
|
if not self.is_inited then
|
||||||
return 1, 1
|
return 1, 1
|
||||||
end
|
end
|
||||||
@ -66,6 +74,7 @@ function M:get_repeat()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
---@param atlas_path string
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function M:init_tiling_animation(atlas_path)
|
function M:init_tiling_animation(atlas_path)
|
||||||
if not atlas_path then
|
if not atlas_path then
|
||||||
@ -82,21 +91,21 @@ end
|
|||||||
-- Start our repeat shader work
|
-- Start our repeat shader work
|
||||||
---@param repeat_x number X factor
|
---@param repeat_x number X factor
|
||||||
---@param repeat_y number Y factor
|
---@param repeat_y number Y factor
|
||||||
function M:refresh(repeat_x, repeat_y)
|
function M:start_animation(repeat_x, repeat_y)
|
||||||
if not self.is_inited then
|
if not self.is_inited then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self:set_repeat(repeat_x, repeat_y)
|
||||||
|
|
||||||
local node = self.node
|
local node = self.node
|
||||||
local animation = self.animation
|
local animation = self.animation
|
||||||
|
|
||||||
local frame = animation.frames[1]
|
local frame = animation.frames[1]
|
||||||
gui.set(node, "uv_coord", frame.uv_coord)
|
gui.set(node, "uv_coord", frame.uv_coord)
|
||||||
self:set_repeat(repeat_x, repeat_y)
|
|
||||||
|
|
||||||
if #animation.frames > 1 and animation.fps > 0 then
|
if #animation.frames > 1 and animation.fps > 0 then
|
||||||
animation.handle =
|
animation.handle =
|
||||||
timer.delay(1/animation.fps, true, function(self, handle, time_elapsed)
|
timer.delay(1/animation.fps, true, function(_, handle, time_elapsed)
|
||||||
local next_rame = animation.frames[animation.current_frame]
|
local next_rame = animation.frames[animation.current_frame]
|
||||||
gui.set(node, "uv_coord", next_rame.uv_coord)
|
gui.set(node, "uv_coord", next_rame.uv_coord)
|
||||||
|
|
||||||
@ -134,6 +143,8 @@ function M:set_repeat(repeat_x, repeat_y)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
---@param offset_perc_x number? X offset
|
||||||
|
---@param offset_perc_y number? Y offset
|
||||||
function M:set_offset(offset_perc_x, offset_perc_y)
|
function M:set_offset(offset_perc_x, offset_perc_y)
|
||||||
self.params.z = offset_perc_x or self.params.z
|
self.params.z = offset_perc_x or self.params.z
|
||||||
self.params.w = offset_perc_y or self.params.w
|
self.params.w = offset_perc_y or self.params.w
|
||||||
@ -142,6 +153,8 @@ function M:set_offset(offset_perc_x, offset_perc_y)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
---@param margin_x number? X margin
|
||||||
|
---@param margin_y number? Y margin
|
||||||
function M:set_margin(margin_x, margin_y)
|
function M:set_margin(margin_x, margin_y)
|
||||||
self.params.x = margin_x or self.params.x
|
self.params.x = margin_x or self.params.x
|
||||||
self.params.y = margin_y or self.params.y
|
self.params.y = margin_y or self.params.y
|
@ -367,6 +367,14 @@ function M.get_pivot_offset(pivot_or_node)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
---Check if device is desktop
|
||||||
|
---@return boolean
|
||||||
|
function M.is_desktop()
|
||||||
|
return const.CURRENT_SYSTEM_NAME == const.OS.WINDOWS or const.CURRENT_SYSTEM_NAME == const.OS.MAC or const.CURRENT_SYSTEM_NAME == const.OS.LINUX
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
---Check if device is native mobile (Android or iOS)
|
---Check if device is native mobile (Android or iOS)
|
||||||
---@return boolean Is mobile
|
---@return boolean Is mobile
|
||||||
function M.is_mobile()
|
function M.is_mobile()
|
||||||
|
@ -2,6 +2,7 @@ local lang = require("lang.lang")
|
|||||||
local saver = require("saver.saver")
|
local saver = require("saver.saver")
|
||||||
local storage = require("saver.storage")
|
local storage = require("saver.storage")
|
||||||
local druid = require("druid.druid")
|
local druid = require("druid.druid")
|
||||||
|
local helper = require("druid.helper")
|
||||||
|
|
||||||
local druid_logo = require("example.components.druid_logo.druid_logo")
|
local druid_logo = require("example.components.druid_logo.druid_logo")
|
||||||
local panel_information = require("example.components.panel_information.panel_information")
|
local panel_information = require("example.components.panel_information.panel_information")
|
||||||
@ -35,12 +36,16 @@ local druid_examples = require("example.examples.druid_examples")
|
|||||||
---@field output_list output_list
|
---@field output_list output_list
|
||||||
|
|
||||||
|
|
||||||
|
---@param self druid.example
|
||||||
|
local function setup_saver(self)
|
||||||
|
saver.init()
|
||||||
|
saver.bind_save_state("lang", lang.state)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Generic setup that should be done once per application
|
--- Generic setup that should be done once per application
|
||||||
---@param self druid.example
|
---@param self druid.example
|
||||||
local function setup_druid(self)
|
local function setup_druid(self)
|
||||||
saver.init()
|
|
||||||
saver.bind_save_state("lang", lang.state)
|
|
||||||
|
|
||||||
lang.init()
|
lang.init()
|
||||||
lang.set_lang("en") -- Force default start language to EN, switch through the UI to check
|
lang.set_lang("en") -- Force default start language to EN, switch through the UI to check
|
||||||
druid.set_text_function(lang.txp)
|
druid.set_text_function(lang.txp)
|
||||||
@ -172,8 +177,38 @@ local function setup_examples(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
---@param self druid.example
|
||||||
|
local function setup_defos(self)
|
||||||
|
local is_desktop = helper.is_desktop()
|
||||||
|
local is_debug = sys.get_engine_info().is_debug
|
||||||
|
|
||||||
|
if is_desktop and is_debug then
|
||||||
|
timer.delay(1, true, function()
|
||||||
|
local x, y, w, h = defos.get_window_size()
|
||||||
|
saver.set_value("window.last_state", { x, y, w, h })
|
||||||
|
saver.save_game_state()
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Restore window size and position
|
||||||
|
local prev_settings = saver.get_value("window.last_state")
|
||||||
|
if prev_settings then
|
||||||
|
---@cast prev_settings number[]
|
||||||
|
local x, y, w, h = unpack(prev_settings)
|
||||||
|
-- Limit size to 300x200
|
||||||
|
x = vmath.clamp(x, 0, 4000)
|
||||||
|
y = vmath.clamp(y, 0, 4000)
|
||||||
|
w = vmath.clamp(w, 300, 4000)
|
||||||
|
h = vmath.clamp(h, 200, 4000)
|
||||||
|
defos.set_window_size(x, y, w, h)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
---@param self druid.example
|
---@param self druid.example
|
||||||
function init(self)
|
function init(self)
|
||||||
|
setup_saver(self)
|
||||||
|
setup_defos(self)
|
||||||
setup_druid(self)
|
setup_druid(self)
|
||||||
|
|
||||||
self.druid = druid.new(self)
|
self.druid = druid.new(self)
|
||||||
|
@ -30,5 +30,5 @@ material: "/builtins/materials/gui.material"
|
|||||||
adjust_reference: ADJUST_REFERENCE_PARENT
|
adjust_reference: ADJUST_REFERENCE_PARENT
|
||||||
materials {
|
materials {
|
||||||
name: "gui_tiling_node"
|
name: "gui_tiling_node"
|
||||||
material: "/druid/materials/gui_tiling_node/gui_tiling_node.material"
|
material: "/druid/custom/tiling_node/gui_tiling_node.material"
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
local tiling_node = require("druid.widget.tiling_node.tiling_node")
|
local tiling_node = require("druid.custom.tiling_node.tiling_node")
|
||||||
|
|
||||||
---@class examples.example_tiling_node: druid.widget
|
---@class examples.example_tiling_node: druid.widget
|
||||||
local M = {}
|
local M = {}
|
||||||
|
@ -19,11 +19,11 @@ publisher = Insality
|
|||||||
developer = Maksim Tuprikov
|
developer = Maksim Tuprikov
|
||||||
custom_resources = /example/locales
|
custom_resources = /example/locales
|
||||||
dependencies#0 = https://github.com/britzl/deftest/archive/refs/tags/2.8.0.zip
|
dependencies#0 = https://github.com/britzl/deftest/archive/refs/tags/2.8.0.zip
|
||||||
dependencies#1 = https://github.com/Insality/defold-saver/archive/refs/tags/1.zip
|
dependencies#1 = https://github.com/Insality/defold-saver/archive/refs/heads/develop.zip
|
||||||
dependencies#2 = https://github.com/Insality/defold-tweener/archive/refs/tags/3.zip
|
dependencies#2 = https://github.com/Insality/defold-tweener/archive/refs/tags/3.zip
|
||||||
dependencies#3 = https://github.com/Insality/panthera/archive/refs/heads/develop.zip
|
dependencies#3 = https://github.com/Insality/panthera/archive/refs/heads/develop.zip
|
||||||
dependencies#4 = https://github.com/Insality/defold-lang/archive/refs/tags/3.zip
|
dependencies#4 = https://github.com/Insality/defold-lang/archive/refs/tags/3.zip
|
||||||
dependencies#5 = https://github.com/Insality/defold-event/archive/refs/tags/10.zip
|
dependencies#5 = https://github.com/Insality/defold-event/archive/refs/heads/develop.zip
|
||||||
dependencies#6 = https://github.com/subsoap/defos/archive/refs/tags/v2.8.0.zip
|
dependencies#6 = https://github.com/subsoap/defos/archive/refs/tags/v2.8.0.zip
|
||||||
|
|
||||||
[library]
|
[library]
|
||||||
|
@ -6,7 +6,6 @@ return function()
|
|||||||
local druid_system = nil
|
local druid_system = nil
|
||||||
|
|
||||||
local druid = nil
|
local druid = nil
|
||||||
local context = nil
|
|
||||||
|
|
||||||
describe("Blocker component", function()
|
describe("Blocker component", function()
|
||||||
before(function()
|
before(function()
|
||||||
@ -20,15 +19,13 @@ return function()
|
|||||||
mock_time.mock()
|
mock_time.mock()
|
||||||
mock_time.set(60)
|
mock_time.set(60)
|
||||||
|
|
||||||
context = test_helper.get_context()
|
druid = druid_system.new({})
|
||||||
druid = druid_system.new(context)
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
after(function()
|
after(function()
|
||||||
mock_gui.unmock()
|
mock_gui.unmock()
|
||||||
mock_time.unmock()
|
mock_time.unmock()
|
||||||
druid:final(context)
|
druid:final()
|
||||||
druid = nil
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("Should consume input", function()
|
it("Should consume input", function()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user