Remove remaining old packages

This commit is contained in:
johni0702
2016-09-03 13:10:58 +02:00
parent 4de933516e
commit dca1131d49
40 changed files with 23 additions and 3206 deletions

View File

@@ -5,11 +5,10 @@ import com.google.common.util.concurrent.ListenableFutureTask;
import com.replaymod.core.gui.GuiReplaySettings;
import com.replaymod.core.gui.RestoreReplayGui;
import com.replaymod.core.handler.MainMenuHandler;
import com.replaymod.core.utils.OpenGLUtils;
import com.replaymod.render.utils.SoundHandler;
import com.replaymod.replaystudio.util.I18n;
import de.johni0702.minecraft.gui.container.GuiScreen;
import com.replaymod.render.utils.SoundHandler;
import com.replaymod.core.utils.OpenGLUtils;
import eu.crushedpixel.replaymod.utils.TooltipRenderer;
import lombok.Getter;
import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.GameSettings;
@@ -67,8 +66,6 @@ public class ReplayMod {
@Deprecated
public static Configuration config;
@Deprecated
public static TooltipRenderer tooltipRenderer;
@Deprecated
public static SoundHandler soundHandler = new SoundHandler();
private final KeyBindingRegistry keyBindingRegistry = new KeyBindingRegistry();
@@ -125,8 +122,6 @@ public class ReplayMod {
if(!FMLClientHandler.instance().hasOptifine())
GameSettings.Options.RENDER_DISTANCE.setValueMax(64f);
tooltipRenderer = new TooltipRenderer();
if (System.getProperty("replaymod.render.file") != null) {
final File file = new File(System.getProperty("replaymod.render.file"));
if (!file.exists()) {

View File

@@ -2,7 +2,6 @@ package com.replaymod.extras;
import com.replaymod.core.ReplayMod;
import com.replaymod.online.ReplayModOnline;
import eu.crushedpixel.replaymod.utils.StringUtils;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.resources.I18n;
@@ -12,6 +11,8 @@ import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import java.awt.*;
import java.util.List;
public class VersionChecker implements Extra {
@Mod.Instance(ReplayModOnline.MOD_ID)
@@ -43,7 +44,8 @@ public class VersionChecker implements Extra {
int width = Math.max(100, event.gui.width / 2 - 100 - 10);
String[] lines = StringUtils.splitStringInMultipleRows(I18n.format("replaymod.gui.outdated"), width);
@SuppressWarnings("unchecked") List<String> lines =
event.gui.mc.fontRendererObj.listFormattedStringToWidth(I18n.format("replaymod.gui.outdated"), width);
int maxLineWidth = 0;
for(String line : lines) {
@@ -53,7 +55,7 @@ public class VersionChecker implements Extra {
}
}
Gui.drawRect(2, 77, 5 + maxLineWidth + 3, 80 + (lines.length * 10), 0x80FF0000);
Gui.drawRect(2, 77, 5 + maxLineWidth + 3, 80 + (lines.size() * 10), 0x80FF0000);
int i = 0;
for(String line : lines) {

View File

@@ -6,11 +6,10 @@ import com.google.gson.JsonParseException;
import com.google.gson.JsonParser;
import com.mojang.authlib.exceptions.AuthenticationException;
import com.replaymod.core.ReplayMod;
import com.replaymod.online.AuthenticationHash;
import com.replaymod.online.api.replay.ReplayModApiMethods;
import com.replaymod.online.api.replay.SearchQuery;
import com.replaymod.online.api.replay.holders.*;
import eu.crushedpixel.replaymod.gui.elements.listeners.ProgressUpdateListener;
import com.replaymod.online.AuthenticationHash;
import net.minecraft.client.Minecraft;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
@@ -21,6 +20,7 @@ import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import java.util.function.Consumer;
public class ApiClient {
@@ -135,7 +135,7 @@ public class ApiClient {
private boolean cancelDownload = false;
public void downloadFile(int file, File target, ProgressUpdateListener listener) throws IOException, ApiException {
public void downloadFile(int file, File target, Consumer<Float> listener) throws IOException, ApiException {
cancelDownload = false;
QueryBuilder builder = new QueryBuilder(ReplayModApiMethods.download_file);
@@ -168,7 +168,7 @@ public class ApiClient {
fout.write(data, 0, count);
read += count;
listener.onProgressChanged((float)(read)/fileSize);
listener.accept((float) read / fileSize);
}
} finally {
bin.close();

View File

@@ -10,7 +10,6 @@ import de.johni0702.minecraft.gui.element.GuiTextField;
import de.johni0702.minecraft.gui.layout.CustomLayout;
import de.johni0702.minecraft.gui.utils.Consumer;
import de.johni0702.minecraft.gui.utils.Utils;
import eu.crushedpixel.replaymod.gui.GuiConstants;
public class GuiLoginPrompt extends AbstractGuiScreen<GuiLoginPrompt> {

View File

@@ -10,12 +10,11 @@ import de.johni0702.minecraft.gui.element.GuiButton;
import de.johni0702.minecraft.gui.element.GuiLabel;
import de.johni0702.minecraft.gui.element.advanced.GuiProgressBar;
import de.johni0702.minecraft.gui.layout.CustomLayout;
import eu.crushedpixel.replaymod.gui.elements.listeners.ProgressUpdateListener;
import java.io.File;
import java.io.IOException;
public class GuiReplayDownloading extends AbstractGuiScreen<GuiReplayDownloading> implements ProgressUpdateListener {
public class GuiReplayDownloading extends AbstractGuiScreen<GuiReplayDownloading> {
private final GuiScreen cancelScreen;
private final ApiClient apiClient;
@@ -52,7 +51,7 @@ public class GuiReplayDownloading extends AbstractGuiScreen<GuiReplayDownloading
public void run() {
final File replayFile = mod.getDownloadedFile(replayId);
try {
apiClient.downloadFile(replayId, replayFile, GuiReplayDownloading.this);
apiClient.downloadFile(replayId, replayFile, progressBar::setProgress);
if (replayFile.exists()) {
getMinecraft().addScheduledTask(new Runnable() {
@Override
@@ -72,17 +71,6 @@ public class GuiReplayDownloading extends AbstractGuiScreen<GuiReplayDownloading
}).start();
}
@Override
public void onProgressChanged(float progress) {
progressBar.setProgress(progress);
}
@Override
public void onProgressChanged(float progress, String progressString) {
onProgressChanged(progress);
}
@Override
protected GuiReplayDownloading getThis() {
return this;
}

View File

@@ -4,10 +4,10 @@ import com.replaymod.render.frame.RGBFrame;
import com.replaymod.render.rendering.FrameConsumer;
import com.replaymod.render.utils.ByteBufferPool;
import com.replaymod.render.utils.StreamPipe;
import eu.crushedpixel.replaymod.utils.StringUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.crash.CrashReport;
import net.minecraft.crash.CrashReportCategory;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.io.IOUtils;
import org.lwjgl.util.ReadableDimension;
@@ -17,8 +17,6 @@ import java.io.IOException;
import java.io.OutputStream;
import java.nio.channels.Channels;
import java.nio.channels.WritableByteChannel;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import static org.apache.commons.lang3.Validate.isTrue;
@@ -45,11 +43,10 @@ public class VideoWriter implements FrameConsumer<RGBFrame> {
.replace("%FILENAME%", fileName)
.replace("%BITRATE%", String.valueOf(settings.getBitRate()));
List<String> command = new ArrayList<>();
command.add(settings.getExportCommand().isEmpty() ? "ffmpeg" : settings.getExportCommand());
command.addAll(StringUtils.translateCommandline(commandArgs));
String executable = settings.getExportCommand().isEmpty() ? "ffmpeg" : settings.getExportCommand();
System.out.println("Starting " + settings.getExportCommand() + " with args: " + commandArgs);
process = new ProcessBuilder(command).directory(outputFolder).start();
String[] cmdline = new CommandLine(executable).addArguments(commandArgs).toStrings();
process = new ProcessBuilder(cmdline).directory(outputFolder).start();
OutputStream exportLogOut = new FileOutputStream("export.log");
new StreamPipe(process.getInputStream(), exportLogOut).start();
new StreamPipe(process.getErrorStream(), exportLogOut).start();

View File

@@ -2,6 +2,7 @@ package com.replaymod.replay;
import com.google.common.base.Preconditions;
import com.mojang.authlib.GameProfile;
import com.replaymod.core.utils.Restrictions;
import com.replaymod.replay.camera.CameraEntity;
import com.replaymod.replay.camera.SpectatorCameraController;
import com.replaymod.replay.events.ReplayCloseEvent;
@@ -9,14 +10,13 @@ import com.replaymod.replay.events.ReplayOpenEvent;
import com.replaymod.replay.gui.overlay.GuiReplayOverlay;
import com.replaymod.replaystudio.data.Marker;
import com.replaymod.replaystudio.replay.ReplayFile;
import com.replaymod.core.utils.Restrictions;
import com.replaymod.replaystudio.util.Location;
import eu.crushedpixel.replaymod.utils.MouseUtils;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.embedded.EmbeddedChannel;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityOtherPlayerMP;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.Entity;
@@ -26,7 +26,6 @@ import net.minecraft.network.NetworkManager;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.network.handshake.NetworkDispatcher;
import org.lwjgl.opengl.Display;
import org.lwjgl.util.Point;
import java.io.IOException;
import java.util.*;
@@ -307,8 +306,8 @@ public class ReplayHandler {
mc.getFramebuffer().bindFramebuffer(true);
mc.entityRenderer.setupOverlayRendering();
Point point = MouseUtils.getScaledDimensions();
guiScreen.setWorldAndResolution(mc, point.getX(), point.getY());
ScaledResolution resolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
guiScreen.setWorldAndResolution(mc, resolution.getScaledWidth(), resolution.getScaledHeight());
guiScreen.drawScreen(0, 0, 0);
mc.getFramebuffer().unbindFramebuffer();

View File

@@ -1,77 +0,0 @@
package eu.crushedpixel.replaymod.gui;
public class GuiConstants {
//didn't find a better place to put these constants
public static final int CENTER_DOWNLOADED_REPLAYS_BUTTON = 2001;
public static final int CENTER_SEARCH_BUTTON = 2002;
public static final int CENTER_BACK_BUTTON = 2003;
public static final int CENTER_LOGOUT_BUTTON = 2004;
public static final int CENTER_RECENT_BUTTON = 2005;
public static final int CENTER_BEST_BUTTON = 2006;
public static final int CENTER_MANAGER_BUTTON = 2007;
public static final int CENTER_LOAD_REPLAY_BUTTON = 2008;
public static final int CENTER_FAV_REPLAY_BUTTON = 2009;
public static final int CENTER_LIKE_REPLAY_BUTTON = 2010;
public static final int CENTER_DISLIKE_REPLAY_BUTTON = 2011;
public static final int CENTER_FAVORITED_REPLAYS_BUTTON = 2012;
public static final int CENTER_SEARCH_ACTION_BUTTON = 2013;
public static final int CENTER_SEARCH_GAMETYPE_TOGGLE = 2015;
public static final int CENTER_SEARCH_ORDER_TOGGLE = 2016;
public static final int UPLOAD_START_BUTTON = 3003;
public static final int UPLOAD_CANCEL_BUTTON = 3004;
public static final int UPLOAD_BACK_BUTTON = 3005;
public static final int UPLOAD_INFO_FIELD = 3006;
public static final int EXIT_REPLAY_BUTTON = 4001;
public static final int REPLAY_OPTIONS_BUTTON_ID = 8000;
public static final int REPLAY_MANAGER_BUTTON_ID = 9001;
public static final int REPLAY_EDITOR_BUTTON_ID = 9002;
public static final int REPLAY_CENTER_BUTTON_ID = 9003;
public static final int REPLAY_EDITOR_TRIM_TAB = 5000;
public static final int REPLAY_EDITOR_CONNECT_TAB = 5001;
public static final int REPLAY_EDITOR_MODIFY_TAB = 5002;
public static final int REPLAY_EDITOR_SAVEMODE_BUTTON = 5003;
public static final int REPLAY_EDITOR_SAVE_BUTTON = 5004;
public static final int REPLAY_EDITOR_BACK_BUTTON = 5005;
public static final int REPLAY_EDITOR_UP_BUTTON = 5006;
public static final int REPLAY_EDITOR_DOWN_BUTTON = 5007;
public static final int REPLAY_EDITOR_REMOVE_BUTTON = 5008;
public static final int REPLAY_EDITOR_ADD_BUTTON = 5009;
public static final int KEYFRAME_REPOSTORY_NAME_INPUT = 2345;
public static final int KEYFRAME_REPOSITORY_ADD_BUTTON = 3456;
public static final int KEYFRAME_REPOSITORY_REMOVE_BUTTON = 4567;
public static final int KEYFRAME_REPOSITORY_LOAD_BUTTON = 5678;
public static final int KEYFRAME_EDITOR_SAVE_BUTTON = 6000;
public static final int KEYFRAME_EDITOR_CANCEL_BUTTON = 6001;
public static final int KEYFRAME_EDITOR_RIGHT_BUTTON = 6002;
public static final int KEYFRAME_EDITOR_LEFT_BUTTON = 6003;
public static final int PLAYER_OVERVIEW_HIDE_ALL = 1010;
public static final int PLAYER_OVERVIEW_SHOW_ALL = 101;
public static final int PLAYER_OVERVIEW_REMEMBER = -10;
public static final int RENDER_SETTINGS_COLOR_PICKER = 9014;
public static final int RENDER_SETTINGS_OUTPUT_CHOOSER = 9016;
public static final int REPLAY_SETTINGS_RECORDSERVER_ID = 9004;
public static final int REPLAY_SETTINGS_RECORDSP_ID = 9005;
public static final int REPLAY_SETTINGS_SEND_CHAT = 9006;
public static final int REPLAY_SETTINGS_FORCE_LINEAR = 9007;
public static final int REPLAY_SETTINGS_ENABLE_LIGHTING = 9008;
public static final int REPLAY_SETTINGS_INDICATOR_ID = 9012;
public static final int REPLAY_SETTINGS_PATHPREVIEW_ID = 9013;
public static final int REPLAY_SETTINGS_CLEARCALLBACK_ID = 9014;
public static final int REPLAY_EDITING_CANCEL_BUTTON = 1234;
}

View File

@@ -1,170 +0,0 @@
package eu.crushedpixel.replaymod.gui.elements;
import lombok.Getter;
import net.minecraft.client.Minecraft;
import java.util.*;
public class ComposedElement implements GuiElement {
private static final ComposedElementComparator COMPOSED_ELEMENT_COMPARATOR = new ComposedElementComparator();
@Getter
private List<GuiElement> parts = new ArrayList<GuiElement>();
public ComposedElement(GuiElement...parts) {
this.parts = new ArrayList<GuiElement>(Arrays.asList(parts));
Collections.sort(this.parts, COMPOSED_ELEMENT_COMPARATOR);
}
public void addPart(GuiElement part) {
parts.add(part);
Collections.sort(parts, COMPOSED_ELEMENT_COMPARATOR);
}
@Override
public void draw(Minecraft mc, int mouseX, int mouseY, boolean hovered) {
draw(mc, mouseX, mouseY);
}
@Override
public void draw(Minecraft mc, int mouseX, int mouseY) {
GuiElement hovered = null;
for (int i=parts.size()-1; i>=0; i--) {
GuiElement part = parts.get(i);
if(part.isHovering(mouseX, mouseY)) {
hovered = part;
break;
}
}
for(GuiElement part : parts) {
part.draw(mc, mouseX, mouseY, hovered == part);
}
for(GuiElement part : parts) {
part.drawOverlay(mc, mouseX, mouseY);
}
}
@Override
public void drawOverlay(Minecraft mc, int mouseX, int mouseY) {
for (GuiElement part : parts) {
part.drawOverlay(mc, mouseX, mouseY);
}
}
@Override
public boolean isHovering(int mouseX, int mouseY) {
for (GuiElement part : parts) {
if (part.isHovering(mouseX, mouseY)) {
return true;
}
}
return false;
}
@Override
public boolean mouseClick(Minecraft mc, int mouseX, int mouseY, int button) {
boolean clicked = false;
//iterate over elements in reverse order to first handle mouse clicks of elements that are drawn on top
for (int i=0; i<parts.size(); i++) {
GuiElement part = parts.get(parts.size() - 1 - i);
//if GuiOutsideClickableElement, forward mouse clicks outside of that element
if(!clicked || (part instanceof GuiOutsideClickableElement && !part.isHovering(mouseX, mouseY))) {
boolean cl = part.mouseClick(mc, mouseX, mouseY, button);
if(cl) clicked = true;
}
}
return clicked;
}
@Override
public void mouseDrag(Minecraft mc, int mouseX, int mouseY, int button) {
for (GuiElement part : parts) {
part.mouseDrag(mc, mouseX, mouseY, button);
}
}
@Override
public void mouseRelease(Minecraft mc, int mouseX, int mouseY, int button) {
for (GuiElement part : parts) {
part.mouseRelease(mc, mouseX, mouseY, button);
}
}
@Override
public void buttonPressed(Minecraft mc, int mouseX, int mouseY, char key, int keyCode) {
for (GuiElement part : parts) {
part.buttonPressed(mc, mouseX, mouseY, key, keyCode);
}
}
@Override
public void tick(Minecraft mc) {
for (GuiElement part : parts) {
part.tick(mc);
}
}
@Override
public void setElementEnabled(boolean enabled) {
for(GuiElement part : parts) {
part.setElementEnabled(enabled);
}
}
private static class ComposedElementComparator implements Comparator<GuiElement> {
@Override
public int compare(GuiElement o1, GuiElement o2) {
Boolean d1 = o1 instanceof GuiOverlayElement;
Boolean d2 = o2 instanceof GuiOverlayElement;
if(d1 && d2) {
return -new Integer(o1.yPos()).compareTo(o2.yPos());
}
return d1.compareTo(d2);
}
@Override
public boolean equals(Object obj) {
return false;
}
}
@Override
public int xPos() {
return 0;
}
@Override
public int yPos() {
return 0;
}
@Override
public int width() {
return 0;
}
@Override
public int height() {
return 0;
}
@Override
public void xPos(int x) {}
@Override
public void yPos(int y) {}
@Override
public void width(int width) {}
@Override
public void height(int height) {}
}

View File

@@ -1,109 +0,0 @@
package eu.crushedpixel.replaymod.gui.elements;
import net.minecraft.client.Minecraft;
public abstract class DelegatingElement implements GuiElement {
protected boolean enabled = true;
public static DelegatingElement of(final GuiElement element) {
return new DelegatingElement() {
@Override
public GuiElement delegate() {
return element;
}
};
}
public abstract GuiElement delegate();
@Override
public void draw(Minecraft mc, int mouseX, int mouseY, boolean hovered) {
delegate().draw(mc, mouseX, mouseY, hovered);
}
@Override
public void draw(Minecraft mc, int mouseX, int mouseY) {
delegate().draw(mc, mouseX, mouseY);
}
@Override
public void drawOverlay(Minecraft mc, int mouseX, int mouseY) {
delegate().drawOverlay(mc, mouseX, mouseY);
}
@Override
public boolean isHovering(int mouseX, int mouseY) {
return delegate().isHovering(mouseX, mouseY);
}
@Override
public boolean mouseClick(Minecraft mc, int mouseX, int mouseY, int button) {
return delegate().mouseClick(mc, mouseX, mouseY, button);
}
@Override
public void mouseDrag(Minecraft mc, int mouseX, int mouseY, int button) {
delegate().mouseDrag(mc, mouseX, mouseY, button);
}
@Override
public void mouseRelease(Minecraft mc, int mouseX, int mouseY, int button) {
delegate().mouseRelease(mc, mouseX, mouseY, button);
}
@Override
public void buttonPressed(Minecraft mc, int mouseX, int mouseY, char key, int keyCode) {
delegate().buttonPressed(mc, mouseX, mouseY, key, keyCode);
}
@Override
public void tick(Minecraft mc) {
delegate().tick(mc);
}
@Override
public void setElementEnabled(boolean enabled) {
this.enabled = enabled;
}
@Override
public int xPos() {
return delegate().xPos();
}
@Override
public int yPos() {
return delegate().yPos();
}
@Override
public int width() {
return delegate().width();
}
@Override
public int height() {
return delegate().height();
}
@Override
public void xPos(int x) {
delegate().xPos(x);
}
@Override
public void yPos(int y) {
delegate().yPos(y);
}
@Override
public void width(int width) {
delegate().width(width);
}
@Override
public void height(int height) {
delegate().height(height);
}
}

View File

@@ -1,164 +0,0 @@
package eu.crushedpixel.replaymod.gui.elements;
import com.replaymod.core.ReplayMod;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.GlStateManager;
import org.apache.commons.lang3.StringUtils;
import java.awt.*;
public class GuiAdvancedButton extends GuiButton implements GuiElement {
private final Runnable action;
public String hoverText;
public GuiAdvancedButton(int id, int x, int y, String buttonText) {
this(id, x, y, buttonText, null, null);
}
public GuiAdvancedButton(int x, int y, int width, int height, String buttonText, Runnable action, String hoverText) {
this(0, x, y, width, height, buttonText, action, hoverText);
}
public GuiAdvancedButton(int id, int x, int y, String buttonText, Runnable action, String hoverText) {
super(id, x, y, buttonText);
this.action = action;
this.hoverText = hoverText;
}
public GuiAdvancedButton(int id, int x, int y, int width, int height, String buttonText, Runnable action, String hoverText) {
super(id, x, y, width, height, buttonText);
this.action = action;
this.hoverText = hoverText;
}
@Override
public void draw(Minecraft mc, int mouseX, int mouseY) {
this.draw(mc, mouseX, mouseY, isHovering(mouseX, mouseY));
}
@Override
public void draw(Minecraft mc, int mouseX, int mouseY, boolean hovering) {
if (this.visible) {
FontRenderer fontrenderer = mc.fontRendererObj;
mc.getTextureManager().bindTexture(buttonTextures);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.hovered = isHovering(mouseX, mouseY);
int k = this.getHoverState(hovering);
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
GlStateManager.blendFunc(770, 771);
this.drawTexturedModalRect(this.xPosition, this.yPosition, 0, 46 + k * 20, this.width / 2, this.height);
this.drawTexturedModalRect(this.xPosition + this.width / 2, this.yPosition, 200 - this.width / 2, 46 + k * 20, this.width / 2, this.height);
this.mouseDragged(mc, mouseX, mouseY);
int l = 14737632;
if (packedFGColour != 0) {
l = packedFGColour;
} else if (!this.enabled) {
l = 10526880;
} else if (hovering) {
l = 16777120;
}
this.drawCenteredString(fontrenderer, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, l);
}
}
@Override
public void drawOverlay(Minecraft mc, int mouseX, int mouseY) {
hovered = isHovering(mouseX, mouseY);
if(hovered && !StringUtils.isEmpty(hoverText)) {
ReplayMod.tooltipRenderer.drawTooltip(mouseX, mouseY, hoverText, null, Color.WHITE);
}
}
@Override
public boolean isHovering(int mouseX, int mouseY) {
return mouseX >= xPosition
&& mouseY >= yPosition
&& mouseX <= xPosition + width
&& mouseY <= yPosition + height;
}
@Override
public boolean mouseClick(Minecraft mc, int mouseX, int mouseY, int button) {
if (isHovering(mouseX, mouseY) && enabled) {
performAction();
return true;
}
return false;
}
@Override
public void mouseDrag(Minecraft mc, int mouseX, int mouseY, int button) {
}
@Override
public void mouseRelease(Minecraft mc, int mouseX, int mouseY, int button) {
}
@Override
public void buttonPressed(Minecraft mc, int mouseX, int mouseY, char key, int keyCode) {
}
@Override
public void tick(Minecraft mc) {
}
@Override
public void setElementEnabled(boolean enabled) {
this.enabled = enabled;
}
public void performAction() {
if (action != null) {
action.run();
}
}
@Override
public int xPos() {
return xPosition;
}
@Override
public int yPos() {
return yPosition;
}
@Override
public int width() {
return width;
}
@Override
public int height() {
return height;
}
@Override
public void xPos(int x) {
xPosition = x;
}
@Override
public void yPos(int y) {
yPosition = y;
}
@Override
public void width(int width) {
this.width = width;
}
@Override
public void height(int height) {
this.height = height;
}
}

View File

@@ -1,142 +0,0 @@
package eu.crushedpixel.replaymod.gui.elements;
import com.replaymod.core.ReplayMod;
import eu.crushedpixel.replaymod.gui.elements.listeners.CheckBoxListener;
import net.minecraft.client.Minecraft;
import net.minecraftforge.fml.client.config.GuiCheckBox;
import org.apache.commons.lang3.StringUtils;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
public class GuiAdvancedCheckBox extends GuiCheckBox implements GuiElement {
public String hoverText;
public Color hoverTextColor = Color.WHITE;
public GuiAdvancedCheckBox(int xPos, int yPos, String displayString, boolean isChecked) {
super(0, xPos, yPos, displayString, isChecked);
}
public GuiAdvancedCheckBox(String displayString, boolean isChecked, boolean isEnabled) {
this(0, 0, displayString, isChecked);
this.setElementEnabled(isEnabled);
}
private List<CheckBoxListener> listeners = new ArrayList<CheckBoxListener>();
public void addCheckBoxListener(CheckBoxListener listener) {
this.listeners.add(listener);
}
@Override
public void draw(Minecraft mc, int mouseX, int mouseY, boolean hovered) {
draw(mc, mouseX, mouseY);
}
@Override
public void draw(Minecraft mc, int mouseX, int mouseY) {
drawButton(mc, mouseX, mouseY);
}
@Override
public void drawOverlay(Minecraft mc, int mouseX, int mouseY) {
hovered = isHovering(mouseX, mouseY);
if(hovered && !StringUtils.isEmpty(hoverText)) {
ReplayMod.tooltipRenderer.drawTooltip(mouseX, mouseY, hoverText, null, hoverTextColor);
}
}
@Override
public boolean isHovering(int mouseX, int mouseY) {
return mouseX >= xPosition
&& mouseY >= yPosition
&& mouseX < xPosition + width
&& mouseY < yPosition + height;
}
@Override
public boolean mouseClick(Minecraft mc, int mouseX, int mouseY, int button) {
boolean success = mousePressed(mc, mouseX, mouseY);
if(success) fireCheckListeners();
return success;
}
@Override
public void mouseDrag(Minecraft mc, int mouseX, int mouseY, int button) {
}
@Override
public void mouseRelease(Minecraft mc, int mouseX, int mouseY, int button) {
}
@Override
public void buttonPressed(Minecraft mc, int mouseX, int mouseY, char key, int keyCode) {
}
@Override
public void tick(Minecraft mc) {
}
@Override
public void setElementEnabled(boolean enabled) {
this.enabled = enabled;
}
@Override
public void setIsChecked(boolean isChecked) {
super.setIsChecked(isChecked);
fireCheckListeners();
}
private void fireCheckListeners() {
for(CheckBoxListener listener : listeners) {
listener.onCheck(isChecked());
}
}
@Override
public int xPos() {
return xPosition;
}
@Override
public int yPos() {
return yPosition;
}
@Override
public int width() {
return width;
}
@Override
public int height() {
return height;
}
@Override
public void xPos(int x) {
xPosition = x;
}
@Override
public void yPos(int y) {
yPosition = y;
}
@Override
public void width(int width) {
this.width = width;
}
@Override
public void height(int height) {
this.height = height;
}
}

View File

@@ -1,161 +0,0 @@
package eu.crushedpixel.replaymod.gui.elements;
import com.google.common.base.Strings;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiTextField;
import java.awt.*;
public class GuiAdvancedTextField extends GuiTextField implements GuiElement, GuiOutsideClickableElement {
public String hint;
public int hintTextColor = Color.DARK_GRAY.getRGB();
protected boolean isEnabled = true;
private int disabledTextColor;
public GuiAdvancedTextField(FontRenderer fontRenderer, int x, int y, int width, int height) {
super(0, fontRenderer, x, y, width, height);
}
public GuiAdvancedTextField(FontRenderer fontRenderer, String hint) {
super(0, fontRenderer, 0, 0, 0, 0);
this.hint = hint;
}
public GuiAdvancedTextField(FontRenderer fontRenderer, String hint, int maxInputLength) {
this(fontRenderer, hint);
this.height = 20;
setMaxStringLength(maxInputLength);
}
@Override
public void setElementEnabled(boolean isEnabled) {
this.isEnabled = isEnabled;
if(!isEnabled) setFocused(false);
super.setEnabled(isEnabled);
}
@Override
public void setDisabledTextColour(int disabledTextColor) {
this.disabledTextColor = disabledTextColor;
super.setDisabledTextColour(disabledTextColor);
}
@Override
public void draw(Minecraft mc, int mouseX, int mouseY) {
drawTextBox();
}
@Override
public void draw(Minecraft mc, int mouseX, int mouseY, boolean hovered) {
draw(mc, mouseX, mouseY);
}
@Override
public void drawTextBox() {
if (text.isEmpty() && !isFocused() && !Strings.isNullOrEmpty(hint)) {
super.setEnabled(false);
super.setDisabledTextColour(hintTextColor);
text = hint;
super.drawTextBox();
text = "";
super.setDisabledTextColour(disabledTextColor);
super.setEnabled(isEnabled);
} else {
super.drawTextBox();
}
}
@Override
public void drawOverlay(Minecraft mc, int mouseX, int mouseY) {
}
@Override
public boolean isHovering(int mouseX, int mouseY) {
return mouseX >= xPosition
&& mouseY >= yPosition
&& mouseX < xPosition + width
&& mouseY < yPosition + height;
}
@Override
public boolean mouseClick(Minecraft mc, int mouseX, int mouseY, int button) {
mouseClicked(mouseX, mouseY, button);
return isHovering(mouseX, mouseY);
}
@Override
public void mouseDrag(Minecraft mc, int mouseX, int mouseY, int button) {
}
@Override
public void mouseRelease(Minecraft mc, int mouseX, int mouseY, int button) {
}
@Override
public void buttonPressed(Minecraft mc, int mouseX, int mouseY, char key, int keyCode) {
textboxKeyTyped(key, keyCode);
}
@Override
public void tick(Minecraft mc) {
updateCursorCounter();
}
@Override
public void setFocused(boolean focused) {
if(!isEnabled) focused = false;
super.setFocused(focused);
}
@Override
public boolean isFocused() {
return isEnabled && super.isFocused();
}
@Override
public int xPos() {
return xPosition;
}
@Override
public int yPos() {
return yPosition;
}
@Override
public int width() {
return width;
}
@Override
public int height() {
return height;
}
@Override
public void xPos(int x) {
xPosition = x;
}
@Override
public void yPos(int y) {
yPosition = y;
}
@Override
public void width(int width) {
this.width = width;
}
@Override
public void height(int height) {
this.height = height;
}
}

View File

@@ -1,55 +0,0 @@
package eu.crushedpixel.replaymod.gui.elements;
import com.replaymod.core.utils.OpenGLUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;
import net.minecraft.client.Minecraft;
import static com.replaymod.core.ReplayMod.TEXTURE;
public class GuiArrowButton extends GuiAdvancedButton {
private static final int TEXTURE_X = 40;
private static final int TEXTURE_Y = 80;
private static final int TEXTURE_WIDTH = 12;
private static final int TEXTURE_HEIGHT = 12;
@AllArgsConstructor
public enum Direction {
UP(-90), DOWN(90), RIGHT(0), LEFT(180);
@Getter
private int rotation;
}
private Direction dir;
public GuiArrowButton(int buttonId, int x, int y, String buttonText, Direction dir) {
super(buttonId, x, y, buttonText);
this.dir = dir;
width = 20;
height = 20;
}
@Override
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
draw(mc, mouseX, mouseY);
}
@Override
public void draw(Minecraft mc, int mouseX, int mouseY, boolean hovering) {
try {
super.draw(mc, mouseX, mouseY, hovering);
mc.getTextureManager().bindTexture(TEXTURE);
OpenGLUtils.drawRotatedRectWithCustomSizedTexture(xPosition+4, yPosition+4, dir.getRotation(),
TEXTURE_X, TEXTURE_Y, TEXTURE_WIDTH, TEXTURE_HEIGHT, 128, 128);
} catch(Exception e) {
e.printStackTrace();
}
}
}

View File

@@ -1,144 +0,0 @@
package eu.crushedpixel.replaymod.gui.elements;
import eu.crushedpixel.replaymod.utils.MouseUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.GlStateManager;
import org.lwjgl.input.Mouse;
import org.lwjgl.util.Point;
import java.awt.*;
public class GuiColorPicker extends GuiAdvancedButton implements GuiOverlayElement, GuiOutsideClickableElement {
private final int PICKER_SIZE = 100;
private boolean pickerVisible = false;
private int pickedColor = Color.BLACK.getRGB();
public int pickerX, pickerY;
public GuiColorPicker(int buttonId, int x, int y, String text, int pickerX, int pickerY) {
super(buttonId, x, y, text);
this.pickerX = pickerX;
this.pickerY = pickerY;
}
@Override
public void draw(Minecraft mc, int mouseX, int mouseY, boolean hovering) {
if(this.visible) {
FontRenderer fontrenderer = mc.fontRendererObj;
mc.getTextureManager().bindTexture(buttonTextures);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.hovered = isHovering(mouseX, mouseY) && !hoveringPicker(mouseX, mouseY);
int k = this.getHoverState(this.hovered);
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
GlStateManager.blendFunc(770, 771);
this.drawTexturedModalRect(this.xPosition, this.yPosition, 0, 46 + k * 20, this.width / 2, this.height);
this.drawTexturedModalRect(this.xPosition + this.width / 2, this.yPosition, 200 - this.width / 2, 46 + k * 20, this.width / 2, this.height);
this.mouseDragged(mc, mouseX, mouseY);
int l = 14737632;
if (packedFGColour != 0) {
l = packedFGColour;
}
else if (!this.enabled) {
l = 10526880;
}
else if(this.hovered) {
l = 16777120;
}
int strWidth = fontrenderer.getStringWidth(this.displayString);
this.drawCenteredString(fontrenderer, this.displayString, this.xPosition + this.width / 2 - 10, this.yPosition + (this.height - 8) / 2, l);
this.drawGradientRect(this.xPosition + (width+strWidth)/2 - 6, this.yPosition + 4, this.xPosition + (width+strWidth)/2 + 6,
this.yPosition + 4 + 12, Color.BLACK.getRGB(), Color.BLACK.getRGB());
this.drawGradientRect(this.xPosition + (width+strWidth)/2 - 5, this.yPosition + 5, this.xPosition + (width+strWidth)/2 + 5,
this.yPosition + 5 + 10, pickedColor, pickedColor);
if(pickerVisible && this.enabled) {
this.drawGradientRect(pickerX-1, pickerY-1, pickerX+PICKER_SIZE+1, pickerY+PICKER_SIZE+1, Color.BLACK.getRGB(), Color.BLACK.getRGB());
for(int x=0; x < PICKER_SIZE; x++) {
for(int y=0; y < PICKER_SIZE; y++) {
int color = getColorAtPosition(x, y);
this.drawGradientRect(pickerX+x, pickerY+y, pickerX+x+1, pickerY+y+1, color, color);
}
}
}
}
}
@Override
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) {
boolean click = false;
if(pickerVisible && this.enabled) {
if(MouseUtils.isMouseWithinBounds(pickerX, pickerY, PICKER_SIZE, PICKER_SIZE)) {
Point mousePoint = MouseUtils.getMousePos();
setPickerColor(getColorAtPosition(mousePoint.getX() - pickerX, mousePoint.getY() - pickerY));
click = true;
}
}
return click;
}
@Override
public boolean mouseClick(Minecraft mc, int mouseX, int mouseY, int button) {
if(super.mouseClick(mc, mouseX, mouseY, button)) {
if(!hoveringPicker(mouseX, mouseY)) pickerToggled();
return true;
}
return mousePressed(mc, mouseX, mouseY);
}
@Override
public void mouseDragged(Minecraft mc, int mouseX, int mouseY) {
if(Mouse.isButtonDown(0)) mousePressed(mc, mouseX, mouseY);
}
public void pickerToggled() {
pickerVisible = !pickerVisible;
}
private int getColorAtPosition(int x, int y) {
if(x < 0 || x > PICKER_SIZE || y < 0 || y > PICKER_SIZE) return 0;
boolean grey = x >= (PICKER_SIZE-5);
float h = grey ? 0 : (float)x / (PICKER_SIZE - 5);
float s = grey ? 0 : y <= (PICKER_SIZE/2) ? (float)y / (PICKER_SIZE/2) : 1;
float v = grey ? 1 - ((float)y / PICKER_SIZE) : y > (PICKER_SIZE/2) ? 1 - ((float)(y-(PICKER_SIZE/2)) / (PICKER_SIZE/2f)) : 1;
return Color.HSBtoRGB(h, s, v);
}
public void setPickerColor(int color) {
this.pickedColor = color;
}
public int getPickedColor() {
return pickedColor & 0xffffff;
}
@Override
public void setElementEnabled(boolean enabled) {
super.setElementEnabled(enabled);
if(!enabled) pickerVisible = false;
}
@Override
public boolean isHovering(int mouseX, int mouseY) {
if(!pickerVisible) return super.isHovering(mouseX, mouseY);
return super.isHovering(mouseX, mouseY) || hoveringPicker(mouseX, mouseY);
}
public boolean hoveringPicker(int mouseX, int mouseY) {
return enabled
&& mouseX >= pickerX
&& mouseY >= pickerY
&& mouseX <= pickerX+PICKER_SIZE
&& mouseY <= pickerY+PICKER_SIZE;
}
}

View File

@@ -1,35 +0,0 @@
package eu.crushedpixel.replaymod.gui.elements;
import net.minecraft.client.Minecraft;
public interface GuiElement {
void draw(Minecraft mc, int mouseX, int mouseY);
void draw(Minecraft mc, int mouseX, int mouseY, boolean hovered);
void drawOverlay(Minecraft mc, int mouseX, int mouseY);
boolean isHovering(int mouseX, int mouseY);
int xPos();
int yPos();
int width();
int height();
void xPos(int x);
void yPos(int y);
void width(int width);
void height(int height);
boolean mouseClick(Minecraft mc, int mouseX, int mouseY, int button);
void mouseDrag(Minecraft mc, int mouseX, int mouseY, int button);
void mouseRelease(Minecraft mc, int mouseX, int mouseY, int button);
void buttonPressed(Minecraft mc, int mouseX, int mouseY, char key, int keyCode);
void tick(Minecraft mc);
void setElementEnabled(boolean enabled);
}

View File

@@ -1,136 +0,0 @@
package eu.crushedpixel.replaymod.gui.elements;
import eu.crushedpixel.replaymod.gui.elements.listeners.FileChooseListener;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.client.Minecraft;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class GuiFileChooser extends GuiAdvancedButton implements GuiOutsideClickableElement {
private final Minecraft mc = Minecraft.getMinecraft();
private final JFrame jFrame = new JFrame();
@Getter
private File selectedFile;
public void setSelectedFile(File selectedFile) {
this.selectedFile = selectedFile;
updateDisplayString();
}
protected String baseString;
private boolean save = false;
@Setter
private String[] allowedExtensions = null;
private List<FileChooseListener> listeners = new ArrayList<FileChooseListener>();
public GuiFileChooser(int buttonId, int x, int y, String buttonText, File selectedFile, String[] allowedExtensions) {
this(buttonId, x, y, buttonText, selectedFile, allowedExtensions, false);
}
public GuiFileChooser(int buttonId, int x, int y, String buttonText, File selectedFile, String[] allowedExtensions, boolean save) {
super(buttonId, x, y, buttonText);
this.selectedFile = selectedFile;
this.save = save;
this.baseString = buttonText;
updateDisplayString();
this.allowedExtensions = allowedExtensions;
}
public void addFileChooseListener(FileChooseListener listener) {
this.listeners.add(listener);
}
protected void updateDisplayString() {
this.displayString = baseString + (selectedFile == null ? "-" : selectedFile.getName());
}
@Override
public void performAction() {
new Thread(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch(Exception e) {
e.printStackTrace();
}
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFileChooser fileChooser = new JFileChooser();
StringBuilder sb = new StringBuilder();
int i = 0;
for(String extension : allowedExtensions) {
sb.append(".").append(extension);
if(i < allowedExtensions.length - 1) sb.append(",");
i++;
}
fileChooser.setFileFilter(new FileNameExtensionFilter(sb.toString(), allowedExtensions));
if(selectedFile != null) {
fileChooser.setCurrentDirectory(selectedFile.getParentFile());
fileChooser.setSelectedFile(selectedFile);
}
fileChooser.setVisible(true);
mc.addScheduledTask(new Runnable() {
@Override
public void run() {
if(mc.isFullScreen()) mc.toggleFullscreen();
mc.setIngameNotInFocus();
}
});
int result;
if(save) {
result = fileChooser.showSaveDialog(jFrame);
} else {
result = fileChooser.showOpenDialog(jFrame);
}
if(result == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
if(file != null) {
selectedFile = file;
updateDisplayString();
for(FileChooseListener listener : listeners) {
listener.onFileChosen(selectedFile);
}
}
}
fileChooser.invalidate();
}
});
}
}, "replaymod-file-chooser").start();
}
@Override
protected void finalize() throws Throwable {
jFrame.dispose();
super.finalize();
}
}

View File

@@ -1,41 +0,0 @@
package eu.crushedpixel.replaymod.gui.elements;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiListExtended.IGuiListEntry;
import net.minecraft.client.resources.I18n;
import java.awt.*;
public class GuiLoadingListEntry implements IGuiListEntry {
private final Minecraft mc = Minecraft.getMinecraft();
private final String message = I18n.format("replaymod.gui.loading")+"...";
@Override
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected) {
try {
int width = mc.fontRendererObj.getStringWidth(message);
mc.fontRendererObj.drawString(message, x+(listWidth/2)-(width/2), y + (slotHeight/2)-(mc.fontRendererObj.FONT_HEIGHT/2) - 7
, Color.LIGHT_GRAY.getRGB());
String bubbles = System.currentTimeMillis() % 500 >= 250 ? "oOo" : "OoO";
width = mc.fontRendererObj.getStringWidth(bubbles);
mc.fontRendererObj.drawString(bubbles, x+(listWidth/2)-(width/2), y + (slotHeight/2)-(mc.fontRendererObj.FONT_HEIGHT/2) + 8
, Color.LIGHT_GRAY.getRGB());
} catch(Exception e) {
e.printStackTrace();
}
}
@Override
public void setSelected(int p_178011_1_, int p_178011_2_, int p_178011_3_) {}
@Override
public boolean mousePressed(int p_148278_1_, int p_148278_2_, int p_148278_3_, int p_148278_4_, int p_148278_5_, int p_148278_6_) {
return false;
}
@Override
public void mouseReleased(int slotIndex, int x, int y, int mouseEvent, int relativeX, int relativeY) {}
}

View File

@@ -1,132 +0,0 @@
package eu.crushedpixel.replaymod.gui.elements;
import eu.crushedpixel.replaymod.gui.elements.listeners.NumberValueChangeListener;
import net.minecraft.client.gui.FontRenderer;
import java.util.ArrayList;
import java.util.List;
public class GuiNumberInput extends GuiAdvancedTextField {
private List<NumberValueChangeListener> valueChangeListeners = new ArrayList<NumberValueChangeListener>();
protected Double minimum, maximum;
protected boolean acceptFloats = false;
public GuiNumberInput(FontRenderer fontRenderer,
int xPos, int yPos, int width, Double minimum, Double maximum, Double defaultValue, boolean acceptFloats) {
super(fontRenderer, xPos, yPos, width, 20);
this.minimum = minimum;
this.maximum = maximum;
this.acceptFloats = acceptFloats;
setCursorPositionZero();
if(defaultValue != null) {
setValue(defaultValue);
}
}
public GuiNumberInput(FontRenderer fontRenderer,
int xPos, int yPos, int width, int minimum, int maximum, int defaultValue, boolean acceptFloats) {
this(fontRenderer, xPos, yPos, width, (double) minimum, (double) maximum, (double) defaultValue, acceptFloats);
}
/**
* Sets this GuiNumberInput's value without notifying the listeners.
* @param value The value to set
*/
public void setValueQuietly(double value) {
if(minimum != null && value < minimum) {
setText(acceptFloats ? minimum.toString() : Integer.toString((int) Math.round(minimum)));
} else if(maximum != null && value > maximum) {
setText(acceptFloats ? maximum.toString() : Integer.toString((int) Math.round(maximum)));
} else {
if(acceptFloats) {
setText("" + value);
} else {
setText("" + (int) Math.round(value));
}
}
setCursorPositionZero();
}
public void setValue(double value) {
setValueQuietly(value);
fireValueChangeEvent();
}
public void addValueChangeListener(NumberValueChangeListener listener) {
this.valueChangeListeners.add(listener);
}
private void fireValueChangeEvent() {
double val = acceptFloats ? getPreciseValue() : getIntValue();
for(NumberValueChangeListener listener : valueChangeListeners) {
listener.onValueChange(val);
}
}
@Override
public void writeText(String text) {
String textBefore = getText();
int cursorPositionBefore = getCursorPosition();
try {
super.writeText(text);
double val;
if(acceptFloats) {
val = Double.valueOf(getText());
} else {
val = Integer.valueOf(getText());
}
if(minimum != null && val < minimum) {
setText(acceptFloats ? minimum.toString() : Integer.toString((int) Math.round(minimum)));
} else if(maximum != null && val > maximum) {
setText(acceptFloats ? maximum.toString() : Integer.toString((int) Math.round(maximum)));
}
fireValueChangeEvent();
} catch(NumberFormatException e) {
setText(textBefore);
setCursorPosition(cursorPositionBefore);
}
}
@Override
public void deleteFromCursor(int p_146175_1_) {
super.deleteFromCursor(p_146175_1_);
fireValueChangeEvent();
}
@Override
public void deleteWords(int p_146177_1_) {
super.deleteWords(p_146177_1_);
fireValueChangeEvent();
}
public int getIntValue() {
try {
return (int)getPreciseValue();
} catch(Exception e) {
return 0;
}
}
public Integer getIntValueNullable() {
try {
return Integer.valueOf(getText());
} catch(Exception e) {
return null;
}
}
public double getPreciseValue() {
try {
return Double.valueOf(getText());
} catch(Exception e) {
return 0d;
}
}
}

View File

@@ -1,29 +0,0 @@
package eu.crushedpixel.replaymod.gui.elements;
import net.minecraft.client.gui.FontRenderer;
public class GuiNumberInputWithText extends GuiNumberInput {
private String suffix;
public GuiNumberInputWithText(FontRenderer fontRenderer,
int xPos, int yPos, int width, Double minimum, Double maximum, Double defaultValue,
boolean acceptFloats, String suffix) {
super(fontRenderer, xPos, yPos, width, minimum, maximum, defaultValue, acceptFloats);
if(suffix == null) suffix = "";
this.suffix = suffix;
}
@Override
public void drawTextBox() {
int index = getCursorPosition();
String textBefore = getText();
setText(textBefore + suffix);
setCursorPosition(index);
super.drawTextBox();
setText(textBefore);
setCursorPosition(index);
}
}

View File

@@ -1,20 +0,0 @@
package eu.crushedpixel.replaymod.gui.elements;
import net.minecraft.client.resources.I18n;
public class GuiOnOffButton extends GuiToggleButton {
private static final String[] values = new String[] {I18n.format("options.on"), I18n.format("options.off")};
public GuiOnOffButton(int buttonId, int x, int y, int width, int height, String buttonText) {
super(buttonId, x, y, width, height, buttonText, values);
}
public GuiOnOffButton(int buttonId, int x, int y, int width, int height, String buttonText, String onValue, String offValue) {
super(buttonId, x, y, width, height, buttonText, new String[] {onValue, offValue});
}
public boolean isOn() {
return getValue() == 0;
}
}

View File

@@ -1,8 +0,0 @@
package eu.crushedpixel.replaymod.gui.elements;
/**
* A dummy interface which all Gui Elements that can be unfocused (or closed)
* by clicking outside of their bounds have to implement
*/
public interface GuiOutsideClickableElement {
}

View File

@@ -1,8 +0,0 @@
package eu.crushedpixel.replaymod.gui.elements;
/**
* A dummy interface which all GuiElements that should be drawn <b>over</b>
* other GuiElements should implement.
*/
public interface GuiOverlayElement {
}

View File

@@ -1,102 +0,0 @@
package eu.crushedpixel.replaymod.gui.elements;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import java.awt.*;
public class GuiProgressBar extends Gui {
private static final int BORDER_WIDTH = 2;
private final Minecraft mc = Minecraft.getMinecraft();
private int xPosition, yPosition, width, height;
private float progress = 0;
private String progressString = null;
public GuiProgressBar() {
this(0, 0, 0, 0);
}
public GuiProgressBar(int xPosition, int yPosition, int width, int height) {
this(xPosition, yPosition, width, height, 0);
}
public GuiProgressBar(int xPosition, int yPosition, int width, int height, float initialProgress) {
this.xPosition = xPosition;
this.yPosition = yPosition;
this.width = width;
this.height = height;
this.progress = initialProgress;
}
/**
* Sets the progress amount of this GuiProgressBar.
* @param progress A value between 0 and 1
*/
public void setProgress(float progress) {
this.progress = progress;
}
public float getProgress() {
return progress;
}
/**
* Sets position and size of this GuiProgressBar.
*/
public void setBounds(int xPosition, int yPosition, int width, int height) {
this.xPosition = xPosition;
this.yPosition = yPosition;
this.width = width;
this.height = height;
}
/**
* Replaces the default progress String that is being displayed (x%) with a custom String.
* This has to be called whenever the progress itself changes.
* Setting <code>progressString</code> to <code>null</code> uses the default progress String.
* @param progressString The String to display
*/
public void setProgressString(String progressString) {
this.progressString = progressString;
}
public void drawProgressBar() {
int progressWidth = Math.round((width - (2*BORDER_WIDTH)) * progress);
String progressString;
if(this.progressString == null) {
progressString = (int) Math.floor(progress * 100) + "%";
} else {
progressString = this.progressString;
}
// Draws black outline
drawRect(xPosition, yPosition, xPosition + width, yPosition + height, Color.BLACK.getRGB());
// Draws white background
drawRect(xPosition + BORDER_WIDTH, yPosition + BORDER_WIDTH,
xPosition + width - BORDER_WIDTH, yPosition + height - BORDER_WIDTH, Color.WHITE.getRGB());
// Draws red progress
drawRect(xPosition + BORDER_WIDTH, yPosition + BORDER_WIDTH,
xPosition + BORDER_WIDTH + progressWidth, yPosition + height - BORDER_WIDTH, Color.GRAY.getRGB());
int xMiddle = xPosition + (width/2);
int yMiddle = yPosition + (height/2);
int progressStringWidth = mc.fontRendererObj.getStringWidth(progressString);
int progressStringHeight = mc.fontRendererObj.FONT_HEIGHT-3;
int progressStringXPosition = xMiddle - (progressStringWidth/2);
int progressStringYPosition = yMiddle - (progressStringHeight/2);
mc.fontRendererObj.drawString(progressString, progressStringXPosition, progressStringYPosition, Color.BLACK.getRGB());
}
}

View File

@@ -1,185 +0,0 @@
package eu.crushedpixel.replaymod.gui.elements;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiListExtended;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.util.MathHelper;
import org.lwjgl.input.Mouse;
import java.util.ArrayList;
import java.util.List;
public abstract class GuiReplayListExtended extends GuiListExtended {
public int selected = -1;
private List<IGuiListEntry> entries = new ArrayList<IGuiListEntry>();
public GuiReplayListExtended(Minecraft mcIn, int p_i45010_2_,
int p_i45010_3_, int p_i45010_4_, int p_i45010_5_, int p_i45010_6_) {
super(mcIn, p_i45010_2_, p_i45010_3_, p_i45010_4_, p_i45010_5_, p_i45010_6_);
}
@Override
protected void elementClicked(int slotIndex, boolean isDoubleClick,
int mouseX, int mouseY) {
super.elementClicked(slotIndex, isDoubleClick, mouseX, mouseY);
this.selected = slotIndex;
}
@Override
protected void drawSelectionBox(int p_148120_1_, int p_148120_2_, int p_148120_3_, int p_148120_4_) {
int i1 = this.getSize();
Tessellator tessellator = Tessellator.getInstance();
WorldRenderer worldrenderer = tessellator.getWorldRenderer();
for(int j1 = 0; j1 < i1; ++j1) {
int k1 = p_148120_2_ + j1 * this.slotHeight + this.headerPadding;
int l1 = this.slotHeight - 4;
if(k1 > this.bottom || k1 + l1 < this.top) {
this.func_178040_a(j1, p_148120_1_, k1);
}
if(this.showSelectionBox && selected == j1) {
int i2 = this.left + (this.width / 2 - this.getListWidth() / 2);
int j2 = this.left + this.width / 2 + this.getListWidth() / 2;
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.disableTexture2D();
worldrenderer.startDrawingQuads();
worldrenderer.setColorOpaque_I(8421504);
worldrenderer.addVertexWithUV((double) i2, (double) (k1 + l1 + 2), 0.0D, 0.0D, 1.0D);
worldrenderer.addVertexWithUV((double) j2, (double) (k1 + l1 + 2), 0.0D, 1.0D, 1.0D);
worldrenderer.addVertexWithUV((double) j2, (double) (k1 - 2), 0.0D, 1.0D, 0.0D);
worldrenderer.addVertexWithUV((double) i2, (double) (k1 - 2), 0.0D, 0.0D, 0.0D);
worldrenderer.setColorOpaque_I(0);
worldrenderer.addVertexWithUV((double) (i2 + 1), (double) (k1 + l1 + 1), 0.0D, 0.0D, 1.0D);
worldrenderer.addVertexWithUV((double) (j2 - 1), (double) (k1 + l1 + 1), 0.0D, 1.0D, 1.0D);
worldrenderer.addVertexWithUV((double) (j2 - 1), (double) (k1 - 1), 0.0D, 1.0D, 0.0D);
worldrenderer.addVertexWithUV((double) (i2 + 1), (double) (k1 - 1), 0.0D, 0.0D, 0.0D);
tessellator.draw();
GlStateManager.enableTexture2D();
}
this.drawSlot(j1, p_148120_1_, k1, l1, p_148120_3_, p_148120_4_);
}
}
public void clearEntries() {
entries = new ArrayList<IGuiListEntry>();
}
public void addEntry(IGuiListEntry entry) {
entries.add(entry);
}
public void addEntry(int index, IGuiListEntry entry) {
entries.add(index, entry);
}
public void removeEntry(IGuiListEntry entry) {
entries.remove(entry);
}
@Override
public IGuiListEntry getListEntry(int index) {
return entries.get(index);
}
public List<IGuiListEntry> getEntries() {
return entries;
}
@Override
protected int getSize() {
return entries.size();
}
@Override
public void handleMouseInput() {
if(this.isMouseYWithinSlotBounds(this.mouseY)) {
if(Mouse.isButtonDown(0)) {
if(this.initialClickY == -1.0F) {
int i2 = this.getScrollBarX();
int i1 = i2 + 6;
boolean flag = true;
if(this.mouseY >= this.top && this.mouseY <= this.bottom && this.mouseX <= i1) {
int i = this.width / 2 - this.getListWidth() / 2;
int j = this.width / 2 + this.getListWidth() / 2;
int k = this.mouseY - this.top - this.headerPadding + (int) this.amountScrolled - 4;
int l = k / this.slotHeight;
if(this.mouseX >= i && this.mouseX <= j && l >= 0 && k >= 0 && l < this.getSize()) {
//LoadingListEntries should not do anything
if(this.getListEntry(l) instanceof GuiLoadingListEntry) return;
boolean flag1 = l == this.selectedElement && Minecraft.getSystemTime() - this.lastClicked < 250L;
this.elementClicked(l, flag1, this.mouseX, this.mouseY);
this.selectedElement = l;
this.lastClicked = Minecraft.getSystemTime();
} else if(this.mouseX >= i && this.mouseX <= j && k < 0) {
this.func_148132_a(this.mouseX - i, this.mouseY - this.top + (int) this.amountScrolled - 4);
flag = false;
}
if(this.mouseX >= i2 && this.mouseX <= i1) {
this.scrollMultiplier = -1.0F;
int j1 = this.func_148135_f();
if(j1 < 1) {
j1 = 1;
}
int k1 = (int) ((float) ((this.bottom - this.top) * (this.bottom - this.top)) / (float) this.getContentHeight());
k1 = MathHelper.clamp_int(k1, 32, this.bottom - this.top - 8);
this.scrollMultiplier /= (float) (this.bottom - this.top - k1) / (float) j1;
} else {
this.scrollMultiplier = 1.0F;
}
if(flag) {
this.initialClickY = (float) this.mouseY;
} else {
this.initialClickY = -2.0F;
}
} else {
this.initialClickY = -2.0F;
}
} else if(this.initialClickY >= 0.0F) {
this.amountScrolled -= ((float) this.mouseY - this.initialClickY) * this.scrollMultiplier;
this.initialClickY = (float) this.mouseY;
}
} else {
this.initialClickY = -1.0F;
}
int l1 = Mouse.getEventDWheel();
if(l1 != 0) {
if(l1 > 0) {
l1 = -1;
} else if(l1 < 0) {
l1 = 1;
}
this.amountScrolled += (float) (l1 * this.slotHeight / 2);
}
}
}
@Override
public int getSlotIndexFromScreenCoords(int p_148124_1_, int p_148124_2_) {
int k = this.left + this.width / 2 - this.getListWidth() / 2 - (int)(slotHeight*(16/9f));
int l = this.left + this.width / 2 + this.getListWidth() / 2;
int i1 = p_148124_2_ - this.top - this.headerPadding + (int)this.amountScrolled - 4;
int j1 = i1 / this.slotHeight;
return p_148124_1_ < this.getScrollBarX() && p_148124_1_ >= k && p_148124_1_ <= l && j1 >= 0 && i1 >= 0 && j1 < this.getSize() ? j1 : -1;
}
}

View File

@@ -1,221 +0,0 @@
package eu.crushedpixel.replaymod.gui.elements;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.GlStateManager;
import java.awt.*;
import static com.replaymod.core.ReplayMod.TEXTURE;
import static com.replaymod.core.ReplayMod.TEXTURE_SIZE;
import static org.lwjgl.opengl.GL11.GL_BLEND;
import static org.lwjgl.opengl.GL11.glEnable;
public class GuiScrollbar extends Gui implements GuiElement {
protected static final int BORDER_LEFT = 1;
protected static final int BORDER_RIGHT = 2;
protected static final int BORDER_TOP = 1;
protected static final int BACKGROUND_WIDTH = 64;
protected static final int BACKGROUND_HEIGHT = 9;
protected static final int BACKGROUND_BODY_WIDTH = BACKGROUND_WIDTH - BORDER_LEFT - BORDER_RIGHT;
protected static final int BACKGROUND_TEXTURE_X = 64;
protected static final int BACKGROUND_TEXTURE_Y = 97;
protected static final int SLIDER_WIDTH = 62;
protected static final int SLIDER_HEIGHT = 7;
protected static final int SLIDER_TEXTURE_X = 64;
protected static final int SLIDER_TEXTURE_Y = 90;
protected static final int SLIDER_BORDER_LEFT = 1;
protected static final int SLIDER_BORDER_RIGHT = 2;
protected static final int SLIDER_BODY_WIDTH = SLIDER_WIDTH - SLIDER_BORDER_LEFT - SLIDER_BORDER_RIGHT;
/**
* Current position of the left end of the slider. Must be between 0 and 1 - {@link #size} (inclusive).
*/
public double sliderPosition;
/**
* Size of the slider. Should be between 0 (exclusive) and 1 (inclusive)
*/
public double size = 1;
protected final int positionX;
protected final int positionY;
protected final int width;
private int draggingStart = -1;
private double draggingStartPosition;
private boolean enabled = true;
public GuiScrollbar(int positionX, int positionY, int width) {
this.positionX = positionX;
this.positionY = positionY;
this.width = width;
}
private int getSliderOffsetX() {
return (int) Math.round((width - BORDER_LEFT - BORDER_RIGHT) * sliderPosition) + BORDER_LEFT;
}
@Override
public boolean mouseClick(Minecraft mc, int mouseX, int mouseY, int button) {
if(!enabled) return false;
if (isHovering(mouseX, mouseY)) {
draggingStart = mouseX;
draggingStartPosition = sliderPosition;
return true;
}
return false;
}
@Override
public void mouseDrag(Minecraft mc, int mouseX, int mouseY, int button) {
if(!enabled) return;
if (draggingStart != -1) {
double delta = (double) (mouseX - draggingStart) / (width - BORDER_LEFT - BORDER_RIGHT);
sliderPosition = Math.max(0, Math.min(1 - size, draggingStartPosition + delta));
dragged();
}
}
@Override
public void mouseRelease(Minecraft mc, int mouseX, int mouseY, int button) {
mouseDrag(mc, mouseX, mouseY, button);
draggingStart = -1;
}
@Override
public void buttonPressed(Minecraft mc, int mouseX, int mouseY, char key, int keyCode) {
}
@Override
public void tick(Minecraft mc) {
}
@Override
public void draw(Minecraft mc, int mouseX, int mouseY, boolean hovered) {
draw(mc, mouseX, mouseY);
}
@Override
public void draw(Minecraft mc, int mouseX, int mouseY) {
GlStateManager.resetColor();
mc.renderEngine.bindTexture(TEXTURE);
glEnable(GL_BLEND);
// Background
{
// We have to increase the border size as there is one pixel row which is part of the border while drawing
// but isn't during position calculations
int BORDER_LEFT = GuiScrollbar.BORDER_LEFT + 1;
int BACKGROUND_BODY_WIDTH = GuiScrollbar.BACKGROUND_BODY_WIDTH - 1;
int bodyLeft = positionX + BORDER_LEFT;
int bodyRight = positionX + width - BORDER_RIGHT;
// Left border
rect(positionX, positionY, BACKGROUND_TEXTURE_X, BACKGROUND_TEXTURE_Y, BORDER_LEFT, BACKGROUND_HEIGHT);
// Body
for (int i = bodyLeft; i < bodyRight; i += BACKGROUND_BODY_WIDTH) {
rect(i, positionY, BACKGROUND_TEXTURE_X + BORDER_LEFT, BACKGROUND_TEXTURE_Y,
Math.min(BACKGROUND_BODY_WIDTH, bodyRight - i), BACKGROUND_HEIGHT);
}
// Right border
rect(bodyRight, positionY, BACKGROUND_TEXTURE_X + BACKGROUND_WIDTH - BORDER_RIGHT,
BACKGROUND_TEXTURE_Y, BORDER_RIGHT, BACKGROUND_HEIGHT);
}
// The slider itself
{
int positionX = this.positionX + getSliderOffsetX();
int positionY = this.positionY + BORDER_TOP;
int backgroundBodyWidth = width - BORDER_LEFT - BORDER_RIGHT;
int bodyLeft = positionX + SLIDER_BORDER_LEFT;
int bodyRight = positionX + Math.max(1, (int) Math.round(backgroundBodyWidth * size) - SLIDER_BORDER_RIGHT);
// Left border
rect(positionX, positionY, SLIDER_TEXTURE_X, SLIDER_TEXTURE_Y, SLIDER_BORDER_LEFT, SLIDER_HEIGHT);
// Body
for (int i = bodyLeft; i < bodyRight; i += SLIDER_BODY_WIDTH) {
rect(i, positionY, SLIDER_TEXTURE_X + SLIDER_BORDER_LEFT, SLIDER_TEXTURE_Y,
Math.min(SLIDER_BODY_WIDTH, bodyRight - i), SLIDER_HEIGHT);
}
// Right border
rect(bodyRight, positionY, SLIDER_TEXTURE_X + SLIDER_WIDTH - SLIDER_BORDER_RIGHT,
SLIDER_TEXTURE_Y, SLIDER_BORDER_RIGHT, SLIDER_HEIGHT);
}
}
protected void rect(int x, int y, int u, int v, int width, int height) {
GlStateManager.resetColor();
if(!enabled) {
GlStateManager.color(Color.GRAY.getRed()/255f, Color.GRAY.getGreen()/255f, Color.GRAY.getBlue()/255f, 1f);
}
Minecraft.getMinecraft().renderEngine.bindTexture(TEXTURE);
glEnable(GL_BLEND);
drawModalRectWithCustomSizedTexture(x, y, u, v, width, height, TEXTURE_SIZE, TEXTURE_SIZE);
}
@Override
public void drawOverlay(Minecraft mc, int mouseX, int mouseY) {
}
@Override
public boolean isHovering(int mouseX, int mouseY) {
int offsetX = getSliderOffsetX();
int minX = positionX + offsetX;
int maxX = positionX + offsetX + Math.max(3, (int) (width * size));
int minY = positionY + BORDER_TOP;
int maxY = minY + SLIDER_HEIGHT;
return mouseX >= minX && mouseY >= minY && mouseX < maxX && mouseY < maxY;
}
public void dragged() {
}
@Override
public void setElementEnabled(boolean enabled) {
this.enabled = enabled;
}
@Override
public int xPos() {
return positionX;
}
@Override
public int yPos() {
return positionY;
}
@Override
public int width() {
return width;
}
@Override
public int height() {
return SLIDER_HEIGHT;
}
@Override
public void xPos(int x) {}
@Override
public void yPos(int y) {}
@Override
public void width(int width) {}
@Override
public void height(int height) {}
}

View File

@@ -1,39 +0,0 @@
package eu.crushedpixel.replaymod.gui.elements;
import com.replaymod.core.SettingsRegistry;
public class GuiSettingsOnOffButton extends GuiOnOffButton {
private SettingsRegistry settingsRegistry;
private SettingsRegistry.SettingKey<Boolean> toChange;
public GuiSettingsOnOffButton(int buttonId, int x, int y, int width, int height, SettingsRegistry settingsRegistry,
SettingsRegistry.SettingKey<Boolean> toChange) {
super(buttonId, x, y, width, height, toChange.getDisplayString()+": ");
this.settingsRegistry = settingsRegistry;
this.toChange = toChange;
this.setValue(settingsRegistry.get(toChange) ? 0 : 1);
}
public GuiSettingsOnOffButton(int buttonId, int x, int y, int width, int height, SettingsRegistry settingsRegistry,
SettingsRegistry.SettingKey<Boolean> toChange, String onValue, String offValue) {
super(buttonId, x, y, width, height, toChange.getDisplayString()+": ", onValue, offValue);
this.settingsRegistry = settingsRegistry;
this.toChange = toChange;
this.setValue(settingsRegistry.get(toChange) ? 0 : 1);
}
@Override
public void toggle() {
super.toggle();
settingsRegistry.set(toChange, isOn());
settingsRegistry.save();
}
@Override
public void setValue(int value) {
super.setValue(value);
settingsRegistry.set(toChange, isOn());
settingsRegistry.save();
}
}

View File

@@ -1,131 +0,0 @@
package eu.crushedpixel.replaymod.gui.elements;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import java.awt.*;
import java.util.concurrent.Callable;
public class GuiString extends Gui implements GuiElement {
public int positionX, positionY;
public Color color;
public Callable<String> getContent;
private boolean enabled = true;
public GuiString(int positionX, int positionY, Color color, final String content) {
this(positionX, positionY, color, new Callable<String>() {
@Override
public String call() throws Exception {
return content;
}
});
}
public GuiString(int positionX, int positionY, Color color, Callable<String> getContent) {
this.positionX = positionX;
this.positionY = positionY;
this.color = color;
this.getContent = getContent;
}
@Override
public void draw(Minecraft mc, int mouseX, int mouseY, boolean hovered) {
draw(mc, mouseX, mouseY);
}
@Override
public void draw(Minecraft mc, int mouseX, int mouseY) {
String text;
try {
text = getContent.call();
} catch (Exception e) {
throw new RuntimeException(e);
}
drawString(mc.fontRendererObj, text, positionX, positionY, enabled ? color.getRGB() : Color.LIGHT_GRAY.getRGB());
}
@Override
public void drawOverlay(Minecraft mc, int mouseX, int mouseY) {
}
@Override
public boolean isHovering(int mouseX, int mouseY) {
return false;
}
@Override
public boolean mouseClick(Minecraft mc, int mouseX, int mouseY, int button) {
return false;
}
@Override
public void mouseDrag(Minecraft mc, int mouseX, int mouseY, int button) {
}
@Override
public void mouseRelease(Minecraft mc, int mouseX, int mouseY, int button) {
}
@Override
public void buttonPressed(Minecraft mc, int mouseX, int mouseY, char key, int keyCode) {
}
@Override
public void tick(Minecraft mc) {
}
@Override
public void setElementEnabled(boolean enabled) {
this.enabled = enabled;
}
public int getWidth() {
try {
return Minecraft.getMinecraft().fontRendererObj.getStringWidth(this.getContent.call());
} catch(Exception e) {
e.printStackTrace();
return 0;
}
}
@Override
public int xPos() {
return positionX;
}
@Override
public int yPos() {
return positionY;
}
@Override
public int width() {
return getWidth();
}
@Override
public int height() {
return Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT;
}
@Override
public void xPos(int x) {
positionX = x;
}
@Override
public void yPos(int y) {
positionY = y;
}
@Override
public void width(int width) {}
@Override
public void height(int height) {}
}

View File

@@ -1,683 +0,0 @@
/*
* Copyright (c) 2015 johni0702
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package eu.crushedpixel.replaymod.gui.elements;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.util.ChatAllowedCharacters;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
import java.util.Arrays;
import static net.minecraft.client.renderer.GlStateManager.*;
import static net.minecraft.util.MathHelper.clamp_int;
public class GuiTextArea extends Gui implements GuiElement, GuiOutsideClickableElement {
// Constants
protected static final int BORDER = 4;
private static int LINE_SPACING = 2;
// General
protected final FontRenderer fontRenderer;
protected final int guiId;
public boolean enabled = true;
public boolean alwaysFocused;
// Geometry
public int positionX;
public int positionY;
private int width;
private int height;
// Content
private final int maxTextWidth;
private final int maxTextHeight;
private final int maxCharCount;
private String[] text = {""};
private boolean isFocused;
private int cursorX;
private int cursorY;
private int selectionX;
private int selectionY;
// Rendering
private int currentXOffset;
private int currentYOffset;
private int blinkCursorTick;
public int textColorEnabled = 0xE0E0E0;
public int textColorDisabled = 0x707070;
/*
public GuiTextArea(FontRenderer fontRenderer, int positionX, int positionY, int width, int height,
int maxTextWidth, int maxTextHeight) {
this(0, fontRenderer, positionX, positionY, width, height, maxTextWidth, maxTextHeight, -1);
}
*/
public GuiTextArea(FontRenderer fontRenderer, int positionX, int positionY, int width, int height,
int maxTextWidth, int maxTextHeight, int maxCharCount) {
this(0, fontRenderer, positionX, positionY, width, height, maxTextWidth, maxTextHeight, maxCharCount);
}
public GuiTextArea(int guiId, FontRenderer fontRenderer, int positionX, int positionY, int width, int height,
int maxTextWidth, int maxTextHeight, int maxCharCount) {
this.guiId = guiId;
this.fontRenderer = fontRenderer;
this.positionX = positionX;
this.positionY = positionY;
this.width = width;
this.height = height;
this.maxTextWidth = maxTextWidth;
this.maxTextHeight = maxTextHeight;
this.maxCharCount = maxCharCount;
}
public void setText(String[] lines) {
if (lines.length > maxTextHeight) {
lines = Arrays.copyOf(lines, maxTextHeight);
}
this.text = lines;
for (int i = 0; i < lines.length; i++) {
if (lines[i].length() > maxTextWidth) {
lines[i] = lines[i].substring(0, maxTextWidth);
}
}
}
public String[] getText() {
return this.text;
}
public String getText(int fromX, int fromY, int toX, int toY) {
StringBuilder sb = new StringBuilder();
if (fromY == toY) {
sb.append(text[fromY].substring(fromX, toX));
} else {
sb.append(text[fromY].substring(fromX)).append('\n');
for (int y = fromY + 1; y < toY; y++) {
sb.append(text[y]).append('\n');
}
sb.append(text[toY].substring(0, toX));
}
return sb.toString();
}
private void deleteText(int fromX, int fromY, int toX, int toY) {
String[] newText = new String[text.length - (toY - fromY)];
if (fromY > 0) {
System.arraycopy(text, 0, newText, 0, fromY);
}
newText[fromY] = text[fromY].substring(0, fromX) + text[toY].substring(toX);
if (toY + 1 < text.length) {
System.arraycopy(text, toY + 1, newText, fromY + 1, text.length - toY - 1);
}
text = newText;
}
public int getSelectionFromX() {
if (cursorY == selectionY) {
return cursorX > selectionX ? selectionX : cursorX;
}
return cursorY > selectionY ? selectionX : cursorX;
}
public int getSelectionToX() {
if (cursorY == selectionY) {
return cursorX > selectionX ? cursorX : selectionX;
}
return cursorY > selectionY ? cursorX : selectionX;
}
public int getSelectionFromY() {
return cursorY > selectionY ? selectionY : cursorY;
}
public int getSelectionToY() {
return cursorY > selectionY ? cursorY : selectionY;
}
public String getSelectedText() {
if (cursorX == selectionX && cursorY == selectionY) {
return "";
}
int fromX = getSelectionFromX();
int fromY = getSelectionFromY();
int toX = getSelectionToX();
int toY = getSelectionToY();
return getText(fromX, fromY, toX, toY);
}
public void deleteSelectedText() {
if (cursorX == selectionX && cursorY == selectionY) {
return;
}
int fromX = getSelectionFromX();
int fromY = getSelectionFromY();
int toX = getSelectionToX();
int toY = getSelectionToY();
deleteText(fromX, fromY, toX, toY);
cursorX = selectionX = fromX;
cursorY = selectionY = fromY;
updateCurrentXOffset();
updateCurrentYOffset();
}
private void updateCurrentXOffset() {
currentXOffset = Math.min(currentXOffset, cursorX);
String line = text[cursorY].substring(currentXOffset, cursorX);
int currentWidth = fontRenderer.getStringWidth(line);
if (currentWidth > width - BORDER * 2) {
currentXOffset = cursorX - fontRenderer.trimStringToWidth(line, width - BORDER * 2, true).length();
}
}
private void updateCurrentYOffset() {
currentYOffset = Math.min(currentYOffset, cursorY);
int lineHeight = fontRenderer.FONT_HEIGHT + LINE_SPACING;
int contentHeight = height - BORDER * 2;
int maxLines = contentHeight / lineHeight;
if (cursorY - currentYOffset >= maxLines) {
currentYOffset = cursorY - maxLines + 1;
}
}
public String cutSelectedText() {
String selection = getSelectedText();
deleteSelectedText();
return selection;
}
public void writeText(String append) {
for (char c : append.toCharArray()) {
writeChar(c);
}
}
public void writeChar(char c) {
if (!ChatAllowedCharacters.isAllowedCharacter(c) && c != '\n') {
return;
}
int totalCharCount = 0;
for(String line : text) {
totalCharCount += line.length();
}
if(maxCharCount > 0 && totalCharCount-(getSelectedText().length()) >= maxCharCount) {
return;
}
deleteSelectedText();
if (c == '\n') {
if (text.length >= maxTextHeight) {
return;
}
String[] newText = new String[text.length + 1];
if (cursorY > 0) {
System.arraycopy(text, 0, newText, 0, cursorY);
}
newText[cursorY] = text[cursorY].substring(0, cursorX);
newText[cursorY + 1] = text[cursorY].substring(cursorX);
if (cursorY + 1 < text.length) {
System.arraycopy(text, cursorY + 1, newText, cursorY + 2, text.length - cursorY - 1);
}
text = newText;
selectionX = cursorX = 0;
selectionY = ++cursorY;
updateCurrentYOffset();
} else {
String line = text[cursorY];
if (line.length() >= maxTextWidth) {
return;
}
line = line.substring(0, cursorX) + c + line.substring(cursorX);
text[cursorY] = line;
selectionX = ++cursorX;
}
updateCurrentXOffset();
}
private void deleteNextChar() {
String line = text[cursorY];
if (cursorX < line.length()) {
line = line.substring(0, cursorX) + line.substring(cursorX + 1);
text[cursorY] = line;
} else if (cursorY + 1 < text.length) {
deleteText(cursorX, cursorY, 0, cursorY + 1);
}
}
private int getNextWordLength() {
int length = 0;
String line = text[cursorY];
boolean inWord = true;
for (int i = cursorX; i < line.length(); i++) {
if (inWord) {
if (line.charAt(i) == ' ') {
inWord = false;
}
} else {
if (line.charAt(i) != ' ') {
return length;
}
}
length++;
}
return length;
}
private void deleteNextWord() {
int worldLength = getNextWordLength();
if (worldLength == 0) {
deleteNextChar();
} else {
deleteText(cursorX, cursorY, cursorX + worldLength, cursorY);
}
}
private void deletePreviousChar() {
if (cursorX > 0) {
String line = text[cursorY];
line = line.substring(0, cursorX - 1) + line.substring(cursorX);
selectionX = --cursorX;
text[cursorY] = line;
} else if (cursorY > 0) {
int fromX = text[cursorY - 1].length();
deleteText(fromX, cursorY - 1, cursorX, cursorY);
selectionX = cursorX = fromX;
selectionY = --cursorY;
}
updateCurrentXOffset();
}
private int getPreviousWordLength() {
int length = 0;
String line = text[cursorY];
boolean inWord = false;
for (int i = cursorX - 1; i >= 0; i--) {
if (inWord) {
if (line.charAt(i) == ' ') {
return length;
}
} else {
if (line.charAt(i) != ' ') {
inWord = true;
}
}
length++;
}
return length;
}
private void deletePreviousWord() {
int worldLength = getPreviousWordLength();
if (worldLength == 0) {
deletePreviousChar();
} else {
deleteText(cursorX, cursorY, cursorX - worldLength, cursorY);
selectionX = cursorX -= worldLength;
updateCurrentXOffset();
}
}
public void setCursorPosition(int x, int y) {
selectionY = cursorY = clamp_int(y, 0, text.length - 1);
selectionX = cursorX = clamp_int(x, 0, text[cursorY].length());
updateCurrentXOffset();
updateCurrentYOffset();
}
public void setFocused(boolean isFocused) {
isFocused |= alwaysFocused;
if (isFocused && !this.isFocused) {
this.blinkCursorTick = 0; // Restart blinking to indicate successful focus
}
this.isFocused = isFocused;
}
public boolean isFocused() {
return isFocused || alwaysFocused;
}
@Override
public void draw(Minecraft mc, int mouseX, int mouseY, boolean hovered) {
draw(mc, mouseX, mouseY);
}
@Override
public void draw(Minecraft mc, int mouseX, int mouseY) {
// Draw black rect once pixel smaller than gray rect
drawRect(positionX, positionY, positionX + width, positionY + height, 0xffa0a0a0);
drawRect(positionX + 1, positionY + 1, positionX + width - 1, positionY + height - 1, 0xff000000);
int textColor = this.enabled ? textColorEnabled : textColorDisabled;
int lineHeight = fontRenderer.FONT_HEIGHT + LINE_SPACING;
int contentHeight = height - BORDER * 2;
int maxLines = contentHeight / lineHeight;
int contentWidth = width - BORDER * 2;
// Draw lines
for (int i = 0; i < maxLines && i + currentYOffset < text.length; i++) {
int lineY = i + currentYOffset;
String line = text[lineY];
int leftTrimmed = 0;
if (lineY == cursorY) {
line = line.substring(currentXOffset);
leftTrimmed = currentXOffset;
}
line = fontRenderer.trimStringToWidth(line, contentWidth);
// Draw line
int posY = positionY + BORDER + i * lineHeight;
int lineEnd = fontRenderer.drawStringWithShadow(line, positionX + BORDER, posY, textColor);
// Draw selection
int fromX = getSelectionFromX();
int fromY = getSelectionFromY();
int toX = getSelectionToX();
int toY = getSelectionToY();
if (lineY > fromY && lineY < toY) { // Whole line selected
invertColors(lineEnd, posY - 1 + lineHeight, positionX + BORDER, posY - 1);
} else if (lineY == fromY && lineY == toY) { // Part of line selected
String leftStr = line.substring(0, clamp_int(fromX - leftTrimmed, 0, line.length()));
String rightStr = line.substring(clamp_int(toX - leftTrimmed, 0, line.length()));
int left = positionX + BORDER + fontRenderer.getStringWidth(leftStr);
int right = lineEnd - fontRenderer.getStringWidth(rightStr) - 1;
invertColors(right, posY - 1 + lineHeight, left, posY - 1);
} else if (lineY == fromY) { // End of line selected
String rightStr = line.substring(clamp_int(fromX - leftTrimmed, 0, line.length()));
invertColors(lineEnd, posY - 1 + lineHeight, lineEnd - fontRenderer.getStringWidth(rightStr), posY - 1);
} else if (lineY == toY) { // Beginning of line selected
String leftStr = line.substring(0, clamp_int(toX - leftTrimmed, 0, line.length()));
int right = positionX + BORDER + fontRenderer.getStringWidth(leftStr);
invertColors(right, posY - 1 + lineHeight, positionX + BORDER, posY - 1);
}
// Draw cursor
if (lineY == cursorY && blinkCursorTick / 6 % 2 == 0 && isFocused) {
String beforeCursor = line.substring(0, cursorX - leftTrimmed);
int posX = positionX + BORDER + fontRenderer.getStringWidth(beforeCursor);
if (cursorX == text[lineY].length()) {
fontRenderer.drawStringWithShadow("_", posX, posY, 0xfff0f0f0);
} else {
drawRect(posX, posY - 1, posX + 1, posY + 1 + fontRenderer.FONT_HEIGHT, 0xfff0f0f0);
}
}
}
}
private void invertColors(int right, int bottom, int left, int top) {
color(0, 0, 255, 255);
disableTexture2D();
enableColorLogic();
colorLogicOp(GL11.GL_OR_REVERSE);
Tessellator tessellator = Tessellator.getInstance();
WorldRenderer renderer = tessellator.getWorldRenderer();
renderer.startDrawingQuads();
renderer.addVertex(right, top, 0);
renderer.addVertex(left, top, 0);
renderer.addVertex(left, bottom, 0);
renderer.addVertex(right, bottom, 0);
tessellator.draw();
disableColorLogic();
enableTexture2D();
}
@Override
public void drawOverlay(Minecraft mc, int mouseX, int mouseY) {
}
@Override
public boolean isHovering(int mouseX, int mouseY) {
return mouseX >= positionX
&& mouseY >= positionY
&& mouseX < positionX + width
&& mouseY < positionY + height;
}
@Override
public boolean mouseClick(Minecraft mc, int mouseX, int mouseY, int button) {
boolean hovering = isHovering(mouseX, mouseY);
if (hovering && isFocused() && button == 0) {
mouseX -= positionX + BORDER;
mouseY -= positionY + BORDER;
int textY = clamp_int(mouseY / (fontRenderer.FONT_HEIGHT + LINE_SPACING) + currentYOffset, 0, text.length - 1);
if (cursorY != textY) {
currentXOffset = 0;
}
String line = text[textY].substring(currentXOffset);
int textX = fontRenderer.trimStringToWidth(line, mouseX).length() + currentXOffset;
setCursorPosition(textX, textY);
}
setFocused(hovering);
return hovering;
}
@Override
public void mouseDrag(Minecraft mc, int mouseX, int mouseY, int button) {
}
@Override
public void mouseRelease(Minecraft mc, int mouseX, int mouseY, int button) {
}
@Override
public void buttonPressed(Minecraft mc, int mouseX, int mouseY, char key, int keyCode) {
if (!this.isFocused) {
return;
}
if (GuiScreen.isCtrlKeyDown()) {
switch (keyCode) {
case Keyboard.KEY_A: // Select all
cursorX = cursorY = 0;
selectionY = text.length - 1;
selectionX = text[selectionY].length();
updateCurrentXOffset();
updateCurrentYOffset();
return;
case Keyboard.KEY_C: // Copy
GuiScreen.setClipboardString(getSelectedText());
return;
case Keyboard.KEY_V: // Paste
if (enabled) {
writeText(GuiScreen.getClipboardString());
}
return;
case Keyboard.KEY_X: // Cut
if (enabled) {
GuiScreen.setClipboardString(cutSelectedText());
}
return;
}
}
boolean words = GuiScreen.isCtrlKeyDown();
boolean select = GuiScreen.isShiftKeyDown();
switch (keyCode) {
case Keyboard.KEY_HOME:
cursorX = 0;
break;
case Keyboard.KEY_END:
cursorX = text[cursorY].length();
break;
case Keyboard.KEY_LEFT:
if (cursorX == 0) {
if (cursorY > 0) {
cursorY--;
cursorX = text[cursorY].length();
}
} else {
if (words) {
cursorX -= getPreviousWordLength();
} else {
cursorX--;
}
}
break;
case Keyboard.KEY_RIGHT:
if (cursorX == text[cursorY].length()) {
if (cursorY < text.length - 1) {
cursorY++;
cursorX = 0;
}
} else {
if (words) {
cursorX += getNextWordLength();
} else {
cursorX++;
}
}
break;
case Keyboard.KEY_UP:
if (cursorY > 0) {
cursorY--;
cursorX = Math.min(cursorX, text[cursorY].length());
}
break;
case Keyboard.KEY_DOWN:
if (cursorY + 1 < text.length) {
cursorY++;
cursorX = Math.min(cursorX, text[cursorY].length());
}
break;
case Keyboard.KEY_BACK:
if (enabled) {
if (getSelectedText().length() > 0) {
deleteSelectedText();
} else if (words) {
deletePreviousWord();
} else {
deletePreviousChar();
}
}
return;
case Keyboard.KEY_DELETE:
if (enabled) {
if (getSelectedText().length() > 0) {
deleteSelectedText();
} else if (words) {
deleteNextWord();
} else {
deleteNextChar();
}
}
return;
default:
if (enabled) {
if (key == '\r') {
key = '\n';
}
writeChar(key);
}
return;
}
updateCurrentXOffset();
updateCurrentYOffset();
if (!select) {
selectionX = cursorX;
selectionY = cursorY;
}
}
@Override
public void tick(Minecraft mc) {
blinkCursorTick++;
}
@Override
public void setElementEnabled(boolean enabled) {
this.enabled = enabled;
}
public void setWidth(int width) {
this.width = width;
updateCurrentXOffset();
}
@Override
public int xPos() {
return positionX;
}
@Override
public int yPos() {
return positionY;
}
@Override
public int width() {
return width;
}
@Override
public int height() {
return height;
}
@Override
public void xPos(int x) {
positionX = x;
}
@Override
public void yPos(int y) {
positionY = y;
}
@Override
public void width(int width) {
this.width = width;
}
@Override
public void height(int height) {
this.height = height;
}
}

View File

@@ -1,42 +0,0 @@
package eu.crushedpixel.replaymod.gui.elements;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.ResourceLocation;
import java.awt.*;
public class GuiTexturedButton extends GuiAdvancedButton implements GuiElement {
private final ResourceLocation texture;
private final int u, v;
private final int textureWidth, textureHeight;
public GuiTexturedButton(int buttonId, int x, int y, int width, int height, ResourceLocation texture,
int u, int v, int textureWidth, int textureHeight, Runnable action, String hoverText) {
super(buttonId, x, y, width, height, "", action, hoverText);
this.texture = texture;
this.u = u;
this.v = v;
this.textureWidth = textureWidth;
this.textureHeight = textureHeight;
}
@Override
public void draw(Minecraft mc, int mouseX, int mouseY, boolean hovering) {
if (visible) {
hovered = isHovering(mouseX, mouseY) && enabled;
if(!enabled) {
GlStateManager.color(Color.GRAY.getRed() / 255f, Color.GRAY.getGreen() / 255f, Color.GRAY.getBlue() / 255f, 1f);
} else {
GlStateManager.color(1f, 1f, 1f);
}
mc.renderEngine.bindTexture(texture);
int u = this.u + (hovering ? width : 0);
Gui.drawModalRectWithCustomSizedTexture(xPosition, yPosition, u, v, width, height, textureWidth, textureHeight);
}
}
}

View File

@@ -1,58 +0,0 @@
package eu.crushedpixel.replaymod.gui.elements;
import net.minecraft.client.Minecraft;
public class GuiToggleButton extends GuiAdvancedButton {
private String baseText;
private String[] values;
private int value;
public GuiToggleButton(int buttonId, int x, int y, String buttonText, String[] values) {
super(buttonId, x, y, buttonText);
this.values = values;
this.baseText = buttonText;
this.value = 0;
if(values.length <= 1) {
throw new RuntimeException("At least two elements need to be added to a GuiToggleButton");
}
this.displayString = baseText+values[value];
}
public GuiToggleButton(int buttonId, int x, int y, int width, int height, String buttonText, String[] values) {
this(buttonId, x, y, buttonText, values);
this.width = width;
this.height = height;
}
@Override
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) {
boolean success = super.mousePressed(mc, mouseX, mouseY);
if (success) {
toggle();
}
return success;
}
@Override
public void performAction() {
toggle();
}
public void toggle() {
value++;
if(value >= values.length) value = 0;
this.displayString = baseText+values[value];
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
this.displayString = baseText+values[value];
}
}

View File

@@ -1,7 +0,0 @@
package eu.crushedpixel.replaymod.gui.elements.listeners;
public interface CheckBoxListener {
void onCheck(boolean checked);
}

View File

@@ -1,9 +0,0 @@
package eu.crushedpixel.replaymod.gui.elements.listeners;
import java.io.File;
public interface FileChooseListener {
void onFileChosen(File file);
}

View File

@@ -1,7 +0,0 @@
package eu.crushedpixel.replaymod.gui.elements.listeners;
public interface NumberValueChangeListener {
void onValueChange(double value);
}

View File

@@ -1,9 +0,0 @@
package eu.crushedpixel.replaymod.gui.elements.listeners;
public interface ProgressUpdateListener {
void onProgressChanged(float progress);
void onProgressChanged(float progress, String progressString);
}

View File

@@ -1,7 +0,0 @@
package eu.crushedpixel.replaymod.gui.elements.listeners;
public interface SelectionListener {
void onSelectionChanged(int selectionIndex);
}

View File

@@ -1,36 +0,0 @@
package eu.crushedpixel.replaymod.utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import org.lwjgl.input.Mouse;
import org.lwjgl.util.Point;
public class MouseUtils {
private static final Minecraft mc = Minecraft.getMinecraft();
public static Point getMousePos() {
Point scaled = getScaledDimensions();
int width = scaled.getX();
int height = scaled.getY();
final int mouseX = (Mouse.getX() * width / mc.displayWidth);
final int mouseY = (height - Mouse.getY() * height / mc.displayHeight);
return new Point(mouseX, mouseY);
}
public static Point getScaledDimensions() {
ScaledResolution sr = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
final int width = sr.getScaledWidth();
final int heigth = sr.getScaledHeight();
return new Point(width, heigth);
}
public static boolean isMouseWithinBounds(int minX, int minY, int width, int height) {
Point mousePos = getMousePos();
return mousePos.getX() >= minX && mousePos.getX() <= minX + width
&& mousePos.getY() >= minY && mousePos.getY() <= minY + height;
}
}

View File

@@ -1,116 +0,0 @@
package eu.crushedpixel.replaymod.utils;
import net.minecraft.client.Minecraft;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;
public class StringUtils {
private static final Minecraft mc = Minecraft.getMinecraft();
public static String[] splitStringInMultipleRows(String string, int maxWidth) {
if(string == null) return new String[0];
List<String> rows = new ArrayList<String>();
String remaining = string;
while(remaining.length() > 0) {
String[] split = remaining.split(" ");
String b = "";
for(String sp : split) {
b += sp + " ";
if(mc.fontRendererObj.getStringWidth(b.trim()) > maxWidth) {
b = b.substring(0, b.trim().length() - (sp.length()));
break;
}
}
String trimmed = b.trim();
rows.add(trimmed);
try {
remaining = remaining.substring(trimmed.length() + 1);
} catch(Exception e) {
break;
}
}
return rows.toArray(new String[rows.size()]);
}
/**
* Slightly modified from apache commons exec. Licensed under the Apache License, Version 2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Crack a command line.
*
* @param toProcess
* the command line to process
* @return the command line broken into strings. An empty or null toProcess
* parameter results in a zero sized array
*/
public static List<String> translateCommandline(final String toProcess) {
if (toProcess == null || toProcess.length() == 0) {
// no command? no string
return Collections.emptyList();
}
// parse with a simple finite state machine
final int normal = 0;
final int inQuote = 1;
final int inDoubleQuote = 2;
int state = normal;
final StringTokenizer tok = new StringTokenizer(toProcess, "\"\' ", true);
final ArrayList<String> list = new ArrayList<String>();
StringBuilder current = new StringBuilder();
boolean lastTokenHasBeenQuoted = false;
while (tok.hasMoreTokens()) {
final String nextTok = tok.nextToken();
switch (state) {
case inQuote:
if ("\'".equals(nextTok)) {
lastTokenHasBeenQuoted = true;
state = normal;
} else {
current.append(nextTok);
}
break;
case inDoubleQuote:
if ("\"".equals(nextTok)) {
lastTokenHasBeenQuoted = true;
state = normal;
} else {
current.append(nextTok);
}
break;
default:
if ("\'".equals(nextTok)) {
state = inQuote;
} else if ("\"".equals(nextTok)) {
state = inDoubleQuote;
} else if (" ".equals(nextTok)) {
if (lastTokenHasBeenQuoted || current.length() != 0) {
list.add(current.toString());
current = new StringBuilder();
}
} else {
current.append(nextTok);
}
lastTokenHasBeenQuoted = false;
break;
}
}
if (lastTokenHasBeenQuoted || current.length() != 0) {
list.add(current.toString());
}
if (state == inQuote || state == inDoubleQuote) {
throw new IllegalArgumentException("Unbalanced quotes in "
+ toProcess);
}
return list;
}
}

View File

@@ -1,81 +0,0 @@
package eu.crushedpixel.replaymod.utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiScreen;
import org.lwjgl.util.Point;
import java.awt.Color;
public class TooltipRenderer extends Gui {
private final Minecraft mc = Minecraft.getMinecraft();
public void drawTooltip(int x, int y, String text, GuiScreen parent, Color textColor) {
drawTooltip(x, y, text, parent, textColor.getRGB());
}
public void drawTooltip(int x, int y, String text, GuiScreen parent, int textColor) {
drawTooltip(x, y, StringUtils.splitStringInMultipleRows(text, 250), parent, textColor);
}
public void drawTooltip(int x, int y, String[] textLines, GuiScreen parent, int textColor) {
int maxLineWidth = 0;
int screenWidth, screenHeight;
if(parent == null) {
Point screenDimensions = MouseUtils.getScaledDimensions();
screenWidth = screenDimensions.getX();
screenHeight = screenDimensions.getY();
} else {
screenWidth = parent.width;
screenHeight = parent.height;
}
for(String line : textLines) {
int stringWidth = mc.fontRendererObj.getStringWidth(line);
if(stringWidth > maxLineWidth) {
maxLineWidth = stringWidth;
}
}
int j2 = x + 12;
int k2 = y - 12;
int i1 = 8;
if (textLines.length > 1) {
i1 += (textLines.length - 1) * 12;
}
if (j2 + maxLineWidth > screenWidth) {
j2 -= 28 + maxLineWidth;
}
if (k2 + i1 + 6 > screenHeight) {
k2 = screenHeight - i1 - 6;
}
int j1 = -267386864;
this.drawGradientRect(j2 - 3, k2 - 4, j2 + maxLineWidth + 3, k2 - 3, j1, j1);
this.drawGradientRect(j2 - 3, k2 + i1 + 3, j2 + maxLineWidth + 3, k2 + i1 + 4, j1, j1);
this.drawGradientRect(j2 - 3, k2 - 3, j2 + maxLineWidth + 3, k2 + i1 + 3, j1, j1);
this.drawGradientRect(j2 - 4, k2 - 3, j2 - 3, k2 + i1 + 3, j1, j1);
this.drawGradientRect(j2 + maxLineWidth + 3, k2 - 3, j2 + maxLineWidth + 4, k2 + i1 + 3, j1, j1);
int k1 = 1347420415;
int l1 = (k1 & 16711422) >> 1 | k1 & -16777216;
this.drawGradientRect(j2 - 3, k2 - 3 + 1, j2 - 3 + 1, k2 + i1 + 3 - 1, k1, l1);
this.drawGradientRect(j2 + maxLineWidth + 2, k2 - 3 + 1, j2 + maxLineWidth + 3, k2 + i1 + 3 - 1, k1, l1);
this.drawGradientRect(j2 - 3, k2 - 3, j2 + maxLineWidth + 3, k2 - 3 + 1, k1, k1);
this.drawGradientRect(j2 - 3, k2 + i1 + 2, j2 + maxLineWidth + 3, k2 + i1 + 3, l1, l1);
for(String line : textLines) {
mc.fontRendererObj.drawStringWithShadow(line, j2, k2, textColor);
k2 += 12;
}
}
}