Skip to content
This repository has been archived by the owner on Nov 7, 2022. It is now read-only.

Commit

Permalink
Work on UI #4
Browse files Browse the repository at this point in the history
  • Loading branch information
boomboompower committed Mar 7, 2020
1 parent bf267d8 commit 8462c4f
Show file tree
Hide file tree
Showing 11 changed files with 932 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.List;

import me.do_you_like.mods.skinchanger.SkinChangerMod;
import me.do_you_like.mods.skinchanger.gui.SkinChangerMenu;
import me.do_you_like.mods.skinchanger.utils.backend.InternetConnection;
import me.do_you_like.mods.skinchanger.utils.resources.LocalFileData;
import me.do_you_like.mods.skinchanger.utils.game.ChatColor;
Expand Down Expand Up @@ -97,6 +98,10 @@ public void onCommand(ICommandSender sender, String[] args) {

sendMessage(ChatColor.AQUA + "Your skin is now " + (IS_SLIM_SKIN ? "slim" : "normal"));

return;
} else if (args[0].equalsIgnoreCase("ui") || args[0].equalsIgnoreCase("gui")) {
new SkinChangerMenu().display();

return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,104 @@

package me.do_you_like.mods.skinchanger.gui;

import java.awt.Color;

import me.do_you_like.mods.skinchanger.utils.gui.impl.ModernButton;
import me.do_you_like.mods.skinchanger.utils.gui.impl.ModernGui;
import me.do_you_like.mods.skinchanger.utils.gui.impl.ModernHeader;
import me.do_you_like.mods.skinchanger.utils.gui.impl.ModernSlider;

public class SkinChangerMenu extends ModernGui {

// ModernHeader hack
//
// For the middle of the left half of the screen do:
// xPosition = (this.width / 2) / scale
//
// For the middle of the right half of the screen do:
// xPosition = (this.width / 2) * scale

@Override
public void onGuiOpen() {
ModernHeader title = new ModernHeader((int) ((this.width / 2) / 1.5F), 12, "SkinChanger", 1.5F, false);

title.setDrawCentered(true);

// ----------------------------------

ModernHeader skinSettings = new ModernHeader(95, 165, "Skin Settings", 1.20F, true, Color.RED);

skinSettings.setOffsetBetweenDrawables(32F);

skinSettings.getSubDrawables().add(new ModernButton(12, 5, 20, "Load from Player").setAsPartOfHeader(skinSettings));
skinSettings.getSubDrawables().add(new ModernButton(13, 5, 20, "Load from URL").setAsPartOfHeader(skinSettings));
skinSettings.getSubDrawables().add(new ModernButton(14, 5, 20, "Load from File").setAsPartOfHeader(skinSettings));
skinSettings.getSubDrawables().add(new ModernButton(15, 5, 20, "Reset Skin").setAsPartOfHeader(skinSettings));

// ----------------------------------

ModernHeader capeSettings = new ModernHeader(95, 585, "Cape Settings", 1.25F, true, Color.GREEN);

capeSettings.getSubDrawables().add(new ModernButton(12, 5, 20, "Load from Player").setAsPartOfHeader(capeSettings));
capeSettings.getSubDrawables().add(new ModernButton(13, 5, 20, "Load from URL").setAsPartOfHeader(capeSettings));
capeSettings.getSubDrawables().add(new ModernButton(14, 5, 20, "Load from File").setAsPartOfHeader(capeSettings));
capeSettings.getSubDrawables().add(new ModernButton(15, 5, 20, "Reset Skin").setAsPartOfHeader(capeSettings));

// ----------------------------------

ModernHeader recentSkins = new ModernHeader(525, 165, "Recent Skins", 1.3F, true, Color.YELLOW);

// ----------------------------------

ModernHeader recentCapes = new ModernHeader(525, 585, "Recent Capes", 1.33F, true, Color.LIGHT_GRAY);

// ----------------------------------

this.headerList.add(title);
this.headerList.add(skinSettings);
this.headerList.add(capeSettings);
this.headerList.add(recentSkins);
this.headerList.add(recentCapes);

this.sliderList.add(new ModernSlider(5, this.width / 2 - 100, this.height / 2 + 74, 200, 20, "Scale: ", 1.0F, 200.0F, 100.0F) {
@Override
public void onSliderUpdate() {
System.out.println(getValue() / 100);

for (ModernHeader header : SkinChangerMenu.this.headerList) {
if (header == title) {
continue;
}

header.setScaleSize((float) (getValue() / 100.0D));
}
}
});

this.sliderList.add(new ModernSlider(6, this.width / 2 - 100, this.height / 2 + 98, 200, 20, "Offset: ", 1.0F, 100.0F, 50.0F) {
@Override
public void onSliderUpdate() {
skinSettings.getWidth();

//skinSettings.setOffsetBetweenDrawables((float) (getValue() / 1.0D));
}
});
}

@Override
public void preRender() {
public void onGuiClose() {
this.headerList.clear();
}

@Override
public void preRender() {
}

@Override
public void onRender(int mouseX, int mouseY, float partialTicks) {
drawDefaultBackground();

drawCenteredString(this.fontRendererObj, "by boomboompower", this.width / 2, 16, Color.CYAN.getRGB());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,17 @@ public static void notEmpty(String value, String errorMessage) {
// Hit em with the fat exception
throw new IllegalArgumentException(errorMessage);
}

public static void conditionMet(boolean condition) {
conditionMet(condition, "Condition was not met.");
}

public static void conditionMet(boolean condition, String errorMessage) {
if (condition) {
return;
}

// Hit em with the fat exception
throw new IllegalArgumentException(errorMessage);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2020 boomboompower
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package me.do_you_like.mods.skinchanger.utils.general;

import lombok.Getter;

public class XYPosition {

@Getter
private final float x;

@Getter
private final float y;

public XYPosition(XYPosition position) {
this.x = position.x;
this.y = position.y;
}

public XYPosition(float x, float y) {
this.x = x;
this.y = y;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (C) 2020 boomboompower
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package me.do_you_like.mods.skinchanger.utils.gui;

import me.do_you_like.mods.skinchanger.utils.gui.impl.ModernHeader;

public interface ModernDrawable {

public int getX();

public int getY();

/**
* Calls the render function for the drawable.
*
* @param mouseX the current x position of the mouse.
* @param mouseY the current y position of the mouse.
*/
public void render(int mouseX, int mouseY);

public default void renderFromHeader(int xPos, int yPos, int mouseX, int mouseY, int recommendedYOffset) {
render(mouseX, mouseY);
}

/**
* Should this drawable be drawn? If this is false the header will not call the {@link #render(int, int)} method.
*
* @return true if {@link #render(int, int)} should be called for the drawable.
*/
public boolean isEnabled();

public ModernDrawable setAsPartOfHeader(ModernHeader parent);

/**
* Should this drawable be rendered relative to its header (if its part of one)?
*
* @return true if the drawable should be moved based on header position.
*/
public default boolean renderRelativeToHeader() {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* Copyright (C) 2020 boomboompower
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package me.do_you_like.mods.skinchanger.utils.gui.impl;

import java.io.File;
import lombok.Getter;
import lombok.Setter;

import me.do_you_like.mods.skinchanger.utils.gui.ModernDrawable;
import me.do_you_like.mods.skinchanger.utils.resources.LocalFileData;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;

import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.ResourceLocation;

import org.lwjgl.opengl.GL11;

public class ModernBlurBox implements ModernDrawable {

@Getter
private int x;

@Getter
private int y;

@Getter
@Setter
private int width;

@Getter
@Setter
private int height;

@Getter
@Setter
private boolean enabled;

public ModernBlurBox(int xPos, int yPos, int width, int height) {

}

@Override
public void render(int mouseX, int mouseY) {
ResourceLocation location = new ResourceLocation("textures/misc/vignette.png");

LocalFileData data = new LocalFileData(location, new File("icon.png"));

GlStateManager.disableDepth();
GlStateManager.disableAlpha();
GlStateManager.enableTexture2D();
GlStateManager.enableBlend();
GlStateManager.alphaFunc(770, 771);

GlStateManager.bindTexture(data.getGlTextureId());

GL11.glCopyTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, this.x, this.y, this.x + this.width, this.y + this.height, 1);

ScaledResolution scaler = new ScaledResolution(Minecraft.getMinecraft());
Tessellator tessellator = Tessellator.getInstance();
WorldRenderer renderer = tessellator.getWorldRenderer();

renderer.color(1.0F, 1.0F, 1.0F, 1.0F);
renderer.begin(7, DefaultVertexFormats.POSITION_TEX); // 7 = OpenGl.GL_QUADS

// tessellator.addVertexWithUV(x,y,z,u,v);
// to
// renderer.pos(x,y,z).tex(u,v).endVertex();

renderer.pos(this.x / (scaler.getScaleFactor() * 2.0f), this.y + this.height / (scaler.getScaleFactor() * 2.0f), 0).tex(0.0f, 0.0f).endVertex();
renderer.pos(this.x + this.width / (scaler.getScaleFactor() * 2.0f), this.y + this.height / (scaler.getScaleFactor() * 2.0f), 1.0F).tex(1.0f, 0.0f).endVertex();
renderer.pos(this.x + this.width / (scaler.getScaleFactor() * 2.0f), this.y / (scaler.getScaleFactor() * 2.0f), 0).tex(1.0f, 1.0f).endVertex();
renderer.pos( this.x / (scaler.getScaleFactor() * 2.0f), this.y / (scaler.getScaleFactor() * 2.0f), 0).tex(0.0f, 1.0f).endVertex();

GL11.glCopyTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, this.x, this.y, this.x + this.width, this.y + this.height, 1);

tessellator.draw();
}

@Override
public void renderFromHeader(int xPos, int yPos, int mouseX, int mouseY, int recommendedYOffset) {

}

@Override
public boolean renderRelativeToHeader() {
return true;
}

@Override
public ModernDrawable setAsPartOfHeader(ModernHeader parent) {
return this;
}
}
Loading

0 comments on commit 8462c4f

Please sign in to comment.