i started making minecraft mod , have question regarding gui's want create slide, issue buttonlist.add(new guislider());
i don't understand parameters, can explain them me? thanks! :d
ok, figured out, need create separate slider other default, call there.
my slider code:
package tutorial.generic; 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.lwjgl.opengl.gl11; public class guisliderfixed extends guibutton { public float slidervalue = 1.0f; public float slidermaxvalue = 1.0f; public float sliderminvalue = 1.0f; public boolean dragging = false; public string label; public guisliderfixed(int id, int x, int y, string label, float startingvalue, float maxvalue, float minvalue) { super(id, x, y, 150, 20, label); this.label = label; this.slidervalue = startingvalue; this.slidermaxvalue = maxvalue; this.sliderminvalue = minvalue; } protected int gethoverstate(boolean par1) { return 0; } @override public void drawbutton(minecraft mc, int mousex, int mousey) { if (this.visible) { fontrenderer fontrenderer = mc.fontrendererobj; mc.gettexturemanager().bindtexture(buttontextures); glstatemanager.color(1.0f, 1.0f, 1.0f, 1.0f); this.hovered = mousex >= this.xposition && mousey >= this.yposition && mousex < this.xposition + this.width && mousey < this.yposition + this.height; 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; } this.drawcenteredstring(fontrenderer, this.displaystring, this.xposition + this.width / 2, this.yposition + (this.height - 8) / 2, l); } } protected void mousedragged(minecraft par1minecraft, int par2, int par3) { if (this.enabled && this.visible && this.packedfgcolour == 0) { if (this.dragging) { this.slidervalue = (float) (par2 - (this.xposition + 4)) / (float) (this.width - 8); if (this.slidervalue < 0.0f) { this.slidervalue = 0.0f; } if (this.slidervalue > 1.0f) { this.slidervalue = 1.0f; } } this.displaystring = label + ": " + (int) (slidervalue * slidermaxvalue); gl11.glcolor4f(1.0f, 1.0f, 1.0f, 1.0f); this.drawtexturedmodalrect(this.xposition + (int) (this.slidervalue * (float) (this.width - 8)), this.yposition, 0, 66, 4, 20); this.drawtexturedmodalrect(this.xposition + (int) (this.slidervalue * (float) (this.width - 8)) + 4, this.yposition, 196, 66, 4, 20); } } public boolean mousepressed(minecraft par1minecraft, int par2, int par3) { if (super.mousepressed(par1minecraft, par2, par3)) { this.slidervalue = (float) (par2 - (this.xposition + 4)) / (float) (this.width - 8); if (this.slidervalue < 0.0f) { this.slidervalue = 0.0f; } if (this.slidervalue > 1.0f) { this.slidervalue = 1.0f; } this.dragging = true; return true; } else { return false; } } public void mousereleased(int par1, int par2) { this.dragging = false; } } my gui code:
package tutorial.generic; import java.awt.color; import java.io.ioexception; import net.minecraft.client.gui.guibutton; import net.minecraft.client.gui.guiscreen; import net.minecraft.client.gui.guislider; import net.minecraft.client.gui.guitextfield; import net.minecraft.entity.player.entityplayer; import net.minecraft.nbt.nbttagcompound; import net.minecraft.util.chatcomponenttext; import net.minecraft.util.resourcelocation; import net.minecraft.util.statcollector; import net.minecraft.world.world; public class guigenerictileentity extends guiscreen{ public static nbttagcompound nametag = new nbttagcompound(); private int x, y, z; private entityplayer player; private world world; private int xsize, ysize; public static guitextfield textfield; public static guisliderfixed myslider; public static nbttagcompound maxspeedtag = new nbttagcompound(); public guigenerictileentity(entityplayer player, world world, int x, int y, int z) { this.x = x; this.y = y; this.z = z; this.player = player; this.world = world; xsize = 176; ysize = 214; } private resourcelocation backgroundimage = new resourcelocation(generic.modid.tolowercase() + ":" + "textures/gui/guibackgenerictileentity.png"); @override public void drawscreen(int mousex, int mousey, float renderpartialticks) { this.mc.gettexturemanager().bindtexture(backgroundimage); int x = (this.width - xsize) / 2; int y = (this.height - ysize) / 2; drawtexturedmodalrect(x, y, 0, 0, xsize, ysize); fontrendererobj.drawstring("mtta system", (int) (width / 2 - (width / 13)), height / 15, 8); fontrendererobj.drawstring("train name :", (int) (width / 2 - (width / 13)), (int) (height / 7.8), 8); fontrendererobj.drawstring("max speed :", (int) (width / 2 - (width / 13)), (int) (height / 3.5), 8); textfield.drawtextbox(); super.drawscreen(mousex, mousey, renderpartialticks); } @override public boolean doesguipausegame() { return false; } @override public void updatescreen(){ textfield.updatecursorcounter(); super.updatescreen(); } @override protected void keytyped(char typedchar, int keycode) throws ioexception{ textfield.textboxkeytyped(typedchar, keycode); super.keytyped(typedchar, keycode); } @override public void initgui(){ buttonlist.add(new guibutton(1, (int) (xsize / 3 * 2.35), ysize - (ysize / 18), xsize - 20, height / 12, "save , close")); myslider = new guisliderfixed(3, width / 2 - 75, height / 3, "mph ", 1.0f, 100.0f, 1.0f); buttonlist.add(myslider); myslider.slidervalue = maxspeedtag.getfloat("maxspeed"); textfield = new guitextfield(width / 2, fontrendererobj, width / 2 - 50, (int) (height / 6), 100, 20); textfield.setmaxstringlength(30); textfield.settext(nametag.getstring("name")); textfield.setfocused(true); textfield.setcanlosefocus(false); super.initgui(); } @override protected void actionperformed(guibutton guibutton) { //id id give button switch(guibutton.id) { case 1: player.closescreen(); nametag.setstring("name", textfield.gettext()); maxspeedtag.setfloat("maxspeed", myslider.slidervalue); generictileentity.processactivate(player, world); player.addchatmessage(new chatcomponenttext("saved current settings " + textfield.gettext() + "!")); break; } //packet code here //packetdispatcher.sendpackettoserver(packet); //send packet } } calling new slider works this:
create new guisliderfixed in gui code ---> example: ---> guisliderfixed myslider = new guisliderfixed();
set parameters (int id, int x, int y, string label, float statingvalue, float maxvalue, float minvalue) ---> example: ---> guisliderfixed myslider = new guisliderfixed(3, width / 2 - 75, height / 3, "mph ", 1.0f, 100.0f, 1.0f);
add buttonlist ---> example ---> buttonlist.add(myslider);
hope helps!
Comments
Post a Comment