Last active
December 7, 2016 11:23
-
-
Save Eiyeron/36000ef40fc9d343d0cd2da507b6a3eb to your computer and use it in GitHub Desktop.
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
class LanguageSelectionState extends FlxFSMState<BattleEngine> { | |
var localeButtons:Array<FlxButton>; | |
var localeFlags:Array<FlxSprite>; | |
var locales:Array<String>; | |
var background:FlxSprite; | |
var okButton:FlxButton; | |
public function new() | |
{ | |
super(); | |
background = new FlxSprite(0, 0); | |
var color = FlxColor.BLACK; | |
background.makeGraphic(640, 480, color); | |
background.alpha = 0.5; | |
localeButtons = []; | |
localeFlags = []; | |
// Global was already initiated with en-US. | |
locales = Global.tongue.locales; | |
var i = 0; | |
var length:Float = Global.tongue.locales.length; | |
var sizeUsed:Float = 50*(length+1); | |
var offset:Float= (FlxG.height - sizeUsed)/2; | |
for (locale in locales) { | |
var locale_text = Global.tongue.getIndexString(IndexString.Language, locale); | |
var button = new FlxButton(0, 50 * i+offset, locale_text); | |
button.scale.set(2,2); | |
button.updateHitbox(); | |
button.label.scale.set(2,2); | |
button.label.updateHitbox(); | |
button.x = (FlxG.width - button.width)/2.; | |
for(offset in button.labelOffsets) | |
offset.y += 4; | |
var flag = new FlxSprite(0,0); | |
flag.loadGraphic(Global.tongue.getIcon(locale)); | |
flag.scale.set(2,2); | |
flag.updateHitbox(); | |
flag.setPosition(button.x - flag.width - 2, button.y+8); | |
localeButtons.push(button); | |
localeFlags.push(flag); | |
i++; | |
} | |
okButton = new FlxButton(0, offset + sizeUsed + offset/2, "OK"); | |
okButton.scale.set(2,2); | |
okButton.updateHitbox(); | |
okButton.x = (FlxG.width - okButton.width)/2.; | |
okButton.label.scale.set(2,2); | |
okButton.label.updateHitbox(); | |
for(offset in okButton.labelOffsets) | |
offset.y += 4; | |
} | |
override public function enter(owner:BattleEngine, fsm:FlxFSM<BattleEngine>):Void | |
{ | |
owner.language_selected = false; | |
owner.add(background); | |
for(button in localeButtons) { | |
button.onDown.callback = function() { | |
var index = localeButtons.indexOf(button); | |
Global.language = locales[index]; | |
Global.tongue.init(locales[index]); | |
for(button in localeButtons) { | |
var locale_text = Global.tongue.getIndexString(IndexString.Language, Global.tongue.locales[localeButtons.indexOf(button)]); | |
button.text = locale_text; | |
} | |
} | |
owner.add(button); | |
} | |
okButton.onUp.callback = function() { | |
owner.language_selected = true; | |
} | |
for(flag in localeFlags) { | |
owner.add(flag); | |
} | |
owner.add(okButton); | |
} | |
override public function exit(owner:BattleEngine):Void{ | |
owner.textbox.dismiss(); | |
owner.remove(background); | |
for(button in localeButtons) | |
owner.remove(button); | |
for(flag in localeFlags) | |
owner.remove(flag); | |
owner.remove(okButton); | |
var tutorial_save = new FlxSave(); | |
if(tutorial_save.bind("tutorial")) { | |
tutorial_save.data.language = Global.language; | |
trace("Language saved"); | |
tutorial_save.close(); | |
} | |
else { | |
FlxG.log.error("couldn't open save"); | |
} | |
} | |
} |
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
<?xml version="1.0" encoding="utf-8" ?> | |
<data> | |
<file id="battle" value="battle.tsv"/> | |
<file id="special_attacks" value="special_attacks.tsv"/> | |
<file id="items" value="items.tsv"/> | |
<file id="enemies" value="enemies.tsv"/> | |
<!--American English--> | |
<locale id="en-US" is_default="true" sort="0"> | |
<contributors value="Eiyeron"/> | |
<ui language="Language" region="Region" accept="OK" /> | |
<label id="en-US" language="English" region="U.S."/> | |
<label id="fr-FR" language="Anglais" region="U.S.A."/> | |
</locale> | |
<!--French French--> | |
<locale id="fr-FR"> | |
<contributors value="Eiyeron"/> | |
<ui language="Langage" region="Région" accept="OK" /> | |
<label id="en-US" language="French" region="France"/> | |
<label id="fr-FR" language="Français" region="France"/> | |
</locale> | |
</data> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would be there a way to get a specific Language tag from a given other language, something like
Because I can't make tjhe menu change the button labels without having to reload FireTongue, unless it's the intended behaviour.
(SOrry, I'm not so clever)
Edit: I'm trying to edit the labels directly on a call back, I'd like to reproduce that logic without having to call init.