Skip to content

Commit

Permalink
Merge pull request #727 from GreenLightning/develop
Browse files Browse the repository at this point in the history
Added Shephiroth's font methods and updated chat class
  • Loading branch information
danielduner committed Mar 3, 2012
2 parents 13eb851 + 6961e03 commit 8becc54
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/com/mojang/mojam/Chat.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ public class Chat implements KeyListener {
private static final int MAX_MESSAGES = 10;
private static final int MAX_MESSAGE_LENGTH = 35;
private static final int TICKS_PER_MESSAGE = 60 * 4;
private static final int FADE_TICKS = 60 / 2;

private ArrayList<String> messages = new ArrayList<String>();
private int displayedMessage = -1;
private int displayTicks = 0;
private int fadingTicks = 0;
private boolean fading;
private boolean open = false;
private String currentMessage = "";
private String waitingMessage = null;
Expand Down Expand Up @@ -50,10 +53,19 @@ public String getWaitingMessage() {

public void tick() {
if (displayedMessage > -1) {
displayTicks++;
if (displayTicks == TICKS_PER_MESSAGE) {
displayTicks = 0;
displayedMessage -= 1;
if (!fading) {
displayTicks++;
if (displayTicks == TICKS_PER_MESSAGE) {
displayTicks = 0;
fading = true;
}
} else {
fadingTicks++;
if (fadingTicks == FADE_TICKS) {
fadingTicks = 0;
fading = false;
displayedMessage--;
}
}
}
}
Expand All @@ -68,6 +80,14 @@ public void render(Screen screen) {
}
} else {
for (int i = 0; i <= displayedMessage; i++) {
if (i == displayedMessage) {
if (fading) {
int alpha = 255 - (fadingTicks * 255 / FADE_TICKS);
Font.defaultFont().drawOpaque(screen, messages.get(i), xOffset,
(yOffset -= 8), alpha);
continue;
}
}
Font.defaultFont().draw(screen, messages.get(i), xOffset, (yOffset -= 8));
}
}
Expand Down
43 changes: 43 additions & 0 deletions src/com/mojang/mojam/gui/Font.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,35 @@ public void draw(Screen screen, String msg, int x, int y, int width) {
}
}

/**
* Draw the given text onto the given screen at the given position with given opacity
*
* @param screen Screen
* @param msg Message
* @param x X coordinate
* @param y Y coordinate
* @param width Maximum line width in pixels
* @param opaque Opacity of text. Range from 0x00 (transparent) to 0xff (opaque)
*/
public void drawOpaque(Screen screen, String msg, int x, int y, int width, int opaque) {
int startX = x;
int length = msg.length();
for (int i = 0; i < length; i++) {
char character = msg.charAt(i);
Bitmap bitmap = getCharacterBitmap(character);
int heightOffset = 0;
if (letters.indexOf(character) < 0) {
heightOffset = fontCharacterFactory.getHeightOffset(character);
}
screen.alphaBlit(bitmap, x, y + heightOffset, opaque);
x += bitmap.w + letterSpacing;
if (x > width - bitmap.w) {
x = startX;
y += glyphHeight + 2;
}
}
}

private Bitmap getCharacterBitmap(char character) {
int charPosition = letters.indexOf(character);
if (charPosition >= 0) {
Expand All @@ -228,6 +257,20 @@ private Bitmap getCharacterBitmap(char character) {
}
}

/**
*
* * Draw the given text onto the given screen at the given position with given opacity
*
* @param screen Screen
* @param msg Message
* @param x X coordinate
* @param y Y coordinate
* @param opaque Opacity of text. Range from 0x00 (transparent) to 0xff (opaque)
*/
public void drawOpaque(Screen screen, String msg, int x, int y, int opaque) {
drawOpaque(screen, msg, x, y, Integer.MAX_VALUE, opaque);
}

/**
* Draw the given text onto the given screen at the given position
*
Expand Down

0 comments on commit 8becc54

Please sign in to comment.