mirror of
https://github.com/britzl/monarch.git
synced 2025-06-27 10:27:49 +02:00
Allow data to be passed when showing or going back
This commit is contained in:
parent
149c50221c
commit
09e2478378
@ -181,6 +181,69 @@ nodes {
|
|||||||
text_leading: 1.0
|
text_leading: 1.0
|
||||||
text_tracking: 0.0
|
text_tracking: 0.0
|
||||||
}
|
}
|
||||||
|
nodes {
|
||||||
|
position {
|
||||||
|
x: 320.0
|
||||||
|
y: 1050.0
|
||||||
|
z: 0.0
|
||||||
|
w: 1.0
|
||||||
|
}
|
||||||
|
rotation {
|
||||||
|
x: 0.0
|
||||||
|
y: 0.0
|
||||||
|
z: 0.0
|
||||||
|
w: 1.0
|
||||||
|
}
|
||||||
|
scale {
|
||||||
|
x: 1.0
|
||||||
|
y: 1.0
|
||||||
|
z: 1.0
|
||||||
|
w: 1.0
|
||||||
|
}
|
||||||
|
size {
|
||||||
|
x: 200.0
|
||||||
|
y: 100.0
|
||||||
|
z: 0.0
|
||||||
|
w: 1.0
|
||||||
|
}
|
||||||
|
color {
|
||||||
|
x: 1.0
|
||||||
|
y: 1.0
|
||||||
|
z: 1.0
|
||||||
|
w: 1.0
|
||||||
|
}
|
||||||
|
type: TYPE_TEXT
|
||||||
|
blend_mode: BLEND_MODE_ALPHA
|
||||||
|
text: "<text>"
|
||||||
|
font: "example"
|
||||||
|
id: "level"
|
||||||
|
xanchor: XANCHOR_NONE
|
||||||
|
yanchor: YANCHOR_NONE
|
||||||
|
pivot: PIVOT_CENTER
|
||||||
|
outline {
|
||||||
|
x: 1.0
|
||||||
|
y: 1.0
|
||||||
|
z: 1.0
|
||||||
|
w: 1.0
|
||||||
|
}
|
||||||
|
shadow {
|
||||||
|
x: 1.0
|
||||||
|
y: 1.0
|
||||||
|
z: 1.0
|
||||||
|
w: 1.0
|
||||||
|
}
|
||||||
|
adjust_mode: ADJUST_MODE_FIT
|
||||||
|
line_break: false
|
||||||
|
parent: "root"
|
||||||
|
layer: ""
|
||||||
|
inherit_alpha: true
|
||||||
|
alpha: 1.0
|
||||||
|
outline_alpha: 1.0
|
||||||
|
shadow_alpha: 1.0
|
||||||
|
template_node_child: false
|
||||||
|
text_leading: 1.0
|
||||||
|
text_tracking: 0.0
|
||||||
|
}
|
||||||
material: "/builtins/materials/gui.material"
|
material: "/builtins/materials/gui.material"
|
||||||
adjust_reference: ADJUST_REFERENCE_PARENT
|
adjust_reference: ADJUST_REFERENCE_PARENT
|
||||||
max_nodes: 512
|
max_nodes: 512
|
||||||
|
@ -3,6 +3,9 @@ local transitions = require "monarch.transitions.gui"
|
|||||||
|
|
||||||
function init(self)
|
function init(self)
|
||||||
msg.post(".", "acquire_input_focus")
|
msg.post(".", "acquire_input_focus")
|
||||||
|
|
||||||
|
local data = monarch.data(hash("game"))
|
||||||
|
gui.set_text(gui.get_node("level"), tostring(data.level))
|
||||||
|
|
||||||
self.transition = transitions.create(gui.get_node("root"))
|
self.transition = transitions.create(gui.get_node("root"))
|
||||||
.show_in(transitions.slide_in_right, gui.EASING_OUTQUAD, 0.6, 0)
|
.show_in(transitions.slide_in_right, gui.EASING_OUTQUAD, 0.6, 0)
|
||||||
@ -14,7 +17,7 @@ end
|
|||||||
function on_input(self, action_id, action)
|
function on_input(self, action_id, action)
|
||||||
if action_id == hash("touch") and action.released then
|
if action_id == hash("touch") and action.released then
|
||||||
if gui.pick_node(gui.get_node("win_button"), action.x, action.y) then
|
if gui.pick_node(gui.get_node("win_button"), action.x, action.y) then
|
||||||
monarch.show(hash("menu"), { clear = true }, function()
|
monarch.show(hash("menu"), { clear = true }, nil, function()
|
||||||
print("showing menu done")
|
print("showing menu done")
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
@ -14,7 +14,7 @@ end
|
|||||||
function on_input(self, action_id, action)
|
function on_input(self, action_id, action)
|
||||||
if action_id == hash("touch") and action.released then
|
if action_id == hash("touch") and action.released then
|
||||||
if gui.pick_node(gui.get_node("startgame_button"), action.x, action.y) then
|
if gui.pick_node(gui.get_node("startgame_button"), action.x, action.y) then
|
||||||
monarch.show(hash("popup"), nil, function()
|
monarch.show(hash("popup"), nil, nil, function()
|
||||||
print("showing popup done")
|
print("showing popup done")
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
@ -18,7 +18,7 @@ function on_input(self, action_id, action)
|
|||||||
if action_id == hash("touch") and action.released then
|
if action_id == hash("touch") and action.released then
|
||||||
if gui.pick_node(self.ok, action.x, action.y) then
|
if gui.pick_node(self.ok, action.x, action.y) then
|
||||||
print("ok")
|
print("ok")
|
||||||
monarch.show(hash("pregame"), nil, function()
|
monarch.show(hash("pregame"), nil, nil, function()
|
||||||
print("pregame show done")
|
print("pregame show done")
|
||||||
end)
|
end)
|
||||||
elseif gui.pick_node(self.cancel, action.x, action.y) then
|
elseif gui.pick_node(self.cancel, action.x, action.y) then
|
||||||
|
@ -17,7 +17,7 @@ function on_input(self, action_id, action)
|
|||||||
if action_id == hash("touch") and action.released then
|
if action_id == hash("touch") and action.released then
|
||||||
if gui.pick_node(self.play, action.x, action.y) then
|
if gui.pick_node(self.play, action.x, action.y) then
|
||||||
print("play")
|
print("play")
|
||||||
monarch.show(hash("game"), nil, function()
|
monarch.show(hash("game"), nil, { level = 1 }, function()
|
||||||
print("showing game done")
|
print("showing game done")
|
||||||
end)
|
end)
|
||||||
elseif gui.pick_node(self.back, action.x, action.y) then
|
elseif gui.pick_node(self.back, action.x, action.y) then
|
||||||
|
@ -116,16 +116,27 @@ local function back_out(screen, cb)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Get data associated with a screen
|
||||||
|
-- @param id Id of the screen to get data for
|
||||||
|
-- @return Data associated with the screen
|
||||||
|
function M.data(id)
|
||||||
|
assert(id, "You must provide a screen id")
|
||||||
|
assert(screens[id], ("There is no screen registered with id %s"):format(tostring(id)))
|
||||||
|
return screens[id].data
|
||||||
|
end
|
||||||
|
|
||||||
--- Show a new screen
|
--- Show a new screen
|
||||||
-- @param id Id of the screen to show
|
-- @param id Id of the screen to show
|
||||||
-- @param options Table with options when showing the screen (can be nil). Valid values:
|
-- @param options Table with options when showing the screen (can be nil). Valid values:
|
||||||
-- * clear - Set to true if the stack should be cleared down to an existing instance of the screen
|
-- * clear - Set to true if the stack should be cleared down to an existing instance of the screen
|
||||||
|
-- @param data Optional data to set on the screen. Can be retrieved by the data() function
|
||||||
-- @ param cb Optional callback to invoke when screen is shown
|
-- @ param cb Optional callback to invoke when screen is shown
|
||||||
function M.show(id, options, cb)
|
function M.show(id, options, data, cb)
|
||||||
assert(id, "You must provide a screen id")
|
assert(id, "You must provide a screen id")
|
||||||
assert(screens[id], ("There is no screen registered with id %s"):format(tostring(id)))
|
assert(screens[id], ("There is no screen registered with id %s"):format(tostring(id)))
|
||||||
|
|
||||||
local screen = screens[id]
|
local screen = screens[id]
|
||||||
|
screen.data = data
|
||||||
|
|
||||||
-- manipulate the current top
|
-- manipulate the current top
|
||||||
-- close popup if needed
|
-- close popup if needed
|
||||||
@ -163,13 +174,17 @@ end
|
|||||||
|
|
||||||
|
|
||||||
-- Go back to the previous screen in the stack
|
-- Go back to the previous screen in the stack
|
||||||
|
-- @param data Optional data to set for the previous screen
|
||||||
-- @param cb Optional callback to invoke when the previous screen is visible again
|
-- @param cb Optional callback to invoke when the previous screen is visible again
|
||||||
function M.back(cb)
|
function M.back(data, cb)
|
||||||
local screen = table.remove(stack)
|
local screen = table.remove(stack)
|
||||||
if screen then
|
if screen then
|
||||||
back_out(screen, cb)
|
back_out(screen, cb)
|
||||||
local top = stack[#stack]
|
local top = stack[#stack]
|
||||||
if top then
|
if top then
|
||||||
|
if data then
|
||||||
|
screen.data = data
|
||||||
|
end
|
||||||
back_in(top, screen)
|
back_in(top, screen)
|
||||||
end
|
end
|
||||||
elseif cb then
|
elseif cb then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user