Skip to content

Commit 2af1ddd

Browse files
committed
cookie
1 parent e6166c4 commit 2af1ddd

8 files changed

Lines changed: 340 additions & 56 deletions

File tree

assets/ui/options/checkbox.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"path": "ui/options/checkbox",
3+
"antialiasing": true,
4+
"animation":
5+
{
6+
"type": "sparrow",
7+
"anims":
8+
[
9+
{
10+
"name": "checked",
11+
"prefix": "Press"
12+
},
13+
{
14+
"name": "unchecked",
15+
"prefix": "Unselect"
16+
}
17+
]
18+
}
19+
}

assets/ui/options/checkbox.png

179 KB
Loading

assets/ui/options/checkbox.xml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<TextureAtlas imagePath="checkbox.png">
3+
<SubTexture name="Press0000" x="0" y="0" width="311" height="311" frameX="-46" frameY="-34" frameWidth="427" frameHeight="345"/>
4+
<SubTexture name="Press0001" x="311" y="0" width="311" height="311" frameX="-46" frameY="-34" frameWidth="427" frameHeight="345"/>
5+
<SubTexture name="Press0002" x="622" y="0" width="311" height="311" frameX="-46" frameY="-34" frameWidth="427" frameHeight="345"/>
6+
<SubTexture name="Press0003" x="933" y="0" width="311" height="311" frameX="-46" frameY="-34" frameWidth="427" frameHeight="345"/>
7+
<SubTexture name="Press0004" x="1244" y="0" width="318" height="311" frameX="-46" frameY="-34" frameWidth="427" frameHeight="345"/>
8+
<SubTexture name="Press0005" x="1562" y="0" width="367" height="322" frameX="-30" frameY="-23" frameWidth="427" frameHeight="345"/>
9+
<SubTexture name="Press0006" x="0" y="322" width="405" height="337" frameX="-11" frameY="-8" frameWidth="427" frameHeight="345"/>
10+
<SubTexture name="Press0007" x="405" y="322" width="423" height="344" frameX="-2" frameY="-1" frameWidth="427" frameHeight="345"/>
11+
<SubTexture name="Press0008" x="828" y="322" width="425" height="344" frameX="-1" frameY="-1" frameWidth="427" frameHeight="345"/>
12+
<SubTexture name="Press0009" x="1253" y="322" width="427" height="345"/>
13+
<SubTexture name="Press0010" x="0" y="667" width="426" height="345" frameX="-1" frameY="0" frameWidth="427" frameHeight="345"/>
14+
<SubTexture name="Press0011" x="426" y="667" width="425" height="344" frameX="-1" frameY="-1" frameWidth="427" frameHeight="345"/>
15+
<SubTexture name="Press0012" x="851" y="667" width="425" height="344" frameX="-1" frameY="-1" frameWidth="427" frameHeight="345"/>
16+
<SubTexture name="Press0013" x="851" y="667" width="425" height="344" frameX="-1" frameY="-1" frameWidth="427" frameHeight="345"/>
17+
<SubTexture name="Unselect0000" x="1276" y="667" width="413" height="338" frameX="0" frameY="0" frameWidth="414" frameHeight="338"/>
18+
<SubTexture name="Unselect0001" x="0" y="1012" width="407" height="312" frameX="-7" frameY="-26" frameWidth="414" frameHeight="338"/>
19+
<SubTexture name="Unselect0002" x="407" y="1012" width="392" height="311" frameX="-18" frameY="-27" frameWidth="414" frameHeight="338"/>
20+
<SubTexture name="Unselect0003" x="799" y="1012" width="364" height="311" frameX="-35" frameY="-27" frameWidth="414" frameHeight="338"/>
21+
<SubTexture name="Unselect0004" x="1163" y="1012" width="345" height="311" frameX="-38" frameY="-27" frameWidth="414" frameHeight="338"/>
22+
<SubTexture name="Unselect0005" x="1508" y="1012" width="328" height="311" frameX="-38" frameY="-27" frameWidth="414" frameHeight="338"/>
23+
<SubTexture name="Unselect0006" x="0" y="1324" width="315" height="311" frameX="-38" frameY="-27" frameWidth="414" frameHeight="338"/>
24+
<SubTexture name="Unselect0007" x="315" y="1324" width="312" height="311" frameX="-38" frameY="-27" frameWidth="414" frameHeight="338"/>
25+
<SubTexture name="Unselect0008" x="627" y="1324" width="312" height="311" frameX="-38" frameY="-27" frameWidth="414" frameHeight="338"/>
26+
<SubTexture name="Unselect0009" x="939" y="1324" width="312" height="311" frameX="-38" frameY="-27" frameWidth="414" frameHeight="338"/>
27+
<SubTexture name="Unselect0010" x="1251" y="1324" width="312" height="311" frameX="-38" frameY="-27" frameWidth="414" frameHeight="338"/>
28+
<SubTexture name="Unselect0011" x="1563" y="1324" width="312" height="311" frameX="-38" frameY="-27" frameWidth="414" frameHeight="338"/>
29+
<SubTexture name="Unselect0012" x="0" y="1635" width="312" height="311" frameX="-38" frameY="-27" frameWidth="414" frameHeight="338"/>
30+
<SubTexture name="Unselect0013" x="312" y="1635" width="312" height="311" frameX="-38" frameY="-27" frameWidth="414" frameHeight="338"/>
31+
</TextureAtlas>

src/funkin/objects/FunkinSprite.hx

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,19 @@ class FunkinSprite extends FlxSprite
5050
/**
5151
* Loads frames and applies it to this sprite.
5252
* @param path The path of where frames should load from.
53+
* @param forcedType Which type to force. If null, it will be determined automatically.
5354
* @return This `FunkinSprite` instance (nice for chaining stuff together, if you're into that).
5455
*/
55-
public function loadFrames(path:String):FunkinSprite
56+
public function loadFrames(path:String, ?forcedType:Null<String>):FunkinSprite
5657
{
5758
if (atlas != null)
5859
{
5960
atlas.destroy();
6061
atlas = null;
6162
}
6263

64+
// TODO: make forcedType work, im too lazy
65+
6366
if (Paths.location.exists(path + '.xml'))
6467
{
6568
frames = Paths.content.sparrowAtlas(path);
@@ -322,6 +325,51 @@ class FunkinSprite extends FlxSprite
322325

323326
return _onAnimFinished;
324327
}
328+
329+
@:noCompletion
330+
override function set_width(value:Float):Float
331+
{
332+
if (atlas != null)
333+
{
334+
atlas.width = value;
335+
return atlas.width;
336+
}
337+
338+
return super.set_width(value);
339+
}
340+
341+
@:noCompletion
342+
override function get_width():Float
343+
{
344+
if (atlas != null)
345+
{
346+
return atlas.width;
347+
}
348+
349+
return super.get_width();
350+
}
351+
352+
@:noCompletion
353+
override function set_height(value:Float):Float
354+
{
355+
if (atlas != null)
356+
{
357+
atlas.height = value;
358+
return atlas.height;
359+
}
360+
361+
return super.set_height(value);
362+
}
363+
364+
override function get_height():Float
365+
{
366+
if (atlas != null)
367+
{
368+
return atlas.height;
369+
}
370+
371+
return super.get_height();
372+
}
325373
}
326374

327375
typedef FunkinSpriteGroup = FlxTypedSpriteGroup<FunkinSprite>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package funkin.objects.ui;
2+
3+
import funkin.structures.ObjectStructure;
4+
import haxe.Json;
5+
6+
class OptionCheckbox extends FunkinSprite
7+
{
8+
/**
9+
* Where is the checkbox config json located?
10+
* Can be overriden by scripts.
11+
*/
12+
public static var CHECKBOX_PATH:String = 'ui/options/checkbox';
13+
14+
/**
15+
* The current checkbox value.
16+
* If changed, an animation for said change will occur.
17+
*/
18+
public var checkboxValue(default, set):Bool = false;
19+
20+
/**
21+
* Gets called when the checkbox value changes.
22+
* Should be used for saving the value into data.
23+
*/
24+
public var valueChanged:Null<Void->Void> = null;
25+
26+
public function new(checkboxValue:Bool)
27+
{
28+
super();
29+
30+
var structureContent:String = Paths.content.json(CHECKBOX_PATH);
31+
var structure:ObjectStructure = Json.parse(structureContent);
32+
FunkinSpriteUtil.createFromStructure(this, structure);
33+
34+
this.checkboxValue = checkboxValue;
35+
finishAnimation();
36+
}
37+
38+
function set_checkboxValue(value:Bool):Bool
39+
{
40+
checkboxValue = value;
41+
42+
playAnimation((checkboxValue ? 'checked' : 'unchecked'), true);
43+
44+
if (valueChanged != null)
45+
{
46+
valueChanged();
47+
}
48+
49+
return value;
50+
}
51+
}

0 commit comments

Comments
 (0)