Jump to content

[1-14-newer] how to make a button with a specified texture ?


matt1999rd

Recommended Posts

I am doing a mod with a special button and I don't know how to display it on the gui I have already done.

I use the line

Minecraft.getInstance().getTextureManager().bindTexture(SW_BUTTON_TEXTURE_USED);

but I did not show it on screen

How can I make it visible ?

for information the ResourceLocation is found and the boolean is at True

Link to comment
Share on other sites

It is for the gui :


public class ControllerScreen extends Screen {

    private ResourceLocation GUI = new ResourceLocation(SwitchRailMod.MODID,"textures/gui/controller_gui.png");

    private static final int WIDTH = 206;
    private static final int HEIGHT = 152;



    public int scaleX = 16;
    public int scaleY = 11;

    boolean addone =false;
    boolean delone =true;

    public Button ZoomInButton ;

    public Button ZoomOutButton ;

    public SwitchButton FirstSwitchButton ;

    private static final int white = 0xffffff;

    private TileEntity te;

    public ControllerScreen(TileEntity tileEntity) {
        super(new StringTextComponent("Switch Controller"));
        te = tileEntity;
    }
    public void init() {
        int relX = (this.width-WIDTH) / 2;
        int relY = (this.height-HEIGHT) / 2;

        addButton(new Button(relX+12,
                relY+122,
                146,
                20,
                "Done",
                button-> onClose()));
        ZoomInButton = new Button(relX+160,
                relY+26,
                39,
                20,
                "Zoom+",
                button-> ZoomIn());
        ZoomOutButton = new Button(relX+160,
                relY+47,
                39,
                20,
                "Zoom-",
                button-> ZoomOut());

        addButton(ZoomInButton);

        addButton(ZoomOutButton);

        FirstSwitchButton = new SwitchButton(relX+13,
                relY+22,
                scaleX,
                scaleY,
                "",
                SwitchType.TRIPLE,
                new BlockPos(0,0,0));

        addButton(FirstSwitchButton);


    }

    @Override
    public boolean isPauseScreen() {
        return true;
    }

    public void changeSwitch(){
    }

    public void ZoomOut(){
        System.out.println("Zoom - active");
        scaleX = (addone) ? scaleX + 1 : scaleX + 2 ;
        addone = !addone;
        delone = !delone;
        scaleY += 1;
    }

    public void ZoomIn(){
        System.out.println("Zoom + active");
        scaleX = (delone) ? scaleX - 1 : scaleX - 2 ;
        delone = !delone;
        addone = !addone;
        scaleY -= 1;
    }



    @Override
    public void render(int mouseX, int mouseY, float partialTicks) {
        GlStateManager.color4f(1.0F,1.0F,1.0F,1.0F);
        this.minecraft.getTextureManager().bindTexture(GUI);
        int relX = (this.width-WIDTH) / 2;
        int relY = (this.height-HEIGHT) / 2;
        this.blit(relX,relY,0,0,WIDTH,HEIGHT);
        this.drawString(Minecraft.getInstance().fontRenderer,"RailSystem",relX+10,relY+10,white);
        this.drawString(Minecraft.getInstance().fontRenderer,scaleX+" X "+scaleY,relX+160,relY+68,white);
        ZoomOutButton.active = (scaleX != 16);
        ZoomInButton.active = (scaleX != 4);
        FirstSwitchButton.visible = true;
        FirstSwitchButton.setWidth(scaleX);
        FirstSwitchButton.setHeight(scaleY);
        //displaySwitch(relX,relY);
        GlStateManager.enableBlend();
        super.render(mouseX, mouseY, partialTicks);


    }



    private void displaySwitch(int RelativeX,int RelativeY){
        List<SwitchData> switches = ((ControllerTile)te).getSwitch();
        if (!switches.isEmpty()) {
            int i = 20;
            for (SwitchData data : switches) {
                this.drawString(Minecraft.getInstance().fontRenderer,
                        data.type.getName()+" : "+data.pos.toString(),
                        RelativeX + 10, RelativeY + i, white);
                i += 10;
            }
        }
    }
}

 

and here is the code of my button :

package fr.mattmouss.switchrail.gui;

import fr.mattmouss.switchrail.SwitchRailMod;
import fr.mattmouss.switchrail.switchdata.SwitchType;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.AbstractGui;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.client.gui.widget.button.AbstractButton;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;

public class SwitchButton extends Widget {

    SwitchType type;
    BlockPos pos;

    private ResourceLocation SW_BUTTON_9x9 = new ResourceLocation(SwitchRailMod.MODID,"textures/gui/sw_button_9x9.png");
    private ResourceLocation SW_BUTTON_10x10 = new ResourceLocation(SwitchRailMod.MODID,"textures/gui/sw_button_10x10.png");
    private ResourceLocation SW_BUTTON_11x11 = new ResourceLocation(SwitchRailMod.MODID,"textures/gui/sw_button_11x11.png");
    private ResourceLocation SW_BUTTON_13x12 = new ResourceLocation(SwitchRailMod.MODID,"textures/gui/sw_button_13x12.png");
    private ResourceLocation SW_BUTTON_14x14 = new ResourceLocation(SwitchRailMod.MODID,"textures/gui/sw_button_14x14.png");
    private ResourceLocation SW_BUTTON_18x16 = new ResourceLocation(SwitchRailMod.MODID,"textures/gui/sw_button_18x16.png");
    private ResourceLocation SW_BUTTON_20x19 = new ResourceLocation(SwitchRailMod.MODID,"textures/gui/sw_button_20x19.png");
    private ResourceLocation SW_BUTTON_28x24 = new ResourceLocation(SwitchRailMod.MODID,"textures/gui/sw_button_28x24.png");
    private ResourceLocation SW_BUTTON_36x33 = new ResourceLocation(SwitchRailMod.MODID,"textures/gui/sw_button_36x33.png");

    public SwitchButton(int widthIn, int heightIn, int width, int height, String text,SwitchType type,BlockPos pos) {
        super(widthIn,heightIn,width,height,text);
        this.type = type;
        this.pos = pos;
    }

    @Override
    public void render(int mouseX, int mouseY, float partialTicks) {
        ResourceLocation SW_BUTTON_TEXTURE_USED ;
        switch (this.width){
            case 16:
                SW_BUTTON_TEXTURE_USED = SW_BUTTON_9x9;
                break;
            case 14:
                SW_BUTTON_TEXTURE_USED = SW_BUTTON_10x10;
                break;
            case 13:
                SW_BUTTON_TEXTURE_USED = SW_BUTTON_11x11;
                break;
            case 11:
                SW_BUTTON_TEXTURE_USED = SW_BUTTON_13x12;
                break;
            case 10:
                SW_BUTTON_TEXTURE_USED = SW_BUTTON_14x14;
                break;
            case 8:
                SW_BUTTON_TEXTURE_USED = SW_BUTTON_18x16;
                break;
            case 7:
                SW_BUTTON_TEXTURE_USED = SW_BUTTON_20x19;
                break;
            case 5:
                SW_BUTTON_TEXTURE_USED = SW_BUTTON_28x24;
                break;
            case 4:
                SW_BUTTON_TEXTURE_USED = SW_BUTTON_36x33;
                break;
            default:
                throw new IllegalArgumentException("no such scaleX authorised !! ");

        }
        Minecraft.getInstance().getTextureManager().bindTexture(SW_BUTTON_TEXTURE_USED);
        //super.render(mouseX, mouseY, partialTicks);
    }

}
Link to comment
Share on other sites

 

4 minutes ago, diesieben07 said:

Look at the normal button and adjust the rendering to your needs. 

I don't understand what you mean...

If I use render from super I get the normal aspect and without I did not show up

And I am not sure that I can do what I want because I want to make a GUI that shows button corresponding to blocks in world.

Link to comment
Share on other sites

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
  • Topics

×
×
  • Create New...

Important Information

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