new strumline screen

This commit is contained in:
Frakist
2023-07-30 16:16:58 +03:00
parent dc45c64706
commit 06d9a63e72
2 changed files with 84 additions and 52 deletions
@@ -10,7 +10,7 @@ class CharterStrumlineScreen extends UISubstateWindow {
public var strumLineID:Int = -1;
public var strumLine:ChartStrumLine;
public var charactersTextBox:UITextBox;
public var charactersList:UIButtonList;
public var typeDropdown:UIDropDown;
public var stagePositionDropdown:UIDropDown;
public var hudScaleStepper:UINumericStepper;
@@ -45,7 +45,7 @@ class CharterStrumlineScreen extends UISubstateWindow {
visible: true
};
winTitle = creatingStrumLine ? 'Creating Strumline #$strumLineID' : 'Strumline #$strumLineID properties';
winTitle = creatingStrumLine ? 'Creating strumline #$strumLineID' : 'Editting strumline #$strumLineID properties';
winWidth = 690; winHeight = 390;
FlxG.sound.music.pause();
@@ -56,23 +56,18 @@ class CharterStrumlineScreen extends UISubstateWindow {
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, creatingStrumLine ? "Create New Strumline" : "Edit Strumline Properties", 28));
charactersList = new UIButtonList(15, 43, 250, 330, "", () -> charactersList.add(new CharacterButton(0,0,"New Char", charactersList)), 2, 2);
for (i in strumLine.characters) charactersList.add(new CharacterButton(0,0,i, charactersList));
charactersList.cameraSpacing = 2;
add(charactersList);
charactersTextBox = new UITextBox(title.x, title.y + title.height + 38, strumLine.characters.join(", "));
charactersTextBox.onChange = (newChars:String) -> {
updateCharacterIcons([for (char in newChars.split(",")) char.trim()]);
};
add(charactersTextBox);
addLabelOn(charactersTextBox, "Characters");
charactersList.frames = Paths.getFrames('editors/ui/inputbox');
updateCharacterIcons(strumLine.characters);
typeDropdown = new UIDropDown(charactersTextBox.x, charactersTextBox.y + 32 + 58, 200, 32, ["OPPONENT", "PLAYER", "ADDITIONAL"], strumLine.type);
typeDropdown = new UIDropDown(charactersList.x + 265, charactersList.y + 20, 200, 32, ["OPPONENT", "PLAYER", "ADDITIONAL"], strumLine.type);
add(typeDropdown);
addLabelOn(typeDropdown, "Type");
usesChartscrollSpeed = new UICheckbox(typeDropdown.x + 200 - 32 + 26, typeDropdown.y + 32 + 58, "Uses charts scroll speed?", strumLine.scrollSpeed == null);
usesChartscrollSpeed = new UICheckbox(typeDropdown.x + 104, typeDropdown.y + 130, "Uses charts scroll speed?", strumLine.scrollSpeed == null);
usesChartscrollSpeed.onChecked = function(b) {
if(b)
{
@@ -84,7 +79,7 @@ class CharterStrumlineScreen extends UISubstateWindow {
}
add(usesChartscrollSpeed);
scrollSpeedStepper = new UINumericStepper(typeDropdown.x, typeDropdown.y + 32 + 58, usesChartscrollSpeed.checked ? PlayState.SONG.scrollSpeed : strumLine.scrollSpeed, 0.1, 2, 0, 10, 82);
scrollSpeedStepper = new UINumericStepper(typeDropdown.x, typeDropdown.y + 128, usesChartscrollSpeed.checked ? PlayState.SONG.scrollSpeed : strumLine.scrollSpeed, 0.1, 2, 0, 10, 82);
if(usesChartscrollSpeed.checked)
{
scrollSpeedStepper.selectable = false;
@@ -100,7 +95,7 @@ class CharterStrumlineScreen extends UISubstateWindow {
add(stagePositionDropdown);
addLabelOn(stagePositionDropdown, "Stage Position");
hudScaleStepper = new UINumericStepper(stagePositionDropdown.x + 200 - 32 + 26, stagePositionDropdown.y, strumLine.strumScale == null ? 1 : strumLine.strumScale, 0.001, 2, null, null, 74);
hudScaleStepper = new UINumericStepper(typeDropdown.x, typeDropdown.y + 64, strumLine.strumScale == null ? 1 : strumLine.strumScale, 0.001, 2, null, null, 74);
add(hudScaleStepper);
addLabelOn(hudScaleStepper, "Scale");
@@ -133,34 +128,16 @@ class CharterStrumlineScreen extends UISubstateWindow {
closeButton.x -= closeButton.bWidth;
}
function updateCharacterIcons(characters:Array<String>) {
for (icon in characterIcons) {
remove(icon);
icon.destroy();
}
characterIcons = [];
for (i => char in characters) {
var iconSprite = new HealthIcon(Character.getIconFromCharName(char));
iconSprite.scrollFactor.set(1,1);
iconSprite.scale.set(0.5, 0.5);
iconSprite.updateHitbox();
iconSprite.setPosition(
charactersTextBox.x + 320 + 8 + ((iconSprite.width + 4) * i),
(charactersTextBox.y + 16) - (iconSprite.height/2)
);
add(iconSprite);
characterIcons.push(iconSprite);
}
}
function saveStrumline() {
for (stepper in [hudXStepper, hudYStepper, hudScaleStepper])
@:privateAccess stepper.__onChange(stepper.label.text);
strumLine = {
characters: [for (char in charactersTextBox.label.text.split(",")) char.trim()],
characters: [for (char in charactersList.buttons.members)
if(char is CharacterButton) {
var char:CharacterButton = cast char;
char.textBox.label.text.trim();
}],
type: typeDropdown.index,
notes: strumLine.notes,
position: ["DAD", "BOYFRIEND", "GIRLFRIEND"][stagePositionDropdown.index].toLowerCase(),
@@ -171,4 +148,39 @@ class CharterStrumlineScreen extends UISubstateWindow {
if(!usesChartscrollSpeed.checked) strumLine.scrollSpeed = scrollSpeedStepper.value;
if (onSave != null) onSave(strumLine);
}
}
class CharacterButton extends UIButton {
public var charIcon:HealthIcon;
public var textBox:UITextBox;
public var deleteButton:UIButton;
public var deleteIcon:FlxSprite;
public function new(x:Float, y:Float, char:String, parent:UIButtonList) {
charIcon = new HealthIcon(char);
charIcon.scale.set(0.5, 0.5);
charIcon.updateHitbox();
super(x, y, "", null, 246, Math.floor(charIcon.height));
charIcon.setPosition(x + 10, bHeight/2 - charIcon.height / 2);
members.push(charIcon);
members.remove(field);
members.push(textBox = new UITextBox(95, bHeight/2 - 16, char, 100));
textBox.onChange = function(char:String) {
charIcon.loadGraphic(Assets.exists(Paths.image("icons/" + char)) ? Paths.image("icons/" + char) : Paths.image("icons/face"), true, 150, 150);
charIcon.updateHitbox();
}
deleteButton = new UIButton(textBox.x + 105, y, "", function () {
parent.remove(this);
}, 32);
deleteButton.color = 0xFFFF0000;
members.push(deleteButton);
deleteIcon = new FlxSprite(deleteButton.x + (15/2), deleteButton.y + 8).loadGraphic(Paths.image('editors/character/delete-button'));
deleteIcon.antialiasing = false;
members.push(deleteIcon);
}
override function update(elapsed) {
charIcon.y = y + bHeight / 2 - charIcon.height / 2;
deleteButton.y = y + bHeight / 2 - deleteButton.bHeight / 2;
textBox.y = y + bHeight/2 - 16;
deleteIcon.x = deleteButton.x + (15/2); deleteIcon.y = deleteButton.y + 8;
super.update(elapsed);
}
}
+33 -13
View File
@@ -13,32 +13,36 @@ class UIButtonList extends UIWindow {
public var addButton:UIButton;
public var addIcon:FlxSprite;
public var buttonCameras:FlxCamera;
public var cameraSpacing = 36;
var _buttonXOffset:Float = 16;
var _buttonYOffset:Float = 16;
public function new(x:Int, y:Int, width:Int, height:Int, windowName:String, addButtonCallback:Void->Void = null, buttonYOffset = 16) {
public function new(x:Int, y:Int, width:Int, height:Int, windowName:String, addButtonCallback:Void->Void = null, buttonXOffset:Float = 16, buttonYOffset:Float = 16) {
super(x, y, width, height, windowName);
members.push(buttons);
_buttonXOffset = buttonXOffset;
_buttonYOffset = buttonYOffset;
buttonCameras = new FlxCamera(x, y+36, width, height-38);
buttonCameras = new FlxCamera(x, y+cameraSpacing, width, height-cameraSpacing);
FlxG.cameras.add(buttonCameras, false);
buttonCameras.bgColor = 0;
addButton = new UIButton(25, 16, "", addButtonCallback != null ? addButtonCallback : function() return false, 426);
addButton = new UIButton(25, 16, "", addButtonCallback != null ? addButtonCallback : function() return false, Math.floor(bWidth - buttonXOffset * 2));
addButton.color = 0xFF00FF00;
addIcon = new FlxSprite(addButton.x + (440/2) - 8, addButton.y + (32/2) - 8).loadGraphic(Paths.image('editors/charter/add-button'));
addIcon = new FlxSprite(addButton.x + addButton.bHeight / 2, addButton.y + (32/2) - 8).loadGraphic(Paths.image('editors/charter/add-button'));
addIcon.antialiasing = false;
addButton.members.push(addIcon);
add(addButton);
}
public function add(button:UIButton)
insert(button, buttons.members.length);
insert(button, Math.floor(Math.max(buttons.members.indexOf(addButton), 0)));
public function insert(button:UIButton, position:Int) {
buttons.insert(position, button);
button.cameras = [buttonCameras];
for (i => button in buttons.members)
button.setPosition(16, -scrollY + (button.bHeight + _buttonYOffset) * i);
button.x = _buttonXOffset;
if (addButton.bHeight != button.bHeight) addButton.bHeight = button.bHeight;
scrollY += button.bHeight;
}
public function remove(button:UIButton) {
buttons.remove(button, true);
@@ -49,7 +53,12 @@ class UIButtonList extends UIWindow {
public function updateButtonsPos(elapsed:Float) {
for (i => button in buttons.members) {
if (_curMoving != button) {
button.y = CoolUtil.fpsLerp(button.y, -scrollY + (button.bHeight + _buttonYOffset) * i, 0.1);
for (i in button.members)
if (i is UIButton) {
var i:UIButton = cast(i, UIButton);
i.selectable = true;
}
button.y = CoolUtil.fpsLerp(button.y, -scrollY + ((buttons.members[i-1] != null ? buttons.members[i-1].bHeight : 0) + _buttonYOffset) * i, 0.1);
button.shouldPress = true;
}
if (button != addButton && button.hovered && FlxG.mouse.justPressed) _curMoving = button;
@@ -57,17 +66,17 @@ class UIButtonList extends UIWindow {
if (_curMoving != null) {
_curMovingInterval += FlxG.mouse.deltaY;
if (Math.abs(_curMovingInterval) > addButton.bHeight / 2) {
_curMovingInterval += 100;
_curMovingInterval = 999;
_curMoving.shouldPress = false;
_curMoving.y = CoolUtil.fpsLerp(_curMoving.y, FlxG.mouse.getScreenPosition(buttonCameras).y - (_curMoving.bHeight / 2), 0.2);
buttons.sort(function(o,a,b) return flixel.util.FlxSort.byValues(o, a == addButton ? 999 : a.y + 40, b == addButton ? 999 : b.y + 40), -1);
buttons.sort(function(o,a,b) return flixel.util.FlxSort.byValues(o, a == addButton ? 999 : a.y + (a.bHeight / 2), b == addButton ? 999 : b.y + (a.bHeight / 2)), -1);
}
if (FlxG.mouse.justReleased) {
_curMoving = null;
_curMovingInterval = 0;
}
}
addIcon.x = addButton.x + (220) - 8; addIcon.y = addButton.y + (16) - 8;
addIcon.x = addButton.x + addButton.bWidth / 2 - addIcon.width / 2; addIcon.y = addButton.y + addButton.bHeight / 2 - addIcon.height / 2;
}
var scrollY:Float = 0;
@@ -79,12 +88,23 @@ class UIButtonList extends UIWindow {
__rect.width = bWidth; __rect.height = bHeight-23;
var nextscrollY = scrollY - ((hovered = UIState.state.isOverlapping(this, __rect)) ? FlxG.mouse.wheel : 0) * 12;
if (_curMoving != null) {
for (i in _curMoving.members)
if (i is UIButton) {
var i:UIButton = cast(i, UIButton);
i.selectable = false;
}
nextscrollY -= Math.min((bHeight - 100) - FlxG.mouse.getScreenPosition(buttonCameras).y, 0) / 5;
nextscrollY += Math.min(FlxG.mouse.getScreenPosition(buttonCameras).y - 100, 0) / 5;
}
scrollY = FlxMath.bound(nextscrollY, 0, -16 + Math.abs(Math.min(bHeight - (addButton.bHeight + _buttonYOffset) * (buttons.members.length+1), 0)));
scrollY = FlxMath.bound(nextscrollY, 0, -_buttonYOffset + Math.abs(Math.min(bHeight - ((addButton.bHeight + _buttonYOffset) * buttons.members.length + (cameraSpacing + _buttonYOffset)), 0)));
for (button in buttons.members)
if (button != null) button.selectable = (hovered && button.callback != null);
if (button != null) button.selectable = (hovered);
addButton.selectable = hovered;
if (__lastDrawCameras[0] != null) {
buttonCameras.height = bHeight - cameraSpacing;
buttonCameras.x = x - __lastDrawCameras[0].scroll.x;
buttonCameras.y = y + cameraSpacing - __lastDrawCameras[0].scroll.y;
buttonCameras.zoom = __lastDrawCameras[0].zoom;
}
}
}