-
Notifications
You must be signed in to change notification settings - Fork 80
[Feature] Add stock tag system & augment GUI #1578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Goldenfield192
wants to merge
16
commits into
TeamOpenIndustry:master
Choose a base branch
from
Goldenfield192:stock-tags
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
2a3a149
feat: add basic stock tag system
Goldenfield192 4f0b776
feat: add augment gui
Goldenfield192 74e1c31
feat: rework augment filter
Goldenfield192 32700e3
fix: add filter for speed retarder
Goldenfield192 1c9f65b
feat: migrate stock existing `tag`
Goldenfield192 8a02fdf
feat: migrate tile existing `augmentFilterID`
Goldenfield192 f188c66
fix typo
Goldenfield192 44e6e5c
Add display text
Goldenfield192 bd75f44
i18n: add translation keys
Goldenfield192 faded64
fix: remove comment
Goldenfield192 e452e13
feat: rewrite filter implement
Goldenfield192 239628b
fix: add error handler
Goldenfield192 67a5d45
docs: add comment
Goldenfield192 b096e19
docs: add comment
Goldenfield192 3be135b
Merge branch 'master' into stock-tags
Goldenfield192 fa5dfdf
feat: add cg filter for actuator
Goldenfield192 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
187 changes: 187 additions & 0 deletions
187
src/main/java/cam72cam/immersiverailroading/gui/AugmentFilterGUI.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
package cam72cam.immersiverailroading.gui; | ||
|
||
import cam72cam.immersiverailroading.library.*; | ||
import cam72cam.immersiverailroading.tile.TileRailBase; | ||
import cam72cam.mod.entity.Player; | ||
import cam72cam.mod.gui.helpers.GUIHelpers; | ||
import cam72cam.mod.gui.screen.*; | ||
import cam72cam.mod.math.Vec3i; | ||
import cam72cam.mod.net.Packet; | ||
import cam72cam.mod.render.opengl.RenderState; | ||
import cam72cam.mod.serialization.TagField; | ||
import cam72cam.mod.text.TextUtil; | ||
|
||
import java.util.function.Function; | ||
|
||
import static cam72cam.immersiverailroading.gui.ClickListHelper.next; | ||
|
||
public class AugmentFilterGUI implements IScreen { | ||
private final Vec3i pos; | ||
private final Augment augment; | ||
private final Augment.Properties properties; | ||
private TextField includeTags; | ||
private TextField excludeTags; | ||
private Button stockDetectorMode; | ||
private Button redstoneMode; | ||
private CheckBox pushpull; | ||
private Button couplerMode; | ||
private Button locoControlMode; | ||
|
||
public AugmentFilterGUI(TileRailBase tileRailBase) { | ||
this.pos = tileRailBase.getPos(); | ||
this.augment = tileRailBase.getAugment(); | ||
this.properties = tileRailBase.getAugmentProperties() == null | ||
? Augment.Properties.EMPTY | ||
: tileRailBase.getAugmentProperties(); | ||
} | ||
|
||
@Override | ||
public void init(IScreenBuilder screen) { | ||
int xtop = -GUIHelpers.getScreenWidth() / 2; | ||
int ytop = -GUIHelpers.getScreenHeight() / 4; | ||
|
||
int xOffset = 0; | ||
int yOffset = 40; | ||
|
||
int buttonWidth = 220; | ||
int buttonHeight = 20; | ||
|
||
includeTags = new TextField(screen, xtop + xOffset, ytop + yOffset, buttonWidth-1, buttonHeight); | ||
includeTags.setText(properties.positiveFilter); | ||
includeTags.setValidator(s -> { | ||
properties.positiveFilter = s; | ||
return true; | ||
}); | ||
yOffset += 40; | ||
|
||
excludeTags = new TextField(screen, xtop + xOffset, ytop + yOffset, buttonWidth-1, buttonHeight); | ||
excludeTags.setText(properties.negativeFilter); | ||
excludeTags.setValidator(s -> { | ||
properties.negativeFilter = s; | ||
return true; | ||
}); | ||
yOffset += 25; | ||
|
||
Function<Enum<?>, String> translate = e -> TextUtil.translate(e.toString()); | ||
|
||
stockDetectorMode = new Button(screen, xtop + xOffset, ytop + yOffset, buttonWidth, buttonHeight, GuiText.SELECTOR_AUGMENT_DETECT + translate.apply(properties.stockDetectorMode)) { | ||
@Override | ||
public void onClick(Player.Hand hand) { | ||
properties.stockDetectorMode = next(properties.stockDetectorMode, Player.Hand.PRIMARY); | ||
stockDetectorMode.setText(GuiText.SELECTOR_AUGMENT_DETECT + translate.apply(properties.stockDetectorMode)); | ||
} | ||
}; | ||
stockDetectorMode.setEnabled(this.augment == Augment.DETECTOR); | ||
yOffset += 25; | ||
|
||
redstoneMode = new Button(screen, xtop + xOffset, ytop + yOffset, buttonWidth, buttonHeight, GuiText.SELECTOR_AUGMENT_REDSTONE + translate.apply(properties.redstoneMode)) { | ||
@Override | ||
public void onClick(Player.Hand hand) { | ||
properties.redstoneMode = next(properties.redstoneMode, Player.Hand.PRIMARY); | ||
redstoneMode.setText(GuiText.SELECTOR_AUGMENT_REDSTONE + translate.apply(properties.redstoneMode)); | ||
} | ||
}; | ||
redstoneMode.setEnabled(this.augment == Augment.COUPLER | ||
|| this.augment == Augment.ITEM_LOADER | ||
|| this.augment == Augment.ITEM_UNLOADER | ||
|| this.augment == Augment.FLUID_LOADER | ||
|| this.augment == Augment.FLUID_UNLOADER); | ||
yOffset += 25; | ||
|
||
pushpull = new CheckBox(screen, xtop + xOffset, ytop + yOffset, GuiText.SELECTOR_AUGMENT_PUSHPULL.toString(), properties.pushpull) { | ||
@Override | ||
public void onClick(Player.Hand hand) { | ||
properties.pushpull = !properties.pushpull; | ||
pushpull.setChecked(properties.pushpull); | ||
} | ||
}; | ||
pushpull.setEnabled(this.augment == Augment.COUPLER | ||
|| this.augment == Augment.ITEM_LOADER | ||
|| this.augment == Augment.ITEM_UNLOADER | ||
|| this.augment == Augment.FLUID_LOADER | ||
|| this.augment == Augment.FLUID_UNLOADER); | ||
yOffset += 15; | ||
|
||
couplerMode = new Button(screen, xtop + xOffset, ytop + yOffset, buttonWidth, buttonHeight, GuiText.SELECTOR_AUGMENT_COUPLER + translate.apply(properties.couplerAugmentMode)) { | ||
@Override | ||
public void onClick(Player.Hand hand) { | ||
properties.couplerAugmentMode = next(properties.couplerAugmentMode, Player.Hand.PRIMARY); | ||
couplerMode.setText(GuiText.SELECTOR_AUGMENT_COUPLER + translate.apply(properties.couplerAugmentMode)); | ||
} | ||
}; | ||
couplerMode.setEnabled(this.augment == Augment.COUPLER); | ||
yOffset += 25; | ||
|
||
locoControlMode = new Button(screen, xtop + xOffset, ytop + yOffset, buttonWidth, buttonHeight, GuiText.SELECTOR_AUGMENT_CONTROL + translate.apply(properties.locoControlMode)) { | ||
@Override | ||
public void onClick(Player.Hand hand) { | ||
properties.locoControlMode = next(properties.locoControlMode, Player.Hand.PRIMARY); | ||
locoControlMode.setText(GuiText.SELECTOR_AUGMENT_CONTROL + translate.apply(properties.locoControlMode)); | ||
} | ||
}; | ||
locoControlMode.setEnabled(this.augment == Augment.LOCO_CONTROL); | ||
} | ||
|
||
@Override | ||
public void onEnterKey(IScreenBuilder builder) { | ||
builder.close(); | ||
} | ||
|
||
@Override | ||
public void onClose() { | ||
if(properties.positiveFilter == null) { | ||
properties.positiveFilter = ""; | ||
} | ||
if (properties.negativeFilter == null) { | ||
properties.negativeFilter = ""; | ||
} | ||
new AugmentFilterChangePacket(pos, properties).sendToServer(); | ||
} | ||
|
||
@Override | ||
public void draw(IScreenBuilder builder, RenderState state) { | ||
IScreen.super.draw(builder, state); | ||
|
||
GUIHelpers.drawRect(0, 0, GUIHelpers.getScreenWidth(), GUIHelpers.getScreenHeight(), 0x88000000); | ||
|
||
GUIHelpers.drawRect(0, 0, 220, GUIHelpers.getScreenHeight(), 0xCC000000); | ||
|
||
int xtop = -GUIHelpers.getScreenWidth() / 2; | ||
int ytop = -GUIHelpers.getScreenHeight() / 4; | ||
|
||
int xOffset = 110; | ||
int yOffset = 30; | ||
GUIHelpers.drawCenteredString(GuiText.LABEL_CURRENT_AUGMENT + this.augment.toString(), xOffset, 10, 0xFFFFFFFF); | ||
|
||
GUIHelpers.drawCenteredString(GuiText.LABEL_INCLUDED_TAG.toString(), xOffset, yOffset, 0xFFFFFFFF); | ||
includeTags.setText(properties.positiveFilter); | ||
yOffset+=40; | ||
|
||
GUIHelpers.drawCenteredString(GuiText.LABEL_EXCLUDED_TAG.toString(), xOffset, yOffset, 0xFFFFFFFF); | ||
excludeTags.setText(properties.negativeFilter); | ||
} | ||
|
||
public static class AugmentFilterChangePacket extends Packet { | ||
@TagField | ||
Vec3i pos; | ||
|
||
@TagField | ||
Augment.Properties properties; | ||
|
||
public AugmentFilterChangePacket() { | ||
} | ||
|
||
public AugmentFilterChangePacket(Vec3i pos, Augment.Properties filter) { | ||
this.pos = pos; | ||
this.properties = filter; | ||
} | ||
|
||
@Override | ||
protected void handle() { | ||
TileRailBase railBase = this.getWorld().getBlockEntity(pos, TileRailBase.class); | ||
if (railBase != null && railBase.getAugment() != null) { | ||
railBase.setAugmentProperties(properties); | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.