#81 Add simple input control via messages

This commit is contained in:
Insality
2021-10-22 00:56:46 +03:00
parent bbdf2b405d
commit 1da5476837
10 changed files with 1672 additions and 3 deletions

View File

@@ -1184,3 +1184,66 @@ embedded_instances {
z: 1.0
}
}
embedded_instances {
id: "system_message_input"
data: "components {\n"
" id: \"screen_factory\"\n"
" component: \"/monarch/screen_factory.script\"\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"
" properties {\n"
" id: \"screen_id\"\n"
" value: \"system_message_input\"\n"
" type: PROPERTY_TYPE_HASH\n"
" }\n"
" properties {\n"
" id: \"popup\"\n"
" value: \"true\"\n"
" type: PROPERTY_TYPE_BOOLEAN\n"
" }\n"
"}\n"
"embedded_components {\n"
" id: \"collectionfactory\"\n"
" type: \"collectionfactory\"\n"
" data: \"prototype: \\\"/example/examples/system/message_input/message_input.collection\\\"\\n"
"load_dynamically: false\\n"
"\"\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
}
}

View File

@@ -141,6 +141,7 @@ local function init_lobby(self)
self.lobby_grid:add(get_button_disabled(self, "Custom components"))
self.lobby_grid:add(get_button_disabled(self, "Component interests"))
self.lobby_grid:add(get_button_disabled(self, "Nested Druids"))
self.lobby_grid:add(get_button(self, "Message input", "system_message_input"))
self.lobby_grid:add(get_button_disabled(self, "Input priority"))
end

View File

@@ -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
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -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