Skip to content

Commit 302ed2b

Browse files
committed
Added interface for TextManagerUI.
1 parent fb6db0b commit 302ed2b

File tree

3 files changed

+71
-36
lines changed

3 files changed

+71
-36
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*******************************************************************************
2+
* Copyright 2014 Rafael Garcia Moreno.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
******************************************************************************/
16+
package com.bladecoder.engine.ui;
17+
18+
import com.bladecoder.engine.model.Text;
19+
20+
/**
21+
* TextManagerUI draws texts and dialogs on screen.
22+
*
23+
* @author rgarcia
24+
*
25+
*/
26+
public interface ITextManagerUI {
27+
public void setText(Text t);
28+
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@
3737
/**
3838
* TextManagerUI draws texts and dialogs on screen.
3939
*
40-
* For now, only one subtitle is displayed in the screen.
40+
* For now, only one subtitle is displayed in the screen at a time.
4141
*
4242
* @author rgarcia
4343
*
4444
*/
45-
public class TextManagerUI extends Actor {
45+
public class TextManagerUI extends Actor implements ITextManagerUI {
4646
private static final float PADDING = DPIUtils.getMarginSize();
4747

4848
private final Vector3 unprojectTmp = new Vector3();
@@ -72,6 +72,7 @@ public TextManagerUI(UI ui) {
7272
setVisible(false);
7373
}
7474

75+
@Override
7576
public void setText(Text t) {
7677
text = t;
7778

blade-engine/src/com/bladecoder/engine/ui/defaults/DefaultSceneScreen.java

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import com.bladecoder.engine.ui.SceneScreen;
7777
import com.bladecoder.engine.ui.TesterBot;
7878
import com.bladecoder.engine.ui.TextManagerUI;
79+
import com.bladecoder.engine.ui.ITextManagerUI;
7980
import com.bladecoder.engine.ui.UI;
8081
import com.bladecoder.engine.ui.UI.Screens;
8182
import com.bladecoder.engine.util.Config;
@@ -93,7 +94,7 @@ public class DefaultSceneScreen implements SceneScreen {
9394
private PieMenu pie;
9495
private InventoryUI inventoryUI;
9596
private Actor dialogUI;
96-
private TextManagerUI textManagerUI;
97+
private Actor textManagerUI;
9798
private ShapeRenderer renderer;
9899

99100
private InventoryButton inventoryButton;
@@ -154,12 +155,11 @@ public boolean tap(float x, float y, int count, int button) {
154155
else {
155156
getInputUnProject(unprojectTmp);
156157

157-
if (w.inCutMode()
158-
|| (!w.inCutMode() && !TextManager.AUTO_HIDE_TEXTS && textManagerUI.isVisible())) {
159-
160-
if(recorder.isRecording())
158+
if (w.inCutMode() || (!w.inCutMode() && !TextManager.AUTO_HIDE_TEXTS && textManagerUI.isVisible())) {
159+
160+
if (recorder.isRecording())
161161
return true;
162-
162+
163163
w.getCurrentScene().getTextManager().next();
164164
} else if (inventoryUI.isVisible()) {
165165
inventoryUI.hide();
@@ -305,8 +305,7 @@ public boolean keyTyped(char character) {
305305

306306
@Override
307307
public boolean scrolled(int amount) {
308-
if (uiEnabled && !ui.getWorld().hasDialogOptions()
309-
&& ui.getWorld().getInventory().isVisible()) {
308+
if (uiEnabled && !ui.getWorld().hasDialogOptions() && ui.getWorld().getInventory().isVisible()) {
310309

311310
boolean fromDown = (inventoryUI.getInventoryPos() == InventoryPos.CENTER
312311
|| inventoryUI.getInventoryPos() == InventoryPos.DOWN);
@@ -329,10 +328,10 @@ else if ((amount > 0 && !fromDown || amount < 0 && fromDown) && !inventoryUI.isV
329328
private final WorldListener worldListener = new WorldListener() {
330329
@Override
331330
public void text(Text t) {
332-
if(t != null && t.type == Text.Type.UI) {
331+
if (t != null && t.type == Text.Type.UI) {
333332
showUIText(t);
334-
} else {
335-
textManagerUI.setText(t);
333+
} else {
334+
((ITextManagerUI) textManagerUI).setText(t);
336335
}
337336
}
338337

@@ -368,44 +367,44 @@ public DefaultSceneScreen() {
368367
public UI getUI() {
369368
return ui;
370369
}
371-
370+
372371
private void showUIText(Text t) {
373372
// Type UI texts will show at the same time that TextManagerUI texts.
374-
375-
String style = t.style == null ?"ui-text":t.style;
373+
374+
String style = t.style == null ? "ui-text" : t.style;
376375
Label msg = new Label(t.str, getUI().getSkin(), style);
377376

378377
msg.setWrap(true);
379378
msg.setAlignment(Align.center, Align.center);
380379
msg.setColor(t.color);
381380
msg.setSize(msg.getWidth() + DPIUtils.getMarginSize() * 2, msg.getHeight() + DPIUtils.getMarginSize() * 2);
382-
381+
383382
stage.addActor(msg);
384383
unprojectTmp.set(t.x, t.y, 0);
385384
ui.getWorld().getSceneCamera().scene2screen(getStage().getViewport(), unprojectTmp);
386-
385+
387386
float posx, posy;
388-
387+
389388
if (t.x == TextManager.POS_CENTER) {
390389
posx = (getStage().getViewport().getScreenWidth() - msg.getWidth()) / 2;
391390
} else if (t.y == TextManager.POS_SUBTITLE) {
392391
posx = DPIUtils.getMarginSize();
393392
} else {
394393
posx = unprojectTmp.x;
395394
}
396-
395+
397396
if (t.y == TextManager.POS_CENTER) {
398397
posy = (getStage().getViewport().getScreenHeight() - msg.getHeight()) / 2;
399398
} else if (t.y == TextManager.POS_SUBTITLE) {
400399
posy = getStage().getViewport().getScreenHeight() - msg.getHeight() - DPIUtils.getMarginSize() * 3;
401400
} else {
402401
posy = unprojectTmp.y;
403402
}
404-
403+
405404
msg.setPosition(posx, posy);
406405
msg.getColor().a = 0;
407-
msg.addAction(sequence(Actions.fadeIn(0.4f, Interpolation.fade), Actions.delay(t.time,
408-
sequence(fadeOut(0.4f, Interpolation.fade), Actions.removeActor()))));
406+
msg.addAction(sequence(Actions.fadeIn(0.4f, Interpolation.fade),
407+
Actions.delay(t.time, sequence(fadeOut(0.4f, Interpolation.fade), Actions.removeActor()))));
409408
}
410409

411410
private void updateUI() {
@@ -530,16 +529,16 @@ else if (Gdx.input.isPeripheralAvailable(Peripheral.MultitouchScreen))
530529

531530
// UPDATE POINTER
532531
if (!pie.isVisible() && actorUnderCursor != currentActor) {
533-
currentActor = actorUnderCursor;
534-
532+
currentActor = actorUnderCursor;
533+
535534
if (currentActor != null) {
536535
if (showDesc)
537536
pointer.setDesc(currentActor.getDesc());
538537

539538
Verb leaveVerb = currentActor.getVerb(Verb.LEAVE_VERB);
540-
539+
541540
TextureRegion r = null;
542-
541+
543542
if (leaveVerb != null) {
544543
if (leaveVerb.getIcon() != null
545544
&& (r = getUI().getSkin().getAtlas().findRegion(leaveVerb.getIcon())) != null) {
@@ -550,18 +549,18 @@ else if (Gdx.input.isPeripheralAvailable(Peripheral.MultitouchScreen))
550549
}
551550
} else {
552551
Verb actionVerb = currentActor.getVerb(Verb.ACTION_VERB);
553-
554-
if(actionVerb != null && actionVerb.getIcon() != null
552+
553+
if (actionVerb != null && actionVerb.getIcon() != null
555554
&& (r = getUI().getSkin().getAtlas().findRegion(actionVerb.getIcon())) != null) {
556555
pointer.setIcon(r);
557-
} else {
556+
} else {
558557
pointer.setHotspotIcon();
559558
}
560559
}
561560
} else {
562561
pointer.setDefaultIcon();
563562
}
564-
} else if(pie.isVisible()) {
563+
} else if (pie.isVisible()) {
565564
currentActor = actorUnderCursor;
566565
}
567566
}
@@ -883,7 +882,7 @@ public void actorClick(InteractiveActor a, int button) {
883882
// SINGLE CLICK UI
884883
// Preference TALKTO, ACTION, PICKUP, LOOKAT
885884
String verb = Verb.TALKTO_VERB;
886-
885+
887886
if (a.getVerb(verb) == null)
888887
verb = Verb.PICKUP_VERB;
889888

@@ -959,10 +958,17 @@ public Actor getDialogUI() {
959958
return dialogUI;
960959
}
961960

962-
public void setTextManagerUI(TextManagerUI a) {
963-
textManagerUI.remove();
964-
textManagerUI = a;
965-
stage.addActor(textManagerUI);
961+
public void setTextManagerUI(Actor a) {
962+
if (a instanceof ITextManagerUI) {
963+
textManagerUI.remove();
964+
textManagerUI = a;
965+
stage.addActor(textManagerUI);
966+
} else {
967+
EngineLogger.error("ERROR setTextManagerUI: actor is not a ITextManagerUI");
968+
969+
dispose();
970+
Gdx.app.exit();
971+
}
966972
}
967973

968974
public void setDialogUI(Actor a) {

0 commit comments

Comments
 (0)