mirror of
https://github.com/Insality/druid.git
synced 2025-09-27 10:02:18 +02:00
#81 Add simple input control via messages
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
name: "message_input"
|
||||
scale_along_z: 0
|
||||
embedded_instances {
|
||||
id: "go"
|
||||
data: "components {\n"
|
||||
" id: \"message_input\"\n"
|
||||
" component: \"/example/examples/system/message_input/message_input.gui\"\n"
|
||||
" position {\n"
|
||||
" x: 0.0\n"
|
||||
" y: 0.0\n"
|
||||
" z: 0.0\n"
|
||||
" }\n"
|
||||
" rotation {\n"
|
||||
" x: 0.0\n"
|
||||
" y: 0.0\n"
|
||||
" z: 0.0\n"
|
||||
" w: 1.0\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
""
|
||||
position {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale3 {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
}
|
||||
}
|
1430
example/examples/system/message_input/message_input.gui
Normal file
1430
example/examples/system/message_input/message_input.gui
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,72 @@
|
||||
local druid = require("druid.druid")
|
||||
local const = require("druid.const")
|
||||
|
||||
|
||||
local function click_callback(self, text, some)
|
||||
print("Button tap callback:", text, some)
|
||||
end
|
||||
|
||||
|
||||
local function trigger_callback(self, params)
|
||||
msg.post(".", const.ON_MESSAGE_INPUT, {
|
||||
node_id = params.node_id,
|
||||
action = params.action
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
function init(self)
|
||||
self.druid = druid.new(self)
|
||||
|
||||
self.button_left = self.druid:new_button("button_left/button", click_callback)
|
||||
self.button_left.on_long_click:subscribe(function() print("long click") end)
|
||||
self.button_left.on_double_click:subscribe(function() print("double click") end)
|
||||
self.button_left.on_repeated_click:subscribe(function() print("repeated_click") end)
|
||||
|
||||
self.button_right = self.druid:new_button("button_right/button", click_callback)
|
||||
|
||||
self.druid:new_button("button_trigger_left/button", trigger_callback, {
|
||||
node_id = "button_left/button",
|
||||
action = const.MESSAGE_INPUT.BUTTON_CLICK
|
||||
})
|
||||
|
||||
self.druid:new_button("button_trigger_left_double/button", trigger_callback, {
|
||||
node_id = "button_left/button",
|
||||
action = const.MESSAGE_INPUT.BUTTON_DOUBLE_CLICK
|
||||
})
|
||||
|
||||
self.druid:new_button("button_trigger_left_long/button", trigger_callback, {
|
||||
node_id = "button_left/button",
|
||||
action = const.MESSAGE_INPUT.BUTTON_LONG_CLICK
|
||||
})
|
||||
|
||||
self.druid:new_button("button_trigger_left_repeated/button", trigger_callback, {
|
||||
node_id = "button_left/button",
|
||||
action = const.MESSAGE_INPUT.BUTTON_REPEATED_CLICK
|
||||
})
|
||||
|
||||
self.druid:new_button("button_trigger_right/button", trigger_callback, {
|
||||
node_id = "button_right/button",
|
||||
action = const.MESSAGE_INPUT.BUTTON_CLICK
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
function final(self)
|
||||
self.druid:final()
|
||||
end
|
||||
|
||||
|
||||
function update(self, dt)
|
||||
self.druid:update(dt)
|
||||
end
|
||||
|
||||
|
||||
function on_message(self, message_id, message, sender)
|
||||
self.druid:on_message(message_id, message, sender)
|
||||
end
|
||||
|
||||
|
||||
function on_input(self, action_id, action)
|
||||
return self.druid:on_input(action_id, action)
|
||||
end
|
Reference in New Issue
Block a user