diff --git a/.gitattributes b/.gitattributes index 82dff937902..e70d16d2bcb 100644 --- a/.gitattributes +++ b/.gitattributes @@ -14914,6 +14914,7 @@ src/main/java/forge/gui/package-info.java svneol=native#text/plain src/main/java/forge/gui/toolbox/CardFaceSymbols.java svneol=native#text/plain src/main/java/forge/gui/toolbox/FButton.java -text src/main/java/forge/gui/toolbox/FCheckBox.java -text +src/main/java/forge/gui/toolbox/FComboBoxPanel.java -text src/main/java/forge/gui/toolbox/FLabel.java -text src/main/java/forge/gui/toolbox/FList.java -text src/main/java/forge/gui/toolbox/FOverlay.java -text diff --git a/src/main/java/forge/GameLog.java b/src/main/java/forge/GameLog.java index 1719426d697..6e8dc7f6b56 100644 --- a/src/main/java/forge/GameLog.java +++ b/src/main/java/forge/GameLog.java @@ -24,6 +24,7 @@ import java.util.Observable; import org.apache.commons.lang3.StringUtils; import forge.game.event.IGameEventVisitor; +import forge.properties.ForgePreferences.FPref; /** @@ -103,6 +104,11 @@ public class GameLog extends Observable { } return result; } + + public GameLogEntryType getGameLogEntryTypeSetting() { + String logEntryType = Singletons.getModel().getPreferences().getPref(FPref.DEV_LOG_ENTRY_TYPE); + return GameLogEntryType.valueOf(logEntryType); + } public IGameEventVisitor getEventVisitor() { return formatter; diff --git a/src/main/java/forge/gui/home/settings/CSubmenuPreferences.java b/src/main/java/forge/gui/home/settings/CSubmenuPreferences.java index 4e06a5255b8..55718e46d6d 100644 --- a/src/main/java/forge/gui/home/settings/CSubmenuPreferences.java +++ b/src/main/java/forge/gui/home/settings/CSubmenuPreferences.java @@ -15,6 +15,7 @@ import org.apache.commons.lang3.tuple.Pair; import forge.Command; import forge.Constant.Preferences; +import forge.GameLogEntryType; import forge.Singletons; import forge.control.FControl.Screens; import forge.control.RestartUtil; @@ -73,6 +74,15 @@ public enum CSubmenuPreferences implements ICDoc { prefs.save(); } }); + + view.getCboLogEntryType().addItemListener(new ItemListener() { + @Override + public void itemStateChanged(final ItemEvent e) { + GameLogEntryType selectedType = (GameLogEntryType) view.getCboLogEntryType().getSelectedItem(); + prefs.setPref(FPref.DEV_LOG_ENTRY_TYPE, selectedType.toString()); + prefs.save(); + } + }); lstControls.clear(); // just in case lstControls.add(Pair.of(view.getCbCompactMainMenu(), FPref.UI_COMPACT_MAIN_MENU)); @@ -145,6 +155,7 @@ public enum CSubmenuPreferences implements ICDoc { updateAIProfiles(); view.getCbDevMode().setSelected(prefs.getPrefBoolean(FPref.DEV_MODE_ENABLED)); + view.getCboLogEntryType().setSelectedItem(GameLogEntryType.valueOf(prefs.getPref(FPref.DEV_LOG_ENTRY_TYPE))); for(Pair kv: lstControls) { kv.getKey().setSelected(prefs.getPrefBoolean(kv.getValue())); diff --git a/src/main/java/forge/gui/home/settings/VSubmenuPreferences.java b/src/main/java/forge/gui/home/settings/VSubmenuPreferences.java index 4fd7b698d48..48170a144e9 100644 --- a/src/main/java/forge/gui/home/settings/VSubmenuPreferences.java +++ b/src/main/java/forge/gui/home/settings/VSubmenuPreferences.java @@ -13,6 +13,7 @@ import java.util.List; import java.util.Map; import javax.swing.JCheckBox; +import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; @@ -26,6 +27,7 @@ import net.miginfocom.swing.MigLayout; import org.apache.commons.lang3.StringUtils; +import forge.GameLogEntryType; import forge.Singletons; import forge.control.KeyboardShortcuts; import forge.control.KeyboardShortcuts.Shortcut; @@ -36,6 +38,7 @@ import forge.gui.home.EMenuGroup; import forge.gui.home.IVSubmenu; import forge.gui.home.VHomeUI; import forge.gui.toolbox.FCheckBox; +import forge.gui.toolbox.FComboBoxPanel; import forge.gui.toolbox.FLabel; import forge.gui.toolbox.FList; import forge.gui.toolbox.FScrollPane; @@ -92,6 +95,8 @@ public enum VSubmenuPreferences implements IVSubmenu { private final JCheckBox cbStackLand = new OptionsCheckBox("Stack AI Land"); private final JCheckBox cbManaBurn = new OptionsCheckBox("Mana Burn"); private final JCheckBox cbDevMode = new OptionsCheckBox("Developer Mode"); + private final FComboBoxPanel cbpLogEntryType = + new FComboBoxPanel(GameLogEntryType.values(), "Game Log Verbosity:"); private final JCheckBox cbEnforceDeckLegality = new OptionsCheckBox("Deck Conformance"); private final JCheckBox cbCloneImgSource = new OptionsCheckBox("Clones use original card art"); private final JCheckBox cbOverlayCardName = new OptionsCheckBox("Card Name"); @@ -153,6 +158,9 @@ public enum VSubmenuPreferences implements IVSubmenu { pnlPrefs.add(cbDevMode, regularConstraints); pnlPrefs.add(new NoteLabel("Enables menu with functions for testing during development."), regularConstraints); + pnlPrefs.add(cbpLogEntryType, "w 80%!, gap 10% 0 0 10px, span 2 1"); + pnlPrefs.add(new NoteLabel("Changes how much information is displayed in the game log. Sorted by least to most verbose."), regularConstraints); + pnlPrefs.add(cbEnforceDeckLegality, regularConstraints); pnlPrefs.add(new NoteLabel("Enforces deck legality relevant to each environment (minimum deck sizes, max card count etc)"), regularConstraints); @@ -227,7 +235,7 @@ public enum VSubmenuPreferences implements IVSubmenu { scrContent.setBorder(null); } - + public void reloadShortcuts() { for (Map.Entry e : shortcutFields.entrySet()) { e.getValue().reload(e.getKey()); @@ -492,6 +500,11 @@ public enum VSubmenuPreferences implements IVSubmenu { public JCheckBox getCbDevMode() { return cbDevMode; } + + /** @return {@link javax.swing.JComboBox} */ + public JComboBox getCboLogEntryType() { + return cbpLogEntryType.getJComboBox(); + } /** @return {@link javax.swing.JCheckBox} */ public JCheckBox getCbEnforceDeckLegality() { diff --git a/src/main/java/forge/gui/match/views/VLog.java b/src/main/java/forge/gui/match/views/VLog.java index 10d08f07dac..3b88e6d095e 100644 --- a/src/main/java/forge/gui/match/views/VLog.java +++ b/src/main/java/forge/gui/match/views/VLog.java @@ -1,146 +1,143 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Nate - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.gui.match.views; - -import java.util.List; - -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTextArea; -import javax.swing.border.EmptyBorder; - -import net.miginfocom.swing.MigLayout; -import forge.GameLog; -import forge.GameLogEntry; -import forge.GameLogEntryType; -import forge.gui.framework.DragCell; -import forge.gui.framework.DragTab; -import forge.gui.framework.EDocID; -import forge.gui.framework.IVDoc; -import forge.gui.match.controllers.CLog; -import forge.gui.toolbox.FSkin; - -/** - * Assembles Swing components of game log report. - * - *

(V at beginning of class name denotes a view class.) - */ -public enum VLog implements IVDoc { - /** */ - SINGLETON_INSTANCE; - - // Fields used with interface IVDoc - private DragCell parentCell; - private final DragTab tab = new DragTab("Log"); - - // Other fields - private final JPanel pnl = new JPanel(new MigLayout("insets 0, gap 0, wrap")); - private final JScrollPane scroller = new JScrollPane(pnl); - - //========== Constructor - private VLog() { - scroller.setOpaque(false); - scroller.setBorder(null); - scroller.getViewport().setOpaque(false); - - pnl.setOpaque(false); - } - - //========== Overridden methods - /* (non-Javadoc) - * @see forge.gui.framework.IVDoc#populate() - */ - @Override - public void populate() { - // (Panel uses observers to update, no permanent components here.) - } - - /* (non-Javadoc) - * @see forge.gui.framework.IVDoc#setParentCell() - */ - @Override - public void setParentCell(final DragCell cell0) { - this.parentCell = cell0; - } - - /* (non-Javadoc) - * @see forge.gui.framework.IVDoc#getParentCell() - */ - @Override - public DragCell getParentCell() { - return this.parentCell; - } - - /* (non-Javadoc) - * @see forge.gui.framework.IVDoc#getDocumentID() - */ - @Override - public EDocID getDocumentID() { - return EDocID.REPORT_LOG; - } - - /* (non-Javadoc) - * @see forge.gui.framework.IVDoc#getTabLabel() - */ - @Override - public DragTab getTabLabel() { - return tab; - } - - /* (non-Javadoc) - * @see forge.gui.framework.IVDoc#getLayoutControl() - */ - @Override - public CLog getLayoutControl() { - return CLog.SINGLETON_INSTANCE; - } - - //========== Observer update methods - /** - * @param model */ - public void updateConsole(GameLog model) { - // No need to update this unless it's showing - if (!parentCell.getSelected().equals(this)) { return; } - - // TODO - some option to make this configurable is probably desirable - // By default, grab everything log level 3 or less. - final List data = model.getLogEntries(GameLogEntryType.DAMAGE); - final int size = data.size(); - - pnl.removeAll(); - - for (int i = size - 1; i >= 0; i--) { - JTextArea tar = new JTextArea(data.get(i).message); - - if (i % 2 == 1) { tar.setOpaque(false); } - else { tar.setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA)); } - tar.setBorder(new EmptyBorder(2, 2, 2, 2)); - tar.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - - tar.setFocusable(false); - tar.setEditable(false); - tar.setLineWrap(true); - tar.setWrapStyleWord(true); - - pnl.add(tar, "w 98%!, gap 1% 0 0 0"); - } - - parentCell.getBody().setLayout(new MigLayout("insets 0, gap 0, wrap")); - parentCell.getBody().add(scroller, "w 98%!, pushy, growy, gap 1% 0 5px 5px"); - } -} +/* + * Forge: Play Magic: the Gathering. + * Copyright (C) 2011 Nate + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package forge.gui.match.views; + +import java.util.List; + +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.border.EmptyBorder; + +import net.miginfocom.swing.MigLayout; +import forge.GameLog; +import forge.GameLogEntry; +import forge.gui.framework.DragCell; +import forge.gui.framework.DragTab; +import forge.gui.framework.EDocID; +import forge.gui.framework.IVDoc; +import forge.gui.match.controllers.CLog; +import forge.gui.toolbox.FSkin; + +/** + * Assembles Swing components of game log report. + * + *

(V at beginning of class name denotes a view class.) + */ +public enum VLog implements IVDoc { + /** */ + SINGLETON_INSTANCE; + + // Fields used with interface IVDoc + private DragCell parentCell; + private final DragTab tab = new DragTab("Log"); + + // Other fields + private final JPanel pnl = new JPanel(new MigLayout("insets 0, gap 0, wrap")); + private final JScrollPane scroller = new JScrollPane(pnl); + + //========== Constructor + private VLog() { + scroller.setOpaque(false); + scroller.setBorder(null); + scroller.getViewport().setOpaque(false); + + pnl.setOpaque(false); + } + + //========== Overridden methods + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#populate() + */ + @Override + public void populate() { + // (Panel uses observers to update, no permanent components here.) + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#setParentCell() + */ + @Override + public void setParentCell(final DragCell cell0) { + this.parentCell = cell0; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getParentCell() + */ + @Override + public DragCell getParentCell() { + return this.parentCell; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getDocumentID() + */ + @Override + public EDocID getDocumentID() { + return EDocID.REPORT_LOG; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getTabLabel() + */ + @Override + public DragTab getTabLabel() { + return tab; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getLayoutControl() + */ + @Override + public CLog getLayoutControl() { + return CLog.SINGLETON_INSTANCE; + } + + //========== Observer update methods + /** + * @param model */ + public void updateConsole(GameLog model) { + // No need to update this unless it's showing + if (!parentCell.getSelected().equals(this)) { return; } + + final List data = model.getLogEntries(model.getGameLogEntryTypeSetting()); + final int size = data.size(); + + pnl.removeAll(); + + for (int i = size - 1; i >= 0; i--) { + JTextArea tar = new JTextArea(data.get(i).message); + + if (i % 2 == 1) { tar.setOpaque(false); } + else { tar.setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA)); } + tar.setBorder(new EmptyBorder(2, 2, 2, 2)); + tar.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + + tar.setFocusable(false); + tar.setEditable(false); + tar.setLineWrap(true); + tar.setWrapStyleWord(true); + + pnl.add(tar, "w 98%!, gap 1% 0 0 0"); + } + + parentCell.getBody().setLayout(new MigLayout("insets 0, gap 0, wrap")); + parentCell.getBody().add(scroller, "w 98%!, pushy, growy, gap 1% 0 5px 5px"); + } +} diff --git a/src/main/java/forge/gui/toolbox/FComboBoxPanel.java b/src/main/java/forge/gui/toolbox/FComboBoxPanel.java new file mode 100644 index 00000000000..c2b7691309d --- /dev/null +++ b/src/main/java/forge/gui/toolbox/FComboBoxPanel.java @@ -0,0 +1,85 @@ +package forge.gui.toolbox; + +import java.awt.Component; +import java.awt.FlowLayout; +import javax.swing.DefaultListCellRenderer; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.ListCellRenderer; +import javax.swing.border.EmptyBorder; + +/** + * TODO: Write javadoc for this type. + * + */ +@SuppressWarnings("serial") +public class FComboBoxPanel extends JPanel { + + private String comboBoxCaption = ""; + private final JComboBox comboBox; + + public FComboBoxPanel(E[] comboBoxItems, String comboBoxCaption) { + super(); + this.comboBox = new JComboBox(comboBoxItems); + this.comboBoxCaption = comboBoxCaption; + applyLayoutAndSkin(); + } + + public final JComboBox getJComboBox() { + return this.comboBox; + } + + private void applyLayoutAndSkin() { + + FlowLayout panelLayout = new FlowLayout(FlowLayout.LEFT); + panelLayout.setVgap(0); + this.setLayout(panelLayout); + this.setOpaque(false); + + if (this.comboBoxCaption != "") { + JLabel comboLabel; + comboLabel = new JLabel(this.comboBoxCaption); + comboLabel.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + comboLabel.setFont(FSkin.getBoldFont(12)); + this.add(comboLabel); + } + + this.comboBox.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + this.comboBox.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + this.comboBox.setFont(FSkin.getFont(12)); + this.comboBox.setEditable(false); + this.comboBox.setFocusable(true); + this.comboBox.setOpaque(true); + this.comboBox.setRenderer(new ComplexCellRenderer()); + this.add(this.comboBox); + + } + + private class ComplexCellRenderer implements ListCellRenderer { + + private DefaultListCellRenderer defaultRenderer = new DefaultListCellRenderer(); + + /* (non-Javadoc) + * @see javax.swing.ListCellRenderer#getListCellRendererComponent(javax.swing.JList, java.lang.Object, int, boolean, boolean) + */ + @Override + public Component getListCellRendererComponent(JList lst0, E1 val0, int i0, + boolean isSelected, boolean cellHasFocus) { + + JLabel lblItem = (JLabel) defaultRenderer.getListCellRendererComponent( + lst0, val0, i0, isSelected, cellHasFocus); + + lblItem.setBorder(new EmptyBorder(4, 3, 4, 3)); + lblItem.setBackground(FSkin.getColor(hasFocus() ? FSkin.Colors.CLR_ACTIVE : FSkin.Colors.CLR_INACTIVE)); + lblItem.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + lblItem.setFont(FSkin.getFont(12)); + lblItem.setOpaque(isSelected); + return lblItem; + + } + + } + +} diff --git a/src/main/java/forge/properties/ForgePreferences.java b/src/main/java/forge/properties/ForgePreferences.java index 7328ccedc92..e1cb6735344 100644 --- a/src/main/java/forge/properties/ForgePreferences.java +++ b/src/main/java/forge/properties/ForgePreferences.java @@ -21,6 +21,7 @@ import java.util.List; import forge.Constant; import forge.Constant.Preferences; +import forge.GameLogEntryType; import forge.game.ai.AiProfileUtil; import forge.gui.home.EMenuItem; import forge.gui.match.VMatchUI; @@ -74,6 +75,7 @@ public class ForgePreferences extends PreferencesStore { DEV_MODE_ENABLED ("false"), DEV_MILLING_LOSS ("true"), DEV_UNLIMITED_LAND ("false"), + DEV_LOG_ENTRY_TYPE (GameLogEntryType.DAMAGE.toString()), DECKGEN_SINGLETONS ("false"), DECKGEN_ARTIFACTS ("false"),