[editor only] Fix some focus issues

This commit is contained in:
fgnm
2021-05-04 17:54:41 +02:00
parent f92048e3a4
commit f1dfe98b27
6 changed files with 44 additions and 24 deletions
@@ -32,19 +32,26 @@ import games.rednblack.editor.HyperLap2DFacade;
public class KeyboardListener implements EventListener {
private final String eventName;
private final boolean handleFocus;
private String lastValue;
public KeyboardListener(String eventName) {
this(eventName, true);
}
public KeyboardListener(String eventName, boolean focus) {
this.eventName = eventName;
this.handleFocus = focus;
}
@Override
public boolean handle(Event event) {
if (event instanceof FocusListener.FocusEvent) {
if (handleFocus && event instanceof FocusListener.FocusEvent) {
handleFocusListener((FocusListener.FocusEvent) event);
return true;
}
if (event instanceof InputEvent) {
handleInputListener((InputEvent) event);
return true;
@@ -57,8 +64,6 @@ public class KeyboardListener implements EventListener {
case keyUp:
if (event.getKeyCode() == Input.Keys.ENTER || event.getKeyCode() == Input.Keys.NUMPAD_ENTER) {
keyboardHandler((VisTextField) event.getTarget());
VisTextField field = (VisTextField) event.getTarget();
lastValue = field.getText();
}
break;
}
@@ -68,9 +73,9 @@ public class KeyboardListener implements EventListener {
VisTextField field = (VisTextField) event.getTarget();
if(event.isFocused()) {
//it was a focus in event, which is no change
lastValue = field.getText();
return;
}
switch (event.getType()) {
case keyboard:
keyboardHandler(field);
@@ -78,19 +83,21 @@ public class KeyboardListener implements EventListener {
case scroll:
break;
}
}
private void keyboardHandler(VisTextField target) {
if(!target.isInputValid()) {
return;
}
// check for change
if(lastValue.equals(target.getText())) {
if(lastValue != null && lastValue.equals(target.getText())) {
// no change = no event;
return;
}
lastValue = target.getText();
HyperLap2DFacade facade = HyperLap2DFacade.getInstance();
facade.sendNotification(eventName, target.getText());
}
@@ -27,6 +27,7 @@ import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.SnapshotArray;
import com.kotcrab.vis.ui.FocusManager;
import games.rednblack.editor.utils.KeyBindingsLayout;
import games.rednblack.h2d.common.MsgAPI;
import games.rednblack.h2d.common.view.tools.Tool;
@@ -199,6 +200,8 @@ public class SandboxMediator extends Mediator<Sandbox> {
public boolean touchDown(Entity entity, float x, float y, int pointer, int button) {
super.touchDown(entity, x, y, pointer, button);
setSandboxFocus();
switch (button) {
case Input.Buttons.MIDDLE:
// if middle button is pressed - PAN the scene
@@ -372,13 +375,7 @@ public class SandboxMediator extends Mediator<Sandbox> {
public boolean touchDown(Entity entity, float x, float y, int pointer, int button) {
super.touchDown(entity, x, y, pointer, button);
Sandbox sandbox = Sandbox.getInstance();
// setting key and scroll focus on main area
sandbox.getUIStage().setKeyboardFocus();
sandbox.getUIStage().setScrollFocus(sandbox.getUIStage().midUI);
sandbox.setKeyboardFocus();
setSandboxFocus();
switch (button) {
case Input.Buttons.MIDDLE:
@@ -491,4 +488,14 @@ public class SandboxMediator extends Mediator<Sandbox> {
public String getCurrentSelectedToolName() {
return currentSelectedTool != null ? currentSelectedTool.getName() : "";
}
private void setSandboxFocus() {
Sandbox sandbox = Sandbox.getInstance();
FocusManager.resetFocus(sandbox.getUIStage());
// setting key and scroll focus on main area
sandbox.getUIStage().setKeyboardFocus();
sandbox.getUIStage().setScrollFocus(sandbox.getUIStage().midUI);
sandbox.setKeyboardFocus();
}
}
@@ -39,7 +39,6 @@ public class UIMultiPropertyBox extends UICollapsibleBox {
propertiesTable = new VisTable();
scrollPaneInner = new VisTable();
scrollPane = StandardWidgetsFactory.createScrollPane(scrollPaneInner);
scrollPane.setFadeScrollBars(true);
propertiesTable.add(scrollPane).maxHeight(Gdx.graphics.getHeight() * 0.38f).width(BOX_DEFAULT_WIDTH);
@@ -39,7 +39,6 @@ public abstract class UIItemCollapsibleProperties extends UIItemProperties {
public UIItemCollapsibleProperties(String title) {
this.title = title;
mainTable = new VisTable();
row().padTop(9).padBottom(6);
add(crateHeaderTable()).expandX().fillX().padBottom(7);
createCollapsibleWidget();
@@ -150,6 +150,22 @@ public class UIBasicItemPropertiesMediator extends UIItemPropertiesMediator<Enti
return viewComponent.isXYScaleLinked();
}
@Override
public void setItem(Entity item) {
super.setItem(item);
lockUpdates = true;
int entityType = EntityUtils.getType(observableReference);
if (entityType == EntityFactory.COLOR_PRIMITIVE
|| entityType == EntityFactory.LABEL_TYPE
|| entityType == EntityFactory.COMPOSITE_TYPE
|| entityType == EntityFactory.NINE_PATCH) {
viewComponent.setWidthHeightDisabled(false);
} else {
viewComponent.setWidthHeightDisabled(true);
}
lockUpdates = false;
}
@Override
protected void translateObservableDataToView(Entity entity) {
transformComponent = ComponentRetriever.get(entity, TransformComponent.class);
@@ -166,14 +182,6 @@ public class UIBasicItemPropertiesMediator extends UIItemPropertiesMediator<Enti
}
}
if (entityType == EntityFactory.COLOR_PRIMITIVE
|| entityType == EntityFactory.LABEL_TYPE
|| entityType == EntityFactory.COMPOSITE_TYPE
|| entityType == EntityFactory.NINE_PATCH) {
viewComponent.setWidthHeightDisabled(false);
} else {
viewComponent.setWidthHeightDisabled(true);
}
if (entityType == EntityFactory.LIGHT_TYPE) {
componentClassMap.remove(LIGHT_COMPONENT_KEY);
componentClassMap.remove(SHADER_COMPONENT_KEY);