diff --git a/assets/data/l10n/query.json b/assets/data/l10n/query.json index c9890f81d..ff0b3395b 100644 --- a/assets/data/l10n/query.json +++ b/assets/data/l10n/query.json @@ -1,4 +1,9 @@ { + "BEHAVIOR_ALL_SELECTED": "All selected", + "BEHAVIOR_AT_LEAST": "At least {0}", + "BEHAVIOR_MERCENARY_SKILLS": "Mercenary Skills", + "BEHAVIOR_SHIP_WEAPON_MOUNTS": "Ship Weapon Mounts", + "BEHAVIOR_SHIP_BUILT_INS": "Ship Built-Ins", "BUILT_IN": "Built-in hullmods", "CLASS_SIZE": "Class size", "DAMAGE_TYPE": "Damage type", @@ -15,6 +20,8 @@ "FIND_MATCHING": "Find Matching", "FIND_SELECTED": "Select & Search", "ITEM_TYPES": "Item types", + "MANAGE_BEHAVIOR": "Query Building Logic", + "MANAGE_BEHAVIOR_INFO": "Define how many selected criteria have to be matched.", "MANAGE_DMODS": "Ship filtering based on d-mods", "MANAGE_DMOD_COUNT": "D-mod count", "MANAGE_DMOD_SET": "Allowed and disallowed d-mods", diff --git a/src/stelnet/board/query/QueryL10n.java b/src/stelnet/board/query/QueryL10n.java index daceb0f32..114566e83 100644 --- a/src/stelnet/board/query/QueryL10n.java +++ b/src/stelnet/board/query/QueryL10n.java @@ -1,6 +1,11 @@ package stelnet.board.query; public enum QueryL10n { + BEHAVIOR_ALL_SELECTED, + BEHAVIOR_AT_LEAST, + BEHAVIOR_MERCENARY_SKILLS, + BEHAVIOR_SHIP_BUILT_INS, + BEHAVIOR_SHIP_WEAPON_MOUNTS, BUILT_IN, CLASS_SIZE, DAMAGE_TYPE, @@ -17,6 +22,8 @@ public enum QueryL10n { FIND_MATCHING, FIND_SELECTED, ITEM_TYPES, + MANAGE_BEHAVIOR, + MANAGE_BEHAVIOR_INFO, MANAGE_DMODS, MANAGE_DMOD_COUNT, MANAGE_DMOD_SET, diff --git a/src/stelnet/board/query/view/manage/BuilderBehaviorButton.java b/src/stelnet/board/query/view/manage/BuilderBehaviorButton.java new file mode 100644 index 000000000..c42d443f6 --- /dev/null +++ b/src/stelnet/board/query/view/manage/BuilderBehaviorButton.java @@ -0,0 +1,12 @@ +package stelnet.board.query.view.manage; + +import uilib.AreaCheckbox; +import uilib.UiConstants; +import uilib.property.Size; + +public class BuilderBehaviorButton extends AreaCheckbox { + + public BuilderBehaviorButton(String title, boolean isStateOn) { + super(new Size(UiConstants.AUTO_WIDTH, UiConstants.DEFAULT_BUTTON_HEIGHT), title, true, isStateOn); + } +} diff --git a/src/stelnet/board/query/view/manage/ButtonUtils.java b/src/stelnet/board/query/view/manage/ButtonUtils.java index 4f6bf9818..0cf4fea7a 100644 --- a/src/stelnet/board/query/view/manage/ButtonUtils.java +++ b/src/stelnet/board/query/view/manage/ButtonUtils.java @@ -95,6 +95,15 @@ public static FilteringButton[] getSubmarketButtons(QueryManager manager) { return elements.toArray(new FilteringButton[] {}); } + public static BuilderBehaviorButton[] getBehaviorButtons() { + return new BuilderBehaviorButton[] { + new BuilderBehaviorButton(L10n.get(QueryL10n.BEHAVIOR_AT_LEAST, 1), true), + new BuilderBehaviorButton(L10n.get(QueryL10n.BEHAVIOR_AT_LEAST, 2), false), + new BuilderBehaviorButton(L10n.get(QueryL10n.BEHAVIOR_AT_LEAST, 3), false), + new BuilderBehaviorButton(L10n.get(QueryL10n.BEHAVIOR_ALL_SELECTED), false), + }; + } + private static String getSubmarketName(SubmarketSpecAPI submarketSpec) { String name = submarketSpec.getName().replace("\n", " ").trim(); if (name.isEmpty()) { diff --git a/src/stelnet/board/query/view/manage/ManageResultsFactory.java b/src/stelnet/board/query/view/manage/ManageResultsFactory.java index 86303d461..88abfb8b0 100644 --- a/src/stelnet/board/query/view/manage/ManageResultsFactory.java +++ b/src/stelnet/board/query/view/manage/ManageResultsFactory.java @@ -11,7 +11,10 @@ import stelnet.board.query.view.SectionHeader; import stelnet.board.query.view.SizeHelper; import stelnet.util.ColorHelper; +import stelnet.util.L10n; +import uilib.AreaCheckbox; import uilib.Button; +import uilib.Paragraph; import uilib.Renderable; import uilib.RenderableFactory; import uilib.Spacer; @@ -20,9 +23,12 @@ public class ManageResultsFactory extends FilterAwareFactory implements RenderableFactory { + private final AreaCheckbox[] behaviorMercenarySkillsButtons; + private final AreaCheckbox[] behaviorShipWeaponMountsButtons; + private final AreaCheckbox[] behaviorShipBuiltInsButtons; private final FilteringButton[] dModCount; private final FilteringButton[] dModAllowed; - private final GroupByButton[] groupingButtons; + private final Button[] groupingButtons; private final Button[] submarketButtons; private final Button[] otherButtons; @@ -32,6 +38,9 @@ public ManageResultsFactory(QueryManager manager) { groupingButtons = ButtonUtils.getGroupingButtons(manager); submarketButtons = ButtonUtils.getSubmarketButtons(manager); otherButtons = ButtonUtils.getOtherButtons(manager); + behaviorMercenarySkillsButtons = ButtonUtils.getBehaviorButtons(); + behaviorShipWeaponMountsButtons = ButtonUtils.getBehaviorButtons(); + behaviorShipBuiltInsButtons = ButtonUtils.getBehaviorButtons(); } @Override @@ -50,20 +59,27 @@ public List create(Size size) { elements.add(new SectionHeader(sizeHelper.getGroupAndTextWidth(), QueryL10n.MANAGE_DMODS, true)); elements.add(new ButtonGroup(sizeHelper, QueryL10n.MANAGE_DMOD_COUNT, dModCount)); elements.add(new ButtonGroup(sizeHelper, QueryL10n.MANAGE_DMOD_SET, dModAllowed)); + elements.add(new SectionHeader(sizeHelper.getGroupAndTextWidth(), QueryL10n.MANAGE_BEHAVIOR, true)); + elements.add(new Paragraph(L10n.get(QueryL10n.MANAGE_BEHAVIOR_INFO), sizeHelper.getGroupAndTextWidth())); + elements.add(new ButtonGroup(sizeHelper, QueryL10n.BEHAVIOR_MERCENARY_SKILLS, behaviorMercenarySkillsButtons)); + elements.add( + new ButtonGroup(sizeHelper, QueryL10n.BEHAVIOR_SHIP_WEAPON_MOUNTS, behaviorShipWeaponMountsButtons) + ); + elements.add(new ButtonGroup(sizeHelper, QueryL10n.BEHAVIOR_SHIP_BUILT_INS, behaviorShipBuiltInsButtons)); return elements; } - private void prepareButtons(FilteringButton[] buttonsToPrepare) { + private void prepareButtons(AreaCheckbox[] buttonsToPrepare) { Color textColor = ColorHelper.basePlayerColor(); Color backgroundColor = ColorHelper.darkPlayerColor(); - for (FilteringButton button : buttonsToPrepare) { + for (AreaCheckbox button : buttonsToPrepare) { button.setTextColor(textColor); button.setBackgroundColor(backgroundColor); prepareButton(button); } } - private void prepareButton(FilteringButton button) { + private void prepareButton(AreaCheckbox button) { float textScale = 1.0f; float backgroundScale = 1.0f; if (button.isStateOn()) { diff --git a/src/stelnet/filter/LogicalGate.java b/src/stelnet/filter/LogicalGate.java new file mode 100644 index 000000000..21ed846f0 --- /dev/null +++ b/src/stelnet/filter/LogicalGate.java @@ -0,0 +1,33 @@ +package stelnet.filter; + +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import stelnet.util.MemoryHelper; + +@Getter +@EqualsAndHashCode(callSuper = false) +@RequiredArgsConstructor +public class LogicalGate extends Filter { + + private final LogicalOr anyFilter; + private final LogicalAnd allFilter; + private final String allMemoryKey; + + @Override + public boolean accept(Object object) { + return getFilter().accept(object); + } + + @Override + public String toString() { + return getFilter().toString(); + } + + private Filter getFilter() { + if (MemoryHelper.getBoolean(allMemoryKey)) { + return allFilter; + } + return anyFilter; + } +}