SOME CODE
This commit is contained in:
@@ -20,17 +20,16 @@ class EditNoteTypesList extends UISubstateWindow {
|
||||
super.create();
|
||||
|
||||
var title:UIText;
|
||||
add(title = new UIText(windowSpr.x + 25, windowSpr.y + 15 + 16, 0, "Edit Note Types List", 28));
|
||||
add(title = new UIText(windowSpr.x + 20, windowSpr.y + 30 + 16, 0, "Edit Note Types", 28));
|
||||
|
||||
var noteTypesFileList = getNoteTypesList(true);
|
||||
if (noteTypesFileList.length == 0) noteTypesFileList = getNoteTypesList(false);
|
||||
var list:Array<String> = Charter.instance.noteTypes;
|
||||
|
||||
noteTypesList = new UIButtonList<NoteTypeButton>(15, title.y + title.height + 10, winWidth - 35, 260, "", FlxPoint.get(winWidth - 35, 60), null, 0);
|
||||
noteTypesList.addButton.callback = () -> noteTypesList.add(new NoteTypeButton(0, 0, "New Note Type", noteTypesFileList, noteTypesList));
|
||||
noteTypesList.cameraSpacing = 0;
|
||||
for (i in list)
|
||||
noteTypesList.add(new NoteTypeButton(0, 0, i, noteTypesFileList, noteTypesList));
|
||||
noteTypesList = new UIButtonList<NoteTypeButton>(20, title.y + title.height + 10, winWidth - 40, 342 - 85 - 16, "", FlxPoint.get(winWidth - 40, (342 - 85 - 16)/4), null, 0);
|
||||
noteTypesList.addButton.callback = () -> noteTypesList.add(new NoteTypeButton(0, 0, 'Note Type ${noteTypesList.buttons.members.length}', noteTypesList.buttons.members.length, noteTypesFileList, noteTypesList));
|
||||
noteTypesList.cameraSpacing = 0; noteTypesList.dragCallback = (object:NoteTypeButton, oldIndex:Int, newIndex:Int) -> {object.IDText.text = '${newIndex}.';};
|
||||
for (i=>noteType in Charter.instance.noteTypes)
|
||||
noteTypesList.add(new NoteTypeButton(0, 0, noteType, i, noteTypesFileList, noteTypesList));
|
||||
add(noteTypesList);
|
||||
noteTypesList.frames = Paths.getFrames('editors/ui/inputbox');
|
||||
|
||||
@@ -62,32 +61,37 @@ class EditNoteTypesList extends UISubstateWindow {
|
||||
{
|
||||
var oldList:Array<String> = Charter.instance.noteTypes;
|
||||
var newList:Array<String> = [for (note in noteTypesList.buttons.members) note.textBox.label.text];
|
||||
|
||||
Charter.instance.noteTypes = newList;
|
||||
Charter.instance.changeNoteType(null, false);
|
||||
|
||||
Charter.instance.undos.addToUndo(CEditNoteTypes(oldList, newList));
|
||||
}
|
||||
}
|
||||
|
||||
class NoteTypeButton extends UIButton {
|
||||
public var IDText:UIText;
|
||||
public var noteSpr:FlxSprite;
|
||||
public var textBox:UIAutoCompleteTextBox;
|
||||
public var deleteButton:UIButton;
|
||||
public var deleteIcon:FlxSprite;
|
||||
public var list:Array<String>;
|
||||
|
||||
public function new(x:Float, y:Float, name:String, list:Array<String>, parent:UIButtonList<NoteTypeButton>) {
|
||||
public function new(x:Float, y:Float, name:String, noteID:Int, suggestList:Array<String>, parent:UIButtonList<NoteTypeButton>) {
|
||||
super(x, y, '', null, Std.int(parent.buttonSize.x), Std.int(parent.buttonSize.y));
|
||||
autoAlpha = false;
|
||||
|
||||
members.push(textBox = new UIAutoCompleteTextBox(5, bHeight/2 - 40, name, 250));
|
||||
textBox.suggestItems = [for(script in (this.list = list)) Path.withoutExtension(script)];
|
||||
members.push(IDText = new UIText(10, 10, 0, '${noteID}.'));
|
||||
|
||||
updateNote(name);
|
||||
|
||||
members.push(textBox = new UIAutoCompleteTextBox(IDText.x + 10, 10, name, 200-4));
|
||||
textBox.suggestItems = [for(script in (suggestList)) Path.withoutExtension(script)];
|
||||
textBox.onChange = function(noteType:String) {
|
||||
updateNote(noteType);
|
||||
};
|
||||
textBox.antialiasing = true;
|
||||
|
||||
field.alignment = LEFT;
|
||||
field.x = textBox.x;
|
||||
field.y = textBox.y + textBox.height + 30;
|
||||
field.height = 9;
|
||||
|
||||
deleteButton = new UIButton(textBox.x + textBox.label.width + 10, textBox.y - 8, "", function () {
|
||||
deleteButton = new UIButton(textBox.x + textBox.label.width + 10, textBox.y, "", function () {
|
||||
parent.remove(this);
|
||||
}, 32);
|
||||
deleteButton.color = 0xFFFF0000;
|
||||
@@ -99,27 +103,31 @@ class NoteTypeButton extends UIButton {
|
||||
members.push(deleteIcon);
|
||||
}
|
||||
|
||||
private var lastName:String = null;
|
||||
override function update(elapsed) {
|
||||
deleteButton.y = y + bHeight / 2 - deleteButton.bHeight / 2 - 8;
|
||||
textBox.y = y + bHeight/2 - 20;
|
||||
public function updateNote(notetype:String) {
|
||||
if (noteSpr == null) members.push(noteSpr = new FlxSprite());
|
||||
|
||||
var path:String = 'game/notes/default';
|
||||
if (Assets.exists(Paths.image('game/notes/${notetype}')))
|
||||
path = 'game/notes/${notetype}';
|
||||
|
||||
noteSpr.frames = Paths.getFrames(path);
|
||||
noteSpr.animation.addByPrefix('scroll', 'green0');
|
||||
noteSpr.animation.play("scroll");
|
||||
noteSpr.updateHitbox(); /*noteSpr.angle = 20;*/
|
||||
noteSpr.setGraphicSize(34, 34);
|
||||
noteSpr.updateHitbox(); noteSpr.antialiasing = true;
|
||||
}
|
||||
|
||||
override function update(elapsed:Float) {
|
||||
IDText.x = x + 12; IDText.y = (y + bHeight/2) - (IDText.height/2);
|
||||
noteSpr.x = IDText.x + IDText.width + 2; noteSpr.y = (y + bHeight/2) - (noteSpr.height/2);
|
||||
textBox.x = noteSpr.x + noteSpr.width + 12; textBox.y = (y + bHeight/2) - (textBox.bHeight/2);
|
||||
deleteButton.x = textBox.x + textBox.bWidth + 14; deleteButton.y = textBox.y;
|
||||
deleteIcon.x = deleteButton.x + (15/2); deleteIcon.y = deleteButton.y + 8;
|
||||
|
||||
deleteButton.selectable = selectable;
|
||||
deleteButton.shouldPress = shouldPress;
|
||||
|
||||
super.update(elapsed);
|
||||
field.follow(this, textBox.x, textBox.x + textBox.height + 30);
|
||||
if(lastName != textBox.label.text) {
|
||||
lastName = textBox.label.text;
|
||||
|
||||
var toUse:String = 'Path: ${EditNoteTypesList.pathString}$lastName.';
|
||||
for(name in list) if(Path.withoutExtension(name) == lastName) {
|
||||
toUse += Path.extension(name);
|
||||
break;
|
||||
}
|
||||
if(Path.extension(toUse) == "") toUse += '?';
|
||||
field.text = toUse;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ class UIButtonList<T:UIButton> extends UIWindow {
|
||||
public var buttonOffset:FlxPoint = FlxPoint.get();
|
||||
|
||||
public var dragging:Bool = false;
|
||||
public var dragCallback:(T,Int,Int)->Void;
|
||||
|
||||
var curMoving:T = null;
|
||||
var curMovingInterval:Float = 0;
|
||||
@@ -50,13 +51,14 @@ class UIButtonList<T:UIButton> extends UIWindow {
|
||||
}
|
||||
|
||||
public inline function add(button:T) {
|
||||
button.ID = buttons.members.length-1;
|
||||
buttons.add(button);
|
||||
curMovingInterval = 0;
|
||||
nextscrollY += button.bHeight;
|
||||
}
|
||||
|
||||
|
||||
public inline function insert(button:T, position:Int) {
|
||||
button.ID = position;
|
||||
buttons.insert(position, button);
|
||||
nextscrollY += button.bHeight;
|
||||
}
|
||||
@@ -114,9 +116,15 @@ class UIButtonList<T:UIButton> extends UIWindow {
|
||||
|
||||
buttonCameras.scroll.y = nextscrollY;
|
||||
|
||||
for (button in buttons) {
|
||||
if (button != null) button.selectable = button.shouldPress = (hovered && !dragging);
|
||||
for (i => button in buttons.members) {
|
||||
if (button == null) continue;
|
||||
button.selectable = button.shouldPress = (hovered && !dragging);
|
||||
button.cameras = [buttonCameras];
|
||||
if (button.ID != i) {
|
||||
if (dragCallback != null) dragCallback(cast button, button.ID, i);
|
||||
button.ID = i; // Ok back to normal :D
|
||||
}
|
||||
|
||||
}
|
||||
addButton.selectable = (hovered && !dragging);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user