Merge branch 'character-editor-v3' into new-editors

This commit is contained in:
NeeEoo
2024-04-27 20:30:57 +02:00
34 changed files with 1244 additions and 564 deletions
@@ -1,5 +1,5 @@
<!DOCTYPE codename-engine-character>
<character x="-50" y="330" isGF="false" flipX="true" isPlayer="true" antialiasing="true" sprite="bf-holding-gf-dead" color="#31B0D1">
<character x="-50" y="330" flipX="true" isPlayer="true" antialiasing="true" sprite="bf-holding-gf-dead" color="#31B0D1">
<anim x="0" loop="false" y="0" fps="24" anim="BF Dies with GF" name="firstDeath"/>
<anim x="0" loop="false" y="-17" fps="24" anim="BF Dead with GF Loop" name="deathLoop"/>
<anim x="0" loop="false" y="14" fps="24" anim="RETRY confirm holding gf" name="deathConfirm"/>
+1 -1
View File
@@ -1,5 +1,5 @@
<!DOCTYPE codename-engine-character>
<character icon="bf-pixel-dead" x="200" y="570" isGF="false" scale="6" flipX="true" isPlayer="true" antialiasing="false" sprite="bf-pixel-dead" color="#7BD6F6">
<character icon="bf-pixel-dead" x="200" y="570" scale="6" flipX="true" isPlayer="true" antialiasing="false" sprite="bf-pixel-dead" color="#7BD6F6">
<anim x="0" loop="false" y="0" fps="24" anim="BF Dies pixel" name="firstDeath"/>
<anim x="-5" loop="true" y="-2" fps="24" anim="Retry Loop" name="deathLoop"/>
<anim x="-5" loop="false" y="-2" fps="24" anim="RETRY CONFIRM" name="deathConfirm"/>
+1 -1
View File
@@ -1,5 +1,5 @@
<!DOCTYPE codename-engine-character>
<character isPlayer="false" flipX="false" isGF="true" x="75" y="335" icon="gf" color="#A5004D">
<character isPlayer="false" flipX="false" x="75" y="335" icon="gf" color="#A5004D">
<anim name="danceLeft" anim="GF Dancing Beat Hair blowing CAR" fps="24" loop="false" x="0" y="0" indices="30,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14" />
<anim name="danceRight" anim="GF Dancing Beat Hair blowing CAR" fps="24" loop="false" x="0" y="0" indices="15,16,17,18,19,20,21,22,23,24,25,26,27,28,29" />
</character>
+1 -1
View File
@@ -1,5 +1,5 @@
<!DOCTYPE codename-engine-character>
<character x="115" icon="gf" y="325" isGF="true" flipX="false" isPlayer="false" antialiasing="true" color="#A5004D">
<character x="115" icon="gf" y="325" flipX="false" isPlayer="false" antialiasing="true" color="#A5004D">
<anim x="0" loop="true" y="-9" fps="24" anim="GF FEAR" name="scared"/>
<anim x="0" loop="false" y="-9" fps="24" anim="GF Down Note" name="singDOWN"/>
<anim x="0" loop="false" y="-9" fps="24" anim="GF Dancing Beat" indices="15,16,17,18,19,20,21,22,23,24,25,26,27,28,29" name="danceRight"/>
+1 -1
View File
@@ -1,5 +1,5 @@
<!DOCTYPE codename-engine-character>
<character icon="gf" isGF="true" flipX="false" isPlayer="false" antialiasing="true" color="#A5004D">
<character icon="gf" flipX="false" isPlayer="false" antialiasing="true" color="#A5004D">
<anim x="0" loop="false" y="0" fps="24" anim="GF Dancing at Gunpoint" indices="30,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14" name="danceLeft"/>
<anim x="0" loop="true" y="0" fps="24" anim="GF Dancing at Gunpoint" name="dance-cutscene"/>
<anim x="-315" loop="true" y="6" fps="24" anim="GF Crying at Gunpoint" indices="0,1,2,3,4,5,6,7,8,9,10,11,12" name="sad"/>
+1 -1
View File
@@ -1,5 +1,5 @@
<!DOCTYPE codename-engine-character>
<character isPlayer="false" flipX="false" isGF="true" x="100" y="275" color="#A5004D">
<character isPlayer="false" flipX="false" x="100" y="275" color="#A5004D">
<anim name="cheer" anim="GF Cheer" fps="24" loop="false" />
<anim name="singUP" anim="GF Up Note" fps="24" loop="false" x="0" y="0" />
<anim name="singLEFT" anim="GF left note" fps="24" loop="false" x="0" y="0" />
+1 -1
View File
@@ -1,5 +1,5 @@
<!DOCTYPE codename-engine-character>
<character x="150" icon="senpai" camx="100" y="360" isGF="false" scale="6" camy="87" isPlayer="false" antialiasing="false" sprite="senpai" color="#FFAA6F">
<character x="150" icon="senpai" camx="100" y="360" scale="6" camy="87" isPlayer="false" antialiasing="false" sprite="senpai" color="#FFAA6F">
<anim x="0" loop="false" y="0" fps="24" anim="Angry Senpai Idle" name="idle"/>
<anim x="4" loop="false" y="1" fps="24" anim="Angry Senpai LEFT NOTE" name="singLEFT"/>
<anim x="2" loop="false" y="0" fps="24" anim="Angry Senpai DOWN NOTE" name="singDOWN"/>
+1 -1
View File
@@ -1,5 +1,5 @@
<!DOCTYPE codename-engine-character>
<character x="0" icon="tankman" y="180" isGF="false" flipX="true" isPlayer="true" sprite="tankman" color="#FFFFFF">
<character x="0" icon="tankman" y="180" flipX="true" isPlayer="true" sprite="tankman" color="#FFFFFF">
<anim x="0" loop="false" y="0" fps="24" anim="Tankman Idle Dance instance 100" name="idle"/>
<anim x="-1" loop="false" y="-7" fps="24" anim="Tankman Right Note instance 1000" name="singRIGHT"/>
<anim x="98" loop="false" y="-90" fps="24" anim="Tankman DOWN note instance 1000" name="singDOWN"/>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 287 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 248 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<TextureAtlas imagePath="button.png">
<!-- Created without animate lol i wrote this-->
<!-- Thanks yosh, and i wrote this script incase anyone ever needs to resize these xmls -->
<!-- Here you guys go :D https://try.haxe.org/#7C373001 -lunar -->
<SubTexture name="normal-topleft" x="0" y="0" width="4" height="4"/>
<SubTexture name="normal-top" x="4" y="0" width="8" height="4"/>
<SubTexture name="normal-topright" x="12" y="0" width="4" height="4"/>
<SubTexture name="normal-middleleft" x="0" y="4" width="4" height="8"/>
<SubTexture name="normal-middle" x="4" y="4" width="8" height="8"/>
<SubTexture name="normal-middleright" x="12" y="4" width="4" height="8"/>
<SubTexture name="normal-bottomleft" x="0" y="12" width="4" height="4"/>
<SubTexture name="normal-bottom" x="4" y="12" width="8" height="4"/>
<SubTexture name="normal-bottomright" x="12" y="12" width="4" height="4"/>
<SubTexture name="hover-topleft" x="16" y="0" width="4" height="4"/>
<SubTexture name="hover-top" x="20" y="0" width="8" height="4"/>
<SubTexture name="hover-topright" x="28" y="0" width="4" height="4"/>
<SubTexture name="hover-middleleft" x="16" y="4" width="4" height="8"/>
<SubTexture name="hover-middle" x="20" y="4" width="8" height="8"/>
<SubTexture name="hover-middleright" x="28" y="4" width="4" height="8"/>
<SubTexture name="hover-bottomleft" x="16" y="12" width="4" height="4"/>
<SubTexture name="hover-bottom" x="20" y="12" width="8" height="4"/>
<SubTexture name="hover-bottomright" x="28" y="12" width="4" height="4"/>
<SubTexture name="pressed-topleft" x="32" y="0" width="4" height="4"/>
<SubTexture name="pressed-top" x="36" y="0" width="8" height="4"/>
<SubTexture name="pressed-topright" x="44" y="0" width="4" height="4"/>
<SubTexture name="pressed-middleleft" x="32" y="4" width="4" height="8"/>
<SubTexture name="pressed-middle" x="36" y="4" width="8" height="8"/>
<SubTexture name="pressed-middleright" x="44" y="4" width="4" height="8"/>
<SubTexture name="pressed-bottomleft" x="32" y="12" width="4" height="4"/>
<SubTexture name="pressed-bottom" x="36" y="12" width="8" height="4"/>
<SubTexture name="pressed-bottomright" x="44" y="12" width="4" height="4"/>
</TextureAtlas>
+410
View File
@@ -0,0 +1,410 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
/**
Xml node types.
@see https://haxe.org/manual/std-Xml.html
**/
enum abstract XmlType(Int) {
/**
Represents an XML element type.
**/
var Element = 0;
/**
Represents XML parsed character data type.
**/
var PCData = 1;
/**
Represents XML character data type.
**/
var CData = 2;
/**
Represents an XML comment type.
**/
var Comment = 3;
/**
Represents an XML doctype element type.
**/
var DocType = 4;
/**
Represents an XML processing instruction type.
**/
var ProcessingInstruction = 5;
/**
Represents an XML document type.
**/
var Document = 6;
public function toString():String {
return switch (cast this : XmlType) {
case Element: "Element";
case PCData: "PCData";
case CData: "CData";
case Comment: "Comment";
case DocType: "DocType";
case ProcessingInstruction: "ProcessingInstruction";
case Document: "Document";
};
}
}
/**
Cross-platform Xml API.
@see https://haxe.org/manual/std-Xml.html
**/
class Xml {
/**
XML element type.
**/
static public var Element(default, never) = XmlType.Element;
/**
XML parsed character data type.
**/
static public var PCData(default, never) = XmlType.PCData;
/**
XML character data type.
**/
static public var CData(default, never) = XmlType.CData;
/**
XML comment type.
**/
static public var Comment(default, never) = XmlType.Comment;
/**
XML doctype element type.
**/
static public var DocType(default, never) = XmlType.DocType;
/**
XML processing instruction type.
**/
static public var ProcessingInstruction(default, never) = XmlType.ProcessingInstruction;
/**
XML document type.
**/
static public var Document(default, never) = XmlType.Document;
/**
Parses the String into an Xml document.
**/
static public function parse(str:String):Xml {
return haxe.xml.Parser.parse(str);
}
/**
Returns the type of the Xml Node. This should be used before
accessing other functions since some might raise an exception
if the node type is not correct.
**/
public var nodeType(default, null):XmlType;
/**
Returns the node name of an Element.
**/
@:isVar public var nodeName(get, set):String;
/**
Returns the node value. Only works if the Xml node is not an Element or a Document.
**/
@:isVar public var nodeValue(get, set):String;
/**
Returns the parent object in the Xml hierarchy.
The parent can be `null`, an Element or a Document.
**/
public var parent(default, null):Xml;
var children:Array<Xml>;
var attributeMap:Map<String, String>;
public var attributeOrder:Array<String>;
#if !cppia inline #end function get_nodeName() {
if (nodeType != Element) {
throw 'Bad node type, expected Element but found $nodeType';
}
return nodeName;
}
#if !cppia inline #end function set_nodeName(v) {
if (nodeType != Element) {
throw 'Bad node type, expected Element but found $nodeType';
}
return this.nodeName = v;
}
#if !cppia inline #end function get_nodeValue() {
if (nodeType == Document || nodeType == Element) {
throw 'Bad node type, unexpected $nodeType';
}
return nodeValue;
}
#if !cppia inline #end function set_nodeValue(v) {
if (nodeType == Document || nodeType == Element) {
throw 'Bad node type, unexpected $nodeType';
}
return this.nodeValue = v;
}
/**
Creates a node of the given type.
**/
static public function createElement(name:String):Xml {
var xml = new Xml(Element);
xml.nodeName = name;
return xml;
}
/**
Creates a node of the given type.
**/
static public function createPCData(data:String):Xml {
var xml = new Xml(PCData);
xml.nodeValue = data;
return xml;
}
/**
Creates a node of the given type.
**/
static public function createCData(data:String):Xml {
var xml = new Xml(CData);
xml.nodeValue = data;
return xml;
}
/**
Creates a node of the given type.
**/
static public function createComment(data:String):Xml {
var xml = new Xml(Comment);
xml.nodeValue = data;
return xml;
}
/**
Creates a node of the given type.
**/
static public function createDocType(data:String):Xml {
var xml = new Xml(DocType);
xml.nodeValue = data;
return xml;
}
/**
Creates a node of the given type.
**/
static public function createProcessingInstruction(data:String):Xml {
var xml = new Xml(ProcessingInstruction);
xml.nodeValue = data;
return xml;
}
/**
Creates a node of the given type.
**/
static public function createDocument():Xml {
return new Xml(Document);
}
/**
Get the given attribute of an Element node. Returns `null` if not found.
Attributes are case-sensitive.
**/
public function get(att:String):String {
if (nodeType != Element) {
throw 'Bad node type, expected Element but found $nodeType';
}
return attributeMap[att];
}
/**
Set the given attribute value for an Element node.
Attributes are case-sensitive.
**/
public function set(att:String, value:String):Void {
if (nodeType != Element) {
throw 'Bad node type, expected Element but found $nodeType';
}
attributeMap.set(att, value);
}
/**
Removes an attribute for an Element node.
Attributes are case-sensitive.
**/
public function remove(att:String):Void {
if (nodeType != Element) {
throw 'Bad node type, expected Element but found $nodeType';
}
attributeMap.remove(att);
}
/**
Tells if the Element node has a given attribute.
Attributes are case-sensitive.
**/
public function exists(att:String):Bool {
if (nodeType != Element) {
throw 'Bad node type, expected Element but found $nodeType';
}
return attributeMap.exists(att);
}
/**
Returns an `Iterator` on all the attribute names.
**/
public function attributes():Iterator<String> {
if (nodeType != Element) {
throw 'Bad node type, expected Element but found $nodeType';
}
return attributeMap.keys();
}
/**
Returns an iterator of all child nodes.
Only works if the current node is an Element or a Document.
**/
public #if !cppia inline #end function iterator():Iterator<Xml> {
ensureElementType();
return children.iterator();
}
/**
Returns an iterator of all child nodes which are Elements.
Only works if the current node is an Element or a Document.
**/
public function elements():Iterator<Xml> {
ensureElementType();
var ret = [for (child in children) if (child.nodeType == Element) child];
return ret.iterator();
}
/**
Returns an iterator of all child nodes which are Elements with the given nodeName.
Only works if the current node is an Element or a Document.
**/
public function elementsNamed(name:String):Iterator<Xml> {
ensureElementType();
var ret = [
for (child in children)
if (child.nodeType == Element && child.nodeName == name) child
];
return ret.iterator();
}
/**
Returns the first child node.
**/
public #if !cppia inline #end function firstChild():Xml {
ensureElementType();
return children[0];
}
/**
Returns the first child node which is an Element.
**/
public function firstElement():Xml {
ensureElementType();
for (child in children) {
if (child.nodeType == Element) {
return child;
}
}
return null;
}
/**
Adds a child node to the Document or Element.
A child node can only be inside one given parent node, which is indicated by the `parent` property.
If the child is already inside this Document or Element, it will be moved to the last position among the Document or Element's children.
If the child node was previously inside a different node, it will be moved to this Document or Element.
**/
public function addChild(x:Xml):Void {
ensureElementType();
if (x.parent != null) {
x.parent.removeChild(x);
}
children.push(x);
x.parent = this;
}
/**
Removes a child from the Document or Element.
Returns true if the child was successfuly removed.
**/
public function removeChild(x:Xml):Bool {
ensureElementType();
if (children.remove(x)) {
x.parent = null;
return true;
}
return false;
}
/**
Inserts a child at the given position among the other childs.
A child node can only be inside one given parent node, which is indicated by the [parent] property.
If the child is already inside this Document or Element, it will be moved to the new position among the Document or Element's children.
If the child node was previously inside a different node, it will be moved to this Document or Element.
**/
public function insertChild(x:Xml, pos:Int):Void {
ensureElementType();
if (x.parent != null) {
x.parent.children.remove(x);
}
children.insert(pos, x);
x.parent = this;
}
/**
Returns a String representation of the Xml node.
**/
public #if !cppia inline #end function toString():String {
return haxe.xml.Printer.print(this);
}
function new(nodeType:XmlType) {
this.nodeType = nodeType;
children = [];
attributeMap = new Map();
}
inline function ensureElementType() {
if (nodeType != Document && nodeType != Element) {
throw 'Bad node type, expected Element or Document but found $nodeType';
}
}
}
+38
View File
@@ -2,6 +2,8 @@ package funkin.backend.utils;
import flixel.util.FlxColor;
import openfl.display.BitmapData;
import openfl.geom.Point;
import openfl.geom.Rectangle;
class BitmapUtil {
/**
@@ -66,4 +68,40 @@ class BitmapUtil {
}
return mostPresentColor;
}
/**
* Returns a new bitmap without any empty transperent space on the edges
* @param bitmap The bitmap to be cropped
*/
public static function crop(bitmap:BitmapData) {
var bitmapBounds:Rectangle = BitmapUtil.bounds(bitmap);
var croppedBitmap:BitmapData = new BitmapData(Std.int(bitmapBounds.width), Std.int(bitmapBounds.height), true, 0x00000000);
croppedBitmap.copyPixels(bitmap, bitmapBounds, new Point(0,0));
return croppedBitmap;
}
/**
* Get bounds of non empty pixels in the bitmap
* @param bitmap
* @return
*/
public static function bounds(bitmap:BitmapData, ?limit:Rectangle = null):Rectangle {
var minX:Int = limit != null ? Std.int(limit.width) : bitmap.width;
var minY:Int = limit != null ? Std.int(limit.height) : bitmap.height;
var maxX:Int = limit != null ? Std.int(limit.x) : 0;
var maxY:Int = limit != null ? Std.int(limit.y) : 0;
for (y in (limit != null ? Std.int(limit.x) : 0)...(limit != null ? Std.int(limit.height) : bitmap.height))
for (x in (limit != null ? Std.int(limit.y) : 0)...(limit != null ? Std.int(limit.width) : bitmap.width)) {
if (bitmap.getPixel32(x, y) != 0x00000000) {
if (x < minX) minX = x;
if (y < minY) minY = y;
if (x > maxX) maxX = x;
if (y > maxY) maxY = y;
}
}
return new Rectangle(minX, minY, maxX-minX+1, maxY-minY+1);
}
}
@@ -0,0 +1,170 @@
package funkin.editors.character;
import openfl.geom.Rectangle;
import funkin.backend.utils.XMLUtil.AnimData;
import flixel.math.FlxPoint;
import flixel.util.FlxColor;
class CharacterAnimButton extends UIButton {
public var anim:String = null;
public var data:AnimData = null;
public var parent:CharacterAnimsWindow;
public var animationDisplayBG:UISliceSprite;
public var nameTextBox:UITextBox;
public var animTextBox:UITextBox;
public var positionXStepper:UINumericStepper;
public var positionYStepper:UINumericStepper;
public var fpsStepper:UINumericStepper;
public var loopedCheckbox:UICheckbox;
public var indicesTextBox:UITextBox;
public var XYComma:UIText;
public var editButton:FlxSprite;
public var editIcon:FlxSprite;
public var deleteButton:UIButton;
public var deleteIcon:FlxSprite;
public var ghostButton:UIButton;
public var ghostIcon:FlxSprite;
public var tempOpenButton:UIButton;
public var labels:Map<UISprite, UIText> = [];
public function new(x:Float, y:Float, animData:AnimData, parent:CharacterAnimsWindow) {
this.anim = animData.name;
this.data = animData;
this.parent = parent;
super(x,y, '${animData.name} (${animData.x}, ${animData.y})', function () {
CharacterEditor.instance.playAnimation(this.anim);
}, Std.int(500-16-32), 208);
function addLabelOn(ui:UISprite, text:String, ?size:Int):UIText {
var uiText:UIText = new UIText(ui.x, ui.y-18, 0, text, size);
members.push(uiText); labels.set(ui, uiText);
return uiText;
}
autoAlpha = autoFrames = autoFollow = false;
frames = Paths.getFrames('editors/ui/inputbox');
field.fieldWidth = 0; framesOffset = 9;
field.size = 14;
// field.visible = false;
animationDisplayBG = new UISliceSprite(x+12, y+12+18+12, 128, 128, 'editors/ui/inputbox-small');
members.push(animationDisplayBG);
nameTextBox = new UITextBox(animationDisplayBG.x+126+16, animationDisplayBG.y, animData.name, 116, 22, false, true);
members.push(nameTextBox);
addLabelOn(nameTextBox, "Name", 12);
animTextBox = new UITextBox(nameTextBox.x + 100 + 12, nameTextBox.y, animData.anim, 146, 22, false, true);
members.push(animTextBox);
addLabelOn(animTextBox, "Animation", 12);
positionXStepper = new UINumericStepper(animTextBox.x, animTextBox.y+32+18, animData.x, 0.001, 2, null, null, 64, 22, true);
members.push(positionXStepper);
addLabelOn(positionXStepper, "Position (X,Y)", 12);
members.push(XYComma = new UIText(positionXStepper.x+104-32+0, positionXStepper.y + 9, 0, ",", 18));
positionYStepper = new UINumericStepper(positionXStepper.x+104-32+26, positionXStepper.y, animData.y, 0.001, 2, null, null, 64, 22, true);
members.push(positionYStepper);
fpsStepper = new UINumericStepper(animTextBox.x + 200 + 26, animTextBox.y, 0, 0.1, 2, animData.fps, 100, 52, 22, true);
members.push(fpsStepper);
addLabelOn(fpsStepper, "FPS", 12);
loopedCheckbox = new UICheckbox(fpsStepper.x + 82 - 32 + 26, fpsStepper.y, "Looping?", animData.loop, 0, true);
members.push(loopedCheckbox);
addLabelOn(loopedCheckbox, "Looped", 12);
loopedCheckbox.x += 8; loopedCheckbox.y += 6;
indicesTextBox = new UITextBox(nameTextBox.x, nameTextBox.y, animData.indices.getDefault([]).join(","), 278, 22, false, true);
members.push(indicesTextBox);
addLabelOn(indicesTextBox, "Indices (frames)", 12);
editIcon = new FlxSprite().loadGraphic(Paths.image('editors/character/edit-button'), true, 16, 16);
editIcon.animation.add("open", [0]);
editIcon.animation.add("closed", [1]);
editIcon.animation.play("closed");
editIcon.antialiasing = false;
editIcon.updateHitbox();
members.push(editIcon);
deleteButton = new UIButton(0, 0, "", null, 28*2,24);
deleteButton.color = 0xFFAC3D3D;
members.push(deleteButton);
deleteIcon = new FlxSprite(x-(10+16), y+8).loadGraphic(Paths.image("editors/deleter"));
deleteIcon.color = 0xFFD60E0E;
deleteIcon.antialiasing = false;
members.push(deleteIcon);
ghostButton = new UIButton(0, 0, "", null, 28,24);
ghostButton.color = 0xFFADADAD;
ghostButton.alpha = 0.5;
members.push(ghostButton);
ghostIcon = new FlxSprite(x-(10+16), y+8).loadGraphic(Paths.image('editors/character/ghost'), true, 16, 12);
ghostIcon.animation.add("alive", [0]);
ghostIcon.animation.add("dead", [1]);
ghostIcon.animation.play("dead");
ghostIcon.antialiasing = false;
ghostIcon.updateHitbox();
members.push(ghostIcon);
}
public override function update(elapsed:Float) {
editIcon.follow(this, 22, 18);
field.follow(this, 22+16+8, 17);
deleteButton.follow(this, (500-16-32)-16-(28*2), 14);
deleteIcon.follow(deleteButton, (deleteButton.bWidth/2)-6.5, (deleteButton.bHeight/2)-6);
ghostButton.follow(this, (500-16-32)-16-(28*2)-16-28, 14);
ghostIcon.follow(ghostButton, (ghostButton.bWidth/2)-8, (ghostButton.bHeight/2)-6);
animationDisplayBG.follow(this, 16, 8+32+8+2+11);
nameTextBox.follow(this, 14+128+16, 8+32+8+2+8+14);
animTextBox.follow(this, 14+128+12+116+20, 8+32+8+2+8+14);
positionXStepper.follow(this, 14+128+16, 8+32+8+2+8+10+24+26);
positionYStepper.follow(this, 14+128+16+64-32+28, 8+32+8+2+8+10+24+26);
XYComma.follow(positionXStepper, 64-24, 6);
fpsStepper.follow(this, 14+128+16+64-32+28+64-22+20, 8+32+8+2+8+10+24+26);
loopedCheckbox.follow(this, 14+128+16+64-32+28+64-22+20+52-22+18+8, 8+32+8+2+8+10+24+32);
indicesTextBox.follow(this, 14+128+16, 8+32+8+2+8+10+24+26+24+22);
for (ui => text in labels)
text.follow(ui, -(2+(ui is UICheckbox?12:0)), -(18+(ui is UICheckbox?6:0)));
super.update(elapsed);
}
public override function draw() {
super.draw();
if (parent.displayAnimsFramesList.exists(anim)) {
var displayData:{frame:Int, scale:Float, animBounds:Rectangle} = parent.displayAnimsFramesList.get(anim);
parent.displayWindowSprite.frame = parent.displayWindowSprite.frames.frames[displayData.frame];
parent.displayWindowSprite.scale.x = parent.displayWindowSprite.scale.y = displayData.scale;
parent.displayWindowSprite.updateHitbox();
// parent.displayWindowSprite.origin.set();
parent.displayWindowSprite.follow(
this, 16+(128/2)-((parent.displayWindowSprite.frame.sourceSize.x*displayData.scale)/2),
8+32+8+2+11+(128/2)-((parent.displayWindowSprite.frame.sourceSize.y*displayData.scale)/2)
);
parent.displayWindowSprite.draw();
}
}
}
@@ -1,123 +0,0 @@
package funkin.editors.character;
import flixel.animation.FlxAnimation;
import flixel.math.FlxPoint;
import funkin.backend.utils.XMLUtil.AnimData;
class CharacterAnimScreen extends UISubstateWindow {
public var animData:AnimData;
public var nameTextBox:UITextBox;
public var animTextBox:UITextBox;
public var fpsStepper:UINumericStepper;
public var loopedCheckbox:UICheckbox;
public var indicesTextBox:UITextBox;
public var offsetXStepper:UINumericStepper;
public var offsetYStepper:UINumericStepper;
public var saveButton:UIButton;
public var closeButton:UIButton;
public var onSave:(animData:AnimData) -> Void = null;
public function new(animData:AnimData, ?onSave:(animData:AnimData) -> Void) {
this.animData = animData;
this.onSave = onSave;
super();
}
public override function create() {
var creatingAnim:Bool = animData == null;
if (creatingAnim)
animData = {
name: "name",
anim: "anim",
fps: 24,
loop: false,
animType: NONE,
x: 0,
y: 0,
indices: []
};
winTitle = creatingAnim ? 'Creating Animation' : 'Animation ${animData.name} properties';
winWidth = 690; winHeight = 314;
super.create();
function addLabelOn(ui:UISprite, text:String)
add(new UIText(ui.x, ui.y - 24, 0, text));
var title:UIText;
add(title = new UIText(windowSpr.x + 20, windowSpr.y + 30 + 16, 0, creatingAnim ? "Create New Animation" : "Edit Animation Properties", 28));
nameTextBox = new UITextBox(title.x, title.y + title.height + 38, animData.name, 160);
add(nameTextBox);
addLabelOn(nameTextBox, "Name");
animTextBox = new UITextBox(nameTextBox.x + 160 + 26, nameTextBox.y, animData.anim, 200);
add(animTextBox);
addLabelOn(animTextBox, "Animation");
fpsStepper = new UINumericStepper(animTextBox.x + 200 + 26, animTextBox.y, animData.fps, 0.1, 2, 1, 100, 82);
add(fpsStepper);
addLabelOn(fpsStepper, "FPS");
loopedCheckbox = new UICheckbox(fpsStepper.x + 82 - 32 + 26, fpsStepper.y, "Looped", animData.loop);
add(loopedCheckbox);
addLabelOn(loopedCheckbox, "Looping");
loopedCheckbox.x += 8; loopedCheckbox.y += 6;
indicesTextBox = new UITextBox(nameTextBox.x, nameTextBox.y + 32 + 40, animData.indices.join(", "), 270);
add(indicesTextBox);
addLabelOn(indicesTextBox, "Indices");
offsetXStepper = new UINumericStepper(indicesTextBox.x + 270 + 26, indicesTextBox.y, animData.x, 0.001, 2, null, null, 84);
add(offsetXStepper);
addLabelOn(offsetXStepper, "Offset (X,Y)");
add(new UIText(offsetXStepper.x + 84 - 32 + 0, offsetXStepper.y + 9, 0, ",", 22));
offsetYStepper = new UINumericStepper(offsetXStepper.x + 84 - 32 + 26, offsetXStepper.y, animData.y, 0.001, 2, null, null, 84);
add(offsetYStepper);
saveButton = new UIButton(windowSpr.x + windowSpr.bWidth - 20 - 125, windowSpr.y + windowSpr.bHeight - 16 - 32, "Save & Close", function() {
saveAnimData();
close();
}, 125);
add(saveButton);
closeButton = new UIButton(saveButton.x - 20, saveButton.y, creatingAnim ? "Cancel" : "Close", function() {
if (creatingAnim && onSave != null) onSave(null);
close();
}, 125);
add(closeButton);
closeButton.color = 0xFFFF0000;
closeButton.x -= closeButton.bWidth;
}
public function saveAnimData() {
for (stepper in [offsetXStepper, offsetYStepper, fpsStepper])
@:privateAccess stepper.__onChange(stepper.label.text);
animData = {
name: nameTextBox.label.text,
anim: animTextBox.label.text,
fps: fpsStepper.value,
loop: loopedCheckbox.checked,
animType: NONE,
x: offsetXStepper.value,
y: offsetYStepper.value,
indices: []
};
var indicesSplit = indicesTextBox.label.text.split(",");
for(indice in indicesSplit) {
var i = Std.parseInt(indice.trim());
if (i != null)
animData.indices.push(i);
}
if (onSave != null) onSave(animData);
}
}
@@ -0,0 +1,49 @@
package funkin.editors.character;
import flixel.graphics.FlxGraphic;
import openfl.geom.Rectangle;
import flixel.graphics.frames.FlxFrame;
import funkin.game.Character;
using funkin.backend.utils.BitmapUtil;
class CharacterAnimsWindow extends UIButtonList<CharacterAnimButton> {
public var character:Character;
public var displayWindowSprite:FlxSprite;
public var displayWindowGraphic:FlxGraphic;
public var displayAnimsFramesList:Map<String, {scale:Float, animBounds:Rectangle, frame:Int}> = [];
public function new(x:Float, y:Float, character:Character) {
super(x, y, Std.int(500-16), 419, "", FlxPoint.get(Std.int(500-16-32), 208));
cameraSpacing = 0;
frames = Paths.getFrames('editors/ui/inputbox');
buttonCameras.pixelPerfectRender = true;
if (Assets.exists(Paths.image('characters/${character.sprite}')))
displayWindowGraphic = FlxG.bitmap.add(Assets.getBitmapData(Paths.image('characters/${character.sprite}'), true, false));
displayWindowSprite = new FlxSprite();
displayWindowSprite.loadGraphicFromSprite(character);
displayWindowSprite.antialiasing = character.antialiasing;
displayWindowSprite.flipX = character.flipX;
@:privateAccess
for (name => anim in displayWindowSprite.animation._animations) {
var frameIndex:Int = anim.frames.getDefault([0])[0];
var frame:FlxFrame = displayWindowSprite.frames.frames[frameIndex];
var frameRect:Rectangle = new Rectangle(frame.offset.x, frame.offset.y, frame.sourceSize.x, frame.sourceSize.y);
var animBounds:Rectangle = displayWindowGraphic != null ? displayWindowGraphic.bitmap.bounds(frameRect) : frameRect;
displayAnimsFramesList.set(name, {frame: anim.frames.getDefault([0])[0], scale: 104/animBounds.height, animBounds: animBounds});
}
for (anim in character.getAnimOrder())
add(new CharacterAnimButton(0,0, character.animDatas.get(anim), this));
}
}
@@ -1,5 +1,7 @@
package funkin.editors.character;
import funkin.editors.extra.CameraHoverDummy;
import openfl.display.BitmapData;
import flixel.math.FlxPoint;
import funkin.backend.system.framerate.Framerate;
import funkin.backend.utils.XMLUtil.AnimData;
@@ -28,15 +30,12 @@ class CharacterEditor extends UIState {
public var uiGroup:FlxTypedGroup<FlxSprite> = new FlxTypedGroup<FlxSprite>();
// WINDOWS
public var characterPropertiresWindow:CharacterPropertiesWindow;
public var characterAnimsWindow:UIButtonList<CharacterAnimButtons>;
public var cameraHoverDummy:CameraHoverDummy;
public var characterPropertiesWindow:CharacterPropertiesWindow;
public var characterAnimsWindow:CharacterAnimsWindow;
// camera for the character itself so that it can be unzoomed/zoomed in again
public var charCamera:FlxCamera;
// camera for the animations list
public var animsCamera:FlxCamera;
// camera for the ui
public var uiCamera:FlxCamera;
public var undos:UndoList<CharacterChange> = new UndoList<CharacterChange>();
@@ -211,8 +210,6 @@ class CharacterEditor extends UIState {
uiCamera = new FlxCamera();
uiCamera.bgColor = 0;
animsCamera = new FlxCamera(800-23,140+23+30+46,450+23,511-24-30);
animsCamera.bgColor = 0;
characterBG = new FunkinSprite(0, 0, Paths.image('editors/character/WOAH'));
characterBG.cameras = [charCamera];
@@ -221,8 +218,9 @@ class CharacterEditor extends UIState {
characterBG.scrollFactor.set();
add(characterBG);
// characterBG.visible = false;
FlxG.cameras.add(uiCamera);
FlxG.cameras.add(animsCamera);
character = new Character(0,0, __character, false, false);
character.debugMode = true;
@@ -234,23 +232,24 @@ class CharacterEditor extends UIState {
add(ghosts);
add(character);
uiGroup.cameras = [uiCamera];
add(cameraHoverDummy = new CameraHoverDummy(uiGroup, FlxPoint.weak(0, 0)));
characterPropertiesWindow = new CharacterPropertiesWindow((FlxG.width-(532+16)), 23+12+10, character);
uiGroup.add(characterPropertiesWindow);
topMenuSpr = new UITopMenu(topMenu);
topMenuSpr.cameras = uiGroup.cameras = [uiCamera];
topMenuSpr.cameras = [uiCamera];
characterPropertiresWindow = new CharacterPropertiesWindow();
uiGroup.add(characterPropertiresWindow);
characterAnimsWindow = new UIButtonList<CharacterAnimButtons>(777, 209, 473, 488, "Character Animations", FlxPoint.get(429, 32));
characterAnimsWindow.addButton.callback = function() CharacterEditor.instance.createAnimWithUI();
var animOrder = character.getAnimOrder();
for (i=>anim in animOrder)
characterAnimsWindow.add(new CharacterAnimButtons(0,0, anim, character.getAnimOffset(anim)));
characterAnimsWindow = new CharacterAnimsWindow(characterPropertiesWindow.x, characterPropertiesWindow.y+224+16, character);
uiGroup.add(characterAnimsWindow);
playAnimation(animOrder[0]);
add(topMenuSpr);
add(uiGroup);
add(topMenuSpr);
playAnimation(character.getAnimOrder()[0]);
_view_focus_character(null);
if(Framerate.isLoaded) {
Framerate.fpsCounter.alpha = 0.4;
@@ -270,23 +269,13 @@ class CharacterEditor extends UIState {
}
}
//private var movingCam:Bool = false;
//private var camDragSpeed:Float = 1.2;
private var nextScroll:FlxPoint = FlxPoint.get(0,0);
var _nextScroll:FlxPoint = FlxPoint.get(0,0);
var _cameraZoomMulti:Float = 1;
public override function update(elapsed:Float) {
super.update(elapsed);
if(FlxG.keys.justPressed.ANY)
UIUtil.processShortcuts(topMenu);
if (true) {
if(FlxG.keys.justPressed.ANY)
UIUtil.processShortcuts(topMenu);
}
if (character != null)
characterPropertiresWindow.characterInfo.text = '${character.getNameList().length} Animations\nFlipped: ${character.flipX}\nSprite: ${character.sprite}\nAnim: ${character.getAnimName()}\nOffset: (${character.frameOffset.x}, ${character.frameOffset.y})';
if (!(characterPropertiresWindow.hovered || characterAnimsWindow.hovered) && !characterAnimsWindow.dragging) {
if (cameraHoverDummy.hovered) {
if (FlxG.mouse.wheel != 0) {
zoom += 0.25 * FlxG.mouse.wheel;
__camZoom = Math.pow(2, zoom);
@@ -296,8 +285,9 @@ class CharacterEditor extends UIState {
closeCurrentContextMenu();
openContextMenu(topMenu[2].childs);
}
if (FlxG.mouse.pressed) {
nextScroll.set(nextScroll.x - FlxG.mouse.deltaScreenX, nextScroll.y - FlxG.mouse.deltaScreenY);
_nextScroll.set(_nextScroll.x - FlxG.mouse.deltaScreenX, _nextScroll.y - FlxG.mouse.deltaScreenY);
currentCursor = HAND;
} else
currentCursor = ARROW;
@@ -305,15 +295,17 @@ class CharacterEditor extends UIState {
currentCursor = ARROW;
charCamera.scroll.set(
lerp(charCamera.scroll.x, nextScroll.x, 0.35),
lerp(charCamera.scroll.y, nextScroll.y, 0.35)
lerp(charCamera.scroll.x, _nextScroll.x, 0.35),
lerp(charCamera.scroll.y, _nextScroll.y, 0.35)
);
charCamera.zoom = lerp(charCamera.zoom, __camZoom, 0.125);
charCamera.zoom = lerp(charCamera.zoom, __camZoom*_cameraZoomMulti, 0.125);
characterBG.scale.set(FlxG.width/characterBG.width, FlxG.height/characterBG.height);
characterBG.scale.set(characterBG.scale.x / charCamera.zoom, characterBG.scale.y / charCamera.zoom);
super.update(elapsed);
WindowUtils.prefix = undos.unsaved ? "* " : "";
SaveWarning.showWarning = undos.unsaved;
}
@@ -357,15 +349,6 @@ class CharacterEditor extends UIState {
button.anim
]);
// clean
if (charXML.exists("gameOverChar") && character.gameOverCharacter == "bf-dead") charXML.remove("gameOverChar");
if (charXML.exists("camx") && character.cameraOffset.x == 0) charXML.remove("camx");
if (charXML.exists("camy") && character.cameraOffset.y == 0) charXML.remove("camy");
if (charXML.exists("holdTime") && character.holdTime == 4) charXML.remove("holdTime");
if (charXML.exists("flipX") && !character.flipX) charXML.remove("flipX");
if (charXML.exists("scale") && character.scale.x == 1) charXML.remove("scale");
if (charXML.exists("antialiasing") && character.antialiasing) charXML.remove("antialiasing");
return "<!DOCTYPE codename-engine-character>\n" + Printer.print(charXML, true);
}
@@ -390,9 +373,6 @@ class CharacterEditor extends UIState {
ghosts.setOffsets(anim, offsets.clone());
}
for (charButton in characterAnimsWindow.buttons.members)
charButton.updateInfo(charButton.anim, character.getAnimOffset(charButton.anim), ghosts.animGhosts[charButton.anim].visible);
changeOffset(character.getAnimName(), FlxPoint.get(0, 0), false); // apply da new offsets
}
}
@@ -434,21 +414,18 @@ class CharacterEditor extends UIState {
}
public function createAnimWithUI() {
FlxG.state.openSubState(new CharacterAnimScreen(null, (_) -> {
if (_ != null) createAnim(_);
}));
}
public function editAnimWithUI(name:String) {
FlxG.state.openSubState(new CharacterAnimScreen(character.animDatas.get(name), (_) -> {
if (_ != null) editAnim(name, _);
}));
}
public function createAnim(animData:AnimData, animID:Int = -1, addtoUndo:Bool = true) {
/*
XMLUtil.addAnimToSprite(character, animData);
ghosts.createGhost(animData.name);
var newButton = new CharacterAnimButtons(0, 0, animData.name, FlxPoint.get(animData.x,animData.y));
var newButton = new CharacterAnimButton(0, 0, animData.name, FlxPoint.get(animData.x,animData.y));
if (animID == -1) characterAnimsWindow.add(newButton);
else characterAnimsWindow.insert(newButton, animID);
@@ -456,18 +433,18 @@ class CharacterEditor extends UIState {
if (addtoUndo)
undos.addToUndo(CCreateAnim(character.getNameList().length, animData));
*/
}
public function editAnim(name:String, animData:AnimData, addtoUndo:Bool = true) {
var oldAnimData:AnimData = character.animDatas.get(name);
var buttoner:CharacterAnimButtons = null;
var buttoner:CharacterAnimButton = null;
for (button in characterAnimsWindow.buttons.members)
if (button.anim == name) buttoner = button;
ghosts.removeGhost(name);
XMLUtil.addAnimToSprite(character, animData);
ghosts.createGhost(animData.name);
buttoner.updateInfo(animData.name, character.getAnimOffset(animData.name), ghosts.animGhosts[animData.name].visible);
if (character.getAnimName() == animData.name) // update anim ifs its currently selected
playAnimation(animData.name);
@@ -526,10 +503,9 @@ class CharacterEditor extends UIState {
var ghost:Character = ghosts.animGhosts.get(anim);
ghost.visible = !ghost.visible;
var animButton:CharacterAnimButtons = null;
var animButton:CharacterAnimButton = null;
for (button in characterAnimsWindow.buttons.members)
if (button.anim == anim) animButton = button;
animButton.updateInfo(anim, character.getAnimOffset(anim), ghost.visible);
}
function _playback_play_anim(_) {
@@ -589,9 +565,6 @@ class CharacterEditor extends UIState {
if (character.getNameList().length == 0) return;
character.animOffsets.set(anim, character.getAnimOffset(anim) + change);
for (i in characterAnimsWindow.buttons.members)
if (i.anim == anim)
i.updateInfo(anim, character.getAnimOffset(anim), ghosts.animGhosts[anim].visible);
character.frameOffset.set(character.getAnimOffset(anim).x, character.getAnimOffset(anim).y);
ghosts.updateOffsets(anim, change);
@@ -607,13 +580,6 @@ class CharacterEditor extends UIState {
for (anim => offsets in character.animOffsets)
anim => offsets.clone()
];
for (anim in character.getNameList()) {
character.animOffsets[anim].zero();
for (i in characterAnimsWindow.buttons.members)
if (i.anim == anim)
i.updateInfo(anim, character.getAnimOffset(anim), ghosts.animGhosts[anim].visible);
}
changeOffset(character.getAnimName(), FlxPoint.get(), false);
ghosts.clearOffsets();
@@ -642,6 +608,16 @@ class CharacterEditor extends UIState {
zoom = 0;
__camZoom = Math.pow(2, zoom);
}
function _view_focus_character(_) {
if (character == null) return;
var characterMidpoint:FlxPoint = character.getMidpoint();
characterMidpoint.x -= (FlxG.width/2)-character.globalOffset.x;
characterMidpoint.y -= (FlxG.height/2)-character.globalOffset.y+(23/4);
_nextScroll.set(characterMidpoint.x, characterMidpoint.y);
characterMidpoint.put();
}
#end
}
@@ -0,0 +1,53 @@
package funkin.editors.character;
import openfl.geom.Point;
import openfl.geom.Rectangle;
import openfl.display.BitmapData;
import flixel.util.FlxColor;
using funkin.backend.utils.BitmapUtil;
// DONT DELETE I MIGHT USE LATER -lunar
class CharacterIconDisplay extends UISprite {
public var healthBarBG:FlxSprite;
public var healthBar:FlxSprite;
public var textProperties:UIText;
public function new(x:Float, y:Float, name:String, icon:String, color:Null<FlxColor>, barWidth:Int) {
super(x, y);
var path:String = Paths.image('icons/${icon}');
if (!Assets.exists(path)) path = Paths.image('icons/face');
var imageBitmap:BitmapData = Assets.getBitmapData(path, true, false);
var iconBitmap:BitmapData = new BitmapData(150, 150, true, 0x00000000);
iconBitmap.copyPixels(imageBitmap, new Rectangle(0, 0, 150, 150), new Point(0,0));
loadGraphic(FlxG.bitmap.add(iconBitmap.crop()));
scale.x = scale.y = 40/pixels.height;
updateHitbox();
// bye guys :((
imageBitmap.dispose(); iconBitmap.dispose();
antialiasing = true;
healthBarBG = new FlxSprite(x+(width/2), y+(height*(2.25/4))+2).makeSolid(barWidth-Std.int(width), 10, 0xFF000000);
healthBar = new FlxSprite(healthBarBG.x+2, healthBarBG.y+2).makeSolid(
Std.int(healthBarBG.width-4), Std.int(healthBarBG.height-4),
color != null ? color : 0xFFFFFFFF
);
textProperties = new UIText(x+width+2, healthBarBG.y-14, 0, 'Character Properties of ${name}...', 13);
members.push(healthBarBG);
members.push(healthBar);
members.push(textProperties);
}
public override function draw() {
drawMembers();
drawSuper();
}
}
@@ -23,7 +23,6 @@ class CharacterInfoScreen extends UISubstateWindow {
public var singTimeStepper:UINumericStepper;
public var customPropertiesButtonList:UIButtonList<PropertyButton>;
public var isPlayerCheckbox:UICheckbox;
public var isGFCheckbox:UICheckbox;
public var saveButton:UIButton;
public var closeButton:UIButton;
@@ -119,11 +118,7 @@ class CharacterInfoScreen extends UISubstateWindow {
add(isPlayerCheckbox);
addLabelOn(isPlayerCheckbox, "Is Player");
isGFCheckbox = new UICheckbox(isPlayerCheckbox.x + 128, positionXStepper.y + 10 + 32 + 28, "isGF", character.isGF);
add(isGFCheckbox);
addLabelOn(isGFCheckbox, "Is GF");
for (checkbox in [isPlayerCheckbox, isGFCheckbox, antialiasingCheckbox, flipXCheckbox])
for (checkbox in [isPlayerCheckbox, antialiasingCheckbox, flipXCheckbox])
{checkbox.y += 4; checkbox.x += 6;}
saveButton = new UIButton(windowSpr.x + windowSpr.bWidth - 20, windowSpr.y + windowSpr.bHeight- 20, "Save & Close", function() {
@@ -168,7 +163,6 @@ class CharacterInfoScreen extends UISubstateWindow {
var xml = Xml.createElement("character");
xml.set("isPlayer", isPlayerCheckbox.checked ? "true" : "false");
xml.set("isGF", isGFCheckbox.checked ? "true" : "false");
xml.set("x", Std.string(positionXStepper.value));
xml.set("y", Std.string(positionYStepper.value));
xml.set("gameOverChar", gameOverCharTextBox.label.text);
@@ -1,27 +1,65 @@
package funkin.editors.character;
import flixel.util.FlxColor;
import funkin.game.Character;
class CharacterPropertiesWindow extends UIWindow {
public var newButton:UIButton;
public var editButton:UIButton;
class CharacterPropertiesWindow extends UISliceSprite {
public var positionXStepper:UINumericStepper;
public var positionYStepper:UINumericStepper;
public var scaleStepper:UINumericStepper;
public var flipXCheckbox:UICheckbox;
public var characterInfo:UIText;
public var cameraXStepper:UINumericStepper;
public var cameraYStepper:UINumericStepper;
public var antialiasingCheckbox:UICheckbox;
public var testAsDropDown:UIDropDown;
public var designedAsDropDown:UIDropDown;
public function new(x:Float, y:Float, character:Character) {
super(x, y, Std.int(500-16), 204+20, "editors/ui/inputbox");
public function new() {
super(800-23,23 + 23, 450 + 23, 140, "Character Properties");
function addLabelOn(ui:UISprite, text:String)
members.push(new UIText(ui.x, ui.y - 24, 0, text));
newButton = new UIButton( x +(450 + 23)- 25 - 3 - 200, y + 12 + 31, "New Character", null, 200);
members.push(newButton);
newButton.color = FlxColor.GREEN;
positionXStepper = new UINumericStepper(x+16, y+36, character.globalOffset.x, 0.001, 2, null, null, 104);
members.push(positionXStepper);
addLabelOn(positionXStepper, "Position (X,Y)");
editButton = new UIButton(newButton.x, newButton.y + 12 + 30 + 4, "Edit Character Info", function () {
CharacterEditor.instance.editInfoWithUI();
}, 200);
members.push(editButton);
members.push(new UIText(positionXStepper.x+104-32+0, positionXStepper.y + 9, 0, ",", 22));
characterInfo = new UIText(x + 450 + 20 - 42 - 400, y + 36 + 10, 400, "0 Animations:\nFlipped:\nSprite:\nAnim:\nOffset: (,)");
characterInfo.alignment = LEFT;
members.push(characterInfo);
positionYStepper = new UINumericStepper(positionXStepper.x+104-32+26, positionXStepper.y, character.globalOffset.y, 0.001, 2, null, null, 104);
members.push(positionYStepper);
scaleStepper = new UINumericStepper(positionYStepper.x+104-32+32, positionYStepper.y, character.scale.x, 0.001, 2, null, null, 104);
members.push(scaleStepper);
addLabelOn(scaleStepper, "Scale");
flipXCheckbox = new UICheckbox(scaleStepper.x+104-32+24, scaleStepper.y, "Flipped?", character.flipX);
members.push(flipXCheckbox);
addLabelOn(flipXCheckbox, "Flipped X");
cameraXStepper = new UINumericStepper(positionXStepper.x, positionXStepper.y+32+32+4, character.cameraOffset.x, 0.001, 2, null, null, 104);
members.push(cameraXStepper);
addLabelOn(cameraXStepper, "Camera Position (X,Y)");
members.push(new UIText(cameraXStepper.x + 104-32+0, cameraXStepper.y+9, 0, ",", 22));
cameraYStepper = new UINumericStepper(cameraXStepper.x+104-32+26, cameraXStepper.y, character.cameraOffset.y, 0.001, 2, null, null, 104);
members.push(cameraYStepper);
antialiasingCheckbox = new UICheckbox(cameraYStepper.x+104-32+32+24, cameraYStepper.y, "Antialiased?", character.antialiasing);
members.push(antialiasingCheckbox);
addLabelOn(antialiasingCheckbox, "Antialiasing");
testAsDropDown = new UIDropDown(cameraXStepper.x, cameraXStepper.y+32+32+4, 238, 32, ["PLAYER", "OPPONENT"], 0);
members.push(testAsDropDown);
addLabelOn(testAsDropDown, "Test Character As...");
designedAsDropDown = new UIDropDown(testAsDropDown.x+238, testAsDropDown.y, 238, 32, ["PLAYER", "OPPONENT"], 0);
members.push(designedAsDropDown);
addLabelOn(designedAsDropDown, "Char Desgined As...");
antialiasingCheckbox.x+=14;
for (checkbox in [flipXCheckbox, antialiasingCheckbox])
{checkbox.y += 3; checkbox.x += 12;}
}
}
+3 -3
View File
@@ -1,6 +1,7 @@
package funkin.editors.charter;
// ! FUCK YOU CHUF (your biggest fan -lunar) <3
import funkin.editors.extra.CameraHoverDummy;
import flixel.input.keyboard.FlxKey;
import flixel.math.FlxPoint;
import flixel.sound.FlxSound;
@@ -8,7 +9,6 @@ import funkin.backend.chart.*;
import funkin.backend.chart.ChartData;
import funkin.backend.system.Conductor;
import funkin.backend.system.framerate.Framerate;
import funkin.editors.charter.CharterBackdropGroup.CharterBackdropDummy;
import funkin.editors.charter.CharterBackdropGroup.EventBackdrop;
import funkin.editors.charter.CharterStrumline;
import funkin.editors.ui.UIContextMenu.UIContextMenuOption;
@@ -50,7 +50,7 @@ class Charter extends UIState {
public var eventsBackdrop:EventBackdrop;
public var addEventSpr:CharterEventAdd;
public var gridBackdropDummy:CharterBackdropDummy;
public var gridBackdropDummy:CameraHoverDummy;
public var noteHoverer:CharterNoteHoverer;
public var noteDeleteAnims:CharterDeleteAnim;
@@ -391,7 +391,7 @@ class Charter extends UIState {
eventsBackdrop.cameras = [charterCamera];
eventsGroup.eventsBackdrop = eventsBackdrop;
add(gridBackdropDummy = new CharterBackdropDummy(gridBackdrops));
add(gridBackdropDummy = new CameraHoverDummy(gridBackdrops, FlxPoint.weak(1, 0)));
selectionBox = new UISliceSprite(0, 0, 2, 2, 'editors/ui/selection');
selectionBox.visible = false;
selectionBox.scrollFactor.set(1, 1);
@@ -237,26 +237,6 @@ class CharterBackdrop extends FlxTypedGroup<Dynamic> {
}
}
class CharterBackdropDummy extends UISprite {
var parent:CharterBackdropGroup;
public function new(parent:CharterBackdropGroup) {
super();
this.parent = parent;
cameras = parent.cameras;
scrollFactor.set(1, 0);
}
public override function updateButton() {
camera.getViewRect(__rect);
UIState.state.updateRectButtonHandler(this, __rect, onHovered);
}
public override function draw() {
@:privateAccess
__lastDrawCameras = cameras.copy();
}
}
class EventBackdrop extends FlxBackdrop {
public var eventBeatSeparator:FlxBackdrop;
public var eventSecSeparator:FlxBackdrop;
@@ -0,0 +1,21 @@
package funkin.editors.extra;
class CameraHoverDummy extends UISprite {
var parent:FlxBasic;
public function new(?parent:FlxBasic, scroll:FlxPoint) {
super();
this.parent = parent;
cameras = parent == null ? [FlxG.camera] : parent.cameras;
scrollFactor.copyFrom(scroll);
}
public override function updateButton() {
camera.getViewRect(__rect);
UIState.state.updateRectButtonHandler(this, __rect, onHovered);
}
public override function draw() {
@:privateAccess
__lastDrawCameras = cameras.copy();
}
}
+5 -2
View File
@@ -6,6 +6,9 @@ class UIButton extends UISliceSprite {
public var shouldPress = true;
public var hasBeenPressed = false;
public var autoFrames:Bool = true;
public var autoFollow:Bool = true;
public override function new(x:Float, y:Float, text:String, callback:Void->Void, w:Int = 120, h:Int = 32) {
super(x, y, w, h, 'editors/ui/button');
this.callback = callback;
@@ -18,7 +21,7 @@ class UIButton extends UISliceSprite {
public override function resize(w:Int, h:Int) {
super.resize(w, h);
if (field != null) field.fieldWidth = w;
if (field != null && autoFollow) field.fieldWidth = w;
}
public override function onHovered() {
@@ -31,7 +34,7 @@ class UIButton extends UISliceSprite {
}
public override function update(elapsed:Float) {
field.follow(this, 0, (bHeight - field.height) / 2);
if (autoFollow) field.follow(this, 0, (bHeight - field.height) / 2);
if (!hovered && hasBeenPressed && FlxG.mouse.justReleased) hasBeenPressed = false;
if (autoAlpha) alpha = field.alpha = selectable ? 1 : 0.4;
super.update(elapsed);
+2 -2
View File
@@ -105,14 +105,14 @@ class UIButtonList<T:UIButton> extends UIWindow {
super.update(elapsed);
nextscrollY = FlxMath.bound(buttonCameras.scroll.y - (hovered ? FlxG.mouse.wheel : 0) * 12, -buttonSpacing, Math.max((addButton.y + 32 + (buttonSpacing*1.5)) - buttonCameras.height, -buttonSpacing));
nextscrollY = FlxMath.bound(nextscrollY - (hovered ? FlxG.mouse.wheel : 0) * 12, -buttonSpacing, Math.max((addButton.y + 32 + (buttonSpacing*1.5)) - buttonCameras.height, -buttonSpacing));
if (curMoving != null && dragging) {
nextscrollY -= Math.min((bHeight - 100) - FlxG.mouse.getWorldPosition(buttonCameras).y, 0) / 8;
nextscrollY += Math.min(FlxG.mouse.getWorldPosition(buttonCameras).y - 100, 0) / 8;
}
buttonCameras.scroll.y = nextscrollY;
buttonCameras.scroll.y = FlxMath.lerp(buttonCameras.scroll.y, nextscrollY, 1/3);
for (i => button in buttons.members) {
if (button == null) continue;
+7 -5
View File
@@ -2,20 +2,22 @@ package funkin.editors.ui;
class UICheckbox extends UISprite {
public var checked:Bool = false;
public var small:Bool = false;
public var onChecked:Bool->Void = null;
public var field:UIText;
public var check:FlxSprite;
public function new(x:Float, y:Float, text:String, checked:Bool = false, w:Int = 0) {
public function new(x:Float, y:Float, text:String, checked:Bool = false, w:Int = 0, small:Bool = false) {
super(x, y);
loadGraphic(Paths.image('editors/ui/checkbox'), true, 20, 20);
for(frame=>name in ["normal", "hover", "pressed", "selected"])
loadGraphic(Paths.image('editors/ui/checkbox${small ? "-small" : ""}'), true, small ? 14 : 20, small ? 14 : 20);
for(frame=>name in ["normal", "hover", "pressed", "checkmark"])
animation.add(name, [frame], 0, false);
this.checked = checked;
this.small = small;
field = new UIText(x, y, w, text);
field = new UIText(x, y, w, text, small ? 12 : 15);
check = new FlxSprite().loadGraphicFromSprite(this);
check.animation.play("selected");
@@ -42,7 +44,7 @@ class UICheckbox extends UISprite {
public inline function updatePositions() {
check.follow(this);
field.follow(this, 25, 0);
field.follow(this, (small ? 14 : 20)+5, 0);
}
public override function draw() {
+2 -2
View File
@@ -7,8 +7,8 @@ class UINumericStepper extends UITextBox {
public var max:Null<Float> = null;
public var step:Float = 1;
public function new(x:Float, y:Float, value:Float = 0, step:Float = 1, precision:Int = 0, ?min:Float, ?max:Float, w:Int = 180, h:Int = 32) {
super(x, y, "", w - h, h, false);
public function new(x:Float, y:Float, value:Float = 0, step:Float = 1, precision:Int = 0, ?min:Float, ?max:Float, w:Int = 180, h:Int = 32, small:Bool = false) {
super(x, y, "", w - h, h, false, small);
onChange = __onChange;
+3 -3
View File
@@ -17,10 +17,10 @@ class UITextBox extends UISliceSprite implements IUIFocusable {
var __wasFocused:Bool = false;
public function new(x:Float, y:Float, text:String = "", width:Int = 320, height:Int = 32, multiline:Bool = false) {
super(x, y, width, height, 'editors/ui/inputbox');
public function new(x:Float, y:Float, text:String = "", width:Int = 320, height:Int = 32, multiline:Bool = false, small:Bool = false) {
super(x, y, width, height, 'editors/ui/inputbox${small ? "-small" : ""}');
label = new UIText(0, 0, width, text);
label = new UIText(0, 0, width, text, small ? 12 : 15);
members.push(label);
caretSpr = new FlxSprite(0, 0);
+186 -295
View File
@@ -1,5 +1,6 @@
package funkin.game;
import flixel.util.typeLimit.OneOfTwo;
import flixel.graphics.frames.FlxFrame;
import flixel.math.FlxPoint;
import flixel.math.FlxRect;
@@ -26,15 +27,8 @@ using StringTools;
@:allow(funkin.desktop.editors.CharacterEditor)
@:allow(funkin.game.StrumLine)
@:allow(funkin.game.PlayState)
class Character extends FunkinSprite implements IBeatReceiver implements IOffsetCompatible
{
private var __stunnedTime:Float = 0;
private var __lockAnimThisFrame:Bool = false;
public var stunned(default, set):Bool = false;
class Character extends FunkinSprite implements IBeatReceiver implements IOffsetCompatible {
public var isPlayer:Bool = false;
public var isGF:Bool = false;
public var curCharacter:String = 'bf';
public var sprite:String = 'bf';
@@ -45,41 +39,21 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
public var icon:String = null;
public var iconColor:Null<FlxColor> = null;
public var gameOverCharacter:String = "bf-dead";
public var gameOverCharacter:String = Character.FALLBACK_DEAD_CHARACTER;
public var cameraOffset:FlxPoint = new FlxPoint(0, 0);
public var globalOffset:FlxPoint = new FlxPoint(0, 0);
public var cameraOffset:FlxPoint = FlxPoint.get(0, 0);
public var globalOffset:FlxPoint = FlxPoint.get(0, 0);
public var script:Script;
public var xml:Access;
public var shadowFrame:CharacterShadowFrame;
public var idleSuffix:String = "";
public var stunned(default, set):Bool = false;
public inline function getCameraPosition()
{
var midpoint = getMidpoint();
var event = EventManager.get(PointEvent).recycle(
midpoint.x + (isPlayer ? -100 : 150) + globalOffset.x + cameraOffset.x,
midpoint.y - 100 + globalOffset.y + cameraOffset.y);
script.call("onGetCamPos", [event]);
midpoint.put();
// this event cannot be cancelled
return new FlxPoint(event.x, event.y);
}
@:noCompletion var __stunnedTime:Float = 0;
@:noCompletion var __lockAnimThisFrame:Bool = false;
var singAnims = ["singLEFT", "singDOWN", "singUP", "singRIGHT"];
public function playSingAnim(direction:Int, suffix:String = "", Context:PlayAnimContext = SING, Force:Bool = true, Reversed:Bool = false, Frame:Int = 0)
{
var event = EventManager.get(DirectionAnimEvent).recycle(singAnims[direction % singAnims.length] + suffix, direction, suffix, Context, Reversed, Frame, Force);
script.call("onPlaySingAnim", [event]);
if (!event.cancelled)
playAnim(event.animName, event.force, event.context, event.reversed, event.frame);
}
public function new(x:Float, y:Float, ?character:String = "bf", isPlayer:Bool = false, switchAnims:Bool = true, disableScripts:Bool = false)
{
public function new(x:Float, y:Float, ?character:String = "bf", isPlayer:Bool = false, switchAnims:Bool = true, disableScripts:Bool = false) {
super(x, y);
animOffsets = new Map<String, FlxPoint>();
@@ -88,87 +62,29 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
antialiasing = true;
while (true)
{
switch (curCharacter)
{
// case 'your-char': // To hardcode characters
default:
// load xml
var xmlPath = Paths.xml('characters/$curCharacter');
if (!Assets.exists(xmlPath))
{
curCharacter = "bf";
continue;
}
xml = getXMLFromCharName(this);
var plainXML = Assets.getText(xmlPath);
try
{
var charXML = Xml.parse(plainXML).firstElement();
if (charXML == null) throw new Exception("Missing \"character\" node in XML.");
xml = new Access(charXML);
} catch (e) {
Logs.trace('Error while loading character ${curCharacter}: ${e}', ERROR);
curCharacter = "bf";
continue;
}
// Loads the script
if(!disableScripts) {
script = Script.create(Paths.script(Path.withoutExtension(xmlPath), null, true));
} else {
script = new DummyScript(curCharacter);
}
if(!disableScripts)
script = Script.create(Paths.script(Path.withoutExtension(Paths.xml('characters/$curCharacter')), null, true));
else
script = new DummyScript(curCharacter);
script.setParent(this);
script.load();
buildCharacter(xml);
script.call("create");
script.setParent(this);
script.load();
applyXML(xml);
script.call("create");
}
break;
}
if (script == null)
script = new DummyScript(curCharacter);
/**
NON CONVERTED CHARACTERS - DO NOT REMOVE
**/
// case 'bf-pixel-dead':
// frames = Paths.getSparrowAtlas('weeb/bfPixelsDEAD');
// animation.addByPrefix('singUP', "BF Dies pixel", 24, false);
// animation.addByPrefix('firstDeath', "BF Dies pixel", 24, false);
// animation.addByPrefix('deathLoop', "Retry Loop", 24, true);
// animation.addByPrefix('deathConfirm', "RETRY CONFIRM", 24, false);
// animation.play('firstDeath');
// addOffset('firstDeath');
// addOffset('deathLoop', -37);
// addOffset('deathConfirm', -37);
// playAnim('firstDeath');
// // pixel bullshit
// setGraphicSize(Std.int(width * 6));
// updateHitbox();
// antialiasing = false;
// flipX = true;
script.call("postCreate");
}
public function fixChar(switchAnims:Bool = false, autoInterval:Bool = false)
{
public function fixChar(switchAnims:Bool = false, autoInterval:Bool = false) {
if ((isDanceLeftDanceRight = hasAnimation("danceLeft") && hasAnimation("danceRight")) && autoInterval)
beatInterval = 1;
// alternative to xor operator
// for people who dont believe it, heres the truth table
// [ a ][ b ][ a!= b ]
// [ true ][ true ][ false ]
// [ true ][ false ][ true ]
// [ false ][ true ][ true ]
// [ true ][ true ][ false ]
// bros provided evedince :skull:
if (isPlayer != playerOffsets && switchAnims)
{
if (isPlayer != playerOffsets && switchAnims) {
// character is flipped
CoolUtil.switchAnimFrames(animation.getByName('singRIGHT'), animation.getByName('singLEFT'));
CoolUtil.switchAnimFrames(animation.getByName('singRIGHTmiss'), animation.getByName('singLEFTmiss'));
@@ -182,15 +98,13 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
__baseFlipped = flipX;
}
var __baseFlipped:Bool = false;
var isDanceLeftDanceRight:Bool = false;
@:noCompletion var __baseFlipped:Bool = false;
@:noCompletion var isDanceLeftDanceRight:Bool = false;
override function update(elapsed:Float)
{
override function update(elapsed:Float) {
super.update(elapsed);
script.call("update", [elapsed]);
if (stunned)
{
if (stunned) {
__stunnedTime += elapsed;
if (__stunnedTime > 5 / 60)
stunned = false;
@@ -204,33 +118,20 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
private var danced:Bool = false;
/**
* FOR GF DANCING SHIT
*/
public function dance()
{
public function dance() {
if(debugMode) return;
var event = EventManager.get(DanceEvent).recycle(danced);
script.call("onDance", [event]);
if (event.cancelled)
return;
if (event.cancelled) return;
switch (curCharacter)
{
// hardcode custom dance animations here
default:
if (isDanceLeftDanceRight)
{
playAnim(((danced = !danced) ? 'danceLeft' : 'danceRight') + idleSuffix, DANCE);
}
else
playAnim('idle' + idleSuffix, DANCE);
}
if (isDanceLeftDanceRight)
playAnim(((danced = !danced) ? 'danceLeft' : 'danceRight') + idleSuffix, DANCE);
else
playAnim('idle' + idleSuffix, DANCE);
}
public function tryDance()
{
public function tryDance() {
switch (lastAnimContext) {
case SING | MISS:
if (lastHit + (Conductor.stepCrochet * holdTime) < Conductor.songPosition)
@@ -250,96 +151,61 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
* Whenever the character should dance on beat or not. Set to false for `gf`, since the dance animation is automatically handled by PlayState.
*/
public var danceOnBeat:Bool = true;
public override function beatHit(curBeat:Int) {
script.call("beatHit", [curBeat]);
if (danceOnBeat && (curBeat + beatOffset) % beatInterval == 0 && !__lockAnimThisFrame)
{
tryDance();
}
}
public override function stepHit(curStep:Int) {
public override function stepHit(curStep:Int)
script.call("stepHit", [curStep]);
// nothing
}
var __reverseDrawProcedure:Bool = false;
@:noCompletion var __reverseDrawProcedure:Bool = false;
public override function getScreenBounds(?newRect:FlxRect, ?camera:FlxCamera):FlxRect {
if (__reverseDrawProcedure)
{
if (__reverseDrawProcedure) {
scale.x *= -1;
var bounds = super.getScreenBounds(newRect, camera);
var bounds:FlxRect = super.getScreenBounds(newRect, camera);
scale.x *= -1;
return bounds;
}
return super.getScreenBounds(newRect, camera);
}
public function isFlippedOffsets() {
return (isPlayer != playerOffsets) != (flipX != __baseFlipped);
public override function isOnScreen(?camera:FlxCamera):Bool {
if (debugMode) return true;
return super.isOnScreen(camera);
}
var __drawingShadowFrame = false;
var __oldColorTransform = new ColorTransform();
public function isFlippedOffsets()
return (isPlayer != playerOffsets) != (flipX != __baseFlipped);
public override function draw() {
if (!__drawingShadowFrame && shadowFrame != null) {
__drawingShadowFrame = true;
var oldFrame = _frame;
var oldPos = FlxPoint.get(frameOffset.x, frameOffset.y);
__oldColorTransform.copyColorTransform(colorTransform);
colorTransform.alphaMultiplier = 1;
colorTransform.alphaOffset = 0;
colorTransform.blueMultiplier = 0;
colorTransform.blueOffset = 25;
colorTransform.greenMultiplier = 0;
colorTransform.greenOffset = 25;
colorTransform.redMultiplier = 0;
colorTransform.redOffset = 25;
_frame = shadowFrame.frame;
var o = getAnimOffset(shadowFrame.anim);
frameOffset.set(o.x, o.y);
super.draw();
_frame = oldFrame;
frameOffset.set(oldPos.x, oldPos.y);
colorTransform.copyColorTransform(__oldColorTransform);
oldPos.put();
__drawingShadowFrame = false;
}
if (isFlippedOffsets())
{
if (isFlippedOffsets()) {
__reverseDrawProcedure = true;
flipX = !flipX;
scale.x *= -1;
super.draw();
flipX = !flipX;
scale.x *= -1;
__reverseDrawProcedure = false;
}
else
super.draw();
} else super.draw();
}
public override function playAnim(AnimName:String, Force:Bool = false, Context:PlayAnimContext = NONE, Reversed:Bool = false, Frame:Int = 0):Void
{
public var singAnims = ["singLEFT", "singDOWN", "singUP", "singRIGHT"];
public function playSingAnim(direction:Int, suffix:String = "", Context:PlayAnimContext = SING, Force:Bool = true, Reversed:Bool = false, Frame:Int = 0) {
var event = EventManager.get(DirectionAnimEvent).recycle(singAnims[direction % singAnims.length] + suffix, direction, suffix, Context, Reversed, Frame, Force);
script.call("onPlaySingAnim", [event]);
if (!event.cancelled)
playAnim(event.animName, event.force, event.context, event.reversed, event.frame);
}
public override function playAnim(AnimName:String, Force:Bool = false, Context:PlayAnimContext = NONE, Reversed:Bool = false, Frame:Int = 0) {
var event = EventManager.get(PlayAnimEvent).recycle(AnimName, Force, Reversed, Frame, Context);
script.call("onPlayAnim", [event]);
if (event.cancelled)
return;
if (event.cancelled) return;
super.playAnim(event.animName, event.force, event.context, event.reverse, event.startingFrame);
@@ -348,50 +214,63 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
lastHit = Conductor.songPosition;
}
public override function destroy()
{
public inline function getCameraPosition() {
var midpoint:FlxPoint = getMidpoint();
var event = EventManager.get(PointEvent).recycle(
midpoint.x + (isPlayer ? -100 : 150) + globalOffset.x + cameraOffset.x,
midpoint.y - 100 + globalOffset.y + cameraOffset.y);
script.call("onGetCamPos", [event]);
midpoint.put();
return new FlxPoint(event.x, event.y);
}
public override function destroy() {
super.destroy();
cameraOffset.put();
globalOffset.put();
}
// FlxTrail Stuff for fixing position
@:noCompletion var __reverseTrailProcedure:Bool = false;
var __reverseTrailProcedure:Bool = false;
/**
* When using trails on characters you should do `trail.beforeCache = char.beforeTrailCache;`
**/
dynamic function beforeTrailCache() {
if (isFlippedOffsets())
{
// When using trails on characters you should do `trail.beforeCache = char.beforeTrailCache;`
public dynamic function beforeTrailCache()
if (isFlippedOffsets()) {
flipX = !flipX;
scale.x *= -1;
__reverseTrailProcedure = true;
}
}
/**
* When using trails on characters you should do `trail.afterCache = char.afterTrailCache;`
**/
dynamic function afterTrailCache() {
if (__reverseTrailProcedure)
{
// When using trails on characters you should do `trail.afterCache = char.afterTrailCache;`
public dynamic function afterTrailCache()
if (__reverseTrailProcedure) {
flipX = !flipX;
scale.x *= -1;
__reverseTrailProcedure = false;
}
public function applyXML(xml:Access) { // just for now till i remake the dumb editor
gameOverCharacter = Character.FALLBACK_DEAD_CHARACTER;
cameraOffset.set(0, 0);
globalOffset.set(0, 0);
playerOffsets = false;
flipX = false;
holdTime = 4;
iconColor = null;
animation.destroyAnimations();
animDatas.clear();
__baseFlipped = false;
buildCharacter(xml);
}
// Character editor and loading
public function applyXML(xml:Access) {
this.xml = xml; // modders wassup
public inline function buildCharacter(xml:Access) {
this.xml = xml; // Modders wassup :D
sprite = curCharacter;
if (xml.x.exists("isPlayer")) playerOffsets = (xml.x.get("isPlayer") == "true");
if (xml.x.exists("isGF")) isGF = (xml.x.get("isGF") == "true");
if (xml.x.exists("x")) globalOffset.x = Std.parseFloat(xml.x.get("x"));
if (xml.x.exists("y")) globalOffset.y = Std.parseFloat(xml.x.get("y"));
if (xml.x.exists("gameOverChar")) gameOverCharacter = xml.x.get("gameOverChar");
@@ -402,7 +281,7 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
if (xml.x.exists("icon")) icon = xml.x.get("icon");
if (xml.x.exists("color")) iconColor = FlxColor.fromString(xml.x.get("color"));
if (xml.x.exists("scale")) {
var scale = Std.parseFloat(xml.x.get("scale")).getDefault(1);
var scale:Float = Std.parseFloat(xml.x.get("scale")).getDefault(1);
this.scale.set(scale, scale);
updateHitbox();
}
@@ -412,46 +291,50 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
var hasInterval:Bool = xml.x.exists("interval");
if (hasInterval) beatInterval = Std.parseInt(xml.x.get("interval"));
var tempList = ["isPlayer", "isGF", "x", "y", "gameOverChar", "camx", "camy", "holdTime", "flipX", "icon", "color", "scale", "antialiasing", "sprite", "interval"];
var atts = xml.x.attributes();
for (i in atts)
if (!tempList.contains(i))
extra[i] = xml.x.get(i);
loadSprite(Paths.image('characters/$sprite'));
animation.destroyAnimations();
animDatas.clear();
for (anim in xml.nodes.anim)
{
XMLUtil.addXMLAnimation(this, anim);
}
for (attribute in xml.x.attributes())
if (!characterProperties.contains(attribute))
extra[attribute] = xml.x.get(attribute);
fixChar(true, !hasInterval);
dance();
}
public function buildXML(?animsOrder:Array<String>):Xml {
var xml = Xml.createElement("character");
xml.set("isPlayer", playerOffsets == true ? "true" : "false");
xml.set("isGF", isGF == true ? "true" : "false");
xml.set("x", Std.string(globalOffset.x));
xml.set("y", Std.string(globalOffset.y));
xml.set("gameOverChar", gameOverCharacter);
xml.set("camx", Std.string(cameraOffset.x));
xml.set("camy", Std.string(cameraOffset.y));
xml.set("holdTime", Std.string(holdTime));
xml.set("flipX", Std.string(flipX));
xml.set("icon", getIcon());
if (iconColor != null)
xml.set("color", iconColor.toWebString());
xml.set("scale", Std.string(scale.x));
xml.set("antialiasing", antialiasing == true ? "true" : "false");
xml.set("sprite", sprite);
public static var characterProperties:Array<String> = [
"x", "y", "sprite", "scale", "antialiasing",
"flipX", "camx", "camy", "isPlayer", "icon",
"color", "gameOverChar", "holdTime"
];
public static var characterAnimProperties:Array<String> = [
"name", "anim", "x", "y", "fps", "loop", "indices"
];
public inline function buildXML(?animsOrder:Array<String>):Xml {
var xml:Xml = Xml.createElement("character");
xml.attributeOrder = characterProperties.copy();
if (globalOffset.x != 0) xml.set("x", Std.string(FlxMath.roundDecimal(globalOffset.x, 2)));
if (globalOffset.y != 0) xml.set("y", Std.string(FlxMath.roundDecimal(globalOffset.y, 2)));
for (prop=>val in extra) {
xml.set(prop, Std.string(val));
}
if (cameraOffset.x != 0) xml.set("camx", Std.string(FlxMath.roundDecimal(cameraOffset.x, 2)));
if (cameraOffset.y != 0) xml.set("camy", Std.string(FlxMath.roundDecimal(cameraOffset.y, 2)));
if (holdTime != 4) xml.set("holdTime", Std.string(FlxMath.roundDecimal(holdTime, 4)));
if (flipX) xml.set("flipX", Std.string(flipX));
xml.set("icon", getIcon());
if (gameOverCharacter != Character.FALLBACK_DEAD_CHARACTER) xml.set("gameOverChar", gameOverCharacter);
if (iconColor != null) xml.set("color", iconColor.toWebString());
xml.set("sprite", sprite);
if (scale.x != 1) xml.set("scale", Std.string(FlxMath.roundDecimal(scale.x, 4)));
if (!antialiasing) xml.set("antialiasing", antialiasing == true ? "true" : "false");
if (playerOffsets) xml.set("isPlayer", playerOffsets == true ? "true" : "false");
var anims:Array<AnimData> = [];
if (animsOrder != null) {
@@ -460,22 +343,32 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
} else
anims = Lambda.array(animDatas);
for (anim in anims)
{
for (anim in anims) {
var animXml:Xml = Xml.createElement('anim');
animXml.attributeOrder = characterAnimProperties;
animXml.set("name", anim.name);
animXml.set("anim", anim.anim);
animXml.set("loop", Std.string(anim.loop));
animXml.set("fps", Std.string(anim.fps));
animXml.set("fps", Std.string(FlxMath.roundDecimal(anim.fps, 2)));
var offset:FlxPoint = getAnimOffset(anim.name);
animXml.set("x", Std.string(offset.x));
animXml.set("y", Std.string(offset.y));
animXml.set("x", Std.string(FlxMath.roundDecimal(offset.x, 2)));
animXml.set("y", Std.string(FlxMath.roundDecimal(offset.y, 2)));
offset.putWeak();
if (anim.indices.length > 0)
animXml.set("indices", anim.indices.join(","));
xml.addChild(animXml);
}
for (name => val in extra)
if (!xml.attributeOrder.contains(name)) {
xml.attributeOrder.push(name);
xml.set(name, Std.string(val));
}
this.xml = new Access(xml);
return xml;
}
@@ -483,74 +376,72 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
public inline function getIcon()
return (icon != null) ? icon : curCharacter;
public function getAnimOrder() {
public function getAnimOrder()
return [for(a in xml.nodes.anim) if(a.has.name) a.att.name];
}
// Getters / Setters
@:noCompletion private function set_stunned(b:Bool)
{
@:noCompletion private function set_stunned(b:Bool) {
__stunnedTime = 0;
return stunned = b;
}
// Backwards Compat
/**
* Interval at which the character will dance (higher number = slower dance)
*/
// Interval at which the character will dance (higher number = slower dance)
@:noCompletion public var danceInterval(get, set):Int;
@:noCompletion private function set_danceInterval(v:Int)
return beatInterval = v;
@:noCompletion private function get_danceInterval()
return beatInterval;
// Statics
public static function getIconFromCharName(?curCharacter:String) {
if(curCharacter == null) return "face";
var icon = curCharacter;
while(true) {
switch (curCharacter) {
// case 'your-char': // To hardcode characters icons
default:
// load xml
var xmlPath = Paths.xml('characters/$curCharacter');
if (!Assets.exists(xmlPath)) {
curCharacter = "bf";
continue;
}
public static var FALLBACK_CHARACTER:String = "bf";
public static var FALLBACK_DEAD_CHARACTER:String = "bf-dead";
public static function getXMLFromCharName(character:OneOfTwo<String, Character>):Access {
var char:Character = null;
if (character is Character) {
char = cast(character, Character);
character = char.curCharacter;
}
var xml = null;
var plainXML = Assets.getText(xmlPath);
try {
var charXML = Xml.parse(plainXML).firstElement();
if (charXML == null) throw new Exception("Missing \"character\" node in XML.");
xml = new Access(charXML);
} catch(e) {
Logs.trace('Error while loading character ${curCharacter}: ${e}', ERROR);
curCharacter = "bf";
continue;
}
var xml:Access = null;
while (true) {
var xmlPath:String = Paths.xml('characters/$character');
if (!Assets.exists(xmlPath)) {
character = FALLBACK_CHARACTER;
if (char != null)
char.curCharacter = character;
continue;
}
if (xml.x.exists("icon")) icon = xml.x.get("icon");
}
var plainXML:String = Assets.getText(xmlPath);
try {
var charXML:Xml = Xml.parse(plainXML).firstElement();
if (charXML == null) throw new Exception("Missing \"character\" node in XML.");
xml = new Access(charXML);
} catch (e) {
Logs.trace('Error while loading character ${character}: ${e}', ERROR);
character = FALLBACK_CHARACTER;
if (char != null)
char.curCharacter = character;
continue;
}
break;
}
return xml;
}
public static function getIconFromCharName(?character:String) {
if(character == null) return "face";
var icon:String = character;
var xml:Access = getXMLFromCharName(character);
if (xml != null && xml.x.exists("icon")) icon = xml.x.get("icon");
return icon;
}
public static function getList(?mods:Bool = false):Array<String> {
public static function getList(?mods:Bool = false):Array<String>
return [
for (path in Paths.getFolderContent('data/characters/', true, mods ? MODS : BOTH))
if (Path.extension(path) == "xml") CoolUtil.getFilename(path)
];
}
}
typedef CharacterShadowFrame =
{
var anim:String;
var frame:FlxFrame;
}
}
+6 -2
View File
@@ -36,12 +36,16 @@ class GameOverSubstate extends MusicBeatSubstate
public var lossSFX:FlxSound;
public function new(x:Float, y:Float, character:String = "bf-dead", player:Bool = true, gameOverSong:String = "gameOver", lossSFX:String = "gameOverSFX", retrySFX:String = "gameOverEnd")
public function new(x:Float, y:Float, character:String = null, player:Bool = true, gameOverSong:String = "gameOver", lossSFX:String = "gameOverSFX", retrySFX:String = "gameOverEnd")
{
super();
this.x = x;
this.y = y;
this.characterName = character;
characterName = character;
if (characterName == null)
characterName = Character.FALLBACK_DEAD_CHARACTER;
this.player = player;
this.gameOverSong = gameOverSong;
this.lossSFXName = lossSFX;
+1 -1
View File
@@ -1389,7 +1389,7 @@ class PlayState extends MusicBeatState
charToUse == null ? 0 : charToUse.x,
charToUse == null ? 0 : charToUse.y,
charToUse,
deathCharID.getDefault(charToUse != null ? charToUse.gameOverCharacter : "bf-dead"),
deathCharID.getDefault(charToUse != null ? charToUse.gameOverCharacter : Character.FALLBACK_DEAD_CHARACTER),
charToUse != null ? charToUse.isPlayer : true,
gameOverSong.getDefault(this.gameOverSong),
lossSFX.getDefault(this.lossSFX),
+137
View File
@@ -0,0 +1,137 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package haxe.xml;
using StringTools;
/**
This class provides utility methods to convert Xml instances to
String representation.
**/
class Printer {
/**
Convert `Xml` to string representation.
Set `pretty` to `true` to prettify the result.
**/
static public function print(xml:Xml, ?pretty = false) {
var printer = new Printer(pretty);
printer.writeNode(xml, "");
return printer.output.toString();
}
var output:StringBuf;
var pretty:Bool;
function new(pretty) {
output = new StringBuf();
this.pretty = pretty;
}
function writeNode(value:Xml, tabs:String) {
switch (value.nodeType) {
case CData:
write(tabs + "<![CDATA[");
write(value.nodeValue);
write("]]>");
newline();
case Comment:
var commentContent:String = value.nodeValue;
commentContent = ~/[\n\r\t]+/g.replace(commentContent, "");
commentContent = "<!--" + commentContent + "-->";
write(tabs);
write(StringTools.trim(commentContent));
newline();
case Document:
for (child in value) {
writeNode(child, tabs);
}
case Element:
write(tabs + "<");
write(value.nodeName);
var attributes:Array<String> = value.attributeOrder;
if (attributes == null)
attributes = [for (att in value.attributes()) att];
for (attribute in attributes) {
if (!value.exists(attribute) || value.get(attribute).trim() == "") continue;
write(" " + attribute + "=\"");
write(StringTools.htmlEscape(value.get(attribute), true));
write("\"");
}
if (hasChildren(value)) {
write(">");
newline();
for (child in value) {
writeNode(child, pretty ? tabs + "\t" : tabs);
}
write(tabs + "</");
write(value.nodeName);
write(">");
newline();
} else {
write("/>");
newline();
}
case PCData:
var nodeValue:String = value.nodeValue;
if (nodeValue.length != 0) {
write(tabs + StringTools.htmlEscape(nodeValue));
newline();
}
case ProcessingInstruction:
write("<?" + value.nodeValue + "?>");
newline();
case DocType:
write("<!DOCTYPE " + value.nodeValue + ">");
newline();
}
}
inline function write(input:String) {
output.add(input);
}
inline function newline() {
if (pretty) {
output.add("\n");
}
}
function hasChildren(value:Xml):Bool {
for (child in value) {
switch (child.nodeType) {
case Element, PCData:
return true;
case CData, Comment:
if (StringTools.ltrim(child.nodeValue).length != 0) {
return true;
}
case _:
}
}
return false;
}
}