Skip to content

Commit

Permalink
New Feature: Added option to ignore multiplier for stockpile items (I…
Browse files Browse the repository at this point in the history
…ssue #411)
  • Loading branch information
GoldenGnu committed Sep 28, 2023
1 parent d0e689d commit ab2b10d
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ public Component prepareRenderer(final TableCellRenderer renderer, final int row
} else if (object instanceof SubpileItem) { //Total
if (!stockpileItem.isEditable() && columnName.equals(StockpileTableFormat.COUNT_MINIMUM.getColumnName())) {
ColorSettings.configCell(component, ColorEntry.GLOBAL_GRAND_TOTAL, isSelected);
}
if (columnName.equals(StockpileTableFormat.TAGS.getColumnName())) {
} else if (columnName.equals(StockpileTableFormat.TAGS.getColumnName())) {
ColorSettings.configCell(component, ColorEntry.GLOBAL_GRAND_TOTAL, isSelected);
}
} else if (object instanceof StockpileTotal) { //Total
Expand All @@ -145,8 +144,7 @@ public Component prepareRenderer(final TableCellRenderer renderer, final int row
int jLabelWidth = jLabel.getMaximumSize().width + 1;
jLabel.setIconTextGap(Math.max(0, columnWidth - jLabelWidth));
}
}
if (columnName.equals(StockpileTableFormat.NAME.getColumnName())) {
} else if (columnName.equals(StockpileTableFormat.NAME.getColumnName())) {
if (Settings.get().isStockpileHalfColors()) {
if (stockpileItem.getPercentNeeded() >= (Settings.get().getStockpileColorGroup3() / 100.0) ) {
//Group 3
Expand All @@ -167,45 +165,35 @@ public Component prepareRenderer(final TableCellRenderer renderer, final int row
ColorSettings.configCell(component, ColorEntry.STOCKPILE_TABLE_BELOW_THRESHOLD, isSelected);
}
}
} else if (stockpileItem.isIgnoreMultiplier() && columnName.equals(StockpileTableFormat.COUNT_MINIMUM_MULTIPLIED.getColumnName())) {
ColorSettings.configCell(component, ColorEntry.GLOBAL_GRAND_TOTAL, isSelected);
}
//Foreground
if (columnName.equals(StockpileTableFormat.COUNT_NOW_INVENTORY.getColumnName()) && !stockpileItem.getStockpile().isAssets()) {
component.setForeground(component.getBackground());
}
if (columnName.equals(StockpileTableFormat.COUNT_NOW_BUY_ORDERS.getColumnName()) && (!stockpileItem.getStockpile().isBuyOrders() || stockpileItem.isRuns())) {
} else if (columnName.equals(StockpileTableFormat.COUNT_NOW_BUY_ORDERS.getColumnName()) && (!stockpileItem.getStockpile().isBuyOrders() || stockpileItem.isRuns())) {
component.setForeground(component.getBackground());
}
if (columnName.equals(StockpileTableFormat.COUNT_NOW_SELL_ORDERS.getColumnName()) && (!stockpileItem.getStockpile().isSellOrders() || stockpileItem.isRuns())) {
} else if (columnName.equals(StockpileTableFormat.COUNT_NOW_SELL_ORDERS.getColumnName()) && (!stockpileItem.getStockpile().isSellOrders() || stockpileItem.isRuns())) {
component.setForeground(component.getBackground());
}
if (columnName.equals(StockpileTableFormat.COUNT_NOW_BUY_TRANSACTIONS.getColumnName()) && (!stockpileItem.getStockpile().isBuyTransactions() || stockpileItem.isRuns())) {
} else if (columnName.equals(StockpileTableFormat.COUNT_NOW_BUY_TRANSACTIONS.getColumnName()) && (!stockpileItem.getStockpile().isBuyTransactions() || stockpileItem.isRuns())) {
component.setForeground(component.getBackground());
}
if (columnName.equals(StockpileTableFormat.COUNT_NOW_SELL_TRANSACTIONS.getColumnName()) && (!stockpileItem.getStockpile().isSellTransactions() || stockpileItem.isRuns())) {
} else if (columnName.equals(StockpileTableFormat.COUNT_NOW_SELL_TRANSACTIONS.getColumnName()) && (!stockpileItem.getStockpile().isSellTransactions() || stockpileItem.isRuns())) {
component.setForeground(component.getBackground());
}
if (columnName.equals(StockpileTableFormat.COUNT_NOW_JOBS.getColumnName()) && !stockpileItem.getStockpile().isJobs()) {
} else if (columnName.equals(StockpileTableFormat.COUNT_NOW_JOBS.getColumnName()) && !stockpileItem.getStockpile().isJobs()) {
component.setForeground(component.getBackground());
}
if (columnName.equals(StockpileTableFormat.COUNT_NOW_SELLING_CONTRACTS.getColumnName()) && (!stockpileItem.getStockpile().isSellingContracts() || stockpileItem.isRuns())) {
} else if (columnName.equals(StockpileTableFormat.COUNT_NOW_SELLING_CONTRACTS.getColumnName()) && (!stockpileItem.getStockpile().isSellingContracts() || stockpileItem.isRuns())) {
component.setForeground(component.getBackground());
}
if (columnName.equals(StockpileTableFormat.COUNT_NOW_SOLD_CONTRACTS.getColumnName()) && (!stockpileItem.getStockpile().isSoldContracts() || stockpileItem.isRuns())) {
} else if (columnName.equals(StockpileTableFormat.COUNT_NOW_SOLD_CONTRACTS.getColumnName()) && (!stockpileItem.getStockpile().isSoldContracts() || stockpileItem.isRuns())) {
component.setForeground(component.getBackground());
}
if (columnName.equals(StockpileTableFormat.COUNT_NOW_BUYING_CONTRACTS.getColumnName()) && (!stockpileItem.getStockpile().isBuyingContracts() || stockpileItem.isRuns())) {
} else if (columnName.equals(StockpileTableFormat.COUNT_NOW_BUYING_CONTRACTS.getColumnName()) && (!stockpileItem.getStockpile().isBuyingContracts() || stockpileItem.isRuns())) {
component.setForeground(component.getBackground());
}
if (columnName.equals(StockpileTableFormat.COUNT_NOW_BOUGHT_CONTRACTS.getColumnName()) && (!stockpileItem.getStockpile().isBoughtContracts() || stockpileItem.isRuns())) {
} else if (columnName.equals(StockpileTableFormat.COUNT_NOW_BOUGHT_CONTRACTS.getColumnName()) && (!stockpileItem.getStockpile().isBoughtContracts() || stockpileItem.isRuns())) {
component.setForeground(component.getBackground());
}
if (columnName.equals(StockpileTableFormat.COUNT_NEEDED.getColumnName()) && stockpileItem.getCountNeeded() < 0) {
} else if (columnName.equals(StockpileTableFormat.COUNT_NEEDED.getColumnName()) && stockpileItem.getCountNeeded() < 0) {
ColorSettings.configCell(component, ColorEntry.GLOBAL_VALUE_NEGATIVE, isSelected);
}
if (columnName.equals(StockpileTableFormat.VALUE_NEEDED.getColumnName()) && stockpileItem.getValueNeeded() < 0) {
} else if (columnName.equals(StockpileTableFormat.VALUE_NEEDED.getColumnName()) && stockpileItem.getValueNeeded() < 0) {
ColorSettings.configCell(component, ColorEntry.GLOBAL_VALUE_NEGATIVE, isSelected);
}
if (columnName.equals(StockpileTableFormat.VOLUME_NEEDED.getColumnName()) && stockpileItem.getVolumeNeeded() < 0) {
} else if (columnName.equals(StockpileTableFormat.VOLUME_NEEDED.getColumnName()) && stockpileItem.getVolumeNeeded() < 0) {
ColorSettings.configCell(component, ColorEntry.GLOBAL_VALUE_NEGATIVE, isSelected);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ public static class StockpileItem implements Comparable<StockpileItem>, Location
private int typeID;
private double countMinimum;
private boolean runs;
private boolean ignoreMultiplier;

//soft init
protected JButton jButton;
Expand Down Expand Up @@ -585,20 +586,26 @@ public StockpileItem(final Stockpile stockpile, final StockpileItem stockpileIte
stockpileItem.item,
stockpileItem.typeID,
stockpileItem.countMinimum,
stockpileItem.runs
stockpileItem.runs,
stockpileItem.ignoreMultiplier
);
}

public StockpileItem(final Stockpile stockpile, final Item item, final int typeID, final double countMinimum, final boolean runs) {
this(stockpile, item, typeID, countMinimum, runs, getNewID());
this(stockpile, item, typeID, countMinimum, runs, false, getNewID());
}

public StockpileItem(final Stockpile stockpile, final Item item, final int typeID, final double countMinimum, final boolean runs, final long id) {
public StockpileItem(final Stockpile stockpile, final Item item, final int typeID, final double countMinimum, final boolean runs, boolean ignoreMultiplier) {
this(stockpile, item, typeID, countMinimum, runs, ignoreMultiplier, getNewID());
}

public StockpileItem(final Stockpile stockpile, final Item item, final int typeID, final double countMinimum, final boolean runs, boolean ignoreMultiplier, final long id) {
this.stockpile = stockpile;
this.item = item;
this.typeID = typeID;
this.countMinimum = countMinimum;
this.runs = runs;
this.ignoreMultiplier = ignoreMultiplier;
this.id = id;
}

Expand All @@ -608,6 +615,7 @@ void update(StockpileItem stockpileItem) {
this.typeID = stockpileItem.typeID;
this.countMinimum = stockpileItem.countMinimum;
this.runs = stockpileItem.runs;
this.ignoreMultiplier = stockpileItem.ignoreMultiplier;
}

@Override
Expand All @@ -626,6 +634,14 @@ public boolean isEditable() {
return true;
}

public boolean isIgnoreMultiplier() {
return ignoreMultiplier;
}

public void setIgnoreMultiplier(boolean ignoreMultiplier) {
this.ignoreMultiplier = ignoreMultiplier;
}

private void reset() {
inventoryCountNow = 0;
sellOrdersCountNow = 0;
Expand Down Expand Up @@ -1163,7 +1179,11 @@ public double getCountMinimum() {
}

public long getCountMinimumMultiplied() {
return (long) Math.ceil(stockpile.getMultiplier() * countMinimum);
if (isIgnoreMultiplier()) {
return (long) Math.ceil(countMinimum);
} else {
return (long) Math.ceil(stockpile.getMultiplier() * countMinimum);
}
}

public long getCountNow() {
Expand Down Expand Up @@ -1428,7 +1448,7 @@ public static class StockpileTotal extends StockpileItem {
private double volumeNeeded = 0;

public StockpileTotal(final Stockpile stockpile) {
super(stockpile, new Item(0), 0, 0, false, 0);
super(stockpile, new Item(0), 0, 0, false, false, 0);
}

private void reset() {
Expand Down Expand Up @@ -1876,7 +1896,7 @@ public static class SubpileItem extends StockpileItem {
private int level;

public SubpileItem(Stockpile stockpile, StockpileItem parentItem, SubpileStock subpileStock, int level, String path) {
super(stockpile, parentItem);
super(stockpile, parentItem.getItem(), parentItem.getItemTypeID(), parentItem.getCountMinimum(), parentItem.isRuns(), false);
itemLinks.add(new SubpileItemLinks(parentItem, subpileStock));
setLevel(level);
this.path = path;
Expand Down Expand Up @@ -1950,20 +1970,33 @@ public String getName() {
@Override
public double getCountMinimum() {
double countMinimum = 0;
for (SubpileItemLinks item : itemLinks) {
SubpileStock stock = item.getSubpileStock();
if (stock != null) {
countMinimum = + countMinimum + (item.getStockpileItem().getCountMinimum() * item.getSubpileStock().getSubMultiplier());
for (SubpileItemLinks link : itemLinks) {
SubpileStock stock = link.getSubpileStock();
StockpileItem item = link.getStockpileItem();
if (item.isIgnoreMultiplier() || stock == null) {
countMinimum = countMinimum + item.getCountMinimum();
} else {
countMinimum = + countMinimum + item.getStockpileItem().getCountMinimum();
countMinimum = countMinimum + (item.getCountMinimum() * stock.getSubMultiplier());
}
}
return countMinimum;
}

@Override
public long getCountMinimumMultiplied() {
return (long) Math.ceil(getStockpile().getMultiplier() * getCountMinimum());
double countMinimum = 0;
for (SubpileItemLinks link : itemLinks) {
SubpileStock stock = link.getSubpileStock();
StockpileItem item = link.getStockpileItem();
if (item.isIgnoreMultiplier()) {
countMinimum = countMinimum + item.getCountMinimum();
} else if (stock != null) {
countMinimum = countMinimum + (item.getCountMinimum() * stock.getSubMultiplier() * getStockpile().getMultiplier());
} else {
countMinimum = countMinimum + (item.getCountMinimum() * getStockpile().getMultiplier());
}
}
return (long) Math.ceil(countMinimum);
}

private static class SubpileItemLinks {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import javax.swing.DefaultComboBoxModel;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
Expand Down Expand Up @@ -102,11 +103,14 @@ public String toString() {
private final JComboBox<Item> jItems;
private final JLabel jSubpile;
private JTextField jCountMinimum;
private final JLabel jBlueprintTypeLabel;
private final JComboBox<BlueprintAddType> jBlueprintType;
private final JComboBox<Integer> jMe;
private final JComboBox<ManufacturingFacility> jFacility;
private final JComboBox<ManufacturingRigs> jRigs;
private final JComboBox<ManufacturingSecurity> jSecurity;
private final JLabel jIgnoreMultiplierLabel;
private final JCheckBox jIgnoreMultiplier;

private final List<JComponent> manufacturingComponents = new ArrayList<>();
private final EventList<Item> items = EventListManager.create();
Expand Down Expand Up @@ -139,7 +143,10 @@ public void focusGained(final FocusEvent e) {
});
jCountMinimum.addCaretListener(listener);

JLabel jBlueprintTypeLabel = new JLabel(TabsStockpile.get().blueprintType());
jIgnoreMultiplierLabel = new JLabel(TabsStockpile.get().multiplier());
jIgnoreMultiplier = new JCheckBox(TabsStockpile.get().multiplierIgnore());

jBlueprintTypeLabel = new JLabel(TabsStockpile.get().blueprintType());
jBlueprintType = new JComboBox<>(BlueprintAddType.values());
jBlueprintType.setActionCommand(StockpileItemAction.TYPE_CHANGE.name());
jBlueprintType.addActionListener(listener);
Expand Down Expand Up @@ -206,21 +213,23 @@ public void actionPerformed(ActionEvent e) {
.addGroup(layout.createParallelGroup()
.addComponent(jItemsLabel)
.addComponent(jBlueprintTypeLabel)
.addComponent(jCountMinimumLabel)
.addComponent(jMeLabel)
.addComponent(jFacilityLabel)
.addComponent(jRigsLabel)
.addComponent(jSecurityLabel)
.addComponent(jIgnoreMultiplierLabel)
.addComponent(jCountMinimumLabel)
)
.addGroup(layout.createParallelGroup()
.addComponent(jItems, 300, 300, 300)
.addComponent(jSubpile, 300, 300, 300)
.addComponent(jBlueprintType, 300, 300, 300)
.addComponent(jCountMinimum, 300, 300, 300)
.addComponent(jMe, 300, 300, 300)
.addComponent(jFacility, 300, 300, 300)
.addComponent(jRigs, 300, 300, 300)
.addComponent(jSecurity, 300, 300, 300)
.addComponent(jIgnoreMultiplier, 300, 300, 300)
.addComponent(jCountMinimum, 300, 300, 300)
)
)
.addGroup(layout.createSequentialGroup()
Expand Down Expand Up @@ -255,6 +264,10 @@ public void actionPerformed(ActionEvent e) {
.addComponent(jSecurityLabel, Program.getButtonsHeight(), Program.getButtonsHeight(), Program.getButtonsHeight())
.addComponent(jSecurity, Program.getButtonsHeight(), Program.getButtonsHeight(), Program.getButtonsHeight())
)
.addGroup(layout.createParallelGroup()
.addComponent(jIgnoreMultiplierLabel, Program.getButtonsHeight(), Program.getButtonsHeight(), Program.getButtonsHeight())
.addComponent(jIgnoreMultiplier, Program.getButtonsHeight(), Program.getButtonsHeight(), Program.getButtonsHeight())
)
.addGroup(layout.createParallelGroup()
.addComponent(jCountMinimumLabel, Program.getButtonsHeight(), Program.getButtonsHeight(), Program.getButtonsHeight())
.addComponent(jCountMinimum, Program.getButtonsHeight(), Program.getButtonsHeight(), Program.getButtonsHeight())
Expand All @@ -274,10 +287,18 @@ protected StockpileItem showEdit(final StockpileItem editStockpileItem) {
if (editStockpileItem instanceof SubpileStock) {
jSubpile.setText(editStockpileItem.getName());
jSubpile.setVisible(true);
jBlueprintTypeLabel.setVisible(false);
jBlueprintType.setVisible(false);
jIgnoreMultiplierLabel.setVisible(false);
jIgnoreMultiplier.setVisible(false);
jItems.setVisible(false);
} else {
jItems.setSelectedItem(item);
jSubpile.setVisible(false);
jBlueprintTypeLabel.setVisible(true);
jBlueprintType.setVisible(true);
jIgnoreMultiplierLabel.setVisible(true);
jIgnoreMultiplier.setVisible(true);
jItems.setVisible(true);
}
if (item.isBlueprint()) {
Expand Down Expand Up @@ -332,6 +353,7 @@ private void updateData() {
jItems.setVisible(true);
jItems.setSelectedIndex(0);
jCountMinimum.setText("");
jIgnoreMultiplier.setSelected(false);
}

private void show() {
Expand Down Expand Up @@ -366,7 +388,8 @@ private StockpileItem getStockpileItem() {
} else {
typeID = item.getTypeID();
}
return new StockpileItem(getStockpile(), item, typeID, countMinimum, runs);
boolean ignoreMultiplier = jIgnoreMultiplier.isSelected();
return new StockpileItem(getStockpile(), item, typeID, countMinimum, runs, ignoreMultiplier);
}

private List<StockpileItem> getStockpileItems() {
Expand All @@ -378,6 +401,7 @@ private List<StockpileItem> getStockpileItems() {
} catch (NumberFormatException ex) {
countMinimum = 0;
}
boolean ignoreMultiplier = jIgnoreMultiplier.isSelected();
Integer me = jMe.getItemAt(jMe.getSelectedIndex());
ManufacturingFacility facility = jFacility.getItemAt(jFacility.getSelectedIndex());
ManufacturingRigs rigs = jRigs.getItemAt(jRigs.getSelectedIndex());
Expand All @@ -387,14 +411,14 @@ private List<StockpileItem> getStockpileItems() {
for (IndustryMaterial material : item.getManufacturingMaterials()) {
Item materialItem = ApiIdConverter.getItem(material.getTypeID());
double count = ApiIdConverter.getManufacturingQuantity(material.getQuantity(), me, facility, rigs, security, countMinimum, false);
itemsMaterial.add(new StockpileItem(getStockpile(), materialItem, material.getTypeID(), count, false));
itemsMaterial.add(new StockpileItem(getStockpile(), materialItem, material.getTypeID(), count, false, ignoreMultiplier));
}
} else if (jBlueprintType.isEnabled() && jBlueprintType.getItemAt(jBlueprintType.getSelectedIndex()) == BlueprintAddType.REACTION_MATERIALS) {
//Reaction Materials
for (IndustryMaterial material : item.getReactionMaterials()) {
Item materialItem = ApiIdConverter.getItem(material.getTypeID());
double count = ApiIdConverter.getManufacturingQuantity(material.getQuantity(), me, facility, rigs, security, countMinimum, false);
itemsMaterial.add(new StockpileItem(getStockpile(), materialItem, material.getTypeID(), count, false));
itemsMaterial.add(new StockpileItem(getStockpile(), materialItem, material.getTypeID(), count, false, ignoreMultiplier));
}
} else {
return null;
Expand Down Expand Up @@ -519,6 +543,7 @@ public void run() {
boolean oldUpdateValue = updating;
updating = true;
jCountMinimum.setText(String.valueOf(item.getCountMinimum()));
jIgnoreMultiplier.setSelected(item.isIgnoreMultiplier());
updating = oldUpdateValue;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public TabsStockpile(final Locale locale) {
public abstract String me();
public abstract String multiple();
public abstract String multiplier();
public abstract String multiplierIgnore();
public abstract String multiplierSign();
public abstract String myLocations();
public abstract String name();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -847,10 +847,11 @@ private void parseStockpiles(final Element stockpilesElement, final List<Stockpi
}
int typeID = getInt(itemNode, "typeid");
boolean runs = getBooleanNotNull(itemNode, "runs", false);
boolean ignoreMultiplier = getBooleanNotNull(itemNode, "ignoremultiplier", false);
double countMinimum = getDouble(itemNode, "minimum");
if (typeID != 0) { //Ignore Total
Item item = ApiIdConverter.getItemUpdate(Math.abs(typeID));
StockpileItem stockpileItem = new StockpileItem(stockpile, item, typeID, countMinimum, runs, id);
StockpileItem stockpileItem = new StockpileItem(stockpile, item, typeID, countMinimum, runs, ignoreMultiplier, id);
stockpile.add(stockpileItem);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ private void writeStockpiles(final Document xmldoc, final List<Stockpile> stockp
setAttribute(itemNode, "typeid", item.getItemTypeID());
setAttribute(itemNode, "minimum", item.getCountMinimum());
setAttribute(itemNode, "runs", item.isRuns());
setAttribute(itemNode, "ignoremultiplier", item.isIgnoreMultiplier());
stockpileNode.appendChild(itemNode);
}
//SUBPILES
Expand Down
Loading

0 comments on commit ab2b10d

Please sign in to comment.