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
8 changes: 0 additions & 8 deletions src/main/java/vswe/stevesfactory/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ public static final class ClientCategory {
// Factory manager GUI options
public final BooleanValue useFixedSizeScreen;
public final BooleanValue useBackgroundOnFullscreen;
public final IntValue defaultEditorMoveSpeed;
public final IntValue acceleratedEditorMoveSpeed;

private ClientCategory(Builder builder) {
builder.comment("General client config options").push("general");
Expand All @@ -165,12 +163,6 @@ private ClientCategory(Builder builder) {
useBackgroundOnFullscreen = builder
.comment("Enable to use vanilla background instead of a plain rectangle")
.define("useBackgroundOnFullscreen", false);
defaultEditorMoveSpeed = builder
.comment("Determines how fast arrow keys moving is (for editor panel)")
.defineInRange("defaultEditorMoveSpeed", 2, 0, Integer.MAX_VALUE);
acceleratedEditorMoveSpeed = builder
.comment("Determines how fast arrow keys moving is, while Shift is pressed")
.defineInRange("acceleratedEditorMoveSpeed", 20, 0, Integer.MAX_VALUE);
builder.pop();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ public static void drawColorLogic(int x, int y, int width, int height, int red,
RenderSystem.enableTexture();
}

public static void drawBorderedBox(int x1, int y1, int x2, int y2) {
GlStateManager.disableTexture();
drawRect(x1, y1, x2, y2, 0xff404040);
drawRect(x1 + 1, y1 + 1, x2 - 1, y2 - 1, 0xff5e5e5e);
GlStateManager.enableTexture();
}

public static void drawThickBeveledBox(int x1, int y1, int x2, int y2, int thickness, int topLeftColor, int bottomRightColor, int fillColor) {
RenderSystem.disableTexture();
drawRect(x1, y1, x2, y2, bottomRightColor);
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/vswe/stevesfactory/library/gui/ScissorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public final class ScissorTest {
public static ScissorTest scaled(int x, int y, int width, int height) {
MainWindow mainWindow = Minecraft.getInstance().getMainWindow();
double scale = mainWindow.getGuiScaleFactor();
x += RenderingHelper.getTranslationX();
y += RenderingHelper.getTranslationY();
return new ScissorTest((int) (x * scale), (int) (mainWindow.getHeight() - ((y + height) * scale)),
(int) (width * scale), (int) (height * scale));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package vswe.stevesfactory.library.gui;

import com.google.common.base.MoreObjects;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.ResourceLocation;
Expand All @@ -9,6 +10,8 @@

import java.awt.*;

import static org.lwjgl.opengl.GL11.GL_QUADS;

/**
* Wraps around a ResourceLocation, used to simplify drawing 2D textures.
*/
Expand Down Expand Up @@ -57,8 +60,10 @@ public void draw(int x, int y) {
}

public void draw(int x, int y, int width, int height) {
RenderSystem.enableAlphaTest();
RenderSystem.color3f(1F, 1F, 1F);
RenderingHelper.bindTexture(texture);
RenderingHelper.getRenderer().begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
RenderingHelper.getRenderer().begin(GL_QUADS, DefaultVertexFormats.POSITION_TEX);
vertices(x, y, width, height);
Tessellator.getInstance().draw();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package vswe.stevesfactory.library.gui.widget;

import com.google.common.base.Preconditions;
import it.unimi.dsi.fastutil.ints.Int2BooleanFunction;
import vswe.stevesfactory.library.gui.TextureWrapper;

public class CallbackIconButton extends AbstractIconButton {

public static final Int2BooleanFunction DUMMY = b -> false;

private TextureWrapper textureNormal;
private TextureWrapper textureHovering;
public Int2BooleanFunction onClick = DUMMY;

public CallbackIconButton(TextureWrapper textureNormal, TextureWrapper textureHovering) {
super(0, 0, 0, 0);
this.setTextures(textureNormal, textureHovering);
}

@Override
public TextureWrapper getTextureNormal() {
return textureNormal;
}

@Override
public TextureWrapper getTextureHovered() {
return textureHovering;
}

public void setTextureNormal(TextureWrapper textureNormal) {
checkArguments(textureNormal, textureHovering);
this.textureNormal = textureNormal;
this.setDimensions(textureNormal.getPortionWidth(), textureNormal.getPortionHeight());
}

public void setTextureHovering(TextureWrapper textureHovering) {
checkArguments(textureNormal, textureHovering);
this.textureHovering = textureHovering;
this.setDimensions(textureHovering.getPortionWidth(), textureHovering.getPortionHeight());
}

public void setTextures(TextureWrapper textureNormal, TextureWrapper textureHovering) {
checkArguments(textureNormal, textureHovering);
this.textureNormal = textureNormal;
this.textureHovering = textureHovering;
// Either one is fine, since we checked that they are the same size
this.setDimensions(textureNormal.getPortionWidth(), textureNormal.getPortionHeight());
}

private static void checkArguments(TextureWrapper textureNormal, TextureWrapper textureHovering) {
Preconditions.checkArgument(textureNormal.getPortionWidth() == textureHovering.getPortionWidth());
Preconditions.checkArgument(textureNormal.getPortionHeight() == textureHovering.getPortionHeight());
}

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
return onClick.apply(button);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package vswe.stevesfactory.library.gui.widget;

import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.Minecraft;
import vswe.stevesfactory.library.gui.debug.RenderEventDispatcher;
Expand Down
38 changes: 16 additions & 22 deletions src/main/java/vswe/stevesfactory/library/gui/window/Dialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,23 @@
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import java.util.function.*;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.IntConsumer;
import java.util.function.Supplier;

public class Dialog extends AbstractPopupWindow {

public static Dialog createPrompt(String message, BiConsumer<Integer, String> onConfirm) {
return createPrompt(message, onConfirm, (b, t) -> {});
}

public static Dialog createPrompt(String message, BiConsumer<Integer, String> onConfirm, BiConsumer<Integer, String> onCancel) {
return createPrompt(message, "", onConfirm, onCancel);
}

public static Dialog createPrompt(String message, String defaultText, BiConsumer<Integer, String> onConfirm) {
return createPrompt(message, defaultText, onConfirm, (b, t) -> {});
}

public static Dialog createPrompt(String message, String defaultText, BiConsumer<Integer, String> onConfirm, BiConsumer<Integer, String> onCancel) {
return createPrompt(message, defaultText, "gui.sfm.ok", "gui.sfm.cancel", onConfirm, onCancel);
}

public static Dialog createPrompt(String message, String defaultText, String confirm, String cancel, BiConsumer<Integer, String> onConfirm, BiConsumer<Integer, String> onCancel) {
public static Dialog createPrompt(
String message,
Supplier<? extends TextField> fieldProvider,
String confirm, String cancel,
BiConsumer<Integer, String> onConfirm,
BiConsumer<Integer, String> onCancel
) {
Dialog dialog = dialog(message);

TextField inputBox = new TextField(0, 0, 0, 16);
inputBox.setText(defaultText);
TextField inputBox = fieldProvider.get();
dialog.insertBeforeButtons(inputBox);
dialog.onPostReflow = inputBox::expandHorizontally;

Expand Down Expand Up @@ -123,8 +115,10 @@ private static Dialog dialog(String message) {
private Box<TextButton> buttons;
private List<AbstractWidget> children;

public Runnable onPreReflow = () -> {};
public Runnable onPostReflow = () -> {};
public Runnable onPreReflow = () -> {
};
public Runnable onPostReflow = () -> {
};

public Dialog() {
this.messageBox = new TextList(10, 10, new ArrayList<>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import vswe.stevesfactory.ui.manager.editor.ConnectionsPanel;
import vswe.stevesfactory.ui.manager.editor.EditorPanel;
import vswe.stevesfactory.ui.manager.selection.SelectionPanel;
import vswe.stevesfactory.ui.manager.tool.ToolPanel;
import vswe.stevesfactory.ui.manager.tool.ToolHolderPanel;
import vswe.stevesfactory.ui.manager.tool.group.GroupDataModel;
import vswe.stevesfactory.ui.manager.toolbox.ToolboxPanel;

Expand Down Expand Up @@ -191,7 +191,7 @@ public static class TopLevelWidget extends AbstractContainer<DynamicWidthWidget<
public final SelectionPanel selectionPanel;
public final EditorPanel editorPanel;
public final ConnectionsPanel connectionsPanel;
public final ToolPanel toolPanel;
public final ToolHolderPanel toolHolderPanel;
public final ToolboxPanel toolboxPanel;
private final ImmutableList<DynamicWidthWidget<?>> children;

Expand All @@ -200,10 +200,10 @@ private TopLevelWidget(PrimaryWindow window) {
this.selectionPanel = new SelectionPanel();
this.editorPanel = new EditorPanel();
this.connectionsPanel = new ConnectionsPanel();
this.toolPanel = new ToolPanel();
this.toolHolderPanel = new ToolHolderPanel();
this.toolboxPanel = new ToolboxPanel();
// Let connections panel receive events first
this.children = ImmutableList.of(selectionPanel, connectionsPanel, editorPanel, toolPanel, toolboxPanel);
this.children = ImmutableList.of(selectionPanel, connectionsPanel, editorPanel, toolHolderPanel, toolboxPanel);
}

public void init() {
Expand Down Expand Up @@ -250,14 +250,14 @@ public void reflow() {
selectionPanel.setHeight(prevHeight);
editorPanel.setHeight(prevHeight);
connectionsPanel.setHeight(prevHeight);
toolPanel.setHeight(prevHeight);
toolHolderPanel.setHeight(prevHeight);
toolboxPanel.setHeight(prevHeight);
}

selectionPanel.reflow();
editorPanel.reflow();
connectionsPanel.reflow();
toolPanel.reflow();
toolHolderPanel.reflow();
toolboxPanel.reflow();
DynamicWidthWidget.reflowDynamicWidth(getDimensions(), children);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,22 +253,6 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
return true;
}
}

int offset = Screen.hasShiftDown() ? Config.CLIENT.acceleratedEditorMoveSpeed.get() : Config.CLIENT.defaultEditorMoveSpeed.get();
switch (keyCode) {
case GLFW_KEY_UP:
yOffset.add(offset);
break;
case GLFW_KEY_DOWN:
yOffset.subtract(offset);
break;
case GLFW_KEY_LEFT:
xOffset.add(offset);
break;
case GLFW_KEY_RIGHT:
xOffset.subtract(offset);
break;
}
return false;
}

Expand Down Expand Up @@ -301,9 +285,9 @@ public void update(float particleTicks) {

private void openActionMenu() {
ContextMenu contextMenu = ContextMenu.atCursor(ImmutableList.of(
new CallbackEntry(FactoryManagerGUI.PASTE_ICON, "gui.sfm.FactoryManager.Editor.CtxMenu.Paste", b -> actionPaste()),
new CallbackEntry(null, "gui.sfm.FactoryManager.Editor.CtxMenu.CleanupProcedures", b -> actionCleanup()),
new CallbackEntry(null, "gui.sfm.FactoryManager.Generic.CtxMenu.ToggleFullscreen", b -> FactoryManagerGUI.get().getPrimaryWindow().toggleFullscreen())
new CallbackEntry(FactoryManagerGUI.PASTE_ICON, "gui.sfm.FactoryManager.Editor.Paste", b -> actionPaste()),
new CallbackEntry(null, "gui.sfm.FactoryManager.Editor.CleanupProcedures", b -> actionCleanup()),
new CallbackEntry(null, "gui.sfm.FactoryManager.Generic.ToggleFullscreen", b -> FactoryManagerGUI.get().getPrimaryWindow().toggleFullscreen())
));
WidgetScreen.getCurrent().addPopupWindow(contextMenu);
}
Expand All @@ -314,7 +298,7 @@ private void actionPaste() {
try {
tag = JsonToNBT.getTagFromJson(json);
} catch (CommandSyntaxException e) {
Dialog.createDialog("gui.sfm.FactoryManager.Editor.Dialog.PasteProcedure.Fail").tryAddSelfToActiveGUI();
Dialog.createDialog("gui.sfm.FactoryManager.Editor.Paste.Fail").tryAddSelfToActiveGUI();
return;
}

Expand Down
Loading