mirror of
https://github.com/britzl/monarch.git
synced 2025-06-27 10:27:49 +02:00
parent
38f95e0b5b
commit
7e2ff2990c
@ -243,11 +243,11 @@ local function change_context(screen)
|
|||||||
screen.wait_for = nil
|
screen.wait_for = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local function unload(screen)
|
local function unload(screen, force)
|
||||||
log("unload()", screen.id)
|
log("unload()", screen.id)
|
||||||
|
|
||||||
if screen.proxy then
|
if screen.proxy then
|
||||||
if screen.auto_preload then
|
if screen.auto_preload and not force then
|
||||||
msg.post(screen.proxy, DISABLE)
|
msg.post(screen.proxy, DISABLE)
|
||||||
screen.loaded = false
|
screen.loaded = false
|
||||||
screen.preloaded = true
|
screen.preloaded = true
|
||||||
@ -264,7 +264,7 @@ local function unload(screen)
|
|||||||
go.delete(instance)
|
go.delete(instance)
|
||||||
end
|
end
|
||||||
screen.factory_ids = nil
|
screen.factory_ids = nil
|
||||||
if screen.auto_preload then
|
if screen.auto_preload and not force then
|
||||||
screen.loaded = false
|
screen.loaded = false
|
||||||
screen.preloaded = true
|
screen.preloaded = true
|
||||||
else
|
else
|
||||||
@ -449,7 +449,7 @@ local function show_in(screen, previous_screen, reload, add_to_stack, cb)
|
|||||||
change_context(screen)
|
change_context(screen)
|
||||||
if reload and screen.loaded then
|
if reload and screen.loaded then
|
||||||
log("show_in() reloading", screen.id)
|
log("show_in() reloading", screen.id)
|
||||||
unload(screen)
|
unload(screen, reload)
|
||||||
end
|
end
|
||||||
load(screen)
|
load(screen)
|
||||||
if add_to_stack then
|
if add_to_stack then
|
||||||
|
37
test/data/screen_preload.collection
Normal file
37
test/data/screen_preload.collection
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
name: "screen_preload"
|
||||||
|
scale_along_z: 0
|
||||||
|
embedded_instances {
|
||||||
|
id: "go"
|
||||||
|
data: "components {\n"
|
||||||
|
" id: \"screen_preload\"\n"
|
||||||
|
" component: \"/test/data/screen_preload.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
|
||||||
|
}
|
||||||
|
}
|
131
test/data/screen_preload.gui
Normal file
131
test/data/screen_preload.gui
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
script: "/test/data/screen_preload.gui_script"
|
||||||
|
fonts {
|
||||||
|
name: "example"
|
||||||
|
font: "/assets/example.font"
|
||||||
|
}
|
||||||
|
background_color {
|
||||||
|
x: 0.0
|
||||||
|
y: 0.0
|
||||||
|
z: 0.0
|
||||||
|
w: 0.0
|
||||||
|
}
|
||||||
|
nodes {
|
||||||
|
position {
|
||||||
|
x: 320.0
|
||||||
|
y: 697.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_BOX
|
||||||
|
blend_mode: BLEND_MODE_ALPHA
|
||||||
|
texture: ""
|
||||||
|
id: "box"
|
||||||
|
xanchor: XANCHOR_NONE
|
||||||
|
yanchor: YANCHOR_NONE
|
||||||
|
pivot: PIVOT_CENTER
|
||||||
|
adjust_mode: ADJUST_MODE_FIT
|
||||||
|
layer: ""
|
||||||
|
inherit_alpha: true
|
||||||
|
slice9 {
|
||||||
|
x: 0.0
|
||||||
|
y: 0.0
|
||||||
|
z: 0.0
|
||||||
|
w: 0.0
|
||||||
|
}
|
||||||
|
clipping_mode: CLIPPING_MODE_NONE
|
||||||
|
clipping_visible: true
|
||||||
|
clipping_inverted: false
|
||||||
|
alpha: 1.0
|
||||||
|
template_node_child: false
|
||||||
|
size_mode: SIZE_MODE_AUTO
|
||||||
|
}
|
||||||
|
nodes {
|
||||||
|
position {
|
||||||
|
x: 0.0
|
||||||
|
y: 0.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: 0.0
|
||||||
|
y: 0.0
|
||||||
|
z: 0.0
|
||||||
|
w: 1.0
|
||||||
|
}
|
||||||
|
type: TYPE_TEXT
|
||||||
|
blend_mode: BLEND_MODE_ALPHA
|
||||||
|
text: "PRELOAD"
|
||||||
|
font: "example"
|
||||||
|
id: "text"
|
||||||
|
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: "box"
|
||||||
|
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"
|
||||||
|
adjust_reference: ADJUST_REFERENCE_PARENT
|
||||||
|
max_nodes: 512
|
5
test/data/screen_preload.gui_script
Normal file
5
test/data/screen_preload.gui_script
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
function init(self)
|
||||||
|
local monarch = require "monarch.monarch"
|
||||||
|
local data = monarch.data(hash("screen_preload"))
|
||||||
|
data.count = data.count + 1
|
||||||
|
end
|
@ -408,3 +408,66 @@ embedded_instances {
|
|||||||
z: 1.0
|
z: 1.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
embedded_instances {
|
||||||
|
id: "screen_preload"
|
||||||
|
data: "components {\n"
|
||||||
|
" id: \"screen\"\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: \"screen_preload\"\n"
|
||||||
|
" type: PROPERTY_TYPE_HASH\n"
|
||||||
|
" }\n"
|
||||||
|
" properties {\n"
|
||||||
|
" id: \"preload\"\n"
|
||||||
|
" value: \"true\"\n"
|
||||||
|
" type: PROPERTY_TYPE_BOOLEAN\n"
|
||||||
|
" }\n"
|
||||||
|
"}\n"
|
||||||
|
"embedded_components {\n"
|
||||||
|
" id: \"collectionfactory\"\n"
|
||||||
|
" type: \"collectionfactory\"\n"
|
||||||
|
" data: \"prototype: \\\"/test/data/screen_preload.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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -6,6 +6,7 @@ local monarch = require "monarch.monarch"
|
|||||||
local SCREEN1_STR = hash("screen1")
|
local SCREEN1_STR = hash("screen1")
|
||||||
local SCREEN1 = hash(SCREEN1_STR)
|
local SCREEN1 = hash(SCREEN1_STR)
|
||||||
local SCREEN2 = hash("screen2")
|
local SCREEN2 = hash("screen2")
|
||||||
|
local SCREEN_PRELOAD = hash("screen_preload")
|
||||||
local BACKGROUND = hash("background")
|
local BACKGROUND = hash("background")
|
||||||
local POPUP1 = hash("popup1")
|
local POPUP1 = hash("popup1")
|
||||||
local POPUP2 = hash("popup2")
|
local POPUP2 = hash("popup2")
|
||||||
@ -355,5 +356,31 @@ return function()
|
|||||||
assert(mock_msg.messages(URL1)[10].message_id == monarch.SCREEN_TRANSITION_IN_FINISHED)
|
assert(mock_msg.messages(URL1)[10].message_id == monarch.SCREEN_TRANSITION_IN_FINISHED)
|
||||||
assert(mock_msg.messages(URL1)[10].message.screen == SCREEN1)
|
assert(mock_msg.messages(URL1)[10].message.screen == SCREEN1)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
it("should be able to preload a screen and always keep it loaded", function()
|
||||||
|
monarch.show(SCREEN_PRELOAD, nil, { count = 1 })
|
||||||
|
assert(wait_until_shown(SCREEN_PRELOAD), "Screen_preload was never shown")
|
||||||
|
-- first time the screen gets loaded it will increment the count
|
||||||
|
assert(monarch.data(SCREEN_PRELOAD).count == 2)
|
||||||
|
|
||||||
|
monarch.show(SCREEN_PRELOAD, { clear = true }, { count = 1 })
|
||||||
|
assert(wait_until_shown(SCREEN_PRELOAD), "Screen_preload was never shown")
|
||||||
|
-- second time the screen gets shown it will already be loaded and not increment the count
|
||||||
|
assert(monarch.data(SCREEN_PRELOAD).count == 1)
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
it("should be able to reload a preloaded screen", function()
|
||||||
|
monarch.show(SCREEN_PRELOAD, nil, { count = 1 })
|
||||||
|
assert(wait_until_shown(SCREEN_PRELOAD), "Screen_preload was never shown")
|
||||||
|
-- first time the screen gets loaded it will increment the count
|
||||||
|
assert(monarch.data(SCREEN_PRELOAD).count == 2)
|
||||||
|
|
||||||
|
monarch.show(SCREEN_PRELOAD, { clear = true, reload = true }, { count = 1 })
|
||||||
|
assert(wait_until_shown(SCREEN_PRELOAD), "Screen_preload was never shown")
|
||||||
|
-- second time the screen gets shown it will be reloaded and increment the count
|
||||||
|
assert(monarch.data(SCREEN_PRELOAD).count == 2)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user