Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import cam72cam.mod.entity.Player;
import cam72cam.mod.gui.helpers.GUIHelpers;
import cam72cam.mod.gui.screen.*;
import cam72cam.mod.input.Keyboard;
import cam72cam.mod.math.Vec3i;
import cam72cam.mod.net.Packet;
import cam72cam.mod.render.opengl.RenderState;
Expand Down Expand Up @@ -73,67 +74,63 @@ public void init(IScreenBuilder screen) {

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 = new Button(screen, xtop + xOffset, ytop + yOffset, buttonWidth, buttonHeight,
GuiText.SELECTOR_AUGMENT_DETECT + translate.apply(properties.stockDetectorMode),
(hand, button) -> {
properties.stockDetectorMode = next(properties.stockDetectorMode, Player.Hand.PRIMARY);
button.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 = new Button(screen, xtop + xOffset, ytop + yOffset, buttonWidth, buttonHeight,
GuiText.SELECTOR_AUGMENT_REDSTONE + translate.apply(properties.redstoneMode),
(hand, button) -> {
properties.redstoneMode = next(properties.redstoneMode, Player.Hand.PRIMARY);
button.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 = new CheckBox(screen, xtop + xOffset, ytop + yOffset, GuiText.SELECTOR_AUGMENT_PUSHPULL.toString(), properties.pushpull,
(hand, checkBox) -> {
properties.pushpull = !properties.pushpull;
checkBox.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 = new Button(screen, xtop + xOffset, ytop + yOffset, buttonWidth, buttonHeight,
GuiText.SELECTOR_AUGMENT_COUPLER + translate.apply(properties.couplerAugmentMode),
(hand, button) -> {
properties.couplerAugmentMode = next(properties.couplerAugmentMode, Player.Hand.PRIMARY);
button.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 = new Button(screen, xtop + xOffset, ytop + yOffset, buttonWidth, buttonHeight,
GuiText.SELECTOR_AUGMENT_CONTROL + translate.apply(properties.locoControlMode),
(hand, button) -> {
properties.locoControlMode = next(properties.locoControlMode, Player.Hand.PRIMARY);
button.setText(GuiText.SELECTOR_AUGMENT_CONTROL + translate.apply(properties.locoControlMode));
});
locoControlMode.setEnabled(this.augment == Augment.LOCO_CONTROL);
}

@Override
public void onEnterKey(IScreenBuilder builder) {
builder.close();
public void onKeyType(IScreenBuilder builder, Keyboard.KeyCode keyCode) {
if (keyCode == Keyboard.KeyCode.NUMPADENTER || keyCode == Keyboard.KeyCode.RETURN) {
builder.close();
}
}

@Override
Expand Down
116 changes: 56 additions & 60 deletions src/main/java/cam72cam/immersiverailroading/gui/CastingGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import cam72cam.mod.gui.screen.Button;
import cam72cam.mod.gui.screen.IScreen;
import cam72cam.mod.gui.screen.IScreenBuilder;
import cam72cam.mod.input.Keyboard;
import cam72cam.mod.item.ItemStack;
import cam72cam.mod.render.opengl.RenderState;
import cam72cam.mod.resource.Identifier;

import java.util.Collections;
Expand Down Expand Up @@ -58,85 +60,79 @@ private void updatePickerButton() {

@Override
public void init(IScreenBuilder screen) {
pickerButton = new Button(screen, -100, -20 - 10, GuiText.SELECTOR_TYPE.toString("")) {
@Override
public void onClick(Player.Hand hand) {
CraftPicker.showCraftPicker(screen, currentItem, CraftingType.CASTING, (ItemStack item) -> {
if (item != null) {
currentItem = item;
EntityRollingStockDefinition def =
currentItem.is(IRItems.ITEM_ROLLING_STOCK_COMPONENT) ?
new ItemRollingStockComponent.Data(currentItem).def :
new ItemRollingStock.Data(currentItem).def;
if (def != null && !gauge.isModel() && gauge.value() != def.recommended_gauge.value()) {
gauge = def.recommended_gauge;
gaugeButton.setText(GuiText.SELECTOR_GAUGE.toString(gauge));
}
updatePickerButton();
sendItemPacket();
}
});
}
};
pickerButton = new Button(screen, -100, -20 - 10, GuiText.SELECTOR_TYPE.toString(""),
(hand, button) -> {
CraftPicker.showCraftPicker(screen, currentItem, CraftingType.CASTING, (ItemStack item) -> {
if (item != null) {
currentItem = item;
EntityRollingStockDefinition def =
currentItem.is(IRItems.ITEM_ROLLING_STOCK_COMPONENT) ?
new ItemRollingStockComponent.Data(currentItem).def :
new ItemRollingStock.Data(currentItem).def;
if (def != null && !gauge.isModel() && gauge.value() != def.recommended_gauge.value()) {
gauge = def.recommended_gauge;
gaugeButton.setText(GuiText.SELECTOR_GAUGE.toString(gauge));
}
updatePickerButton();
sendItemPacket();
}
});
});
updatePickerButton();

gaugeButton = new Button(screen, 0, -10, 100, 20, GuiText.SELECTOR_GAUGE.toString(gauge)) {
@Override
public void onClick(Player.Hand hand) {
if(!currentItem.isEmpty()) {
EntityRollingStockDefinition def = new ItemRollingStockComponent.Data(currentItem).def;
if (def != null && ConfigBalance.DesignGaugeLock) {
List<Gauge> validGauges = Collections.singletonList(Gauge.from(def.recommended_gauge.value()));
gauge = next(validGauges, gauge, hand);
} else {
gauge = next(Gauge.values(), gauge, hand);
}
}
gaugeButton.setText(GuiText.SELECTOR_GAUGE.toString(gauge));
sendItemPacket();
}
};
singleCastButton = new Button(screen, 0, +20 - 10, 100, 20, GuiText.SELECTOR_CAST_SINGLE.toString()) {
@Override
public void onClick(Player.Hand hand) {
if (tile.getCraftMode() != CraftingMachineMode.SINGLE) {
tile.setCraftMode(CraftingMachineMode.SINGLE);
} else {
tile.setCraftMode(CraftingMachineMode.STOPPED);
}
}
gaugeButton = new Button(screen, 0, -10, 100, 20, GuiText.SELECTOR_GAUGE.toString(gauge),
(hand, button) -> {
if(!currentItem.isEmpty()) {
EntityRollingStockDefinition def = new ItemRollingStockComponent.Data(currentItem).def;
if (def != null && ConfigBalance.DesignGaugeLock) {
List<Gauge> validGauges = Collections.singletonList(Gauge.from(def.recommended_gauge.value()));
gauge = next(validGauges, gauge, hand);
} else {
gauge = next(Gauge.values(), gauge, hand);
}
}
gaugeButton.setText(GuiText.SELECTOR_GAUGE.toString(gauge));
sendItemPacket();
});
singleCastButton = new Button(screen, 0, +20 - 10, 100, 20, GuiText.SELECTOR_CAST_SINGLE.toString(),
(hand, button) -> {
if (tile.getCraftMode() != CraftingMachineMode.SINGLE) {
tile.setCraftMode(CraftingMachineMode.SINGLE);
} else {
tile.setCraftMode(CraftingMachineMode.STOPPED);
}
}) {
@Override
public void onUpdate() {
singleCastButton.setTextColor(tile.getCraftMode() == CraftingMachineMode.SINGLE ? 0xcc4334 : 0);
}
};
repeatCastButton = new Button(screen, 0, +40 - 10, 100, 20, GuiText.SELECTOR_CAST_REPEAT.toString()) {
@Override
public void onClick(Player.Hand hand) {
if (tile.getCraftMode() != CraftingMachineMode.REPEAT) {
tile.setCraftMode(CraftingMachineMode.REPEAT);
} else {
tile.setCraftMode(CraftingMachineMode.STOPPED);
}
}

repeatCastButton = new Button(screen, 0, +40 - 10, 100, 20, GuiText.SELECTOR_CAST_REPEAT.toString(),
(hand, button) -> {
if (tile.getCraftMode() != CraftingMachineMode.REPEAT) {
tile.setCraftMode(CraftingMachineMode.REPEAT);
} else {
tile.setCraftMode(CraftingMachineMode.STOPPED);
}
}) {
@Override
public void onUpdate() {
repeatCastButton.setTextColor(tile.getCraftMode() == CraftingMachineMode.REPEAT ? 0xcc4334 : 0);
}
};
}

@Override
public void onEnterKey(IScreenBuilder b) {
}
@Override
public void onKeyType(IScreenBuilder builder, Keyboard.KeyCode keyCode) {
}

@Override
@Override
public void onClose() {

}

@Override
public void draw(IScreenBuilder builder) {
public void draw(IScreenBuilder builder, RenderState state) {
double fluidPercent = ((CastingInstance) tile.getMultiblock()).getSteelLevel();
int progress = this.tile.getCraftProgress();
float cost;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import cam72cam.immersiverailroading.model.StockModel;
import cam72cam.mod.MinecraftClient;
import cam72cam.mod.entity.Entity;
import cam72cam.mod.entity.Player;
import cam72cam.mod.gui.helpers.GUIHelpers;
import cam72cam.mod.gui.screen.*;
import cam72cam.mod.input.Keyboard;
import cam72cam.mod.render.opengl.RenderState;
import util.Matrix4;

Expand Down Expand Up @@ -47,57 +47,42 @@ public void init(IScreenBuilder screen) {
int width = 200;
int height = 20;

new ListSelector<String>(screen, 0, width, height, variant,
stock.getDefinition().textureNames.entrySet().stream()
.collect(Collectors.toMap(
Map.Entry::getValue, Map.Entry::getKey,
(u, v) -> u, LinkedHashMap::new))
) {
@Override
public void onClick(String option) {
variant = option;
}
}.setVisible(true);
new ListSelector<>(screen, 0, width, height, variant,
stock.getDefinition().textureNames.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey, (u, v) -> u, LinkedHashMap::new)),
(sel, val) -> variant = val
).setVisible(true);

Slider zoom_slider = new Slider(screen, xtop + width, (int) (GUIHelpers.getScreenHeight()*0.75 - height),
GuiText.SLIDER_ZOOM.toString(), 0.1, 2, 1, true) {
@Override
public void onSlider() {
zoom = this.getValue();
}
};
GuiText.SLIDER_ZOOM.toString(), 0.1, 2, 1, true,
slider -> zoom = slider.getValue());

width = 100;
Button random = new Button(screen, GUIHelpers.getScreenWidth() / 2 - width, ytop, width, height,
GuiText.SELECTOR_PAINTBRUSH_RANDOM.toString()) {
@Override
public void onClick(Player.Hand hand) {
variant = ItemPaintBrush.nextRandomTexture(stock, variant);
}
};
GuiText.SELECTOR_PAINTBRUSH_RANDOM.toString(),
(hand, button) -> variant = ItemPaintBrush.nextRandomTexture(stock, variant));

Button apply = new Button(screen, GUIHelpers.getScreenWidth() / 2 - width, (int) (GUIHelpers.getScreenHeight()*0.75 - height*2),
width, height, GuiText.SELECTOR_PAINTBRUSH_TO_STOCK.toString()) {
@Override
public void onClick(Player.Hand hand) {
new ItemPaintBrush.PaintBrushPacket(stock, PaintBrushMode.GUI, variant, false).sendToServer();
screen.close();
}
};
width, height, GuiText.SELECTOR_PAINTBRUSH_TO_STOCK.toString(),
(hand, button) -> {
new ItemPaintBrush.PaintBrushPacket(stock, PaintBrushMode.GUI, variant, false).sendToServer();
screen.close();
});

Button apply_connected = new Button(screen, GUIHelpers.getScreenWidth() / 2 - width, (int) (GUIHelpers.getScreenHeight()*0.75 - height),
width, height, GuiText.SELECTOR_PAINTBRUSH_TO_TRAIN.toString()) {
@Override
public void onClick(Player.Hand hand) {
new ItemPaintBrush.PaintBrushPacket(stock, PaintBrushMode.GUI, variant, true).sendToServer();
screen.close();
}
};
width, height, GuiText.SELECTOR_PAINTBRUSH_TO_TRAIN.toString(),
(hand, button) -> {
new ItemPaintBrush.PaintBrushPacket(stock, PaintBrushMode.GUI, variant, true).sendToServer();
screen.close();
});
}

@Override
public void onEnterKey(IScreenBuilder builder) {
new ItemPaintBrush.PaintBrushPacket(stock, PaintBrushMode.GUI, variant, false).sendToServer();
builder.close();
public void onKeyType(IScreenBuilder builder, Keyboard.KeyCode keyCode) {
if (keyCode == Keyboard.KeyCode.NUMPADENTER || keyCode == Keyboard.KeyCode.RETURN) {
new ItemPaintBrush.PaintBrushPacket(stock, PaintBrushMode.GUI, variant, false).sendToServer();
builder.close();
}
}

@Override
Expand Down
Loading