Skip to content

Instantly share code, notes, and snippets.

@greysondn
Created January 22, 2019 21:30
Show Gist options
  • Save greysondn/10e823affd3472b00186f618bb6ac8cc to your computer and use it in GitHub Desktop.
Save greysondn/10e823affd3472b00186f618bb6ac8cc to your computer and use it in GitHub Desktop.
Widget Widget
package net.darkglass.consume.substate;
import flixel.addons.ui.FlxUISubState;
import flash.geom.Rectangle;
import flixel.addons.ui.FlxUI;
import flixel.addons.ui.FlxUI9SliceSprite;
import flixel.addons.ui.FlxUIButton;
import flixel.addons.ui.FlxUIRadioGroup;
import flixel.addons.ui.FlxUITabMenu;
import flixel.addons.ui.FlxUIText;
import flixel.text.FlxText.FlxTextFormat;
import com.example.Registry;
class OptionSubstate extends FlxUISubState
{
private var registry:Registry = Registry.create();
override public function create():Void
{
// comment was NSFW, scrubbed
super.create();
// why don't we organize these options? ... But
// first! ... We'll need to build a window proper
// for them. So that's my first task, I suppose.
var buttonNormalImg:String = "assets/images/gui/classic/nineslice/window.png";
var buttonHoverImg:String = "assets/images/gui/classic/nineslice/window-hover.png";
var buttonClickImg:String = "assets/images/gui/classic/nineslice/window-click.png";
var buttonDisabledImg:String = "assets/images/gui/classic/nineslice/window-disabled.png";
var buttonEnabledGFX:Array<String> = [buttonNormalImg, buttonHoverImg, buttonClickImg];
var buttonDisabledGFX:Array<String> = [buttonDisabledImg, buttonDisabledImg, buttonDisabledImg];
var slicecoords:Array<Array<Int>> = [[1, 1, 2, 2], [1, 1, 2, 2], [1, 1, 2, 2]];
var background:FlxUI9SliceSprite = new FlxUI9SliceSprite(23, 23, buttonNormalImg, new Rectangle(0, 0, 804, 594), [1, 1, 2, 2]);
this.add(background);
// clickable button that doesn't suck too hard to close it?
var backButton:FlxUIButton = new FlxUIButton(32, 566, "Back", onClick_back);
backButton.loadGraphicSlice9(buttonEnabledGFX, 786, 42, slicecoords, false, -1);
this.add(backButton);
// title
// loc 32x32
// size 786x87
var fntcol:FlxTextFormat = new FlxTextFormat(0xFF000000);
var titleTxt:FlxUIText = new FlxUIText(32, 32, 786, "Options", 87);
titleTxt.alignment = "center";
titleTxt.addFormat(fntcol);
this.add(titleTxt);
// basic tab menu (holy crap!)
var tabs:Array<{name:String, label:String}> = [
{ name:"tab_1", label:"Game"},
{ name:"tab_2", label:"Contents"},
{ name:"tab_3", label:"Display"},
{ name:"tab_4", label:"Debug"}
];
var tabMenu = new FlxUITabMenu(null, tabs, true);
tabMenu.x = 32;
tabMenu.y = 127;
tabMenu.resize(786, 431);
// about tab contents
// pos 40x154
// siz 770x396
// game tab contents
// -----------------
var tabGroupGame:FlxUI = new FlxUI(null, tabMenu, null);
tabGroupGame.name = "tab_1";
// difficulty title
var difficultyTitleTxt:FlxUIText = new FlxUIText(8, 8, 770, "Difficulty", 32);
difficultyTitleTxt.alignment = "left";
tabGroupGame.add(difficultyTitleTxt);
// difficulty options radio group
var difficultyIDs:Array<String> = ["diff_easy", "diff_normal", "diff_hard"];
var difficultyLabels:Array<String> = ["Easy", "Normal", "Hard"];
var difficultyRadio:FlxUIRadioGroup = new FlxUIRadioGroup(
8, // x pos
40, // y pos
difficultyIDs, // code ids
["gamma", "stand you", "are now unchained"], // user labels
this.onSelect_difficulty, // callback
50, // vertical space between buttons
100, // max width of a button
40, // height of a button
100 // max width of a label
);
tabGroupGame.add(difficultyRadio);
tabMenu.addGroup(tabGroupGame);
titleTxt.addFormat(fntcol);
this.add(titleTxt);
// contents tab contents
// ---------------------
var tabGroupContents:FlxUI = new FlxUI(null, tabMenu, null);
tabGroupContents.name = "tab_2";
tabMenu.addGroup(tabGroupContents);
// display tab contents
// --------------------
var tabGroupDisplay:FlxUI = new FlxUI(null, tabMenu, null);
tabGroupDisplay.name = "tab_3";
tabMenu.addGroup(tabGroupDisplay);
// debug tab contents
// ------------------
var tabGroupDebug:FlxUI = new FlxUI(null, tabMenu, null);
tabGroupDebug.name = "tab_4";
tabMenu.addGroup(tabGroupDebug);
// remember when we started the tab menu? Now we can add it to the state.
this.add(tabMenu);
}
public function onClick_back():Void
{
this.close();
}
/**
* adjusts difficulty value in game's registry
*
* @param diff_id the id of the now selected difficulty
*/
public function onSelect_difficulty(diff_id:String):Void
{
switch (diff_id)
{
case "diff_easy":
this.registry.difficulty = 0.5;
case "diff_normal":
this.registry.difficulty = 1.0;
case "diff_hard":
this.registry.difficulty = 1.5;
default:
// throw an error
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment