From fd95c9d2e493104ce6280cf653133ee9aafef2d4 Mon Sep 17 00:00:00 2001 From: fgnm Date: Thu, 12 Oct 2023 12:18:50 +0200 Subject: [PATCH] [editor only] Fix double sticky notes and more intelligent save command --- .../editor/controller/BootstrapCommand.java | 1 - .../ui/widget/actors/StickyNoteActor.java | 28 ++++++++++++++----- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/main/java/games/rednblack/editor/controller/BootstrapCommand.java b/src/main/java/games/rednblack/editor/controller/BootstrapCommand.java index b64867ff..0b21747a 100644 --- a/src/main/java/games/rednblack/editor/controller/BootstrapCommand.java +++ b/src/main/java/games/rednblack/editor/controller/BootstrapCommand.java @@ -45,7 +45,6 @@ public class BootstrapCommand extends SimpleCommand { facade.registerCommand(MsgAPI.ACTION_CAMERA_CHANGE_COMPOSITE, CompositeCameraChangeCommand.class); facade.registerCommand(MsgAPI.ACTION_CREATE_PRIMITIVE, CreatePrimitiveCommand.class); facade.registerCommand(MsgAPI.ACTION_CREATE_STICKY_NOTE, CreateStickyNoteCommand.class); - facade.registerCommand(MsgAPI.ACTION_CREATE_STICKY_NOTE, CreateStickyNoteCommand.class); facade.registerCommand(MsgAPI.ACTION_REMOVE_STICKY_NOTE, RemoveStickyNoteCommand.class); facade.registerCommand(MsgAPI.ACTION_MODIFY_STICKY_NOTE, ModifyStickyNoteCommand.class); diff --git a/src/main/java/games/rednblack/editor/view/ui/widget/actors/StickyNoteActor.java b/src/main/java/games/rednblack/editor/view/ui/widget/actors/StickyNoteActor.java index de2e9fe0..2f3310b1 100644 --- a/src/main/java/games/rednblack/editor/view/ui/widget/actors/StickyNoteActor.java +++ b/src/main/java/games/rednblack/editor/view/ui/widget/actors/StickyNoteActor.java @@ -5,13 +5,12 @@ import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.math.Interpolation; import com.badlogic.gdx.math.Vector2; -import com.badlogic.gdx.scenes.scene2d.Action; -import com.badlogic.gdx.scenes.scene2d.Group; -import com.badlogic.gdx.scenes.scene2d.InputEvent; -import com.badlogic.gdx.scenes.scene2d.InputListener; +import com.badlogic.gdx.scenes.scene2d.*; import com.badlogic.gdx.scenes.scene2d.actions.Actions; +import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.utils.Align; +import com.badlogic.gdx.utils.Timer; import com.kotcrab.vis.ui.widget.MenuItem; import com.kotcrab.vis.ui.widget.VisImage; import com.kotcrab.vis.ui.widget.VisTextArea; @@ -71,10 +70,25 @@ public class StickyNoteActor extends VisWindow { } } }); + contentArea.addListener(new ChangeListener() { + @Override + public void changed(ChangeEvent event, Actor actor) { + saveTask.cancel(); + Timer.schedule(saveTask, 1); + } + }); add(contentArea).padTop(5).padLeft(5).grow(); setOrigin(Align.topLeft); } + Timer.Task saveTask = new Timer.Task() { + @Override + public void run() { + StickyNoteVO payload = ModifyStickyNoteCommand.payload(StickyNoteActor.this); + facade.sendNotification(MsgAPI.ACTION_MODIFY_STICKY_NOTE, payload); + } + }; + @Override public void close() { Action action = Actions.parallel(Actions.rotateBy(-35, .25f, Interpolation.swingIn), @@ -316,15 +330,15 @@ public class StickyNoteActor extends VisWindow { private void showPopupMenu() { H2DPopupMenu popupMenu = new H2DPopupMenu(); - MenuItem rename = new MenuItem("Remove note"); - rename.addListener( + MenuItem remove = new MenuItem("Remove note"); + remove.addListener( new ClickListener(Input.Buttons.LEFT) { @Override public void clicked(InputEvent event, float x, float y) { facade.sendNotification(MsgAPI.ACTION_REMOVE_STICKY_NOTE, id); } }); - popupMenu.addItem(rename); + popupMenu.addItem(remove); MenuItem changeColor = new MenuItem("Change color"); changeColor.addListener( new ClickListener(Input.Buttons.LEFT) {