- Баллы
- 88
- Имя в Minecraft
- EvilEnginer
В общем я тут почитал английские гайды по кодерпаку и сделал нестандартные прозрачные кнопки главного меню, цвет текста при наведении мыши на кнопку может быть любым. И сейчас дорогие друзья я вам расскажу как сделать кнопки как на скриншоте.
1) В Project Explorer в Eclipse ищем папку net.minecraft.src
2) Создаём класс в этой папке и называем его CustomButton
3) В созданный файл копируем следующий код.
Строка 40 в коде меняет цвет текста при наведении мыши на кнопку код цвета HTML
4) Сохраняем работу
5) В ProjectExplorer ищем папку net.minecraft.client.gui открываем файл Gui.java
после protected float zLevel; строчка 16 вставляем этот код
6) Сохраняем работу
7) Открываем файл GuiMainMenu.java
a) Ищем private void addSingleplayerMultiplayerButtons(int par1, int par2)
б) В блоке 1
и блоке 2
Заменим слова GuiButton на CustomButton по образцу.
8) В начале файла GuiMainMenu.java после всех import пишем свой
import net.minecraft.src.CustomButton;
Гайд будет обновляться и дополняться. Прошу поставить мне лайк если мой первый гайд был для Вас полезным. Всем спасибо.
UP
1) В Project Explorer в Eclipse ищем папку net.minecraft.src
2) Создаём класс в этой папке и называем его CustomButton
3) В созданный файл копируем следующий код.
Код:
package net.minecraft.src;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
public class CustomButton extends GuiButton {
public CustomButton(int i, int j, int k, String s)
{
this(i, j, k, 200, 20, s);
}
public CustomButton(int i, int j, int k, int l, int i1, String s)
{
super(i, j, k, l, i1, s);
}
protected int getHoverState(boolean flag)
{
byte byte0 = 1;
if (!enabled)
{
byte0 = 0;
}
else if (flag)
{
byte0 = 2;
}
return byte0;
}
public void drawButton(Minecraft mc, int mx, int my)
{
FontRenderer fontrenderer = mc.fontRenderer;
boolean flag = mx >= xPosition && my >= yPosition && mx < xPosition + width && my < yPosition + height; //Flag, tells if your mouse is hovering the button
if (flag)
{ // Hover Action
drawBorderedRect(xPosition, yPosition, xPosition + width, yPosition + height, 1, 0x90FFFFFF, 0x80000000);
drawCenteredString(fontrenderer, displayString, xPosition + width / 2, yPosition + (height - 8) / 2, 0xADFF2F); //0xADFF2F - html color code, google it.
}
else { // Normal
drawBorderedRect(xPosition, yPosition, xPosition + width, yPosition + height, 1, 0x90FFFFFF, 0x60000000);
drawCenteredString(fontrenderer, displayString, xPosition + width / 2, yPosition + (height - 8) / 2, 0xFFCCCCCC);
}
}
}
Строка 40 в коде меняет цвет текста при наведении мыши на кнопку код цвета HTML
4) Сохраняем работу
5) В ProjectExplorer ищем папку net.minecraft.client.gui открываем файл Gui.java
после protected float zLevel; строчка 16 вставляем этот код
Код:
public void drawBorderedRect(int x, int y, int x1, int y1, int size, int borderC, int insideC)
{
drawRect(x + size, y + size, x1 - size, y1 - size, insideC);
drawRect(x + size, y + size, x1, y, borderC);
drawRect(x, y, x + size, y1, borderC);
drawRect(x1, y1, x1 - size, y + size, borderC);
drawRect(x, y1 - size, x1, y1, borderC);
}
7) Открываем файл GuiMainMenu.java
a) Ищем private void addSingleplayerMultiplayerButtons(int par1, int par2)
б) В блоке 1
Код:
private void addSingleplayerMultiplayerButtons(int par1, int par2)
{
this.buttonList.add(new CustomButton(1, this.width / 2 - 100, par1 + 90, I18n.getString("menu.singleplayer")));
this.buttonList.add(new CustomButton(2, this.width / 2 - 100, par1 + par2 * 1 + 90, I18n.getString("menu.multiplayer")));
//If Minecraft Realms is enabled, halve the size of both buttons and set them next to eachother.
fmlModButton = new CustomButton(6, this.width / 2 - 100, par1 + par2 * 2 + 90, I18n.getString("Mods"));
this.buttonList.add(fmlModButton);
buttonPar1 = par1;
buttonPar2 = par2;
minecraftRealmsButton = new CustomButton(14, this.width / 2 - 100, par1 + par2 * 2, I18n.getString("menu.online"));
minecraftRealmsButton.width = 98;
minecraftRealmsButton.xPosition = this.width / 2 - 100;
this.minecraftRealmsButton.drawButton = false;
}
Код:
this.buttonList.add(new CustomButton(0, this.width / 2 - 100, j + 72 + 12, 98, 20, I18n.getString("menu.options")));
this.buttonList.add(new CustomButton(4, this.width / 2 + 2, j + 72 + 12, 98, 20, I18n.getString("menu.quit")));
Заменим слова GuiButton на CustomButton по образцу.
8) В начале файла GuiMainMenu.java после всех import пишем свой
import net.minecraft.src.CustomButton;
Гайд будет обновляться и дополняться. Прошу поставить мне лайк если мой первый гайд был для Вас полезным. Всем спасибо.
UP
Последнее редактирование:
. Нашёл кое что интересное в сети на инглише вот и решил поделиться со всеми. Что у меня в планах: