Archived
0

add illegal only option to vendor filter

This commit is contained in:
Mo
2016-04-16 16:58:17 +03:00
parent 89c2c46365
commit 2981909d02
7 changed files with 27 additions and 4 deletions

View File

@@ -33,6 +33,8 @@ public class VendorFilterController {
private CheckBox cbDontBuy; private CheckBox cbDontBuy;
@FXML @FXML
private CheckBox cbSkipIllegal; private CheckBox cbSkipIllegal;
@FXML
private CheckBox cbIllegalOnly;
private VendorFilter filter; private VendorFilter filter;
private Dialog<VendorFilter> dlg; private Dialog<VendorFilter> dlg;
@@ -89,6 +91,7 @@ public class VendorFilterController {
private void fill(VendorFilter filter){ private void fill(VendorFilter filter){
this.filter = filter; this.filter = filter;
cbIllegalOnly.setSelected(filter.isIllegalOnly());
cbSkipIllegal.setSelected(filter.isSkipIllegal()); cbSkipIllegal.setSelected(filter.isSkipIllegal());
cbDontSell.setSelected(filter.isDontSell()); cbDontSell.setSelected(filter.isDontSell());
cbDontBuy.setSelected(filter.isDontBuy()); cbDontBuy.setSelected(filter.isDontBuy());
@@ -112,6 +115,7 @@ public class VendorFilterController {
private void save() { private void save() {
LOG.trace("Old filter", filter); LOG.trace("Old filter", filter);
filter.setIllegalOnly(cbIllegalOnly.isSelected());
filter.setSkipIllegal(cbSkipIllegal.isSelected()); filter.setSkipIllegal(cbSkipIllegal.isSelected());
filter.dontSell(cbDontSell.isSelected()); filter.dontSell(cbDontSell.isSelected());
filter.dontBuy(cbDontBuy.isSelected()); filter.dontBuy(cbDontBuy.isSelected());

View File

@@ -213,6 +213,7 @@ filter.stations.global=Default filter
# vFilter.fxml # vFilter.fxml
filter.stations.legalOnly=Legals only filter.stations.legalOnly=Legals only
filter.stations.illegalOnly=Sell illegal only
filter.stations.notBuy=Don't buy filter.stations.notBuy=Don't buy
filter.stations.notSell=Don't sell filter.stations.notSell=Don't sell
filter.stations.label.notBuy=Don't buy: filter.stations.label.notBuy=Don't buy:

View File

@@ -213,6 +213,7 @@ filter.stations.global=\u0413\u043B\u043E\u0431\u0430\u043B\u044C\u043D\u044B\u0
# vFilter.fxml # vFilter.fxml
filter.stations.legalOnly=\u0422\u043E\u043B\u044C\u043A\u043E \u043B\u0435\u0433\u0430\u043B\u044C\u043D\u044B\u0435 filter.stations.legalOnly=\u0422\u043E\u043B\u044C\u043A\u043E \u043B\u0435\u0433\u0430\u043B\u044C\u043D\u044B\u0435
filter.stations.illegalOnly=\u0422\u043E\u043B\u044C\u043A\u043E \u043A\u043E\u043D\u0442\u0440\u0430\u0431\u0430\u043D\u0434\u0430
filter.stations.notBuy=\u041D\u0435 \u043F\u043E\u043A\u0443\u043F\u0430\u0442\u044C filter.stations.notBuy=\u041D\u0435 \u043F\u043E\u043A\u0443\u043F\u0430\u0442\u044C
filter.stations.notSell=\u041D\u0435 \u043F\u0440\u043E\u0434\u0430\u0432\u0430\u0442\u044C filter.stations.notSell=\u041D\u0435 \u043F\u0440\u043E\u0434\u0430\u0432\u0430\u0442\u044C
filter.stations.label.notBuy=\u041D\u0435 \u043F\u043E\u043A\u0443\u043F\u0430\u0442\u044C: filter.stations.label.notBuy=\u041D\u0435 \u043F\u043E\u043A\u0443\u043F\u0430\u0442\u044C:

View File

@@ -3,11 +3,13 @@
<VBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ru.trader.controllers.VendorFilterController" <VBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ru.trader.controllers.VendorFilterController"
styleClass="dialog" spacing="10"> styleClass="dialog" spacing="10">
<HBox spacing="10"> <HBox spacing="10">
<CheckBox fx:id="cbIllegalOnly" text="%filter.stations.illegalOnly"/>
<CheckBox fx:id="cbSkipIllegal" text="%filter.stations.legalOnly"/> <CheckBox fx:id="cbSkipIllegal" text="%filter.stations.legalOnly"/>
</HBox>
<HBox spacing="10">
<CheckBox fx:id="cbDontSell" text="%filter.stations.notBuy"/> <CheckBox fx:id="cbDontSell" text="%filter.stations.notBuy"/>
<CheckBox fx:id="cbDontBuy" text="%filter.stations.notSell"/> <CheckBox fx:id="cbDontBuy" text="%filter.stations.notSell"/>
</HBox> </HBox>
<VBox spacing="4"> <VBox spacing="4">
<Label text="%filter.stations.label.notBuy"/> <Label text="%filter.stations.label.notBuy"/>
<ScrollPane maxHeight="200" maxWidth="400"> <ScrollPane maxHeight="200" maxWidth="400">

View File

@@ -11,6 +11,7 @@ public class VendorFilter {
private boolean disable; private boolean disable;
private boolean skipIllegal; private boolean skipIllegal;
private boolean illegalOnly;
private boolean dontBuy; private boolean dontBuy;
private boolean dontSell; private boolean dontSell;
private final Collection<Item> buyExcludes; private final Collection<Item> buyExcludes;
@@ -20,6 +21,7 @@ public class VendorFilter {
buyExcludes = new ArrayList<>(); buyExcludes = new ArrayList<>();
sellExcludes = new ArrayList<>(); sellExcludes = new ArrayList<>();
skipIllegal = false; skipIllegal = false;
illegalOnly = false;
} }
public boolean isDisable() { public boolean isDisable() {
@@ -38,6 +40,14 @@ public class VendorFilter {
this.skipIllegal = skipIllegal; this.skipIllegal = skipIllegal;
} }
public boolean isIllegalOnly() {
return illegalOnly;
}
public void setIllegalOnly(boolean illegalOnly) {
this.illegalOnly = illegalOnly;
}
public boolean isDontBuy() { public boolean isDontBuy() {
return dontBuy; return dontBuy;
} }
@@ -91,17 +101,17 @@ public class VendorFilter {
if (skipIllegal && offer.isIllegal()) return true; if (skipIllegal && offer.isIllegal()) return true;
switch (offer.getType()) { switch (offer.getType()) {
case SELL: return dontSell || sellExcludes.contains(offer.getItem()); case SELL: return dontSell || sellExcludes.contains(offer.getItem());
case BUY: return dontBuy || buyExcludes.contains(offer.getItem()); case BUY: return dontBuy || (illegalOnly && !offer.isIllegal()) || buyExcludes.contains(offer.getItem());
} }
return false; return false;
} }
public boolean isFiltered(Vendor vendor, Item item, OFFER_TYPE offerType){ public boolean isFiltered(Vendor vendor, Item item, OFFER_TYPE offerType){
if (disable) return false; if (disable) return false;
if (skipIllegal && (item.isIllegal(vendor))) return true; if (skipIllegal && item.isIllegal(vendor)) return true;
switch (offerType) { switch (offerType) {
case SELL: return dontSell || sellExcludes.contains(item); case SELL: return dontSell || sellExcludes.contains(item);
case BUY: return dontBuy || buyExcludes.contains(item); case BUY: return dontBuy || (illegalOnly && !item.isIllegal(vendor)) || buyExcludes.contains(item);
} }
return false; return false;
} }

View File

@@ -30,6 +30,7 @@ public class FiltersStore {
private static final String DEFAULT_VENDOR_FILTER_KEY = "default"; private static final String DEFAULT_VENDOR_FILTER_KEY = "default";
private static final String VENDOR_FILTERS_FIELD = "stations"; private static final String VENDOR_FILTERS_FIELD = "stations";
private static final String LEGAL_ONLY_FIELD = "legalOnly"; private static final String LEGAL_ONLY_FIELD = "legalOnly";
private static final String SELL_ILLEGAL_ONLY_FIELD = "illegalOnly";
private static final String DONT_SELL_FIELD = "notSell"; private static final String DONT_SELL_FIELD = "notSell";
private static final String DONT_BUY_FIELD = "notBuy"; private static final String DONT_BUY_FIELD = "notBuy";
private static final String SELL_FILTER_FIELD = "excludeSell"; private static final String SELL_FILTER_FIELD = "excludeSell";
@@ -95,6 +96,7 @@ public class FiltersStore {
private void write(String key, VendorFilter filter, JsonGenerator generator) throws IOException { private void write(String key, VendorFilter filter, JsonGenerator generator) throws IOException {
generator.writeObjectFieldStart(key); generator.writeObjectFieldStart(key);
generator.writeBooleanField(DISABLE_FIELD, filter.isDisable()); generator.writeBooleanField(DISABLE_FIELD, filter.isDisable());
generator.writeBooleanField(SELL_ILLEGAL_ONLY_FIELD, filter.isIllegalOnly());
generator.writeBooleanField(LEGAL_ONLY_FIELD, filter.isSkipIllegal()); generator.writeBooleanField(LEGAL_ONLY_FIELD, filter.isSkipIllegal());
generator.writeBooleanField(DONT_SELL_FIELD, filter.isDontSell()); generator.writeBooleanField(DONT_SELL_FIELD, filter.isDontSell());
generator.writeBooleanField(DONT_BUY_FIELD, filter.isDontBuy()); generator.writeBooleanField(DONT_BUY_FIELD, filter.isDontBuy());
@@ -196,6 +198,7 @@ public class FiltersStore {
filter.setDisable(node.get(DISABLE_FIELD).asBoolean()); filter.setDisable(node.get(DISABLE_FIELD).asBoolean());
filter.setSkipIllegal(node.get(LEGAL_ONLY_FIELD).asBoolean()); filter.setSkipIllegal(node.get(LEGAL_ONLY_FIELD).asBoolean());
filter.dontSell(node.get(DONT_SELL_FIELD).asBoolean()); filter.dontSell(node.get(DONT_SELL_FIELD).asBoolean());
filter.setIllegalOnly(node.get(SELL_ILLEGAL_ONLY_FIELD).asBoolean());
filter.dontBuy(node.get(DONT_BUY_FIELD).asBoolean()); filter.dontBuy(node.get(DONT_BUY_FIELD).asBoolean());
Iterator<JsonNode> iterator = node.get(SELL_FILTER_FIELD).elements(); Iterator<JsonNode> iterator = node.get(SELL_FILTER_FIELD).elements();
while (iterator.hasNext()) { while (iterator.hasNext()) {

View File

@@ -57,6 +57,7 @@ public class FiltersStoreTest extends Assert {
VendorFilter vendorFilter = new VendorFilter(); VendorFilter vendorFilter = new VendorFilter();
vendorFilter.setDisable(true); vendorFilter.setDisable(true);
vendorFilter.setSkipIllegal(true); vendorFilter.setSkipIllegal(true);
vendorFilter.setIllegalOnly(true);
vendorFilter.dontBuy(true); vendorFilter.dontBuy(true);
vendorFilter.addSellExclude(gold); vendorFilter.addSellExclude(gold);
vendorFilter.addSellExclude(tea); vendorFilter.addSellExclude(tea);
@@ -102,6 +103,7 @@ public class FiltersStoreTest extends Assert {
private void assertFilter(VendorFilter expected, VendorFilter actual){ private void assertFilter(VendorFilter expected, VendorFilter actual){
assertEquals(expected.isDisable(), actual.isDisable()); assertEquals(expected.isDisable(), actual.isDisable());
assertEquals(expected.isIllegalOnly(), actual.isIllegalOnly());
assertEquals(expected.isSkipIllegal(), actual.isSkipIllegal()); assertEquals(expected.isSkipIllegal(), actual.isSkipIllegal());
assertEquals(expected.isDontBuy(), actual.isDontBuy()); assertEquals(expected.isDontBuy(), actual.isDontBuy());
assertEquals(expected.isDontSell(), actual.isDontSell()); assertEquals(expected.isDontSell(), actual.isDontSell());