Jump to content

Recommended Posts

Posted (edited)

I recently wrote a GuiScreen to change options in my mod, which works just fine, but the mouse doesn't show.

Here is the GuiScreen which opens:

package pvphud.main;

import java.io.IOException;

import org.lwjgl.input.Mouse;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent;
import pvphud.main.KeyStrokes.ColorChoice;

public class PVPHudOptions extends GuiScreen
{
	private GuiButton colorButton;
	private GuiButton cornerButton;
	@Override
	public void drawScreen(int mouseX, int mouseY, float partialTicks) 
	{
	    this.drawDefaultBackground();
	    super.drawScreen(mouseX, mouseY, partialTicks);
	}
	@Override
	public boolean doesGuiPauseGame() 
	{
	    return false;
	}
	@Override
	public void initGui() 
	{
		this.fontRenderer.drawString("QXB Strokes!", this.width / 2 - 100, this.height / 2 - 48, 0xFFFFFFFF);
	    this.buttonList.add(this.colorButton = new GuiButton(0, this.width / 2 - 100, this.height / 2 - 24, "Color Choice: " + KeyStrokes.chosenColor));
	    this.buttonList.add(this.cornerButton = new GuiButton(1, this.width / 2 - 100, this.height / 2 + 4, "Corner Choice: " + KeyStrokes.chosenCorner));
	}
	@Override
	protected void actionPerformed(GuiButton button) throws IOException 
	{
	    if (button == this.colorButton) 
	    {
	    	int colorInt = KeyStrokes.chosenColor.ordinal();
	    	colorInt ++;
	    	if(colorInt >= KeyStrokes.ColorChoice.values().length)
	    	{
	    		colorInt = 0;
	    	}
	    	KeyStrokes.setColorChoice(KeyStrokes.ColorChoice.values()[colorInt]);
	    }
	    if (button == this.cornerButton){
	    	int cornerInt = KeyStrokes.chosenCorner.ordinal();
	    	cornerInt ++;
	    	if(cornerInt >= KeyStrokes.Corner.values().length)
	    	{
	    		cornerInt = 0;
	    	}
	    	KeyStrokes.setCornerChoice(KeyStrokes.Corner.values()[cornerInt]);
	    }
	}
	@Override
	public void updateScreen()
    {
		this.initGui();
    }
	@Override
	public void onGuiClosed()
    {
    }
}

 

Edited by bboc
Posted
19 minutes ago, bboc said:

@Override public void updateScreen() {
    this.initGui();
}

 

Oh god why. ;_;

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)
7 minutes ago, Draco18s said:

Oh god why. ;_;

Sorry fam, I'm really just tryna learn by doing here, I needed the buttons' contents to update depending on what option they had chosen, and despite being ghetto that seemed like a working way to do it. What method do you suggest to make sure the button contents are constantly updated?

 

*Edit NVM That was stupid I can just re-add the button I should have thought that through more. The issue still stands however, I can't get the mouse to render.

Edited by bboc
Posted

You are adding new buttons every frame. 120 new buttons every second your gui is open.

You want to update the buttons, then hold a reference TO the button and update it, don't create a new one.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)
27 minutes ago, Draco18s said:

You are adding new buttons every frame. 120 new buttons every second your gui is open.

You want to update the buttons, then hold a reference TO the button and update it, don't create a new one.

You're absolutely right. I'm just not thinking through this stuff right or something rn. Regardless, I've replaced the re-adding with .set, so now it just updates the button. Beyond that, I still need to render the mouse, and my original guess of mc.mousehelper.ungrabMouseCursor() doesn't seem to work.

 

*EDIT Through using Mouse.setGrabbed(false) I can allow myself to click the buttons, but for some reason it's very sporadic and only lets me sometimes click them.

Edited by bboc
Posted (edited)
3 hours ago, diesieben07 said:

Post updated code.

package pvphud.main;
import java.io.IOException;
import org.lwjgl.input.Mouse;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import pvphud.main.KeyStrokes.ColorChoice;
public class PVPHudOptions extends GuiScreen
{
    private GuiButton colorButton;
    private GuiButton cornerButton;
    @Override
    public void drawScreen(int mouseX, int mouseY, float partialTicks) 
    {
        this.drawDefaultBackground();
        super.drawScreen(mouseX, mouseY, partialTicks);
    }
    @Override
    public boolean doesGuiPauseGame()
    {
        return false;
    }
    @Override
    public void initGui() 
    {
        this.buttonList.add(this.colorButton = new GuiButton(0, this.width / 2 - 100, this.height / 2 - 24, "Color Choice: " + KeyStrokes.chosenColor));
        this.buttonList.add(this.cornerButton = new GuiButton(1, this.width / 2 - 100, this.height / 2 + 4, "Corner Choice: " + KeyStrokes.chosenCorner));
    }
    @Override
    protected void actionPerformed(GuiButton button) throws IOException 
    {
        if (button == this.colorButton) 
        {
            int colorInt = KeyStrokes.chosenColor.ordinal();
            colorInt ++;
            if(colorInt >= KeyStrokes.ColorChoice.values().length)
            {
                colorInt = 0;
            }
            KeyStrokes.setColorChoice(KeyStrokes.ColorChoice.values()[colorInt]);
            this.buttonList.set(0, this.colorButton = new GuiButton(0, this.width / 2 - 100, this.height / 2 - 24, "Color Choice: " + KeyStrokes.chosenColor));
        }
        if (button == this.cornerButton){
            int cornerInt = KeyStrokes.chosenCorner.ordinal();
            cornerInt ++;
            if(cornerInt >= KeyStrokes.Corner.values().length)
            {
                cornerInt = 0;
            }
            KeyStrokes.setCornerChoice(KeyStrokes.Corner.values()[cornerInt]);
            this.buttonList.set(1, this.cornerButton = new GuiButton(1, this.width / 2 - 100, this.height / 2 + 4, "Corner Choice: " + KeyStrokes.chosenCorner));
        }
    }
}

 

Edited by bboc
Posted
3 minutes ago, diesieben07 said:

I don't see how that would break mouse capturing...

I don't see why either tbh. I'm currently in the process of rewriting everything from the ground up, because my previous code was very hacky and rushed, but to maybe stop this from happening again; here's the way that I was calling the GuiScreen, perhaps the issue lies in there? 

package pvphud.main;

import java.util.List;

import net.minecraft.client.Minecraft;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.server.MinecraftServer;


public class HudOpener extends CommandBase
{

	@Override
	public String getName() 
	{
		return "pvphud";
	}

	@Override
	public String getUsage(ICommandSender sender) 
	{
		return "pvphud";
	}

	@Override
	public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException 
	{
		Minecraft.getMinecraft().displayGuiScreen(new PVPHudOptions());
	}
	
}

 

Posted
2 minutes ago, diesieben07 said:

How are you registering that command? If it is a normal server command, what you are doing is reaching across logical sides, not a good idea and probably the cause of your issue.

I think you're right? Though honestly I'm not certain. What I've got is:

@EventHandler
	public void serverLoad(FMLServerStartingEvent event)
    {
        event.registerServerCommand(new HudOpener());
    }

 

Posted
36 minutes ago, diesieben07 said:

You are registering a server command. GUIs are purely client side.

As an alternative should I just add a check in the chat message sent event? Is there an alternative way to add a client side command?

Posted
28 minutes ago, diesieben07 said:

ClientCommandHandler

I've registered my command with that and the GUI is working wonderfully, thank you sm.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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