Skip to content

Commit

Permalink
Add listener for SpeechBubble.
Browse files Browse the repository at this point in the history
  • Loading branch information
steffen-wilke committed Apr 28, 2019
1 parent 4e53e63 commit dc550f0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/de/gurkenlabs/litiengine/gui/SpeechBubble.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
import java.awt.image.BufferedImage;
import java.text.AttributedCharacterIterator;
import java.text.AttributedString;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

import de.gurkenlabs.litiengine.Game;
import de.gurkenlabs.litiengine.IUpdateable;
Expand All @@ -35,13 +37,13 @@ public class SpeechBubble implements IUpdateable, IRenderable {
private static final int DISPLAYTIME_MIN = 2000;
private static final int DISPLAYTIME_PER_LETTER = 120;
private static final int LETTER_WRITE_DELAY = 30;
private Font font;

private static final double TRIANGLE_SIZE = 6;

private final List<SpeechBubbleListener> listeners = new CopyOnWriteArrayList<>();
private final int currentTextDisplayTime;
private final SpeechBubbleAppearance appearance;

private Font font;
private BufferedImage bubble;
private String currentText;

Expand Down Expand Up @@ -107,6 +109,10 @@ public static boolean isActive(final IEntity entity) {
return activeSpeechBubbles.containsKey(entity);
}

public void addListener(SpeechBubbleListener listener) {
this.listeners.add(listener);
}

public IEntity getEntity() {
return this.entity;
}
Expand Down Expand Up @@ -168,6 +174,10 @@ public void update() {
activeSpeechBubbles.remove(this.getEntity());
}

for(SpeechBubbleListener listener : this.listeners) {
listener.hidden();
}

return;
}

Expand Down
6 changes: 6 additions & 0 deletions src/de/gurkenlabs/litiengine/gui/SpeechBubbleListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package de.gurkenlabs.litiengine.gui;

public interface SpeechBubbleListener {
public default void hidden() {
}
}

0 comments on commit dc550f0

Please sign in to comment.