mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
Support rendering game log
This commit is contained in:
@@ -145,12 +145,12 @@ public class FSkinColor {
|
||||
if (brightnessDelta != NO_BRIGHTNESS_DELTA) {
|
||||
if (brightnessDelta < 0) {
|
||||
for (int i = 0; i > brightnessDelta; i--) {
|
||||
color = FSkinColor.stepColor(color, 10);
|
||||
color = FSkinColor.stepColor(color, -20);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < brightnessDelta; i++) {
|
||||
color = FSkinColor.stepColor(color, -10);
|
||||
color = FSkinColor.stepColor(color, 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,32 @@
|
||||
package forge.screens.match.views;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
|
||||
|
||||
import forge.Forge.Graphics;
|
||||
import forge.assets.FSkinColor;
|
||||
import forge.assets.FSkinFont;
|
||||
import forge.assets.FSkinColor.Colors;
|
||||
import forge.game.GameLog;
|
||||
import forge.game.GameLogEntry;
|
||||
import forge.game.GameLogEntryType;
|
||||
import forge.menu.FDropDown;
|
||||
import forge.model.FModel;
|
||||
import forge.toolbox.FDisplayObject;
|
||||
import forge.utils.ForgePreferences.FPref;
|
||||
|
||||
public class VLog extends FDropDown {
|
||||
private final GameLog model;
|
||||
|
||||
public VLog(GameLog model0) {
|
||||
model = model0;
|
||||
private static final float PADDING = 5;
|
||||
private static final FSkinFont FONT = FSkinFont.get(11);
|
||||
private static final FSkinColor ALT_ROW_COLOR = FSkinColor.get(Colors.CLR_ZEBRA);
|
||||
private static final FSkinColor ROW_COLOR = ALT_ROW_COLOR.darker();
|
||||
private static final FSkinColor FORE_COLOR = FSkinColor.get(Colors.CLR_TEXT);
|
||||
|
||||
private final GameLog log;
|
||||
|
||||
public VLog(GameLog log0) {
|
||||
log = log0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -15,9 +34,72 @@ public class VLog extends FDropDown {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawBackground(Graphics g) {
|
||||
float w = getWidth();
|
||||
float h = getHeight();
|
||||
g.fillRect(ROW_COLOR, 0, 0, w, h); //can fill background with main row color since drop down will never be taller than number of rows
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ScrollBounds updateAndGetPaneSize(float maxWidth, float maxVisibleHeight) {
|
||||
|
||||
return new ScrollBounds(maxWidth, maxVisibleHeight);
|
||||
clear();
|
||||
|
||||
GameLogEntryType logVerbosityFilter = GameLogEntryType.valueOf(FModel.getPreferences().getPref(FPref.DEV_LOG_ENTRY_TYPE));
|
||||
List<GameLogEntry> logEntrys = log.getLogEntries(logVerbosityFilter);
|
||||
|
||||
LogEntryDisplay logEntryDisplay;
|
||||
float width = maxWidth - getMenuTab().getScreenPosition().x; //stretch from tab to edge of screen
|
||||
|
||||
float y = 1;
|
||||
float height;
|
||||
if (logEntrys.isEmpty()) {
|
||||
logEntryDisplay = add(new LogEntryDisplay("[Empty]", false));
|
||||
height = logEntryDisplay.getMinHeight(width);
|
||||
logEntryDisplay.setBounds(0, y, width, height);
|
||||
y += height;
|
||||
}
|
||||
else {
|
||||
boolean isAltRow = false;
|
||||
for (int i = logEntrys.size() - 1; i >= 0; i--) { //show latest entry on bottom
|
||||
logEntryDisplay = add(new LogEntryDisplay(logEntrys.get(i).message, isAltRow));
|
||||
height = logEntryDisplay.getMinHeight(width);
|
||||
logEntryDisplay.setBounds(0, y, width, height);
|
||||
isAltRow = !isAltRow;
|
||||
y += height;
|
||||
}
|
||||
}
|
||||
|
||||
return new ScrollBounds(width, y + 1);
|
||||
}
|
||||
|
||||
private class LogEntryDisplay extends FDisplayObject {
|
||||
private final String text;
|
||||
private final boolean isAltRow;
|
||||
|
||||
private LogEntryDisplay(String text0, boolean isAltRow0) {
|
||||
text = text0;
|
||||
isAltRow = isAltRow0;
|
||||
}
|
||||
|
||||
private float getMinHeight(float width) {
|
||||
width -= 2 * PADDING; //account for left and right insets
|
||||
float height = FONT.getFont().getWrappedBounds(text, width).height;
|
||||
height += 2 * PADDING;
|
||||
return Math.round(height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics g) {
|
||||
float w = getWidth();
|
||||
float h = getHeight();
|
||||
|
||||
if (isAltRow) {
|
||||
g.fillRect(ALT_ROW_COLOR, 0, 0, w, h);
|
||||
}
|
||||
|
||||
//use full height without padding so text not scaled down
|
||||
g.drawText(text, FONT, FORE_COLOR, PADDING, PADDING, w - 2 * PADDING, h, true, HAlignment.LEFT, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user