-
Notifications
You must be signed in to change notification settings - Fork 263
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
b11fa4a
commit e838815
Showing
11 changed files
with
170 additions
and
14 deletions.
There are no files selected for viewing
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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-imageinputlabel/save-texture.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,118 @@ | ||
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 label = this.rexUI.add.imageInputLabel({ | ||
orientation: 'y', | ||
x: 400, y: 300, | ||
width: 240, | ||
space: { left: 20, right: 20, top: 20, bottom: 20, icon: 20, text: 20 }, | ||
|
||
iconWidth: 200, iconHeight: 200, | ||
|
||
background: this.rexUI.add.roundRectangle({ | ||
radius: 20, | ||
strokeColor: COLOR_DARK, | ||
strokeWidth: 3 | ||
}), | ||
|
||
// Editable text input | ||
text: CreateCanvasInput(this), | ||
expandTextWidth: true, | ||
|
||
// 'Save' button | ||
action: this.add.text(0, 0, 'Save'), | ||
|
||
canvas: { | ||
fill: 'grey' | ||
}, | ||
|
||
clickTarget: 'icon', | ||
|
||
domButton: true, // true | ||
}) | ||
.layout() | ||
|
||
var gameObject; | ||
|
||
label | ||
.on('select', function (file, label) { | ||
console.log(file); | ||
label.setText(label.getFileName(file)); | ||
}) | ||
.onClick(label.getElement('action'), function () { | ||
var key = label.text; | ||
label.saveTexture(key); | ||
console.log(`Save texture ${key}`) | ||
|
||
// Display new texture | ||
if (!gameObject) { | ||
gameObject = this.add.image(0, 0, '').setOrigin(0); | ||
} | ||
gameObject.setTexture(key); | ||
}, this) | ||
|
||
|
||
} | ||
|
||
update() { } | ||
} | ||
|
||
var CreateCanvasInput = function (scene) { | ||
return scene.rexUI.add.canvasInput({ | ||
background: { | ||
'focus.stroke': 'red', | ||
}, | ||
|
||
style: { | ||
fontSize: 20, | ||
backgroundBottomY: 5, | ||
backgroundHeight: 24, | ||
|
||
'cursor.color': 'black', | ||
'cursor.backgroundColor': 'white', | ||
}, | ||
|
||
text: 'Click icon', | ||
|
||
selectAll: true | ||
}) | ||
} | ||
|
||
var config = { | ||
type: Phaser.AUTO, | ||
parent: 'phaser-example', | ||
width: 800, | ||
height: 600, | ||
scale: { | ||
mode: Phaser.Scale.FIT, | ||
autoCenter: Phaser.Scale.CENTER_BOTH, | ||
}, | ||
dom: { | ||
createContainer: true | ||
}, | ||
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
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,10 @@ | ||
var GetFileName = function (file) { | ||
if (!file) { | ||
return null; | ||
} | ||
|
||
var name = file.name; | ||
return name.substr(0, name.lastIndexOf('.')); | ||
} | ||
|
||
export default GetFileName; |
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
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