Skip to content

Commit

Permalink
v1.5.0 (#19)
Browse files Browse the repository at this point in the history
* v0.5.0

Manual merge of upstream changes up to 0.5.0

 * Added NBT Viewer diagram
 * Updated GregTech Circuits diagram
 * Implemented horizontal scrolling

* Update GT5 dep

* Replace EnumSet with HashSet

EnumSet breaks due to dynamic modification of the OrePrefixes enum

* [ci skip] upgraded build system (#20)

Co-authored-by: Raven Szewczyk <git@eigenraven.me>

* Fix crash when EnderStorage loads too late

---------

Co-authored-by: Martin Robertz <dream-master@gmx.net>
Co-authored-by: Raven Szewczyk <git@eigenraven.me>
Co-authored-by: OneEyeMaker <oneeyemaker@gmail.com>
  • Loading branch information
4 people authored Feb 3, 2023
1 parent 65aa5b9 commit 8ef8cec
Show file tree
Hide file tree
Showing 37 changed files with 1,070 additions and 474 deletions.
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies {

compile('com.github.GTNewHorizons:DetravScannerMod:1.6.9:dev') {transitive=false}
compile('com.github.GTNewHorizons:EnderStorage:1.4.12:dev') {transitive=false}
compile('com.github.GTNewHorizons:GT5-Unofficial:5.09.41.214:dev') {transitive=false}
compile('com.github.GTNewHorizons:GT5-Unofficial:5.09.41.254:dev') {transitive=false}
compile('com.github.GTNewHorizons:GTplusplus:1.7.190:dev') {transitive=false}
compile('com.github.GTNewHorizons:NewHorizonsCoreMod:1.9.127:dev') {transitive=false}
compile('com.github.GTNewHorizons:bartworks:0.5.138:dev') {transitive=false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;

import org.lwjgl.input.Keyboard;

import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.PositionedStack;
Expand All @@ -31,8 +33,10 @@
import com.github.dcysteine.neicustomdiagram.api.diagram.interactable.InteractiveComponentGroup;
import com.github.dcysteine.neicustomdiagram.api.diagram.matcher.DiagramMatcher;
import com.github.dcysteine.neicustomdiagram.api.draw.Dimension;
import com.github.dcysteine.neicustomdiagram.api.draw.GuiManager;
import com.github.dcysteine.neicustomdiagram.api.draw.Point;
import com.github.dcysteine.neicustomdiagram.api.draw.scroll.MouseButton;
import com.github.dcysteine.neicustomdiagram.api.draw.scroll.ScrollDirection;
import com.github.dcysteine.neicustomdiagram.api.draw.scroll.ScrollManager;
import com.github.dcysteine.neicustomdiagram.main.config.ConfigOptions;
import com.google.common.collect.ImmutableList;

Expand All @@ -42,7 +46,7 @@ public class DiagramGroup implements ICraftingHandler, IUsageHandler {
protected final DiagramMatcher matcher;
protected final Supplier<DiagramState> diagramStateSupplier;

protected final GuiManager guiManager;
protected final ScrollManager scrollManager;
protected final DiagramState diagramState;
protected final ImmutableList<Diagram> diagrams;

Expand All @@ -51,7 +55,7 @@ public DiagramGroup(DiagramGroupInfo info, DiagramMatcher matcher, Supplier<Diag
this.matcher = matcher;
this.diagramStateSupplier = diagramStateSupplier;

this.guiManager = new GuiManager();
this.scrollManager = new ScrollManager();
this.diagramState = diagramStateSupplier.get();
this.diagrams = ImmutableList.of();
}
Expand All @@ -65,7 +69,7 @@ public DiagramGroup(DiagramGroup parent, Iterable<? extends Diagram> diagrams) {
this.matcher = parent.matcher;
this.diagramStateSupplier = parent.diagramStateSupplier;

this.guiManager = new GuiManager();
this.scrollManager = new ScrollManager();
this.diagramState = this.diagramStateSupplier.get();
this.diagrams = ImmutableList.copyOf(diagrams);
}
Expand Down Expand Up @@ -159,50 +163,46 @@ public final IUsageHandler getUsageHandler(String inputId, Object... ingredients
@OverridingMethodsMustInvokeSuper
@Override
public void onUpdate() {
guiManager.tick();
scrollManager.tick();
diagramState.tick();
}

@Override
public void drawBackground(int recipe) {
Diagram diagram = diagrams.get(recipe);
Dimension diagramDimension = diagram.dimension(diagramState);
guiManager.checkScrollState(diagramDimension);
guiManager.beforeDraw(diagramDimension);
scrollManager.refreshState(diagramDimension);
scrollManager.beforeDraw();

diagram.drawBackground(diagramState);

guiManager.afterDraw(diagramDimension);
scrollManager.afterDraw();
}

@Override
public void drawForeground(int recipe) {
Diagram diagram = diagrams.get(recipe);
Dimension diagramDimension = diagram.dimension(diagramState);
guiManager.beforeDraw(diagramDimension);
scrollManager.beforeDraw();

diagram.drawForeground(diagramState);
diagrams.get(recipe).drawForeground(diagramState);
Optional<Interactable> interactable = findHoveredInteractable(recipe);
interactable.ifPresent(i -> i.drawOverlay(diagramState));

guiManager.afterDraw(diagramDimension);
scrollManager.afterDraw();
}

public void drawTooltip(GuiRecipe<?> gui, int recipe) {
Diagram diagram = diagrams.get(recipe);
Dimension diagramDimension = diagram.dimension(diagramState);
guiManager.drawScrollbar(diagramDimension);
scrollManager.drawScrollbars();

Optional<Interactable> interactable = findHoveredInteractable(recipe);
interactable.ifPresent(i -> i.drawTooltip(diagramState, guiManager.getAbsoluteMousePosition()));
interactable.ifPresent(i -> i.drawTooltip(diagramState, scrollManager.getAbsoluteMousePosition()));
}

protected Optional<Interactable> findHoveredInteractable(int recipe) {
if (!mouseInBounds()) {
return Optional.empty();
}

Point mousePos = guiManager.getRelativeMousePosition(recipe);
Point mousePos = scrollManager.getRelativeMousePosition(recipe);
for (Interactable interactable : diagrams.get(recipe).interactables(diagramState)) {
if (interactable.checkBoundingBox(mousePos)) {
return Optional.of(interactable);
Expand All @@ -213,7 +213,7 @@ protected Optional<Interactable> findHoveredInteractable(int recipe) {
}

public boolean mouseInBounds() {
return guiManager.mouseInBounds();
return scrollManager.mouseInBounds();
}

public boolean interact(int recipe, Interactable.RecipeType recipeType) {
Expand All @@ -239,6 +239,21 @@ public boolean keyTyped(GuiRecipe<?> gui, char keyChar, int keyCode, int recipe)
return interact(recipe, Interactable.RecipeType.USAGE);
}

Dimension diagramDimension = diagrams.get(recipe).dimension(diagramState);
switch (keyCode) {
case Keyboard.KEY_UP:
return scrollManager.keyboardScroll(diagramDimension, ScrollDirection.UP);

case Keyboard.KEY_DOWN:
return scrollManager.keyboardScroll(diagramDimension, ScrollDirection.DOWN);

case Keyboard.KEY_LEFT:
return scrollManager.keyboardScroll(diagramDimension, ScrollDirection.LEFT);

case Keyboard.KEY_RIGHT:
return scrollManager.keyboardScroll(diagramDimension, ScrollDirection.RIGHT);
}

return false;
}

Expand All @@ -248,10 +263,8 @@ public boolean keyTyped(GuiRecipe<?> gui, char keyChar, int keyCode, int recipe)
*/
@Override
public boolean mouseClicked(GuiRecipe<?> gui, int button, int recipe) {
boolean handled = guiManager.mouseClickScrollbar(
button == 0 ? GuiManager.MouseButton.LEFT : GuiManager.MouseButton.RIGHT,
diagrams.get(recipe).dimension(diagramState));
if (handled) {
MouseButton mouseButton = button == 0 ? MouseButton.LEFT : MouseButton.RIGHT;
if (scrollManager.mouseClickScrollbar(mouseButton)) {
return true;
}

Expand All @@ -268,21 +281,14 @@ public boolean mouseClicked(GuiRecipe<?> gui, int button, int recipe) {

@Override
public boolean mouseScrolled(GuiRecipe<?> gui, int scroll, int recipe) {
if (!mouseInBounds() && !guiManager.mouseInScrollBounds()) {
return false;
}
GuiManager.ScrollDirection direction = scroll > 0 ? GuiManager.ScrollDirection.UP
: GuiManager.ScrollDirection.DOWN;
ScrollDirection direction = scroll > 0 ? ScrollDirection.UP : ScrollDirection.DOWN;

if (NEIClientUtils.shiftKey()) {
if (mouseInBounds() && NEIClientUtils.shiftKey()) {
diagramState.scroll(direction);
return true;
}

Diagram diagram = diagrams.get(recipe);
Dimension diagramDimension = diagram.dimension(diagramState);
if (guiManager.isScrollable(diagramDimension)) {
guiManager.scroll(direction);
if (scrollManager.mouseScroll(direction)) {
return true;
} else {
return ConfigOptions.DISABLE_PAGE_SCROLL.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import codechicken.nei.NEIClientUtils;

import com.github.dcysteine.neicustomdiagram.api.draw.GuiManager;
import com.github.dcysteine.neicustomdiagram.api.draw.scroll.ScrollDirection;
import com.github.dcysteine.neicustomdiagram.main.config.ConfigOptions;

/**
Expand Down Expand Up @@ -43,8 +43,8 @@ public void tick() {
}

/** "Scrolls" the tick counter by one cycle at a time. */
public void scroll(GuiManager.ScrollDirection direction) {
ticks += direction.factor * TICKS_PER_CYCLE;
public void scroll(ScrollDirection direction) {
ticks += direction.yFactor * TICKS_PER_CYCLE;
}

/** Due to backwards scrolling, {@code ticks()} may be negative! */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public abstract class Grid {

public static final int TOTAL_WIDTH = 166;
public static final int TOTAL_HEIGHT = 332;
public static final int STACK_WIDTH = 16;
public static final int SLOT_WIDTH = 18;
public static final int BIG_SLOT_WIDTH = 26;
public static final int MARGIN_WIDTH = 6;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ public void draw(DiagramState diagramState) {
* Interactables are not included here, because they will be handled by {@link Diagram}.
*
* <p>
* This means that interactables <b>will not be included</b> in the calculations for {@link #maxX()} and
* {@link #maxY()}!
* This means that interactables <b>will not be included</b> in the calculations for {@link #maxDimension()}!
*/
private Iterable<Drawable> drawables() {
return Iterables.concat(lines(), slotGroups().values(), slots().values(), labels());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,12 @@ public abstract class Text implements BoundedDrawable {
public abstract boolean shadow();

@Override
public Dimension dimension() {
int width = GuiDraw.getStringWidth(text());
int height = Draw.TEXT_HEIGHT;

if (small()) {
width /= 2;
height /= 2;
}

return Dimension.create(width, height);
}
public abstract Dimension dimension();

@Override
public void draw(DiagramState diagramState) {
Draw.drawText(text(), position(), colour(), small(), shadow());
Point topLeft = position().translate(-dimension().width() / 2, -dimension().height() / 2);
Draw.drawText(text(), topLeft, colour(), small(), shadow());
}

@ToPrettyString
Expand Down Expand Up @@ -126,10 +117,11 @@ public Text build() {
width /= 2;
height /= 2;
}
Dimension dimension = Dimension.create(width, height);

Point center = position.translate(direction.xFactor * width / 2, direction.yFactor * height / 2);

return new AutoValue_Text(text, center, colour, small, shadow);
return new AutoValue_Text(text, center, colour, small, shadow, dimension);
}
}

Expand Down Expand Up @@ -201,11 +193,21 @@ public List<Text> build() {
}

int y = position.y();
if (direction.yFactor < 0) {
// If we're extending the multi-line text upwards, then we need to move to start at
// the top of the area so that we build the lines top-to-bottom.
y -= textLines.size() * lineHeight;
// Move to top of text area.
switch (direction.yFactor) {
case -1:
y -= textLines.size() * lineHeight;
break;

case 0:
y -= textLines.size() * lineHeight / 2;
break;

case 1:
// We're already at the top.
break;
}

for (String line : textLines) {
list.add(
builder(line, Point.create(position.x(), y), direction).setColour(colour).setSmall(small)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,12 @@ public int height(TextFormatting formatting) {
* drawing code.
*/
public void draw(int x, int y, TextFormatting formatting) {
Point topLeft = Point.create(x, y);
Point center = Point.create(x + width(formatting) / 2, y + height(formatting) / 2);

switch (type()) {
case TEXT:
Draw.drawText(formatting.format(text()), center, Draw.Colour.WHITE, formatting.small(), true);
Draw.drawText(formatting.format(text()), topLeft, Draw.Colour.WHITE, formatting.small(), true);
break;

case DISPLAY_COMPONENT_ICON:
Expand All @@ -139,7 +140,7 @@ public void draw(int x, int y, TextFormatting formatting) {
case COMPONENT_DESCRIPTION:
Draw.drawText(
formatting.format(componentDescription().description()),
center,
topLeft,
Draw.Colour.WHITE,
formatting.small(),
true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* Immutable class representing a width and height.
*
* <p>
* While this class's contents are the same as those of {@link Point}, for type-safety, we treat this as a separate
* class.
* While this class's contents are the same as those of {@link Point} and {@link Vector}, for type-safety, we treat this
* as a separate class.
*/
@AutoValue
public abstract class Dimension {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,30 +130,25 @@ public static void drawArrowhead(Point a, Point b, int colour) {
}

/**
* Draws some text centered on the given point.
* Draws some text, with the given point being the top-left corner. This is different from most other draw methods,
* which draw from the center, but doing this helps avoid left-justified text being off by one pixel due to integer
* division.
*
* @param colour See {@link Draw.Colour} for colour encoding information.
* @param small Whether to draw half-scale text.
* @param shadow Whether to draw a shadow for the text.
*/
public static void drawText(String text, Point pos, int colour, boolean small, boolean shadow) {
int width = GuiDraw.getStringWidth(text);
int height = TEXT_HEIGHT;
if (small) {
width /= 2;
height /= 2;
}

int x, y;
if (small) {
x = 2 * pos.x() - width;
y = 2 * pos.y() - height;
x = 2 * pos.x();
y = 2 * pos.y();

GL11.glPushMatrix();
GL11.glScalef(0.5f, 0.5f, 0.5f);
} else {
x = pos.x() - (width / 2);
y = pos.y() - (height / 2);
x = pos.x();
y = pos.y();
}

GL11.glDisable(GL11.GL_LIGHTING);
Expand Down Expand Up @@ -200,9 +195,10 @@ public static void drawTextOverIcon(String text, Point pos, Grid.Direction dir,
textHeight /= 2;
}

Point textCenter = pos
.translate(dir.xFactor * (ICON_WIDTH - textWidth) / 2, dir.yFactor * (ICON_WIDTH - textHeight) / 2);
drawText(text, textCenter, colour, small, shadow);
Point directionPos = pos.translate(dir.xFactor * ICON_WIDTH / 2, dir.yFactor * ICON_WIDTH / 2);
Point textAnchor = directionPos
.translate(-(dir.xFactor + 1) * textWidth / 2, -(dir.yFactor + 1) * textHeight / 2);
drawText(text, textAnchor, colour, small, shadow);
}

/**
Expand Down
Loading

0 comments on commit 8ef8cec

Please sign in to comment.