Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
shuijf
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wildfirecode13
shuijf
Commits
129d2ba2
Commit
129d2ba2
authored
Jun 17, 2019
by
wildfirecode
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
fb4a421a
Changes
21
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
1631 additions
and
0 deletions
+1631
-0
MainController.ts
assets/scripts/MainController.ts
+94
-0
ApiComponent.ts
assets/scripts/api/ApiComponent.ts
+71
-0
SampleApi.ts
assets/scripts/api/SampleApi.ts
+46
-0
SamplePollingApi.ts
assets/scripts/api/SamplePollingApi.ts
+74
-0
BuriedPoint.ts
assets/scripts/common/BuriedPoint.ts
+123
-0
Toast.ts
assets/scripts/common/Toast.ts
+81
-0
AlertDialogContent.ts
assets/scripts/dialogs/AlertDialogContent.ts
+21
-0
GameOverPanel.ts
assets/scripts/dialogs/GameOverPanel.ts
+11
-0
RuleDialogContent.ts
assets/scripts/dialogs/RuleDialogContent.ts
+26
-0
entityUtils.ts
assets/scripts/entityUtils.ts
+6
-0
getTween.ts
assets/scripts/getTween.ts
+23
-0
Navigator.ts
assets/scripts/navigator/Navigator.ts
+156
-0
SingleSceneNavigator.ts
assets/scripts/navigator/SingleSceneNavigator.ts
+62
-0
StackNavigator.ts
assets/scripts/navigator/StackNavigator.ts
+101
-0
VirtualNavigator.ts
assets/scripts/navigator/VirtualNavigator.ts
+122
-0
DialogContent.ts
assets/scripts/popup/DialogContent.ts
+77
-0
Popup.ts
assets/scripts/popup/Popup.ts
+160
-0
PopupEffect.ts
assets/scripts/popup/PopupEffect.ts
+163
-0
ScenePlay.ts
assets/scripts/scenes/ScenePlay.ts
+35
-0
SceneStart.ts
assets/scripts/scenes/SceneStart.ts
+109
-0
transformUtils.ts
assets/scripts/transformUtils.ts
+70
-0
No files found.
assets/scripts/MainController.ts
0 → 100644
View file @
129d2ba2
import
ScillaComponent
from
"scilla-components/src/base/ScillaComponent"
;
import
{
dynamic
,
engine
,
Entity
}
from
"scilla/src"
;
import
Toast
from
"./common/Toast"
;
import
{
initEnv
}
from
"./common/BuriedPoint"
;
import
Popup
from
"./popup/Popup"
;
export
default
class
MainController
extends
ScillaComponent
{
Popup
:
Entity
;
//PopupContainer 弹窗容器
Toast
:
Entity
;
//toast 实体
hdToolId
:
dynamic
;
actId
:
dynamic
;
private
_toast
:
Toast
;
private
_popup
:
Popup
;
// fuckNavigator(p) {
// console.log('fuckNavigator from MainController', p)
// }
onAwake
()
{
super
.
onAwake
();
engine
.
dataCenter
.
set
(
'CFG'
,
window
[
'CFG'
]);
this
.
_toast
=
this
.
Toast
.
getComponent
(
Toast
);
this
.
_popup
=
this
.
Popup
.
getComponent
(
Popup
);
initEnv
();
this
.
broadcast
(
'callApi'
,
1
,
'ajaxElement'
,
{
duibaId
:
this
.
hdToolId
,
activityId
:
this
.
actId
})
}
onGotAjaxElement
()
{
this
.
broadcast
(
'initGameStage'
);
}
onGotAjaxElementError
(
e
)
{
console
.
log
(
e
);
// if (typeof e === 'string') {
// switch (e) {
// case '0100016': //活动未开始
// case '0100014': //活动已结束
// case '0100017': //活动已关闭
// this.showErrorToast(e);
// break;
// default:
// this.showNetError();
// }
// } else {
// this.showNetError();
// }
}
showErrorToast
(
e
)
{
// switch (e) {
// case '0100016': //活动未开始
// this.showToast('活动未开始,暂时无法参与');
// break;
// case '0100014': //活动已结束
// case '0100017': //活动已关闭
// this.showToast('活动已结束,无法参与');
// break;
// }
}
showToast
(
content
,
duration
?)
{
this
.
_toast
.
show
({
content
,
duration
,
})
}
showDialog
(
name
,
data
?,
callback
?)
{
this
.
_popup
.
showDialog
(
name
,
data
,
callback
);
}
showNetError
(
action
?)
{
// this.showDialog('Alert', { title: '网络异常', content: '请检查网络后重试!', button: '重新加载', showCloseButton: false }, () => {
// if (typeof action === 'function') {
// action();
// } else {
// action = action || 'refresh';
// switch (action) {
// case 'back':
// history.back();
// break;
// case 'refresh':
// location.reload();
// break;
// }
// }
// })
}
}
assets/scripts/api/ApiComponent.ts
0 → 100644
View file @
129d2ba2
/**
* Created by rockyl on 2018-12-16.
*
* Api接口组件基类
*/
import
{
engine
,
ScillaEvent
}
from
"scilla/src"
;
import
ScillaComponent
from
"scilla-components/src/base/ScillaComponent"
;
export
enum
RequestMethod
{
GET
=
'GET'
,
POST
=
'POST'
,
PUT
=
'PUT'
,
DELETE
=
'DELETE'
,
}
export
default
class
ApiComponent
extends
ScillaComponent
{
name
:
string
;
method
:
RequestMethod
=
RequestMethod
.
POST
;
params
:
any
;
onResponse
:
ScillaEvent
=
new
ScillaEvent
();
onError
:
ScillaEvent
=
new
ScillaEvent
();
onFinish
:
ScillaEvent
=
new
ScillaEvent
();
autoCall
:
boolean
=
false
;
private
_args
;
onAwake
()
{
super
.
onAwake
();
if
(
this
.
autoCall
){
this
.
execute
();
}
}
protected
async
execute
(
paramsInput
?,
...
args
)
{
this
.
_args
=
args
;
}
onGotResponse
(
response
:
any
)
{
if
(
this
.
name
){
engine
.
dataCenter
.
set
(
'API'
,
this
.
name
,
response
.
data
);
}
if
(
this
.
_args
&&
this
.
_args
.
length
>
0
){
this
.
onResponse
.
invoke
(
response
.
data
,
...
this
.
_args
);
}
else
{
this
.
onResponse
.
invoke
(
response
.
data
);
}
this
.
onCallFinish
();
}
onGotError
(
e
)
{
if
(
this
.
_args
&&
this
.
_args
.
length
>
0
){
this
.
onError
.
invoke
(
e
,
...
this
.
_args
);
}
else
{
this
.
onError
.
invoke
(
e
);
}
this
.
onCallFinish
();
}
onCallFinish
(){
if
(
this
.
_args
&&
this
.
_args
.
length
>
0
){
this
.
onFinish
.
invoke
(...
this
.
_args
);
}
else
{
this
.
onFinish
.
invoke
();
}
}
}
assets/scripts/api/SampleApi.ts
0 → 100644
View file @
129d2ba2
/**
* Created by hwj on 2018/12/1.
*
* 简单的api组件
*/
import
{
utils
,
}
from
'scilla/src'
import
ApiComponent
from
"./ApiComponent"
;
import
{
callApi
}
from
"../net/webService"
;
export
default
class
SampleApi
extends
ApiComponent
{
uri
:
string
;
ignoreSuccessField
=
false
;
async
callApi
(
name
,
paramsInput
,
...
args
){
if
(
this
.
name
==
name
){
await
this
.
execute
(
paramsInput
,
...
args
);
}
}
protected
async
execute
(
paramsInput
?,
...
args
)
{
await
super
.
execute
(
paramsInput
,
...
args
);
const
params
=
{};
if
(
this
.
params
){
utils
.
injectProp
(
params
,
this
.
params
);
}
if
(
paramsInput
){
utils
.
injectProp
(
params
,
paramsInput
);
}
const
{
uri
,
method
}
=
this
;
try
{
const
response
=
await
callApi
(
uri
,
params
,
method
,
'json'
,
this
.
ignoreSuccessField
);
this
.
onGotResponse
(
response
);
return
response
.
data
;
}
catch
(
e
)
{
this
.
onGotError
(
e
);
}
}
}
assets/scripts/api/SamplePollingApi.ts
0 → 100644
View file @
129d2ba2
/**
* Created by hwj on 2018/12/1.
*
* 轮询api组件
*/
import
{
raw
,
utils
,}
from
'scilla/src'
import
ApiComponent
from
"./ApiComponent"
;
import
{
polling
}
from
"../net/webService"
;
export
default
class
SamplePollingApi
extends
ApiComponent
{
successField
:
string
;
successValues
:
raw
;
uri
:
string
;
maxTimes
=
5
;
delay
=
500
;
private
_abortFlag
=
false
;
async
callApi
(
name
,
paramsInput
,
...
args
)
{
if
(
this
.
name
==
name
)
{
await
this
.
execute
(
paramsInput
,
...
args
);
}
}
abortCallApi
(
name
){
if
(
this
.
name
==
name
)
{
this
.
_abort
();
}
}
protected
async
execute
(
paramsInput
?,
...
args
)
{
await
super
.
execute
(
paramsInput
,
...
args
);
this
.
_abortFlag
=
false
;
const
params
=
{};
if
(
this
.
params
)
{
utils
.
injectProp
(
params
,
this
.
params
);
}
if
(
paramsInput
)
{
utils
.
injectProp
(
params
,
paramsInput
);
}
const
{
uri
,
method
}
=
this
;
try
{
const
response
=
await
polling
(
this
.
successFunc
,
uri
,
params
,
this
.
maxTimes
,
this
.
delay
,
this
.
abortFunc
,
method
);
this
.
onGotResponse
(
response
);
return
response
.
data
;
}
catch
(
e
)
{
this
.
onGotError
(
e
);
}
}
protected
abortFunc
=
()
=>
{
return
this
.
_abortFlag
;
}
protected
_abort
(){
this
.
_abortFlag
=
true
;
}
successFunc
=
(
response
)
=>
{
// const {successField, successValues} = this;
// let v = successField ? response.data[successField] : response.data;
// return successValues ? successValues.indexOf(v) >= 0 : false;
return
response
.
origin
.
code
!=
"C000000001"
;
}
}
assets/scripts/common/BuriedPoint.ts
0 → 100644
View file @
129d2ba2
/**
* Created by rockyl on 2018-12-26.
*
* 埋点按钮
*/
import
InteractComponent
from
"scilla-components/src/base/InteractComponent"
;
import
{
callApi
}
from
"../net/webService"
;
import
{
engine
}
from
"scilla/src"
;
export
default
class
BuriedPoint
extends
InteractComponent
{
dpm
:
string
;
dcm
:
string
;
private
_buriedPointName
:
string
;
private
_exposured
:
boolean
;
onAwake
()
{
super
.
onAwake
();
if
(
this
.
dpm
&&
this
.
dcm
&&
!
this
.
_exposured
)
{
this
.
setConfig
(
this
.
dpm
,
this
.
dcm
,
true
);
}
}
onTouchTap
(
e
)
{
super
.
onTouchTap
(
e
);
if
(
this
.
_buriedPointName
)
{
logClick
(
this
.
_buriedPointName
);
}
}
setConfig
(
dpm
,
dcm
,
needLogExposure
=
false
)
{
this
.
_buriedPointName
=
'buried-point-'
+
Date
.
now
()
+
Math
.
floor
(
Math
.
random
()
*
999999
);
addBuriedPointConfig
(
this
.
_buriedPointName
,
{
dpm
,
dcm
}
);
if
(
needLogExposure
)
{
logExposure
(
this
.
_buriedPointName
);
this
.
_exposured
=
true
;
}
}
}
let
_buriedPoints
:
any
=
{};
let
env
:
any
;
export
function
initEnv
()
{
const
cfg
=
engine
.
dataCenter
.
get
(
'CFG'
);
env
=
{
app_id
:
cfg
.
appId
,
oaid
:
cfg
.
opActivityId
,
page_id
:
3
,
comp_id
:
4
,
}
}
export
function
addBuriedPoints
(
buriedPoints
)
{
for
(
let
name
in
buriedPoints
)
{
_buriedPoints
[
name
]
=
buriedPoints
[
name
];
}
}
export
function
addBuriedPointConfig
(
name
,
config
)
{
const
{
dpm
,
dcm
}
=
config
;
_buriedPoints
[
name
]
=
new
BuriedPointData
(
dpm
,
dcm
);
}
export
function
addBuriedPointConfigs
(
configs
)
{
for
(
let
name
in
configs
)
{
addBuriedPointConfig
(
name
,
configs
[
name
]);
}
}
export
function
logExposure
(
name
)
{
return
log
(
name
,
'exposure'
);
}
export
function
logClick
(
name
)
{
return
log
(
name
,
'click'
);
}
function
log
(
name
,
type
)
{
if
(
DEBUG
)
{
//return;
}
let
logPoint
=
_buriedPoints
[
name
];
let
appId
=
engine
.
dataCenter
.
get
(
'CFG'
,
'appId'
);
let
{
dpm
,
dcm
}
=
logPoint
;
return
callApi
(
//todo 埋点
type
==
'exposure'
?
'//embedlog.duiba.com.cn/exposure/standard'
:
'/log/click'
,
{
dpm
,
dcm
,
appId
},
'get'
,
type
==
'exposure'
?
'jsonp'
:
'json'
).
catch
(
e
=>
{
//console.log(e);
});
}
function
fillData
(
src
)
{
let
result
=
src
;
for
(
let
key
in
env
)
{
result
=
result
.
replace
(
key
,
env
[
key
]);
}
return
result
;
}
class
BuriedPointData
{
dpm
:
string
;
dcm
:
string
;
constructor
(
dpm
,
dcm
)
{
this
.
dpm
=
fillData
(
dpm
);
this
.
dcm
=
fillData
(
dcm
);
}
}
assets/scripts/common/Toast.ts
0 → 100644
View file @
129d2ba2
/**
* Created by rockyl on 2019-01-02.
*
* Toast
*/
import
{
Entity
,
createTween
,
Tween
,
ease
,
engine
,}
from
"scilla/src"
;
import
ScillaComponent
from
"scilla-components/src/base/ScillaComponent"
;
import
TextRenderer
from
"scilla-components/src/renderer/TextRenderer"
;
import
Transform
from
"scilla-components/src/base/Transform"
;
export
default
class
Toast
extends
ScillaComponent
{
Label
:
Entity
;
padding
=
20
;
offsetY
=
0
;
showDuration
=
300
;
hideDuration
=
300
;
private
_bgTransform
:
Transform
;
private
_labelRenderer
:
TextRenderer
;
private
_labelTransform
:
Transform
;
private
_tweenIn
:
Tween
;
private
_tweenOut
:
Tween
;
private
_timerDuration
;
onAwake
()
{
super
.
onAwake
();
if
(
!
this
.
_bgTransform
)
{
const
{
offsetY
,
hideDuration
,
showDuration
,
transform
}
=
this
;
this
.
_bgTransform
=
this
.
getComponent
(
Transform
);
this
.
_labelRenderer
=
this
.
Label
.
getComponent
(
TextRenderer
);
this
.
_labelTransform
=
this
.
Label
.
getComponent
(
Transform
);
this
.
_tweenIn
=
createTween
(
this
,
transform
,
false
,
{
autoPlay
:
false
})
.
to
({
position
:
{
x
:
0
,
y
:
offsetY
}},
showDuration
,
ease
.
cubicOut
);
this
.
_tweenOut
=
createTween
(
this
,
transform
,
false
,
{
autoPlay
:
false
})
.
to
({
position
:
{
y
:
0
}},
hideDuration
,
ease
.
cubicIn
)
.
call
(
this
.
onHidden
);
this
.
transform
.
position
.
y
=
this
.
outPos
;
}
}
private
get
outPos
(){
return
engine
.
renderContext
.
stageCenter
.
y
+
this
.
_bgTransform
.
height
;
}
show
({
content
,
duration
=
1000
})
{
this
.
entity
.
enabled
=
true
;
const
{
_bgTransform
,
_labelRenderer
,
_labelTransform
,
padding
}
=
this
;
_labelRenderer
.
text
=
content
;
_labelRenderer
.
measureBounds
();
_bgTransform
.
width
=
_labelTransform
.
width
+
padding
*
2
;
_bgTransform
.
height
=
_labelTransform
.
height
+
padding
*
2
;
this
.
_tweenOut
.
queue
[
0
].
props
.
position
.
y
=
this
.
outPos
;
this
.
_tweenIn
.
play
(
true
);
if
(
this
.
_timerDuration
)
{
clearTimeout
(
this
.
_timerDuration
);
this
.
_timerDuration
=
null
;
}
this
.
_timerDuration
=
setTimeout
(()
=>
{
this
.
hide
();
},
duration
);
}
hide
()
{
this
.
_tweenOut
.
play
(
true
);
}
private
onHidden
()
{
this
.
entity
.
enabled
=
false
;
}
}
assets/scripts/dialogs/AlertDialogContent.ts
0 → 100644
View file @
129d2ba2
/**
* Created by rockyl on 2019-04-10.
*
* 警告对话框内容
*/
import
DialogContent
from
"../popup/DialogContent"
;
export
default
class
AlertDialogContent
extends
DialogContent
{
onAwake
()
{
super
.
onAwake
();
}
setup
(
data
:
any
=
{})
{
}
onClickConfirmButton
()
{
this
.
hide
(
'confirm'
)
}
}
assets/scripts/dialogs/GameOverPanel.ts
0 → 100644
View file @
129d2ba2
import
DialogContent
from
'../popup/DialogContent'
;
export
default
class
GameOverPanel
extends
DialogContent
{
onAwake
()
{
super
.
onAwake
();
}
onclick_againBtn
()
{
this
.
bubbling
(
'fuckNavigator'
,
'start'
)
}
}
assets/scripts/dialogs/RuleDialogContent.ts
0 → 100644
View file @
129d2ba2
/**
* Created by rockyl on 2019-04-10.
*
* 规则对话框内容
*/
import
HtmlRenderer
from
"scilla-components/src/renderer/HtmlRenderer"
;
import
{
dynamic
,
Entity
}
from
"scilla/src"
;
import
DialogContent
from
"../popup/DialogContent"
;
export
default
class
RuleDialogContent
extends
DialogContent
{
Content
:
Entity
;
ajaxElement
:
dynamic
;
//ajax Element
private
_contentRenderer
:
HtmlRenderer
;
onAwake
()
{
super
.
onAwake
();
this
.
_contentRenderer
=
this
.
Content
.
getComponent
(
HtmlRenderer
);
}
setup
(
data
)
{
this
.
_contentRenderer
.
htmlText
=
this
.
ajaxElement
.
rule
;
}
}
assets/scripts/entityUtils.ts
0 → 100644
View file @
129d2ba2
import
{
TextRenderer
}
from
"scilla-components/src"
;
import
{
Entity
}
from
"scilla/src"
;
export
const
setText
=
(
entity
:
Entity
,
text
)
=>
{
entity
.
getComponent
(
TextRenderer
).
text
=
text
;
}
\ No newline at end of file
assets/scripts/getTween.ts
0 → 100644
View file @
129d2ba2
import
{
Transform
,
ScillaComponent
}
from
'scilla-components/src'
;
import
{
createTween
,
Entity
}
from
'scilla/src'
;
export
const
getTween
=
(
context
,
val
:
Transform
|
Entity
|
ScillaComponent
,
obj
,
duration
,
ease
?)
=>
{
return
new
Promise
((
r
)
=>
{
let
target
:
Transform
;
if
(
val
instanceof
Transform
)
{
target
=
val
;
}
else
{
target
=
val
.
getComponent
(
Transform
)
}
const
postionObj
=
{};
for
(
const
key
in
obj
)
{
if
(
key
==
'x'
||
key
==
'y'
)
{
postionObj
[
key
]
=
obj
[
key
];
delete
obj
[
key
];
}
}
createTween
(
context
,
target
.
position
,
true
).
to
(
postionObj
,
duration
,
ease
);
createTween
(
context
,
target
,
true
).
to
(
obj
,
duration
,
ease
).
call
(
r
);
});
}
\ No newline at end of file
assets/scripts/navigator/Navigator.ts
0 → 100644
View file @
129d2ba2
/**
* Created by rocky.l on 2017/1/19.
*
* 场景导航器
*/
import
{
EventEmitter
}
from
'scilla/src'
import
{
alien
}
from
"./StackNavigator"
;
import
NavigatorAction
=
alien
.
NavigatorAction
;
import
INavigatorDelegate
=
alien
.
INavigatorDelegate
;
import
StackNavigator
=
alien
.
StackNavigator
;
export
interface
INavigatorViewBase
{
onAddView
():
boolean
;
onWillMount
(
last
:
string
,
action
:
NavigatorAction
,
parameters
:
any
):
Promise
<
any
>
;
onWillUnMount
(
next
:
string
,
action
:
NavigatorAction
,
parameters
:
any
):
Promise
<
any
>
;
onWillEnter
(
last
:
string
,
action
:
NavigatorAction
,
parameters
:
any
):
Promise
<
any
>
;
onDidEnter
(
last
:
string
,
action
:
NavigatorAction
,
parameters
:
any
):
void
;
onWillLeave
(
next
:
string
,
action
:
NavigatorAction
,
parameters
:
any
):
Promise
<
any
>
;
onDidLeave
(
next
:
string
,
action
:
NavigatorAction
,
parameters
:
any
):
void
;
}
const
showLog
=
false
;
export
class
Navigator
extends
EventEmitter
implements
INavigatorDelegate
{
static
VIEW_WILL_ENTER
:
string
=
'VIEW_WILL_ENTER'
;
static
VIEW_DID_ENTER
:
string
=
'VIEW_DID_ENTER'
;
static
VIEW_WILL_LEAVE
:
string
=
'VIEW_WILL_LEAVE'
;
static
VIEW_DID_LEAVE
:
string
=
'VIEW_DID_LEAVE'
;
stack
:
StackNavigator
;
protected
_classDic
:
any
;
protected
_instanceDic
:
any
;
protected
_currentName
:
string
;
protected
_currentView
:
INavigatorViewBase
;
constructor
()
{
super
();
this
.
_classDic
=
{};
this
.
_instanceDic
=
{};
this
.
stack
=
new
StackNavigator
(
this
);
}
register
(
name
:
string
,
clazz
:
any
):
void
{
this
.
_classDic
[
name
]
=
clazz
;
}
push
(
name
:
string
,
parameters
:
any
=
null
)
{
this
.
stack
.
push
(
name
,
parameters
);
}
pop
(
parameters
:
any
=
null
)
{
this
.
stack
.
pop
(
parameters
);
}
popToBottom
(
parameters
:
any
=
null
)
{
this
.
stack
.
popTo
(
0
,
null
,
parameters
);
}
popAll
(
name
:
string
,
parameters
:
any
=
null
)
{
this
.
stack
.
popAll
(
name
,
parameters
);
}
replace
(
name
:
string
,
parameters
:
any
=
null
)
{
this
.
stack
.
replace
(
name
,
parameters
);
}
jump
(
name
:
string
,
parameters
:
any
=
null
)
{
this
.
stack
.
jump
(
name
,
parameters
);
}
get
currentView
():
INavigatorViewBase
{
return
this
.
_currentView
;
}
get
currentName
():
string
{
return
this
.
_currentName
;
}
protected
newView
(
name
:
string
):
INavigatorViewBase
{
return
new
this
.
_classDic
[
name
]();
}
protected
getViewInstanceByName
(
name
:
string
):
INavigatorViewBase
{
let
view
:
INavigatorViewBase
=
this
.
_instanceDic
[
name
];
if
(
!
view
)
{
view
=
this
.
_instanceDic
[
name
]
=
this
.
newView
(
name
);
}
return
view
;
}
protected
addView
(
view
:
INavigatorViewBase
,
addToBottom
)
{
}
/**
* 栈入实现
* @param name
* @param last
* @param action
* @param parameters
* @returns {Promise<void>}
*/
async
onEnter
(
name
:
string
,
last
:
string
,
action
:
NavigatorAction
,
parameters
:
any
)
{
let
view
:
INavigatorViewBase
=
this
.
getViewInstanceByName
(
name
);
this
.
_currentView
=
view
;
this
.
_currentName
=
name
;
await
view
.
onWillMount
(
last
,
action
,
parameters
);
let
addToBottom
=
view
.
onAddView
();
this
.
addView
(
view
,
addToBottom
);
if
(
showLog
)
console
.
log
(
name
+
' will enter.'
);
this
.
emit
(
Navigator
.
VIEW_WILL_ENTER
,
{
name
,
last
,
action
,
parameters
});
await
view
.
onWillEnter
(
last
,
action
,
parameters
);
if
(
showLog
)
console
.
log
(
name
+
' did enter.'
);
this
.
emit
(
Navigator
.
VIEW_DID_ENTER
,
{
name
,
last
,
action
,
parameters
});
view
.
onDidEnter
(
last
,
action
,
parameters
);
}
/**
* 栈出实现
* @param name
* @param next
* @param action
* @param parameters
* @returns {Promise<void>}
*/
async
onLeave
(
name
:
string
,
next
:
string
,
action
:
NavigatorAction
,
parameters
:
any
)
{
let
view
:
INavigatorViewBase
=
this
.
getViewInstanceByName
(
name
);
await
view
.
onWillUnMount
(
name
,
action
,
parameters
);
if
(
showLog
)
console
.
log
(
name
+
' will leave.'
);
this
.
emit
(
Navigator
.
VIEW_WILL_LEAVE
,
{
name
,
next
,
action
,
parameters
});
await
view
.
onWillLeave
(
next
,
action
,
parameters
);
if
(
showLog
)
console
.
log
(
name
+
' did leave.'
);
this
.
emit
(
Navigator
.
VIEW_DID_LEAVE
,
{
name
,
next
,
action
,
parameters
});
view
.
onDidLeave
(
next
,
action
,
parameters
);
}
/**
* 当收到错误实现
* @param error
*/
onError
(
error
:
Error
)
{
}
}
assets/scripts/navigator/SingleSceneNavigator.ts
0 → 100644
View file @
129d2ba2
/**
* Created by rockyl on 2019-04-09.
*
* 单场景导航器
*/
import
ScillaComponent
from
"scilla-components/src/base/ScillaComponent"
;
import
{
ScenePlay
,
SceneStart
}
from
"../scenes"
;
import
{
VirtualNavigator
}
from
"./VirtualNavigator"
;
export
default
class
SingleSceneNavigator
extends
ScillaComponent
{
_navigator
:
VirtualNavigator
;
onCreate
()
{
super
.
onCreate
();
this
.
_navigator
=
new
VirtualNavigator
(
this
.
entity
);
this
.
_navigator
.
register
(
'start'
,
'SceneStart'
,
SceneStart
);
this
.
_navigator
.
register
(
'play'
,
'ScenePlay'
,
ScenePlay
);
}
onAwake
()
{
super
.
onAwake
();
this
.
push
(
'start'
);
}
onUpdate
(
t
)
{
super
.
onUpdate
(
t
);
}
onSleep
()
{
super
.
onSleep
();
}
onDestroy
()
{
super
.
onDestroy
();
}
push
(
name
:
string
,
parameters
:
any
=
null
)
{
this
.
_navigator
.
stack
.
push
(
name
,
parameters
);
}
pop
(
parameters
:
any
=
null
)
{
this
.
_navigator
.
stack
.
pop
(
parameters
);
}
popToBottom
(
parameters
:
any
=
null
)
{
this
.
_navigator
.
stack
.
popTo
(
0
,
null
,
parameters
);
}
popAll
(
name
:
string
,
parameters
:
any
=
null
)
{
this
.
_navigator
.
stack
.
popAll
(
name
,
parameters
);
}
replace
(
name
:
string
,
parameters
:
any
=
null
)
{
this
.
_navigator
.
stack
.
replace
(
name
,
parameters
);
}
jump
(
name
:
string
,
parameters
:
any
=
null
)
{
this
.
_navigator
.
stack
.
jump
(
name
,
parameters
);
}
}
assets/scripts/navigator/StackNavigator.ts
0 → 100644
View file @
129d2ba2
/**
* Created by rocky.l on 2017/1/17.
*
* 堆栈导航器
*/
export
module
alien
{
export
enum
NavigatorAction
{
Push
,
Pop
,
Replace
,
Jump
}
export
interface
INavigatorDelegate
{
onEnter
(
name
:
string
,
last
:
string
,
action
:
NavigatorAction
,
parameters
:
any
);
onLeave
(
name
:
string
,
next
:
string
,
action
:
NavigatorAction
,
parameters
:
any
);
onError
(
error
:
Error
);
}
export
class
StackNavigator
{
private
_stack
:
string
[];
private
_delegate
:
INavigatorDelegate
;
constructor
(
delegate
:
INavigatorDelegate
)
{
this
.
_stack
=
[];
this
.
_delegate
=
delegate
;
}
private
catchPromise
(
p
:
Promise
<
any
>
)
{
if
(
p
)
{
p
.
catch
((
e
=>
{
this
.
_delegate
.
onError
(
e
);
}))
}
}
push
(
name
:
string
,
parameters
:
any
=
null
)
{
let
last
:
string
=
this
.
getTopSceneName
();
if
(
last
)
{
if
(
last
==
name
)
{
return
;
}
this
.
catchPromise
(
this
.
_delegate
.
onLeave
(
last
,
name
,
NavigatorAction
.
Push
,
parameters
));
}
this
.
_stack
.
push
(
name
);
this
.
catchPromise
(
this
.
_delegate
.
onEnter
(
name
,
last
,
NavigatorAction
.
Push
,
parameters
));
}
popTo
(
index
,
name
?:
string
,
parameters
:
any
=
null
)
{
if
(
this
.
_stack
.
length
>
0
&&
this
.
_stack
.
length
<
(
index
+
1
))
{
return
;
}
let
last
:
string
=
this
.
getTopSceneName
();
this
.
_stack
.
splice
(
Math
.
max
(
index
+
1
,
0
));
let
next
:
string
=
this
.
_stack
[
index
];
if
(
!
next
)
{
this
.
_stack
.
push
(
next
=
name
);
}
if
(
last
)
{
this
.
catchPromise
(
this
.
_delegate
.
onLeave
(
last
,
next
,
NavigatorAction
.
Pop
,
parameters
));
}
this
.
catchPromise
(
this
.
_delegate
.
onEnter
(
next
,
last
,
NavigatorAction
.
Pop
,
parameters
));
}
pop
(
parameters
:
any
=
null
)
{
this
.
popTo
(
this
.
_stack
.
length
-
2
,
null
,
parameters
);
}
popAll
(
name
:
string
,
parameters
:
any
=
null
)
{
this
.
popTo
(
-
1
,
name
,
parameters
);
}
replace
(
name
:
string
,
parameters
:
any
=
null
)
{
let
last
:
string
=
this
.
_stack
.
pop
();
this
.
_stack
.
push
(
name
);
this
.
catchPromise
(
this
.
_delegate
.
onLeave
(
last
,
name
,
NavigatorAction
.
Replace
,
parameters
));
this
.
catchPromise
(
this
.
_delegate
.
onEnter
(
name
,
last
,
NavigatorAction
.
Replace
,
parameters
));
}
jump
(
name
:
string
,
parameters
:
any
=
null
){
if
(
this
.
_stack
.
length
<
2
){
this
.
push
(
name
,
parameters
);
return
;
}
let
last
:
string
=
this
.
_stack
.
pop
();
this
.
_stack
.
splice
(
1
);
let
next
:
string
=
name
;
this
.
_stack
.
push
(
next
);
this
.
_delegate
.
onLeave
(
last
,
next
,
NavigatorAction
.
Pop
,
parameters
);
this
.
_delegate
.
onEnter
(
next
,
last
,
NavigatorAction
.
Pop
,
parameters
);
}
private
getTopSceneName
():
string
{
return
this
.
_stack
.
length
>
0
?
this
.
_stack
[
this
.
_stack
.
length
-
1
]
:
null
;
}
private
getBottomSceneName
():
string
{
return
this
.
_stack
.
length
>
0
?
this
.
_stack
[
0
]
:
null
;
}
}
}
assets/scripts/navigator/VirtualNavigator.ts
0 → 100644
View file @
129d2ba2
/**
* Created by rocky.l on 2017/1/19.
*
* 场景导航器
*/
import
{
Entity
,
EventEmitter
}
from
'scilla/src'
import
{
alien
}
from
"./StackNavigator"
;
import
NavigatorAction
=
alien
.
NavigatorAction
;
import
INavigatorDelegate
=
alien
.
INavigatorDelegate
;
import
StackNavigator
=
alien
.
StackNavigator
;
const
showLog
=
false
;
export
const
VIEW_WILL_ENTER
:
string
=
'VIEW_WILL_ENTER'
;
export
const
VIEW_DID_ENTER
:
string
=
'VIEW_DID_ENTER'
;
export
const
VIEW_WILL_LEAVE
:
string
=
'VIEW_WILL_LEAVE'
;
export
const
VIEW_DID_LEAVE
:
string
=
'VIEW_DID_LEAVE'
;
export
interface
INavigatorViewBase
{
onWillMount
(
last
:
string
,
action
:
NavigatorAction
,
parameters
:
any
):
Promise
<
any
>
;
onWillUnMount
(
next
:
string
,
action
:
NavigatorAction
,
parameters
:
any
):
Promise
<
any
>
;
onWillEnter
(
last
:
string
,
action
:
NavigatorAction
,
parameters
:
any
):
Promise
<
any
>
;
onDidEnter
(
last
:
string
,
action
:
NavigatorAction
,
parameters
:
any
):
void
;
onWillLeave
(
next
:
string
,
action
:
NavigatorAction
,
parameters
:
any
):
Promise
<
any
>
;
onDidLeave
(
next
:
string
,
action
:
NavigatorAction
,
parameters
:
any
):
void
;
}
export
class
VirtualNavigator
extends
EventEmitter
implements
INavigatorDelegate
{
stack
:
StackNavigator
;
protected
_currentName
:
string
;
protected
_currentView
:
INavigatorViewBase
;
protected
_classDic
:
any
;
protected
_container
:
Entity
;
constructor
(
container
)
{
super
();
this
.
_container
=
container
;
this
.
_classDic
=
{};
this
.
stack
=
new
StackNavigator
(
this
);
}
register
(
alias
:
string
,
childName
:
string
,
componentDef
):
void
{
this
.
_classDic
[
alias
]
=
{
childName
,
componentDef
,
};
}
get
currentView
():
INavigatorViewBase
{
return
this
.
_currentView
;
}
get
currentName
():
string
{
return
this
.
_currentName
;
}
protected
getViewInstanceByName
(
name
:
string
):
INavigatorViewBase
{
let
{
childName
,
componentDef
,}
=
this
.
_classDic
[
name
];
let
scene
:
Entity
=
this
.
_container
.
getChildrenByName
(
childName
)[
0
];
let
component
:
any
=
scene
.
getComponent
(
componentDef
);
return
component
;
}
/**
* 栈入实现
* @param name
* @param last
* @param action
* @param parameters
* @returns {Promise<void>}
*/
async
onEnter
(
name
:
string
,
last
:
string
,
action
:
NavigatorAction
,
parameters
:
any
)
{
let
view
:
INavigatorViewBase
=
this
.
getViewInstanceByName
(
name
);
this
.
_currentView
=
view
;
this
.
_currentName
=
name
;
await
view
.
onWillMount
(
last
,
action
,
parameters
);
if
(
showLog
)
console
.
log
(
name
+
' will enter.'
);
this
.
emit
(
VIEW_WILL_ENTER
,
{
name
,
last
,
action
,
parameters
});
await
view
.
onWillEnter
(
last
,
action
,
parameters
);
if
(
showLog
)
console
.
log
(
name
+
' did enter.'
);
this
.
emit
(
VIEW_DID_ENTER
,
{
name
,
last
,
action
,
parameters
});
view
.
onDidEnter
(
last
,
action
,
parameters
);
}
/**
* 栈出实现
* @param name
* @param next
* @param action
* @param parameters
* @returns {Promise<void>}
*/
async
onLeave
(
name
:
string
,
next
:
string
,
action
:
NavigatorAction
,
parameters
:
any
)
{
let
view
:
INavigatorViewBase
=
this
.
getViewInstanceByName
(
name
);
await
view
.
onWillUnMount
(
name
,
action
,
parameters
);
if
(
showLog
)
console
.
log
(
name
+
' will leave.'
);
this
.
emit
(
VIEW_WILL_LEAVE
,
{
name
,
next
,
action
,
parameters
});
await
view
.
onWillLeave
(
next
,
action
,
parameters
);
if
(
showLog
)
console
.
log
(
name
+
' did leave.'
);
this
.
emit
(
VIEW_DID_LEAVE
,
{
name
,
next
,
action
,
parameters
});
view
.
onDidLeave
(
next
,
action
,
parameters
);
}
/**
* 当收到错误实现
* @param error
*/
onError
(
error
:
Error
)
{
}
}
assets/scripts/popup/DialogContent.ts
0 → 100644
View file @
129d2ba2
/**
* Created by rockyl on 2018-12-12.
*
* 对话框内容组件
*/
import
ScillaComponent
from
"scilla-components/src/base/ScillaComponent"
;
import
{
fade
,
flew
,
none
,
zoom
}
from
"./PopupEffect"
;
import
{
raw
}
from
"scilla/src"
;
import
{
decorators
}
from
"scilla/src"
;
import
{
Button
}
from
"scilla-components/src"
;
const
{
dirtyFieldTrigger
}
=
decorators
;
export
default
class
DialogContent
extends
ScillaComponent
{
@
dirtyFieldTrigger
effect
:
PopupEffect
=
PopupEffect
.
flew
;
showEffectOptions
:
raw
;
hideEffectOptions
:
raw
;
protected
_closeButtons
:
Button
[];
effectImpl
=
none
;
protected
onModify
(
value
,
key
,
oldValue
)
{
super
.
onModify
(
value
,
key
,
oldValue
);
if
(
key
===
'effect'
)
{
this
.
effectImpl
=
effects
[
value
];
}
}
onAwake
()
{
super
.
onAwake
();
if
(
!
this
.
_closeButtons
)
{
this
.
_closeButtons
=
[];
const
buttons
=
this
.
entity
.
getChildrenByName
(
'CloseButton'
);
if
(
buttons
)
{
buttons
.
forEach
(
button
=>
{
const
closeBtn
=
button
.
getComponent
(
Button
);
closeBtn
.
onClick
.
addListener
(
this
.
onTapCloseButton
,
this
);
})
}
}
}
protected
onTapCloseButton
()
{
this
.
hide
();
}
setup
(
data
)
{
}
show
=
(
data
?,
callback
?)
=>
{
this
.
bubbling
(
'showDialog'
,
this
.
entity
.
name
,
data
,
callback
);
}
hide
=
(
action
?)
=>
{
this
.
bubbling
(
'hideDialog'
,
this
.
entity
.
name
,
action
||
'close'
);
}
}
const
effects
=
{
none
,
fade
,
flew
,
zoom
,
};
export
enum
PopupEffect
{
none
=
'none'
,
fade
=
'fade'
,
flew
=
'flew'
,
zoom
=
'zoom'
,
}
assets/scripts/popup/Popup.ts
0 → 100644
View file @
129d2ba2
/**
* Created by rockyl on 2018-12-12.
* 弹层
*/
import
DialogContent
from
"./DialogContent"
;
import
RectRenderer
from
"scilla-components/src/renderer/RectRenderer"
;
import
TouchInterrupt
from
"scilla-components/src/base/TouchInterrupt"
;
import
Transform
from
"scilla-components/src/base/Transform"
;
import
ScillaComponent
from
"scilla-components/src/base/ScillaComponent"
;
import
{
none
}
from
"./PopupEffect"
;
import
{
createTween
,
Entity
}
from
"scilla/src"
;
import
SingleSceneNavigator
from
"../navigator/SingleSceneNavigator"
;
export
default
class
Popup
extends
ScillaComponent
{
blackLayerDuration
=
300
;
private
_bgRenderer
:
RectRenderer
;
private
_touchInterrupt
:
TouchInterrupt
;
private
_dialogStack
=
[];
sceneContainer
:
Entity
;
_navigator
:
SingleSceneNavigator
;
onAwake
()
{
super
.
onAwake
();
this
.
_touchInterrupt
=
this
.
getComponent
(
TouchInterrupt
);
this
.
_touchInterrupt
.
enabled
=
false
;
const
bgRenderer
=
this
.
_bgRenderer
=
this
.
getComponent
(
RectRenderer
);
bgRenderer
.
enabled
=
false
;
this
.
_navigator
=
this
.
sceneContainer
.
getComponent
(
SingleSceneNavigator
)
}
fuckNavigator
(
p
)
{
console
.
log
(
'fuckNavigator'
,
p
)
this
.
_navigator
.
push
(
p
)
}
onUpdate
(
t
)
{
super
.
onUpdate
(
t
);
}
onSleep
()
{
super
.
onSleep
();
}
onDestroy
()
{
super
.
onDestroy
();
}
setBgVisible
(
visible
)
{
if
(
visible
)
{
this
.
_bgRenderer
.
enabled
=
true
;
}
this
.
_bgRenderer
.
alpha
=
visible
?
0
:
1
;
createTween
(
this
,
this
.
_bgRenderer
,
true
)
.
to
({
alpha
:
visible
?
1
:
0
},
this
.
blackLayerDuration
)
.
call
(()
=>
{
if
(
!
visible
)
{
this
.
_bgRenderer
.
enabled
=
false
;
}
});
}
getDialogInStack
(
name
)
{
let
result
;
for
(
let
dialog
of
this
.
_dialogStack
)
{
if
(
dialog
.
name
===
name
)
{
result
=
dialog
;
break
;
}
}
return
result
;
}
private
bringToTop
(
dialogConfig
)
{
let
index
=
this
.
_dialogStack
.
indexOf
(
dialogConfig
);
if
(
index
>=
0
)
{
this
.
_dialogStack
.
splice
(
index
,
1
);
}
this
.
_dialogStack
.
push
(
dialogConfig
);
}
private
delete
(
dialogConfig
)
{
let
index
=
this
.
_dialogStack
.
indexOf
(
dialogConfig
);
this
.
_dialogStack
.
splice
(
index
,
1
);
}
async
showDialog
(
name
,
data
?,
callback
?)
{
let
dialogConfig
=
this
.
getDialogInStack
(
name
);
let
dialog
=
this
.
entity
.
getChildrenByName
(
name
)[
0
];
if
(
!
dialogConfig
)
{
dialogConfig
=
{
name
,
data
,
callback
,
dialog
};
dialog
.
enabled
=
true
;
}
this
.
bringToTop
(
dialogConfig
);
const
parent
=
dialog
.
parent
;
parent
.
removeChild
(
dialog
);
parent
.
addChildAt
(
dialog
,
parent
.
children
.
length
);
this
.
setBgVisible
(
true
);
this
.
_touchInterrupt
.
enabled
=
true
;
const
content
:
DialogContent
=
dialog
.
getComponent
(
DialogContent
);
content
&&
content
.
setup
(
data
);
const
transform
=
dialog
.
getComponent
(
Transform
);
const
effect
=
content
?
content
.
effectImpl
:
none
;
const
effectOptions
=
content
?
content
.
showEffectOptions
:
null
;
await
effect
.
show
(
transform
,
effectOptions
);
}
async
hideDialog
(
name
,
action
?:
string
,
data
?)
{
let
dialogConfig
=
this
.
getDialogInStack
(
name
);
if
(
!
dialogConfig
)
{
return
;
}
let
dialog
=
this
.
entity
.
getChildrenByName
(
name
)[
0
];
this
.
delete
(
dialogConfig
);
if
(
this
.
_dialogStack
.
length
===
0
)
{
this
.
setBgVisible
(
false
);
this
.
_touchInterrupt
.
enabled
=
false
;
}
const
transform
=
dialog
.
getComponent
(
Transform
);
const
content
:
DialogContent
=
dialog
.
getComponent
(
DialogContent
);
const
effect
=
content
?
content
.
effectImpl
:
none
;
const
effectOptions
=
content
?
content
.
hideEffectOptions
:
null
;
await
effect
.
hide
(
transform
,
effectOptions
);
dialog
.
enabled
=
false
;
if
(
dialogConfig
.
callback
)
{
dialogConfig
.
callback
(
action
,
data
);
dialogConfig
.
callback
=
null
;
}
}
hideAll
()
{
for
(
let
dialog
of
this
.
_dialogStack
)
{
this
.
hideDialog
(
dialog
.
name
);
}
}
}
assets/scripts/popup/PopupEffect.ts
0 → 100644
View file @
129d2ba2
/**
* Created by rockyl on 2019-05-15.
*/
import
Transform
from
"scilla-components/src/base/Transform"
;
import
{
createTween
,
ease
,
engine
}
from
"scilla/src"
;
function
bearingsToOutPos
(
bearings
)
{
const
{
width
,
height
}
=
engine
.
renderContext
.
stageSize
;
let
x
,
y
;
switch
(
bearings
)
{
case
'south'
:
x
=
0
;
y
=
height
/
2
;
break
;
case
'west'
:
x
=
-
width
/
2
;
y
=
0
;
break
;
case
'east'
:
x
=
width
/
2
;
y
=
0
;
break
;
case
'north'
:
default
:
x
=
0
;
y
=
-
height
/
2
;
}
return
{
x
,
y
,
}
}
export
const
none
=
{
show
(
transform
:
Transform
,
options
?)
{
transform
.
position
.
setXY
(
0
,
0
);
return
Promise
.
resolve
();
},
hide
(
transform
:
Transform
,
options
?)
{
transform
.
position
.
setXY
(
engine
.
renderContext
.
stageSize
.
width
,
0
);
return
Promise
.
resolve
();
}
};
export
const
fade
=
{
show
(
transform
:
Transform
,
options
?:
{
bearings
?:
string
,
duration
?:
number
,
easeFunc
?:
Function
})
{
options
=
options
||
{};
transform
.
alpha
=
0
;
const
toProps
:
any
=
{
alpha
:
1
,
};
return
new
Promise
(
resolve
=>
{
createTween
(
transform
,
transform
)
.
to
(
toProps
,
options
.
duration
||
300
,
options
.
easeFunc
)
.
call
(
resolve
);
})
},
hide
(
transform
:
Transform
,
options
?:
{
bearings
?:
string
,
duration
?:
number
,
easeFunc
?:
Function
})
{
options
=
options
||
{};
const
toProps
:
any
=
{
alpha
:
0
,
};
return
new
Promise
(
resolve
=>
{
createTween
(
transform
,
transform
)
.
to
(
toProps
,
options
.
duration
||
200
,
options
.
easeFunc
)
.
call
(
resolve
);
});
}
};
export
const
flew
=
{
show
(
transform
:
Transform
,
options
?:
{
bearings
?:
string
,
withFade
?:
boolean
,
duration
?:
number
,
easeFunc
?:
Function
})
{
options
=
options
||
{};
let
outPos
=
bearingsToOutPos
(
options
.
bearings
);
transform
.
position
.
copyFrom
(
outPos
);
const
toProps
:
any
=
{
position
:
{
x
:
0
,
y
:
0
,},
};
const
withFade
=
options
.
hasOwnProperty
(
'withFade'
)
?
options
.
withFade
:
false
;
if
(
withFade
)
{
transform
.
alpha
=
0
;
toProps
.
alpha
=
1
;
}
return
new
Promise
(
resolve
=>
{
createTween
(
transform
,
transform
)
.
to
(
toProps
,
options
.
duration
||
300
,
options
.
easeFunc
||
ease
.
backOut
)
.
call
(
resolve
);
})
},
hide
(
transform
:
Transform
,
options
?:
{
bearings
?:
string
,
withFade
?:
boolean
,
duration
?:
number
,
easeFunc
?:
Function
})
{
options
=
options
||
{};
let
outPos
=
bearingsToOutPos
(
options
.
bearings
);
const
toProps
:
any
=
{
position
:
outPos
,
};
const
withFade
=
options
.
hasOwnProperty
(
'withFade'
)
?
options
.
withFade
:
false
;
if
(
withFade
)
{
toProps
.
alpha
=
0
;
}
return
new
Promise
(
resolve
=>
{
createTween
(
transform
,
transform
)
.
to
(
toProps
,
options
.
duration
||
200
,
options
.
easeFunc
||
ease
.
backIn
)
.
call
(
resolve
);
});
}
};
export
const
zoom
=
{
show
(
transform
:
Transform
,
options
?:
{
bearings
?:
string
,
withFade
?:
boolean
,
duration
?:
number
,
easeFunc
?:
Function
})
{
options
=
options
||
{};
transform
.
scale
.
setXY
(
0
,
0
);
const
toProps
:
any
=
{
scale
:
{
x
:
1
,
y
:
1
,},
};
const
withFade
=
options
.
hasOwnProperty
(
'withFade'
)
?
options
.
withFade
:
false
;
if
(
withFade
)
{
transform
.
alpha
=
0
;
toProps
.
alpha
=
1
;
}
return
new
Promise
(
resolve
=>
{
createTween
(
transform
,
transform
)
.
to
(
toProps
,
options
.
duration
||
300
,
options
.
easeFunc
||
ease
.
backOut
)
.
call
(
resolve
);
})
},
hide
(
transform
:
Transform
,
options
?:
{
bearings
?:
string
,
withFade
?:
boolean
,
duration
?:
number
,
easeFunc
?:
Function
})
{
options
=
options
||
{};
const
toProps
:
any
=
{
scale
:
{
x
:
0
,
y
:
0
},
};
const
withFade
=
options
.
hasOwnProperty
(
'withFade'
)
?
options
.
withFade
:
false
;
if
(
withFade
)
{
toProps
.
alpha
=
0
;
}
return
new
Promise
(
resolve
=>
{
createTween
(
transform
,
transform
)
.
to
(
toProps
,
options
.
duration
||
200
,
options
.
easeFunc
||
ease
.
backIn
)
.
call
(
resolve
);
});
}
};
assets/scripts/scenes/ScenePlay.ts
0 → 100644
View file @
129d2ba2
import
ScillaComponent
from
"scilla-components/src/base/ScillaComponent"
;
import
{
alien
}
from
"../navigator/StackNavigator"
;
import
{
INavigatorViewBase
}
from
"../navigator/VirtualNavigator"
;
export
default
class
ScenePlay
extends
ScillaComponent
implements
INavigatorViewBase
{
onAwake
()
{
super
.
onAwake
();
}
// _timer
onDidEnter
(
last
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
void
{
this
.
entity
.
enabled
=
true
;
}
onDidLeave
(
next
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
void
{
this
.
entity
.
enabled
=
false
;
}
async
onWillEnter
(
last
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
)
{
}
async
onWillLeave
(
next
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
)
{
}
onWillMount
(
last
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
Promise
<
any
>
{
return
undefined
;
}
onWillUnMount
(
next
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
Promise
<
any
>
{
return
undefined
;
}
}
assets/scripts/scenes/SceneStart.ts
0 → 100644
View file @
129d2ba2
/**
* Created by rockyl on 2019-04-09.
*/
import
ScillaComponent
from
"scilla-components/src/base/ScillaComponent"
;
import
{
dynamic
,
Entity
}
from
"scilla/src"
;
import
{
setText
}
from
"../entityUtils"
;
import
{
alien
}
from
"../navigator/StackNavigator"
;
import
{
INavigatorViewBase
}
from
"../navigator/VirtualNavigator"
;
export
default
class
SceneStart
extends
ScillaComponent
implements
INavigatorViewBase
{
ajaxElement
:
dynamic
;
doJoin
:
dynamic
;
// getNgameStartStatus: dynamic;
countTxt
:
Entity
;
startbtn
:
Entity
;
rankbtn
:
Entity
;
rulebtn
:
Entity
;
onAwake
()
{
super
.
onAwake
();
this
.
setCountText
(
''
);
// SingleSceneNavigator
console
.
log
(
'fuck start scene'
)
}
private
setCountText
(
text
:
string
)
{
setText
(
this
.
countTxt
,
text
);
}
initGameStage
()
{
this
.
updateCountText
();
}
updateCountText
()
{
const
{
element
}
=
this
.
ajaxElement
;
let
text
=
''
if
(
element
.
freeLimit
>
0
)
{
text
=
`今日剩余免费次数:
${
element
.
freeLimit
}
次`
;
}
else
{
text
=
`
${
element
.
needCredits
}${
window
[
'CFG'
].
unitName
}
/次`
}
this
.
setCountText
(
text
);
}
onClick_startbtn
()
{
this
.
broadcast
(
'callApi'
,
1
,
'doJoin'
,
{
activityId
:
window
[
'CFG'
].
actId
,
activityType
:
'hdtool'
,
consumerId
:
window
[
'CFG'
].
consumerId
});
// globalEvent.emit('popup', { name: 'RulePanel', params: {} }, this.onAlertClose);
}
onGotDojoin
()
{
console
.
log
(
'onGotDojoin'
,
this
.
doJoin
);
this
.
broadcast
(
'callApi'
,
1
,
'getNgameStartStatus'
,
{
orderId
:
this
.
doJoin
});
}
onGotDojoinError
()
{
console
.
log
(
'onGotDojoinError'
)
}
onGot_getNgameStartStatus
()
{
// console.log('onGot_getNgameStartStatus', this.getNgameStartStatus);
//fuck 不可以循环引用
this
.
bubbling
(
'fuck'
,
'play'
);
}
onGotError_getNgameStartStatus
()
{
console
.
log
(
'onGotError_getNgameStartStatus'
);
}
onClick_rulebtn
()
{
console
.
log
(
'onClick_rulebtn'
);
this
.
bubbling
(
'showDialog'
,
'Rule'
);
}
onClick_rankbtn
()
{
alert
(
'onClick_rankbtn'
)
// globalEvent.emit('alert', {title: 'Success', content: 'You complete this puzzle', button: 'Next level'}, this.onAlertClose);
}
onDidEnter
(
last
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
void
{
this
.
entity
.
enabled
=
true
;
}
onDidLeave
(
next
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
void
{
this
.
entity
.
enabled
=
false
;
}
async
onWillEnter
(
last
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
)
{
}
async
onWillLeave
(
next
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
)
{
}
onWillMount
(
last
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
Promise
<
any
>
{
return
undefined
;
}
onWillUnMount
(
next
:
string
,
action
:
alien
.
NavigatorAction
,
parameters
:
any
):
Promise
<
any
>
{
return
undefined
;
}
}
assets/scripts/transformUtils.ts
0 → 100644
View file @
129d2ba2
import
ScillaComponent
from
'components/base/ScillaComponent'
;
import
{
Transform
,
TextRenderer
}
from
'scilla-components/src'
;
import
{
Entity
}
from
'scilla/src'
;
export
const
setX
=
(
entity
:
Entity
,
x
)
=>
{
entity
.
getComponent
(
Transform
).
position
.
x
=
x
;
}
export
const
setAlpha
=
(
val
:
Entity
|
ScillaComponent
,
alpha
:
number
)
=>
{
if
(
val
instanceof
Entity
)
{
val
.
getComponent
(
Transform
).
alpha
=
alpha
;
}
else
if
(
val
instanceof
ScillaComponent
)
{
val
.
entity
.
getComponent
(
Transform
).
alpha
=
alpha
;
}
}
export
const
setScale
=
(
val
:
Entity
|
ScillaComponent
,
x
)
=>
{
if
(
val
instanceof
Entity
)
{
val
.
getComponent
(
Transform
).
scale
.
x
=
x
;
val
.
getComponent
(
Transform
).
scale
.
y
=
x
;
}
else
if
(
val
instanceof
ScillaComponent
)
{
val
.
entity
.
getComponent
(
Transform
).
scale
.
x
=
x
;
val
.
entity
.
getComponent
(
Transform
).
scale
.
y
=
x
;
}
}
export
const
setText
=
(
entity
:
Entity
,
text
:
string
)
=>
{
entity
.
getComponent
(
TextRenderer
).
text
=
text
;
}
export
const
getScale
=
(
val
:
Entity
|
ScillaComponent
)
=>
{
if
(
val
instanceof
Entity
)
{
return
val
.
getComponent
(
Transform
).
scale
;
}
else
if
(
val
instanceof
ScillaComponent
)
{
return
val
.
getComponent
(
Transform
).
scale
;
}
}
export
const
setY
=
(
entity
:
Entity
,
y
)
=>
{
entity
.
getComponent
(
Transform
).
position
.
y
=
y
;
}
export
const
getX
=
(
val
:
Entity
|
ScillaComponent
)
=>
{
let
entity
:
Entity
;
if
(
val
instanceof
Entity
)
entity
=
val
;
else
entity
=
val
.
entity
;
return
entity
.
getComponent
(
Transform
).
position
.
x
}
export
const
getY
=
(
val
:
Entity
|
ScillaComponent
)
=>
{
let
entity
:
Entity
;
if
(
val
instanceof
Entity
)
entity
=
val
;
else
entity
=
val
.
entity
;
return
entity
.
getComponent
(
Transform
).
position
.
y
}
export
const
setXY
=
(
val
:
Entity
|
ScillaComponent
,
x
,
y
)
=>
{
let
entity
:
Entity
;
if
(
val
instanceof
Entity
)
entity
=
val
;
else
entity
=
val
.
entity
;
setX
(
entity
,
x
);
setY
(
entity
,
y
);
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment