Skip to content
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

Cool quest gui #105

Open
wants to merge 7 commits into
base: 1.12
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
4 changes: 2 additions & 2 deletions src/main/java/betterquesting/api/storage/BQ_Settings.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package betterquesting.api.storage;

import betterquesting.core.ModReference;
import net.minecraft.util.ResourceLocation;

import java.io.File;
import net.minecraft.util.ResourceLocation;

/**
* A container for all the configurable settings in the mod
Expand Down Expand Up @@ -37,4 +36,5 @@ public class BQ_Settings {
public static String defaultVisibility = "NORMAL";

public static boolean spawnWithQuestBook = true;
public static boolean taskFoldedInitially = false;
}
201 changes: 143 additions & 58 deletions src/main/java/betterquesting/api/utils/RenderUtils.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
package betterquesting.api2.client.gui.panels.content;

import java.util.List;

import org.lwjgl.opengl.GL11;

import betterquesting.api.utils.RenderUtils;
import betterquesting.api2.client.gui.misc.IGuiRect;
import betterquesting.api2.client.gui.panels.IGuiPanel;
import betterquesting.api2.client.gui.resources.colors.GuiColorStatic;
import betterquesting.api2.client.gui.themes.presets.PresetIcon;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;

/**
* Displays task info over the panel.
*/
public class PanelTaskOverlay implements IGuiPanel {

public static final float FRAME_WIDTH = 2;

private final IGuiPanel delegate;
private State state;
private boolean consume;
private String text; // Long text will be scaled.

public PanelTaskOverlay(IGuiPanel delegate) { this.delegate = delegate; }

public PanelTaskOverlay setState(State state) {
this.state = state;
return this;
}

public PanelTaskOverlay setConsume(boolean consume) {
this.consume = consume;
return this;
}

public PanelTaskOverlay setText(String text) {
this.text = text;
return this;
}

@Override
public void drawPanel(int mx, int my, float partialTick) {
delegate.drawPanel(mx, my, partialTick);
switch (state) {
case INCOMPLETE -> {
renderIncomplete();
if (consume)
renderConsumeIcon(mx, my);
}
case COMPLETE -> {
renderComplete(mx, my);
}
case IN_PROGRESS -> {
renderInProgress();
if (consume)
renderConsumeIcon(mx, my);
}
}
renderText(mx, my);
}

// delegates

@Override
public IGuiRect getTransform() { return delegate.getTransform(); }

@Override
public void initPanel() {
delegate.initPanel();
}

@Override
public void setEnabled(boolean state) {
delegate.setEnabled(state);
}

@Override
public boolean isEnabled() { return delegate.isEnabled(); }

@Override
public boolean onMouseClick(int mx, int my, int button) {
return delegate.onMouseClick(mx, my, button);
}

@Override
public boolean onMouseRelease(int mx, int my, int button) {
return delegate.onMouseRelease(mx, my, button);
}

@Override
public boolean onMouseScroll(int mx, int my, int scroll) {
return delegate.onMouseScroll(mx, my, scroll);
}

@Override
public boolean onKeyTyped(char c, int keycode) {
return delegate.onKeyTyped(c, keycode);
}

@Override
public List<String> getTooltip(int mx, int my) {
return delegate.getTooltip(mx, my);
}

private void renderIncomplete() {
renderFrame(0.2f * RenderUtils.sineWave(2, 0) + 0.3f, 0, 0, 1);
}

private void renderComplete(int mx, int my) {
renderFrame(0.2f, 1, 0, 1);
int size = 12;
IGuiRect rect = getTransform();
int x = rect.getX() + rect.getWidth() - size + 2;
int y = rect.getY() - 2;
int a = getTransform().contains(mx, my) ? 100 : 255;
PresetIcon.ICON_CHECK.getTexture().drawTexture(x, y, size, size, 0, 0, new GuiColorStatic(0, 255, 0, a));
}

private void renderInProgress() {
float r = 0.3f * RenderUtils.sineWave(2, 0) + 0.3f;
float g = r;
renderFrame(r, g, 0, 1);
}

private void renderFrame(float red, float green, float blue, float alpha) {
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder vertexbuffer = tessellator.getBuffer();
GlStateManager.enableBlend();
GlStateManager.disableTexture2D();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA,
GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA,
GlStateManager.SourceFactor.ONE,
GlStateManager.DestFactor.ZERO);
GlStateManager.color(red, green, blue, alpha);

vertexbuffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION);
IGuiRect rect = getTransform();
double w = FRAME_WIDTH / 2;
vertexbuffer.pos((double) rect.getX() - w, (double) rect.getY() + w, 0.0D).endVertex();
vertexbuffer.pos((double) rect.getX() + rect.getWidth() + w, (double) rect.getY() + w, 0.0D).endVertex();
vertexbuffer.pos((double) rect.getX() + rect.getWidth() + w, (double) rect.getY() - w, 0.0D).endVertex();
vertexbuffer.pos((double) rect.getX() - w, (double) rect.getY() - w, 0.0D).endVertex();

vertexbuffer.pos((double) rect.getX() - w, (double) rect.getY() + rect.getHeight() + w, 0.0D).endVertex();
vertexbuffer.pos((double) rect.getX() + rect.getWidth() + w, (double) rect.getY() + rect.getHeight() + w, 0.0D).endVertex();
vertexbuffer.pos((double) rect.getX() + rect.getWidth() + w, (double) rect.getY() + rect.getHeight() - w, 0.0D).endVertex();
vertexbuffer.pos((double) rect.getX() - w, (double) rect.getY() + rect.getHeight() - w, 0.0D).endVertex();

vertexbuffer.pos((double) rect.getX() - w, (double) rect.getY() + rect.getHeight() + w, 0.0D).endVertex();
vertexbuffer.pos((double) rect.getX() + w, (double) rect.getY() + rect.getHeight() + w, 0.0D).endVertex();
vertexbuffer.pos((double) rect.getX() + w, (double) rect.getY() - w, 0.0D).endVertex();
vertexbuffer.pos((double) rect.getX() - w, (double) rect.getY() - w, 0.0D).endVertex();

vertexbuffer.pos((double) rect.getX() + rect.getWidth() - w, (double) rect.getY() + rect.getHeight() + w, 0.0D).endVertex();
vertexbuffer.pos((double) rect.getX() + rect.getWidth() + w, (double) rect.getY() + rect.getHeight() + w, 0.0D).endVertex();
vertexbuffer.pos((double) rect.getX() + rect.getWidth() + w, (double) rect.getY() - w, 0.0D).endVertex();
vertexbuffer.pos((double) rect.getX() + rect.getWidth() - w, (double) rect.getY() - w, 0.0D).endVertex();

tessellator.draw();
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
}

private void renderText(int mx, int my) {
GlStateManager.enableBlend();
FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
IGuiRect rect = getTransform();
int width = fontRenderer.getStringWidth(text);
int x = rect.getX() + rect.getWidth() - width;
int y = rect.getY() + rect.getHeight() - fontRenderer.FONT_HEIGHT + 1;
int a = getTransform().contains(mx, my) ? 100 : 255;
if (x < rect.getX() + FRAME_WIDTH / 2) {
//scale to fit
float s = (rect.getWidth() - FRAME_WIDTH) / width;
float new_x = rect.getX() + FRAME_WIDTH / 2;
float new_y = y + fontRenderer.FONT_HEIGHT * (1 - s) - FRAME_WIDTH / 2;
GlStateManager.pushMatrix();
GlStateManager.translate(new_x, new_y, 0);
GlStateManager.scale(s, s, s);
fontRenderer.drawStringWithShadow(text, 0, 0, 0xFFFFFF | (a << 24));
GlStateManager.popMatrix();
} else {
fontRenderer.drawStringWithShadow(text, x, y, 0xFFFFFF | (a << 24));
}
}

private void renderConsumeIcon(int mx, int my) {
GlStateManager.enableBlend();
FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
IGuiRect rect = getTransform();
int x = rect.getX() + rect.getWidth() - fontRenderer.getStringWidth("C");
int y = rect.getY() + 1;
int a = getTransform().contains(mx, my) ? 100 : 255;
fontRenderer.drawStringWithShadow("C", x, y, 0xFFFF00 | (a << 24));
}

public enum State {
INCOMPLETE,
COMPLETE,
IN_PROGRESS,
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import net.minecraft.client.renderer.GlStateManager;

public class GuiColorPulse implements IGuiColor {
// Saves me having to run the math function every frame
private final static double RAD = Math.toRadians(360F);

private final IGuiColor c1;
private final IGuiColor c2;
Expand All @@ -27,37 +25,22 @@ public GuiColorPulse(IGuiColor color1, IGuiColor color2, double period, float ph

@Override
public int getRGB() {
// Period in milliseconds
double pms = 1000D * period;
// Current period time
double time = System.currentTimeMillis() % pms;
// Shift current time by phase, wrap value and scale between 0.0 - 1.0
time = (time + (pms * phase)) % pms / pms;
// Convert time to sine wave between 0.0 and 1.0
float blend = (float) (Math.cos(time * RAD) / 2D + 0.5D);
float blend = RenderUtils.sineWave(period, phase);
// Return interpolated color
return RenderUtils.lerpRGB(c1.getRGB(), c2.getRGB(), blend);
}

@Override
public float getRed() {
return (getRGB() >> 16 & 255) / 255F;
}
public float getRed() { return (getRGB() >> 16 & 255) / 255F; }

@Override
public float getGreen() {
return (getRGB() >> 8 & 255) / 255F;
}
public float getGreen() { return (getRGB() >> 8 & 255) / 255F; }

@Override
public float getBlue() {
return (getRGB() & 255) / 255F;
}
public float getBlue() { return (getRGB() & 255) / 255F; }

@Override
public float getAlpha() {
return (getRGB() >> 24 & 255) / 255F;
}
public float getAlpha() { return (getRGB() >> 24 & 255) / 255F; }

@Override
public void applyGlColor() {
Expand All @@ -68,4 +51,5 @@ public void applyGlColor() {
float b = (float) (color & 255) / 255F;
GlStateManager.color(r, g, b, a);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ public enum PresetIcon {
ICON_MENU("icon_menu"),

ICON_PATREON("icon_patreon"),
ICON_TWITCH("icon_twitch");
ICON_TWITCH("icon_twitch"),
ICON_CHECK("icon_check");

public static final ResourceLocation TX_ICONS = new ResourceLocation(ModReference.MODID, "textures/gui/editor_icons.png");

Expand Down Expand Up @@ -197,5 +198,6 @@ public static void registerIcons(IThemeRegistry reg) {

reg.setDefaultTexture(ICON_PATREON.key, new SimpleTexture(TX_ICONS, new GuiRectangle(144, 80, 16, 16)).maintainAspect(true));
reg.setDefaultTexture(ICON_TWITCH.key, new SimpleTexture(TX_ICONS, new GuiRectangle(160, 80, 16, 16)).maintainAspect(true));
reg.setDefaultTexture(ICON_CHECK.key, new SimpleTexture(TX_ICONS, new GuiRectangle(0, 48, 16, 16)).maintainAspect(true));
}
}
Loading