The GUI I have in mind is similar to terrafirmacraft's knapping GUI. The player would be presented with a 5x7 grid where he would have to carve out a rune.
I have no idea how to accomplish the "carving" part though.
I tried looking through the code of the TFC mod, but found it way too complicated.
I've never seen the example you've mentioned, but the way I'd go about trying this is making that grid out of buttons, which you can then handle however you want. For examples of buttons in use in GUIs, have a look at the Beacon GUI. Otherwise, I used that class to make a custom GUI where buttons are used to select an upgrade for a weapon:
I've never seen the example you've mentioned, but the way I'd go about trying this is making that grid out of buttons, which you can then handle however you want. For examples of buttons in use in GUIs, have a look at the Beacon GUI. Otherwise, I used that class to make a custom GUI where buttons are used to select an upgrade for a weapon:
There are probably a lot of different approaches to this one. But just let me explain how I would go about doing this:
1. Create a private two - dimensional array of booleans to store which parts are carved out.
For example: private boolean[][] grid = new boolean[gridWidth][gridHeight];
2. Create a method for rendering the grid. In this method you loop through your array and render some quads (Select the texture based off the boolean is true / false (The part is carved out or not)
3. Call your rendering method from the drawGuiContainerBackgroundLayer() method of your GUI
4. In your mouseClicked() method you wanna check if the coordinates where the player has clicked, is one of grid pieces (Would create a separate method for that). If it is one of your grid components, than set it to true (If it was false before)
5. For checking the result ... you wanna create either a button for that or check it every tick. I would create a two - dimensional boolean array for each possible rune and then compare it with your grid. If it is the same than give the rune to the player
Hope you kinda understand what I'm trying to explain you. (I know I'm pretty bad with explaining ;( ) If you need some more information to one of the steps feel free to ask me. But like I said there a probably a lot of different ways to go about that. For sure some better ones then mine (It's similar to what I've done in my research system)
What about the result of the carving? How would you go about detecting which pattern of buttons was pressed and then add a crafting result?
Have a button you click to finish the "carving", which would compare the state of all the buttons against your carving recipes. If it matches one, then perhaps drop the output item onto the player, or however you want to handle it.
TechMage66's method would work too, but it would require a bit more manual work, when the button class is already available. Don't reinvent the wheel if you don't need to. The buttons can have any texture you want, so using them won't limit your graphical presentation of the GUI much.
EDIT:
You can make the buttons toggle their state on press easily by overriding the appropriate methods and using something like:
Thanks for all your replies. I guess I'll try TechMages66's method since it looks easier too me. I'll report when I run into a problem or when I finish the system.
There are probably a lot of different approaches to this one. But just let me explain how I would go about doing this:
1. Create a private two - dimensional array of booleans to store which parts are carved out.
For example: private boolean[][] grid = new boolean[gridWidth][gridHeight];
2. Create a method for rendering the grid. In this method you loop through your array and render some quads (Select the texture based off the boolean is true / false (The part is carved out or not)
3. Call your rendering method from the drawGuiContainerBackgroundLayer() method of your GUI
4. In your mouseClicked() method you wanna check if the coordinates where the player has clicked, is one of grid pieces (Would create a separate method for that). If it is one of your grid components, than set it to true (If it was false before)
5. For checking the result ... you wanna create either a button for that or check it every tick. I would create a two - dimensional boolean array for each possible rune and then compare it with your grid. If it is the same than give the rune to the player
Hope you kinda understand what I'm trying to explain you. (I know I'm pretty bad with explaining ;( ) If you need some more information to one of the steps feel free to ask me. But like I said there a probably a lot of different ways to go about that. For sure some better ones then mine (It's similar to what I've done in my research system)
Nice Greetings
TechMage66
I have already ran into a problem. Since I know nothing about rendering and gl, I have stopped at point 2. What would I have to code to render these grid pieces? Also, what would I have to do if I wanted each grid piece to be a different texture?
Make sure it will render the texture in full colour and not translucent.
3) drawTexturedModalRect(xPosition, yPosition, iconX, y, width, height);
Draw the button texture on the screen. First two parameters are the position on the screen, second two are top left position of the button texture on the GUI texture image and the last two are the width and height of the button texture.
That's the basics of what's needed to render the texture. I don't know in your case if anything else is needed, but the calls to my button rendering are handled by vanilla code so that's a part that's easier with my method.
Make sure it will render the texture in full colour and not translucent.
3) drawTexturedModalRect(xPosition, yPosition, iconX, y, width, height);
Draw the button texture on the screen. First two parameters are the position on the screen, second two are top left position of the button texture on the GUI texture image and the last two are the width and height of the button texture.
That's the basics of what's needed to render the texture. I don't know in your case if anything else is needed, but the calls to my button rendering are handled by vanilla code so that's a part that's easier with my method.
Thanks for the explanation. But what are "quads" mentioned by TechMage66?
And now I need help with point 4. First off, what are the params for mouseClicked()? Then how would I check if a specific area was pressed? And when it was pressed would the GUI update to show the texture?
2) You don't need to call "GL11.glColor4f(1F, 1F, 1F, 1F);" every time you draw one of the carving squares. Just call it at the beginning of the method, outside of the 'for' loops.
Nothing else I can suggest right now, but onto what you've asked.
The method for mouseClicked looks like this:
mouseClicked(int mouseX, int mouseY, int mouseButton)
If you want more info, then just look at the method in GuiScreen. You could have just searched for the method in the class with CTRL + F.
It tells you exactly where the mouse was clicked. So all you need to do is check if one of your carving squares were clicked, and do what you want to do with it. Your code (although needs to be adjusted with what I said in improvement #1) already will display the correct texture for the square depending on it's state.
2) You don't need to call "GL11.glColor4f(1F, 1F, 1F, 1F);" every time you draw one of the carving squares. Just call it at the beginning of the method, outside of the 'for' loops.
Nothing else I can suggest right now, but onto what you've asked.
The method for mouseClicked looks like this:
mouseClicked(int mouseX, int mouseY, int mouseButton)
If you want more info, then just look at the method in GuiScreen. You could have just searched for the method in the class with CTRL + F.
It tells you exactly where the mouse was clicked. So all you need to do is check if one of your carving squares were clicked, and do what you want to do with it. Your code (although needs to be adjusted with what I said in improvement #1) already will display the correct texture for the square depending on it's state.
Alright, so I got an algorithm going to check the position of the mouse click and compare it to the areas of the squares. But the mouseClicked() method seems to be giving me very different values to those of the GUI. I'm guessing it's because it takes into consideration the whole screen. How would I make the mouseClicked method start counting from the GUI's top and left?
Ok it seems to be working now! BUT if I click on any of the squares below y = 86 (6, 7 row) the game comes with a weird crash: http://pastebin.com/4Rb6hy9e
Look like you're trying to access a value of your 2D grid array which is out of it's bounds on line 66. I don't see why it's happening, so I suggest you do some debugging.
Look like you're trying to access a value of your 2D grid array which is out of it's bounds on line 66. I don't see why it's happening, so I suggest you do some debugging.
Well log prints are a way of debugging, but your IDE will have a debugging tool built in, where you can add breakpoints to lines of code which will pause Minecraft when it reaches it, and then you can look at the current values of variables and step through the next lines of code it will run. If you don't know about it, I strongly recommend you look into how to use it for your IDE. It can really help and speed up debugging code.
The GUI I have in mind is similar to terrafirmacraft's knapping GUI. The player would be presented with a 5x7 grid where he would have to carve out a rune.
I have no idea how to accomplish the "carving" part though.
I tried looking through the code of the TFC mod, but found it way too complicated.
Here's what I have so far:
Handler
http://pastebin.com/NVG8dz4a
GUI
http://pastebin.com/uQAwyAsr
Container
http://pastebin.com/6ct1k6jT
Open the GUI
http://pastebin.com/LwsbPKvs
Registration
I've never seen the example you've mentioned, but the way I'd go about trying this is making that grid out of buttons, which you can then handle however you want. For examples of buttons in use in GUIs, have a look at the Beacon GUI. Otherwise, I used that class to make a custom GUI where buttons are used to select an upgrade for a weapon:
https://github.com/alxnns1/MobHunter/blob/master/src/main/java/com/alxnns1/mobhunter/gui/GuiWeaponUpgrade.java
The button classes are defined at the bottom.
The rest of the repository is there, so feel free to look around for any extra information you need.
What about the result of the carving? How would you go about detecting which pattern of buttons was pressed and then add a crafting result?
There are probably a lot of different approaches to this one. But just let me explain how I would go about doing this:
1. Create a private two - dimensional array of booleans to store which parts are carved out.
For example: private boolean[][] grid = new boolean[gridWidth][gridHeight];
2. Create a method for rendering the grid. In this method you loop through your array and render some quads (Select the texture based off the boolean is true / false (The part is carved out or not)
3. Call your rendering method from the drawGuiContainerBackgroundLayer() method of your GUI
4. In your mouseClicked() method you wanna check if the coordinates where the player has clicked, is one of grid pieces (Would create a separate method for that). If it is one of your grid components, than set it to true (If it was false before)
5. For checking the result ... you wanna create either a button for that or check it every tick. I would create a two - dimensional boolean array for each possible rune and then compare it with your grid. If it is the same than give the rune to the player
Hope you kinda understand what I'm trying to explain you. (I know I'm pretty bad with explaining ;( ) If you need some more information to one of the steps feel free to ask me. But like I said there a probably a lot of different ways to go about that. For sure some better ones then mine (It's similar to what I've done in my research system)
Nice Greetings
TechMage66
Have a button you click to finish the "carving", which would compare the state of all the buttons against your carving recipes. If it matches one, then perhaps drop the output item onto the player, or however you want to handle it.
TechMage66's method would work too, but it would require a bit more manual work, when the button class is already available. Don't reinvent the wheel if you don't need to. The buttons can have any texture you want, so using them won't limit your graphical presentation of the GUI much.
EDIT:
You can make the buttons toggle their state on press easily by overriding the appropriate methods and using something like:
That works, but does it really make sense to be able to un-carve something?
It is up to MelonSlise to decide how to handle that, I guess.
Thanks for all your replies. I guess I'll try TechMages66's method since it looks easier too me. I'll report when I run into a problem or when I finish the system.
I have already ran into a problem. Since I know nothing about rendering and gl, I have stopped at point 2. What would I have to code to render these grid pieces? Also, what would I have to do if I wanted each grid piece to be a different texture?
EDIT: Sorry for double post
You'll need something like what's in my button rendering code here.
So you can see there:
1) mc.getTextureManager().bindTexture(guiImage);
I set the texture to use to my GUI texture.
2) GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
Make sure it will render the texture in full colour and not translucent.
3) drawTexturedModalRect(xPosition, yPosition, iconX, y, width, height);
Draw the button texture on the screen. First two parameters are the position on the screen, second two are top left position of the button texture on the GUI texture image and the last two are the width and height of the button texture.
4) drawCenteredString(fontrenderer, displayString, (xPosition + 16) + (width - 16) / 2, yPosition + (height - 8) / 2, textColour);
I draw some text on the button.
That's the basics of what's needed to render the texture. I don't know in your case if anything else is needed, but the calls to my button rendering are handled by vanilla code so that's a part that's easier with my method.
Thanks for the explanation. But what are "quads" mentioned by TechMage66?
Yeah I meant Rectangles ... Sorry if that confused you ;(
Nice Greetings
TechMage66
Here's the code so far:
http://pastebin.com/fiYHwHJg
And now I need help with point 4. First off, what are the params for mouseClicked()? Then how would I check if a specific area was pressed? And when it was pressed would the GUI update to show the texture?
Okay, so some improvements firstly:
1) You should not have all your textures in separate files. Refer to my example where I have my resource location defined here and the GUI texture can be found here.
2) You don't need to call "GL11.glColor4f(1F, 1F, 1F, 1F);" every time you draw one of the carving squares. Just call it at the beginning of the method, outside of the 'for' loops.
Nothing else I can suggest right now, but onto what you've asked.
The method for mouseClicked looks like this:
If you want more info, then just look at the method in GuiScreen. You could have just searched for the method in the class with CTRL + F.
It tells you exactly where the mouse was clicked. So all you need to do is check if one of your carving squares were clicked, and do what you want to do with it. Your code (although needs to be adjusted with what I said in improvement #1) already will display the correct texture for the square depending on it's state.
Alright, so I got an algorithm going to check the position of the mouse click and compare it to the areas of the squares. But the mouseClicked() method seems to be giving me very different values to those of the GUI. I'm guessing it's because it takes into consideration the whole screen. How would I make the mouseClicked method start counting from the GUI's top and left?
http://pastebin.com/fyezCjQB
You should have access to guiLeft and guiTop.
If these are not working correctly (Had this problem one time before) you can calculate them easily by your self:
this.guiLeft = (this.width - this.xSize) / 2;
this.guiTop = (this.height - this.ySize) / 2;
Nice Greetings
TechMage66
Ok it seems to be working now! BUT if I click on any of the squares below y = 86 (6, 7 row) the game comes with a weird crash:
http://pastebin.com/4Rb6hy9e
Updated code:
http://pastebin.com/K8vRaCz9
Ok I'll take a look into it.
I had a bit spare time today so I created the rendering code for my self (For testing purpose). So if you wanna take a look into it: GuiRunes
Nice Greetings
TechMage66
Look like you're trying to access a value of your 2D grid array which is out of it's bounds on line 66. I don't see why it's happening, so I suggest you do some debugging.
Mine and yours look essentially the same. But notice how in your mouseClicked() method you need to remove the '=' from 'mouseX <= guiLeft + ...'
How exactly do I debug?
Well log prints are a way of debugging, but your IDE will have a debugging tool built in, where you can add breakpoints to lines of code which will pause Minecraft when it reaches it, and then you can look at the current values of variables and step through the next lines of code it will run. If you don't know about it, I strongly recommend you look into how to use it for your IDE. It can really help and speed up debugging code.