Skip to content
This repository has been archived by the owner on Feb 4, 2024. It is now read-only.

Market queries enhancements #112

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions assets/data/l10n/query.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions src/stelnet/board/query/QueryL10n.java
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions src/stelnet/board/query/view/manage/BuilderBehaviorButton.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
9 changes: 9 additions & 0 deletions src/stelnet/board/query/view/manage/ButtonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
24 changes: 20 additions & 4 deletions src/stelnet/board/query/view/manage/ManageResultsFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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
Expand All @@ -50,20 +59,27 @@ public List<Renderable> 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()) {
Expand Down
33 changes: 33 additions & 0 deletions src/stelnet/filter/LogicalGate.java
Original file line number Diff line number Diff line change
@@ -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 {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably not needed


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;
}
}