diff options
author | Indrajith K L | 2021-09-22 10:10:50 +0530 |
---|---|---|
committer | Indrajith K L | 2021-09-22 10:10:50 +0530 |
commit | 9abd235ed2b9a5c80d5e63d6187d69e9317c2f0d (patch) | |
tree | 5a7618d359c216a9a24ff73e2bdc3550e9d03080 /source/shared/UserNamePopup.hx | |
download | LeaderboardTest-9abd235ed2b9a5c80d5e63d6187d69e9317c2f0d.tar.gz LeaderboardTest-9abd235ed2b9a5c80d5e63d6187d69e9317c2f0d.tar.bz2 LeaderboardTest-9abd235ed2b9a5c80d5e63d6187d69e9317c2f0d.zip |
* Initial Commit
* Leaderboard Implementation for dreamlo
* FlxSave for Player Data
* GUID Generation for Unique User
Diffstat (limited to 'source/shared/UserNamePopup.hx')
-rw-r--r-- | source/shared/UserNamePopup.hx | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/source/shared/UserNamePopup.hx b/source/shared/UserNamePopup.hx new file mode 100644 index 0000000..81e7129 --- /dev/null +++ b/source/shared/UserNamePopup.hx @@ -0,0 +1,57 @@ +package shared; + +import flixel.FlxG; +import flixel.FlxObject; +import flixel.FlxSprite; +import flixel.addons.ui.FlxInputText; +import flixel.addons.ui.FlxUIGroup; +import flixel.graphics.FlxGraphic; +import flixel.group.FlxGroup.FlxTypedGroup; +import flixel.text.FlxText; +import flixel.ui.FlxButton; +import flixel.util.FlxColor; +import flixel.util.FlxSave; + +class UserNamePopup extends FlxTypedGroup<FlxSprite> +{ + var popupWidth:Int = 200; + var popupHeight:Int = 100; + var pX:Float = 0; + var pY:Float = 0; + var textFieldWidth = 150; + var textFieldHeight = 8; + var txtInput:FlxInputText; + var playerSave:FlxSave; + + public function new(OnClick:PlayerSave->Void) + { + super(); + this.playerSave = new FlxSave(); + this.playerSave.bind("PlayerSaveObj"); + this.pX = (FlxG.width / 2) - (this.popupWidth / 2); + this.pY = (FlxG.height / 2) - (popupHeight / 2); + var inputTextX = this.pX + (this.popupWidth / 2) - (this.textFieldWidth / 2); + var inputTextY = this.pY + (this.popupHeight / 2) - this.textFieldHeight; + var uiBackground:UIBackground = new UIBackground(this.pX, this.pY, this.popupWidth, this.popupHeight, FlxColor.PURPLE); + var label:FlxText = new FlxText(inputTextX, inputTextY - 20, 100, "Enter Your Name"); + var enterGameBut = new FlxButton(inputTextX + textFieldWidth / 2 - 4, inputTextY + 20, "Enter Game", onEnterGame.bind(this, OnClick)); + this.txtInput = new FlxInputText(inputTextX, inputTextY, this.textFieldWidth, "", this.textFieldHeight); + txtInput.backgroundColor = FlxColor.PURPLE; + txtInput.color = FlxColor.WHITE; + add(uiBackground); + add(label); + add(txtInput); + add(enterGameBut); + } + + function onEnterGame(event, OnClick) + { + FlxG.camera.shake(0.05); + var guid = Utils.Guid(); + PlayerSave.instance.setPlayerData(this.txtInput.text, guid); + this.playerSave.data.playerSaveObj = PlayerSave.instance; + this.playerSave.flush(); + OnClick(PlayerSave.instance); + trace(OnClick); + } +} |