- 3
- 0
Всем привет. Подскажите пожалуйста такую вещь.
У меня есть мод на дуэли, хочу добавить в основную GUI дуэлей кнопку при нажатии которой поверх основной GUI дуэлей открывалось новое с определенным текстом, как я могу это сделать? Я уже и класс создал новый и кнопку добавил. Но почему-то при нажатии на кнопку у меня на милисекунду открывается вторая GUI, но потом закрываются сразу оба... Может вы сможете мне помочь....
Вот код второй GUI
А вот код основной GUI дуэлей
У меня есть мод на дуэли, хочу добавить в основную GUI дуэлей кнопку при нажатии которой поверх основной GUI дуэлей открывалось новое с определенным текстом, как я могу это сделать? Я уже и класс создал новый и кнопку добавил. Но почему-то при нажатии на кнопку у меня на милисекунду открывается вторая GUI, но потом закрываются сразу оба... Может вы сможете мне помочь....
Вот код второй GUI
Java:
public class ButtonInfo extends GuiScreen {
private GuiScreen parentScreen;
public ButtonInfo(GuiScreen parentScreen) {
this.parentScreen = parentScreen;
}
@Override
public void drawScreen(int x, int y, float part) {
Util.drawRect(0, 0, this.width, this.height, Util.color(50, 50, 50, 70));
float widthmenu = 80;
float heightmenu = 50;
// main
Util.drawGradientRect(this.width / 2 - widthmenu, this.height / 2 - heightmenu, this.width / 2 + widthmenu,
this.height / 2 + heightmenu + 15, Util.color(0, 0, 50, 75), Util.color(0, 0, 50, 75));
CustomFontRenderer.drawString("Тест", this.width / 2 - 30, this.height / 2 - 41,
CustomFont.rexbold);
int buttonWidth = 100;
int buttonHeight = 20;
int buttonX = this.width / 2 - buttonWidth / 2;
int buttonY = this.height - buttonHeight - 10;
GuiButton backButton = new GuiButton(0, buttonX, buttonY, buttonWidth, buttonHeight, "Назад");
this.buttonList.add(backButton);
super.drawScreen(x, y, part);
}
@Override
protected void actionPerformed(GuiButton button) {
if (button.id == 0) {
this.mc.displayGuiScreen(this.parentScreen);
}
}
}
А вот код основной GUI дуэлей
Java:
public class DuelGui extends CustomGuiScreen {
public static boolean enemyReady;
public static String enemyName = "";
public ResetButton buttonReady;
public ArrayList<ItemStack> enemyItems = new ArrayList<ItemStack>();
public DuelGui(String enemyName, ArrayList<ItemStack> stacks) {
this.enemyName = enemyName;
this.enemyItems = stacks;
}
@Override
public void initGui() {
this.buttonList.clear();
this.buttonList.add(this.buttonReady = new ResetButton(this.width / 2 - 31, this.height / 2 + 155, 65, 20, "Согласиться"));
ArrayList<ItemStack> stacks = new ArrayList<ItemStack>();
stacks.addAll(Arrays.asList(this.mc.thePlayer.inventory.armorInventory));
stacks.addAll(Arrays.asList(this.mc.thePlayer.inventory.mainInventory));
{
int i = 0;
for (ItemStack s : this.enemyItems) {
if (s != null) {
this.buttonList.add(new OtherItemButton(this.width / 2 + 15 + ((i % 7) * 23),
this.height / 2 - 90 + ((i / 7) * 23), 22, 20, s));
i++;
}
}
}
{
int i = 0;
for (ItemStack s : stacks) {
if (s != null) {
this.buttonList.add(new MyItemButton(this.width / 2 - 170 + ((i % 7) * 23),
this.height / 2 - 90 + ((i / 7) * 23), 22, 20, s));
i++;
}
}
}
{
this.buttonList.add(new GuiButton(1, this.width / 2 - 31, this.height / 2 + 130, 65, 20, "Информация"));
}
}
@Override
public void drawScreen(int x, int y, float part) {
Util.drawRect(0, 0, this.width, this.height, Util.color(50, 50, 50, 70));
float widthmenu = 190;
float heightmenu = 164;
// main
Util.drawGradientRect(this.width / 2 - widthmenu, this.height / 2 - heightmenu, this.width / 2 + widthmenu,
this.height / 2 + heightmenu + 15, Util.color(0, 0, 50, 75), Util.color(0, 0, 50, 75));
// left title
Util.drawGradientRect(this.width / 2 - widthmenu + 12, this.height / 2 - heightmenu + 32, this.width / 2 - 4,
this.height / 2 - heightmenu + 60, Util.color(0, 191, 255, 55), Util.color(0, 191, 255, 125));;
// right title
Util.drawGradientRect(this.width / 2 + 4, this.height / 2 - heightmenu + 32, this.width / 2 + widthmenu - 8,
this.height / 2 - heightmenu + 60, Util.color(0, 191, 255, 125), Util.color(0, 191, 255, 55));;
// left down
Util.drawGradientRect(this.width / 2 - widthmenu + 12, this.height / 2 - heightmenu + 67, this.width / 2 - 4,
this.height / 2 + heightmenu - 75, Util.color(0, 191, 255, 55), Util.color(0, 191, 255, 125));;
//line
Util.drawRect(this.width / 2 - widthmenu, this.height / 2 - heightmenu - -20, this.width / 2 + widthmenu,
this.height / 2 - heightmenu - -22, Util.color(255, 165, 0, 255));
//main text
CustomFontRenderer.drawString("DUEL OF THE FATES", this.width / 2 - 48, this.height / 2 - 159,
CustomFont.rexbold);
//right center text
CustomFont font = new CustomFont("hudbold", 18);
CustomFontRenderer.drawString("Статистика игрока: §e" + Minecraft.getMinecraft().getSession().getUsername(), this.width / 2 - -3, this.height / 2 - -95, font);
CustomFont font2 = new CustomFont("hudbold", 15);
CustomFontRenderer.drawString("§7Количество проведенных дуэлей: §d7", this.width / 2 - -3, this.height / 2 - -106,
font2);
CustomFontRenderer.drawString("§7Количество выйгранных дуэлей: §a9", this.width / 2 - -3, this.height / 2 - -116,
font2);
CustomFontRenderer.drawString("§7Количество проигранных дуэлей: §c4", this.width / 2 - -3, this.height / 2 - -126,
font2);
CustomFontRenderer.drawString("§7Общий KDR за все дуэли: §61.4", this.width / 2 - -3, this.height / 2 - -136,
font2);
//left center text
CustomFontRenderer.drawString("§fСтатистика игрока: §e" + Minecraft.getMinecraft().getSession().getUsername(),
this.width / 2 - 179, this.height / 2 - -95, font);
CustomFontRenderer.drawString("§7Количество проигранных дуэлей: §c4", this.width / 2 - 179, this.height / 2 - -126,
font2);
CustomFontRenderer.drawString("§7Количество выйгранных дуэлей: §a9", this.width / 2 - 179, this.height / 2 - -116,
font2);
CustomFontRenderer.drawString("§7Общий KDR за все дуэли: §61.4", this.width / 2 - 179, this.height / 2 - -136,
font2);
CustomFontRenderer.drawString("§7Количество проведенных дуэлей: §d13", this.width / 2 - 179, this.height / 2 - -106,
font2);
//NEDOline left center xD
//Util.drawGradientRect(this.width / 2 - (widthmenu*2) + 201, this.height / 2 - (heightmenu/2) + 179, this.width / 2 - widthmenu - -186,
// this.height / 2 + (heightmenu/2) - -17, Util.color(255, 165, 0, 255), Util.color(255, 165, 0, 255));
//NEDOline right center xD
// Util.drawGradientRect(this.width / 2 + 3, this.height / 2 - (heightmenu/2) + 179, this.width / 2 + (widthmenu*2) - 198,
// this.height / 2 + (heightmenu/2) - -17, Util.color(255, 165, 0, 255), Util.color(255, 165, 0, 255));
// right down
Util.drawGradientRect(this.width / 2 + 4, this.height / 2 - heightmenu + 67, this.width / 2 + widthmenu - 8,
this.height / 2 + heightmenu - 75, Util.color(0, 191, 255, 125), Util.color(0, 191, 255, 55));
{
String display = Minecraft.getMinecraft().thePlayer.getCommandSenderName();
String ready = "";
if (!this.buttonReady.enabled) {
ready = "Согласен";
} else {
ready = "Не согласен";
}
CustomFont font12 = new CustomFont("Rex-Bold", 20);
CustomFontRenderer.drawString(display,
this.width / 2 + 6 - widthmenu / 2 - CustomFontRenderer.getStringWidth(font12, display) / 2,
this.height / 2 - 128, font12);
CustomFont font3 = new CustomFont("Rex-Bold", 17);
CustomFontRenderer.drawString(ready,
this.width / 2 + 6 - widthmenu / 2 - CustomFontRenderer.getStringWidth(font3, ready) / 2,
this.height / 2 - 118, font3);
}
{
String display = enemyName;
String ready = "";
if (enemyReady) {
ready = "Согласен";
} else {
ready = "Не согласен";
}
CustomFont font11 = new CustomFont("Rex-Bold", 20);
CustomFontRenderer.drawString(display,
this.width / 2 + 6 + widthmenu / 2 - CustomFontRenderer.getStringWidth(font11, display) / 2,
this.height / 2 - 128, font11);
CustomFont font3 = new CustomFont("Rex-Bold", 17);
CustomFontRenderer.drawString(ready,
this.width / 2 + 6 + widthmenu / 2 - CustomFontRenderer.getStringWidth(font3, ready) / 2,
this.height / 2 - 118, font3);
}
super.drawScreen(x, y, part);
for (GuiButton b : (ArrayList<GuiButton>) this.buttonList) {
if (b instanceof OtherItemButton) {
if (((OtherItemButton) b).outlined()) {
Util.drawToolTip(((OtherItemButton) b).stack, x, y);
}
}
if (b instanceof MyItemButton) {
if (((MyItemButton) b).outlined()) {
Util.drawToolTip(((MyItemButton) b).stack, x, y);
}
}
}
}
@Override
public void actionPerformed(GuiButton button) {
if (button.id == 1) {
this.mc.displayGuiScreen(new ButtonInfo(this));
}
}
@Override
public void onGuiClosed() {
Duels.network.sendToServer(Duels.network.createPacket(1, 0));
}
static {
enemyName = "";
}
}