Fully working typing labels with proper component UI

This commit is contained in:
fgnm
2020-08-28 21:02:23 +02:00
parent 4bb67df2fa
commit 3af0f93df7
12 changed files with 141 additions and 18 deletions
+1
View File
@@ -96,6 +96,7 @@ dependencies {
implementation project(":hyperlap2d-runtime-libgdx")
implementation project(":h2d-libgdx-spine-extension")
implementation "com.rafaskoberg.gdx:typing-label:$typingLabelVersion"
implementation "com.kotcrab.vis:vis-ui:$visuiVersion"
implementation "com.esotericsoftware.spine:spine-libgdx:$spineVersion"
implementation "com.mortennobel:java-image-scaling:0.8.5"
@@ -3,6 +3,7 @@ package games.rednblack.editor.renderer.data;
import com.badlogic.ashley.core.Entity;
import games.rednblack.editor.renderer.components.DimensionsComponent;
import games.rednblack.editor.renderer.components.label.LabelComponent;
import games.rednblack.editor.renderer.components.label.TypingLabelComponent;
public class LabelVO extends MainItemVO {
@@ -15,6 +16,7 @@ public class LabelVO extends MainItemVO {
public float height = 0;
public boolean wrap = false;
public boolean isTyping = false;
public LabelVO() {
super();
@@ -22,13 +24,14 @@ public class LabelVO extends MainItemVO {
public LabelVO(LabelVO vo) {
super(vo);
text = new String(vo.text);
style = new String(vo.style);
size = vo.size;
align = vo.align;
width = vo.width;
height = vo.height;
wrap = vo.wrap;
text = new String(vo.text);
style = new String(vo.style);
size = vo.size;
align = vo.align;
width = vo.width;
height = vo.height;
wrap = vo.wrap;
isTyping = vo.isTyping;
}
@Override
@@ -36,12 +39,16 @@ public class LabelVO extends MainItemVO {
super.loadFromEntity(entity);
LabelComponent labelComponent = entity.getComponent(LabelComponent.class);
DimensionsComponent dimensionsComponent = entity.getComponent(DimensionsComponent.class);
TypingLabelComponent typingLabelComponent = entity.getComponent(TypingLabelComponent.class);
text = labelComponent.getText().toString();
style = labelComponent.fontName;
size = labelComponent.fontSize;
align = labelComponent.labelAlign;
wrap = labelComponent.wrap;
isTyping = typingLabelComponent != null;
width = dimensionsComponent.width;
height = dimensionsComponent.height;
}
@@ -8,6 +8,7 @@ import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;
import games.rednblack.editor.renderer.components.DimensionsComponent;
import games.rednblack.editor.renderer.components.label.LabelComponent;
import games.rednblack.editor.renderer.components.label.TypingLabelComponent;
import games.rednblack.editor.renderer.data.*;
import games.rednblack.editor.renderer.factory.EntityFactory;
import games.rednblack.editor.renderer.resources.IResourceRetriever;
@@ -54,6 +55,11 @@ public class LabelComponentFactory extends ComponentFactory{
component.setFontScale(multiplier/projectInfoVO.pixelToWorld);
entity.add(component);
if (vo.isTyping) {
TypingLabelComponent typingLabelComponent = engine.createComponent(TypingLabelComponent.class);
entity.add(typingLabelComponent);
}
return component;
}
@@ -27,7 +27,6 @@ public class TypingLabelSystem extends IteratingSystem {
if (typingLabelComponent.typingLabel == null) {
typingLabelComponent.typingLabel = new TypingLabel(labelComponent.text, labelComponent.style);
BitmapFont font = typingLabelComponent.typingLabel.getBitmapFontCache().getFont();
float fontScaleX = labelComponent.fontScaleX;
@@ -37,8 +36,23 @@ public class TypingLabelSystem extends IteratingSystem {
typingLabelComponent.typingLabel.setSize(dimensionsComponent.width, dimensionsComponent.height);
typingLabelComponent.typingLabel.setWrap(labelComponent.wrap);
typingLabelComponent.typingLabel.setAlignment(labelComponent.labelAlign, labelComponent.lineAlign);
} else if (!typingLabelComponent.typingLabel.getOriginalText().equals(labelComponent.text)){
typingLabelComponent.typingLabel.setText(labelComponent.text);
} else {
if (!typingLabelComponent.typingLabel.getOriginalText().equals(labelComponent.text)){
typingLabelComponent.typingLabel.setText(labelComponent.text);
}
if (typingLabelComponent.typingLabel.getWrap() != labelComponent.wrap) {
typingLabelComponent.typingLabel.setWrap(labelComponent.wrap);
}
if (typingLabelComponent.typingLabel.getLabelAlign() != labelComponent.labelAlign
|| typingLabelComponent.typingLabel.getLineAlign() != labelComponent.lineAlign) {
typingLabelComponent.typingLabel.setAlignment(labelComponent.labelAlign, labelComponent.lineAlign);
}
if (typingLabelComponent.typingLabel.getWidth() != dimensionsComponent.width) {
typingLabelComponent.typingLabel.setWidth(dimensionsComponent.width);
}
if (typingLabelComponent.typingLabel.getHeight() != dimensionsComponent.height) {
typingLabelComponent.typingLabel.setHeight(dimensionsComponent.height);
}
}
typingLabelComponent.typingLabel.act(deltaTime);
@@ -53,6 +53,7 @@ public class LabelDrawableLogic implements Drawable {
} else {
typingLabelComponent.typingLabel.setColor(tmpColor);
typingLabelComponent.typingLabel.setPosition(entityTransformComponent.x, entityTransformComponent.y);
typingLabelComponent.typingLabel.setOrigin(entityTransformComponent.originX, entityTransformComponent.originY);
typingLabelComponent.typingLabel.draw(batch, 1);
}
}
@@ -21,6 +21,7 @@ package games.rednblack.editor.view.ui.box;
import com.badlogic.ashley.core.Entity;
import com.badlogic.gdx.utils.reflect.ClassReflection;
import com.badlogic.gdx.utils.reflect.ReflectionException;
import games.rednblack.editor.renderer.components.label.TypingLabelComponent;
import games.rednblack.editor.renderer.components.light.LightBodyComponent;
import games.rednblack.h2d.common.MsgAPI;
import com.puremvc.patterns.mediator.Mediator;
@@ -110,6 +111,8 @@ public class UIMultiPropertyBoxMediator extends PanelMediator<UIMultiPropertyBox
PhysicsBodyComponent physicsComponent = ComponentRetriever.get(entity, PhysicsBodyComponent.class);
ShaderComponent shaderComponent = ComponentRetriever.get(entity, ShaderComponent.class);
LightBodyComponent lightComponent = ComponentRetriever.get(entity, LightBodyComponent.class);
TypingLabelComponent typingLabelComponent = ComponentRetriever.get(entity, TypingLabelComponent.class);
if(polygonComponent != null) {
mediatorNames.add(UIPolygonComponentPropertiesMediator.NAME);
}
@@ -122,6 +125,9 @@ public class UIMultiPropertyBoxMediator extends PanelMediator<UIMultiPropertyBox
if(lightComponent != null) {
mediatorNames.add(UILightBodyPropertiesMediator.NAME);
}
if (typingLabelComponent != null) {
mediatorNames.add(UITypingLabelPropertiesMediator.NAME);
}
}
@Override
@@ -63,11 +63,11 @@ public class UIBasicItemPropertiesMediator extends UIItemPropertiesMediator<Enti
final private HashMap<String, UIBasicItemProperties.ItemType> itemTypeMap = new HashMap<>();
public static final String POLYGON_COMPONENT_KEY = "Polygon Component";
public static final String PHYSICS_COMPONENT_KEY = "Physics Component";
public static final String SHADER_COMPONENT_KEY = "Shader Component";
public static final String LIGHT_COMPONENT_KEY = "Light Component";
public static final String TYPING_LABEL_COMPONENT_KEY = "Typing Label Component";
public static final String POLYGON_COMPONENT_KEY = "Polygon";
public static final String PHYSICS_COMPONENT_KEY = "Physics";
public static final String SHADER_COMPONENT_KEY = "Shader";
public static final String LIGHT_COMPONENT_KEY = "Light";
public static final String TYPING_LABEL_COMPONENT_KEY = "Typing Label";
final private HashMap<String, Class<? extends Component>> componentClassMap = new HashMap<>();
@@ -41,7 +41,7 @@ public class UIPhysicsProperties extends UIRemovableProperties {
private VisCheckBox fixedRotation;
public UIPhysicsProperties() {
super("Physics Component");
super("Physics");
bodyTypes.put(0, "STATIC");
bodyTypes.put(1, "KINEMATIC");
@@ -47,7 +47,7 @@ public class UIPolygonComponentProperties extends UIRemovableProperties {
private VisTextButton pasteBtn;
public UIPolygonComponentProperties() {
super("Polygon Component");
super("Polygon");
}
public void initView() {
@@ -41,7 +41,7 @@ public class UIShaderProperties extends UIRemovableProperties {
private VisSelectBox<String> shadersSelector;
public UIShaderProperties() {
super("Custom Shader Component");
super("Custom Shader");
}
public void initView(HashMap<String, ShaderProgram> shaders) {
@@ -0,0 +1,28 @@
package games.rednblack.editor.view.ui.properties.panels;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.event.ButtonToNotificationListener;
import games.rednblack.editor.view.ui.properties.UIRemovableProperties;
import games.rednblack.h2d.common.view.ui.StandardWidgetsFactory;
public class UITypingLabelProperties extends UIRemovableProperties {
public static final String prefix = "games.rednblack.editor.view.ui.properties.panels.UITypingLabelProperties";
public static final String CLOSE_CLICKED = prefix + ".CLOSE_CLICKED";
public static final String RESTART_BUTTON_CLICKED = prefix + ".RESTART_BUTTON_CLICKED";
public UITypingLabelProperties() {
super("Typing Label");
TextButton restartButton = StandardWidgetsFactory.createTextButton("Restart");
mainTable.add(restartButton);
restartButton.addListener(new ButtonToNotificationListener(RESTART_BUTTON_CLICKED));
}
@Override
public void onRemove() {
HyperLap2DFacade.getInstance().sendNotification(CLOSE_CLICKED);
}
}
@@ -0,0 +1,60 @@
package games.rednblack.editor.view.ui.properties.panels;
import com.badlogic.ashley.core.Entity;
import com.puremvc.patterns.observer.Notification;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.controller.commands.RemoveComponentFromItemCommand;
import games.rednblack.editor.renderer.components.label.TypingLabelComponent;
import games.rednblack.editor.renderer.utils.ComponentRetriever;
import games.rednblack.editor.view.ui.properties.UIItemPropertiesMediator;
import games.rednblack.h2d.common.MsgAPI;
import org.apache.commons.lang3.ArrayUtils;
public class UITypingLabelPropertiesMediator extends UIItemPropertiesMediator<Entity, UITypingLabelProperties> {
private static final String TAG = UITypingLabelPropertiesMediator.class.getCanonicalName();
public static final String NAME = TAG;
public UITypingLabelPropertiesMediator() {
super(NAME, new UITypingLabelProperties());
}
@Override
public String[] listNotificationInterests() {
String[] defaultNotifications = super.listNotificationInterests();
String[] notificationInterests = new String[]{
UITypingLabelProperties.CLOSE_CLICKED,
UITypingLabelProperties.RESTART_BUTTON_CLICKED
};
return ArrayUtils.addAll(defaultNotifications, notificationInterests);
}
@Override
public void handleNotification(Notification notification) {
super.handleNotification(notification);
switch (notification.getName()) {
case UITypingLabelProperties.CLOSE_CLICKED:
HyperLap2DFacade.getInstance().sendNotification(MsgAPI.ACTION_REMOVE_COMPONENT, RemoveComponentFromItemCommand.payload(observableReference, TypingLabelComponent.class));
break;
case UITypingLabelProperties.RESTART_BUTTON_CLICKED:
restartTypingLabel();
break;
}
}
private void restartTypingLabel() {
TypingLabelComponent typingLabelComponent = ComponentRetriever.get(observableReference, TypingLabelComponent.class);
typingLabelComponent.typingLabel.restart();
}
@Override
protected void translateObservableDataToView(Entity item) {
}
@Override
protected void translateViewToItemData() {
}
}