Jump to content

GuiScreen color


Quickdroppin

Recommended Posts

I'm making a GUI for my mod, but I've gotten stuck on something I've never seen before.

I made gui buttons and sliders that should have colors in them, but the colors only work if I start Minecraft from within my IDE (eclipse).

(I'm using §a and so on for colors.) If I use it on my normal minecraft forge client, it get's messed up with weird characters and there's no colors.

 

Also, whenever I open the gui with my command, it lags for a second and then it opens.. or sometimes crashes my game with the error "Updating screen events". I tried searching it up but I couldn't find anything.

I've never had the problem with colors or any lag when opening any of my guis in my previous mods.

I'm using JRE 1.8.0 and this is for Minecraft Forge 1.7.10.

 

I found something about having to add a delay to open the GUI, but it doesn't help with anything than actually delaying it. If there's no delay, the game crashes.

 

GUI is opened with:

		Timer t = new Timer();
		
		t.schedule(new TimerTask() {

			@Override
			public void run() {
				
				Minecraft.getMinecraft().displayGuiScreen(new CraftGUI());
			}
			
		}, 10);

 

The entire CraftGUI class:

package me.quova.keyboardwarrior;

import java.awt.font.FontRenderContext;
import java.io.IOException;
import java.text.DecimalFormat;

import cpw.mods.fml.client.config.GuiSlider;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiLabel;
import net.minecraft.client.gui.GuiScreen;

public class CraftGUI extends GuiScreen {

	
    private GuiButton Exit;
    
    private GuiSlider typeDelay;
    
    private GuiSlider equationDelay;
    
    private GuiButton typeEnabled;
    
    private GuiButton equationEnabled;
    

    @Override
    public void initGui() {
        
        this.buttonList.add(Exit = new GuiButton(0, this.width / 2 - 100, this.height - (this.height / 4) + 10, "Exit"));
        
        this.buttonList.add(typeDelay = new GuiSlider(1, this.width / 2 - 100, this.height - (this.height / 2) - 60, 200, 20, "Type delay: §c", "", 0.0, 10.0, KeyboardWarrior.typeDelay, true, true));
        
        this.buttonList.add(equationDelay = new GuiSlider(3, this.width / 2 - 100, this.height - (this.height / 2) - 30, 200, 20, "Equation delay: §c", "", 0.0, 10.0, KeyboardWarrior.equationDelay, true, true));
        
        this.buttonList.add(typeEnabled = new GuiButton(2, this.width / 2 - 100, this.height - (this.height / 2), KeyboardWarrior.typeDS));
        
        this.buttonList.add(equationEnabled = new GuiButton(4, this.width / 2 - 100, this.height - (this.height / 2) + 30, KeyboardWarrior.equationDS));
        
        super.initGui();
    }
    
    
    @Override
    public void onGuiClosed() {
    	
    	try {
    		
        	String ft = String.valueOf(typeDelay.getValue()).substring(0, 3).replace(",", ".");
        	
        	KeyboardWarrior.typeDelay = Double.valueOf(ft);
        	
    	} catch (Exception ex) {
    		
    		try {
    			
            	String ft = String.valueOf(typeDelay.getValue()).substring(0, 2).replace(",", ".");
            	
            	KeyboardWarrior.typeDelay = Double.valueOf(ft);
            	
    		} catch (Exception ex1) {
    			
    		}
    	}
    	
    	
    	try {
        	
        	String fe = String.valueOf(equationDelay.getValue()).substring(0, 3).replace(",", ".");
        	
        	KeyboardWarrior.equationDelay = Double.valueOf(fe);
        	
    	} catch (Exception ex) {
        	
    		try {
    			
            	String fe = String.valueOf(equationDelay.getValue()).substring(0, 2).replace(",", ".");
            	
            	KeyboardWarrior.equationDelay = Double.valueOf(fe);
            	
    		} catch (Exception ex2) {
    			
    		}
    	}
    	
    	super.onGuiClosed();
    }

    
    @Override
    protected void actionPerformed(GuiButton button) {
    	
        switch(button.id) {
        
        case 0: 
        	
        	try {
        		
            	String ft = String.valueOf(typeDelay.getValue()).substring(0, 3).replace(",", ".");
            	
            	KeyboardWarrior.typeDelay = Double.valueOf(ft);
            	
        	} catch (Exception ex) {
        		
        		try {
        			
                	String ft = String.valueOf(typeDelay.getValue()).substring(0, 2).replace(",", ".");
                	
                	KeyboardWarrior.typeDelay = Double.valueOf(ft);
                	
        		} catch (Exception ex1) {
        			
        		}
        	}
        	
        	
        	try {
            	
            	String fe = String.valueOf(equationDelay.getValue()).substring(0, 3).replace(",", ".");
            	
            	KeyboardWarrior.equationDelay = Double.valueOf(fe);
            	
        	} catch (Exception ex) {
            	
        		try {
        			
                	String fe = String.valueOf(equationDelay.getValue()).substring(0, 2).replace(",", ".");
                	
                	KeyboardWarrior.equationDelay = Double.valueOf(fe);
                	
        		} catch (Exception ex2) {
        			
        		}
        	}
        	
        	mc.thePlayer.closeScreenNoPacket();
        	
        	break;
        	
        case 2:
        	
    		if(KeyboardWarrior.typeEnabled) {
    			
    			KeyboardWarrior.typeEnabled = false;
    			
    			KeyboardWarrior.typeDS = "Type: §cfalse";
    			
    		} else {
    			
    			KeyboardWarrior.typeEnabled = true;
    			
    			KeyboardWarrior.typeDS = "Type: §atrue";
    		}
    		
    		((GuiButton) this.buttonList.get(3)).displayString = KeyboardWarrior.typeDS;
    		
    		break;
    		
    		
        case 4:
        	
    		if(KeyboardWarrior.equationEnabled) {
    			
    			KeyboardWarrior.equationEnabled = false;
    			
    			KeyboardWarrior.equationDS = "Equations: §cfalse";
    			
    		} else {
    			
    			KeyboardWarrior.equationEnabled = true;
    			
    			KeyboardWarrior.equationDS = "Equations: §atrue";
    		}
    		
    		((GuiButton) this.buttonList.get(4)).displayString = KeyboardWarrior.equationDS;
    		
    		break;
    		
    		
        default: 
        	
        	break;
        }
        
        super.actionPerformed(button);
    }
	

    @Override
    public void drawScreen(int mouseX, int mouseY, float ticks) {
    	
    	this.drawDefaultBackground();

        super.drawScreen(mouseX, mouseY, ticks);
    }
    

    @Override
    public boolean doesGuiPauseGame() {
    	
        return false;
    }
}

 

Edited by Quickdroppin
Link to comment
Share on other sites

  • Guest locked this topic
Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.