add button log titlebar button to cycle through 4 styles.

master
lodici 2015-09-22 20:02:07 +01:00
parent 27aa38b1e3
commit 1191446837
7 changed files with 73 additions and 11 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 467 B

View File

@ -39,6 +39,7 @@ public enum MagicIcon {
ARROWUP_ICON("w_arrowup.png"),
PLUS_ICON("w_plus28.png"),
MINUS_ICON("w_minus28.png"),
MARKER_ICON("w_marker.png"),
MISSING_ICON("missing2.png"),
ARENA("arena.png"),

View File

@ -16,6 +16,7 @@ import magic.data.MagicIcon;
import magic.translate.UiString;
import magic.ui.IconImages;
import magic.ui.ScreenController;
import magic.ui.message.MessageStyle;
import magic.ui.screen.widget.ActionBarButton;
import magic.ui.widget.ActionButtonTitleBar;
import magic.ui.widget.TexturedPanel;
@ -34,6 +35,7 @@ class LogStackViewer extends TexturedPanel {
private final StackViewer stackViewer;
private final ActionButtonTitleBar logTitleBar;
private final ActionButtonTitleBar stackTitleBar;
private MessageStyle messageStyle = MessageStyle.PLAIN;
LogStackViewer(LogViewer aLogBookViewer, StackViewer aStackViewer) {
@ -77,8 +79,24 @@ class LogStackViewer extends TexturedPanel {
);
}
private JButton getMessageStyleActionButton() {
return new ActionBarButton(
IconImages.getIcon(MagicIcon.MARKER_ICON),
"Cycle message style",
"Click to cycle through various styles for the log/stack messages.",
new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
messageStyle = messageStyle.getNext();
logViewer.setMessageStyle(messageStyle);
}
}
);
}
private List<JButton> getLogActionButtons() {
final List<JButton> btns = new ArrayList<>();
btns.add(getMessageStyleActionButton());
btns.add(getLogFileActionButton());
btns.add(getLogViewActionButton(MagicIcon.DOWNARROW_ICON));
return btns;

View File

@ -10,6 +10,8 @@ import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import magic.model.MagicMessage;
import magic.ui.SwingGameController;
import magic.ui.message.MessageStyle;
import magic.ui.message.TextComponent;
import magic.ui.widget.FontsAndBorders;
import magic.ui.widget.TexturedPanel;
import net.miginfocom.swing.MigLayout;
@ -61,6 +63,13 @@ class LogViewer extends TexturedPanel {
return new MessagePanel(message, this, controller);
}
void setMessageStyle(MessageStyle aStyle) {
TextComponent.messageStyle = aStyle;
messagePanels.removeAll();
update();
revalidate();
}
private class LogScrollPane extends JScrollPane {
private static final int INCREMENT = 108;

View File

@ -0,0 +1,12 @@
package magic.ui.message;
public enum MessageStyle {
PLAIN,
PLAINBOLD,
PLAINBOLDMONO,
BOLD;
public MessageStyle getNext() {
return values()[(ordinal() + 1) % values().length];
}
}

View File

@ -9,7 +9,9 @@ import java.awt.Rectangle;
import javax.swing.JComponent;
import magic.model.MagicMessage;
class TextComponent extends TComponent {
public class TextComponent extends TComponent {
public static MessageStyle messageStyle = MessageStyle.PLAIN;
private final String text;
private final Font font;
@ -29,19 +31,39 @@ class TextComponent extends TComponent {
this.text = text;
this.cardInfo = aCardInfo;
final boolean isBoldFont = isInteractive() && !text.startsWith("#");
this.font = isBoldFont ? aFont.deriveFont(Font.BOLD) : aFont;
this.fontColor = getTextColor(isChoice, choiceColor);
this.font = getTextFont(aFont);
this.metrics = component.getFontMetrics(this.font);
fontColor = text.startsWith("#") & !isChoice
? Color.DARK_GRAY
: isChoice
? choiceColor
: Color.BLACK;
this.newLine = !(".".equals(text) || ",".equals(text));
}
private Color getTextColor(boolean isChoice, Color choiceColor) {
return isCardId() & !isChoice
? Color.DARK_GRAY
: isInteractive() && messageStyle != MessageStyle.PLAINBOLDMONO
? Color.BLUE
: isChoice
? choiceColor
: Color.BLACK;
}
private Font getTextFont(final Font aFont) {
final boolean isBoldFont =
messageStyle != MessageStyle.PLAIN
&& (isInteractive() || messageStyle == MessageStyle.BOLD)
&& !isCardId();
return messageStyle == MessageStyle.PLAIN
? aFont
: isBoldFont
? aFont.deriveFont(Font.BOLD)
: aFont;
}
private boolean isCardId() {
return text.startsWith("#");
}
@Override
boolean requiresNewLine() {

View File

@ -20,7 +20,7 @@ public class ActionButtonTitleBar extends TitleBar {
actionsPanel.setOpaque(false);
actionsPanel.setLayout(new MigLayout("insets 0, gap 10", "", "grow, fill"));
actionsPanel.setLayout(new MigLayout("insets 0, gap 12", "", "grow, fill"));
for (JButton btn : actionButtons) {
actionsPanel.add(btn, "w 16!, h 16!");
}