Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.minecraft.src;
- import java.awt.Frame;
- import java.awt.Window;
- import java.lang.reflect.InvocationTargetException;
- import java.lang.reflect.Method;
- import net.minecraft.client.Minecraft;
- import org.lwjgl.LWJGLException;
- import org.lwjgl.input.Keyboard;
- import org.lwjgl.opengl.Display;
- import org.lwjgl.opengl.DisplayMode;
- public class GenuineGuiScreenSize extends GuiScreen {
- private GuiTextField theGuiTextField;
- private String errorMessage1 = "";
- private String errorMessage2 = "";
- private String screenSize;
- private GuiScreen parent;
- public GenuineGuiScreenSize(GuiScreen parent) {
- this.parent = parent;
- screenSize = Integer.toString(Display.getParent().getWidth()) + "x" + Integer.toString(Display.getParent().getHeight());
- }
- protected void actionPerformed(GuiButton par1GuiButton) {
- if (par1GuiButton.enabled) {
- if (par1GuiButton.id == 1) {
- this.mc.displayGuiScreen(null);
- }
- else if (par1GuiButton.id == 0) {
- String[] size = this.theGuiTextField.getText().split("[ -/xX]");
- if (size.length == 2) {
- try {
- int width = Integer.valueOf(size[0]);
- int height = Integer.valueOf(size[1]);
- if (width >= 400 && height >= 300) {
- setInGameScreenSize(width, height);
- this.mc.displayGuiScreen(null);
- }
- else {
- errorMessage1 = "\2474Error:\247f Must be > or = 400x300.";
- errorMessage2 = "(x can be anything on the numpad)";
- }
- }
- catch (NumberFormatException e) {
- errorMessage1 = "\2474Error:\247f Input must be numbers.";
- errorMessage2 = "";
- }
- }
- else {
- if (this.theGuiTextField.getText().equalsIgnoreCase("max")) {
- setInGameScreenSize(10000, 10000);
- this.mc.displayGuiScreen(parent);
- }
- errorMessage1 = "\2474Error:\247f Input must look like 800x600";
- errorMessage2 = "(x can be anything on the numpad)";
- }
- }
- }
- }
- public void drawScreen(int par1, int par2, float par3) {
- screenSize = Integer.toString(Display.getParent().getWidth()) + "x" + Integer.toString(Display.getParent().getHeight());
- StringTranslate var4 = StringTranslate.getInstance();
- this.drawDefaultBackground();
- this.drawCenteredString(this.fontRenderer, "Set Screen Size", this.width / 2, this.height / 4 - 60 + 20, 16777215);
- this.drawString(this.fontRenderer, var4.translateKey("Enter new size - Like: 1280x720, or max"), this.width / 2 - 100, this.height / 4 - 15, 10526880);
- this.drawString(this.fontRenderer, errorMessage1, this.width / 2 - 100, this.height / 4 + 27, 10526880);
- this.drawString(this.fontRenderer, errorMessage2, this.width / 2 - 100, this.height / 4 + 47, 10526880);
- this.theGuiTextField.drawTextBox();
- super.drawScreen(par1, par2, par3);
- }
- public void initGui() {
- Keyboard.enableRepeatEvents(true);
- this.controlList.clear();
- this.controlList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 108, StringTranslate.getInstance().translateKey("gui.done")));
- this.controlList.add(new GuiButton(1, this.width / 2 - 100, this.height / 4 + 132, StringTranslate.getInstance().translateKey("gui.cancel")));
- this.theGuiTextField = new GuiTextField(this.fontRenderer, this.width / 2 - 100, this.height / 4, 200, 20);
- this.theGuiTextField.setFocused(true);
- this.theGuiTextField.setText(screenSize);
- }
- protected void keyTyped(char par1, int par2) {
- if (par1 == '+')
- return;
- this.theGuiTextField.textboxKeyTyped(par1, par2);
- ((GuiButton) this.controlList.get(0)).enabled = this.theGuiTextField.getText().trim().length() > 0;
- if (par1 == 13 /* Enter */) {
- this.actionPerformed((GuiButton) this.controlList.get(0));
- }
- }
- protected void mouseClicked(int par1, int par2, int par3) {
- super.mouseClicked(par1, par2, par3);
- this.theGuiTextField.mouseClicked(par1, par2, par3);
- }
- public void onGuiClosed() {
- Keyboard.enableRepeatEvents(false);
- }
- public void setInGameScreenSize(int width, int height) {
- int widthDif = Window.getWindows()[0].getWidth() - Display.getParent().getWidth();
- int heightDif = Window.getWindows()[0].getHeight() - Display.getParent().getHeight();
- if (Display.isFullscreen()) {
- try {
- int x = 100000;
- int y = 100000;
- DisplayMode mode = null;
- for (DisplayMode dm : Display.getAvailableDisplayModes()) {
- if ((Math.abs(dm.getWidth() - width) <= x) && (Math.abs(dm.getHeight() - height) <= y)) {
- x = Math.abs(dm.getWidth() - width);
- y = Math.abs(dm.getHeight() - height);
- mode = dm;
- }
- }
- for (DisplayMode dm : Display.getAvailableDisplayModes())
- if ((Math.abs(dm.getWidth() - width) == x) && (Math.abs(dm.getHeight() - height) == y) && mode.getBitsPerPixel() <= dm.getBitsPerPixel()
- && mode.getFrequency() <= dm.getFrequency())
- mode = dm;
- if (mode != null) {
- Display.setDisplayMode(mode);
- mc.displayWidth = Display.getDisplayMode().getWidth();
- mc.displayHeight = Display.getDisplayMode().getHeight();
- if (mc.displayWidth <= 0)
- mc.displayWidth = 1;
- if (mc.displayHeight <= 0)
- mc.displayHeight = 1;
- Display.update();
- Method method = null;
- try {
- method = Minecraft.class.getDeclaredMethod("a", int.class, int.class);
- }
- catch (NoSuchMethodException e) {
- try {
- method = Minecraft.class.getDeclaredMethod("resize", int.class, int.class);
- }
- catch (NoSuchMethodException e1) {
- }
- }
- if (method != null) {
- method.setAccessible(true);
- method.invoke(mc, mc.displayWidth, mc.displayHeight);
- }
- }
- }
- catch (LWJGLException e) {
- e.printStackTrace();
- }
- catch (IllegalArgumentException e) {
- e.printStackTrace();
- }
- catch (SecurityException e) {
- e.printStackTrace();
- }
- catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- catch (InvocationTargetException e) {
- e.printStackTrace();
- }
- }
- else {
- if (width == 10000 && height == 10000)
- Frame.getFrames()[0].setExtendedState(Frame.MAXIMIZED_BOTH);
- Window.getWindows()[0].setSize(width + widthDif, height + heightDif);
- }
- }
- public void updateScreen() {
- this.theGuiTextField.updateCursorCounter();
- }
- }
Advertisement