Add Console window

This commit is contained in:
fgnm
2020-12-31 00:35:57 +01:00
parent 2005fb2430
commit 1df60bb697
14 changed files with 532 additions and 196 deletions
+2
View File
@@ -8,6 +8,8 @@
- Add `Resources` menu:
* Add Create Placeholder
* Add Create Perlin Noise textures
- Add `Console` to show debug logs
- Add hide GUI with F12 button
- Update HyperLap2D project version to 0.1.1
- Update libGDX to 1.9.13 (SNAPSHOT)
- Fixed some memory leaks and NPEs
Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

+203 -194
View File
File diff suppressed because it is too large Load Diff
+14 -1
View File
@@ -193,6 +193,11 @@
titleFont: big-font,
background: sticky-note,
titleFontColor: black
},
console: {
titleFont: big-font,
background: console-background,
titleFontColor: white
}
},
com.badlogic.gdx.scenes.scene2d.ui.ProgressBar$ProgressBarStyle: {
@@ -318,7 +323,15 @@
selection: selection,
background: textfield,
cursor: cursor
}
},
console: {
errorBorder: border-error,
font: default-mono-font,
fontColor: white,
disabledFontColor: white,
selection: selection,
cursor: cursor
},
},
com.kotcrab.vis.ui.widget.VisImageTextButton$VisImageTextButtonStyle: {
hierarchy-item-root: {
Binary file not shown.

Before

Width:  |  Height:  |  Size: 57 KiB

After

Width:  |  Height:  |  Size: 59 KiB

@@ -0,0 +1,138 @@
package games.rednblack.editor;
import games.rednblack.h2d.common.MsgAPI;
import org.puremvc.java.patterns.facade.Facade;
import java.io.OutputStream;
import java.io.PrintStream;
public class ConsoleInterceptor extends PrintStream {
private final Facade facade;
public ConsoleInterceptor(OutputStream out) {
super(out, true);
facade = HyperLap2DFacade.getInstance();
}
@Override
public void print(String s) {
super.print(s);
facade.sendNotification(MsgAPI.WRITE_TO_CONSOLE, s);
}
@Override
public void print(boolean b) {
super.print(b);
facade.sendNotification(MsgAPI.WRITE_TO_CONSOLE, String.valueOf(b));
}
@Override
public void print(int i) {
super.print(i);
facade.sendNotification(MsgAPI.WRITE_TO_CONSOLE, String.valueOf(i));
}
@Override
public void print(char c) {
super.print(c);
facade.sendNotification(MsgAPI.WRITE_TO_CONSOLE, String.valueOf(c));
}
@Override
public void print(long l) {
super.print(l);
facade.sendNotification(MsgAPI.WRITE_TO_CONSOLE, String.valueOf(l));
}
@Override
public void print(float f) {
super.print(f);
facade.sendNotification(MsgAPI.WRITE_TO_CONSOLE, String.valueOf(f));
}
@Override
public void print(char[] s) {
super.print(s);
facade.sendNotification(MsgAPI.WRITE_TO_CONSOLE, String.valueOf(s));
}
@Override
public void print(double d) {
super.print(d);
facade.sendNotification(MsgAPI.WRITE_TO_CONSOLE, String.valueOf(d));
}
@Override
public void print(Object obj) {
super.print(obj);
facade.sendNotification(MsgAPI.WRITE_TO_CONSOLE, String.valueOf(obj));
}
@Override
public void println() {
super.println();
facade.sendNotification(MsgAPI.WRITE_TO_CONSOLE, "\n");
}
@Override
public void println(String s) {
super.println(s);
facade.sendNotification(MsgAPI.WRITE_TO_CONSOLE, "\n");
}
@Override
public void println(int x) {
super.println(x);
facade.sendNotification(MsgAPI.WRITE_TO_CONSOLE, "\n");
}
@Override
public void println(char x) {
super.println(x);
facade.sendNotification(MsgAPI.WRITE_TO_CONSOLE, "\n");
}
@Override
public void println(long x) {
super.println(x);
facade.sendNotification(MsgAPI.WRITE_TO_CONSOLE, "\n");
}
@Override
public void println(float x) {
super.println(x);
facade.sendNotification(MsgAPI.WRITE_TO_CONSOLE, "\n");
}
@Override
public void println(char[] x) {
super.println(x);
facade.sendNotification(MsgAPI.WRITE_TO_CONSOLE, "\n");
}
@Override
public void println(double x) {
super.println(x);
facade.sendNotification(MsgAPI.WRITE_TO_CONSOLE, "\n");
}
@Override
public void println(Object x) {
super.println(x);
facade.sendNotification(MsgAPI.WRITE_TO_CONSOLE, "\n");
}
@Override
public void println(boolean x) {
super.println(x);
facade.sendNotification(MsgAPI.WRITE_TO_CONSOLE, "\n");
}
}
@@ -87,6 +87,7 @@ public class HyperLap2D implements IProxy, ApplicationListener, Lwjgl3WindowList
parameter.size = 14;
BitmapFont bigFont = generator.generateFont(parameter);
BitmapFont defaultMono = monoGenerator.generateFont(parameter);
defaultMono.getData().markupEnabled = true;
defaultMono.setFixedWidthGlyphs(parameter.characters);
generator.dispose();
@@ -187,6 +188,9 @@ public class HyperLap2D implements IProxy, ApplicationListener, Lwjgl3WindowList
@Override
public void onRegister() {
System.setErr(new ConsoleInterceptor(System.err));
System.setOut(new ConsoleInterceptor(System.out));
startup();
}
@@ -86,6 +86,7 @@ public class BootstrapViewCommand extends SimpleCommand {
facade.registerMediator(new NodeEditorDialogMediator());
facade.registerMediator(new CreatePlaceholderDialogMediator());
facade.registerMediator(new CreateNoiseDialogMediator());
facade.registerMediator(new ConsoleDialogMediator());
facade.registerMediator(new SaveProjectDialogMediator());
}
@@ -55,6 +55,7 @@ public class KeyBindingsLayout {
public static final int DELETE = 25;
public static final int HIDE_GUI = 26;
public static final int OPEN_CONSOLE = 27;
private static final ObjectMap<Integer, KeyMapper> defaultMapper = new ObjectMap<>();
static {
@@ -95,6 +96,7 @@ public class KeyBindingsLayout {
defaultMapper.put(DELETE, new KeyMapper(DELETE, false, false, false, Input.Keys.DEL));
defaultMapper.put(HIDE_GUI, new KeyMapper(HIDE_GUI, false, false, false, Input.Keys.F12));
defaultMapper.put(OPEN_CONSOLE, new KeyMapper(OPEN_CONSOLE, false, false, false, Input.Keys.F11));
}
private static final Array<KeyMapper> mapping = new Array<>();
@@ -208,6 +208,9 @@ public class HyperLap2DScreen implements Screen, InputProcessor {
case KeyBindingsLayout.HIDE_GUI:
uiStage.addAction(Actions.fadeOut(0.1f));
break;
case KeyBindingsLayout.OPEN_CONSOLE:
facade.sendNotification(MsgAPI.OPEN_CONSOLE);
break;
}
return false;
}
@@ -5,6 +5,8 @@ import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.kotcrab.vis.ui.widget.MenuItem;
import games.rednblack.editor.event.MenuItemListener;
import games.rednblack.editor.utils.KeyBindingsLayout;
import games.rednblack.h2d.common.MsgAPI;
import static games.rednblack.h2d.common.MenuAPI.HELP_MENU;
@@ -22,6 +24,11 @@ public class HelpMenu extends H2DMenu {
});
addItem(docs);
MenuItem console = new MenuItem("Console", new MenuItemListener(MsgAPI.OPEN_CONSOLE, null, HELP_MENU))
.setShortcut(KeyBindingsLayout.getShortcutList(KeyBindingsLayout.OPEN_CONSOLE));
addItem(console);
addSeparator();
MenuItem about = new MenuItem("About", new MenuItemListener(ABOUT_DIALOG_OPEN, null, HELP_MENU));
addItem(about);
}
@@ -0,0 +1,107 @@
package games.rednblack.editor.view.ui.dialog;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.kotcrab.vis.ui.widget.*;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.view.stage.Sandbox;
import games.rednblack.h2d.common.view.ui.Cursors;
import games.rednblack.h2d.common.view.ui.listener.CursorListener;
import games.rednblack.h2d.common.view.ui.listener.ScrollFocusListener;
public class ConsoleDialog extends VisDialog {
private final HighlightTextArea textArea;
public ConsoleDialog() {
super("Console", "console");
setModal(false);
addCloseButton();
this.getTitleTable().padTop(-15);
textArea = new HighlightTextArea("", "console") {
@Override
protected InputListener createInputListener() {
return new TextAreaListener() {
@Override
public boolean keyDown(InputEvent event, int keycode) {
if (keycode == Input.Keys.V)
return true;
return super.keyDown(event, keycode);
}
@Override
public boolean keyTyped(InputEvent event, char character) {
return false;
}
@Override
public boolean keyUp(InputEvent event, int keycode) {
if (keycode == Input.Keys.V)
return true;
return super.keyUp(event, keycode);
}
};
}
@Override
public void draw(Batch batch, float parentAlpha) {
try {
super.draw(batch, parentAlpha);
} catch (Exception ignore) {
//Ignore any exception that may occurs while drawing this
}
}
};
ScrollPane scrollPane = textArea.createCompatibleScrollPane();
scrollPane.addListener(new ScrollFocusListener());
textArea.addListener(new CursorListener(Cursors.TEXT, HyperLap2DFacade.getInstance()));
getContentTable().add(scrollPane).padTop(20).grow().row();
}
@Override
public void addCloseButton() {
VisImageButton closeButton = new VisImageButton("close-window");
this.getTitleTable().add(closeButton).padRight(0).padTop(40);
closeButton.addListener(new ChangeListener() {
@Override
public void changed (ChangeEvent event, Actor actor) {
close();
}
});
closeButton.addListener(new ClickListener() {
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
event.cancel();
return true;
}
});
}
@Override
public void close() {
super.close();
}
public void write(String s) {
if (s.contains("\t"))
s = s.replace("\t", " ");
textArea.appendText(s);
}
@Override
public float getPrefWidth() {
return Sandbox.getInstance().getUIStage().getWidth() * 0.7f;
}
@Override
public float getPrefHeight() {
return Sandbox.getInstance().getUIStage().getHeight() * 0.8f;
}
}
@@ -0,0 +1,50 @@
package games.rednblack.editor.view.ui.dialog;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.view.stage.Sandbox;
import games.rednblack.editor.view.stage.UIStage;
import games.rednblack.h2d.common.MsgAPI;
import org.puremvc.java.interfaces.INotification;
import org.puremvc.java.patterns.mediator.Mediator;
public class ConsoleDialogMediator extends Mediator<ConsoleDialog> {
private static final String TAG = ConsoleDialogMediator.class.getCanonicalName();
private static final String NAME = TAG;
public ConsoleDialogMediator() {
super(NAME, new ConsoleDialog());
}
@Override
public void onRegister() {
super.onRegister();
facade = HyperLap2DFacade.getInstance();
}
@Override
public String[] listNotificationInterests() {
return new String[]{
MsgAPI.OPEN_CONSOLE,
MsgAPI.WRITE_TO_CONSOLE
};
}
@Override
public void handleNotification(INotification notification) {
Sandbox sandbox = Sandbox.getInstance();
UIStage uiStage = sandbox.getUIStage();
switch (notification.getName()) {
case MsgAPI.OPEN_CONSOLE:
if (!viewComponent.hasParent())
viewComponent.show(uiStage);
else
viewComponent.close();
break;
case MsgAPI.WRITE_TO_CONSOLE:
viewComponent.write(notification.getBody());
break;
}
}
}