Fixed double listener bug in tabber.

Added toggle to "unlimited lands" button.
This commit is contained in:
Doublestrike
2011-12-12 07:40:43 +00:00
parent c72048692d
commit 1a996cfb95
3 changed files with 150 additions and 82 deletions

View File

@@ -35,6 +35,8 @@ import forge.view.match.ViewTabber;
*/
public class ControlTabber extends MyObservable {
private final ViewTabber view;
private MouseAdapter maMilling, maHand, maLibrary, maUnlimited,
maMana, maSetup, maTutor, maCounter, maTap, maUntap, maLife;
/**
* Controls the vertical tabber in sidebar used for viewing gameplay data:
@@ -45,6 +47,7 @@ public class ControlTabber extends MyObservable {
*/
public ControlTabber(final ViewTabber v) {
this.view = v;
if (Singletons.getModel().getPreferences().isMillingLossCondition()) {
this.view.getLblMilling().setEnabled(true);
} else {
@@ -62,6 +65,15 @@ public class ControlTabber extends MyObservable {
} else {
this.view.getLblLibraryView().setEnabled(false);
}
if (Singletons.getModel().getPreferences().getUnlimitedLand()) {
this.view.getLblUnlimitedLands().setEnabled(true);
} else {
this.view.getLblUnlimitedLands().setEnabled(false);
}
// Various mouse adapters for dev buttons
initMouseAdapters();
}
/** Adds observers to tabber. */
@@ -89,98 +101,48 @@ public class ControlTabber extends MyObservable {
/** Adds listeners to various components in tabber. */
public void addListeners() {
// Milling enable toggle
this.view.getLblMilling().addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
ControlTabber.this.view.getLblMilling().toggleEnabled();
}
});
this.view.getLblMilling().removeMouseListener(maMilling);
this.view.getLblMilling().addMouseListener(maMilling);
// View any hand toggle
this.view.getLblHandView().addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
ControlTabber.this.view.getLblHandView().toggleEnabled();
}
});
this.view.getLblHandView().removeMouseListener(maHand);
this.view.getLblHandView().addMouseListener(maHand);
// DevMode: View any library toggle
this.view.getLblLibraryView().addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
ControlTabber.this.view.getLblLibraryView().toggleEnabled();
}
});
this.view.getLblLibraryView().removeMouseListener(maLibrary);
this.view.getLblLibraryView().addMouseListener(maLibrary);
// DevMode: Play unlimited land this turn toggle
this.view.getLblUnlimitedLands().addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
GuiDisplayUtil.devModeUnlimitedLand();
// TODO: Enable toggle for this (e.g. Unlimited land each turn:
// enabled)
// Also must change enabled/disabled text in ViewTabber to
// reflect this.
// view.getLblUnlimitedLands().toggleEnabled();
}
});
this.view.getLblUnlimitedLands().removeMouseListener(maUnlimited);
this.view.getLblUnlimitedLands().addMouseListener(maUnlimited);
// DevMode: Generate mana
this.view.getLblGenerateMana().addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
GuiDisplayUtil.devModeGenerateMana();
}
});
this.view.getLblGenerateMana().removeMouseListener(maMana);
this.view.getLblGenerateMana().addMouseListener(maMana);
// DevMode: Battlefield setup
this.view.getLblSetupGame().addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
GuiDisplayUtil.devSetupGameState();
}
});
this.view.getLblSetupGame().removeMouseListener(maSetup);
this.view.getLblSetupGame().addMouseListener(maSetup);
// DevMode: Tutor for card
this.view.getLblTutor().addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
GuiDisplayUtil.devModeTutor();
}
});
this.view.getLblTutor().removeMouseListener(maTutor);
this.view.getLblTutor().addMouseListener(maTutor);
// DevMode: Add counter to permanent
this.view.getLblCounterPermanent().addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
GuiDisplayUtil.devModeAddCounter();
}
});
this.view.getLblCounterPermanent().removeMouseListener(maCounter);
this.view.getLblCounterPermanent().addMouseListener(maCounter);
// DevMode: Tap permanent
this.view.getLblTapPermanent().addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
GuiDisplayUtil.devModeTapPerm();
}
});
this.view.getLblTapPermanent().removeMouseListener(maTap);
this.view.getLblTapPermanent().addMouseListener(maTap);
// DevMode: Untap permanent
this.view.getLblUntapPermanent().addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
GuiDisplayUtil.devModeUntapPerm();
}
});
this.view.getLblUntapPermanent().removeMouseListener(maUntap);
this.view.getLblUntapPermanent().addMouseListener(maUntap);
// DevMode: Set human life
this.view.getLblHumanLife().addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
GuiDisplayUtil.devModeSetLife();
}
});
// DevMode: Set life
this.view.getLblSetLife().removeMouseListener(maLife);
this.view.getLblSetLife().addMouseListener(maLife);
}
/**
@@ -230,4 +192,86 @@ public class ControlTabber extends MyObservable {
public void showPnlStack() {
this.view.getVtpTabber().showTab(0);
}
/** Simple method that inits the mouse adapters for listeners,
* here to simplify life in the constructor.
*/
private void initMouseAdapters() {
maMilling = new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
ControlTabber.this.view.getLblMilling().toggleEnabled();
}
};
maHand = new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
ControlTabber.this.view.getLblHandView().toggleEnabled();
}
};
maLibrary = new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
ControlTabber.this.view.getLblLibraryView().toggleEnabled();
}
};
maUnlimited = new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
ControlTabber.this.view.getLblUnlimitedLands().toggleEnabled();
}
};
maMana = new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
GuiDisplayUtil.devModeGenerateMana();
}
};
maSetup = new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
GuiDisplayUtil.devSetupGameState();
}
};
maTutor = new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
GuiDisplayUtil.devModeTutor();
}
};
maCounter = new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
GuiDisplayUtil.devModeAddCounter();
}
};
maTap = new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
GuiDisplayUtil.devModeTapPerm();
}
};
maUntap = new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
GuiDisplayUtil.devModeUntapPerm();
}
};
maLife = new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
GuiDisplayUtil.devModeSetLife();
}
};
}
}

View File

@@ -55,6 +55,9 @@ public class ForgePreferences extends Preferences {
/** Library view toggle. */
private boolean libraryView;
/** Unlimited land toggle. */
private boolean unlimitedLand;
/** Developer mode. */
private boolean developerMode;
@@ -146,6 +149,7 @@ public class ForgePreferences extends Preferences {
this.setMillingLossCondition(this.getBoolean("loss.condition.milling", true));
this.setHandView(this.getBoolean("developer.handview", true));
this.setLibraryView(this.getBoolean("developer.libraryview", true));
this.setUnlimitedLand(this.getBoolean("developer.unlimitedland", true));
this.setDeveloperMode(this.getBoolean("developer.mode", false));
this.setUploadDraftAI(this.getBoolean("upload.Draft.AI", true));
@@ -221,6 +225,7 @@ public class ForgePreferences extends Preferences {
this.set("loss.condition.milling", this.isMillingLossCondition());
this.set("developer.handview", this.getHandView());
this.set("developer.libraryview", this.getLibraryView());
this.set("developer.unlimitedland", this.getUnlimitedLand());
this.set("developer.mode", this.isDeveloperMode());
this.set("upload.Draft.AI", this.isUploadDraftAI());
@@ -415,6 +420,25 @@ public class ForgePreferences extends Preferences {
this.libraryView = b0;
}
/**
* Determines if "unlimited land" option in dev mode is enabled or not.
*
* @return boolean
*/
public boolean getUnlimitedLand() {
return this.unlimitedLand;
}
/**
* Determines if "unlimited land" option in dev mode is enabled or not.
*
* @param b0
*   boolean
*/
public void setUnlimitedLand(final boolean b0) {
this.unlimitedLand = b0;
}
/**
* Sets the upload draft ai.
*

View File

@@ -82,7 +82,7 @@ public class ViewTabber extends FRoundedPanel {
private final FPanel pnlStack, pnlCombat, pnlConsole, pnlPlayers, pnlDev;
private DevLabel lblMilling, lblHandView, lblLibraryView, lblGenerateMana, lblSetupGame, lblTutor,
lblCounterPermanent, lblTapPermanent, lblUntapPermanent, lblUnlimitedLands, lblHumanLife;
lblCounterPermanent, lblTapPermanent, lblUntapPermanent, lblUnlimitedLands, lblSetLife;
private final FVerticalTabPanel vtpTabber;
@@ -542,8 +542,8 @@ public class ViewTabber extends FRoundedPanel {
*
* @return DevLabel
*/
public DevLabel getLblHumanLife() {
return this.lblHumanLife;
public DevLabel getLblSetLife() {
return this.lblSetLife;
}
/**
@@ -602,39 +602,39 @@ public class ViewTabber extends FRoundedPanel {
lblMilling = new DevLabel("Loss by Milling: Enabled", "Loss by Milling: Disabled");
lblHandView = new DevLabel("View Any Hand: Enabled", "View Any Hand: Disabled");
lblLibraryView = new DevLabel("View Any Library: Enabled", "View Any Library: Disabled");
lblUnlimitedLands = new DevLabel("Play Unlimited Lands This Turn: Enabled", "Play Unlimited Lands This Turn: Disabled");
lblGenerateMana = new DevLabel("Generate Mana");
lblSetupGame = new DevLabel("Setup Game State");
lblTutor = new DevLabel("Tutor for Card");
lblCounterPermanent = new DevLabel("Add Counter to Permanent");
lblTapPermanent = new DevLabel("Tap Permanent");
lblUntapPermanent = new DevLabel("Untap Permanent");
lblUnlimitedLands = new DevLabel("Play Unlimited Lands This Turn");
lblHumanLife = new DevLabel("Set Player Life");
lblSetLife = new DevLabel("Set Player Life");
devLBLs.add(lblMilling);
devLBLs.add(lblHandView);
devLBLs.add(lblLibraryView);
devLBLs.add(lblUnlimitedLands);
devLBLs.add(lblGenerateMana);
devLBLs.add(lblSetupGame);
devLBLs.add(lblTutor);
devLBLs.add(lblCounterPermanent);
devLBLs.add(lblTapPermanent);
devLBLs.add(lblUntapPermanent);
devLBLs.add(lblUnlimitedLands);
devLBLs.add(lblHumanLife);
devLBLs.add(lblSetLife);
final String constraints = "w 95%!, gap 0 0 5px 0";
viewport.add(this.lblMilling, constraints);
viewport.add(this.lblHandView, constraints);
viewport.add(this.lblLibraryView, constraints);
viewport.add(this.lblUnlimitedLands, constraints);
viewport.add(this.lblGenerateMana, constraints);
viewport.add(this.lblSetupGame, constraints);
viewport.add(this.lblTutor, constraints);
viewport.add(this.lblCounterPermanent, constraints);
viewport.add(this.lblTapPermanent, constraints);
viewport.add(this.lblUntapPermanent, constraints);
viewport.add(this.lblUnlimitedLands, constraints);
viewport.add(this.lblHumanLife, constraints);
viewport.add(this.lblSetLife, constraints);
}
/** Assembles swing components for "console" panel. */