Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmess1221 committed Mar 27, 2016
0 parents commit a8a04fe
Show file tree
Hide file tree
Showing 39 changed files with 2,184 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.classpath
.gradle/
.project
.settings/
*.launch
bin/
build/
run/
50 changes: 50 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
buildscript {
repositories {
jcenter()
maven {
name 'forge'
url 'http://files.minecraftforge.net/maven/'
}
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.1-SNAPSHOT'
}
}
apply plugin: 'net.minecraftforge.gradle.liteloader'

version = "1.0"
group = "com.modid"
archivesBaseName = 'modid'
ext.revision = "2"

targetCompatibility = 1.8
sourceCompatibility = 1.8

minecraft {
version = "1.8.9"
mappings = "stable_22"
replace "@VERSION@", project.version
runDir = 'run'
}
processResources{
// this will ensure that this task is redone when the versions change.
def props = [
version: version,
mcversion: minecraft.version,
revision: revision
]
inputs.properties props
exclude "**/*.xcf"
// replace stuff in mcmod.info, nothing else
from(sourceSets.main.resources.srcDirs) {
include 'litemod.json'

// replace version and mcversion
expand props
}

// copy everything else, thats not the mcmod.info
from(sourceSets.main.resources.srcDirs) {
exclude 'litemod.json'
}
}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'ItemDash'
102 changes: 102 additions & 0 deletions src/main/java/mnm/mods/itemdash/DashScroller.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package mnm.mods.itemdash;

public class DashScroller extends GuiDash {

private static final int MIN_GRIP = 10;
private static final int MAX_GRIP = 50;
private static final int BUTTON_SIZE = 15;

private final Scrollable scrollable;

private boolean visible = true;

private int xPos;
private int yPos;
private int height;
private int width = 15;

private boolean scrolling;

private float scrollArea;
private float scrollSize;

public DashScroller(Scrollable itemdash) {
this.scrollable = itemdash;
}

public void drawScrollbar() {
this.zLevel = 300;
mc.getTextureManager().bindTexture(BG);
this.xPos = scrollable.getX() + scrollable.getWidth();

float contentSize = scrollable.getContentHeight();
float windowSize = scrollable.getWindowHeight();
float trackSize = windowSize - BUTTON_SIZE * 2;

float contentRatio = windowSize / contentSize;
float gripSize = trackSize * contentRatio;

gripSize = Math.min(gripSize, MAX_GRIP);
gripSize = Math.max(gripSize, MIN_GRIP);

scrollArea = contentSize - windowSize;
if (!(visible = !(scrollArea <= 0)))
return;
float windowPos = scrollable.getScroll() + scrollable.getY();
float windowRatio = windowPos / scrollArea;
scrollSize = trackSize - gripSize;
float gripPos = scrollSize * windowRatio;

this.yPos = scrollable.getY() + (int) gripPos + BUTTON_SIZE;
height = (int) gripSize;

// top
this.drawBorders(xPos, scrollable.getY(), width, width, 0, 0, 18, 18, BOTTOM);
this.drawTexturedModalRect(xPos, scrollable.getY(), 40, 15, 15, 10);
// bottom
this.drawBorders(xPos, scrollable.getY() + scrollable.getWindowHeight() - width, width, width, 0, 0, 18, 18, TOP);
this.drawTexturedModalRect(xPos, scrollable.getY() + scrollable.getWindowHeight() - width, 40, 25, 15, 10);

this.drawBorders(xPos, scrollable.getY(), width, scrollable.getWindowHeight(), 0, 0, 18, 18, ALL);
this.drawBorders(xPos, this.yPos, width, height, 0, 0, 18, 18, ALL);
this.zLevel = 0;
}

public void mouseClick(int mousex, int mousey, int button) {
if (visible && mousex > xPos && button == 0) {

if (mousey < scrollable.getY() + width) {
scrollable.scroll(-1);
return;
} else if (mousey > scrollable.getY() + scrollable.getWindowHeight() - width) {
scrollable.scroll(1);
return;
}
this.scrolling = true;
if (mousey < yPos || mousey > yPos + height) {
scroll(mousey);
}
}

}

public void mouseRelease(int mousex, int mousey, int button) {
if (visible)
this.scrolling = false;
}

public void mouseDrag(int mousex, int mousey) {
if (visible && scrolling)
scroll(mousey);

}

private void scroll(int mousey) {
mousey -= scrollable.getY() + BUTTON_SIZE;
mousey -= height / 2;
float scrollRatio = mousey / scrollSize;
float scroll = scrollRatio * scrollArea;

scrollable.setScroll((int) scroll);
}
}
95 changes: 95 additions & 0 deletions src/main/java/mnm/mods/itemdash/GuiDash.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package mnm.mods.itemdash;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.util.ResourceLocation;

public class GuiDash extends Gui {

protected static int TOP = 0x1,
LEFT = 0x2,
RIGHT = 0x4,
BOTTOM = 0x8,
TOP_LEFT = 0x10,
TOP_RIGHT = 0x20,
BOTTOM_LEFT = 0x40,
BOTTOM_RIGHT = 0x80,
ALL = TOP | LEFT | RIGHT | BOTTOM | TOP_LEFT | TOP_RIGHT | BOTTOM_LEFT | BOTTOM_RIGHT;

public static final ResourceLocation BG = new ResourceLocation("itemdash", "textures/gui/itemdash.png");

protected Minecraft mc = Minecraft.getMinecraft();

protected void drawBorders(int xPos, int yPos, int width, int height, int u, int v, int texW, int texH, int flags) {
final boolean t = getFlag(flags, TOP);
final boolean l = getFlag(flags, LEFT);
final boolean r = getFlag(flags, RIGHT);
final boolean b = getFlag(flags, BOTTOM);
final boolean tl = getFlag(flags, TOP_LEFT);
final boolean tr = getFlag(flags, TOP_RIGHT);
final boolean bl = getFlag(flags, BOTTOM_LEFT);
final boolean br = getFlag(flags, BOTTOM_RIGHT);

final int wsize = texW / 3;
final int hsize = texH / 3;
// top left
if (tl)
this.drawTexturedModalRect(xPos, yPos, u, v, wsize, hsize);
// top right
if (tr)
this.drawTexturedModalRect(xPos + width - wsize, yPos, u + wsize * 2, v, wsize, hsize);
// bottom left
if (bl)
this.drawTexturedModalRect(xPos, yPos + height - wsize, u, v + hsize * 2, wsize, hsize);
// bottom right
if (br)
this.drawTexturedModalRect(xPos + width - wsize, yPos + height - hsize, u + wsize * 2, v + hsize * 2, wsize, hsize);

int remaining;

// left
if (l) {
int height2 = height - (bl ? hsize : 0);
remaining = height2 - (tl ? hsize : 0);
while (remaining > hsize) {
this.drawTexturedModalRect(xPos, yPos + height2 - remaining, u, v + hsize, wsize, hsize);
remaining -= hsize;
}
this.drawTexturedModalRect(xPos, yPos + height2 - remaining, u, v + hsize, wsize, remaining);
}
// top
if (t) {
int width2 = width - (tr ? wsize : 0);
remaining = width2 - (tl ? wsize : 0);
while (remaining > wsize) {
this.drawTexturedModalRect(xPos + width2 - remaining, yPos, u + wsize, v, wsize, hsize);
remaining -= wsize;
}
this.drawTexturedModalRect(xPos + width2 - remaining, yPos, u + wsize, v, remaining, hsize);
}
// bottom
if (b) {
int width2 = width - (br ? wsize : 0);
remaining = width2 - (bl ? wsize : 0);
while (remaining > wsize) {
this.drawTexturedModalRect(xPos + width2 - remaining, yPos + height - hsize, u + wsize, v + hsize * 2, wsize, hsize);
remaining -= wsize;
}
this.drawTexturedModalRect(xPos + width2 - remaining, yPos + height - hsize, u + wsize, v + hsize * 2, remaining, hsize);
}
// right
if (r) {
int height2 = height - (br ? hsize : 0);
remaining = height - (tr ? hsize : 0);
while (remaining > hsize) {
this.drawTexturedModalRect(xPos + width - wsize, yPos + height2 - remaining, u + wsize * 2, v + hsize, wsize, hsize);
remaining -= hsize;
}
this.drawTexturedModalRect(xPos + width - wsize, yPos + height2 - remaining, u + wsize * 2, v + hsize, wsize, remaining);
}
}

private static boolean getFlag(int b, int b2) {
return (b & b2) == b2;
}
}
93 changes: 93 additions & 0 deletions src/main/java/mnm/mods/itemdash/GuiSettings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package mnm.mods.itemdash;

import java.util.List;
import java.util.function.Predicate;

import com.google.common.collect.Lists;

import mnm.mods.itemdash.setting.BoolSetting;
import mnm.mods.itemdash.setting.OptionSetting;
import mnm.mods.itemdash.setting.Setting;
import mnm.mods.itemdash.setting.StringSetting;

public class GuiSettings extends GuiDash {

private final LiteModItemDash litemod = LiteModItemDash.getInstance();
private final ItemDash itemdash;
private boolean visible;
private Predicate<Void> focused;

private List<Setting<?>> settings = Lists.newArrayList();

public GuiSettings(ItemDash itemdash) {
this.itemdash = itemdash;
this.settings.add(new BoolSetting("Legacy IDs",
it -> litemod.numIds = it,
() -> litemod.numIds));
this.settings.add(new StringSetting(this, "Give Command",
it -> litemod.giveCommand = it,
() -> litemod.giveCommand)
.preset("Vanilla", "/give {0} {1} {2} {3}")
.preset("Essentials", "/i {1}:{3} {2}"));
this.settings.add(new OptionSetting("Sorting",
it -> {
litemod.sort = it;
itemdash.sort(it);
} , () -> litemod.sort)
.option(ItemSorter.BY_ID, "By ID")
.option(ItemSorter.DEFAULT, "By Legacy")
.option(ItemSorter.BY_NAME, "By Name"));
}

public void open() {
if (!visible) {
this.visible = true;
settings.forEach(it -> it.applyCurrent());
}
}

public void close() {
if (visible) {
visible = false;
}
}

public void draw(int mousex, int mousey) {

int xPos = itemdash.xPos;
int yPos = itemdash.yPos;

int lastHeight = 0;
int pos = yPos;
for (Setting<?> it : settings) {
it.setPos(xPos + 4, pos += lastHeight + 6);
lastHeight = it.height;
}

this.settings.forEach(it -> it.draw(mousex, mousey));
}

public void mouseClick(int x, int y) {
this.settings.forEach(it -> it.mouseClick(x, y, 0));
}

public void keyTyped(char key, int code) {
this.settings.forEach(it -> it.keyPush(key, code));
}

public boolean isVisible() {
return visible;
}

public boolean isFocused() {
return focused.test(null);
}

public void addFocus(Predicate<Void> pred) {
if (this.focused == null)
focused = pred;
else
focused = focused.or(pred);
}

}
Loading

0 comments on commit a8a04fe

Please sign in to comment.