mirror of
https://github.com/britzl/monarch.git
synced 2025-11-26 19:00:53 +01:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c65581456 | ||
|
|
d02cd03d2c | ||
|
|
52ce9929a1 | ||
|
|
240c039d03 | ||
|
|
e46a703b25 | ||
|
|
e24acb51d8 | ||
|
|
1174de2ba5 | ||
|
|
95fd994fa0 | ||
|
|
e7edfbe173 | ||
|
|
592418fef7 | ||
|
|
d397b90dc2 | ||
|
|
09e2478378 | ||
|
|
149c50221c |
113
README.md
113
README.md
@@ -10,70 +10,75 @@ https://github.com/britzl/monarch/archive/master.zip
|
|||||||
Using Monarch requires that screens are created in a certain way. Once you have one or more screens created you can start navigating between the screens.
|
Using Monarch requires that screens are created in a certain way. Once you have one or more screens created you can start navigating between the screens.
|
||||||
|
|
||||||
## Creating screens
|
## Creating screens
|
||||||
Monarch screens are created in individual collections and loaded through collection proxies. The recommended setup is to create one game object per screen and per game object attach a collection proxy component and an instance of the ````screen.script```` provided by Monarch. The screen.script will take care of the setup of the screen. All you need to do is to make sure that the script properties on the ````screen.script```` are correct:
|
Monarch screens are created in individual collections and loaded through collection proxies. The recommended setup is to create one game object per screen and per game object attach a collection proxy component and an instance of the ```screen.script``` provided by Monarch. The screen.script will take care of the setup of the screen. All you need to do is to make sure that the script properties on the ```screen.script``` are correct:
|
||||||
|
|
||||||
* **Screen Proxy (url)** - The URL to the collection proxy component containing the actual screen. Defaults to ````#collectionproxy````
|
* **Screen Proxy (url)** - The URL to the collection proxy component containing the actual screen. Defaults to ```#collectionproxy```.
|
||||||
* **Screen Id (hash)** - A unique id that can be used to reference the screen when navigating your app
|
* **Screen Id (hash)** - A unique id that can be used to reference the screen when navigating your app.
|
||||||
* **Popup (boolean)** - Check this if the screen should be treated as a [popup](#popups)
|
* **Popup (boolean)** - Check this if the screen should be treated as a [popup](#popups).
|
||||||
* **Transition Show In (url)** - Optional URL to call when the screen is about to be shown. Use this to trigger a transition (see the section on [transitions](#transitions))
|
* **Transition Url (url)** - Optional URL to call when the screen is about to be shown/hidden. Use this to trigger a transition (see the section on [transitions](#transitions)).
|
||||||
* **Transition Show Out (url)** - Optional URL to call when the screen is about to be hidden. Use this to trigger a transition (see the section on [transitions](#transitions))
|
* **Focus Url (url)** - Optional URL to call when the screen gains or loses focus (see the section on [screen focus](#screen-focus-gainloss)).
|
||||||
* **Transition Back In (url)** - Optional URL to call when the screen is about to be shown when navigating back in the screen hierarchy. Use this to trigger a transition (see the section on [transitions](#transitions))
|
|
||||||
* **Transition Back Out (url)** - Optional URL to call when the screen is about to be hidden when navigating back in the screen hierarchy. Use this to trigger a transition (see the section on [transitions](#transitions))
|
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
## Navigating between screens
|
## Navigating between screens
|
||||||
The navigation in Monarch is based around a stack of screens. When a screen is shown it is pushed to the top of the stack. When going back to a previous screen the topmost screen on the stack is removed. Example:
|
The navigation in Monarch is based around a stack of screens. When a screen is shown it is pushed to the top of the stack. When going back to a previous screen the topmost screen on the stack is removed. Example:
|
||||||
|
|
||||||
* Showing screen A
|
* Showing screen A
|
||||||
* Stack is [A]
|
* Stack is ```[A]```
|
||||||
* Showing screen B
|
* Showing screen B
|
||||||
* Stack is [A, B] - (B is on top)
|
* Stack is ```[A, B]``` - (B is on top)
|
||||||
* Going back
|
* Going back
|
||||||
* Stack is [A]
|
* Stack is ```[A]```
|
||||||
|
|
||||||
### Showing a new screen
|
### Showing a new screen
|
||||||
You show a screen in one of two ways:
|
You show a screen in one of two ways:
|
||||||
|
|
||||||
1. Post a ````show```` message to the ````screen.script````
|
1. Post a ```show``` message to the ```screen.script```
|
||||||
2. Call ````monarch.show(screen_id, [options], [callback])````
|
2. Call ```monarch.show()``` (see below)
|
||||||
|
|
||||||
Showing a screen will push it to the top of the stack and trigger an optional transition. The previous screen will be hidden (with an optional transition) unless the screen to be shown is a [popup](#popups).
|
Showing a screen will push it to the top of the stack and trigger an optional transition. The previous screen will be hidden (with an optional transition) unless the screen to be shown is a [popup](#popups).
|
||||||
|
|
||||||
#### Preventing duplicates in the stack
|
#### Preventing duplicates in the stack
|
||||||
You can pass an optional ````clear```` flag when showing a screen (either as a key value pair in the options table when calling ````monarch.show()```` or in the message). If the clear flag is set Monarch will search the stack for the screen in question. If the screen already exists in the stack and the clear flag is set Monarch will remove all screens between the current top and the screen in question. Example:
|
You can pass an optional ```clear``` flag when showing a screen (either as a key value pair in the options table when calling ```monarch.show()``` or in the message). If the clear flag is set Monarch will search the stack for the screen in question. If the screen already exists in the stack and the ```clear``` flag is set Monarch will remove all screens between the current top and the screen in question. Example:
|
||||||
|
|
||||||
* Stack is [A, B, C, D] - (D is on top)
|
* Stack is ```[A, B, C, D]``` - (D is on top)
|
||||||
* A call to ````monarch.show(B, { clear = true })```` is made
|
* A call to ```monarch.show(B, { clear = true })``` is made
|
||||||
* Stack is [A, B]
|
* Stack is ```[A, B]```
|
||||||
|
|
||||||
|
As opposed to if the ```clear``` flag was not set:
|
||||||
|
|
||||||
|
* Stack is ```[A, B, C, D]``` - (D is on top)
|
||||||
|
* A call to ```monarch.show(B, { clear = false })``` is made
|
||||||
|
* Stack is ```[A, B, C, D, B]``` - (B is on top)
|
||||||
|
|
||||||
### Going back to a previous screen
|
### Going back to a previous screen
|
||||||
You navigate back in the screen hierarchy in one of two ways:
|
You navigate back in the screen hierarchy in one of two ways:
|
||||||
|
|
||||||
1. Post a ````back```` message to the ````screen.script````
|
1. Post a ```back``` message to the ```screen.script```
|
||||||
2. Call ````monarch.back()````
|
2. Call ```monarch.back()``` (see below)
|
||||||
|
|
||||||
|
|
||||||
## Input focus
|
## Input focus
|
||||||
Monarch will acquire and release input focus on the screens and ensure that only the top-most screen will ever have input focus.
|
Monarch will acquire and release input focus on the game objects containing the proxies to the screens and ensure that only the top-most screen will ever have input focus.
|
||||||
|
|
||||||
## Popups
|
## Popups
|
||||||
A screen that is flagged as a popup (see list of screen properties above) will be treated slightly differently when it comes to navigation. If a popup is at the top of the stack (ie currently shown) and another screen or popup is shown then the current popup will be removed from the stack. This means that it is not possible to have a popup anywhere in the stack but the top. This also means that you cannot navigate back to a popup since popups can only exist on the top of the stack. Another important difference between normal screens and popups is that when a popup is shown on top of a non-popup the current top screen will not be unloaded and instead remain visible in the background.
|
A screen that is flagged as a popup (see list of screen properties above) will be treated slightly differently when it comes to navigation. If a popup is at the top of the stack (ie currently shown) and another screen or popup is shown then the current popup will be removed from the stack. This means that it is not possible to have a popup anywhere in the stack but the top. This also means that you cannot navigate back to a popup since popups can only exist on the top of the stack. Another important difference between normal screens and popups is that when a popup is shown on top of a non-popup the current top screen will not be unloaded and instead remain visible in the background.
|
||||||
|
|
||||||
* Stack is [A, B]
|
* Stack is ```[A, B]```
|
||||||
* A call to ````monarch.show(C)```` is made and C is a popup
|
* A call to ```monarch.show(C)``` is made and C is a popup
|
||||||
* Stack is [A, B, C]
|
* Stack is ```[A, B, C]```
|
||||||
* A call to ````monarch.show(D)````
|
* A call to ```monarch.show(D)```
|
||||||
* Stack is [A, B, D]
|
* Stack is ```[A, B, D]```
|
||||||
|
|
||||||
## Transitions
|
## Transitions
|
||||||
You can add optional transitions when navigating between screens. The default behavior is that screen navigation is instant but if you have defined a transition for a screen Monarch will wait until the transition is completed before proceeding. The Transition Show In/Out and Transition Back In/Out properties described above should be URLs to one or more scripts with on_message handlers for the following messages:
|
You can add optional transitions when navigating between screens. The default behavior is that screen navigation is instant but if you have defined a transition for a screen Monarch will wait until the transition is completed before proceeding. The Transition Url property described above should be the URL to a script with an ```on_message``` handlers for the following messages:
|
||||||
|
|
||||||
* ````transition_show_in````
|
* ```transition_show_in```
|
||||||
* ````transition_show_out````
|
* ```transition_show_out```
|
||||||
* ````transition_back_in````
|
* ```transition_back_in```
|
||||||
* ````transition_back_out````
|
* ``transition_back_out```
|
||||||
|
|
||||||
When a transition is completed it is up to the developer to send a ````transition_done```` message back to the sender to indicate that the transition is completed and that Monarch can continue the navigation sequence. Monarch comes with a system for setting up transitions easily in a gui_script. Example:
|
When a transition is completed it is up to the developer to send a ```transition_done``` message back to the sender to indicate that the transition is completed and that Monarch can continue the navigation sequence. Monarch comes with a system for setting up transitions easily in a gui_script. Example:
|
||||||
|
|
||||||
local transitions = require "monarch.transitions.gui"
|
local transitions = require "monarch.transitions.gui"
|
||||||
|
|
||||||
@@ -92,5 +97,49 @@ When a transition is completed it is up to the developer to send a ````transitio
|
|||||||
self.transition.handle(message_id, message, sender)
|
self.transition.handle(message_id, message, sender)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
## Screen focus gain/loss
|
||||||
|
Monarch will send focus gain and focus loss messages if a Focus Url was provided when the screen was created. Example:
|
||||||
|
|
||||||
|
local monarch = require "monarch.monarch"
|
||||||
|
|
||||||
|
function on_message(self, message_id, message, sender)
|
||||||
|
if message_id == monarch.FOCUS_GAINED then
|
||||||
|
print("Focus gained")
|
||||||
|
elseif message_id == monarch.FOCUS_LOST then
|
||||||
|
print("Focus lost")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
## Callbacks
|
## Callbacks
|
||||||
Both the ```monarch.show()``` and ```monarch.back()``` functions take an optional callback function that will be invoked when the transition is completed. Note that this will not take into account when custom transitions are completed. The callback will be invoked immediately when the loading and unloading of collections are done and when the internal state of Monarch has completed the navigation.
|
Both the ```monarch.show()``` and ```monarch.back()``` functions take an optional callback function that will be invoked when the ```transition_show_in``` (or the ```transition_back_in``` in the case of a ```monarch.back()``` call) transition is completed. Tthe transition is considered completed when a ```transition_done``` message has been received (see section on [transitions](#transitions) above).
|
||||||
|
|
||||||
|
## Monarch API
|
||||||
|
|
||||||
|
### monarch.show(screen_id, [options], [data], [callback])
|
||||||
|
Show a Monarch screen
|
||||||
|
|
||||||
|
**PARAMETERS**
|
||||||
|
* ```screen_id``` (hash) - Id of the screen to show.
|
||||||
|
* ```options``` (table) - Options when showing the new screen (see below).
|
||||||
|
* ```data``` (table) - Optional data to associate with the screen. Retrieve using ```monarch.data()```.
|
||||||
|
* ```callback``` (function) - Function to call when the new screen is visible.
|
||||||
|
|
||||||
|
The options table can contain the following fields:
|
||||||
|
|
||||||
|
* ```clear``` (boolean) - If the clear flag is set Monarch will search the stack for the screen that is to be shown. If the screen already exists in the stack and the clear flag is set Monarch will remove all screens between the current top and the screen in question.
|
||||||
|
|
||||||
|
### monarch.back([data], [callback])
|
||||||
|
Go back to a previous Monarch screen
|
||||||
|
|
||||||
|
**PARAMETERS**
|
||||||
|
* ```data``` (table) - Optional data to associate with the screen you are going back to. Retrieve using ```monarch.data()```.
|
||||||
|
* ```callback``` (function) - Function to call when the previous screen is visible.
|
||||||
|
|
||||||
|
### monarch.data(screen_id)
|
||||||
|
Get the data associated with a screen (from a call to ```monarch.show()``` or ```monarch.back()```).
|
||||||
|
|
||||||
|
**PARAMETERS**
|
||||||
|
* ```screen_id``` (hash) - Id of the screen to get data for
|
||||||
|
|
||||||
|
**RETURN**
|
||||||
|
* ```data``` (table) - Data associated with the screen.
|
||||||
|
|||||||
BIN
docs/setup.png
Normal file
BIN
docs/setup.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 53 KiB |
37
example/about.collection
Normal file
37
example/about.collection
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
name: "about"
|
||||||
|
scale_along_z: 0
|
||||||
|
embedded_instances {
|
||||||
|
id: "go"
|
||||||
|
data: "components {\n"
|
||||||
|
" id: \"about\"\n"
|
||||||
|
" component: \"/example/about.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
|
||||||
|
}
|
||||||
|
}
|
||||||
603
example/about.gui
Normal file
603
example/about.gui
Normal file
@@ -0,0 +1,603 @@
|
|||||||
|
script: "/example/about.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: 568.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: 400.0
|
||||||
|
y: 300.0
|
||||||
|
z: 0.0
|
||||||
|
w: 1.0
|
||||||
|
}
|
||||||
|
color {
|
||||||
|
x: 0.3019608
|
||||||
|
y: 0.3019608
|
||||||
|
z: 0.3019608
|
||||||
|
w: 1.0
|
||||||
|
}
|
||||||
|
type: TYPE_BOX
|
||||||
|
blend_mode: BLEND_MODE_ALPHA
|
||||||
|
texture: ""
|
||||||
|
id: "root"
|
||||||
|
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_MANUAL
|
||||||
|
}
|
||||||
|
nodes {
|
||||||
|
position {
|
||||||
|
x: 120.0
|
||||||
|
y: -112.414
|
||||||
|
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: 110.0
|
||||||
|
y: 50.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: "ok_reload_button"
|
||||||
|
xanchor: XANCHOR_NONE
|
||||||
|
yanchor: YANCHOR_NONE
|
||||||
|
pivot: PIVOT_CENTER
|
||||||
|
adjust_mode: ADJUST_MODE_FIT
|
||||||
|
parent: "root"
|
||||||
|
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_MANUAL
|
||||||
|
}
|
||||||
|
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: "OK, reload"
|
||||||
|
font: "example"
|
||||||
|
id: "ok_reload_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: "ok_reload_button"
|
||||||
|
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
|
||||||
|
}
|
||||||
|
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: 380.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: "When clicking OK the menu will be shown again using monarch.show()"
|
||||||
|
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: true
|
||||||
|
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
|
||||||
|
}
|
||||||
|
nodes {
|
||||||
|
position {
|
||||||
|
x: -0.0
|
||||||
|
y: -112.414
|
||||||
|
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: 110.0
|
||||||
|
y: 50.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: "ok_clear_button"
|
||||||
|
xanchor: XANCHOR_NONE
|
||||||
|
yanchor: YANCHOR_NONE
|
||||||
|
pivot: PIVOT_CENTER
|
||||||
|
adjust_mode: ADJUST_MODE_FIT
|
||||||
|
parent: "root"
|
||||||
|
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_MANUAL
|
||||||
|
}
|
||||||
|
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: "OK, clear"
|
||||||
|
font: "example"
|
||||||
|
id: "ok_clear_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: "ok_clear_button"
|
||||||
|
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
|
||||||
|
}
|
||||||
|
nodes {
|
||||||
|
position {
|
||||||
|
x: -120.0
|
||||||
|
y: -112.414
|
||||||
|
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: 110.0
|
||||||
|
y: 50.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: "ok_clearreload_button"
|
||||||
|
xanchor: XANCHOR_NONE
|
||||||
|
yanchor: YANCHOR_NONE
|
||||||
|
pivot: PIVOT_CENTER
|
||||||
|
adjust_mode: ADJUST_MODE_FIT
|
||||||
|
parent: "root"
|
||||||
|
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_MANUAL
|
||||||
|
}
|
||||||
|
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: 100.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: "OK, clear and reload"
|
||||||
|
font: "example"
|
||||||
|
id: "ok_clearreload_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: true
|
||||||
|
parent: "ok_clearreload_button"
|
||||||
|
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
|
||||||
|
}
|
||||||
|
nodes {
|
||||||
|
position {
|
||||||
|
x: 120.0
|
||||||
|
y: -54.414
|
||||||
|
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: 110.0
|
||||||
|
y: 50.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: "ok_button"
|
||||||
|
xanchor: XANCHOR_NONE
|
||||||
|
yanchor: YANCHOR_NONE
|
||||||
|
pivot: PIVOT_CENTER
|
||||||
|
adjust_mode: ADJUST_MODE_FIT
|
||||||
|
parent: "root"
|
||||||
|
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_MANUAL
|
||||||
|
}
|
||||||
|
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: "OK"
|
||||||
|
font: "example"
|
||||||
|
id: "ok_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: "ok_button"
|
||||||
|
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
|
||||||
31
example/about.gui_script
Normal file
31
example/about.gui_script
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
local monarch = require "monarch.monarch"
|
||||||
|
local transitions = require "monarch.transitions.gui"
|
||||||
|
|
||||||
|
function init(self)
|
||||||
|
msg.post(".", "acquire_input_focus")
|
||||||
|
gui.set_render_order(15)
|
||||||
|
|
||||||
|
self.transition = transitions.create(gui.get_node("root"))
|
||||||
|
.show_in(transitions.slide_in_top, gui.EASING_OUTQUAD, 0.6, 0)
|
||||||
|
.show_out(transitions.slide_out_top, gui.EASING_INQUAD, 0.6, 0)
|
||||||
|
.back_in(transitions.slide_in_top, gui.EASING_OUTQUAD, 0.6, 0)
|
||||||
|
.back_out(transitions.slide_out_top, gui.EASING_INQUAD, 0.6, 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
function on_input(self, action_id, action)
|
||||||
|
if action_id == hash("touch") and action.released then
|
||||||
|
if gui.pick_node(gui.get_node("ok_reload_button"), action.x, action.y) then
|
||||||
|
monarch.show(hash("menu"), { reload = true })
|
||||||
|
elseif gui.pick_node(gui.get_node("ok_clear_button"), action.x, action.y) then
|
||||||
|
monarch.show(hash("menu"), { clear = true })
|
||||||
|
elseif gui.pick_node(gui.get_node("ok_clearreload_button"), action.x, action.y) then
|
||||||
|
monarch.show(hash("menu"), { clear = true, reload = true })
|
||||||
|
elseif gui.pick_node(gui.get_node("ok_button"), action.x, action.y) then
|
||||||
|
monarch.show(hash("menu"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function on_message(self, message_id, message, sender)
|
||||||
|
self.transition.handle(message_id, message, sender)
|
||||||
|
end
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -22,22 +22,7 @@ embedded_instances {
|
|||||||
" type: PROPERTY_TYPE_HASH\n"
|
" type: PROPERTY_TYPE_HASH\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" properties {\n"
|
" properties {\n"
|
||||||
" id: \"transition_show_in\"\n"
|
" id: \"transition_url\"\n"
|
||||||
" value: \"menu:/go#menu\"\n"
|
|
||||||
" type: PROPERTY_TYPE_URL\n"
|
|
||||||
" }\n"
|
|
||||||
" properties {\n"
|
|
||||||
" id: \"transition_show_out\"\n"
|
|
||||||
" value: \"menu:/go#menu\"\n"
|
|
||||||
" type: PROPERTY_TYPE_URL\n"
|
|
||||||
" }\n"
|
|
||||||
" properties {\n"
|
|
||||||
" id: \"transition_back_in\"\n"
|
|
||||||
" value: \"menu:/go#menu\"\n"
|
|
||||||
" type: PROPERTY_TYPE_URL\n"
|
|
||||||
" }\n"
|
|
||||||
" properties {\n"
|
|
||||||
" id: \"transition_back_out\"\n"
|
|
||||||
" value: \"menu:/go#menu\"\n"
|
" value: \"menu:/go#menu\"\n"
|
||||||
" type: PROPERTY_TYPE_URL\n"
|
" type: PROPERTY_TYPE_URL\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
@@ -96,7 +81,7 @@ embedded_instances {
|
|||||||
" }\n"
|
" }\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"components {\n"
|
"components {\n"
|
||||||
" id: \"main1\"\n"
|
" id: \"gui\"\n"
|
||||||
" component: \"/example/debug.gui\"\n"
|
" component: \"/example/debug.gui\"\n"
|
||||||
" position {\n"
|
" position {\n"
|
||||||
" x: 0.0\n"
|
" x: 0.0\n"
|
||||||
@@ -150,22 +135,7 @@ embedded_instances {
|
|||||||
" type: PROPERTY_TYPE_HASH\n"
|
" type: PROPERTY_TYPE_HASH\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" properties {\n"
|
" properties {\n"
|
||||||
" id: \"transition_show_in\"\n"
|
" id: \"transition_url\"\n"
|
||||||
" value: \"pregame:/go#pregame\"\n"
|
|
||||||
" type: PROPERTY_TYPE_URL\n"
|
|
||||||
" }\n"
|
|
||||||
" properties {\n"
|
|
||||||
" id: \"transition_show_out\"\n"
|
|
||||||
" value: \"pregame:/go#pregame\"\n"
|
|
||||||
" type: PROPERTY_TYPE_URL\n"
|
|
||||||
" }\n"
|
|
||||||
" properties {\n"
|
|
||||||
" id: \"transition_back_in\"\n"
|
|
||||||
" value: \"pregame:/go#pregame\"\n"
|
|
||||||
" type: PROPERTY_TYPE_URL\n"
|
|
||||||
" }\n"
|
|
||||||
" properties {\n"
|
|
||||||
" id: \"transition_back_out\"\n"
|
|
||||||
" value: \"pregame:/go#pregame\"\n"
|
" value: \"pregame:/go#pregame\"\n"
|
||||||
" type: PROPERTY_TYPE_URL\n"
|
" type: PROPERTY_TYPE_URL\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
@@ -228,22 +198,7 @@ embedded_instances {
|
|||||||
" type: PROPERTY_TYPE_HASH\n"
|
" type: PROPERTY_TYPE_HASH\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" properties {\n"
|
" properties {\n"
|
||||||
" id: \"transition_show_in\"\n"
|
" id: \"transition_url\"\n"
|
||||||
" value: \"game:/go#game\"\n"
|
|
||||||
" type: PROPERTY_TYPE_URL\n"
|
|
||||||
" }\n"
|
|
||||||
" properties {\n"
|
|
||||||
" id: \"transition_show_out\"\n"
|
|
||||||
" value: \"game:/go#game\"\n"
|
|
||||||
" type: PROPERTY_TYPE_URL\n"
|
|
||||||
" }\n"
|
|
||||||
" properties {\n"
|
|
||||||
" id: \"transition_back_in\"\n"
|
|
||||||
" value: \"game:/go#game\"\n"
|
|
||||||
" type: PROPERTY_TYPE_URL\n"
|
|
||||||
" }\n"
|
|
||||||
" properties {\n"
|
|
||||||
" id: \"transition_back_out\"\n"
|
|
||||||
" value: \"game:/go#game\"\n"
|
" value: \"game:/go#game\"\n"
|
||||||
" type: PROPERTY_TYPE_URL\n"
|
" type: PROPERTY_TYPE_URL\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
@@ -311,22 +266,7 @@ embedded_instances {
|
|||||||
" type: PROPERTY_TYPE_BOOLEAN\n"
|
" type: PROPERTY_TYPE_BOOLEAN\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" properties {\n"
|
" properties {\n"
|
||||||
" id: \"transition_show_in\"\n"
|
" id: \"transition_url\"\n"
|
||||||
" value: \"popup:/go#popup\"\n"
|
|
||||||
" type: PROPERTY_TYPE_URL\n"
|
|
||||||
" }\n"
|
|
||||||
" properties {\n"
|
|
||||||
" id: \"transition_show_out\"\n"
|
|
||||||
" value: \"popup:/go#popup\"\n"
|
|
||||||
" type: PROPERTY_TYPE_URL\n"
|
|
||||||
" }\n"
|
|
||||||
" properties {\n"
|
|
||||||
" id: \"transition_back_in\"\n"
|
|
||||||
" value: \"popup:/go#popup\"\n"
|
|
||||||
" type: PROPERTY_TYPE_URL\n"
|
|
||||||
" }\n"
|
|
||||||
" properties {\n"
|
|
||||||
" id: \"transition_back_out\"\n"
|
|
||||||
" value: \"popup:/go#popup\"\n"
|
" value: \"popup:/go#popup\"\n"
|
||||||
" type: PROPERTY_TYPE_URL\n"
|
" type: PROPERTY_TYPE_URL\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
@@ -367,3 +307,71 @@ embedded_instances {
|
|||||||
z: 1.0
|
z: 1.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
embedded_instances {
|
||||||
|
id: "about"
|
||||||
|
data: "components {\n"
|
||||||
|
" id: \"screen\"\n"
|
||||||
|
" component: \"/monarch/screen.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: \"about\"\n"
|
||||||
|
" type: PROPERTY_TYPE_HASH\n"
|
||||||
|
" }\n"
|
||||||
|
" properties {\n"
|
||||||
|
" id: \"popup\"\n"
|
||||||
|
" value: \"true\"\n"
|
||||||
|
" type: PROPERTY_TYPE_BOOLEAN\n"
|
||||||
|
" }\n"
|
||||||
|
" properties {\n"
|
||||||
|
" id: \"transition_url\"\n"
|
||||||
|
" value: \"about:/go#about\"\n"
|
||||||
|
" type: PROPERTY_TYPE_URL\n"
|
||||||
|
" }\n"
|
||||||
|
"}\n"
|
||||||
|
"embedded_components {\n"
|
||||||
|
" id: \"collectionproxy\"\n"
|
||||||
|
" type: \"collectionproxy\"\n"
|
||||||
|
" data: \"collection: \\\"/example/about.collection\\\"\\n"
|
||||||
|
"exclude: 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
299
example/menu.gui
299
example/menu.gui
@@ -181,6 +181,305 @@ nodes {
|
|||||||
text_leading: 1.0
|
text_leading: 1.0
|
||||||
text_tracking: 0.0
|
text_tracking: 0.0
|
||||||
}
|
}
|
||||||
|
nodes {
|
||||||
|
position {
|
||||||
|
x: 499.0
|
||||||
|
y: 1078.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: 50.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: "about_button"
|
||||||
|
xanchor: XANCHOR_NONE
|
||||||
|
yanchor: YANCHOR_NONE
|
||||||
|
pivot: PIVOT_CENTER
|
||||||
|
adjust_mode: ADJUST_MODE_FIT
|
||||||
|
parent: "root"
|
||||||
|
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_MANUAL
|
||||||
|
}
|
||||||
|
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: "ABOUT"
|
||||||
|
font: "example"
|
||||||
|
id: "about_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: "about_button"
|
||||||
|
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
|
||||||
|
}
|
||||||
|
nodes {
|
||||||
|
position {
|
||||||
|
x: 138.0
|
||||||
|
y: 1078.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: 50.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: "back_button"
|
||||||
|
xanchor: XANCHOR_NONE
|
||||||
|
yanchor: YANCHOR_NONE
|
||||||
|
pivot: PIVOT_CENTER
|
||||||
|
adjust_mode: ADJUST_MODE_FIT
|
||||||
|
parent: "root"
|
||||||
|
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_MANUAL
|
||||||
|
}
|
||||||
|
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: "BACK"
|
||||||
|
font: "example"
|
||||||
|
id: "back_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: "back_button"
|
||||||
|
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
|
||||||
|
}
|
||||||
|
nodes {
|
||||||
|
position {
|
||||||
|
x: 320.0
|
||||||
|
y: 1024.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: "timestamp"
|
||||||
|
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
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ local transitions = require "monarch.transitions.gui"
|
|||||||
function init(self)
|
function init(self)
|
||||||
msg.post(".", "acquire_input_focus")
|
msg.post(".", "acquire_input_focus")
|
||||||
|
|
||||||
|
gui.set_text(gui.get_node("timestamp"), os.date())
|
||||||
|
|
||||||
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)
|
||||||
.show_out(transitions.slide_out_left, gui.EASING_INQUAD, 0.6, 0)
|
.show_out(transitions.slide_out_left, gui.EASING_INQUAD, 0.6, 0)
|
||||||
@@ -14,9 +16,15 @@ 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)
|
||||||
|
elseif gui.pick_node(gui.get_node("about_button"), action.x, action.y) then
|
||||||
|
monarch.show(hash("about"), nil, nil, function()
|
||||||
|
print("showing about done")
|
||||||
|
end)
|
||||||
|
elseif gui.pick_node(gui.get_node("back_button"), action.x, action.y) then
|
||||||
|
monarch.back()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ function init(self)
|
|||||||
msg.post(".", "acquire_input_focus")
|
msg.post(".", "acquire_input_focus")
|
||||||
self.ok = gui.get_node("ok_button")
|
self.ok = gui.get_node("ok_button")
|
||||||
self.cancel = gui.get_node("cancel_button")
|
self.cancel = gui.get_node("cancel_button")
|
||||||
gui.set_render_order(16)
|
gui.set_render_order(15)
|
||||||
|
|
||||||
self.transition = transitions.create(gui.get_node("root"))
|
self.transition = transitions.create(gui.get_node("root"))
|
||||||
.show_in(transitions.slide_in_top, gui.EASING_OUTQUAD, 0.6, 0)
|
.show_in(transitions.slide_in_top, gui.EASING_OUTQUAD, 0.6, 0)
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -4,9 +4,17 @@ local screens = {}
|
|||||||
|
|
||||||
local stack = {}
|
local stack = {}
|
||||||
|
|
||||||
|
local CONTEXT = hash("monarch_context")
|
||||||
|
local PROXY_LOADED = hash("proxy_loaded")
|
||||||
|
local PROXY_UNLOADED = hash("proxy_unloaded")
|
||||||
|
|
||||||
|
M.TRANSITION_DONE = hash("transition_done")
|
||||||
|
M.FOCUS_GAINED = hash("monarch_focus_gained")
|
||||||
|
M.FOCUS_LOST = hash("monarch_focus_lost")
|
||||||
|
|
||||||
|
|
||||||
local function screen_from_proxy(proxy)
|
local function screen_from_proxy(proxy)
|
||||||
for id,screen in pairs(screens) do
|
for _,screen in pairs(screens) do
|
||||||
if screen.proxy == proxy then
|
if screen.proxy == proxy then
|
||||||
return screen
|
return screen
|
||||||
end
|
end
|
||||||
@@ -15,7 +23,7 @@ end
|
|||||||
|
|
||||||
local function screen_from_script()
|
local function screen_from_script()
|
||||||
local url = msg.url()
|
local url = msg.url()
|
||||||
for id,screen in pairs(screens) do
|
for _,screen in pairs(screens) do
|
||||||
if screen.script == url then
|
if screen.script == url then
|
||||||
return screen
|
return screen
|
||||||
end
|
end
|
||||||
@@ -31,9 +39,16 @@ local function in_stack(id)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.register(id, proxy, popup, transitions)
|
function M.register(id, proxy, popup, transition_url, focus_url)
|
||||||
assert(not screens[id], ("There is already a screen registered with id %s"):format(tostring(id)))
|
assert(not screens[id], ("There is already a screen registered with id %s"):format(tostring(id)))
|
||||||
screens[id] = { id = id, proxy = proxy, script = msg.url(), popup = popup, transitions = transitions }
|
screens[id] = {
|
||||||
|
id = id,
|
||||||
|
proxy = proxy,
|
||||||
|
script = msg.url(),
|
||||||
|
popup = popup,
|
||||||
|
transition_url = transition_url,
|
||||||
|
focus_url = focus_url,
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.unregister(id)
|
function M.unregister(id)
|
||||||
@@ -46,13 +61,17 @@ local function show_out(screen, next_screen, cb)
|
|||||||
co = coroutine.create(function()
|
co = coroutine.create(function()
|
||||||
screen.co = co
|
screen.co = co
|
||||||
msg.post(screen.script, "release_input_focus")
|
msg.post(screen.script, "release_input_focus")
|
||||||
msg.post(screen.script, "monarch_context")
|
msg.post(screen.script, CONTEXT)
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
if not next_screen.popup then
|
if not next_screen.popup then
|
||||||
msg.post(screen.transitions.show_out, "transition_show_out")
|
msg.post(screen.transition_url, "transition_show_out")
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
msg.post(screen.proxy, "unload")
|
msg.post(screen.proxy, "unload")
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
|
screen.loaded = false
|
||||||
|
end
|
||||||
|
if screen.focus_url then
|
||||||
|
msg.post(screen.focus_url, M.FOCUS_LOST)
|
||||||
end
|
end
|
||||||
screen.co = nil
|
screen.co = nil
|
||||||
if cb then cb() end
|
if cb then cb() end
|
||||||
@@ -60,19 +79,33 @@ local function show_out(screen, next_screen, cb)
|
|||||||
coroutine.resume(co)
|
coroutine.resume(co)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function show_in(screen, cb)
|
local function show_in(screen, reload, cb)
|
||||||
local co
|
local co
|
||||||
co = coroutine.create(function()
|
co = coroutine.create(function()
|
||||||
screen.co = co
|
screen.co = co
|
||||||
msg.post(screen.script, "monarch_context")
|
msg.post(screen.script, CONTEXT)
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
msg.post(screen.proxy, "async_load")
|
if reload and screen.loaded then
|
||||||
coroutine.yield()
|
msg.post(screen.proxy, "unload")
|
||||||
msg.post(screen.proxy, "enable")
|
coroutine.yield()
|
||||||
|
screen.loaded = false
|
||||||
|
end
|
||||||
|
-- the screen could be loaded if the previous screen was a popup
|
||||||
|
-- and the popup asked to show this screen again
|
||||||
|
-- in that case we shouldn't attempt to load it again
|
||||||
|
if not screen.loaded then
|
||||||
|
msg.post(screen.proxy, "async_load")
|
||||||
|
coroutine.yield()
|
||||||
|
msg.post(screen.proxy, "enable")
|
||||||
|
screen.loaded = true
|
||||||
|
end
|
||||||
stack[#stack + 1] = screen
|
stack[#stack + 1] = screen
|
||||||
msg.post(screen.transitions.show_in, "transition_show_in")
|
msg.post(screen.transition_url, "transition_show_in")
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
msg.post(screen.script, "acquire_input_focus")
|
msg.post(screen.script, "acquire_input_focus")
|
||||||
|
if screen.focus_url then
|
||||||
|
msg.post(screen.focus_url, M.FOCUS_GAINED)
|
||||||
|
end
|
||||||
screen.co = nil
|
screen.co = nil
|
||||||
if cb then cb() end
|
if cb then cb() end
|
||||||
end)
|
end)
|
||||||
@@ -83,16 +116,20 @@ local function back_in(screen, previous_screen, cb)
|
|||||||
local co
|
local co
|
||||||
co = coroutine.create(function()
|
co = coroutine.create(function()
|
||||||
screen.co = co
|
screen.co = co
|
||||||
msg.post(screen.script, "monarch_context")
|
msg.post(screen.script, CONTEXT)
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
if not previous_screen.popup then
|
if not previous_screen.popup then
|
||||||
msg.post(screen.proxy, "async_load")
|
msg.post(screen.proxy, "async_load")
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
msg.post(screen.proxy, "enable")
|
msg.post(screen.proxy, "enable")
|
||||||
msg.post(screen.transitions.back_in, "transition_back_in")
|
screen.loaded = true
|
||||||
|
msg.post(screen.transition_url, "transition_back_in")
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
end
|
end
|
||||||
msg.post(screen.script, "acquire_input_focus")
|
msg.post(screen.script, "acquire_input_focus")
|
||||||
|
if screen.focus_url then
|
||||||
|
msg.post(screen.focus_url, M.FOCUS_GAINED)
|
||||||
|
end
|
||||||
screen.co = nil
|
screen.co = nil
|
||||||
if cb then cb() end
|
if cb then cb() end
|
||||||
end)
|
end)
|
||||||
@@ -104,11 +141,16 @@ local function back_out(screen, cb)
|
|||||||
co = coroutine.create(function()
|
co = coroutine.create(function()
|
||||||
screen.co = co
|
screen.co = co
|
||||||
msg.post(screen.script, "release_input_focus")
|
msg.post(screen.script, "release_input_focus")
|
||||||
msg.post(screen.script, "monarch_context")
|
msg.post(screen.script, CONTEXT)
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
msg.post(screen.transitions.back_out, "transition_back_out")
|
msg.post(screen.transition_url, "transition_back_out")
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
msg.post(screen.proxy, "unload")
|
msg.post(screen.proxy, "unload")
|
||||||
|
coroutine.yield()
|
||||||
|
screen.loaded = false
|
||||||
|
if screen.focus_url then
|
||||||
|
msg.post(screen.focus_url, M.FOCUS_LOST)
|
||||||
|
end
|
||||||
screen.co = nil
|
screen.co = nil
|
||||||
if cb then cb() end
|
if cb then cb() end
|
||||||
end)
|
end)
|
||||||
@@ -116,17 +158,30 @@ 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
|
||||||
|
-- * reload - Set to true if screen should be reloaded if it already exists in the stack and is loaded
|
||||||
|
-- This would be the case if doing a show() from a popup on the screen just below the popup.
|
||||||
|
-- @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
|
||||||
-- transition out
|
-- transition out
|
||||||
@@ -139,7 +194,7 @@ function M.show(id, options, cb)
|
|||||||
top = stack[#stack]
|
top = stack[#stack]
|
||||||
end
|
end
|
||||||
-- unload and transition out from top
|
-- unload and transition out from top
|
||||||
if top then
|
if top and top.id ~= screen.id then
|
||||||
show_out(top, screen)
|
show_out(top, screen)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -148,28 +203,29 @@ function M.show(id, options, cb)
|
|||||||
-- already and the clear flag is set then we need
|
-- already and the clear flag is set then we need
|
||||||
-- to remove every screen on the stack up until and
|
-- to remove every screen on the stack up until and
|
||||||
-- including the screen itself
|
-- including the screen itself
|
||||||
if options and options.clear and in_stack(id) then
|
if options and options.clear then
|
||||||
while true do
|
while in_stack(id) do
|
||||||
if table.remove(stack).id == id then
|
table.remove(stack)
|
||||||
break
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- show screen
|
-- show screen
|
||||||
show_in(screen, cb)
|
show_in(screen, options and options.reload, cb)
|
||||||
end
|
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
|
||||||
@@ -179,18 +235,19 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function M.on_message(message_id, message, sender)
|
function M.on_message(message_id, message, sender)
|
||||||
if message_id == hash("proxy_loaded") then
|
if message_id == PROXY_LOADED then
|
||||||
local screen = screen_from_proxy(sender)
|
local screen = screen_from_proxy(sender)
|
||||||
assert(screen, "Unable to find screen for loaded proxy")
|
assert(screen, "Unable to find screen for loaded proxy")
|
||||||
coroutine.resume(screen.co)
|
coroutine.resume(screen.co)
|
||||||
elseif message_id == hash("proxy_unloaded") then
|
elseif message_id == PROXY_UNLOADED then
|
||||||
local screen = screen_from_proxy(sender)
|
local screen = screen_from_proxy(sender)
|
||||||
assert(screen, "Unable to find screen for unloaded proxy")
|
assert(screen, "Unable to find screen for unloaded proxy")
|
||||||
elseif message_id == hash("monarch_context") then
|
coroutine.resume(screen.co)
|
||||||
|
elseif message_id == CONTEXT then
|
||||||
local screen = screen_from_script()
|
local screen = screen_from_script()
|
||||||
assert(screen, "Unable to find screen for current script url")
|
assert(screen, "Unable to find screen for current script url")
|
||||||
coroutine.resume(screen.co)
|
coroutine.resume(screen.co)
|
||||||
elseif message_id == hash("transition_done") then
|
elseif message_id == M.TRANSITION_DONE then
|
||||||
local screen = screen_from_script()
|
local screen = screen_from_script()
|
||||||
assert(screen, "Unable to find screen for current script url")
|
assert(screen, "Unable to find screen for current script url")
|
||||||
coroutine.resume(screen.co)
|
coroutine.resume(screen.co)
|
||||||
@@ -205,4 +262,4 @@ function M.dump_stack()
|
|||||||
return s
|
return s
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
@@ -3,19 +3,12 @@ local monarch = require "monarch.monarch"
|
|||||||
go.property("screen_proxy", msg.url("#collectionproxy"))
|
go.property("screen_proxy", msg.url("#collectionproxy"))
|
||||||
go.property("screen_id", hash(""))
|
go.property("screen_id", hash(""))
|
||||||
go.property("popup", false)
|
go.property("popup", false)
|
||||||
go.property("transition_show_in", msg.url())
|
go.property("transition_url", msg.url())
|
||||||
go.property("transition_show_out", msg.url())
|
go.property("focus_url", msg.url())
|
||||||
go.property("transition_back_in", msg.url())
|
|
||||||
go.property("transition_back_out", msg.url())
|
|
||||||
|
|
||||||
|
|
||||||
function init(self)
|
function init(self)
|
||||||
monarch.register(self.screen_id, self.screen_proxy, self.popup, {
|
monarch.register(self.screen_id, self.screen_proxy, self.popup, self.transition_url, self.focus_url)
|
||||||
show_in = self.transition_show_in,
|
|
||||||
show_out = self.transition_show_out,
|
|
||||||
back_in = self.transition_back_in,
|
|
||||||
back_out = self.transition_back_out,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function final(self)
|
function final(self)
|
||||||
|
|||||||
@@ -79,7 +79,9 @@ function M.create(node)
|
|||||||
|
|
||||||
-- Forward on_message calls here
|
-- Forward on_message calls here
|
||||||
function instance.handle(message_id, message, sender)
|
function instance.handle(message_id, message, sender)
|
||||||
transitions[message_id](sender)
|
if transitions[message_id] then
|
||||||
|
transitions[message_id](sender)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Specify the transition function when this node is transitioned
|
-- Specify the transition function when this node is transitioned
|
||||||
@@ -90,8 +92,7 @@ function M.create(node)
|
|||||||
-- @param delay Transition delay
|
-- @param delay Transition delay
|
||||||
function instance.show_in(fn, easing, duration, delay)
|
function instance.show_in(fn, easing, duration, delay)
|
||||||
transitions[hash("transition_show_in")] = function(url)
|
transitions[hash("transition_show_in")] = function(url)
|
||||||
print("transition_show_in", url, fn)
|
fn(node, initial_position, easing, duration, delay or 0, url)
|
||||||
fn(node, initial_position, easing, duration, delay, url)
|
|
||||||
end
|
end
|
||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
@@ -100,8 +101,7 @@ function M.create(node)
|
|||||||
-- from when showing another screen
|
-- from when showing another screen
|
||||||
function instance.show_out(fn, easing, duration, delay)
|
function instance.show_out(fn, easing, duration, delay)
|
||||||
transitions[hash("transition_show_out")] = function(url)
|
transitions[hash("transition_show_out")] = function(url)
|
||||||
print("transition_show_out")
|
fn(node, initial_position, easing, duration, delay or 0, url)
|
||||||
fn(node, initial_position, easing, duration, delay, url)
|
|
||||||
end
|
end
|
||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
@@ -110,8 +110,7 @@ function M.create(node)
|
|||||||
-- to when navigating back in the screen stack
|
-- to when navigating back in the screen stack
|
||||||
function instance.back_in(fn, easing, duration, delay)
|
function instance.back_in(fn, easing, duration, delay)
|
||||||
transitions[hash("transition_back_in")] = function(url)
|
transitions[hash("transition_back_in")] = function(url)
|
||||||
print("transition_back_in")
|
fn(node, initial_position, easing, duration, delay or 0, url)
|
||||||
fn(node, initial_position, easing, duration, delay, url)
|
|
||||||
end
|
end
|
||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
@@ -120,8 +119,7 @@ function M.create(node)
|
|||||||
-- from when navigating back in the screen stack
|
-- from when navigating back in the screen stack
|
||||||
function instance.back_out(fn, easing, duration, delay)
|
function instance.back_out(fn, easing, duration, delay)
|
||||||
transitions[hash("transition_back_out")] = function(url)
|
transitions[hash("transition_back_out")] = function(url)
|
||||||
print("transition_back_out")
|
fn(node, initial_position, easing, duration, delay or 0, url)
|
||||||
fn(node, initial_position, easing, duration, delay, url)
|
|
||||||
end
|
end
|
||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user