Separated the historic format selector UI for android from the filter class so that it can also be used to select any format for quest pools

This commit is contained in:
austinio7116
2018-04-16 20:17:19 +01:00
committed by maustin
parent defaebd064
commit ad6f26f6a9
3 changed files with 186 additions and 133 deletions

View File

@@ -62,7 +62,16 @@ public abstract class FormatFilter<T extends InventoryItem> extends ItemFilter<T
preventHandling = true;
cbxFormats.setText(selectedFormat); //restore previous selection by default
preventHandling = false;
Forge.openScreen(new HistoricFormatSelect());
HistoricFormatSelect historicFormatSelect = new HistoricFormatSelect();
historicFormatSelect.setOnCloseCallBack(new Runnable(){
@Override
public void run() {
format = historicFormatSelect.getSelectedFormat();
cbxFormats.setText(format.getName());
applyChange();
}
});
Forge.openScreen(historicFormatSelect);
}
else if (index == cbxFormats.getItemCount() - 1) {
preventHandling = true;
@@ -112,113 +121,6 @@ public abstract class FormatFilter<T extends InventoryItem> extends ItemFilter<T
cbxFormats.setSize(width, height);
}
private class HistoricFormatSelect extends FScreen {
private GameFormat selectedFormat;
private final FGroupList<GameFormat> lstFormats = add(new FGroupList<GameFormat>());
private final Set<GameFormat.FormatSubType> historicSubTypes = new HashSet<>(Arrays.asList(GameFormat.FormatSubType.Block,
GameFormat.FormatSubType.Standard,GameFormat.FormatSubType.Extended,GameFormat.FormatSubType.Modern,
GameFormat.FormatSubType.Legacy, GameFormat.FormatSubType.Vintage));
private HistoricFormatSelect() {
super("Choose Format");
for (GameFormat.FormatType group:GameFormat.FormatType.values()){
if (group == GameFormat.FormatType.Historic){
for (GameFormat.FormatSubType subgroup:GameFormat.FormatSubType.values()){
if (historicSubTypes.contains(subgroup)){
lstFormats.addGroup(group.name() + "-" + subgroup.name());
}
}
}else {
lstFormats.addGroup(group.name());
}
}
for (GameFormat format: FModel.getFormats().getOrderedList()){
switch(format.getFormatType()){
case Sanctioned:
lstFormats.addItem(format, 0);
break;
case Casual:
lstFormats.addItem(format, 1);
break;
case Historic:
switch (format.getFormatSubType()){
case Block:
lstFormats.addItem(format, 2);
break;
case Standard:
lstFormats.addItem(format, 3);
break;
case Extended:
lstFormats.addItem(format, 4);
break;
case Modern:
lstFormats.addItem(format, 5);
break;
case Legacy:
lstFormats.addItem(format, 6);
break;
case Vintage:
lstFormats.addItem(format, 7);
break;
}
break;
case Digital:
lstFormats.addItem(format, 8);
break;
case Custom:
lstFormats.addItem(format, 9);
}
}
lstFormats.setListItemRenderer(new FormatRenderer());
}
@Override
public void onClose(Callback<Boolean> canCloseCallback) {
if (selectedFormat != null) {
format = selectedFormat;
cbxFormats.setText(selectedFormat.getName());
applyChange();
}
super.onClose(canCloseCallback);
}
@Override
protected void doLayout(float startY, float width, float height) {
lstFormats.setBounds(0, startY, width, height - startY);
}
private class FormatRenderer extends FList.ListItemRenderer<GameFormat>{
@Override
public float getItemHeight() {
return Utils.AVG_FINGER_HEIGHT;
}
@Override
public boolean tap(Integer index, GameFormat value, float x, float y, int count) {
selectedFormat=value;
Forge.back();
return true;
}
@Override
public void drawValue(Graphics g, Integer index, GameFormat value, FSkinFont font, FSkinColor foreColor, FSkinColor backColor, boolean pressed, float x, float y, float w, float h) {
float offset = SettingsScreen.getInsets(w) - FList.PADDING; //increase padding for settings items
x += offset;
y += offset;
w -= 2 * offset;
h -= 2 * offset;
float textHeight = h;
h *= 0.66f;
g.drawText(value.toString(), font, foreColor, x, y, w - h - FList.PADDING, textHeight, false, HAlignment.LEFT, true);
x += w - h;
y += (textHeight - h) / 2;
}
}
}
private class MultiSetSelect extends FScreen {
private final Set<CardEdition> selectedSets = new HashSet<CardEdition>();
private final FGroupList<CardEdition> lstSets = add(new FGroupList<CardEdition>());

View File

@@ -0,0 +1,141 @@
package forge.itemmanager.filters;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import forge.Forge;
import forge.Graphics;
import forge.assets.FSkinColor;
import forge.assets.FSkinFont;
import forge.game.GameFormat;
import forge.model.FModel;
import forge.screens.FScreen;
import forge.screens.settings.SettingsScreen;
import forge.toolbox.FGroupList;
import forge.toolbox.FList;
import forge.util.Callback;
import forge.util.Utils;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
/**
* Created by maustin on 16/04/2018.
*/
public class HistoricFormatSelect extends FScreen {
private GameFormat selectedFormat;
private final FGroupList<GameFormat> lstFormats = add(new FGroupList<GameFormat>());
private final Set<GameFormat.FormatSubType> historicSubTypes = new HashSet<>(Arrays.asList(GameFormat.FormatSubType.Block,
GameFormat.FormatSubType.Standard,GameFormat.FormatSubType.Extended,GameFormat.FormatSubType.Modern,
GameFormat.FormatSubType.Legacy, GameFormat.FormatSubType.Vintage));
private Runnable onCloseCallBack;
public HistoricFormatSelect() {
super("Choose Format");
for (GameFormat.FormatType group:GameFormat.FormatType.values()){
if (group == GameFormat.FormatType.Historic){
for (GameFormat.FormatSubType subgroup:GameFormat.FormatSubType.values()){
if (historicSubTypes.contains(subgroup)){
lstFormats.addGroup(group.name() + "-" + subgroup.name());
}
}
}else {
lstFormats.addGroup(group.name());
}
}
for (GameFormat format: FModel.getFormats().getOrderedList()){
switch(format.getFormatType()){
case Sanctioned:
lstFormats.addItem(format, 0);
break;
case Casual:
lstFormats.addItem(format, 1);
break;
case Historic:
switch (format.getFormatSubType()){
case Block:
lstFormats.addItem(format, 2);
break;
case Standard:
lstFormats.addItem(format, 3);
break;
case Extended:
lstFormats.addItem(format, 4);
break;
case Modern:
lstFormats.addItem(format, 5);
break;
case Legacy:
lstFormats.addItem(format, 6);
break;
case Vintage:
lstFormats.addItem(format, 7);
break;
}
break;
case Digital:
lstFormats.addItem(format, 8);
break;
case Custom:
lstFormats.addItem(format, 9);
}
}
lstFormats.setListItemRenderer(new FormatRenderer());
}
public GameFormat getSelectedFormat() {
return selectedFormat;
}
public void setOnCloseCallBack(Runnable onCloseCallBack) {
this.onCloseCallBack = onCloseCallBack;
}
@Override
public void onClose(Callback<Boolean> canCloseCallback) {
if (selectedFormat != null) {
if (onCloseCallBack != null) {
onCloseCallBack.run();
}
}
super.onClose(canCloseCallback);
}
@Override
protected void doLayout(float startY, float width, float height) {
lstFormats.setBounds(0, startY, width, height - startY);
}
private class FormatRenderer extends FList.ListItemRenderer<GameFormat>{
@Override
public float getItemHeight() {
return Utils.AVG_FINGER_HEIGHT;
}
@Override
public boolean tap(Integer index, GameFormat value, float x, float y, int count) {
selectedFormat=value;
Forge.back();
return true;
}
@Override
public void drawValue(Graphics g, Integer index, GameFormat value, FSkinFont font, FSkinColor foreColor, FSkinColor backColor, boolean pressed, float x, float y, float w, float h) {
float offset = SettingsScreen.getInsets(w) - FList.PADDING; //increase padding for settings items
x += offset;
y += offset;
w -= 2 * offset;
h -= 2 * offset;
float textHeight = h;
h *= 0.66f;
g.drawText(value.toString(), font, foreColor, x, y, w - h - FList.PADDING, textHeight, false, BitmapFont.HAlignment.LEFT, true);
x += w - h;
y += (textHeight - h) / 2;
}
}
}

View File

@@ -3,6 +3,7 @@ package forge.screens.quest;
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
import forge.FThreads;
import forge.Forge;
import forge.UiCommand;
import forge.assets.FSkinFont;
import forge.assets.FSkinImage;
@@ -13,6 +14,7 @@ import forge.deck.DeckSection;
import forge.game.GameFormat;
import forge.item.PaperCard;
import forge.item.PreconDeck;
import forge.itemmanager.filters.HistoricFormatSelect;
import forge.model.CardCollections;
import forge.model.FModel;
import forge.properties.ForgeConstants;
@@ -129,7 +131,7 @@ public class NewQuestScreen extends FScreen {
private final FLabel lblCustomDeck = scroller.add(new FLabel.Builder().text("Custom deck:").build());
private final FComboBox<Deck> cbxCustomDeck = scroller.add(new FComboBox<Deck>());
private final FLabel btnDefineCustomFormat = scroller.add(new FLabel.ButtonBuilder().text("Define custom format").build());
private final FLabel btnSelectFormat = scroller.add(new FLabel.ButtonBuilder().text("Choose format").build());
private final FLabel lblPoolDistribution = scroller.add(new FLabel.Builder().text("Starting pool distribution:").build());
private final FRadioButton radBalanced = scroller.add(new FRadioButton("Balanced"));
@@ -160,7 +162,7 @@ public class NewQuestScreen extends FScreen {
private final FLabel lblPrizeUnrestricted = scroller.add(new FLabel.Builder().align(HAlignment.RIGHT).font(FSkinFont.get(12)).text("All cards will be available to win.").build());
private final FLabel lblPrizeSameAsStarting = scroller.add(new FLabel.Builder().align(HAlignment.RIGHT).font(FSkinFont.get(12)).text("Only sets found in starting pool will be available.").build());
private final FLabel btnPrizeDefineCustomFormat = scroller.add(new FLabel.ButtonBuilder().text("Define custom format").build());
private final FLabel btnPrizeSelectFormat = scroller.add(new FLabel.ButtonBuilder().text("Choose format").build());
private final FCheckBox cbAllowUnlocks = scroller.add(new FCheckBox("Allow unlock of additional editions"));
private final FCheckBox cbFantasy = scroller.add(new FCheckBox("Fantasy Mode"));
@@ -184,7 +186,7 @@ public class NewQuestScreen extends FScreen {
cbxStartingPool.addItem(StartingPoolType.Complete);
cbxStartingPool.addItem(StartingPoolType.Sanctioned);
cbxStartingPool.addItem(StartingPoolType.CustomFormat);
cbxStartingPool.addItem(StartingPoolType.Casual);
cbxStartingPool.addItem(StartingPoolType.Precon);
cbxStartingPool.addItem(StartingPoolType.DraftDeck);
cbxStartingPool.addItem(StartingPoolType.SealedDeck);
@@ -200,7 +202,7 @@ public class NewQuestScreen extends FScreen {
cbxPrizedCards.addItem("Same as starting pool");
cbxPrizedCards.addItem(StartingPoolType.Complete);
cbxPrizedCards.addItem(StartingPoolType.Sanctioned);
cbxPrizedCards.addItem(StartingPoolType.CustomFormat);
cbxPrizedCards.addItem(StartingPoolType.Casual);
cbxPrizedCards.setChangedHandler(new FEventHandler() {
@Override
public void handleEvent(FEvent e) {
@@ -209,7 +211,7 @@ public class NewQuestScreen extends FScreen {
}
});
for (GameFormat gf : FModel.getFormats().getOrderedList()) {
for (GameFormat gf : FModel.getFormats().getSanctionedList()) {
cbxFormat.addItem(gf);
cbxPrizeFormat.addItem(gf);
}
@@ -275,12 +277,6 @@ public class NewQuestScreen extends FScreen {
preconDescriptions.put(name, description);
}
//TODO: Support defining custom format
btnDefineCustomFormat.setEnabled(false);
btnDefineCustomFormat.setVisible(false);
btnPrizeDefineCustomFormat.setEnabled(false);
btnPrizeDefineCustomFormat.setVisible(false);
// disable the very powerful sets -- they can be unlocked later for a high price
final List<String> unselectableSets = new ArrayList<>();
unselectableSets.add("LEA");
@@ -290,31 +286,43 @@ public class NewQuestScreen extends FScreen {
unselectableSets.add("ARC");
unselectableSets.add("PC2");
btnDefineCustomFormat.setCommand(new FEventHandler() {
btnSelectFormat.setCommand(new FEventHandler() {
@Override
public void handleEvent(FEvent e) {
/*final DialogChooseSets dialog = new DialogChooseSets(customFormatCodes, unselectableSets, false);
dialog.setOkCallback(new Runnable() {
HistoricFormatSelect historicFormatSelect = new HistoricFormatSelect();
historicFormatSelect.setOnCloseCallBack(new Runnable() {
@Override
public void run() {
customFormatCodes.clear();
customFormatCodes.addAll(dialog.getSelectedSets());
List<String> setsToAdd = historicFormatSelect.getSelectedFormat().getAllowedSetCodes();
for (String setName:setsToAdd){
if(!unselectableSets.contains(setName)){
customFormatCodes.add(setName);
}
}
}
});*/
});
Forge.openScreen(historicFormatSelect);
}
});
btnPrizeDefineCustomFormat.setCommand(new FEventHandler() {
btnPrizeSelectFormat.setCommand(new FEventHandler() {
@Override
public void handleEvent(FEvent e) {
/*final DialogChooseSets dialog = new DialogChooseSets(customPrizeFormatCodes, unselectableSets, false);
dialog.setOkCallback(new Runnable() {
HistoricFormatSelect historicFormatSelect = new HistoricFormatSelect();
historicFormatSelect.setOnCloseCallBack(new Runnable() {
@Override
public void run() {
customPrizeFormatCodes.clear();
customPrizeFormatCodes.addAll(dialog.getSelectedSets());
List<String> setsToAdd = historicFormatSelect.getSelectedFormat().getAllowedSetCodes();
for (String setName:setsToAdd){
if(!unselectableSets.contains(setName)){
customPrizeFormatCodes.add(setName);
}
}
}
});*/
});
Forge.openScreen(historicFormatSelect);
}
});
@@ -334,7 +342,7 @@ public class NewQuestScreen extends FScreen {
lblFormat.setVisible(newVal == StartingPoolType.Sanctioned);
cbxFormat.setVisible(newVal == StartingPoolType.Sanctioned);
btnDefineCustomFormat.setVisible(newVal == StartingPoolType.CustomFormat);
btnSelectFormat.setVisible(newVal == StartingPoolType.Casual);
boolean usesDeckList = newVal == StartingPoolType.SealedDeck || newVal == StartingPoolType.DraftDeck || newVal == StartingPoolType.Cube;
lblCustomDeck.setVisible(usesDeckList);
@@ -372,7 +380,7 @@ public class NewQuestScreen extends FScreen {
lblPrizeFormat.setVisible(newVal == StartingPoolType.Sanctioned);
cbxPrizeFormat.setVisible(newVal == StartingPoolType.Sanctioned);
btnPrizeDefineCustomFormat.setVisible(newVal == StartingPoolType.CustomFormat);
btnPrizeSelectFormat.setVisible(newVal == StartingPoolType.Casual);
lblPrizeSameAsStarting.setVisible(newVal == null);
scroller.revalidate();
@@ -480,7 +488,7 @@ public class NewQuestScreen extends FScreen {
}
public GameFormat getRotatingFormat() {
public GameFormat getSanctionedFormat() {
return cbxFormat.getSelectedItem();
}
@@ -506,9 +514,10 @@ public class NewQuestScreen extends FScreen {
if (worldFormat == null) {
switch(getStartingPoolType()) {
case Sanctioned:
fmtStartPool = getRotatingFormat();
fmtStartPool = getSanctionedFormat();
break;
case Casual:
case CustomFormat:
if (customFormatCodes.isEmpty()) {
if (!SOptionPane.showConfirmDialog(
@@ -569,6 +578,7 @@ public class NewQuestScreen extends FScreen {
case Complete:
fmtPrizes = null;
break;
case Casual:
case CustomFormat:
if (customPrizeFormatCodes.isEmpty()) {
if (!SOptionPane.showConfirmDialog(