Skip to content

Commit 35986ed

Browse files
committed
Added textStyle attribute to character actors.
1 parent 08c9a10 commit 35986ed

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

adventure-editor/src/main/java/com/bladecoder/engineeditor/ui/EditActorDialog.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,13 @@ public class EditActorDialog extends EditModelDialog<Scene, BaseActor> {
9797

9898
private InputPanel orgAlign;
9999

100+
private InputPanel textColor;
101+
private InputPanel textStyle;
102+
100103
// 3d Renderer
101104
private InputPanel spriteSize;
102105
private InputPanel cameraName;
103106
private InputPanel fov;
104-
private InputPanel textColor;
105107

106108
// Particle Renderer
107109
private InputPanel particleName;
@@ -178,6 +180,9 @@ public EditActorDialog(Skin skin, Scene parent, BaseActor e) {
178180

179181
textColor = InputPanelFactory.createInputPanel(skin, "Text Color",
180182
"The text color (RRGGBBAA) when the actor talks.", Param.Type.COLOR, false);
183+
184+
textStyle = InputPanelFactory.createInputPanel(skin, "Text Style",
185+
"The style to use (an entry in your `ui.json` in the `com.bladecoder.engine.ui.TextManagerUI$TextManagerUIStyle` section).", Param.Type.STRING, false);
181186

182187
particleName = InputPanelFactory.createInputPanel(skin, "Particle Name", "The name of the particle system.",
183188
Type.PARTICLE_ASSET, true);
@@ -229,7 +234,7 @@ public void changed(ChangeEvent event, Actor actor) {
229234
init(parent, e,
230235
new InputPanel[] { typePanel, id, renderer, particleName, particleAtlas, layer, visible, interaction, desc, state, fakeDepth, pos, refPoint, scale, rot,
231236
tint, text, font, size, textAlign, borderWidth, borderColor, borderStraight, shadowOffsetX, shadowOffsetY,
232-
shadowColor, bboxFromRenderer, zIndex, orgAlign, walkingSpeed, spriteSize, cameraName, fov, textColor });
237+
shadowColor, bboxFromRenderer, zIndex, orgAlign, walkingSpeed, spriteSize, cameraName, fov, textColor, textStyle });
233238

234239
typeChanged();
235240

@@ -280,6 +285,7 @@ private void typeChanged() {
280285
if (ACTOR_TYPES[i].equals(CHARACTER_TYPE_STR)) {
281286
setVisible(walkingSpeed, true);
282287
setVisible(textColor, true);
288+
setVisible(textStyle, true);
283289
}
284290

285291
rendererChanged();
@@ -538,6 +544,7 @@ protected void inputsToModel(boolean create) {
538544

539545
ca.setWalkingSpeed(Float.parseFloat(walkingSpeed.getText()));
540546
ca.setTextColor(Param.parseColor(textColor.getText()));
547+
ca.setTextStyle(textStyle.getText());
541548
}
542549
}
543550
}
@@ -631,6 +638,7 @@ protected void modelToInputs() {
631638

632639
walkingSpeed.setText(Float.toString(ca.getWalkingSpeed()));
633640
textColor.setText(ca.getTextColor() == null ? null : ca.getTextColor().toString());
641+
textStyle.setText(ca.getTextStyle());
634642
typePanel.setText(CHARACTER_TYPE_STR);
635643
} else {
636644
typePanel.setText(SPRITE_TYPE_STR);

blade-engine/src/com/bladecoder/engine/model/CharacterActor.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class CharacterActor extends SpriteActor {
4242

4343
private float walkingSpeed = DEFAULT_WALKING_SPEED;
4444
private Color textColor;
45+
private String textStyle;
4546

4647
private String standAnim = DEFAULT_STAND_ANIM;
4748
private String walkAnim = DEFAULT_WALK_ANIM;
@@ -57,6 +58,14 @@ public void setTextColor(Color textColor) {
5758
this.textColor = textColor;
5859
}
5960

61+
public String getTextStyle() {
62+
return textStyle;
63+
}
64+
65+
public void setTextStyle(String textStyle) {
66+
this.textStyle = textStyle;
67+
}
68+
6069
public String getStandAnim() {
6170
return standAnim;
6271
}
@@ -241,6 +250,7 @@ public void write(Json json) {
241250
json.writeValue("dialogs", dialogs, HashMap.class, Dialog.class);
242251

243252
if (SerializationHelper.getInstance().getMode() == Mode.MODEL) {
253+
json.writeValue("textStyle", textStyle);
244254
} else {
245255
json.writeValue("standAnim", standAnim);
246256
json.writeValue("walkAnim", walkAnim);
@@ -263,6 +273,8 @@ public void read(Json json, JsonValue jsonData) {
263273
for (Dialog d : dialogs.values())
264274
d.setActor(id);
265275
}
276+
277+
textStyle = json.readValue("textStyle", String.class, jsonData);
266278

267279
} else {
268280
if (dialogs != null) {

blade-engine/src/com/bladecoder/engine/ui/TextManagerUI.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.badlogic.gdx.utils.Align;
2929
import com.badlogic.gdx.utils.ObjectMap;
3030
import com.bladecoder.engine.assets.EngineAssetManager;
31+
import com.bladecoder.engine.model.CharacterActor;
3132
import com.bladecoder.engine.model.Text;
3233
import com.bladecoder.engine.model.TextManager;
3334
import com.bladecoder.engine.model.World;
@@ -54,6 +55,8 @@ public class TextManagerUI extends Actor {
5455
private float fontX = 0;
5556

5657
private AtlasRegion charIcon = null;
58+
59+
private TextManagerUIStyle style;
5760

5861
public TextManagerUI(Skin skin) {
5962
setTouchable(Touchable.disabled);
@@ -88,7 +91,7 @@ public void act(float delta) {
8891
unprojectTmp.set(posx, posy, 0);
8992
World.getInstance().getSceneCamera().scene2screen(getStage().getViewport(), unprojectTmp);
9093

91-
final TextManagerUIStyle style = getStyle(currentSubtitle);
94+
style = getStyle(currentSubtitle);
9295

9396
float maxWidth = Math.min(getStage().getViewport().getScreenWidth() - DPIUtils.getMarginSize() * 2,
9497
style.font.getXHeight() * (currentSubtitle.type == Text.Type.TALK ? style.maxTalkCharWidth : style.maxCharWidth));
@@ -143,7 +146,8 @@ public void act(float delta) {
143146

144147
if (currentSubtitle.type == Text.Type.TALK) {
145148
if (style.talkBubble != null) {
146-
setY(getY() + DPIUtils.getTouchMinSize() / 3 + PADDING);
149+
float bubbleHeight = DPIUtils.getTouchMinSize() * style.bubbleSize / 4;
150+
setY(getY() + bubbleHeight + PADDING);
147151
} else {
148152
setY(getY() + PADDING);
149153
}
@@ -175,8 +179,6 @@ && getX() + getWidth() < getStage().getViewport().getScreenWidth() + getWidth())
175179
public void draw(Batch batch, float alpha) {
176180
batch.setColor(Color.WHITE);
177181

178-
final TextManagerUIStyle style = getStyle(subtitle);
179-
180182
if (subtitle.type == Text.Type.TALK) {
181183
if (getX() < 0 || getX() > getStage().getViewport().getScreenWidth())
182184
return;
@@ -215,12 +217,16 @@ public void draw(Batch batch, float alpha) {
215217

216218
private TextManagerUIStyle getStyle(Text text) {
217219
String key = "default";
218-
if (text != null) {
220+
221+
if (text != null && text.style != null && !text.style.isEmpty()) {
219222
key = text.style;
223+
} else if (text.actorId != null) {
224+
CharacterActor a = (CharacterActor) World.getInstance().getCurrentScene().getActor(text.actorId, false);
225+
226+
if(a.getTextStyle() != null)
227+
key = a.getTextStyle();
220228
}
221-
if (key == null || key.isEmpty()) {
222-
key = "default";
223-
}
229+
224230
return styles.get(key);
225231
}
226232

0 commit comments

Comments
 (0)