-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8953ab6
commit 117eb0c
Showing
4 changed files
with
228 additions
and
0 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
examples/ui-scrollablepanel/button-click-childinteractive.bat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@echo off | ||
set main=./examples/ui-scrollablepanel/button-click-childinteractive.js | ||
cd .. | ||
cd .. | ||
npm run watch |
111 changes: 111 additions & 0 deletions
111
examples/ui-scrollablepanel/button-click-childinteractive.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import phaser from 'phaser/src/phaser.js'; | ||
import UIPlugin from '../../templates/ui/ui-plugin.js'; | ||
|
||
const COLOR_PRIMARY = 0x4e342e; | ||
const COLOR_LIGHT = 0x7b5e57; | ||
const COLOR_DARK = 0x260e04; | ||
|
||
class Demo extends Phaser.Scene { | ||
constructor() { | ||
super({ | ||
key: 'examples' | ||
}) | ||
} | ||
|
||
preload() { | ||
} | ||
|
||
create() { | ||
var panel = this.rexUI.add.scrollablePanel({ | ||
x: 400, y: 300, | ||
width: 200, height: 300, | ||
|
||
scrollMode: 'y', | ||
|
||
panel: { | ||
child: CreatePanel(this), | ||
}, | ||
|
||
slider: { | ||
track: this.rexUI.add.roundRectangle({ | ||
width: 20, radius: 10, | ||
color: COLOR_DARK | ||
}), | ||
thumb: this.rexUI.add.roundRectangle({ | ||
radius: 13, | ||
color: COLOR_LIGHT, | ||
}), | ||
}, | ||
|
||
space: { | ||
slider: 10, | ||
} | ||
}) | ||
.layout() | ||
|
||
panel.setChildrenInteractive({ | ||
targets: [ | ||
panel.getElement('panel') | ||
] | ||
}) | ||
.on('child.click', function (child) { | ||
// child : Label from CreateButton() | ||
console.log(`Click ${child.text}`); | ||
}) | ||
} | ||
|
||
update() { } | ||
} | ||
|
||
var CreatePanel = function (scene) { | ||
var panel = scene.rexUI.add.sizer({ | ||
orientation: 'y', | ||
space: { item: 5 } | ||
}) | ||
|
||
for (var i = 0; i < 30; i++) { | ||
panel | ||
.add( | ||
CreateButton(scene, i.toString()), | ||
{ expand: true } | ||
) | ||
} | ||
|
||
return panel; | ||
} | ||
|
||
var CreateButton = function (scene, text) { | ||
return scene.rexUI.add.label({ | ||
height: 30, | ||
|
||
background: scene.rexUI.add.roundRectangle({ | ||
radius: 10, | ||
color: COLOR_PRIMARY | ||
}), | ||
text: scene.add.text(0, 0, text), | ||
|
||
align: 'center' | ||
}) | ||
|
||
} | ||
|
||
var config = { | ||
type: Phaser.AUTO, | ||
parent: 'phaser-example', | ||
width: 800, | ||
height: 600, | ||
scale: { | ||
mode: Phaser.Scale.FIT, | ||
autoCenter: Phaser.Scale.CENTER_BOTH, | ||
}, | ||
scene: Demo, | ||
plugins: { | ||
scene: [{ | ||
key: 'rexUI', | ||
plugin: UIPlugin, | ||
mapping: 'rexUI' | ||
}] | ||
} | ||
}; | ||
|
||
var game = new Phaser.Game(config); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@echo off | ||
set main=./examples/ui-scrollablepanel/button-click.js | ||
cd .. | ||
cd .. | ||
npm run watch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import phaser from 'phaser/src/phaser.js'; | ||
import UIPlugin from '../../templates/ui/ui-plugin.js'; | ||
|
||
const COLOR_PRIMARY = 0x4e342e; | ||
const COLOR_LIGHT = 0x7b5e57; | ||
const COLOR_DARK = 0x260e04; | ||
|
||
class Demo extends Phaser.Scene { | ||
constructor() { | ||
super({ | ||
key: 'examples' | ||
}) | ||
} | ||
|
||
preload() { | ||
} | ||
|
||
create() { | ||
var panel = this.rexUI.add.scrollablePanel({ | ||
x: 400, y: 300, | ||
width: 200, height: 300, | ||
|
||
scrollMode: 'y', | ||
|
||
panel: { | ||
child: CreatePanel(this), | ||
}, | ||
|
||
slider: { | ||
track: this.rexUI.add.roundRectangle({ | ||
width: 20, radius: 10, | ||
color: COLOR_DARK | ||
}), | ||
thumb: this.rexUI.add.roundRectangle({ | ||
radius: 13, | ||
color: COLOR_LIGHT, | ||
}), | ||
}, | ||
|
||
scroller: false, | ||
|
||
space: { | ||
slider: 10, | ||
} | ||
}) | ||
.layout() | ||
|
||
} | ||
|
||
update() { } | ||
} | ||
|
||
var CreatePanel = function (scene) { | ||
var panel = scene.rexUI.add.sizer({ | ||
orientation: 'y', | ||
space: { item: 5 } | ||
}) | ||
|
||
for (var i = 0; i < 30; i++) { | ||
panel | ||
.add( | ||
CreateButton(scene, i.toString()), | ||
{ expand: true } | ||
) | ||
} | ||
|
||
return panel; | ||
} | ||
|
||
var CreateButton = function (scene, text) { | ||
return scene.rexUI.add.label({ | ||
height: 30, | ||
|
||
background: scene.rexUI.add.roundRectangle({ | ||
radius: 10, | ||
color: COLOR_PRIMARY | ||
}), | ||
text: scene.add.text(0, 0, text), | ||
|
||
align: 'center' | ||
}) | ||
.onClick(function () { | ||
console.log(`Click ${text}`); | ||
}) | ||
|
||
} | ||
|
||
var config = { | ||
type: Phaser.AUTO, | ||
parent: 'phaser-example', | ||
width: 800, | ||
height: 600, | ||
scale: { | ||
mode: Phaser.Scale.FIT, | ||
autoCenter: Phaser.Scale.CENTER_BOTH, | ||
}, | ||
scene: Demo, | ||
plugins: { | ||
scene: [{ | ||
key: 'rexUI', | ||
plugin: UIPlugin, | ||
mapping: 'rexUI' | ||
}] | ||
} | ||
}; | ||
|
||
var game = new Phaser.Game(config); |