Skip to content

Instantly share code, notes, and snippets.

@sirsavary
Created February 1, 2015 22:36
Show Gist options
  • Select an option

  • Save sirsavary/e8665943bdd55d8f2a70 to your computer and use it in GitHub Desktop.

Select an option

Save sirsavary/e8665943bdd55d8f2a70 to your computer and use it in GitHub Desktop.
package com.mordrum.mcore.client.gui;
import com.google.common.base.Optional;
import com.google.common.eventbus.Subscribe;
import cpw.mods.fml.client.FMLClientHandler;
import net.malisis.core.client.gui.Anchor;
import net.malisis.core.client.gui.GuiTexture;
import net.malisis.core.client.gui.MalisisGui;
import net.malisis.core.client.gui.component.UIComponent;
import net.malisis.core.client.gui.component.container.UIBackgroundContainer;
import net.malisis.core.client.gui.component.control.UIMoveHandle;
import net.malisis.core.client.gui.component.decoration.UIImage;
import net.malisis.core.client.gui.component.decoration.UILabel;
import net.malisis.core.client.gui.component.interaction.UIButton;
import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.util.ResourceLocation;
import java.awt.*;
/**
* Created by Jesse on 1/31/2015.
*/
public class SomeGUI extends MalisisGui {
protected final Optional<MalisisGui> parent;
protected static final ResourceLocation ALMURA_LOGO_LOCATION = new ResourceLocation("mcore", "textures/gui/mordrum.png");
public SomeGUI(MalisisGui parent) {
this.parent = Optional.fromNullable(parent);
setup();
}
protected void setup() {
UIBackgroundContainer window = new UIBackgroundContainer(this);
window.setSize(200, 225);
window.setAnchor(Anchor.CENTER | Anchor.MIDDLE);
window.setColor(Integer.MIN_VALUE);
window.setBackgroundAlpha(0);
UILabel titleLabel = new UILabel(this, ChatColor.WHITE + "Welcome To Mordrum NXT");
titleLabel.setPosition(0, 5, Anchor.CENTER | Anchor.TOP);
UIBackgroundContainer uiTitleBar = new UIBackgroundContainer(this);
uiTitleBar.setSize(300, 1);
uiTitleBar.setPosition(0, 17, Anchor.CENTER | Anchor.TOP);
uiTitleBar.setColor(Color.gray.getRGB());
UIImage logoImage = new UIImage(this, new GuiTexture(ALMURA_LOGO_LOCATION), null);
logoImage.setAnchor(Anchor.CENTER | Anchor.TOP);
logoImage.setPosition(0, this.getPaddedY(titleLabel, 12));
logoImage.setSize(64, 64);
UIButton multiplayerButton = new UIButton(this, ChatColor.AQUA + "Connect to Mordrum");
multiplayerButton.setSize(180, 16);
multiplayerButton.setPosition(0, this.getPaddedY(logoImage, 12), Anchor.CENTER | Anchor.TOP);
multiplayerButton.setName("button.multiplayer");
multiplayerButton.register(this);
UIButton optionsButton = new UIButton(this, "Options");
optionsButton.setSize(50, 16);
optionsButton.setPosition(10, this.getPaddedY(multiplayerButton, 4), Anchor.LEFT | Anchor.TOP);
optionsButton.setName("button.options");
optionsButton.register(this);
UIButton configurationButton = new UIButton(this, "Configuration");
configurationButton.setSize(76, 16);
configurationButton.setPosition(0, this.getPaddedY(multiplayerButton, 4), Anchor.CENTER | Anchor.TOP);
configurationButton.setName("button.configuration");
configurationButton.register(this);
UIButton aboutButton = new UIButton(this, "About");
aboutButton.setSize(50, 16);
aboutButton.setPosition(-10, this.getPaddedY(multiplayerButton, 4), Anchor.RIGHT | Anchor.TOP);
aboutButton.setName("button.about");
aboutButton.register(this);
UIButton quitButton = new UIButton(this, "Quit");
quitButton.setSize(50, 16);
quitButton.setPosition(0, this.getPaddedY(configurationButton, 14), Anchor.CENTER | Anchor.TOP);
quitButton.setName("button.quit");
quitButton.register(this);
UILabel copyrightLabel = new UILabel(this, ChatColor.GRAY + "Copyright Mordrum 2011 - 2015");
copyrightLabel.setPosition(0, -9, Anchor.CENTER | Anchor.BOTTOM);
copyrightLabel.setFontScale(0.7f);
UILabel trademarkLabel = new UILabel(this, ChatColor.GRAY + "Minecraft is a registered trademark of Mojang AB");
trademarkLabel.setPosition(0, -1, Anchor.CENTER | Anchor.BOTTOM);
trademarkLabel.setFontScale(0.7f);
window.add(titleLabel, uiTitleBar, logoImage, multiplayerButton, optionsButton, configurationButton, aboutButton, quitButton, copyrightLabel, trademarkLabel);
new UIMoveHandle(this, window);
this.addToScreen(window);
}
protected int getPaddedY(UIComponent component, int padding) {
if (component == null) {
return 0;
}
return component.getY() + component.getHeight() + padding;
}
@Subscribe
public void onButtonClick(UIButton.ClickEvent event) {
String buttonID = event.getComponent().getName().toLowerCase();
if (buttonID.equalsIgnoreCase("button.multiplayer")) {
FMLClientHandler.instance().setupServerList();
ServerData data = new ServerData("Mordrum", "play.mordrum.com");
FMLClientHandler.instance().connectToServer(this, data);
} else if (buttonID.equalsIgnoreCase("button.quit")) {
System.exit(0);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment