Skip to content

Commit

Permalink
new objects, CustomNumericStepperUI and CustomCheckBoxUI
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMadera committed Aug 30, 2024
1 parent d313fb0 commit 08d338d
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 0 deletions.
Binary file added assets/images/check_mark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions include.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<project xmlns="http://lime.software/project/1.0.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://lime.software/project/1.0.2 http://lime.software/xsd/project-1.0.2.xsd">
<assets path="assets/images" embed="true"/>
</project>
64 changes: 64 additions & 0 deletions me/customs/ui/CustomCheckBoxUI.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package me.customs.ui;

import flixel.FlxG;
import flixel.FlxSprite;
import flixel.text.FlxText;
import flixel.util.FlxColor;
import flixel.group.FlxSpriteGroup;
import flixel.FlxObject;

class CustomCheckBoxUI extends FlxSpriteGroup
{
var checkBox:FlxSprite;
public var checkSign:FlxSprite;
var text:FlxText;

public var checked:Bool;
public var callback:Void -> Null<Void>;

public function new(x:Float, y:Float, width:Int = 20, height:Int = 20, label:String, size:Int)
{
super(x, y);

checkBox = new FlxSprite().makeGraphic(width, height, 0xFFFFFFFF);
add(checkBox);

checkSign = new FlxSprite().loadGraphic('assets/images/check_mark.png');
checkSign.setGraphicSize(width, height);
add(checkSign);

text = new FlxText(25, 2, 0, label, size);
text.setFormat("VCR OSD Mono", size, FlxColor.WHITE, LEFT);
add(text);

//centerOnSprite(text, checkBox, false, true);
}

public override function update(elapsed:Float)
{
super.update(elapsed);

if(FlxG.mouse.overlaps(this))
{
if(FlxG.mouse.justPressed)
{
clickCheck();
}
}
}

public function clickCheck()
{
checked = !checked;
trace('CHECKED: ' + checked);

checkSign.visible = checked;
if(callback != null) callback();
}

public function updateCheck()
{
checkSign.visible = checked;
if(callback != null) callback();
}
}
73 changes: 73 additions & 0 deletions me/customs/ui/CustomNumericStepperUI.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package me.customs.ui;

import flixel.FlxG;
import flixel.FlxSprite;
import flixel.text.FlxText;
import flixel.util.FlxColor;
import flixel.group.FlxSpriteGroup;
import flixel.math.FlxMath;
import me.customs.ui.CustomButton;

class CustomNumericStepperUI extends FlxSpriteGroup
{
var bg:FlxSprite;
var text:FlxText;
public var button_plus:CustomButton;
public var button_minus:CustomButton;

public var maxValue:Float = 400;
public var minValue:Float = 1;
public var value:Float;
public var callback:Void -> Null<Void>;

public var stepSize:Float;

public function new(x:Float, y:Float, _stepSize:Float, initialValue:Float)
{
super(x, y);

value = initialValue;

stepSize = _stepSize;

bg = new FlxSprite().makeGraphic(40, 20, 0xFFFFFFFF);
add(bg);

text = new FlxText(0, 2, 0, "" + value, 16);
text.setFormat("VCR OSD Mono", 16, FlxColor.BLACK, CENTER);
add(text);

button_plus = new CustomButton(50, 0, 20, 20, 0xFF000000, '+', 16, 0xFFFFFFFF, onPressButtonPlus);
add(button_plus);

button_minus = new CustomButton(80, 0, 20, 20, 0xFF000000, '-', 16, 0xFFFFFFFF, onPressButtonMinus);
add(button_minus);
}

function onPressButtonPlus():Void
{
if(value < maxValue)
{
value += stepSize;
FlxMath.roundDecimal(value, 1);
if(callback != null) callback();
updateText();
}
}

function onPressButtonMinus():Void
{
if(value > minValue)
{
value -= stepSize;
FlxMath.roundDecimal(value, 1);
if(callback != null) callback();
updateText();
}
}

public function updateText()
{
text.text = "" + value;
}
}

0 comments on commit 08d338d

Please sign in to comment.