Archived
0

add minimum supply and minimum demand to vendor filter

This commit is contained in:
iMoHax
2016-12-05 17:45:34 +03:00
parent e557206bce
commit c96f8d320b
6 changed files with 73 additions and 9 deletions

View File

@@ -15,7 +15,9 @@ import ru.trader.model.ItemModel;
import ru.trader.model.MarketModel;
import ru.trader.model.ModelFabric;
import ru.trader.view.support.Localization;
import ru.trader.view.support.NumberField;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Objects;
import java.util.Optional;
@@ -35,6 +37,11 @@ public class VendorFilterController {
private CheckBox cbSkipIllegal;
@FXML
private CheckBox cbIllegalOnly;
@FXML
private NumberField minSupply;
@FXML
private NumberField minDemand;
private VendorFilter filter;
private Dialog<VendorFilter> dlg;
@@ -56,7 +63,9 @@ public class VendorFilterController {
int column = -1;
int row = -1;
GroupModel currentGroup = null;
for (ItemModel item : items) {
ArrayList<ItemModel> sortedItems = new ArrayList<>(items);
sortedItems.sort((i1, i2) -> i1.getGroup().getName().compareTo(i2.getGroup().getName()));
for (ItemModel item : sortedItems) {
row++;
if (column == -1 || !Objects.equals(currentGroup, item.getGroup())){
column++;
@@ -97,6 +106,8 @@ public class VendorFilterController {
cbDontBuy.setSelected(filter.isDontBuy());
fillCheckboxes(sellCbs, filter.getSellExcludes());
fillCheckboxes(buyCbs, filter.getBuyExcludes());
minSupply.setValue(filter.getMinSupply());
minDemand.setValue(filter.getMinDemand());
}
private void fillCheckboxes(Pane checkboxes, Collection<Item> excludes) {
@@ -115,6 +126,8 @@ public class VendorFilterController {
private void save() {
LOG.trace("Old filter", filter);
filter.setMinSupply(minSupply.getValue().longValue());
filter.setMinDemand(minDemand.getValue().longValue());
filter.setIllegalOnly(cbIllegalOnly.isSelected());
filter.setSkipIllegal(cbSkipIllegal.isSelected());
filter.dontSell(cbDontSell.isSelected());

View File

@@ -234,6 +234,8 @@ filter.stations.notBuy=Don't buy
filter.stations.notSell=Don't sell
filter.stations.label.notBuy=Don't buy:
filter.stations.label.notSell=Don't sell:
filter.stations.label.minSupply=Minimum supply:
filter.stations.label.minDemand=Minimum demand:
# analyzer progress
analyzer.orders.title=Search orders

View File

@@ -233,6 +233,8 @@ filter.stations.notBuy=\u041D\u0435 \u043F\u043E\u043A\u0443\u043F\u0430\u0442\u
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.notSell=\u041D\u0435 \u043F\u0440\u043E\u0434\u0430\u0432\u0430\u0442\u044C:
filter.stations.label.minSupply=\u041C\u0438\u043D\u0438\u043C\u0430\u043B\u044C\u043D\u044B\u0439 \u0437\u0430\u043F\u0430\u0441:
filter.stations.label.minDemand=\u041C\u0438\u043D\u0438\u043C\u0430\u043B\u044C\u043D\u044B\u0439 \u0441\u043F\u0440\u043E\u0441:
# analyzer progress
analyzer.orders.title=\u041F\u043E\u0438\u0441\u043A \u0437\u0430\u043A\u0430\u0437\u043E\u0432

View File

@@ -1,24 +1,29 @@
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import ru.trader.view.support.NumberField?>
<VBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ru.trader.controllers.VendorFilterController"
styleClass="dialog" 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" prefWidth="200" />
<CheckBox fx:id="cbDontSell" text="%filter.stations.notBuy" prefWidth="120" />
<Label text="%filter.stations.label.minSupply" prefWidth="120" />
<NumberField fx:id="minSupply" prefWidth="120" />
</HBox>
<HBox spacing="10">
<CheckBox fx:id="cbDontSell" text="%filter.stations.notBuy"/>
<CheckBox fx:id="cbDontBuy" text="%filter.stations.notSell"/>
<CheckBox fx:id="cbIllegalOnly" text="%filter.stations.illegalOnly" prefWidth="200" />
<CheckBox fx:id="cbDontBuy" text="%filter.stations.notSell" prefWidth="120" />
<Label text="%filter.stations.label.minDemand" prefWidth="120" />
<NumberField fx:id="minDemand" prefWidth="120" />
</HBox>
<VBox spacing="4">
<Label text="%filter.stations.label.notBuy"/>
<ScrollPane maxHeight="200" maxWidth="400">
<ScrollPane maxHeight="200" maxWidth="600">
<GridPane fx:id="sellCbs" hgap="5" vgap="5"/>
</ScrollPane>
</VBox>
<VBox spacing="4">
<Label text="%filter.stations.label.notSell"/>
<ScrollPane maxHeight="200" maxWidth="400">
<ScrollPane maxHeight="200" maxWidth="600">
<GridPane fx:id="buyCbs" hgap="5" vgap="5"/>
</ScrollPane>
</VBox>

View File

@@ -14,12 +14,18 @@ public class VendorFilter {
private boolean illegalOnly;
private boolean dontBuy;
private boolean dontSell;
private long minSupply;
private long minDemand;
private final Collection<Item> buyExcludes;
private final Collection<Item> sellExcludes;
public VendorFilter() {
buyExcludes = new ArrayList<>();
sellExcludes = new ArrayList<>();
minSupply = 0;
minDemand = 0;
dontSell = false;
dontBuy = false;
skipIllegal = false;
illegalOnly = false;
}
@@ -32,6 +38,22 @@ public class VendorFilter {
this.disable = disable;
}
public long getMinSupply() {
return minSupply;
}
public void setMinSupply(long minSupply) {
this.minSupply = minSupply;
}
public long getMinDemand() {
return minDemand;
}
public void setMinDemand(long minDemand) {
this.minDemand = minDemand;
}
public boolean isSkipIllegal() {
return skipIllegal;
}
@@ -100,8 +122,8 @@ public class VendorFilter {
if (disable) return false;
if (skipIllegal && offer.isIllegal()) return true;
switch (offer.getType()) {
case SELL: return dontSell || sellExcludes.contains(offer.getItem());
case BUY: return dontBuy || (illegalOnly && !offer.isIllegal()) || buyExcludes.contains(offer.getItem());
case SELL: return dontSell || sellExcludes.contains(offer.getItem()) || (offer.getCount() > 0 && offer.getCount() < minSupply);
case BUY: return dontBuy || (illegalOnly && !offer.isIllegal()) || buyExcludes.contains(offer.getItem()) || (offer.getCount() > 0 && offer.getCount() < minDemand);
}
return false;
}

View File

@@ -21,4 +21,24 @@ public class SimpleGroup implements Group {
public GROUP_TYPE getType() {
return type;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SimpleGroup)) return false;
SimpleGroup that = (SimpleGroup) o;
if (!name.equals(that.name)) return false;
if (type != that.type) return false;
return true;
}
@Override
public int hashCode() {
int result = name.hashCode();
result = 31 * result + type.hashCode();
return result;
}
}