width / 2 - withButton / 2
эта кнопка будет в центре.package net.Hells.MM.guis;
import org.lwjgl.opengl.GL11;
import net.Hells.MM.MM;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiLabel;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.ResourceLocation;
public class GUITAOAMM extends GuiMainMenu
{
private int MX = 0;
private int MY = 0;
private static final ResourceLocation back = new ResourceLocation(MM.MODID + ":textures/gui/backscreen.jpg");
private ResourceLocation field_110351_G;
@Override
public void initGui()
{
int i = this.width / 2 - 208;
this.buttonList.clear();
this.buttonList.add(new GuiButton(1, this.width / 2 - 100, this.height / 4 + 88, I18n.format("menu.singleplayer", new Object[0])));
}
@Override
public void drawScreen(int x, int y, float t)
{
ScaledResolution sc = new ScaledResolution(mc, this.width, this.height);
this.MX = sc.getScaledWidth();
this.MY = sc.getScaledHeight();
super.mc.renderEngine.bindTexture(back);
this.drawCompleteImage(0, 0, this.width, this.height);
int k1;
for (k1 = 0; k1 < this.buttonList.size(); ++k1)
((GuiButton)this.buttonList.get(k1)).drawButton(this.mc, x, y);
for (k1 = 0; k1 < this.labelList.size(); ++k1)
((GuiLabel)this.labelList.get(k1)).func_146159_a(this.mc, x, y);
}
private void drawCompleteImage(int posX, int posY, int width, int height) {
GL11.glPushMatrix();
GL11.glTranslatef((float)posX, (float)posY, 0.0F);
GL11.glBegin(7);
GL11.glTexCoord2f(0.0F, 0.0F);
GL11.glVertex3f(0.0F, 0.0F, 0.0F);
GL11.glTexCoord2f(0.0F, 1.0F);
GL11.glVertex3f(0.0F, (float)height, 0.0F);
GL11.glTexCoord2f(1.0F, 1.0F);
GL11.glVertex3f((float)width, (float)height, 0.0F);
GL11.glTexCoord2f(1.0F, 0.0F);
GL11.glVertex3f((float)width, 0.0F, 0.0F);
GL11.glEnd();
GL11.glPopMatrix();
}
}
initGui вызывается каждый раз когда изменяется окно.Но может надо заново давать расположение кнопок после изменений окна
По ширине.Хз, вроде все правильно. Куда оно у тебя съезжает? По высоте?
Ну когда я ковырял, у меня получилось что-то типа такого и оно нормально отображается, не съезжает.Та Агравайн, ковырялся, а толку?)
public void initGui()
{
this.viewportTexture = new DynamicTexture(256, 256);
this.field_110351_G = this.mc.getTextureManager().getDynamicTextureLocation("background", this.viewportTexture);
boolean flag = true;
int i = this.height / 4 + 48;
if (this.mc.isSingleplayer())
{
this.addSingleplayerMultiplayerButtons(i, 24);
}
else
{
this.addSingleplayerMultiplayerButtons(i, 24);
}
this.buttonList.add(new EgorkaButton(0, this.width / 2 - 100, i + 98 + 12, 98, 20, I18n.format("menu.options", new Object[0])));
this.buttonList.add(new EgorkaButton(4, this.width / 2 + 2, i + 98 + 12, 98, 20, I18n.format("menu.quit", new Object[0])));
Object object = this.field_104025_t;
synchronized (this.field_104025_t)
{
this.field_92023_s = this.fontRendererObj.getStringWidth(this.field_92025_p);
this.field_92024_r = this.fontRendererObj.getStringWidth(this.field_146972_A);
int j = Math.max(this.field_92023_s, this.field_92024_r);
this.field_92022_t = (this.width - j) / 2;
this.field_92021_u = ((GuiButton)this.buttonList.get(0)).yPosition - 24;
this.field_92020_v = this.field_92022_t + j;
this.field_92019_w = this.field_92021_u + 24;
}
}