Skip to content

Commit 8d395ed

Browse files
committed
text fixes
1 parent 143c3e6 commit 8d395ed

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

blade-engine/src/com/bladecoder/engine/actions/SayAction.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ public class SayAction extends BaseCallbackAction {
5151
Type.STRING, true, "rectangle", new String[] { "rectangle",
5252
"talk", "plain" }),
5353
new Param("animation", "The animation to put when talking instead the default talk animation.",
54-
Type.STRING)
54+
Type.STRING),
55+
new Param("quee", "Quee the text if other text is showing or show it inmediatly.",Type.BOOLEAN, false, "false")
5556
};
5657

5758
private String soundId;
@@ -64,6 +65,7 @@ public class SayAction extends BaseCallbackAction {
6465
private String previousAnim = null;
6566
private String talkAnim = null;
6667
private Vector2 pos = null;
68+
private boolean quee = false;
6769

6870
@Override
6971
public void setParams(HashMap<String, String> params) {
@@ -93,6 +95,10 @@ public void setParams(HashMap<String, String> params) {
9395
if (params.get("pos") != null) {
9496
pos = Param.parseVector2(params.get("pos"));
9597
}
98+
99+
if (params.get("quee") != null) {
100+
quee = Boolean.parseBoolean(params.get("quee"));
101+
}
96102
}
97103

98104
@Override
@@ -109,7 +115,6 @@ public boolean run(ActionCallback cb) {
109115

110116
if (text != null) {
111117
float x, y;
112-
boolean quee = false;
113118

114119
if (pos != null) {
115120
x = pos.x;
@@ -195,6 +200,8 @@ public void write(Json json) {
195200
json.writeValue("previousAnim", previousAnim);
196201
json.writeValue("type", type);
197202
json.writeValue("talkAnim", talkAnim);
203+
json.writeValue("pos", pos);
204+
json.writeValue("quee", quee);
198205
super.write(json);
199206
}
200207

@@ -206,6 +213,8 @@ public void read(Json json, JsonValue jsonData) {
206213
previousAnim = json.readValue("previousAnim", String.class, jsonData);
207214
type = json.readValue("type", Text.Type.class, jsonData);
208215
talkAnim = json.readValue("talkAnim", String.class, jsonData);
216+
pos = json.readValue("pos", Vector2.class, jsonData);
217+
quee = json.readValue("quee", Boolean.class, jsonData);
209218
super.read(json, jsonData);
210219
}
211220

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

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,16 @@ public void act(float delta) {
8181
unprojectTmp.set(posx, posy, 0);
8282
World.getInstance().getSceneCamera().scene2screen(sceneScreen.getViewport(), unprojectTmp);
8383

84-
if (currentSubtitle.type == Text.Type.TALK) {
85-
layout.setText(style.font, currentSubtitle.str, currentSubtitle.color, maxTalkWidth, Align.center, true);
86-
} else {
87-
layout.setText(style.font, currentSubtitle.str, currentSubtitle.color, maxRectangleWidth, Align.center, true);
88-
}
84+
float maxWidth = currentSubtitle.type == Text.Type.TALK?maxTalkWidth:maxRectangleWidth;
85+
86+
layout.setText(style.font, currentSubtitle.str, currentSubtitle.color, maxWidth, Align.center, true);
8987

9088
if (posx == TextManager.POS_CENTER || posx == TextManager.POS_SUBTITLE) {
9189
posx = (sceneScreen.getViewport().getScreenWidth() - layout.width)/2;
92-
fontX = (sceneScreen.getViewport().getScreenWidth() - maxRectangleWidth)/2;
90+
fontX = (sceneScreen.getViewport().getScreenWidth() - maxWidth)/2;
9391
} else {
9492
posx = unprojectTmp.x;
93+
fontX = unprojectTmp.x;
9594
}
9695

9796
if (posy == TextManager.POS_CENTER) {
@@ -103,6 +102,7 @@ public void act(float delta) {
103102
}
104103

105104
setPosition(posx - PADDING, posy - PADDING);
105+
setSize(layout.width + PADDING * 2, layout.height + PADDING * 2);
106106

107107
if (currentSubtitle.type == Text.Type.TALK) {
108108
if (style.talkBubble != null) {
@@ -111,20 +111,21 @@ public void act(float delta) {
111111

112112
setX(getX() - layout.width / 2);
113113

114-
fontX = posx - maxTalkWidth / 2;
115-
}
116-
117-
setSize(layout.width + PADDING * 2, layout.height + PADDING * 2);
118-
119-
// check if the text exits the screen
120-
if (getX() < 0) {
121-
setX(0);
122-
} else if (getX() + getWidth() > sceneScreen.getViewport().getScreenWidth()) {
123-
setX(sceneScreen.getViewport().getScreenWidth() - getWidth());
124-
}
114+
fontX = posx - maxWidth / 2;
115+
116+
// check if the text exits the screen
117+
if (getX() < 0 && getX() > -getWidth()) {
118+
setX(0);
119+
fontX = getX() + PADDING;
120+
} else if (getX() + getWidth() > sceneScreen.getViewport().getScreenWidth() &&
121+
getX() + getWidth() < sceneScreen.getViewport().getScreenWidth() + getWidth()) {
122+
setX(sceneScreen.getViewport().getScreenWidth() - getWidth());
123+
fontX = sceneScreen.getViewport().getScreenWidth() - layout.width / 2 - PADDING - maxWidth / 2;
124+
}
125125

126-
if (getY() + getHeight() > sceneScreen.getViewport().getScreenHeight()) {
127-
setY(sceneScreen.getViewport().getScreenHeight() - getHeight());
126+
if (getY() + getHeight() > sceneScreen.getViewport().getScreenHeight()) {
127+
setY(sceneScreen.getViewport().getScreenHeight() - getHeight());
128+
}
128129
}
129130
}
130131
}
@@ -141,14 +142,11 @@ public void draw(Batch batch, float alpha) {
141142
unprojectTmp.set(subtitle.x, subtitle.y, 0);
142143
World.getInstance().getSceneCamera().scene2screen(sceneScreen.getViewport(), unprojectTmp);
143144

144-
float bubbleX = unprojectTmp.x - style.talkBubble.getMinWidth() * scale / 2;
145-
145+
float bubbleX = unprojectTmp.x - style.talkBubble.getMinWidth() * scale / 2;
146146
float bubbleY = getY() - style.talkBubble.getMinHeight() * scale + 2;
147-
148-
// style.talkBubble.draw(batch, bubbleX, bubbleY, style.talkBubble.getMinWidth() * scale,
149-
// style.talkBubble.getMinHeight() * scale);
150147

151-
style.talkBubble.draw(batch, bubbleX, bubbleY, style.talkBubble.getMinWidth() * scale,
148+
if(bubbleX + style.talkBubble.getMinWidth() * scale < getX() + getWidth() && bubbleX > getX())
149+
style.talkBubble.draw(batch, bubbleX, bubbleY, style.talkBubble.getMinWidth() * scale,
152150
style.talkBubble.getMinHeight() * scale);
153151
}
154152

0 commit comments

Comments
 (0)