mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
Allow restoring previous formats/sets after opening choose sets screen
This commit is contained in:
@@ -33,6 +33,7 @@ import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
|
|||||||
|
|
||||||
public abstract class FormatFilter<T extends InventoryItem> extends ItemFilter<T> {
|
public abstract class FormatFilter<T extends InventoryItem> extends ItemFilter<T> {
|
||||||
protected GameFormat format;
|
protected GameFormat format;
|
||||||
|
private String selectedFormat;
|
||||||
private FComboBox<Object> cbxFormats = new FComboBox<Object>();
|
private FComboBox<Object> cbxFormats = new FComboBox<Object>();
|
||||||
|
|
||||||
public FormatFilter(ItemManager<? super T> itemManager0) {
|
public FormatFilter(ItemManager<? super T> itemManager0) {
|
||||||
@@ -45,10 +46,15 @@ public abstract class FormatFilter<T extends InventoryItem> extends ItemFilter<T
|
|||||||
}
|
}
|
||||||
cbxFormats.addItem("Choose Sets...");
|
cbxFormats.addItem("Choose Sets...");
|
||||||
cbxFormats.setSelectedIndex(0);
|
cbxFormats.setSelectedIndex(0);
|
||||||
|
selectedFormat = cbxFormats.getText();
|
||||||
|
|
||||||
cbxFormats.setChangedHandler(new FEventHandler() {
|
cbxFormats.setChangedHandler(new FEventHandler() {
|
||||||
|
private boolean preventHandling = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleEvent(FEvent e) {
|
public void handleEvent(FEvent e) {
|
||||||
|
if (preventHandling) { return; }
|
||||||
|
|
||||||
int index = cbxFormats.getSelectedIndex();
|
int index = cbxFormats.getSelectedIndex();
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
//Do nothing when index set to -1
|
//Do nothing when index set to -1
|
||||||
@@ -58,7 +64,9 @@ public abstract class FormatFilter<T extends InventoryItem> extends ItemFilter<T
|
|||||||
applyChange();
|
applyChange();
|
||||||
}
|
}
|
||||||
else if (index == cbxFormats.getItemCount() - 1) {
|
else if (index == cbxFormats.getItemCount() - 1) {
|
||||||
cbxFormats.setSelectedIndex(-1);
|
preventHandling = true;
|
||||||
|
cbxFormats.setText(selectedFormat); //restore previous selection by default
|
||||||
|
preventHandling = false;
|
||||||
Forge.openScreen(new MultiSetSelect());
|
Forge.openScreen(new MultiSetSelect());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -69,6 +77,12 @@ public abstract class FormatFilter<T extends InventoryItem> extends ItemFilter<T
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void applyChange() {
|
||||||
|
selectedFormat = cbxFormats.getText(); //backup current text
|
||||||
|
super.applyChange();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reset() {
|
public void reset() {
|
||||||
format = null;
|
format = null;
|
||||||
@@ -167,9 +181,6 @@ public abstract class FormatFilter<T extends InventoryItem> extends ItemFilter<T
|
|||||||
cbxFormats.setText(TextUtil.join(setCodes, ", "));
|
cbxFormats.setText(TextUtil.join(setCodes, ", "));
|
||||||
applyChange();
|
applyChange();
|
||||||
}
|
}
|
||||||
else { //if nothing selected, switch to All Sets item
|
|
||||||
cbxFormats.setSelectedIndex(0);
|
|
||||||
}
|
|
||||||
super.onClose(canCloseCallback);
|
super.onClose(canCloseCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user