Settings submenu finished.

Multiple instances of oa2sa method consolidated into GuiUtils.
This commit is contained in:
Doublestrike
2011-12-15 08:51:14 +00:00
parent f0b0d0525b
commit ead16601a3
7 changed files with 136 additions and 108 deletions

View File

@@ -27,6 +27,7 @@ import forge.deck.generate.Generate3ColorDeck;
import forge.deck.generate.Generate5ColorDeck;
import forge.deck.generate.GenerateThemeDeck;
import forge.game.GameType;
import forge.gui.GuiUtils;
import forge.item.CardPrinted;
import forge.view.GuiTopLevel;
import forge.view.home.ViewConstructed;
@@ -396,27 +397,10 @@ public class ControlConstructed {
}
//========= OTHER
/**
* Exhaustively converts object array to string array.
* Probably a much easier way to do this.
*
* @param o0   Object[]
* @return String[]
*/
public String[] oa2sa(Object[] o0) {
String[] output = new String[o0.length];
for (int i = 0; i < o0.length; i++) {
output[i] = o0[i].toString();
}
return output;
}
/** Fired when start button is pressed; checks various conditions from lists and starts game. */
public void start() {
String[] humanSelected = oa2sa(currentHumanSelection.getSelectedValues());
String[] aiSelected = oa2sa(currentAISelection.getSelectedValues());
String[] humanSelected = GuiUtils.oa2sa(currentHumanSelection.getSelectedValues());
String[] aiSelected = GuiUtils.oa2sa(currentAISelection.getSelectedValues());
// Check color-based deck selection for appropriate length
if (currentHumanSelection.getName().equals("lstColorsHuman")) {
@@ -520,8 +504,8 @@ public class ControlConstructed {
}
Deck targetDeck = (player.equals("Human"))
? AllZone.getDeckManager().getDeck(oa2sa(currentHumanSelection.getSelectedValues())[0])
: AllZone.getDeckManager().getDeck(oa2sa(currentAISelection.getSelectedValues())[0]);
? AllZone.getDeckManager().getDeck(GuiUtils.oa2sa(currentHumanSelection.getSelectedValues())[0])
: AllZone.getDeckManager().getDeck(GuiUtils.oa2sa(currentAISelection.getSelectedValues())[0]);
final HashMap<String, Integer> deckMap = new HashMap<String, Integer>();

View File

@@ -84,8 +84,8 @@ public class ControlSealed {
}
}
view.getLstHumanDecks().setListData(oa2sa(humanNames.toArray()));
view.getLstAIDecks().setListData(oa2sa(aiNames.toArray()));
view.getLstHumanDecks().setListData(GuiUtils.oa2sa(humanNames.toArray()));
view.getLstAIDecks().setListData(GuiUtils.oa2sa(aiNames.toArray()));
}
/** */
@@ -155,21 +155,4 @@ public class ControlSealed {
Constant.Runtime.COMPUTER_DECK[0] = aiDeck;
}
/**
* Exhaustively converts object array to string array.
* Probably a much easier way to do this.
*
* @param o0 &emsp; Object[]
* @return String[]
*/
public String[] oa2sa(Object[] o0) {
String[] output = new String[o0.length];
for (int i = 0; i < o0.length; i++) {
output[i] = o0[i].toString();
}
return output;
}
}

View File

@@ -4,23 +4,26 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JRadioButton;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import forge.AllZone;
import forge.Singletons;
import forge.error.ErrorViewer;
import forge.gui.ListChooser;
import forge.properties.ForgePreferences;
import forge.properties.ForgePreferences.CardSizeType;
import forge.properties.ForgePreferences.StackOffsetType;
import forge.view.GuiTopLevel;
import forge.view.home.ViewSettings;
import forge.view.toolbox.FSkin;
/**
* Controls logic and listeners for Settings panel of the home screen.
*
* Saving of preferences happens at every state change in ControlAllUI.
*/
public class ControlSettings {
private ViewSettings view;
private ForgePreferences prefs;
/**
*
@@ -31,6 +34,7 @@ public class ControlSettings {
public ControlSettings(ViewSettings v0) {
this.view = v0;
addListeners();
prefs = Singletons.getModel().getPreferences();
}
/** @return ViewSettings */
@@ -40,12 +44,13 @@ public class ControlSettings {
/** */
public void addListeners() {
/*this.view.getLstChooseSkin().addActionListener(new ActionListener() {
this.view.getLstChooseSkin().addListSelectionListener(new ListSelectionListener() {
@Override
public void actionPerformed(final ActionEvent arg0) {
doChooseSkin();
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting()) { return; }
try { updateSkin(); } catch (Exception e1) { e1.printStackTrace(); }
}
});*/
});
//slapshot5 - work in progress, but I need to check this file in for other changes.
/*
@@ -60,123 +65,117 @@ public class ControlSettings {
this.view.getCbScaleLarger().addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent arg0) {
Singletons.getModel().getPreferences()
.setScaleLargerThanOriginal(ControlSettings.this.view.getCbScaleLarger().isSelected());
prefs.setScaleLargerThanOriginal(ControlSettings.this.view.getCbScaleLarger().isSelected());
try { prefs.save(); } catch (Exception e) { e.printStackTrace(); }
}
});
this.view.getCbDevMode().addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent arg0) {
Singletons.getModel().getPreferences()
.setDeveloperMode(ControlSettings.this.view.getCbDevMode().isSelected());
prefs.setDeveloperMode(ControlSettings.this.view.getCbDevMode().isSelected());
try { prefs.save(); } catch (Exception e) { e.printStackTrace(); }
}
});
this.view.getCbRemoveSmall().addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent arg0) {
Singletons.getModel().getPreferences()
.setDeckGenRmvSmall(ControlSettings.this.view.getCbRemoveSmall().isSelected());
prefs.setDeckGenRmvSmall(ControlSettings.this.view.getCbRemoveSmall().isSelected());
try { prefs.save(); } catch (Exception e) { e.printStackTrace(); }
}
});
this.view.getCbRemoveArtifacts().addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent arg0) {
Singletons.getModel().getPreferences()
.setDeckGenRmvArtifacts(ControlSettings.this.view.getCbRemoveArtifacts().isSelected());
prefs.setDeckGenRmvArtifacts(ControlSettings.this.view.getCbRemoveArtifacts().isSelected());
try { prefs.save(); } catch (Exception e) { e.printStackTrace(); }
}
});
this.view.getCbSingletons().addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent arg0) {
Singletons.getModel().getPreferences()
.setDeckGenSingletons(ControlSettings.this.view.getCbSingletons().isSelected());
prefs.setDeckGenSingletons(ControlSettings.this.view.getCbSingletons().isSelected());
try { prefs.save(); } catch (Exception e) { e.printStackTrace(); }
}
});
this.view.getCbOldUI().addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent arg0) {
Singletons.getModel().getPreferences()
.setOldGui(ControlSettings.this.view.getCbOldUI().isSelected());
prefs.setOldGui(ControlSettings.this.view.getCbOldUI().isSelected());
try { prefs.save(); } catch (Exception e) { e.printStackTrace(); }
}
});
this.view.getCbUploadDraft().addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent arg0) {
Singletons.getModel().getPreferences()
.setUploadDraftAI(ControlSettings.this.view.getCbUploadDraft().isSelected());
prefs.setUploadDraftAI(ControlSettings.this.view.getCbUploadDraft().isSelected());
try { prefs.save(); } catch (Exception e) { e.printStackTrace(); }
}
});
this.view.getCbStackLand().addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent arg0) {
Singletons.getModel().getPreferences()
.setStackAiLand(ControlSettings.this.view.getCbStackLand().isSelected());
prefs.setStackAiLand(ControlSettings.this.view.getCbStackLand().isSelected());
try { prefs.save(); } catch (Exception e) { e.printStackTrace(); }
}
});
this.view.getCbRandomFoil().addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent arg0) {
Singletons.getModel().getPreferences()
.setRandCFoil(ControlSettings.this.view.getCbRandomFoil().isSelected());
prefs.setRandCFoil(ControlSettings.this.view.getCbRandomFoil().isSelected());
try { prefs.save(); } catch (Exception e) { e.printStackTrace(); }
}
});
this.view.getCbTextMana().addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent arg0) {
Singletons.getModel().getPreferences()
.setCardOverlay(ControlSettings.this.view.getCbTextMana().isSelected());
prefs.setCardOverlay(ControlSettings.this.view.getCbTextMana().isSelected());
try { prefs.save(); } catch (Exception e) { e.printStackTrace(); }
}
});
}
private void doChooseSkin() {
final ListChooser<String> ch = new ListChooser<String>("Choose a skin", 0, 1, FSkin.getSkins());
if (ch.show()) {
try {
final String name = ch.getSelectedValue();
final int index = ch.getSelectedIndex();
if (index == -1) {
return;
}
ForgePreferences preferences = Singletons.getModel().getPreferences();
preferences.setSkin(name);
final FSkin skin = new FSkin(name);
AllZone.setSkin(skin);
preferences.save();
private void updateSkin() throws Exception {
String name = view.getLstChooseSkin().getSelectedValue().toString();
FSkin skin = new FSkin(name);
} catch (final Exception ex) {
ErrorViewer.showError(ex);
}
}
}
private void updateSkinList() {
prefs.setSkin(name);
AllZone.setSkin(skin);
((GuiTopLevel) AllZone.getDisplay()).getController().changeState(0);
// This should work, but it doesn't. :| Doublestrike 15-12-11
view.getParentView().showSettingsMenu();
prefs.save();
}
/** @param rad0 &emsp; JRadioButton */
public void updateStackOffset(JRadioButton rad0) {
StackOffsetType sot = StackOffsetType.valueOf(rad0.getText());
/** @param rad0 &emsp; JRadioButton
* @throws Exception */
public void updateStackOffset(JRadioButton rad0) throws Exception {
StackOffsetType sot = StackOffsetType.valueOf(rad0.getText().toLowerCase());
Singletons.getModel().getPreferences().setStackOffset(sot);
prefs.save();
}
/** @param rad0 &emsp; JRadioButton */
public void updateCardSize(JRadioButton rad0) {
/** @param rad0 &emsp; JRadioButton
* @throws Exception */
public void updateCardSize(JRadioButton rad0) throws Exception {
CardSizeType cst = CardSizeType.valueOf(rad0.getText());
Singletons.getModel().getPreferences().setCardSize(cst);
prefs.save();
}
/** @param rad0 &emsp; JRadioButton */
public void updateStackSize(JRadioButton rad0) {
/** @param rad0 &emsp; JRadioButton
* @throws Exception */
public void updateStackSize(JRadioButton rad0) throws Exception {
Singletons.getModel().getPreferences().setMaxStackSize(Integer.parseInt(rad0.getText()));
prefs.save();
}
}

View File

@@ -401,4 +401,21 @@ public final class GuiUtils {
}
return ttf;
}
/**
* Exhaustively converts object array to string array.
* Probably a much easier way to do this.
*
* @param o0 &emsp; Object[]
* @return String[]
*/
public static String[] oa2sa(Object[] o0) {
String[] output = new String[o0.length];
for (int i = 0; i < o0.length; i++) {
output[i] = o0[i].toString();
}
return output;
}
}

View File

@@ -21,6 +21,7 @@ import forge.AllZone;
import forge.control.home.ControlConstructed;
import forge.deck.Deck;
import forge.game.GameType;
import forge.gui.GuiUtils;
import forge.view.toolbox.FSkin;
/**
@@ -55,19 +56,19 @@ public class ViewConstructed extends JPanel {
control = new ControlConstructed(this);
lstColorsHuman = new JList();
lstColorsHuman.setListData(control.oa2sa(control.getColorNames()));
lstColorsHuman.setListData(GuiUtils.oa2sa(control.getColorNames()));
lstColorsAI = new JList();
lstColorsAI.setListData(control.oa2sa(control.getColorNames()));
lstColorsAI.setListData(GuiUtils.oa2sa(control.getColorNames()));
lstDecksHuman = new JList();
lstDecksAI = new JList();
lstThemesHuman = new JList();
lstThemesHuman.setListData(control.oa2sa(control.getThemeNames()));
lstThemesHuman.setListData(GuiUtils.oa2sa(control.getThemeNames()));
lstThemesAI = new JList();
lstThemesAI.setListData(control.oa2sa(control.getThemeNames()));
lstThemesAI.setListData(GuiUtils.oa2sa(control.getThemeNames()));
// Human deck options area
JLabel lblHuman = new JLabel("Choose a deck for the human player:");

View File

@@ -6,6 +6,7 @@ import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.AbstractAction;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JList;
@@ -19,10 +20,11 @@ import net.miginfocom.swing.MigLayout;
import forge.AllZone;
import forge.Singletons;
import forge.control.home.ControlSettings;
import forge.gui.GuiUtils;
import forge.view.toolbox.FSkin;
/**
* TODO: Write javadoc for this type.
* Assembles swing components for "Settings" mode menu.
*
*/
@SuppressWarnings("serial")
@@ -30,6 +32,7 @@ public class ViewSettings extends JScrollPane {
private ControlSettings control;
private FSkin skin;
private JPanel viewport;
private HomeTopLevel parentView;
private JList lstChooseSkin;
private String spacer;
@@ -47,13 +50,14 @@ public class ViewSettings extends JScrollPane {
radCardMedium, radCardLarge, radCardHuge;
/**
*
* TODO: Write javadoc for Constructor.
* Assembles swing components for "Settings" mode menu.
* @param v0 &emsp; HomeTopLevel
*/
public ViewSettings(HomeTopLevel v0) {
super(VERTICAL_SCROLLBAR_ALWAYS, HORIZONTAL_SCROLLBAR_AS_NEEDED);
skin = AllZone.getSkin();
parentView = v0;
viewport = new JPanel();
viewport.setOpaque(false);
@@ -162,6 +166,8 @@ public class ViewSettings extends JScrollPane {
viewport.add(lblNoteSkin, constraints + ", gapbottom 2px");
lstChooseSkin = new JList();
lstChooseSkin.setListData(GuiUtils.oa2sa(FSkin.getSkins().toArray()));
lstChooseSkin.setSelectedValue(Singletons.getModel().getPreferences().getSkin(), true);
viewport.add(new JScrollPane(lstChooseSkin), "gapleft 10%, h 60px!, w 150px!" + spacer);
JLabel lblTitleCardSize = new TitleLabel("Card Size");
@@ -208,6 +214,18 @@ public class ViewSettings extends JScrollPane {
radStack11 = new StackSizeRadio("11");
radStack12 = new StackSizeRadio("12");
ButtonGroup group = new ButtonGroup();
group.add(radStack3);
group.add(radStack4);
group.add(radStack5);
group.add(radStack6);
group.add(radStack7);
group.add(radStack8);
group.add(radStack9);
group.add(radStack10);
group.add(radStack11);
group.add(radStack12);
String constraints = "w 50px!, h 25px!";
radioContainer.add(radStack3, constraints);
radioContainer.add(radStack4, constraints);
@@ -229,6 +247,12 @@ public class ViewSettings extends JScrollPane {
radOffsetMedium = new StackOffsetRadio("Medium");
radOffsetLarge = new StackOffsetRadio("Large");
ButtonGroup group = new ButtonGroup();
group.add(radOffsetTiny);
group.add(radOffsetSmall);
group.add(radOffsetMedium);
group.add(radOffsetLarge);
String constraints = "gapleft 10%, wrap";
viewport.add(radOffsetTiny, constraints);
viewport.add(radOffsetSmall, constraints);
@@ -244,6 +268,14 @@ public class ViewSettings extends JScrollPane {
radCardLarge = new CardSizeRadio("Large");
radCardHuge = new CardSizeRadio("Huge");
ButtonGroup group = new ButtonGroup();
group.add(radCardTiny);
group.add(radCardSmaller);
group.add(radCardSmall);
group.add(radCardMedium);
group.add(radCardLarge);
group.add(radCardHuge);
String constraints = "gapleft 10%, wrap";
viewport.add(radCardTiny, constraints);
viewport.add(radCardSmaller, constraints);
@@ -305,14 +337,16 @@ public class ViewSettings extends JScrollPane {
public StackSizeRadio(String txt0) {
super(txt0);
if(Singletons.getModel().getPreferences().getMaxStackSize() == Integer.parseInt(txt0)) {
if (Singletons.getModel().getPreferences().getMaxStackSize()
== Integer.parseInt(txt0)) {
setSelected(true);
}
this.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent arg0) {
control.updateStackSize(StackSizeRadio.this);
try { control.updateStackSize(StackSizeRadio.this); }
catch (Exception e) { e.printStackTrace(); }
}
});
}
@@ -321,14 +355,16 @@ public class ViewSettings extends JScrollPane {
private class StackOffsetRadio extends OptionsRadio {
public StackOffsetRadio(String txt0) {
super(txt0);
if(Singletons.getModel().getPreferences().getStackOffset().toString() == txt0) {
if (Singletons.getModel().getPreferences().getStackOffset()
.toString().equalsIgnoreCase(txt0)) {
setSelected(true);
}
this.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent arg0) {
control.updateStackOffset(StackOffsetRadio.this);
try { control.updateStackOffset(StackOffsetRadio.this); }
catch (Exception e) { e.printStackTrace(); }
}
});
}
@@ -337,14 +373,16 @@ public class ViewSettings extends JScrollPane {
private class CardSizeRadio extends OptionsRadio {
public CardSizeRadio(String txt0) {
super(txt0);
if(Singletons.getModel().getPreferences().getCardSize().toString() == txt0) {
if (Singletons.getModel().getPreferences().getCardSize()
.toString().equalsIgnoreCase(txt0)) {
setSelected(true);
}
this.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent arg0) {
control.updateCardSize(CardSizeRadio.this);
try { control.updateCardSize(CardSizeRadio.this); }
catch (Exception e) { e.printStackTrace(); }
}
});
}
@@ -432,4 +470,9 @@ public class ViewSettings extends JScrollPane {
public ControlSettings getController() {
return ViewSettings.this.control;
}
/** @return HomeTopLevel */
public HomeTopLevel getParentView() {
return parentView;
}
}

View File

@@ -46,7 +46,7 @@ public class FSkin {
private Map<String, Image> images;
private Font font1 = null;
private final String name = "default";
private String name = "default";
private final String spriteFile = "";
private final String font1file = "font1.ttf";
private Font tempFont;
@@ -95,6 +95,7 @@ public class FSkin {
* the exception
*/
public FSkin(final String skinName) throws Exception {
this.name = skinName;
this.loadFontAndImages(skinName);
}