Compare commits

..

No commits in common. "master" and "splitsvr" have entirely different histories.

3682 changed files with 148374 additions and 153915 deletions

12
.gitattributes vendored
View file

@ -1,12 +0,0 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# Linux start script should use lf
/gradlew text eol=lf
# These are Windows script files and should use crlf
*.bat text eol=crlf
# Binary files should be left untouched
*.jar binary

16
.gitignore vendored
View file

@ -1,8 +1,8 @@
/dev
.metadata
.classpath
.project
.settings
.gradle
bin
build
/common/dev
/common/bin
/client/bin
/client/run
/server/bin
/server/run
/export
/.metadata

View file

@ -1,8 +1,3 @@
# TCR - That Cube Rocks
# TCR
Ein Block-basiertes Open-World-Spiel mit vielen Dimensionen und RPG-Elementen.
**Projekt ist in der frühen Entwicklungsphase / Alpha**
Dieses Projekt ist Public Domain, siehe UNLICENSE.
Der Client verwendet LWJGL für GLFW und OpenGL, für dessen Lizenz siehe [Die LWJGL Website](https://www.lwjgl.org/license).
Ein Minecraft®™ 1.8.9 "Fork"

View file

@ -1,47 +0,0 @@
plugins {
application
id("com.gradleup.shadow") version "8.3.6"
}
repositories {
mavenCentral()
}
dependencies {
implementation(project(":common"))
implementation(platform("org.lwjgl:lwjgl-bom:3.3.6"))
implementation("org.lwjgl", "lwjgl")
implementation("org.lwjgl", "lwjgl-glfw")
implementation("org.lwjgl", "lwjgl-opengl")
runtimeOnly("org.lwjgl", "lwjgl", classifier = "natives-linux")
runtimeOnly("org.lwjgl", "lwjgl", classifier = "natives-freebsd")
runtimeOnly("org.lwjgl", "lwjgl", classifier = "natives-windows")
runtimeOnly("org.lwjgl", "lwjgl-glfw", classifier = "natives-linux")
runtimeOnly("org.lwjgl", "lwjgl-glfw", classifier = "natives-freebsd")
runtimeOnly("org.lwjgl", "lwjgl-glfw", classifier = "natives-windows")
runtimeOnly("org.lwjgl", "lwjgl-opengl", classifier = "natives-linux")
runtimeOnly("org.lwjgl", "lwjgl-opengl", classifier = "natives-freebsd")
runtimeOnly("org.lwjgl", "lwjgl-opengl", classifier = "natives-windows")
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
application {
mainClass = "client.Client"
tasks.run.get().workingDir = rootProject.file("dev/client")
tasks.run.get().workingDir.mkdirs()
tasks.run.get().systemProperties.put("runtime.devmode", "")
}
tasks.shadowJar {
destinationDirectory = rootProject.file("dev")
archiveFileName = "tcr_client.jar"
}

3362
client/src/client/Game.java Executable file

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,4 @@
package client.util;
package client;
import common.util.Util;

View file

@ -0,0 +1,603 @@
package client;
import client.network.ClientPlayer;
import common.block.Block;
import common.entity.Entity;
import common.entity.npc.EntityNPC;
import common.init.BlockRegistry;
import common.init.EntityRegistry;
import common.item.ItemBlock;
import common.item.ItemControl;
import common.item.ItemStack;
import common.material.Material;
import common.packet.CPacketAction;
import common.packet.CPacketBreak;
import common.packet.CPacketClick;
import common.packet.CPacketPlace;
import common.sound.PositionedSound;
import common.world.BlockPos;
import common.world.Facing;
import common.world.State;
import common.world.Vec3;
import common.world.World;
import common.world.WorldClient;
public class PlayerController
{
private final Game gm;
private final ClientPlayer netClientHandler;
private BlockPos currentBlock = new BlockPos(-1, -1, -1);
private ItemStack currentItemHittingBlock;
private float curBlockDamageMP;
private float stepSoundTickCounter;
private int blockHitDelay;
private boolean isHittingBlock;
private boolean noclip;
private int currentPlayerItem;
private boolean interacting;
public PlayerController(Game gmIn, ClientPlayer netHandler)
{
this.gm = gmIn;
this.netClientHandler = netHandler;
}
// public static void clickBlockCreative(Game gmIn, PlayerController playerController, BlockPos pos, Facing facing)
// {
// if (!gmIn.theWorld.extinguishFire(gmIn.thePlayer, pos, facing))
// {
// playerController.onPlayerDestroyBlock(pos, facing);
// }
// }
// public void setPlayerCapabilities()
// {
// this.gm.thePlayer.flying &= this.gm.thePlayer.hasEffect(Potion.flying) || this.gm.thePlayer.noclip;
// }
// public boolean isNoclip()
// {
// return this.gm.thePlayer.capabilities.noClip;
// }
// public void setNoclip(boolean noclip)
// {
// this.noclip = noclip;
// }
// public void setCheat(boolean cheat)
// {
// this.cheat = cheat;
// this.setPlayerCapabilities();
// }
// public boolean shouldDrawHUD()
// {
// return !this.creative;
// }
/**
* Called when a player completes the destruction of a block
*/
public boolean onPlayerDestroyBlock(BlockPos pos, Facing side)
{
// if (this.gamemode.isAdventure())
// {
// if (this.gamemode == Gamemode.SPECTATOR)
// {
// return false;
// }
// if (!this.gm.thePlayer.isAllowEdit())
// {
// Block block = this.gm.theWorld.getBlockState(pos).getBlock();
// ItemStack itemstack = this.gm.thePlayer.getCurrentEquippedItem();
//
// if (itemstack == null)
// {
// return false;
// }
//
// if (!itemstack.canDestroy(block))
// {
// return false;
// }
// }
// }
// if (this.gm.thePlayer.getHeldItem() != null && !this.gm.thePlayer.getHeldItem().getItem().canBreakBlocks())
// {
// return false;
// }
// else
// {
World world = this.gm.theWorld;
State iblockstate = world.getState(pos);
Block block1 = iblockstate.getBlock();
if (block1.getMaterial() == Material.air)
{
return false;
}
else
{
world.playAuxSFX(2001, pos, BlockRegistry.getStateId(iblockstate));
boolean flag = world.setBlockToAir(pos);
if (flag)
{
block1.onBlockDestroyedByPlayer(world, pos, iblockstate);
}
this.currentBlock = new BlockPos(this.currentBlock.getX(), -1, this.currentBlock.getZ());
// if (!this.creative)
// {
ItemStack itemstack1 = this.gm.thePlayer.getCurrentEquippedItem();
if (itemstack1 != null)
{
itemstack1.onBlockDestroyed(world, block1, pos, this.gm.thePlayer);
if (itemstack1.stackSize == 0)
{
this.gm.thePlayer.destroyCurrentEquippedItem();
}
}
// }
return flag;
}
// }
}
/**
* Called when the player is hitting a block with an item.
*/
public boolean clickBlock(BlockPos loc, Facing face)
{
// if (this.gamemode.isAdventure())
// {
// if (this.gamemode == Gamemode.SPECTATOR)
// {
// return false;
// }
// if (!this.gm.thePlayer.isAllowEdit())
// {
// Block block = this.gm.theWorld.getBlockState(loc).getBlock();
// ItemStack itemstack = this.gm.thePlayer.getCurrentEquippedItem();
//
// if (itemstack == null)
// {
// return false;
// }
//
// if (!itemstack.canDestroy(block))
// {
// return false;
// }
// }
// }
if (!World.isValidXZ(loc))
{
return false;
}
else
{
ItemStack stack = this.gm.thePlayer.getHeldItem();
if(stack != null && stack.getItem().onAction(stack, this.gm.thePlayer, this.gm.theWorld, ItemControl.PRIMARY, loc)) {
this.interacting = true;
this.netClientHandler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.START_DESTROY_BLOCK, loc, face));
return true;
}
// if (this.creative)
// {
// this.netClientHandler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.START_DESTROY_BLOCK, loc, face));
// clickBlockCreative(this.gm, this, loc, face);
// this.blockHitDelay = 5;
// }
// else
if (!this.isHittingBlock || !this.isHittingPosition(loc))
{
if (this.isHittingBlock)
{
this.netClientHandler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.ABORT_DESTROY_BLOCK, this.currentBlock, face));
}
this.netClientHandler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.START_DESTROY_BLOCK, loc, face));
Block block1 = this.gm.theWorld.getState(loc).getBlock();
boolean flag = block1.getMaterial() != Material.air;
if (flag && this.curBlockDamageMP == 0.0F)
{
block1.onBlockClicked(this.gm.theWorld, loc, this.gm.thePlayer);
}
if (flag && block1.getPlayerRelativeBlockHardness(this.gm.thePlayer, this.gm.thePlayer.worldObj, loc) >= 1.0F)
{
this.onPlayerDestroyBlock(loc, face);
// if(this.cheat && block1.getPlayerRelativeBlockHardness(this.gm.thePlayer, this.gm.thePlayer.worldObj, loc) < 1.0F)
this.blockHitDelay = 3;
}
else
{
this.isHittingBlock = true;
this.currentBlock = loc;
this.currentItemHittingBlock = this.gm.thePlayer.getHeldItem();
this.curBlockDamageMP = 0.0F;
this.stepSoundTickCounter = 0.0F;
this.gm.theWorld.sendBlockBreakProgress(this.gm.thePlayer.getId(), this.currentBlock, (int)(this.curBlockDamageMP * 10.0F) - 1);
}
}
return true;
}
}
/**
* Resets current block damage and isHittingBlock
*/
public void resetBlockRemoving()
{
if (this.isHittingBlock)
{
this.netClientHandler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.ABORT_DESTROY_BLOCK, this.currentBlock, Facing.DOWN));
this.isHittingBlock = false;
this.curBlockDamageMP = 0.0F;
this.gm.theWorld.sendBlockBreakProgress(this.gm.thePlayer.getId(), this.currentBlock, -1);
}
}
public void resetInteraction()
{
this.interacting = false;
}
public boolean onPlayerDamageBlock(BlockPos posBlock, Facing directionFacing)
{
if(this.interacting)
return false;
this.syncCurrentPlayItem();
if (this.blockHitDelay > 0)
{
--this.blockHitDelay;
return true;
}
// else if (this.creative && World.isValidXZ(posBlock))
// {
// this.blockHitDelay = 5;
// this.netClientHandler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.START_DESTROY_BLOCK, posBlock, directionFacing));
// clickBlockCreative(this.gm, this, posBlock, directionFacing);
// return true;
// }
else if (this.isHittingPosition(posBlock))
{
Block block = this.gm.theWorld.getState(posBlock).getBlock();
if (block.getMaterial() == Material.air)
{
this.isHittingBlock = false;
return false;
}
else
{
this.curBlockDamageMP += block.getPlayerRelativeBlockHardness(this.gm.thePlayer, this.gm.thePlayer.worldObj, posBlock);
if (this.stepSoundTickCounter % 4.0F == 0.0F && block.sound.getStepSound() != null)
{
this.gm.getSoundManager().playSound(new PositionedSound(block.sound.getStepSound(), 0.25F, /* block.sound.getFrequency() * 0.5F, */ (float)posBlock.getX() + 0.5F, (float)posBlock.getY() + 0.5F, (float)posBlock.getZ() + 0.5F));
}
++this.stepSoundTickCounter;
if (this.curBlockDamageMP >= 1.0F)
{
this.isHittingBlock = false;
this.netClientHandler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.STOP_DESTROY_BLOCK, posBlock, directionFacing));
this.onPlayerDestroyBlock(posBlock, directionFacing);
this.curBlockDamageMP = 0.0F;
this.stepSoundTickCounter = 0.0F;
this.blockHitDelay = 5;
}
this.gm.theWorld.sendBlockBreakProgress(this.gm.thePlayer.getId(), this.currentBlock, (int)(this.curBlockDamageMP * 10.0F) - 1);
return true;
}
}
else
{
return this.clickBlock(posBlock, directionFacing);
}
}
// /**
// * player reach distance = 4F
// */
// public float getBlockReachDistance()
// {
// return ;
// }
public void updateController()
{
this.syncCurrentPlayItem();
if (this.netClientHandler.getNetworkManager().isChannelOpen())
{
this.netClientHandler.getNetworkManager().processReceivedPackets();
}
else
{
this.netClientHandler.getNetworkManager().checkDisconnected();
}
}
private boolean isHittingPosition(BlockPos pos)
{
ItemStack itemstack = this.gm.thePlayer.getHeldItem();
boolean flag = this.currentItemHittingBlock == null && itemstack == null;
if (this.currentItemHittingBlock != null && itemstack != null)
{
flag = itemstack.getItem() == this.currentItemHittingBlock.getItem() && ItemStack.areItemStackTagsEqual(itemstack, this.currentItemHittingBlock) && (itemstack.isItemStackDamageable() || itemstack.getMetadata() == this.currentItemHittingBlock.getMetadata());
}
return pos.equals(this.currentBlock) && flag;
}
/**
* Syncs the current player item with the server
*/
private void syncCurrentPlayItem()
{
int i = this.gm.thePlayer.inventory.currentItem;
if (i != this.currentPlayerItem)
{
this.currentPlayerItem = i;
this.netClientHandler.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_ITEMSLOT, this.currentPlayerItem));
}
}
public boolean onPlayerRightClick(EntityNPC player, WorldClient worldIn, ItemStack heldStack, BlockPos hitPos, Facing side, Vec3 hitVec)
{
this.syncCurrentPlayItem();
float f = (float)(hitVec.xCoord - (double)hitPos.getX());
float f1 = (float)(hitVec.yCoord - (double)hitPos.getY());
float f2 = (float)(hitVec.zCoord - (double)hitPos.getZ());
boolean flag = false;
if (!World.isValidXZ(hitPos))
{
return false;
}
else
{
if(heldStack == null || !heldStack.getItem().onAction(heldStack, player, worldIn, ItemControl.SECONDARY, hitPos)) {
// if (this.gamemode != Gamemode.SPECTATOR)
// {
State iblockstate = worldIn.getState(hitPos);
if ((!player.isSneaking() || player.getHeldItem() == null) // && (player.getHeldItem() == null || !player.getHeldItem().getItem().ignoresBlocks())
&& iblockstate.getBlock().onBlockActivated(worldIn, hitPos, iblockstate, player, side, f, f1, f2))
{
flag = true;
}
if (!flag && heldStack != null && heldStack.getItem() instanceof ItemBlock)
{
ItemBlock itemblock = (ItemBlock)heldStack.getItem();
if (!itemblock.canPlaceBlockOnSide(worldIn, hitPos, side, player, heldStack))
{
return false;
}
}
// }
}
else {
heldStack.getItem().onItemUse(heldStack, player, worldIn, hitPos, side, f, f1, f2);
flag = true;
}
this.netClientHandler.addToSendQueue(new CPacketPlace(hitPos, side.getIndex(), player.inventory.getCurrentItem(), f, f1, f2));
if (!flag) // && this.gamemode != Gamemode.SPECTATOR)
{
if (heldStack == null)
{
return false;
}
// else if (this.creative)
// {
// int i = heldStack.getMetadata();
// int j = heldStack.stackSize;
// boolean flag1 = heldStack.onItemUse(player, worldIn, hitPos, side, f, f1, f2);
// heldStack.setItemDamage(i);
// heldStack.stackSize = j;
// return flag1;
// }
else
{
return heldStack.onItemUse(player, worldIn, hitPos, side, f, f1, f2);
}
}
else
{
return true;
}
}
}
/**
* Notifies the server of things like consuming food, etc...
*/
public boolean sendUseItem(EntityNPC playerIn, World worldIn, ItemStack itemStackIn)
{
// if (this.gamemode == Gamemode.SPECTATOR)
// {
// return false;
// }
// else
// {
this.syncCurrentPlayItem();
this.netClientHandler.addToSendQueue(new CPacketPlace(playerIn.inventory.getCurrentItem()));
int i = itemStackIn.stackSize;
ItemStack itemstack = itemStackIn.useItemRightClick(worldIn, playerIn);
if (itemstack != itemStackIn || itemstack != null && itemstack.stackSize != i)
{
playerIn.inventory.mainInventory[playerIn.inventory.currentItem] = itemstack;
if (itemstack.stackSize == 0)
{
playerIn.inventory.mainInventory[playerIn.inventory.currentItem] = null;
}
return true;
}
else
{
return false;
}
// }
}
public EntityNPC createPlayerEntity(WorldClient worldIn, int type)
{
EntityNPC player = (EntityNPC)EntityRegistry.createEntityByID(type, worldIn);
player.setClientPlayer(this.gm, this.netClientHandler);
return player;
}
/**
* Attacks an entity
*/
public void attackEntity(EntityNPC playerIn, Entity targetEntity)
{
this.syncCurrentPlayItem();
this.netClientHandler.addToSendQueue(new CPacketAction(CPacketAction.Action.ATTACK, targetEntity.getId()));
// if (this.gamemode != Gamemode.SPECTATOR)
// {
playerIn.attackTargetEntityWithCurrentItem(targetEntity);
// }
}
/**
* Send packet to server - player is interacting with another entity (left click)
*/
public boolean interactWithEntitySendPacket(EntityNPC playerIn, Entity targetEntity)
{
this.syncCurrentPlayItem();
this.netClientHandler.addToSendQueue(new CPacketAction(CPacketAction.Action.INTERACT, targetEntity.getId()));
return /* this.gamemode != Gamemode.SPECTATOR && */ playerIn.interactWith(targetEntity);
}
// /**
// * Return true when the player rightclick on an entity
// *
// * @param player The player's instance
// * @param entityIn The entity clicked
// * @param movingObject The object clicked
// */
// public boolean isPlayerRightClickingOnEntity(EntityNPC player, Entity entityIn, MovingObjectPosition movingObject)
// {
// this.syncCurrentPlayItem();
// Vec3 vec3 = new Vec3(movingObject.hitVec.xCoord - entityIn.posX, movingObject.hitVec.yCoord - entityIn.posY, movingObject.hitVec.zCoord - entityIn.posZ);
// this.netClientHandler.addToSendQueue(new C02PacketUseEntity(entityIn, vec3));
// return this.gamemode != Gamemode.SPECTATOR && entityIn.interactAt(player, vec3);
// }
/**
* Handles slot clicks sends a packet to the server.
*/
public ItemStack windowClick(int windowId, int slotId, int mouseButtonClicked, int mode, EntityNPC playerIn)
{
short short1 = playerIn.openContainer.getNextTransactionID(playerIn.inventory);
ItemStack itemstack = playerIn.openContainer.slotClick(slotId, mouseButtonClicked, mode, playerIn);
this.netClientHandler.addToSendQueue(new CPacketClick(windowId, slotId, mouseButtonClicked, mode, itemstack, short1));
return itemstack;
}
/**
* GuiEnchantment uses this during multiplayer to tell PlayerControllerMP to send a packet indicating the
* enchantment action the player has taken.
*
* @param windowID The ID of the current window
* @param button The button id (enchantment selected)
*/
public void sendEnchantPacket(int windowID, int button)
{
this.netClientHandler.addToSendQueue(new CPacketAction(CPacketAction.Action.ENCHANT_ITEM, windowID | (button << 8)));
}
// /**
// * Used in PlayerControllerMP to update the server with an ItemStack in a slot.
// */
// public void sendCheatPacket(ItemStack itemStackIn, boolean full)
// {
// }
// /**
// * Sends a Packet107 to the server to drop the item on the ground
// */
// public void sendPacketDropItem(ItemStack itemStackIn)
// {
// if (this.creative && itemStackIn != null)
// {
// this.netClientHandler.addToSendQueue(new CPacketCreative(-1, itemStackIn));
// }
// }
public void onStoppedUsingItem(EntityNPC playerIn)
{
this.syncCurrentPlayItem();
this.netClientHandler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.RELEASE_USE_ITEM, BlockPos.ORIGIN, Facing.DOWN));
playerIn.stopUsingItem();
}
// /**
// * Checks if the player is not creative, used for checking if it should break a block instantly
// */
// public boolean isNotCreative()
// {
// return !this.creative;
// }
// /**
// * returns true if player is in creative mode
// */
// public boolean isCreative()
// {
// return this.creative;
// }
// /**
// * Checks if the player is riding a horse, used to chose the GUI to open
// */
// public boolean isRidingHorse()
// {
// return ;
// }
// public Gamemode getGamemode()
// {
// return this.gamemode;
// }
/**
* Return isHittingBlock
*/
public boolean getIsHittingBlock()
{
return this.isHittingBlock;
}
}

View file

@ -1,4 +1,4 @@
package client.util;
package client;
import java.awt.Color;
import java.awt.Graphics;
@ -171,20 +171,20 @@ public abstract class SkinConverter {
img = ImageIO.read(source);
}
catch(IOException e) {
Log.IO.error(e, "Konnte kein Bild von " + source + " laden");
Log.JNI.error(e, "Konnte kein Bild von " + source + " laden");
return false;
}
if(img == null) {
Log.IO.warn("Konnte kein Bild von " + source + " laden");
Log.JNI.warn("Konnte kein Bild von " + source + " laden");
return false;
}
Log.IO.info("Bild von " + source + " geladen");
Log.JNI.info("Bild von " + source + " geladen");
if(img.getWidth() == 64 && img.getHeight() == 32) {
img = convertSkin(img);
Log.IO.info("Skin " + source + " konvertiert");
Log.JNI.info("Skin " + source + " konvertiert");
}
else if(img.getWidth() != 64 || img.getHeight() != 64) {
Log.IO.warn("Falsche Bildgröße von " + source + ": " + img.getWidth() + "x" + img.getHeight());
Log.JNI.warn("Falsche Bildgröße von " + source + ": " + img.getWidth() + "x" + img.getHeight());
return false;
}
String name = source.getName();
@ -195,7 +195,7 @@ public abstract class SkinConverter {
name = "skin";
if(slim) {
img = convertSlim(img);
Log.IO.info("Skin " + source + " von 'Slim' konvertiert");
Log.JNI.info("Skin " + source + " von 'Slim' konvertiert");
if(!name.startsWith("slim_"))
name = "slim_" + name;
}
@ -217,10 +217,10 @@ public abstract class SkinConverter {
ImageIO.write(img, "png", file);
}
catch(Exception e) {
Log.IO.error(e, "Konnte Bild nicht speichern");
Log.JNI.error(e, "Konnte Bild nicht speichern");
return false;
}
Log.IO.info("Skin " + source + " gespeichert als " + file.getName());
Log.JNI.info("Skin " + source + " gespeichert als " + file.getName());
return true;
}

View file

@ -0,0 +1,30 @@
package client;
public class Timing {
public static long tmr_timer;
public static long tmr_start;
public static long tmr_current;
public static long tmr_last;
public static long tmr_delta;
public static long tmr_update;
public static long tmr_frames;
public static long tmr_iters;
public static long tick_torun;
public static long tick_done;
public static long tick_total;
public static long tick_time;
public static long tick_stime;
public static long tick_ftime;
public static long tick_ttime;
public static long tick_update;
public static double tick_fraction;
public static float framerate;
public static float tickrate;
public static float fdelta;
public static int tickTarget;
public static int tickFrame;
}

View file

@ -11,6 +11,7 @@ import javax.sound.sampled.DataLine.Info;
import common.collect.Lists;
import common.log.Log;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;
public class AudioInterface implements Runnable {
@ -137,12 +138,12 @@ public class AudioInterface implements Runnable {
public void run() {
AudioFormat format = new AudioFormat(Encoding.PCM_SIGNED, 48000, 16, 2, 2 * 2, 48000, false);
Info info = new Info(SourceDataLine.class, format, this.devbufsize == 0 ? AudioSystem.NOT_SPECIFIED : this.devbufsize);
Info info = new Info(SourceDataLine.class, format, this.devbufsize);
try {
this.line = (SourceDataLine)AudioSystem.getLine(info);
this.line.open(format, this.devbufsize == 0 ? AudioSystem.NOT_SPECIFIED : this.devbufsize);
this.line.open(format, this.devbufsize);
}
catch(Exception e) {
catch(LineUnavailableException e) {
this.line = null;
Log.SOUND.error(e, "Konnte Audiogerät nicht öffnen");
}

View file

@ -10,8 +10,7 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import client.Client;
import client.util.FileUtils;
import client.Game;
import common.collect.BiMap;
import common.collect.HashBiMap;
import common.collect.Lists;
@ -23,6 +22,7 @@ import common.rng.Random;
import common.sound.MovingSound;
import common.sound.Sound;
import common.util.ExtMath;
import common.util.FileUtils;
public class SoundManager {
private class Source {
@ -85,7 +85,7 @@ public class SoundManager {
private final Map<String, Integer> playingSoundsStopTime = Maps.<String, Integer>newHashMap();
private final Map<String, Source> sources = new HashMap<String, Source>();
private final String[] channels = new String[28];
private final Client gm;
private final Game gm;
private float listenerX;
private float listenerY;
@ -94,7 +94,7 @@ public class SoundManager {
private int playTime = 0;
private int eventId = 0;
public SoundManager(Client gm) {
public SoundManager(Game gm) {
this.gm = gm;
}
@ -238,8 +238,8 @@ public class SoundManager {
this.sources.put(s, new Source(getBuffer(sound.getSoundLocation()), Volume.getByType(sound.getChannelType()), sound.canRepeat(), s, sound.getXPosF(), sound.getYPosF(), sound.getZPosF(), sound.getAttenuationType(), attn, volume));
this.playingSoundsStopTime.put(s, this.playTime + 20);
this.playingSounds.put(s, sound);
if (sound instanceof MovingSound moving)
this.tickableSounds.add(moving);
if (sound instanceof MovingSound)
this.tickableSounds.add((MovingSound)sound);
}
}

View file

@ -1,12 +1,11 @@
package client.audio;
import client.Client;
import client.Game;
import client.gui.element.Slider;
import client.gui.element.SliderCallback;
import client.vars.CVar;
import client.vars.CVarCategory;
import common.color.TextColor;
import common.sound.EventType;
import common.util.Color;
public enum Volume implements CVar {
MASTER("master", "Gesamt"),
@ -52,7 +51,7 @@ public enum Volume implements CVar {
}
public String getType() {
return Color.DARK_GREEN + "volume";
return TextColor.DGREEN + "volume";
}
public CVarCategory getCategory() {
@ -92,12 +91,12 @@ public enum Volume implements CVar {
}
public void apply() {
if(Client.CLIENT.getAudioInterface() != null)
Client.CLIENT.getAudioInterface().alSetVolume(this, (short)(((float)this.value) / 100.0f * 32767.0f));
if(Game.getGame().getAudioInterface() != null)
Game.getGame().getAudioInterface().alSetVolume(this, (short)(((float)this.value) / 100.0f * 32767.0f));
}
public Slider selector(int x, int y, int w, int h) {
return new Slider(x, y, w, h, 0, 0, 100, 100, this.value, new SliderCallback() {
return new Slider(x, y, w, h, 0, 0, 100, 100, this.value, new Slider.Callback() {
public void use(Slider elem, int value) {
Volume.this.value = value;
Volume.this.apply();

View file

@ -0,0 +1,107 @@
package client.gui;
import java.awt.image.BufferedImage;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.lwjgl.opengl.GL11;
import client.renderer.GlState;
import client.renderer.texture.TextureUtil;
import common.log.Log;
import common.util.FileUtils;
public class Font {
public static final FontChar[] SIZES = new FontChar[256];
public static final int XGLYPH = 12;
public static final int YGLYPH = 18;
private static int texture;
public static void bindTexture() {
GlState.bindTexture(texture);
}
private static int stride(int width, int height, int x, int y, int c) {
return ((c & 15) * width + x) + (((c >> 4) & 15) * height + y) * (width << 4); // << 2;
}
private static byte specialChar(int width, int ch) {
return (byte)((ch == Log.CHR_UNK) ? width : ((ch == Log.CHR_SPC) ? (width / 6) : 127));
}
private static void calculate(int[] data, FontChar[] glyphs, int width, int height, int page) {
int off;
for(int z = 0; z < 256; z++) {
byte s, t, u, v;
if((u = specialChar(width, (page << 8) + z)) != 127) {
s = t = 0;
v = (byte)(((int)u) * height / width);
if(((page << 8) + z) != Log.CHR_UNK) {
for(int x = 0; x < width; x++) {
for(int y = 0; y < height; y++) {
off = stride(width, height, x, y, z);
data[off/*+3*/] = 0;
}
}
}
glyphs[z] = new FontChar(s, t, u, v);
continue;
}
s = t = 127;
u = v = 0;
for(int x = 0; x < width; x++) {
for(int y = 0; y < height; y++) {
off = stride(width, height, x, y, z);
if((data[off/*+3*/] & 0xff000000) != 0) {
s = x < s ? (byte)x : s;
t = y < t ? (byte)y : t;
u = x > u ? (byte)x : u;
v = y > v ? (byte)y : v;
}
}
}
if(s == 127 && t == 127 && u == 0 && v == 0) {
s = t = 0;
}
else {
u += 1;
v += 1;
}
glyphs[z] = new FontChar(s, t, u, v);
}
}
public static void load() {
BufferedImage img = null;
try {
img = TextureUtil.readImage(FileUtils.getResource("textures/font.png"));
}
catch(FileNotFoundException e) {
Log.IO.error("Konnte Font-Textur nicht laden: Datei nicht vorhanden");
}
catch(IOException e) {
Log.IO.error(e, "Konnte Font-Textur nicht laden");
}
if(img != null && (img.getWidth() != XGLYPH * 16 || img.getHeight() != YGLYPH * 16)) {
Log.IO.error("Konnte Font-Textur nicht laden: Größe ist nicht %dx%d", XGLYPH * 16, YGLYPH * 16);
img = null;
}
if(img == null)
throw new IllegalStateException("Konnte erforderliche Schriftart nicht laden");
int[] data = new int[XGLYPH * 16 * YGLYPH * 16];
img.getRGB(0, 0, XGLYPH * 16, YGLYPH * 16, data, 0, XGLYPH * 16);
calculate(data, SIZES, XGLYPH, YGLYPH, 0);
texture = GL11.glGenTextures();
TextureUtil.uploadImage(texture, img);
Log.RENDER.debug("Font-Textur wurde mit ID #%d geladen", texture);
}
public static void unload() {
if(texture != 0) {
GL11.glDeleteTextures(texture);
Log.RENDER.debug("Font-Textur mit ID #%d wurde gelöscht", texture);
texture = 0;
}
}
}

View file

@ -0,0 +1,329 @@
package client.gui;
import java.util.List;
import org.lwjgl.opengl.GL13;
import client.Game;
import client.gui.element.Dropdown;
import client.gui.element.Dropdown.Handle;
import client.gui.element.Element;
import client.renderer.Drawing;
import client.renderer.GlState;
import client.window.Bind;
import client.window.Button;
import client.window.Keysym;
import common.collect.Lists;
public abstract class Gui {
public static final String DIRT_BACKGROUND = "textures/background.png";
public static final int HOVER_COLOR = 0x288080ff;
public static final int PRESS_COLOR = 0x30afafff;
protected final Game gm = Game.getGame();
public Element selected;
private int min_x;
private int min_y;
private int max_x;
private int max_y;
public final List<Element> elems = Lists.newArrayList();
public abstract void init(int width, int height);
public abstract String getTitle();
public void updateScreen() {
}
public void onGuiClosed() {
}
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
}
public void mouseReleased(int mouseX, int mouseY, int state) {
}
public void mouseDragged(int mouseX, int mouseY) {
}
public void drawPost() {
}
// public void drawGuiContainerForegroundLayer() {
// }
//
// public void drawGuiContainerBackgroundLayer() {
// }
public void drawOverlays() {
}
public void useHotbar(int slot) {
}
public void dropItem() {
}
public void drawBackground() {
}
public Element clicked(int x, int y) {
if(this.selected != null && this.selected.visible && (this.selected instanceof Handle) && this.selected.inside(x, y))
return this.selected; // fix (?)
for(Element elem : this.elems) {
if(elem.visible && elem.enabled && elem.inside(x, y))
return elem;
}
return null;
}
public void reformat() {
for(Element elem : this.elems) {
elem.reformat();
}
}
public void deselect() {
if(this.selected != null && !(this.selected instanceof Handle)) {
this.selected.deselect();
this.selected = null;
}
}
public void select(Element elem) {
if(this.selected != elem && !(this.selected instanceof Handle) && !(elem instanceof Handle)) {
if(this.selected != null)
this.selected.deselect();
if(elem != null)
elem.select();
this.selected = elem;
}
}
public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift) {
int prev;
Element elem = this.clicked(x, y);
if(this.selected != null && this.selected != elem && this.selected instanceof Handle) {
this.selected.deselect();
return;
}
else if(this.selected != elem) {
if(this.selected != null)
this.selected.deselect();
if(elem != null)
elem.select();
this.selected = elem;
}
if(elem != null)
elem.mouse(btn, x, y, ctrl, shift);
}
public void mouserel(Button btn, int x, int y) {
if(this.selected != null)
this.selected.mouserel();
}
public void drag(int x, int y) {
if(this.selected != null && (Button.MOUSE_LEFT.isDown() || Button.MOUSE_RIGHT.isDown()))
this.selected.drag(x, y);
}
public void scroll(int scr_x, int scr_y, int x, int y, boolean ctrl, boolean shift) {
Element elem = this.clicked(x, y);
if(elem != null)
elem.scroll(scr_x, scr_y, x, y, ctrl, shift);
}
public void key(Keysym key, boolean ctrl, boolean shift) {
if(this.selected != null)
this.selected.key(key, ctrl, shift);
}
public void character(char code) {
if(this.selected != null)
this.selected.character(code);
}
protected void shift() {
if(this.gm.fb_x != 0 && this.gm.fb_y != 0) {
int shift_x = (this.gm.fb_x - (this.max_x - this.min_x)) / 2 - this.min_x;
int shift_y = (this.gm.fb_y - (this.max_y - this.min_y)) / 2 - this.min_y;
for(Element elem : this.elems) {
elem.shift(shift_x, shift_y);
}
}
}
public void init() {
this.selected = null;
this.min_x = this.min_y = Integer.MAX_VALUE;
this.max_x = this.max_y = Integer.MIN_VALUE;
this.elems.clear();
this.init(this.gm.fb_x, this.gm.fb_y);
}
public void update() {
if(this.selected != null)
this.selected.update();
}
protected <T extends Element> T add(T elem) {
this.elems.add(elem);
elem.setGui(this);
this.min_x = Math.min(this.min_x, elem.getX());
this.min_y = Math.min(this.min_y, elem.getY());
this.max_x = Math.max(this.max_x, elem.getX() + elem.getWidth());
this.max_y = Math.max(this.max_y, elem.getY() + elem.getHeight());
if(elem instanceof Dropdown)
this.add(((Dropdown)elem).getHandle());
return elem;
}
protected Element addSelector(String cvar, int x, int y, int w, int h) {
return this.add(this.gm.getVar(cvar).selector(x, y, w, h));
}
public void draw() {
if(this.selected != null && /* this.selected.r_dirty && */ this.selected instanceof Handle && !this.selected.visible) {
this.selected = null;
}
for(Element elem : this.elems) {
if(/* this.selected != e || */ !(elem instanceof Handle)) // || !e.visible)
elem.draw();
}
if(this.selected != null && /* elem.r_dirty && */ this.selected instanceof Handle && this.selected.visible) {
this.selected.draw();
}
}
public void drawOverlay() {
Element elem = this.selected;
if(Button.isMouseDown() && elem != null && elem.enabled && elem.visible && elem.canClick()) {
elem.drawPress();
return;
}
if(elem != null && elem.enabled && elem.visible)
elem.drawOverlay();
elem = this.clicked(this.gm.mouse_x, this.gm.mouse_y);
if(elem != null && elem.enabled && elem.visible && elem.canHover())
elem.drawHover();
}
// public static void drawRect(int left, int top, int right, int bottom, int color)
// {
// if (left < right)
// {
// int i = left;
// left = right;
// right = i;
// }
//
// if (top < bottom)
// {
// int j = top;
// top = bottom;
// bottom = j;
// }
//
// float f3 = (float)(color >> 24 & 255) / 255.0F;
// float f = (float)(color >> 16 & 255) / 255.0F;
// float f1 = (float)(color >> 8 & 255) / 255.0F;
// float f2 = (float)(color & 255) / 255.0F;
// RenderBuffer worldrenderer = Tessellator.getBuffer();
// GlState.enableBlend();
// GlState.disableTexture2D();
// GlState.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
// GlState.color(f, f1, f2, f3);
// worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION);
// worldrenderer.pos((double)left, (double)bottom, 0.0D).endVertex();
// worldrenderer.pos((double)right, (double)bottom, 0.0D).endVertex();
// worldrenderer.pos((double)right, (double)top, 0.0D).endVertex();
// worldrenderer.pos((double)left, (double)top, 0.0D).endVertex();
// Tessellator.draw();
// GlState.enableTexture2D();
// GlState.disableBlend();
// }
// public static void drawTexturedModalRect(int x, int y, int textureX, int textureY, int width, int height)
// {
// float f = 0.00390625F;
// float f1 = 0.00390625F;
// RenderBuffer worldrenderer = Tessellator.getBuffer();
// worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
// worldrenderer.pos((double)(x + 0), (double)(y + height), 0.0D).tex((double)((float)(textureX + 0) * f), (double)((float)(textureY + height) * f1)).endVertex();
// worldrenderer.pos((double)(x + width), (double)(y + height), 0.0D).tex((double)((float)(textureX + width) * f), (double)((float)(textureY + height) * f1)).endVertex();
// worldrenderer.pos((double)(x + width), (double)(y + 0), 0.0D).tex((double)((float)(textureX + width) * f), (double)((float)(textureY + 0) * f1)).endVertex();
// worldrenderer.pos((double)(x + 0), (double)(y + 0), 0.0D).tex((double)((float)(textureX + 0) * f), (double)((float)(textureY + 0) * f1)).endVertex();
// Tessellator.draw();
// }
//
// public static void drawScaledCustomSizeModalRect(int x, int y, float u, float v, int uWidth, int vHeight, int width, int height, float tileWidth, float tileHeight)
// {
// float f = 1.0F / tileWidth;
// float f1 = 1.0F / tileHeight;
// RenderBuffer worldrenderer = Tessellator.getBuffer();
// worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
// worldrenderer.pos((double)x, (double)(y + height), 0.0D).tex((double)(u * f), (double)((v + (float)vHeight) * f1)).endVertex();
// worldrenderer.pos((double)(x + width), (double)(y + height), 0.0D).tex((double)((u + (float)uWidth) * f), (double)((v + (float)vHeight) * f1)).endVertex();
// worldrenderer.pos((double)(x + width), (double)y, 0.0D).tex((double)((u + (float)uWidth) * f), (double)(v * f1)).endVertex();
// worldrenderer.pos((double)x, (double)y, 0.0D).tex((double)(u * f), (double)(v * f1)).endVertex();
// Tessellator.draw();
// }
//
// public static void drawGradientRect(int left, int top, int right, int bottom, int startColor, int endColor)
// {
// float f = (float)(startColor >> 24 & 255) / 255.0F;
// float f1 = (float)(startColor >> 16 & 255) / 255.0F;
// float f2 = (float)(startColor >> 8 & 255) / 255.0F;
// float f3 = (float)(startColor & 255) / 255.0F;
// float f4 = (float)(endColor >> 24 & 255) / 255.0F;
// float f5 = (float)(endColor >> 16 & 255) / 255.0F;
// float f6 = (float)(endColor >> 8 & 255) / 255.0F;
// float f7 = (float)(endColor & 255) / 255.0F;
// GlState.disableTexture2D();
// GlState.enableBlend();
// GlState.disableAlpha();
// GlState.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
// GlState.shadeModel(GL11.GL_SMOOTH);
// RenderBuffer worldrenderer = Tessellator.getBuffer();
// worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
// worldrenderer.pos((double)right, (double)top, 0.0).color(f1, f2, f3, f).endVertex();
// worldrenderer.pos((double)left, (double)top, 0.0).color(f1, f2, f3, f).endVertex();
// worldrenderer.pos((double)left, (double)bottom, 0.0).color(f5, f6, f7, f4).endVertex();
// worldrenderer.pos((double)right, (double)bottom, 0.0).color(f5, f6, f7, f4).endVertex();
// Tessellator.draw();
// GlState.shadeModel(GL11.GL_FLAT);
// GlState.disableBlend();
// GlState.enableAlpha();
// GlState.enableTexture2D();
// }
public void drawMainBackground() {
if(this.gm.theWorld != null && !this.gm.charEditor) {
// Drawing.drawGradient(0, 0, this.fb_x, this.fb_y, this.theWorld == null ? this.style.bg_top : 0x3f202020,
// this.theWorld == null ? this.style.bg_btm : 0x3f000000);
Drawing.drawGradient(0, 0, this.gm.fb_x, this.gm.fb_y, 0xc0101010, 0xd0101010);
}
else {
Drawing.drawScaled(this.gm, DIRT_BACKGROUND);
}
}
public void render() {
this.drawMainBackground();
this.drawBackground();
if(this.gm.fb_x != 0 && this.gm.fb_y != 0)
this.draw();
GlState.bindTexture(0);
GlState.setActiveTexture(GL13.GL_TEXTURE0);
GlState.enableTexture2D();
GlState.disableDepth();
this.drawPost();
GlState.disableDepth();
this.drawOverlays();
if(Bind.isWindowActive())
this.drawOverlay();
}
}

View file

@ -0,0 +1,44 @@
package client.gui;
import client.gui.element.ActButton;
import client.gui.element.ActButton.Mode;
import client.gui.element.Label;
import client.gui.element.TransparentBox;
public class GuiConfirm extends Gui implements ActButton.Callback {
public static interface Callback {
void confirm(boolean confirmed);
}
protected Callback callback;
protected String messageLine1;
private String messageLine2;
protected String confirmButtonText;
protected String cancelButtonText;
private ActButton confirmBtn;
private ActButton cancelBtn;
public GuiConfirm(Callback callback, String msg1, String msg2, String msgConfirm, String msgCancel) {
this.callback = callback;
this.messageLine1 = msg1;
this.messageLine2 = msg2;
this.confirmButtonText = msgConfirm;
this.cancelButtonText = msgCancel;
}
public void init(int width, int height) {
this.add(new Label(0, 0, 500, 24, this.messageLine1, true));
this.add(new TransparentBox(0, 80, 500, 300, this.messageLine2, this.gm.theWorld != null && !this.gm.charEditor));
this.confirmBtn = this.add(new ActButton(48, 500, 200, 24, this, this.confirmButtonText));
this.cancelBtn = this.add(new ActButton(252, 500, 200, 24, this, this.cancelButtonText));
this.shift();
}
public String getTitle() {
return "Aktion bestätigen";
}
public void use(ActButton btn, Mode mode) {
this.callback.confirm(btn == this.confirmBtn);
}
}

View file

@ -0,0 +1,268 @@
package client.gui;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
import client.gui.element.ActButton;
import client.gui.element.ActButton.Mode;
import client.gui.element.GuiList;
import client.gui.element.ListEntry;
import client.gui.element.NavButton;
import client.renderer.Drawing;
import common.color.TextColor;
import common.init.Config;
import common.log.Log;
import common.network.IPlayer;
import common.util.FileUtils;
import common.util.Tuple;
import common.util.Util;
public class GuiConnect extends GuiList<GuiConnect.ServerInfo> implements ActButton.Callback {
public class ServerInfo implements Comparable<ServerInfo>, ListEntry {
private String name;
private String address;
private int port;
private String user;
private String password;
private String access;
private long lastConnected;
public ServerInfo(String name, String address, int port, String user, String password, String access, long lastConnected) {
this.name = name;
this.address = address;
this.port = port;
this.user = user;
this.password = password;
this.access = access;
this.lastConnected = lastConnected;
}
public String getName() {
return this.name;
}
public String getAddress() {
return this.address;
}
public int getPort() {
return this.port;
}
public String getUser() {
return this.user;
}
public String getPassword() {
return this.password;
}
public String getAccess() {
return this.access;
}
public long getLastConnected() {
return this.lastConnected;
}
public void setData(String name, String address, int port, String user, String password, String access) {
this.name = name;
this.address = address;
this.port = port;
this.user = user;
this.password = password;
this.access = access;
}
public void setLastConnected() {
this.lastConnected = System.currentTimeMillis();
}
public int compareTo(ServerInfo comp) {
return this.lastConnected < comp.lastConnected ? 1 : (this.lastConnected > comp.lastConnected ? -1 : this.name.compareTo(comp.name));
}
public void select(boolean isDoubleClick, int mouseX, int mouseY) {
GuiConnect.this.selectButton.enabled = true;
GuiConnect.this.deleteButton.enabled = true;
GuiConnect.this.editButton.enabled = true;
GuiConnect.this.copyButton.enabled = true;
if(isDoubleClick) {
GuiConnect.this.use(GuiConnect.this.selectButton, Mode.PRIMARY);
}
}
public void draw(int x, int y, int mouseXIn, int mouseYIn, boolean hover) {
Drawing.drawText(this.name + TextColor.GRAY + " - " + TextColor.RESET + this.user, x + 2, y, 0xffffffff);
Drawing.drawText(this.address + TextColor.GRAY + " Port " + TextColor.RESET + this.port, x + 2, y + 18, 0xff808080);
Drawing.drawText("Zuletzt verbunden: " + (this.lastConnected == -1L ? "nie" : DATE_FORMAT.format(new Date(this.lastConnected))), x + 2, y + 18 + 16, 0xff808080);
}
}
public static final GuiConnect INSTANCE = new GuiConnect();
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
private static final File SERVERS_FILE = new File("servers.cfg");
private ActButton deleteButton;
private ActButton selectButton;
private ActButton copyButton;
private ActButton editButton;
private ActButton createButton;
private GuiConnect() {
}
public void init(int width, int height) {
super.init(width, height);
this.setDimensions(width, height, 32, height - 32);
this.elements.clear();
if(SERVERS_FILE.exists()) {
try {
String[] lines = FileUtils.read(SERVERS_FILE).split("\n");
String name = "";
String address = "";
int port = -1;
String user = "";
String password = "";
String access = "";
long time = -1L;
for(int z = 0; z <= lines.length; z++) {
String line = z == lines.length ? null : lines[z];
if(line == null || (line.startsWith("[") && line.endsWith("]"))) {
if(!name.isEmpty() && !address.isEmpty() && !user.isEmpty() && user.length() < IPlayer.MAX_USER_LENGTH && IPlayer.isValidUser(user) && password.length() < IPlayer.MAX_PASS_LENGTH && access.length() < IPlayer.MAX_PASS_LENGTH && address.length() < 128 && name.length() < 128 && port >= 0 && port < 65536)
this.elements.add(new ServerInfo(name, address, port, user, password, access, time));
if(line != null) {
address = "";
port = -1;
user = "";
password = "";
access = "";
time = -1L;
name = line.substring(1, line.length() - 1);
}
}
else {
Tuple<String, String> value = Util.getKeyValue(line);
if(value.first.equals("address"))
address = value.second;
else if(value.first.equals("port"))
try {
port = Integer.parseInt(value.second);
}
catch(NumberFormatException e) {
}
else if(value.first.equals("user"))
user = value.second;
else if(value.first.equals("password"))
password = value.second;
else if(value.first.equals("access"))
access = value.second;
else if(value.first.equals("connected"))
try {
time = Long.parseLong(value.second);
}
catch(NumberFormatException e) {
}
}
}
Collections.sort(this.elements);
}
catch(Exception e) {
Log.IO.error("Konnte Serverliste nicht laden", e);
this.elements.clear();
}
}
this.add(this.selectButton = new ActButton(width / 2 - 383, height - 28, 150, 24, this, "Verbinden"));
this.add(this.createButton = new ActButton(width - 204, 4, 200, 24, this, "Server hinzufügen ..."));
this.add(this.deleteButton = new ActButton(width / 2 - 75, height - 28, 150, 24, this, "Löschen"));
this.add(this.editButton = new ActButton(width / 2 + 79, height - 28, 150, 24, this, "Bearbeiten"));
this.add(this.copyButton = new ActButton(width / 2 - 229, height - 28, 150, 24, this, "Kopieren"));
this.add(new NavButton(4, 4, 200, 24, GuiServer.INSTANCE, "Schnellverbindung ..."));
this.add(new NavButton(width / 2 + 233, height - 28, 150, 24, GuiMenu.INSTANCE, "Abbrechen"));
this.selectButton.enabled = false;
this.deleteButton.enabled = false;
this.editButton.enabled = false;
this.copyButton.enabled = false;
}
public void onGuiClosed() {
this.save();
}
public void applyServer(ServerInfo server) {
if(this.selectedElement < 0)
this.elements.add(server);
this.save();
this.gm.displayGuiScreen(this);
}
private void save() {
try {
StringBuilder sb = new StringBuilder();
for(ServerInfo server : this.elements) {
if(sb.length() > 0)
sb.append("\n");
sb.append("[" + server.getName() + "]\n");
sb.append("address " + server.getAddress() + "\n");
sb.append("port " + server.getPort() + "\n");
sb.append("user " + server.getUser() + "\n");
sb.append("password " + server.getPassword() + "\n");
sb.append("access " + server.getAccess() + "\n");
sb.append("connected " + server.getLastConnected());
}
FileUtils.write(SERVERS_FILE, sb.toString());
}
catch(Exception e) {
Log.IO.error("Konnte Serverliste nicht speichern", e);
}
}
public String getTitle() {
return "Server auswählen";
}
public int getListWidth() {
return 660;
}
public int getSlotHeight() {
return 56;
}
public void use(ActButton button, Mode mode) {
if(button == this.deleteButton) {
if(this.selectedElement >= 0) {
this.elements.remove(this.selectedElement);
this.gm.displayGuiScreen(this);
}
}
else if(button == this.selectButton) {
ServerInfo server = this.getSelected();
if(server != null) {
server.setLastConnected();
this.gm.connect(server.address, server.port, server.user, server.password, server.access);
}
}
else if(button == this.createButton) {
this.setSelected(-1);
this.gm.displayGuiScreen(new GuiServer(new ServerInfo("", "", Config.PORT, "", "", "", -1L)));
}
else if(button == this.editButton) {
ServerInfo server = this.getSelected();
if(server != null)
this.gm.displayGuiScreen(new GuiServer(server));
}
else if(button == this.copyButton) {
ServerInfo server = this.getSelected();
if(server != null) {
this.setSelected(-1);
this.gm.displayGuiScreen(new GuiServer(new ServerInfo(server.name, server.address, server.port, server.user, server.address, server.access, -1L)));
}
}
}
}

View file

@ -0,0 +1,394 @@
package client.gui;
import java.util.List;
import client.Game;
import client.gui.element.ActButton;
import client.gui.element.Fill;
import client.gui.element.Textbox;
import client.gui.element.Textbox.Action;
import client.network.ClientPlayer;
import client.vars.BoolVar;
import client.vars.CVar;
import client.gui.element.TransparentBox;
import client.window.Keysym;
import common.collect.Lists;
import common.color.TextColor;
import common.network.IPlayer;
import common.packet.CPacketComplete;
import common.util.ExtMath;
import common.world.BlockPos;
import common.world.HitPosition;
public class GuiConsole extends Gui implements Textbox.Callback {
public static final GuiConsole INSTANCE = new GuiConsole();
private final List<String> sentMessages = Lists.<String>newArrayList();
private boolean full;
private String historyBuffer = "";
private int sentHistoryCursor = -1;
private boolean playerNamesFound;
private boolean waitingOnAutocomplete;
private boolean reverse;
private String prefixFirst;
private int autocompleteIndex;
private List<String> foundPlayerNames = Lists.<String>newArrayList();
private Textbox inputField;
private TransparentBox logBox;
public GuiConsole setFull(boolean full) {
this.full = full;
return this;
}
public void init(int width, int height) {
if(this.full) {
this.addSelector("con_autoclose", 0, 0, 160, 24);
this.addSelector("con_timestamps", 160, 0, 160, 24);
this.addSelector("con_loglevel", 320, 0, 160, 24);
this.add(new ActButton(480, 0, 160, 24, new ActButton.Callback() {
public void use(ActButton elem, ActButton.Mode action) {
GuiConsole.this.reset();
GuiConsole.this.setLog(GuiConsole.this.gm.getBuffer());
}
}, "Löschen"));
}
this.logBox = this.add(new TransparentBox(0, this.full ? 24 : 0, width, height - (this.full ? 48 : 24), this.gm.getBuffer(), this.gm.theWorld != null && !this.gm.charEditor));
if(this.full)
this.add(new Fill(640, 0, width - 640, 24));
this.inputField = this.add(new Textbox(0, height - 24, width, 24, IPlayer.MAX_CMD_LENGTH, true, this, ""));
this.inputField.setSelected();
this.sentHistoryCursor = this.sentMessages.size();
}
public String getTitle() {
return "Konsole / Chat";
}
public void reset() {
this.gm.reset();
this.sentMessages.clear();
this.sentHistoryCursor = -1;
}
public void setLog(String buffer) {
if(this.logBox != null)
this.logBox.setText(buffer);
}
public void drawMainBackground() {
if(this.gm.theWorld == null || this.gm.charEditor)
super.drawMainBackground();
}
public void key(Keysym key, boolean ctrl, boolean shift) {
super.key(key, ctrl, shift);
// this.waitingOnAutocomplete = false;
if(key != Keysym.TAB && key != Keysym.LEFT_SHIFT && key != Keysym.RIGHT_SHIFT)
this.playerNamesFound = false;
}
public void use(Textbox elem, Action value)
{
this.waitingOnAutocomplete = false;
if (value == Action.FORWARD || value == Action.BACKWARD)
{
this.reverse = value == Action.BACKWARD;
this.autocompletePlayerNames();
}
else
{
this.playerNamesFound = false;
}
if(value == Action.PREVIOUS)
this.getSentHistory(-1);
else if (value == Action.NEXT)
this.getSentHistory(1);
if(value == Action.SEND)
{
String s = this.inputField.getText().trim();
if (s.length() > 0)
{
if(this.sentMessages.isEmpty() || !((String)this.sentMessages.get(this.sentMessages.size() - 1)).equals(s))
this.sentMessages.add(s);
this.sentHistoryCursor = this.sentMessages.size();
this.gm.exec(s);
// if(this.gm.thePlayer != null)
// this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketMessage(CPacketMessage.Type.CHAT, s));
}
this.inputField.setText("");
if((this.gm.conAutoclose || !this.full) && this.gm.theWorld != null)
this.gm.displayGuiScreen(null);
}
}
protected void setText(String newChatText, boolean shouldOverwrite)
{
if (shouldOverwrite)
{
this.inputField.setText(newChatText);
}
else
{
this.inputField.insertText(newChatText);
}
}
private void addMessage(String msg) {
String buffer = this.gm.getBuffer();
if((buffer.length() + msg.length() + 2) > Game.LOG_BUFFER) {
int offset = (msg.length() + 2) > 1024 ? (msg.length() + 2) : 1024;
int nl = buffer.indexOf('\n', offset);
buffer = nl >= 0 ? buffer.substring(nl + 1) : "";
}
this.setLog(buffer + "\n" + TextColor.RESET + msg);
}
public void autocompletePlayerNames()
{
if (this.playerNamesFound)
{
this.inputField.deleteFromCursor();
if (this.autocompleteIndex >= this.foundPlayerNames.size())
{
this.autocompleteIndex = 0;
}
else if (this.autocompleteIndex < 0)
{
this.autocompleteIndex = this.foundPlayerNames.size() - 1;
}
}
else
{
int i = this.inputField.getNthCharFromPos();
this.foundPlayerNames.clear();
this.autocompleteIndex = 0;
// String s = this.inputField.getText().substring(i).toLowerCase();
String s1 = this.inputField.getText().substring(0, this.inputField.getCursorPosition());
String[] localMatches = this.sendAutocompleteRequest(s1);
if(localMatches != null) {
this.onAutocompleteResponse(localMatches);
return;
}
if (this.foundPlayerNames.isEmpty())
{
return;
}
this.playerNamesFound = true;
this.inputField.deleteFromCursor();
}
if (this.foundPlayerNames.size() > 1)
{
StringBuilder stringbuilder = new StringBuilder();
for (String s2 : this.foundPlayerNames)
{
if (stringbuilder.length() > 0)
{
stringbuilder.append(", ");
}
stringbuilder.append(s2);
}
this.addMessage(stringbuilder.toString());
}
this.inputField.insertText((String)this.foundPlayerNames.get(this.autocompleteIndex));
this.autocompleteIndex += this.reverse ? -1 : 1;
}
private String[] complete(String s) {
List<String> list = Lists.<String>newArrayList();
String[] argv = s.split(" ", -1);
String pre = argv[0];
s = argv[argv.length - 1];
Iterable<String> res = pre.startsWith("#") ?
(argv.length == 1 ? this.gm.getVars() : (argv.length == 2 ? getVarCompletion(argv[0].substring(1)) : Lists.newArrayList())) :
(this.gm.thePlayer == null ? Lists.newArrayList() : ((ClientPlayer)this.gm.thePlayer.sendQueue).getPlayerNames());
if(argv.length == 1 && pre.startsWith("#"))
s = s.substring(1);
for(String s1 : res) {
if(s1.regionMatches(true, 0, s, 0, s.length()))
list.add((argv.length == 1 && pre.startsWith("#") ? "#" : "") + s1);
}
return list.isEmpty() ? null : list.toArray(new String[list.size()]);
}
private List<String> getVarCompletion(String var) {
CVar cv = this.gm.getVar(var);
if(cv == null)
return Lists.newArrayList();
if(cv instanceof BoolVar)
return Boolean.parseBoolean(cv.format()) ? Lists.newArrayList("false", "true") : Lists.newArrayList("true", "false");
else
return Lists.newArrayList(cv.getDefault());
// return Lists.newArrayList();
}
private String[] sendAutocompleteRequest(String currentText)
{
if (currentText.length() >= 1)
{
BlockPos blockpos = null;
int eid = -1;
if (this.gm.pointed != null && this.gm.pointed.type == HitPosition.ObjectType.BLOCK)
{
blockpos = this.gm.pointed.block;
}
else if (this.gm.pointed != null && this.gm.pointed.type == HitPosition.ObjectType.ENTITY)
{
eid = this.gm.pointed.entity.getId();
blockpos = new BlockPos(this.gm.pointed.entity);
}
if(currentText.startsWith("/")) {
if(this.gm.thePlayer != null) {
currentText = currentText.substring(1);
this.prefixFirst = currentText.split(" ", -1).length == 1 ? "/" : null;
this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketComplete(currentText, eid, blockpos));
this.waitingOnAutocomplete = true;
}
}
else {
String[] comp = this.complete(currentText);
this.prefixFirst = null;
if(comp != null)
this.waitingOnAutocomplete = true;
return comp;
}
}
return null;
}
private void getSentHistory(int msgPos)
{
int i = this.sentHistoryCursor + msgPos;
int j = this.sentMessages.size();
i = ExtMath.clampi(i, 0, j);
if (i != this.sentHistoryCursor)
{
if (i == j)
{
this.sentHistoryCursor = j;
this.inputField.setText(this.historyBuffer);
}
else
{
if (this.sentHistoryCursor == j)
{
this.historyBuffer = this.inputField.getText();
}
this.inputField.setText(this.sentMessages.get(i));
this.sentHistoryCursor = i;
}
}
}
public void onAutocompleteResponse(String[] choices)
{
if (this.waitingOnAutocomplete)
{
this.playerNamesFound = false;
this.foundPlayerNames.clear();
for (int z = 0; z < choices.length; z++)
{
String s = choices[z];
if(this.prefixFirst != null)
choices[z] = s = this.prefixFirst + s;
if (s.length() > 0)
{
this.foundPlayerNames.add(s);
}
}
String s1 = this.inputField.getText().substring(this.inputField.getNthCharFromPos());
String s2 = getCommonPrefix(choices);
if (s2.length() > 0 && !s1.equalsIgnoreCase(s2))
{
this.inputField.deleteFromCursor();
this.inputField.insertText(s2);
}
else if (this.foundPlayerNames.size() > 0)
{
this.playerNamesFound = true;
this.autocompletePlayerNames();
}
}
}
private static String getCommonPrefix(String[] strs) {
if (strs != null && strs.length != 0) {
int smallestIndexOfDiff = indexOfDifference(strs);
if (smallestIndexOfDiff == -1) {
return strs[0] == null ? "" : strs[0];
} else {
return smallestIndexOfDiff == 0 ? "" : strs[0].substring(0, smallestIndexOfDiff);
}
} else {
return "";
}
}
private static int indexOfDifference(CharSequence[] css) {
if (css != null && css.length > 1) {
boolean anyStringNull = false;
boolean allStringsNull = true;
int arrayLen = css.length;
int shortestStrLen = Integer.MAX_VALUE;
int longestStrLen = 0;
int firstDiff;
for (firstDiff = 0; firstDiff < arrayLen; ++firstDiff) {
if (css[firstDiff] == null) {
anyStringNull = true;
shortestStrLen = 0;
} else {
allStringsNull = false;
shortestStrLen = Math.min(css[firstDiff].length(), shortestStrLen);
longestStrLen = Math.max(css[firstDiff].length(), longestStrLen);
}
}
if (allStringsNull || longestStrLen == 0 && !anyStringNull) {
return -1;
} else if (shortestStrLen == 0) {
return 0;
} else {
firstDiff = -1;
for (int stringPos = 0; stringPos < shortestStrLen; ++stringPos) {
char comparisonChar = css[0].charAt(stringPos);
for (int arrayPos = 1; arrayPos < arrayLen; ++arrayPos) {
if (css[arrayPos].charAt(stringPos) != comparisonChar) {
firstDiff = stringPos;
break;
}
}
if (firstDiff != -1) {
break;
}
}
return firstDiff == -1 && shortestStrLen != longestStrLen ? shortestStrLen : firstDiff;
}
} else {
return -1;
}
}
}

View file

@ -0,0 +1,214 @@
package client.gui;
import java.io.File;
import java.io.FileFilter;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
import client.Game.FileMode;
import client.gui.element.ActButton;
import client.gui.element.ActButton.Mode;
import client.gui.element.GuiList;
import client.gui.element.ListEntry;
import client.gui.element.NavButton;
import client.renderer.Drawing;
import client.world.Converter;
import common.color.TextColor;
import common.dimension.Space;
import common.log.Log;
import common.world.Region;
import common.world.World;
import common.world.Region.FolderInfo;
import common.world.Region.SaveVersion;
public class GuiConvert extends GuiList<GuiConvert.SaveInfo> implements ActButton.Callback
{
protected class SaveInfo implements Comparable<SaveInfo>, ListEntry {
private final String file;
private final int dimensions;
private final int players;
private final long seed;
private final FolderInfo info;
public SaveInfo(String file, int dimensions, int players, long seed, FolderInfo info) {
this.file = file;
this.dimensions = dimensions;
this.players = players;
this.seed = seed;
this.info = info;
}
public String getFile() {
return this.file;
}
public int getDimensions() {
return this.dimensions;
}
public int getPlayers() {
return this.players;
}
public boolean mustConvert() {
return this.info.legacy != null;
}
public String getVersion() {
return this.info.legacy == null ? (this.info.version == null ? "<Unbekannt>" : this.info.version) : this.info.legacy.toString();
}
public boolean isIncompatible() {
return this.info.legacy == SaveVersion.RELEASE_1_13;
}
public long getLastPlayed() {
return this.info.lastPlayed;
}
public long getSeed() {
return this.seed;
}
public int compareTo(SaveInfo comp) {
return this.info.lastPlayed < comp.info.lastPlayed ? 1 : (this.info.lastPlayed > comp.info.lastPlayed ? -1 : this.file.compareTo(comp.file));
}
public void select(boolean isDoubleClick, int mouseX, int mouseY)
{
boolean use = !this.isIncompatible() && this.mustConvert();
GuiConvert.this.selectButton.enabled = use;
if (isDoubleClick && use)
{
GuiConvert.this.use(GuiConvert.this.selectButton, Mode.PRIMARY);
}
}
public void draw(int x, int y, int mouseXIn, int mouseYIn, boolean hover)
{
Drawing.drawText((this.isIncompatible() ? TextColor.DRED : "") + this.getFile() + (this.mustConvert() ? "" :
(TextColor.GRAY + " - " + TextColor.RESET + (this.getPlayers() > 0 ? this.getPlayers() + " Spieler" : "Keine Spieler"))),
x + 2, y, 0xffffffff);
Drawing.drawText((this.mustConvert() ? (this.isIncompatible() ? TextColor.CRIMSON : "") + this.getVersion() : (this.getDimensions() <= 0 ? "Keine Dimensionen" : this.getDimensions() + " Dimension" + (this.getDimensions() != 1 ? "en" : "") + " erschaffen"))
, x + 2, y + 18, 0xff808080);
Drawing.drawText(this.mustConvert() ? (this.isIncompatible() ? TextColor.CRIMSON + "Kann nicht konvertiert werden!" :
"Muss konvertiert werden!") : ( // "Kreativmodus: " + (info.isNoCreative() ? "Aus" : "An") +
"Zuletzt gespielt: " + DATE_FORMAT.format(new Date(this.getLastPlayed()))) + " " + TextColor.LGRAY + this.getVersion(), x + 2, y + 18 + 16, 0xff808080);
}
}
public static final GuiConvert INSTANCE = new GuiConvert();
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
private ActButton selectButton;
private File dir = null;
private GuiConvert()
{
}
private void load() {
this.elements.clear();
if(this.dir == null || !this.dir.exists() || !this.dir.isDirectory())
return;
try
{
File[] files = dir.listFiles();
if(files == null)
throw new RuntimeException("Kann den Speicherordner für Welten nicht lesen oder öffnen!");
for(File file : files) {
if(!file.isDirectory())
continue;
FolderInfo info = Region.loadWorldInfo(file);
if(info == null)
info = Converter.convertMapFormat(file, false);
if(info == null) {
this.elements.add(new SaveInfo(file.getName(), -1, -1,
0L, new FolderInfo(World.START_TIME, file.lastModified(), null, null)));
continue;
}
int dims = -1;
int players = -1;
if(info.legacy == null) {
dims = 0;
File[] folders = new File(new File(dir, file.getName()), "chunk").listFiles(new FileFilter() {
public boolean accept(File pathname) {
return pathname.isDirectory() && !pathname.getName().equals(Space.INSTANCE.getDimensionName());
}
});
if(folders != null) {
for(File sub : folders) {
File[] dim = sub.listFiles();
if(dim != null && dim.length > 0)
dims++;
}
}
File[] plrs = new File(new File(dir, file.getName()), "players").listFiles(new FileFilter() {
public boolean accept(File pathname) {
return pathname.getName().endsWith(".nbt");
}
});
players = plrs == null ? 0 : plrs.length;
}
this.elements.add(new SaveInfo(file.getName(), dims, players,
0L, info));
}
Collections.sort(this.elements);
}
catch (Exception e)
{
Log.IO.error("Konnte Weltliste nicht laden", e);
this.elements.clear();
}
}
public void init(int width, int height)
{
super.init(width, height);
this.setDimensions(width, height, 32, height - 32);
this.load();
this.add(this.selectButton = new ActButton(width / 2 - 383, height - 28, 150, 24, this, "Konvertieren"));
this.add(new NavButton(width / 2 + 233, height - 28, 150, 24, GuiMenu.INSTANCE, "Abbrechen"));
this.add(new ActButton(4, 4, 200, 24, new ActButton.Callback() {
public void use(ActButton elem, ActButton.Mode action) {
if(GuiConvert.this.gm.theWorld != null)
return;
GuiConvert.this.gm.showFileDialog(FileMode.DIRECTORY_LOAD, "Ordner wählen", GuiConvert.this.dir, new FileCallback() {
public void selected(File file) {
GuiConvert.this.dir = file;
GuiConvert.this.gm.displayGuiScreen(GuiConvert.this);
}
});
}
}, "Ordner wählen ..."));
this.selectButton.enabled = false;
}
public String getTitle() {
return "Welt auswählen";
}
public int getListWidth()
{
return 660;
}
public int getSlotHeight()
{
return 56;
}
public void use(ActButton button, Mode mode)
{
String dir = this.getSelected().getFile();
File folder = new File(this.dir, dir);
if(folder.isDirectory())
Converter.convertMapFormat(folder, true);
}
}

View file

@ -0,0 +1,135 @@
package client.gui;
import client.gui.element.NavButton;
import client.gui.element.TransparentBox;
import common.color.TextColor;
import common.init.Config;
import common.log.Log;
public class GuiInfo extends Gui {
private static final String VER =
TextColor.GREEN + "" + TextColor.BUG + "" + TextColor.BUG + "" + TextColor.BUG + " " + TextColor.VIOLET + "" + Config.VERSION + "" +
TextColor.GREEN + " " + TextColor.BUG + "" + TextColor.BUG + "" + TextColor.BUG;
private static final String INFO = "Ein Spiel zur Simulation, zum Testen, für Rollenspiele, Mehrspieler und vieles mehr." + "\n" +
"Optimiert für Geschwindigkeit, Stabilität und" + TextColor.UNKNOWN + "" + TextColor.UNKNOWN + " [Speicherzugriffsfehler]";
private static final String HACKED = "Ein weiterer Release von WAAAAAAAAAAAAAAAAAAAAAAAAAAAAGHDRIVE!!!1!!!ONEoneOnetyone!1!!!" + "\n" +
"Update 0.2 - Läuft jetzt auch mit nur 512KB Fast-RAM!";
private static final String[] LIBRARIES = {
"LWJGL 3.3.6+1 (GLFW + OpenGL)",
"Netty 4.1.119-Final"
};
private static final String[] CODE = {
"Albert Pham - WorldEdit (Snippets)",
"Joonas Vali - NameGenerator",
"LWJGL 2.9.4-nightly-20150209 - Project, Vector*, Matrix*",
"Guava 17.0 - collect, future, Predicates",
"JOrbis 20101023 (JCraft) - jogg, jorbis, CodecJOrbis",
"MC 1.8.9"
};
public static final GuiInfo INSTANCE = new GuiInfo("Über dieses Programm", getFormat(false));
public static final GuiInfo HAX = new GuiInfo("Üb3r d1es3n Cr4ck", getFormat(true));
private final String header;
private final String info;
private static String getFormat(boolean hax) {
return getInfo(hax) + "\n\n" + getCredits(hax) + "\n\n" + getLibraries(hax) + "\n\n" + getCode(hax) + "\n\n" + getOldCredits(hax) + "\n\n" + getColors();
}
private static String getHeader(boolean hax, String normal, String hacked) {
return (hax ? TextColor.RED : TextColor.YELLOW) + (hax ? hacked : normal) + "\n" +
(hax ? TextColor.CYAN : TextColor.WHITE) + "==========================================+==========================================";
}
private static void addLines(StringBuilder sb, boolean hax, String alternate, String category, String... authors) {
sb.append("\n" + (hax ? TextColor.BLUE : TextColor.GRAY)
+ (hax ? alternate : category) + "\n ");
for(int z = 0; z < authors.length; z++) {
if(z > 0)
sb.append((hax ? TextColor.VIOLET : TextColor.GRAY) + ", ");
sb.append((hax ? TextColor.DVIOLET : TextColor.WHITE) + authors[z]);
}
}
private static String getInfo(boolean hax) {
return getHeader(hax, VER, VER) + "\n" + (hax ? (TextColor.VIOLET + HACKED) : (TextColor.LGRAY + INFO));
}
private static String getLibraries(boolean hax) {
StringBuilder sb = new StringBuilder(getHeader(hax, "Verwendete Programmbibliotheken", "U$3d 3xpl0its"));
for(String lib : LIBRARIES) {
sb.append("\n" + TextColor.LGRAY + "-> " + TextColor.NEON + lib);
}
return sb.toString();
}
private static String getCode(boolean hax) {
StringBuilder sb = new StringBuilder(getHeader(hax, "Zusätzlicher Quellcode", "M0ar 3xpl01ts"));
for(String lib : CODE) {
sb.append("\n" + TextColor.LGRAY + "-> " + TextColor.NEON + lib);
}
return sb.toString();
}
private static String getColors() {
StringBuilder sb = new StringBuilder();
int num = 0;
for(TextColor color : TextColor.values()) {
if(num > 0)
sb.append(' ');
if((color.code >= Log.CHR_COLORS1 && color.code <= Log.CHR_COLORE1) || (color.code >= Log.CHR_COLORS2 && color.code <= Log.CHR_COLORE2)) {
sb.append(color + "#" + (char)(num < 10 ? ('0' + num) : ('A' + (num - 10))));
num++;
}
}
return sb.toString();
}
private static String getOldCredits(boolean hax) {
StringBuilder sb = new StringBuilder(getHeader(hax, "Ursprüngliche Mitwirkende", "Das Team -- Nicht TCQ"));
addLines(sb, hax, "Absolut größter Lamer des Universums", "Spielidee und ursprüngliche Umsetzung",
"Markus Persson");
addLines(sb, hax, "Crack und weitere Programmierung", "Spiel-Design, Programmierung und Grafiken",
"Jens Bergensten", "Nathan Adams", "Ryan Holtz", "Michael Stoyke");
addLines(sb, hax, "Entschlüsselung von Ressourcen", "Programmierung",
"Erik Broes", "Paul Spooner", "Ryan Hitchman", "Elliot Segal");
addLines(sb, hax, "Cracktro, Grafiken und Intromusik", "Töne und Geräusche",
"Daniel Rosenfeld", "freesound.org");
addLines(sb, hax, "Packing und Verbreitung", "Management, Administration und Spaß",
"Carl Manneh", "Daniel Kaplan", "Lydia Winters");
addLines(sb, hax, "Server und Hosting", "Zahlen und Statistiken",
"Patrick Geuder");
addLines(sb, hax, "Weiterer Dank und Grüße", "Entwickler von Mo' Creatures (Pferde usw.)",
"John Olarte", "Kent Christian Jensen", "Dan Roque");
return sb.toString();
}
private static String getCredits(boolean hax) {
StringBuilder sb = new StringBuilder(getHeader(hax, "Mitwirkende dieses Programms", "Das Team -- TCQ"));
addLines(sb, hax, "Die dunklen Herrscher", "Quellcode, Design, Grafiken, Refactoring und Code-Cleanup",
TextColor.CYAN + "Sen der \"kleine\" Dämon " + TextColor.CRIMSON + TextColor.DEMON + TextColor.BLACK + TextColor.BLKHEART,
TextColor.RED + "Shen, Herrscher des Schattenlandes " + TextColor.CRIMSON + TextColor.IMP);
return sb.toString();
}
public GuiInfo(String header, String info) {
this.header = header;
this.info = info;
}
public void init(int width, int height) {
this.add(new TransparentBox(10, 10, width - 20, height - 44, this.info, this.gm.theWorld != null && !this.gm.charEditor));
this.add(new NavButton(0, height - 24, width, 24, GuiMenu.INSTANCE, "Zurück"));
}
public String getTitle() {
return this.header;
}
}

View file

@ -1,12 +1,12 @@
package client.gui;
import client.Client;
import client.Game;
import client.gui.element.Bar;
import client.gui.element.Label;
public class GuiLoading extends Gui {
public static interface Callback {
void poll(Client gm, GuiLoading gui);
void poll(Game gm, GuiLoading gui);
}
private final String message;
@ -19,7 +19,7 @@ public class GuiLoading extends Gui {
public static GuiLoading makeServerTask(String message) {
return new GuiLoading(message, new Callback() {
public void poll(Client gm, GuiLoading gui) {
public void poll(Game gm, GuiLoading gui) {
int progress = gm.progress;
if(progress < 0) {
gui.resetBar();
@ -35,7 +35,7 @@ public class GuiLoading extends Gui {
public static GuiLoading makeWaitTask(String message) {
return new GuiLoading(message, new Callback() {
public void poll(Client gm, GuiLoading gui) {
public void poll(Game gm, GuiLoading gui) {
}
});
}
@ -46,11 +46,11 @@ public class GuiLoading extends Gui {
}
public void init(int width, int height) {
this.taskLabel = this.add(new Label(0, 40, 500, 0, ""));
this.progressBar1 = this.add(new Bar(0, 80, 500, 0));
this.progressBar2 = this.add(new Bar(0, 120, 500, 0));
this.taskLabel = this.add(new Label(0, 40, 500, 20, ""));
this.progressBar1 = this.add(new Bar(0, 80, 500, 24));
this.progressBar2 = this.add(new Bar(0, 120, 500, 24));
this.shift();
this.headerLabel = this.add(new Label(0, 40, width, 0, this.message));
this.headerLabel = this.add(new Label(0, 40, width, 20, this.message));
this.progressBar1.visible = false;
this.progressBar2.visible = false;
}

View file

@ -0,0 +1,301 @@
package client.gui;
import client.Timing;
import client.gui.character.GuiChar;
import client.gui.character.GuiCharacters;
import client.gui.element.ActButton;
import client.gui.element.ActButton.Mode;
import client.gui.element.Label;
import client.gui.element.NavButton;
import client.gui.element.Textbox;
import client.gui.options.GuiOptions;
import client.renderer.Drawing;
import client.window.Keysym;
import common.color.TextColor;
import common.init.Config;
import common.rng.Random;
import common.util.ExtMath;
public class GuiMenu extends Gui {
public static final GuiMenu INSTANCE = new GuiMenu();
private GuiMenu() {
}
public void drawMainBackground() {
if(this.gm.theWorld != null)
super.drawMainBackground();
else
this.gm.renderGlobal.renderStarField(this.gm.fb_x, this.gm.fb_y, 0x000000, 0xffffff, (float)this.ticks + (float)Timing.tick_fraction, this.rand);
}
private final Random rand = new Random();
private Label splashLabel;
private ActButton infoButton;
private int ticks;
private int hacked;
private int animWidth = 32;
private int animGrowth = 10;
private int[] animGrow = new int[this.animWidth];
private String animStr = "";
private String animBack = "";
private int animPos;
private int animLen;
private int animDir;
private boolean animStep;
public void init(int width, int height) {
if(this.gm.theWorld == null) {
this.ticks = 0;
this.hacked = 0;
this.resetAnimation();
this.add(new ActButton(0, 0, 400, 24, new ActButton.Callback() {
public void use(ActButton elem, Mode action) {
if(GuiMenu.this.hacked == 9) {
GuiMenu.this.hacked++;
GuiMenu.this.splashLabel.setText(TextColor.VIOLET + "Hax!");
}
else {
GuiMenu.this.gm.displayGuiScreen(GuiConnect.INSTANCE);
}
}
}, "Server beitreten"));
this.add(new ActButton(0, 28, 400, 24, new ActButton.Callback() {
public void use(ActButton elem, Mode action) {
if(GuiMenu.this.hacked == 8)
GuiMenu.this.hacked++;
else
GuiMenu.this.gm.displayGuiScreen(GuiOptions.getPage());
}
}, "Einstellungen"));
this.infoButton = this.add(new ActButton(0, 56, 400, 24, new ActButton.Callback() {
public void use(ActButton elem, Mode action) {
GuiMenu.this.gm.displayGuiScreen(GuiMenu.this.hacked == 10 ? GuiInfo.HAX : GuiInfo.INSTANCE);
}
}, "Info / Über / Mitwirkende") {
public void drawHover() {
if(GuiMenu.this.hacked == 10) {
Drawing.drawRect(this.pos_x, this.pos_y, this.size_x, this.size_y, 0x287f00ff);
GuiMenu.this.rand.setSeed(((long)this.gm.mouse_x * 7652657L) ^ ((long)this.gm.mouse_y * 87262826276L));
int width = Drawing.getWidth("Hax!");
for(int z = 0; z < 64; z++) {
Drawing.drawText("Hax!", GuiMenu.this.rand.zrange(Math.max(1, this.gm.fb_x - width)) +
(int)(ExtMath.sin(((float)(GuiMenu.this.ticks + GuiMenu.this.rand.zrange(256)) + (float)Timing.tick_fraction) / 100.0f * (float)Math.PI * 2.0f) * 16.0f),
GuiMenu.this.rand.zrange(Math.max(1, this.gm.fb_y - Font.YGLYPH)) +
(int)(ExtMath.sin(((float)(GuiMenu.this.ticks + GuiMenu.this.rand.zrange(256)) + (float)Timing.tick_fraction) / 100.0f * (float)Math.PI * 2.0f) * 16.0f),
0xff0000ff | (GuiMenu.this.rand.zrange(256) << 16));
}
}
else {
super.drawHover();
}
}
});
this.add(new NavButton(0, 102, 196, 24, GuiConvert.INSTANCE, "Welt konvertieren"));
this.add(new ActButton(204, 102, 196, 24, new ActButton.Callback() {
public void use(ActButton elem, ActButton.Mode action) {
GuiMenu.this.gm.interrupted = true;
}
}, "Spiel beenden"));
this.shift();
this.add(new Label(4, /* this.gm.fb_y - 2 */ 0, 200, 20, TextColor.VIOLET + Config.VERSION, true));
this.splashLabel = this.add(new Label(0, 160, width, 24, ""));
this.pickSplash();
}
else {
this.add(new NavButton(0, 0, 400, 24, this.gm.charEditor ? GuiChar.INSTANCE : null, this.gm.charEditor ? "Zurück zum Charakter-Editor" : "Zurück zum Spiel"));
this.add(new NavButton(0, 28, this.gm.charEditor ? 400 : 198, 24, GuiOptions.getPage(), "Einstellungen"));
if(!this.gm.charEditor)
this.add(new NavButton(202, 28, 198, 24, GuiCharacters.INSTANCE, "Charakter"));
this.add(new ActButton(0, 102, 400, 24, new ActButton.Callback() {
public void use(ActButton elem, ActButton.Mode action) {
GuiMenu.this.gm.unload(true);
// GuiMenu.this.gm.displayGuiScreen(INSTANCE);
}
}, "Server verlassen und Verbindung trennen"));
this.shift();
}
}
public String getTitle() {
return this.gm.theWorld == null ? "Hauptmenü" : "Menü";
}
private void pickSplash() {
this.splashLabel.setText(TextColor.VIOLET + this.rand.pick(Splashes.SPLASHES));
}
private void resetAnimation() {
this.animStr = "";
this.animBack = "";
this.animPos = 0;
this.animLen = 0;
this.animDir = 0;
this.animStep = false;
this.animWidth = Math.max(5, (this.gm.fb_x - 5) / 10);
this.animGrowth = this.animWidth / 15;
this.animGrow = new int[this.animWidth];
}
private void updateAnimation() {
if(this.animLen == 0) {
this.animDir = this.rand.zrange(3) - 1;
this.animLen = this.animDir == 0 ? (2 + this.rand.zrange(2)) : (8 + this.rand.zrange(96));
}
else {
this.animPos += this.animDir;
if(this.animPos == -1) {
this.animPos = 0;
this.animDir = 1;
}
else if(this.animPos == this.animWidth - 3) {
this.animPos = this.animWidth - 4;
this.animDir = -1;
}
this.animLen--;
}
this.animStep = !this.animStep;
StringBuilder sb = new StringBuilder(11);
sb.append(TextColor.GRAY);
sb.append("[");
sb.append(TextColor.YELLOW);
switch(this.animDir) {
case -1:
sb.append((this.animStep ? '>' : '-') + "' ");
break;
case 0:
sb.append("`" + (this.animStep ? 'O' : 'o') + "'");
break;
case 1:
sb.append(" `" + (this.animStep ? '<' : '-'));
break;
}
sb.append(TextColor.GRAY);
sb.append("]");
this.animStr = sb.toString();
for(int z = this.animPos; z < this.animPos + 4; z++) {
this.animGrow[z] = 0;
}
for(int z = 0; z < this.animGrowth; z++) {
this.animGrow[this.rand.zrange(this.animWidth)] += 1;
}
sb = new StringBuilder(this.animWidth + 2);
sb.append(TextColor.DGREEN);
for(int z = 0; z < this.animWidth; z++) {
switch(this.animGrow[z] / 5) {
case 0:
sb.append(TextColor.BLACK);
break;
case 1:
sb.append(TextColor.GRAY);
break;
case 2:
case 3:
sb.append(TextColor.LGRAY);
break;
case 4:
case 5:
case 6:
sb.append(TextColor.WHITE);
break;
case 7:
case 8:
case 9:
case 10:
sb.append(TextColor.MAGENTA);
break;
case 11:
case 12:
case 13:
case 14:
case 15:
sb.append(TextColor.DVIOLET);
break;
default:
sb.append(TextColor.VIOLET);
break;
}
sb.append(",.");
}
this.animBack = sb.toString();
}
public void updateScreen() {
if(this.gm.theWorld == null) {
this.ticks++;
if(this.gm.shift() && !(this.selected instanceof Textbox))
this.pickSplash();
this.updateAnimation();
}
}
public void key(Keysym key, boolean ctrl, boolean shift) {
super.key(key, ctrl, shift);
if(this.gm.theWorld == null) {
if((key == Keysym.UP || key == Keysym.W) && (this.hacked == 0 || this.hacked == 1))
this.hacked++;
else if((key == Keysym.DOWN || key == Keysym.S) && (this.hacked == 2 || this.hacked == 3))
this.hacked++;
else if((key == Keysym.LEFT || key == Keysym.A) && (this.hacked == 4 || this.hacked == 6))
this.hacked++;
else if((key == Keysym.RIGHT || key == Keysym.D) && (this.hacked == 5 || this.hacked == 7))
this.hacked++;
else
this.hacked = 0;
}
}
/*
protected void actionPerformed(Button button) throws IOException {
if(button.id == 2 && this.hacked == 8) {
this.hacked++;
return;
}
else if(button.id == 1 && this.hacked == 9) {
this.hacked++;
return;
}
if(button.id != 3 || this.hacked != 10)
this.hacked = 0;
switch(button.id) {
case 0:
this.gm.displayGuiScreen(new GuiOptions(this));
break;
case 1:
this.gm.displayGuiScreen(new GuiWorlds(this));
break;
case 2:
this.gm.displayGuiScreen(new GuiMultiplayer(this));
break;
case 3:
if(this.hacked == 10)
Log.info("Hax!");
this.gm.displayGuiScreen(new GuiCredits(this.hacked == 10));
this.hacked = 0;
break;
// case 4:
// this.gm.displayGuiScreen(new GuiLanguage());
// break;
case 4:
this.gm.shutdown();
break;
}
}
*/
public void drawOverlays() {
super.drawOverlays();
if(this.gm.theWorld == null) {
int y = 164;
int h = 16;
int n = Drawing.getWidth(this.splashLabel.getText());
Drawing.drawRect(0, y, this.gm.fb_x / 2 - n / 2 - 10, h, 0x7f7f00ff);
Drawing.drawRect(this.gm.fb_x / 2 + n / 2 + 10, y, this.gm.fb_x - (this.gm.fb_x / 2 + n / 2 + 10), h, 0x7f7f00ff);
Drawing.drawText(this.animBack, this.gm.fb_x - Drawing.getWidth(this.animBack), this.gm.fb_y - 18, 0xffffffff);
Drawing.drawText(this.animStr, this.gm.fb_x - Drawing.getWidth(this.animStr) - 3 - ((this.animWidth - this.animPos - 4) * 10), this.gm.fb_y - 20, 0xffffffff);
}
}
}

View file

@ -0,0 +1,146 @@
package client.gui;
import client.gui.GuiConnect.ServerInfo;
import client.gui.element.ActButton;
import client.gui.element.Label;
import client.gui.element.NavButton;
import client.gui.element.Textbox;
import client.gui.element.Textbox.Action;
import client.vars.CVarCategory;
import client.vars.Variable;
import common.color.TextColor;
import common.init.Config;
import common.network.IPlayer;
public class GuiServer extends Gui implements Textbox.Callback {
public static final GuiServer INSTANCE = new GuiServer(null);
private final ServerInfo server;
private Textbox nameBox;
private Textbox addrBox;
private Textbox portBox;
private Textbox userBox;
private Textbox passBox;
private Textbox accBox;
private Label nameLabel;
private Label addrLabel;
private Label portLabel;
private Label userLabel;
private Label passLabel;
private Label accLabel;
public GuiServer(ServerInfo server) {
this.server = server;
}
@Variable(name = "srv_last_address", category = CVarCategory.SYSTEM, min = 1, max = 128, display = "Letzte Server-Adresse")
private String lastAddr = "";
@Variable(name = "srv_last_port", category = CVarCategory.SYSTEM, min = 0, max = 65535, display = "Letzter Server-Port")
private int lastPort = Config.PORT;
@Variable(name = "srv_last_user", category = CVarCategory.SYSTEM, max = IPlayer.MAX_USER_LENGTH, display = "Letzter Server-Nutzer", validator = IPlayer.UserValidator.class)
private String lastUser = "";
@Variable(name = "srv_last_password", category = CVarCategory.SYSTEM, max = IPlayer.MAX_PASS_LENGTH, display = "Letztes Server-Passwort")
private String lastPass = "";
@Variable(name = "srv_last_access", category = CVarCategory.SYSTEM, max = IPlayer.MAX_PASS_LENGTH, display = "Letzter Server-Zugang")
private String lastAcc = "";
public void init(int width, int height) {
if(this.server != null)
this.nameBox = this.add(new Textbox(0, -50, 400, 24, 128, true, this, this.server.getName()));
this.addrBox = this.add(new Textbox(0, 20, 400, 24, 128, true, this, this.server == null ? this.lastAddr : this.server.getAddress()));
this.portBox = this.add(new Textbox(404, 20, 76, 24, 5, true, this, "" + (this.server == null ? this.lastPort : this.server.getPort())));
this.userBox = this.add(new Textbox(0, 70, 220, 24, IPlayer.MAX_USER_LENGTH, true, this, IPlayer.VALID_USER, this.server == null ? this.lastUser : this.server.getUser()));
this.passBox = this.add(new Textbox(0, 120, 480, 24, IPlayer.MAX_PASS_LENGTH, true, this, this.server == null ? this.lastPass : this.server.getPassword()));
this.accBox = this.add(new Textbox(0, 170, 480, 24, IPlayer.MAX_PASS_LENGTH, true, this, this.server == null ? this.lastAcc : this.server.getAccess()));
this.add(new ActButton(0, 220, 480, 24, new ActButton.Callback() {
public void use(ActButton elem, ActButton.Mode action) {
GuiServer.this.connect();
}
}, this.server == null ? "Verbinden" : (this.server.getName().isEmpty() ? "Hinzufügen" : "Übernehmen")));
this.add(new NavButton(0, 250, 480, 24, GuiConnect.INSTANCE, "Zurück"));
if(this.server != null)
this.nameLabel = this.add(new Label(0, -70, 410, 20, "Name", true));
this.addrLabel = this.add(new Label(0, 0, 410, 20, "Adresse", true));
this.portLabel = this.add(new Label(414, 0, 66, 20, "Port", true));
this.userLabel = this.add(new Label(0, 50, 220, 20, "Nutzer", true));
this.passLabel = this.add(new Label(0, 100, 480, 20, "Passwort", true));
this.accLabel = this.add(new Label(0, 150, 480, 20, "Zugang", true));
this.shift();
}
public String getTitle() {
return this.server == null ? "Mit Server verbinden" : (this.server.getName().isEmpty() ? "Server hinzufügen" : "Server bearbeiten");
}
private void connect() {
if(this.gm.theWorld != null)
return;
String name = null;
if(this.server != null) {
name = this.nameBox.getText();
if(name.isEmpty()) {
this.nameLabel.setText(TextColor.RED + "Name");
return;
}
}
String addr = this.addrBox.getText();
if(addr.isEmpty()) {
this.addrLabel.setText(TextColor.RED + "Adresse");
return;
}
int port = -1;
if(this.portBox.getText().isEmpty()) {
this.portLabel.setText(TextColor.RED + "Port");
return;
}
else {
try {
port = Integer.parseInt(this.portBox.getText());
}
catch(NumberFormatException e) {
}
if(port < 0 || port > 65535) {
this.portLabel.setText(TextColor.RED + "Port");
return;
}
}
String user = this.userBox.getText();
if(user.isEmpty()) {
this.userLabel.setText(TextColor.RED + "Nutzer");
return;
}
String pass = this.passBox.getText();
String acc = this.accBox.getText();
if(this.server == null) {
this.lastAddr = addr;
this.lastPort = port;
this.lastUser = user;
this.lastPass = pass;
this.lastAcc = acc;
this.gm.setDirty();
this.gm.connect(addr, port, user, pass, acc);
}
else {
this.server.setData(name, addr, port, user, pass, acc);
GuiConnect.INSTANCE.applyServer(this.server);
}
}
public void use(Textbox elem, Action value) {
if(value == Action.SEND) {
elem.setDeselected();
this.connect();
}
else if(value == Action.FOCUS) {
if(elem == this.addrBox)
this.addrLabel.setText("Adresse");
else if(elem == this.portBox)
this.portLabel.setText("Port");
else if(elem == this.userBox)
this.userLabel.setText("Nutzer");
else if(this.server != null && elem == this.nameBox)
this.nameLabel.setText("Name");
}
}
}

View file

@ -2,34 +2,35 @@ package client.gui;
public abstract class Splashes {
public static final String[] SPLASHES = {
"Aus der Toiletten-Werbung!",
"Aus der TV-Werbung!",
"Toll!",
"0% pur!",
"Kann Nüsse enthalten!",
"Kann *.,-#+~ enthalten!",
"Besser als Crysis!",
"Mehr Polygone!",
"Sexy!",
"Limitierte Edition!",
"Blinkende Buchstaben!",
"Erstellt von Satan!",
"Er ist hier!",
"Das Schlimmste seiner Klasse!",
"Es ist vollendet (nicht)!",
"Erstellt von Notch!",
"Es ist hier!",
"Das Beste seiner Klasse!",
"Es ist vollendet!",
"Mehr oder weniger frei von Drachen!",
"Aufregung!",
"Weniger als -5 verkauft!",
"Einzigartig!",
"Einen Haufen Scheiße auf YouTube!",
"Dev!",
"Alpha!",
"Beta!",
"Indev!",
"Spinnen überall!",
"Schau es dir an!",
"Heilige Kuh, mann!",
"Es ist ein Spiel!",
"Hergestellt im Schattenland!",
"Hergestellt in Schweden!",
"Benutzt LWJGL!",
"Retikulierende Splinen!",
"Meine Kraft!",
"Hurraaa!",
"Einzelspieler!",
"Tastatur ist kompatibel!",
"Undokumentiert!",
"Barren!",
@ -40,14 +41,17 @@ public abstract class Splashes {
"Überlebe!",
"Verlies!",
"Exklusiv!",
"Die Knie der Biene!",
"Weg mit O.P.P.!",
"Mit Quellcode (mehr oder weniger)!",
"Mit Klasse(n)!",
"Wow!",
"Niemals auf Steam - und das ist auch gut so!",
"Immer noch nicht auf Steam - und das ist auch gut so!",
"Oh, mann!",
"Grauenvolle Community!",
"Pixel!",
"Garfiiieeeeeeeld!",
"Teetsuuuuoooo!",
"Kaaneeeedaaaa!",
"Jetzt ohne Schwierigkeit!",
"Verbessert!",
"9% frei von Bugs!",
@ -55,26 +59,31 @@ public abstract class Splashes {
"13 Kräuter und Gewürze!",
"Fettfrei!",
"Absolut keine Memes!",
"Kostenlose Vampirzähne!",
"Kostenlose Zähne!",
"Fragen Sie Ihnen Arzt oder Apotheker!",
"Alle Bergleute sind willkommen!",
"Cloud-Computing!",
"Frei von \"\"KI\"\"!",
"Legal in Norwegen!",
"Illegal in China!",
"Legal in Finnland!",
"Schwer zu beschreiben!",
"Technisch gesehen gut!",
"Bringe den Speck nach Hause!",
"Indie!",
"GOTY!",
"Ceci n'est pas une title screen!",
"Euklidisch!",
"Jetzt in 4D?!",
"Jetzt in 3D!",
"Bietet Inspiration!",
"Herregud!",
"Komplexe Zellvorgänge!",
"Ja, Sir!",
"Ja, Miss!",
"Von Trollen gespielt!",
"Von Cowboys gespielt!",
"OpenGL 1.5 oder höher!",
"Millionen von Farben!",
"Tausende von Farben!",
"Probiere es!",
"Age of Wonders ist besser!",
"Probiere die Pilzsuppe!",
"Sensationell!",
"Heiße Tamale, heiße heiße Tamale!",
"Spiele ihn runter, Klavierkatze!",
"Garantiert!",
"Makroskopisch!",
@ -85,22 +94,27 @@ public abstract class Splashes {
"Von Melonen geliebt!",
"Ultimative Edition!",
"Merkwürdig!",
"Du hast einen nagelneuen Schlüssel bekommen!",
"Wasserfest!",
"Nicht brennbar!",
"Oha, du!",
"Alles inklusive!",
"Sag es deinen Freunden!",
"NP ist nicht in P!",
"Musik von C418 (DLC)!",
"Viel zu oft live gestreamt!",
"Heimgesucht!",
"Polynomial!",
"Terrestrisch!",
"Alles ist voller Zerstörung!",
"Voll mit Sternen, Planeten und Monden!",
"Wissenschaftlich!",
"Nicht so cool wie Spock!",
"Trage nix bei und höre weg!",
"Grabe niemals nach unten, wenn du keine Erze brauchst!",
"Mache nie Pause!",
"Nicht linear!",
"Han hat zuerst geschossen!",
"Schön dich zu sehen!",
"Eimer mit Lava!",
"Reite auf dem Schwein!",
@ -110,18 +124,25 @@ public abstract class Splashes {
"Holz schlagen!",
"Von Klippen fallen!",
"0% Zucker!",
"180% Alkohol!",
"150% hyperbol!",
"Synecdoche!",
"Lasst uns tanzne!",
"Geheeimes Freitags-Update!",
"Referenz-Implementation!",
"Frei mit zwei.. äähhh fünf Typen mit Essen!",
"Küsse den Himmel!",
"20 GOTO 10!",
"Verlet-Intregration!",
"Peter Griffin!",
"Verteile die Erde gut!",
"8263273626252622872652 Zeilen Quellcode (287228 am 30.7.)!",
"Cogito ergo sum!",
"4815162342 Zeilen Quellcode (287228 am 30.7.)!",
"Ein Skelett fiel heraus!",
"Das Werk von Luzifer!",
"Das Werk von Notch!",
"Die Summe seiner Teile!",
"mureh srednA!",
"BTAF war mal gut!",
"Ich vermisse ADOM!",
"umop-apisdn!",
"GTX750Ti!",
"Bringe mir Mentos und Cola!",
"Finger-leckend!",
@ -141,16 +162,25 @@ public abstract class Splashes {
"Doppelt gepuffert!",
"Fan-Fiction!",
"Flaxkikare!",
"Jason! Jason! Jason!",
"Heißer als die Sonne!",
"Internet-Funktionalität!",
"Autonom!",
"Engagiere!",
"Fantasie!",
"Mau! Mau! Mau!",
"DRR! DRR! DRR!",
"Stoß es Wurzel runter!",
"Regionale Ressourcen!",
"Jaa, facepunch!",
"Jaa, somethingawful!",
"Jaa, /v/!",
"Jaa, tigsource!",
"Jaa, weinkraftforum!",
"Jaa, worldofweinkraft!",
"Buu, reddit!",
"Jaa, 2pp!",
"Goggle anllyticsed:DD :DDD:D!",
"Unterstützt jetzt äöüß!",
"Unterstützt jetzt äöü!",
"Gebt uns Gordon!",
"Gib deinem Kellner Trinkgeld!",
"Macht viel Spaß!",
@ -161,12 +191,15 @@ public abstract class Splashes {
"Allmächtig!",
"Huch!",
"...!",
"Bienen, Mienen, Minen, W-!",
"Bienen, Bienen, Bienen, Bienen!",
"Jag känner en bot!",
"Dieser Text ist schwer bei der Standard-Auflösung zu lesen, aber auf 1080p ist es in Ordnung!",
"Haha, LOL!",
"Hampsterdance!",
"Schalter und Erze!",
"Menger-Schwamm!",
"idspispopd!",
"Eple (originale Version)!",
"So frisch, so sauber!",
"Schnell reagierende Portale!",
"Probiere den Warp aus!",
@ -174,9 +207,10 @@ public abstract class Splashes {
"Oh, ok, NPCs!",
"Endlich mit Leitern!",
"Gruselig!",
"Spiele Minenkraft, schaue Topgear, bekomme Schwein!",
"Darüber gewittert!",
"Spring hoch, spring hoch, und komme runter!",
"Strahlung ist klasse!",
"Joel ist klasse!",
"Ein Rätsel, in einen Mythos verwoben!",
"Riesige Landeszüge voll mit TNT!",
"Willkommen zu deinem Ende! Muahahahahahaha!",
@ -188,21 +222,23 @@ public abstract class Splashes {
"\"Fast nie\" ist ein interessantes Konzept!",
"Eine Menge Wahrheitigkeit!",
"Der TNT-Block ist ein Spion!",
"Turing-unvollständig!",
"Turing-vollständig!",
"Es ist bahnbrechend!",
"Lasst unsere Schlachten beginnen!",
"Der Himmel ist die Grenze - oder auch nicht!",
"Dein PC hat tolle Haare, mach das Ding mal sauber!",
"Shen hat auch tolle Haare!",
"Jeb hat tolle Haare!",
"Ryan hat auch tolle Haare!",
"Gelegentliches Spielen!",
"Unbesiegt!",
"Ein Bisschen wie Lemmings!",
"Folge dem Zug, CJ!",
"Macht von Synergie Verwendung!",
"Diese Nachricht sollte niemals als Splash-Text erscheinen, oder etwa doch? Trololololol!",
"Diese Nachricht wird niemals als Splash-Text erscheinen, ist das nicht komisch?",
"DungeonQuest ist unfair!",
"0815!",
"666!",
"Geh zu den fernen Ländern und weiter!",
"Tyrion würde es lieben!",
"Probiere auch Stellaris!",
"Probiere auch Garry's Mod!",
"Probiere auch GZDoom!",
@ -216,43 +252,52 @@ public abstract class Splashes {
"Brot ist Schmerz!",
"Lese mehr Bücher!",
"Khaaaaaaaaan!",
"Weniger süchtig machend als [zensiert da NSFW]!",
"Weniger süchtig machend als TV Tropes!",
"Mehr süchtig machend als Limonade!",
"Größer als eine Brotkiste!",
"Millionen von Pfirsichen!",
"Fnord!",
"Dies ist meine echte Gestalt! Muahahahaha!",
"Verschwende keine Zeit mit \"\"KI\"\"!",
"Erstellt von einer Katze!",
"Habe Dre vollkommen vergessen!",
"Verschwende keine Zeit mit den Klonen!",
"Kürbiskopf!",
"Hobo humping slobo babe!",
"Erstellt von Jeb!",
"Hat kein Ende!",
"Endlich vollständig!",
"Voll mit Features!",
"Stiefel mit dem Fell!",
"Stop, hammertime!",
"Test!",
"Testificates!",
"Nicht konventionell!",
"Nicht kommerziell!",
"Homeomorphisch zu einer 3-Kugel!",
"Vermeidet nicht doppelte Verneinung!",
"Platziere ALL die Blöcke!",
"Macht Walzen!",
"Erfüllt Erwartungen!",
"Spielen am PC seit 1992!",
"Spielen am PC seit 1873!",
"Ghoughpteighbteau tchoghs!",
"Deja vu!",
"Deja vu!",
"Hab deine Nase!",
"Haley liebt Elan!",
"Hat keine Angst vor der großen, schwarzen Fledermaus!",
"Benutzt nicht das U-Wort!",
"Nicht wirklich leicht!",
"Bis nächsten Freitag oder so!",
"Von den Straßen von Nibelheim!",
"Von den Straßen von Södermalm!",
"150 BPM für 400000 Minuten!",
"Technologisch!",
"Hallo Japan!",
"Funk Soul Bruder!",
"Pumpa kungen!",
"Hallo Japan",
"Hallo Korea!",
"Hallo Wales!",
"Hallo Polen!",
"Hallo China!",
"Hallo China",
"Hallo Russland!",
"Hallo Griechenland!",
"Mein Leben für Aiur (warte mal..)!",
"Mein Leben für Aiur!",
"Lenny lenny = new Lenny(\"(°^°)\");",
"Ich sehe dein Wortschatz hat sich verbessert!",
"Wer hat es dort hin getan?",
@ -260,14 +305,14 @@ public abstract class Splashes {
"if not ok then return end",
"Mehrfarbig!",
"FUNKY LOL",
"Copyright bedeutet LOSER in allen Sprachen!",
"SOPA bedeutet LOSER in Schwedisch!",
"Große Spitze Zähne!",
"Mein Shizun bewacht das Tor!",
"Mmmph, mmph!",
"Füttere keine Landminen an Piranhas!",
"Füttere keine Avocados an Papageien!",
"Schwerter für alle!",
"Bitteee antworte meinem Tweet! (Nutzer wurde gebannt)",
".party().crash().commitWarcrimes().forTheEmperor()!",
".party()!",
"Nehme ihr Kissen!",
"Lege diesen Keks weg!",
"Extrem gruselig!",
@ -275,21 +320,26 @@ public abstract class Splashes {
"Jetzt mit extra Sprengstoff!",
"Nicht kompatibel zu Java 6!",
"Oha.",
"HURNERJSGER?",
"Was'n los, Doc?",
"Enthält jetzt 0 zufällige tägliche Katzen!",
"Das ist Numberwang!",
"((pls rt)) -- Der Vogel ist tot!",
"Willst du meinem Server beitreten?",
"Mach einen großen Zaun drum herum! Oder du wirst v-",
"Lege eine Landmine drüber!",
"Eines Tages, irgendwann in der Zukunft, wird mein Werk r3- ÄÄHHH kopiert werden!",
"Eines Tages, irgendwann in der Zukunft, wird mein Werk zitiert werden!",
"Jetzt mit zusätzlichem Zeug!",
"Zusätzliche Dinge!",
"Hurra, Atombomben für alle!",
"So süß, wie ein schöner ****!",
"So süß, wie ein schöner Bon-Bon!",
"Poppende Tags!",
"Sehr einflussreich in seinem Kreis!",
"Jetzt mit Mehrspieler!",
"Stehe aus deinem Grab auf!",
"Warnung! Ein großes Kampfschiff \"SHEN\" nähert sich schnell!",
"Der blaue Krieger hat das Essen beschossen!",
"Renn, Feigling! Ich hunger!",
"Geschmack ohne Würze!",
"Seltsam, aber nicht fremd!",
"Härter als Diamanten, Reich wie Creme!",
@ -305,13 +355,14 @@ public abstract class Splashes {
"Bau mir einen Tisch, einen funkigen Tisch!",
"Nehm den Aufzug in die Hölle!",
"Hör auf vernünftig zu sein, das hier ist das Internet!",
"/give * tnt 67108864 7",
"/give @a tnt 67108864 7",
"Das ist gut für 3D Realms.",
"Jeder Computer ist ein Laptop, wenn du tapfer genug bist!",
"Mach es alles, jede Sache!",
"Wo ist kein Licht, da kann Spinne!",
"GNU Terry Pratchett",
"Jetzt Java 21!",
"Jetzt Java 8!",
"MeinKraft!",
"Immer noch zu viele Bugs!",
"Wird nicht laggen!",
"Er hat es ruiniert!",
@ -319,6 +370,7 @@ public abstract class Splashes {
"OpenGL 2.0+ (definitiv nicht unterstützt)!",
"Keine Segfaults (nicht) möglich!",
"Keine Abstürze (un)möglich!",
"Alpha!",
"Enthält Bugs!",
"Enthält Mäuse!",
"Enthält Gewalt!",
@ -327,7 +379,6 @@ public abstract class Splashes {
"Du hattest eine. aufgabe.",
"Spinnen können TNT1 A 0 sein!",
"RTFM!",
"Hex, nur mit mehr Ameisen!",
"Vorherrschaft des Imperiums!",
"Vorherrschaft der Eldar!",
"Vorherrschaft der Drukhari!",
@ -358,11 +409,6 @@ public abstract class Splashes {
"Eimer mit Wasser!",
"Hergestellt in Deutschland!",
"Hergestellt in China!",
"Jetzt ohne Einzelspieler!",
"Jetzt mit tieferen Schluchten!",
"Was bist du denn für ein hübsches Ding?",
"[TEXT ZENSIERT]",
"Mehr Energie!",
"Maximale Energie!"
"Jetzt mit Einzelspieler!"
};
}

View file

@ -17,25 +17,25 @@ public enum Style implements Identifyable, Displayable {
this.name = name;
}
@Variable(type = IntType.COLOR, name = "color_border_top", category = CVarCategory.GUI, display = "Umrahmung A")
@Variable(type = IntType.COLOR, name = "color_border_top", category = CVarCategory.GUI, display = "Umrahmung oben / l.")
public int brdr_top;
@Variable(type = IntType.COLOR, name = "color_border_btm", category = CVarCategory.GUI, display = "Umrahmung B")
@Variable(type = IntType.COLOR, name = "color_border_btm", category = CVarCategory.GUI, display = "Umrahmung unten / r.")
public int brdr_btm;
@Variable(type = IntType.COLOR, name = "color_button_top", category = CVarCategory.GUI, display = "Knopf oben")
public int fill_top;
@Variable(type = IntType.COLOR, name = "color_button_btm", category = CVarCategory.GUI, display = "Knopf unten")
public int fill_btm;
@Variable(type = IntType.COLOR, name = "color_textbox_top", category = CVarCategory.GUI, display = "Eingabe oben")
@Variable(type = IntType.COLOR, name = "color_textbox_top", category = CVarCategory.GUI, display = "Textfeld oben")
public int field_top;
@Variable(type = IntType.COLOR, name = "color_textbox_btm", category = CVarCategory.GUI, display = "Eingabe unten")
@Variable(type = IntType.COLOR, name = "color_textbox_btm", category = CVarCategory.GUI, display = "Textfeld unten")
public int field_btm;
@Variable(type = IntType.COLOR, name = "color_label_text", category = CVarCategory.GUI, display = "Beschriftung")
public int text_label;
@Variable(type = IntType.COLOR, name = "color_button_text", category = CVarCategory.GUI, display = "Knopf Text")
public int text_base;
@Variable(type = IntType.COLOR, name = "color_textbox_text", category = CVarCategory.GUI, display = "Eingabe Text")
@Variable(type = IntType.COLOR, name = "color_textbox_text", category = CVarCategory.GUI, display = "Textfeld Text")
public int text_field;
static {

View file

@ -0,0 +1,634 @@
package client.gui.character;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileFilter;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.Arrays;
import javax.imageio.ImageIO;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL13;
import client.Game;
import client.Game.FileMode;
import client.SkinConverter;
import client.gui.FileCallback;
import client.gui.GuiLoading;
import client.gui.element.ActButton;
import client.gui.element.ActButton.Mode;
import client.gui.element.Element;
import client.gui.element.GuiList;
import client.gui.element.Label;
import client.gui.element.ListEntry;
import client.gui.element.NavButton;
import client.gui.element.Slider;
import client.gui.element.Textbox;
import client.gui.element.Textbox.Action;
import client.gui.element.TransparentBox;
import client.renderer.Drawing;
import client.renderer.GlState;
import client.renderer.ItemRenderer;
import client.renderer.entity.RenderManager;
import client.renderer.texture.EntityTexManager;
import client.vars.CVarCategory;
import client.vars.EnumVar;
import client.vars.Variable;
import client.vars.EnumVar.EnumFunction;
import client.window.Button;
import common.collect.Lists;
import common.dimension.DimType;
import common.dimension.Dimension;
import common.entity.npc.Alignment;
import common.entity.npc.CharacterInfo;
import common.entity.npc.EntityHuman;
import common.entity.npc.EntityNPC;
import common.entity.npc.SpeciesInfo;
import common.entity.types.EntityLiving;
import common.init.EntityEggInfo;
import common.init.EntityRegistry;
import common.init.SpeciesRegistry;
import common.init.UniverseRegistry;
import common.init.SpeciesRegistry.ModelType;
import common.log.Log;
import common.network.IPlayer;
import common.packet.CPacketAction;
import common.packet.CPacketMessage;
import common.packet.CPacketSkin;
import common.rng.Random;
import common.util.Displayable;
import common.util.FileUtils;
import common.util.Identifyable;
import common.util.Util;
public class GuiChar extends GuiList<GuiChar.SkinEntry>
{
protected class SkinEntry implements ListEntry
{
private final File skinFile;
private final String id;
private final ModelType model;
private final CharacterInfo charinfo;
private final BufferedImage skinImage;
private final int dynId;
protected SkinEntry(String id, File file, CharacterInfo charinfo, BufferedImage image, ModelType model)
{
this.skinFile = file;
this.charinfo = charinfo;
this.id = id;
this.model = model;
if(this.skinFile != null) {
this.skinImage = image;
int w = this.skinImage.getWidth();
int h = this.skinImage.getHeight();
int[] data = new int[w * h];
this.skinImage.getRGB(0, 0, w, h, data, 0, w);
this.dynId = 0xffff0000 + GuiChar.this.elements.size();
EntityTexManager.setTexture(this.dynId, EntityTexManager.imageToComp(data, model), model);
}
else {
this.skinImage = null;
this.dynId = -1;
}
}
public void draw(int x, int y, int mouseX, int mouseY, boolean hovered)
{
String str =
(this.skinFile != null ? this.skinFile.getName() : (
(this.charinfo.species.prefix && this.charinfo.type != null && !this.charinfo.type.toString().isEmpty() ?
this.charinfo.type.toString() :
EntityRegistry.getEntityName(this.charinfo.species.id))
+ (this.charinfo.name.isEmpty() ? "" : (" " + this.charinfo.name))));
Drawing.drawText(str, x + 64 + 3, y, 0xff000000 | (this.charinfo == null ?
0xffffff : this.charinfo.color1 | this.charinfo.color2));
if(this.charinfo != null)
Drawing.drawText(this.charinfo.skin, x + 64 + 3, y + 18, 0xffc0c0c0);
GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
if (hovered)
Drawing.drawRect(x, y, 64, 64, -1601138544);
this.drawTextureAt(x, y, EntityTexManager.getSkin(this.dynId, this.charinfo != null ? this.charinfo.skin : null, this.model));
}
protected void drawTextureAt(int x, int y, String tex)
{
GlState.enableBlend();
GlState.enableDepth();
boolean flag = GuiChar.this.gm.cameraUsed;
GuiChar.this.gm.cameraUsed = true;
EntityTexManager.altTexture = tex;
EntityTexManager.altLayer = this.dynId;
EntityTexManager.altNpcLayer = this.dynId == -1 && this.charinfo != null ? this.charinfo.skin : null;
drawEntity(x + 32, y + 60, 28.0f
* Math.min(1.8f / GuiChar.this.gm.thePlayer.height, 1.5f / GuiChar.this.gm.thePlayer.width), -45.0f, -20.0f, GuiChar.this.gm.thePlayer);
GuiChar.this.gm.cameraUsed = flag;
EntityTexManager.altTexture = null;
EntityTexManager.altLayer = -1;
EntityTexManager.altNpcLayer = null;
GlState.disableBlend();
GlState.disableDepth();
}
public void deleteTexture() {
if(this.dynId != -1) {
EntityTexManager.setTexture(this.dynId, null, null);
}
}
public void select(boolean dclick, int mx, int my)
{
// BufferedImage img = this.skinImage;
// if(this.charinfo != null) {
// try {
// img = TextureUtil.readImage(FileUtils.getResource(
// EntityNPC.getSkinTexture(this.charinfo.skin)));
// }
// catch(IOException e) {
// if(e instanceof FileNotFoundException)
// Log.JNI.warn("Textur für Skin ist nicht vorhanden: " +
// EntityNPC.getSkinTexture(this.charinfo.skin));
// else
// Log.JNI.error(e, "Konnte Textur nicht laden");
// return;
// }
// }
GuiChar.this.templateButton.enabled = this.charinfo != null;
if(this.skinImage == null) {
GuiChar.this.gm.getNetHandler().addToSendQueue(new CPacketSkin(null, this.charinfo.skin));
}
else {
int[] img = new int[this.model.texWidth * this.model.texHeight];
this.skinImage.getRGB(0, 0, this.skinImage.getWidth(), this.skinImage.getHeight(), img, 0, this.skinImage.getWidth());
GuiChar.this.gm.getNetHandler().addToSendQueue(new CPacketSkin(EntityTexManager.imageToComp(img, this.model), null));
}
// GuiChar.this.gm.getNetHandler().addToSendQueue(new CPacketSkin(this.skinImage, this.skinImage != null ? null : this.charinfo.skin, this.model));
GuiChar.this.currentSkin = this.skinFile != null ? this.skinFile.getName() : this.charinfo.skin;
GuiChar.this.waiting = false;
}
public String getLocation()
{
return this.charinfo == null ? null : this.charinfo.skin;
}
}
private class DragAdjust extends Element {
private int mouseX;
private int mouseY;
private float yawOffset;
private float pitchOffset;
public DragAdjust(int x, int y, int w, int h) {
super(x, y, w, h, null);
}
protected void drawBackground() {
Drawing.drawRect(this.pos_x, this.pos_y, this.size_x, this.size_y, 0x20ffffff);
}
protected void drawForeground(int x1, int y1, int x2, int y2) {
}
public void drag(int x, int y) {
GuiChar.this.yaw = this.yawOffset + (this.mouseX - x) * 2.0f;
GuiChar.this.pitch = this.pitchOffset + (this.mouseY - y) * 2.0f;
}
public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift) {
this.mouseX = x;
this.mouseY = y;
this.yawOffset = GuiChar.this.yaw;
this.pitchOffset = GuiChar.this.pitch;
}
public boolean canHover() {
return false;
}
}
public static enum FilterType implements Identifyable, Displayable {
ALL("all", "Alle anzeigen"), CUSTOM("custom", "Nur eigene"), NPC("preset", "Nur vorgegebene"), SPECIES("species", "Nur Spezies"), SPECIES_CUSTOM("species_custom", "Spezies und eigene");
private final String name;
private final String display;
private FilterType(String name, String display) {
this.name = name;
this.display = display;
}
public String getName() {
return this.name;
}
public String getDisplay() {
return this.display;
}
}
public static class FilterFunction implements EnumFunction<FilterType> {
public void apply(EnumVar cv, FilterType value) {
if(Game.getGame().open instanceof GuiChar)
Game.getGame().displayGuiScreen(Game.getGame().open);
}
}
public static final GuiChar INSTANCE = new GuiChar();
private static final File TEXTURE_FOLDER = new File("skins");
private ActButton templateButton;
private DragAdjust adjust;
private ActButton dimButton;
private TransparentBox descLines;
private float yaw = -15.0f;
private float pitch = -15.0f;
private boolean waiting = true;
private int dimension;
private String currentSkin;
@Variable(name = "char_filter_species", category = CVarCategory.GUI, display = "Filtern", callback = FilterFunction.class, switched = true)
private FilterType filterSpecies = FilterType.ALL;
private GuiChar() {
}
public void init(int width, int height)
{
super.init(width, height);
this.waiting = true;
this.setDimensions(400, height, 32, height - 32);
if(this.gm.getRenderManager().gm == null) {
this.unload();
this.adjust = null;
return;
}
this.currentSkin = this.gm.thePlayer != null && !EntityTexManager.hasCustomSkin(this.gm.thePlayer.getId()) ? this.gm.thePlayer.getChar() : null;
this.load(this.gm.thePlayer == null ? ModelType.HUMANOID : this.gm.thePlayer.getModel(), this.gm.thePlayer != null ? this.gm.thePlayer.getSpecies() : SpeciesRegistry.CLASSES.get(EntityHuman.class));
this.add(new ActButton(4, 4, 194, 24, new ActButton.Callback() {
public void use(ActButton elem, Mode action) {
GuiChar.this.gm.showFileDialog(FileMode.FILE_LOAD_MULTI, "Skin konvertieren", TEXTURE_FOLDER, new FileCallback() {
public void selected(File file) {
if(SkinConverter.convertSkin(file, TEXTURE_FOLDER, false))
GuiChar.this.gm.displayGuiScreen(GuiChar.this);
}
});
}
}, "Importieren: Standard"));
this.add(new ActButton(202, 4, 194, 24, new ActButton.Callback() {
public void use(ActButton elem, Mode action) {
GuiChar.this.gm.showFileDialog(FileMode.FILE_LOAD_MULTI, "Skin konvertieren (schlank)", TEXTURE_FOLDER, new FileCallback() {
public void selected(File file) {
if(SkinConverter.convertSkin(file, TEXTURE_FOLDER, true))
GuiChar.this.gm.displayGuiScreen(GuiChar.this);
}
});
}
}, "Importieren: Schlank"));
this.addSelector("char_filter_species", 400, 4, 300, 24);
this.add(new ActButton(4, height - 28, 194, 24, new ActButton.Callback() {
public void use(ActButton elem, Mode action) {
GuiChar.this.gm.displayGuiScreen(GuiChar.this);
}
}, "Neu laden"));
this.templateButton = this.add(new ActButton(202, height - 28, 194, 24, new ActButton.Callback() {
public void use(ActButton elem, Mode action) {
SkinEntry skin = GuiChar.this.getSelected();
if(skin != null && skin.getLocation() != null) {
String loc = skin.getLocation();
File file = new File(TEXTURE_FOLDER, loc + ".png");
int z = 1;
while(file.exists()) {
file = new File(TEXTURE_FOLDER, loc + "_" + (++z) + ".png");
}
InputStream in = null;
try {
in = FileUtils.getResource(EntityNPC.getSkinTexture(loc));
Files.copy(in, file.toPath());
}
catch(Exception e) {
if(e instanceof FileNotFoundException)
Log.JNI.warn("Textur ist nicht zum Kopieren vorhanden: " + EntityNPC.getSkinTexture(loc));
else
Log.JNI.error(e, "Konnte Textur nicht kopieren");
}
finally {
if(in != null) {
try {
in.close();
}
catch(Throwable e) {
}
}
}
GuiChar.this.gm.displayGuiScreen(GuiChar.this);
}
}
}, "Vorlage kopieren"));
this.adjust = this.add(new DragAdjust(width / 2 - 230, height - 64 - 640, 460, 640));
this.add(new Label(width - 396, 36, 392, 20, "Spezies: " + (this.gm.thePlayer == null ? "<?>" : this.gm.thePlayer.getSpecies().name), true));
this.add(new NavButton(width - 396, 56, 392, 24, GuiSpecies.INSTANCE, "Spezies ändern"));
this.add(new Label(width - 396, 36 + 92, 392, 20, "Klasse: " + (this.gm.thePlayer == null || this.gm.thePlayer.getSpecies().classEnum == null || this.gm.thePlayer.getNpcClass() == null || this.gm.thePlayer.getNpcClass().toString().isEmpty() ? "<Keine>" : this.gm.thePlayer.getNpcClass().toString()), true))
.enabled = this.gm.thePlayer != null && this.gm.thePlayer.getSpecies().classEnum != null;
this.add(new NavButton(width - 396, 56 + 92, 392, 24, GuiClass.INSTANCE, "Klasse ändern"))
.enabled = this.gm.thePlayer != null && this.gm.thePlayer.getSpecies().classEnum != null;
final ActButton[] alignBtns = new ActButton[Alignment.values().length];
for (int z = 0; z < Alignment.values().length; z++)
{
final Alignment align = Alignment.values()[z];
alignBtns[z] = this.add(new ActButton(width - 396 + (z % 3) * 132, height - 32 - 28 * 3 + 28 * (z / 3), 128, 24, new ActButton.Callback() {
public void use(ActButton elem, Mode action) {
if(GuiChar.this.gm.thePlayer != null) {
GuiChar.this.waiting = false;
GuiChar.this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_ALIGN, align.ordinal()));
for(ActButton btn : alignBtns) {
btn.enabled = btn != elem;
}
}
}
}, align.color + align.display));
alignBtns[z].enabled = this.gm.thePlayer == null || this.gm.thePlayer.getAlignment() != align;
}
this.add(new Slider(width / 2 - 200, height - 28, 400, 24, 1, this.gm.thePlayer == null ? 120 : this.gm.thePlayer.getMinSize(), this.gm.thePlayer == null ? 320 : this.gm.thePlayer.getMaxSize(), this.gm.thePlayer == null ? 180 : this.gm.thePlayer.getDefaultSize(), this.gm.thePlayer == null ? 180 : this.gm.thePlayer.getCurrentSize(), new Slider.Callback() {
public void use(Slider elem, int value) {
if(GuiChar.this.gm.thePlayer != null) {
GuiChar.this.waiting = false;
GuiChar.this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_HEIGHT, value));
}
}
}, "Spieler-Größe", "cm")).enabled = this.gm.thePlayer == null || this.gm.thePlayer.getMinSize() != this.gm.thePlayer.getMaxSize();
this.add(new Label(width / 2 - 200, 36, 400, 20, "Name", true));
this.add(new Label(width - 396, height - 384, 392, 20, "Beschreibung", true));
final Textbox descField = this.add(new Textbox(width - 396, height - 364, 392, 130, IPlayer.MAX_INFO_LENGTH, new Textbox.Callback() {
public void use(Textbox elem, Action value) {
}
}, ""));
this.add(new ActButton(width - 198, height - 28, 194, 24, new ActButton.Callback() {
public void use(ActButton elem, Mode action) {
if(GuiChar.this.gm.thePlayer != null) {
GuiChar.this.gm.displayGuiScreen(GuiLoading.makeWaitTask("Lade Welt ..."));
Dimension dim = UniverseRegistry.getBaseDimensions().get(GuiChar.this.dimension);
GuiChar.this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketMessage(CPacketMessage.Type.INFO, descField.getText()));
GuiChar.this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketAction(CPacketAction.Action.CLOSE_EDITOR, dim.getDimensionId()));
}
}
}, "Charakter erstellen"));
this.add(new Textbox(width / 2 - 200, 36 + 20, 400, 24, IPlayer.MAX_NICK_LENGTH, true, new Textbox.Callback() {
public void use(Textbox elem, Action value) {
if(value == Action.SEND || value == Action.UNFOCUS) {
String name = elem.getText();
if(name.isEmpty())
elem.setText(GuiChar.this.gm.thePlayer == null ? "..." : GuiChar.this.gm.thePlayer.getCustomNameTag());
else if(GuiChar.this.gm.thePlayer != null) {
GuiChar.this.waiting = false;
GuiChar.this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketMessage(CPacketMessage.Type.DISPLAY, name));
}
}
}
}, IPlayer.VALID_NICK, this.gm.thePlayer == null ? "" : this.gm.thePlayer.getCustomNameTag()));
this.templateButton.enabled = false;
this.dimension = new Random().zrange(UniverseRegistry.getBaseDimensions().size());
EntityEggInfo egg = EntityRegistry.SPAWN_EGGS.get(this.gm.thePlayer == null ? EntityRegistry.getEntityString(EntityHuman.class) : EntityRegistry.getEntityString(this.gm.thePlayer));
if(egg != null && egg.origin != null) {
Dimension dim = UniverseRegistry.getDimension(egg.origin);
if(dim != null) {
for(int z = 0; z < UniverseRegistry.getBaseDimensions().size(); z++) {
if(UniverseRegistry.getBaseDimensions().get(z).getDimensionId() == dim.getDimensionId()) {
this.dimension = z;
break;
}
}
}
}
this.dimButton = this.add(new ActButton(width - 396, height - 220, 392, 24, new ActButton.Callback() {
public void use(ActButton elem, Mode mode) {
if(mode == Mode.TERTIARY) {
GuiChar.this.dimension = new Random().zrange(UniverseRegistry.getBaseDimensions().size());
}
else if(mode == Mode.SECONDARY) {
if(--GuiChar.this.dimension < 0)
GuiChar.this.dimension = UniverseRegistry.getBaseDimensions().size() - 1;
}
else {
if(++GuiChar.this.dimension >= UniverseRegistry.getBaseDimensions().size())
GuiChar.this.dimension = 0;
}
GuiChar.this.setDimButton();
}
}, ""));
this.descLines = this.add(new TransparentBox(width - 396, height - 220 + 24, 392, 66, "", false));
this.setDimButton();
}
private void setDimButton() {
Dimension dim = UniverseRegistry.getBaseDimensions().get(this.dimension);
this.dimButton.setText((dim.getType() == DimType.PLANET ? "Heimplanet" : "Heimdimension") + ": " + dim.getFormattedName(false));
String name = dim.getFormattedName(true);
int index = name.indexOf(" / ");
this.descLines.setText(index >= 0 ? Util.buildLines(name.substring(index + " / ".length()).split(" / ")) : "");
}
public void onGuiClosed()
{
this.unload();
}
public void drawOverlays()
{
if(this.adjust != null) {
float factor = this.gm.thePlayer.width > 2.15f ? 2.15f / this.gm.thePlayer.width : 1.0f;
factor = this.gm.thePlayer.height > 3.0f && 3.0f / this.gm.thePlayer.height < factor ? 3.0f / this.gm.thePlayer.height : factor;
drawEntity(400 + (this.gm.fb_x - 400 - 400) / 2, this.gm.fb_y - 160, 160.0f * factor
, this.yaw, this.pitch, this.gm.thePlayer);
}
}
public void updateScreen() {
if(this.adjust == null && this.gm.getRenderManager().gm != null)
this.gm.displayGuiScreen(this);
}
public void checkReopen() {
if(this.adjust != null && this.waiting) {
this.waiting = false;
this.gm.displayGuiScreen(this);
}
}
public String getTitle() {
return "Charakter anpassen";
}
public static BufferedImage loadSkin(File file)
{
BufferedImage img = null;
try {
img = ImageIO.read(file);
}
catch(IOException e) {
return null;
}
if(img == null) {
return null;
}
return img;
}
public void load(ModelType model, SpeciesInfo speciesOnly)
{
this.unload();
TEXTURE_FOLDER.mkdirs();
File[] files = this.filterSpecies == FilterType.NPC || this.filterSpecies == FilterType.SPECIES ? null : TEXTURE_FOLDER.listFiles(new FileFilter() {
public boolean accept(File pathname) {
return pathname.isFile() && pathname.getName().endsWith(".png");
}
});
int pos = 0;
// this.elements.add(new SkinEntry("default", null, null, null, model));
// if("default".equals(currentSkin))
// this.setSelected(pos);
// pos++;
if(files != null) {
Arrays.sort(files);
for(File file : files)
{
BufferedImage img = loadSkin(file);
if(img != null) {
if(img.getWidth() == model.texWidth && img.getHeight() == model.texHeight) {
this.elements.add(new SkinEntry(file.getName(), file, null, img, model));
if(file.getName().equals(this.currentSkin))
this.setSelected(pos);
pos++;
}
}
}
}
if(this.filterSpecies == FilterType.CUSTOM)
return;
for(SpeciesInfo species : this.filterSpecies == FilterType.SPECIES || this.filterSpecies == FilterType.SPECIES_CUSTOM ? Lists.newArrayList(speciesOnly) : SpeciesRegistry.SPECIMEN) {
for(CharacterInfo charinfo : species.chars) {
if(charinfo.species.renderer == model) {
this.elements.add(new SkinEntry(charinfo.skin, null, charinfo, null, charinfo.species.renderer));
if(charinfo.skin.equals(this.currentSkin))
this.setSelected(pos);
pos++;
}
}
}
}
public void unload()
{
for (SkinEntry entry : this.elements)
{
entry.deleteTexture();
}
this.elements.clear();
}
public int getListWidth()
{
return 400 - 20;
}
public int getSlotHeight()
{
return 64 + 4;
}
// public static void drawEntityOnScreen(int posX, int posY, float scale, float mouseX, float mouseY, EntityLiving ent)
// {
// GlState.enableColorMaterial();
// SKC.glPushMatrix();
// SKC.glTranslatef((float)posX, (float)posY, 50.0F);
// SKC.glScalef(-scale, scale, scale);
// SKC.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);
// float f = ent.yawOffset;
// float f1 = ent.rotYaw;
// float f2 = ent.rotPitch;
// float f3 = ent.prevHeadYaw;
// float f4 = ent.headYaw;
// SKC.glRotatef(135.0F, 0.0F, 1.0F, 0.0F);
// ItemRenderer.enableStandardItemLighting();
// SKC.glRotatef(-135.0F, 0.0F, 1.0F, 0.0F);
// SKC.glRotatef(-((float)Math.atan((double)(mouseY / 40.0F))) * 20.0F, 1.0F, 0.0F, 0.0F);
// ent.yawOffset = (float)Math.atan((double)(mouseX / 40.0F)) * 20.0F;
// ent.rotYaw = (float)Math.atan((double)(mouseX / 40.0F)) * 40.0F;
// ent.rotPitch = -((float)Math.atan((double)(mouseY / 40.0F))) * 20.0F;
// ent.headYaw = ent.rotYaw;
// ent.prevHeadYaw = ent.rotYaw;
// SKC.glTranslatef(0.0F, 0.0F, 0.0F);
// RenderManager rendermanager = Game.getGame().getRenderManager();
// rendermanager.setPlayerViewY(180.0F);
//// rendermanager.setRenderShadow(false);
// rendermanager.renderEntity(ent, 0.0D, 0.0D, 0.0D, 1.0F);
//// rendermanager.setRenderShadow(true);
// ent.yawOffset = f;
// ent.rotYaw = f1;
// ent.rotPitch = f2;
// ent.prevHeadYaw = f3;
// ent.headYaw = f4;
// SKC.glPopMatrix();
// ItemRenderer.disableStandardItemLighting();
// GlState.disableRescaleNormal();
// GlState.setActiveTexture(SKC.GL_TEXTURE1);
// GlState.disableTexture2D();
// GlState.setActiveTexture(SKC.GL_TEXTURE0);
// }
public static void drawEntity(int posX, int posY, float scale, float yaw, float pitch, EntityLiving ent)
{
GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
GlState.enableDepth();
GlState.enableColorMaterial();
GL11.glPushMatrix();
GL11.glTranslatef((float)posX, (float)posY, 200.0F);
GL11.glScalef(-scale, scale, scale);
GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);
float f = ent.yawOffset;
float f1 = ent.rotYaw;
float f2 = ent.rotPitch;
float f3 = ent.prevHeadYaw;
float f4 = ent.headYaw;
GL11.glRotatef(135.0F, 0.0F, 1.0F, 0.0F);
ItemRenderer.enableStandardItemLighting();
GL11.glRotatef(-135.0F, 0.0F, 1.0F, 0.0F);
GL11.glTranslatef(0.0F, ent.height / 2, 0.0F);
GL11.glRotatef(-pitch, 1.0F, 0.0F, 0.0F);
ent.yawOffset = yaw;
ent.rotYaw = yaw;
ent.rotPitch = 0.0f;
ent.headYaw = ent.rotYaw;
ent.prevHeadYaw = ent.rotYaw;
GL11.glTranslatef(0.0F, -(ent.height / 2), 0.0F);
RenderManager rendermanager = Game.getGame().getRenderManager();
rendermanager.setPlayerViewY(180.0F);
rendermanager.renderEntity(ent, 0.0D, 0.0D, 0.0D, 1.0F);
// GL11.glTranslatef(0.0F, 0.0F, 0.0F);
ent.yawOffset = f;
ent.rotYaw = f1;
ent.rotPitch = f2;
ent.prevHeadYaw = f3;
ent.headYaw = f4;
GL11.glPopMatrix();
ItemRenderer.disableStandardItemLighting();
GlState.disableRescaleNormal();
GlState.setActiveTexture(GL13.GL_TEXTURE1);
GlState.disableTexture2D();
GlState.setActiveTexture(GL13.GL_TEXTURE0);
GlState.disableDepth();
}
}

View file

@ -0,0 +1,122 @@
package client.gui.character;
import client.gui.GuiConfirm;
import client.gui.GuiMenu;
import client.gui.element.ActButton;
import client.gui.element.ActButton.Mode;
import client.gui.element.GuiList;
import client.gui.element.ListEntry;
import client.gui.element.NavButton;
import client.gui.element.TransparentBox;
import client.renderer.Drawing;
import common.color.TextColor;
import common.entity.npc.PlayerCharacter;
import common.packet.CPacketAction;
public class GuiCharacters extends GuiList<GuiCharacters.CharacterEntry> implements ActButton.Callback
{
protected class CharacterEntry implements ListEntry
{
private final PlayerCharacter character;
private final boolean initial;
protected CharacterEntry(PlayerCharacter character, boolean initial)
{
this.character = character;
this.initial = initial;
}
public void draw(int x, int y, int mouseX, int mouseY, boolean hovered)
{
if(this.initial)
Drawing.drawRect(x, y, 1, 36, 0xffaf0000);
String str = this.character == null ? TextColor.BLUE + "[" + TextColor.CYAN + "+" + TextColor.BLUE + "]" :
String.format(TextColor.GREEN + "Level " + TextColor.DGREEN + "%d " + TextColor.YELLOW + "%s " + TextColor.VIOLET + "%s" + TextColor.GRAY + " [%s%s" + TextColor.GRAY + "]",
character.level, character.type, character.name, character.align.color, character.align.display);
String pos = this.character == null ? TextColor.BROWN + "Neuen Charakter erstellen" :
String.format(TextColor.NEON + "%s " + TextColor.GRAY + "bei " + TextColor.ACID + "%d" + TextColor.GRAY + ", " + TextColor.ACID + "%d" + TextColor.GRAY + ", " + TextColor.ACID + "%d",
character.dim, character.pos.getX(), character.pos.getY(), character.pos.getZ());
Drawing.drawText(str, x + 3, y, 0xffffffff);
Drawing.drawText(pos, x + 3, y + 16, 0xffffffff);
}
public void select(boolean dclick, int mx, int my)
{
if(dclick)
GuiCharacters.this.use(GuiCharacters.this.actionButtom, Mode.PRIMARY);
GuiCharacters.this.updateButtons();
}
}
public static final GuiCharacters INSTANCE = new GuiCharacters();
private TransparentBox descField;
private ActButton actionButtom;
private ActButton deleteButtom;
private GuiCharacters() {
}
private void updateButtons() {
CharacterEntry entry = this.getSelected();
this.descField.setText(entry == null ? "" : (entry.character == null ? "*neuer Charakter*" : (entry.character.info == null ? "*keine Beschreibung vorhanden*" : this.getSelected().character.info)));
this.actionButtom.setText(entry != null && entry.character == null ? "Charakter erstellen" : "Charakter spielen");
this.actionButtom.enabled = entry != null && !entry.initial;
this.deleteButtom.enabled = entry != null && entry.character != null && !entry.initial;
}
public void init(int width, int height)
{
super.init(width, height);
this.setDimensions(600, height, 32, height - 32);
this.elements.clear();
if(this.gm.getNetHandler() != null) {
int initialSelection = this.gm.getNetHandler().getSelectedCharacter();
for(PlayerCharacter character : this.gm.getNetHandler().getCharacterList()) {
this.elements.add(new CharacterEntry(initialSelection == this.elements.size() ? new PlayerCharacter(character.name, character.info, character.align, this.gm.thePlayer.worldObj.dimension.getFormattedName(false), this.gm.thePlayer.getPosition(), character.type, this.gm.thePlayer.experienceLevel) : character, initialSelection == this.elements.size()));
}
this.elements.add(new CharacterEntry(null, false));
this.setSelected(initialSelection);
}
this.descField = this.add(new TransparentBox(width - 390, 62, 380, height - 124, "", false));
this.deleteButtom = this.add(new ActButton(width / 2 - 304, height - 28, 200, 24, this, "Charakter löschen"));
this.actionButtom = this.add(new ActButton(width / 2 - 100, height - 28, 200, 24, this, ""));
this.add(new NavButton(width / 2 + 104, height - 28, 200, 24, GuiMenu.INSTANCE, "Abbrechen"));
this.updateButtons();
}
public String getTitle() {
return "Charakter anpassen";
}
public int getListWidth()
{
return 560;
}
public int getSlotHeight()
{
return 36 + 4;
}
public void use(ActButton elem, Mode action) {
CharacterEntry entry = GuiCharacters.this.getSelected();
if(entry != null && GuiCharacters.this.gm.getNetHandler() != null) {
if(elem == this.actionButtom) {
if(entry.character == null)
this.gm.getNetHandler().addToSendQueue(new CPacketAction(CPacketAction.Action.OPEN_EDITOR));
else
this.gm.getNetHandler().addToSendQueue(new CPacketAction(CPacketAction.Action.SELECT_CHARACTER, this.selectedElement));
}
else if(elem == this.deleteButtom && entry.character != null) {
this.gm.displayGuiScreen(new GuiConfirm(new GuiConfirm.Callback() {
public void confirm(boolean confirmed) {
if(confirmed)
GuiCharacters.this.gm.getNetHandler().addToSendQueue(new CPacketAction(CPacketAction.Action.DELETE_CHARACTER, GuiCharacters.this.selectedElement));
GuiCharacters.this.gm.displayGuiScreen(GuiCharacters.this);
}
}, "Möchtest du diesen Charakter wirklich löschen?", "Der Fortschritt, die Gegenstände und die Historie von \"" + entry.character.name + "\" werden für imer verloren sein!", "Löschen", "Abbrechen"));
}
}
}
}

View file

@ -0,0 +1,77 @@
package client.gui.character;
import client.gui.element.ActButton;
import client.gui.element.ActButton.Mode;
import client.gui.element.GuiList;
import client.gui.element.ListEntry;
import client.gui.element.NavButton;
import client.renderer.Drawing;
import common.packet.CPacketAction;
public class GuiClass extends GuiList<GuiClass.ClassEntry> implements ActButton.Callback
{
protected class ClassEntry implements ListEntry
{
private final Enum clazz;
protected ClassEntry(Enum clazz)
{
this.clazz = clazz;
}
public void draw(int x, int y, int mouseX, int mouseY, boolean hovered)
{
if(GuiClass.this.gm.thePlayer != null && this.clazz == GuiClass.this.gm.thePlayer.getNpcClass())
Drawing.drawRect(x, y, 1, 44, 0xffaf0000);
Drawing.drawText(this.clazz.toString().isEmpty() ? "<Keine>" : this.clazz.toString(), x + 3, y, 0xffffffff);
}
public void select(boolean dclick, int mx, int my)
{
if((GuiClass.this.selectButton.enabled = GuiClass.this.gm.thePlayer == null || this.clazz != GuiClass.this.gm.thePlayer.getNpcClass()) && dclick)
GuiClass.this.use(GuiClass.this.selectButton, Mode.PRIMARY);
}
}
public static final GuiClass INSTANCE = new GuiClass();
private ActButton selectButton;
private GuiClass() {
}
public void init(int width, int height)
{
super.init(width, height);
this.setDimensions(400, height, 32, height - 32);
this.elements.clear();
if(this.gm.thePlayer != null && this.gm.thePlayer.getSpecies().classEnum != null)
for(Enum clazz : this.gm.thePlayer.getSpecies().classEnum.getEnumConstants()) {
this.elements.add(new ClassEntry(clazz));
}
this.add(new NavButton(width - 198 * 2, height - 28, 194, 24, GuiChar.INSTANCE, "Zurück"));
this.selectButton = this.add(new ActButton(width - 198, height - 28, 194, 24, this, "Klasse ändern"));
}
public String getTitle() {
return "Klasse wählen";
}
public int getListWidth()
{
return 400 - 20;
}
public int getSlotHeight()
{
return 44 + 4;
}
public void use(ActButton elem, Mode action) {
ClassEntry entry = this.getSelected();
if(entry != null && GuiClass.this.gm.thePlayer != null) {
GuiClass.this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_CLASS, entry.clazz.ordinal()));
this.gm.displayGuiScreen(GuiChar.INSTANCE);
}
}
}

View file

@ -0,0 +1,79 @@
package client.gui.character;
import client.gui.element.ActButton;
import client.gui.element.ActButton.Mode;
import client.gui.element.GuiList;
import client.gui.element.ListEntry;
import client.gui.element.NavButton;
import client.renderer.Drawing;
import common.entity.npc.SpeciesInfo;
import common.init.EntityRegistry;
import common.init.SpeciesRegistry;
import common.packet.CPacketAction;
public class GuiSpecies extends GuiList<GuiSpecies.SpeciesEntry> implements ActButton.Callback
{
protected class SpeciesEntry implements ListEntry
{
private final SpeciesInfo species;
protected SpeciesEntry(SpeciesInfo species)
{
this.species = species;
}
public void draw(int x, int y, int mouseX, int mouseY, boolean hovered)
{
if(GuiSpecies.this.gm.thePlayer != null && this.species == GuiSpecies.this.gm.thePlayer.getSpecies())
Drawing.drawRect(x, y, 1, 44, 0xffaf0000);
Drawing.drawText(this.species.name, x + 3, y, 0xff000000 | this.species.color1 | this.species.color2);
if(this.species.classEnum != null)
Drawing.drawText(this.species.classEnum.getEnumConstants().length + " Klassen", x + 3, y + 18, 0xffc0c0c0);
}
public void select(boolean dclick, int mx, int my)
{
if((GuiSpecies.this.selectButton.enabled = GuiSpecies.this.gm.thePlayer == null || this.species != GuiSpecies.this.gm.thePlayer.getSpecies()) && dclick)
GuiSpecies.this.use(GuiSpecies.this.selectButton, Mode.PRIMARY);
}
}
public static final GuiSpecies INSTANCE = new GuiSpecies();
private ActButton selectButton;
private GuiSpecies() {
}
public void init(int width, int height)
{
super.init(width, height);
this.setDimensions(400, height, 32, height - 32);
this.elements.clear();
for(SpeciesInfo species : SpeciesRegistry.SPECIMEN) {
this.elements.add(new SpeciesEntry(species));
}
this.add(new NavButton(width - 198 * 2, height - 28, 194, 24, GuiChar.INSTANCE, "Zurück"));
this.selectButton = this.add(new ActButton(width - 198, height - 28, 194, 24, this, "Spezies ändern"));
}
public String getTitle() {
return "Spezies wählen";
}
public int getListWidth()
{
return 400 - 20;
}
public int getSlotHeight()
{
return 44 + 4;
}
public void use(ActButton elem, Mode action) {
SpeciesEntry entry = this.getSelected();
if(entry != null && GuiSpecies.this.gm.thePlayer != null)
GuiSpecies.this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_SPECIES, EntityRegistry.getEntityID(entry.species.clazz)));
}
}

View file

@ -0,0 +1,50 @@
package client.gui.container;
import common.inventory.ContainerBrewingStand;
import common.inventory.IInventory;
import common.inventory.InventoryPlayer;
public class GuiBrewing extends GuiContainer
{
// private static final String brewingStandGuiTextures = "textures/gui/brewing_stand.png";
/** The player inventory bound to this GUI. */
private final InventoryPlayer playerInventory;
private IInventory tileBrewingStand;
public GuiBrewing(InventoryPlayer playerInv, IInventory p_i45506_2_)
{
super(new ContainerBrewingStand(playerInv, p_i45506_2_));
this.playerInventory = playerInv;
this.tileBrewingStand = p_i45506_2_;
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY
*/
public void drawGuiContainerForegroundLayer()
{
String s = this.tileBrewingStand.getCommandName();
this.drawString(s, 8, 6);
this.drawString(this.playerInventory.getCommandName(), 8, this.ySize - 96 + 2);
}
/**
* Args : renderPartialTicks, mouseX, mouseY
*/
public void drawGuiContainerBackgroundLayer()
{
int k = this.tileBrewingStand.getField(0);
if (k > 0)
{
int l = (int)(28.0F * (1.0F - (float)k / 400.0F));
if (l > 0)
{
this.rect(97, 16, 9, l, 0xffff20);
}
}
}
}

View file

@ -0,0 +1,53 @@
package client.gui.container;
import client.Game;
import common.inventory.ContainerChest;
import common.inventory.IInventory;
public class GuiChest extends GuiContainer
{
// /** The ResourceLocation containing the chest GUI texture. */
// private static final String CHEST_GUI_TEXTURE = "textures/gui/generic_54.png";
private IInventory upperChestInventory;
private IInventory lowerChestInventory;
/**
* window height is calculated with these values; the more rows, the heigher
*/
private int inventoryRows;
public GuiChest(IInventory upperInv, IInventory lowerInv)
{
super(new ContainerChest(upperInv, lowerInv, Game.getGame().thePlayer));
this.upperChestInventory = upperInv;
this.lowerChestInventory = lowerInv;
// this.allowUserInput = false;
int i = 222;
int j = i - 108;
this.inventoryRows = lowerInv.getSizeInventory() / 9;
this.ySize = j + this.inventoryRows * 18;
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY
*/
public void drawGuiContainerForegroundLayer()
{
this.drawString(this.lowerChestInventory.getCommandName(), 8, 6);
this.drawString(this.upperChestInventory.getCommandName(), 8, this.ySize - 96 + 2);
}
/**
* Args : renderPartialTicks, mouseX, mouseY
*/
// protected void drawGuiContainerBackgroundLayer(int mouseX, int mouseY)
// {
// GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
// this.gm.getTextureManager().bindTexture(CHEST_GUI_TEXTURE);
// int i = (this.width - this.xSize) / 2;
// int j = (this.height - this.ySize) / 2;
//// this.rect(i, j, 0, 0, this.xSize, this.inventoryRows * 18 + 17);
//// this.rect(i, j + this.inventoryRows * 18 + 17, 0, 126, this.xSize, 96);
// }
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,42 @@
package client.gui.container;
import common.inventory.ContainerWorkbench;
import common.inventory.InventoryPlayer;
import common.world.BlockPos;
import common.world.World;
public class GuiCrafting extends GuiContainer
{
// private static final String craftingTableGuiTextures = "textures/gui/crafting_table.png";
public GuiCrafting(InventoryPlayer playerInv, World worldIn)
{
this(playerInv, worldIn, BlockPos.ORIGIN);
}
public GuiCrafting(InventoryPlayer playerInv, World worldIn, BlockPos blockPosition)
{
super(new ContainerWorkbench(playerInv, worldIn, blockPosition));
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY
*/
public void drawGuiContainerForegroundLayer()
{
this.drawString("Handwerk", 28, 6);
this.drawString("Inventar", 8, this.ySize - 96 + 2);
}
// /**
// * Args : renderPartialTicks, mouseX, mouseY
// */
// protected void drawGuiContainerBackgroundLayer(int mouseX, int mouseY)
// {
// GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
// this.gm.getTextureManager().bindTexture(craftingTableGuiTextures);
// int i = (this.width - this.xSize) / 2;
// int j = (this.height - this.ySize) / 2;
//// this.rect(i, j, 0, 0, this.xSize, this.ySize);
// }
}

View file

@ -0,0 +1,46 @@
package client.gui.container;
import common.inventory.ContainerDispenser;
import common.inventory.IInventory;
import common.inventory.InventoryPlayer;
public class GuiDispenser extends GuiContainer
{
// private static final String dispenserGuiTextures = "textures/gui/dispenser.png";
/** The player inventory bound to this GUI. */
private final InventoryPlayer playerInventory;
/** The inventory contained within the corresponding Dispenser. */
public IInventory dispenserInventory;
public GuiDispenser(InventoryPlayer playerInv, IInventory dispenserInv)
{
super(new ContainerDispenser(playerInv, dispenserInv));
this.playerInventory = playerInv;
this.dispenserInventory = dispenserInv;
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY
*/
public void drawGuiContainerForegroundLayer()
{
String s = this.dispenserInventory.getCommandName();
this.drawString(s, 8, 6);
this.drawString(this.playerInventory.getCommandName(), 8, this.ySize - 96 + 2);
}
// /**
// * Args : renderPartialTicks, mouseX, mouseY
// */
// protected void drawGuiContainerBackgroundLayer(int mouseX, int mouseY)
// {
// GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
// this.gm.getTextureManager().bindTexture(dispenserGuiTextures);
// int i = (this.width - this.xSize) / 2;
// int j = (this.height - this.ySize) / 2;
//// this.rect(i, j, 0, 0, this.xSize, this.ySize);
// }
}

View file

@ -0,0 +1,288 @@
package client.gui.container;
import common.color.TextColor;
import common.enchantment.Enchantment;
import common.inventory.ContainerEnchantment;
import common.inventory.InventoryPlayer;
import common.rng.Random;
import common.tileentity.IWorldNameable;
import common.world.World;
public class GuiEnchant extends GuiContainer
{
/** The ResourceLocation containing the Enchantment GUI texture location */
// private static final String ENCHANTMENT_TABLE_GUI_TEXTURE = "textures/gui/enchanting_table.png";
private static final String[] NAMES = "the elder scrolls klaatu berata niktu xyzzy bless curse light darkness fire air earth water hot dry cold wet ignite snuff embiggen twist shorten stretch fiddle destroy imbue galvanize enchant free limited range of towards inside sphere cube self other ball mental physical grow shrink demon elemental spirit animal creature beast humanoid undead fresh stale ".split(" ");
/** The player inventory currently bound to this GuiEnchantment instance. */
private final InventoryPlayer playerInventory;
private final Random nameRand = new Random();
private final Random random = new Random();
private final ContainerEnchantment container;
private final IWorldNameable table;
// public int field_147073_u;
// public float field_147071_v;
// public float field_147069_w;
// public float field_147082_x;
// public float field_147081_y;
// public float field_147080_z;
// public float field_147076_A;
// ItemStack field_147077_B;
public GuiEnchant(InventoryPlayer inventory, World worldIn, IWorldNameable table)
{
super(new ContainerEnchantment(inventory, worldIn));
this.playerInventory = inventory;
this.container = (ContainerEnchantment)this.inventorySlots;
this.table = table;
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY
*/
public void drawGuiContainerForegroundLayer()
{
this.drawString(this.table.getCommandName(), 12, 5);
this.drawString(this.playerInventory.getCommandName(), 8, this.ySize - 96 + 2);
}
// /**
// * Called from the main game loop to update the screen.
// */
// public void updateScreen()
// {
// super.updateScreen();
// this.updateAnimation();
// }
/**
* Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
*/
public void mouseClicked(int mouseX, int mouseY, int mouseButton)
{
super.mouseClicked(mouseX, mouseY, mouseButton);
// int i = (this.width - this.xSize) / 2;
// int j = (this.height - this.ySize) / 2;
for (int k = 0; k < 3; ++k)
{
int l = mouseX - 60;
int i1 = mouseY - (14 + 19 * k);
if (l >= 0 && i1 >= 0 && l < 108 && i1 < 19 && this.container.enchantItem(this.gm.thePlayer, k))
{
this.gm.controller.sendEnchantPacket(this.container.windowId, k);
}
}
}
public void addButtons() {
super.addButtons();
this.button(60, 14 + 19 * 0, 108, 19);
this.button(60, 14 + 19 * 1, 108, 19);
this.button(60, 14 + 19 * 2, 108, 19);
}
/**
* Args : renderPartialTicks, mouseX, mouseY
*/
public void drawGuiContainerBackgroundLayer()
{
this.nameRand.setSeed((long)this.container.xpSeed);
for (int l = 0; l < 3; ++l)
{
int i1 = 60;
int j1 = i1 + 20;
String s = this.getRandomName();
int l1 = this.container.enchantLevels[l];
if (l1 == 0)
{
this.rect(i1, 14 + 19 * l, 108, 19, 0x404040);
}
else
{
String s1 = "" + l1;
int i2 = 6839882;
if (/* (k < l + 1 || */ this.gm.thePlayer.experienceLevel < l1) // && !this.gm.thePlayer.creative)
{
this.rect(i1, 14 + 19 * l, 108, 19, 0x400000);
this.rect(i1 + 1, 15 + 19 * l, 16, 16, 0x200000);
this.drawString(s, j1, 16 + 19 * l); // , /*k1,*/ (i2 & 16711422) >> 1);
i2 = 4226832;
}
else
{
// int j2 = SKC.getMouseX() - this.guiLeft - 60;
// int k2 = SKC.getMouseY() - this.guiTop - (14 + 19 * l);
// if (j2 >= 0 && k2 >= 0 && j2 < 108 && k2 < 19)
// {
// this.rect(i1, 14 + 19 * l, 108, 19, 0x20ff20);
// i2 = 16777088;
// }
// else
// {
this.rect(i1, 14 + 19 * l, 108, 19, 0x20ff20);
// }
this.rect(i1 + 1, 15 + 19 * l, 16, 16, 0x008000);
this.drawString(s, j1, 16 + 19 * l);
i2 = 8453920;
}
this.drawString(s1, j1 + 86 - this.getStringWidth(s1), 16 + 19 * l + 7);
}
}
}
/**
* Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
*/
public void drawScreen(int mouseX, int mouseY)
{
super.drawScreen(mouseX, mouseY);
// boolean flag = this.gm.thePlayer.creative;
// int i = this.container.getLapisAmount();
for (int j = 0; j < 3; ++j)
{
int k = this.container.enchantLevels[j];
int l = this.container.enchantmentIds[j];
int i1 = j + 1;
if (this.isPointInRegion(60, 14 + 19 * j, 108, 17, mouseX, mouseY) && k > 0 && l >= 0)
{
StringBuilder sb = new StringBuilder();
if (l >= 0 && Enchantment.getEnchantmentById(l & 255) != null)
{
String s = Enchantment.getEnchantmentById(l & 255).getFormattedName((l & 65280) >> 8);
sb.append(TextColor.WHITE + s + " . . . ?");
}
// if (!flag)
// {
// if (l >= 0 && sb.length() != 0)
// {
// sb.append("\n");
// }
if (this.gm.thePlayer.experienceLevel < k)
{
sb.append((sb.length() != 0 ? "\n" : "") + TextColor.RED + String.format("Erfahrungsstufe %d erforderlich", this.container.enchantLevels[j]));
}
else
{
String s1 = "";
// if (i1 == 1)
// {
// s1 = I18n.format("container.enchant.lapis.one");
// }
// else
// {
// s1 = I18n.format("container.enchant.lapis.many", i1);
// }
//
// if (i >= i1)
// {
// list.add(ChatFormat.GRAY.toString() + "" + s1);
// }
// else
// {
// list.add(ChatFormat.RED.toString() + "" + s1);
// }
if (i1 == 1)
{
s1 = "1 Erfahrungsstufe";
}
else
{
s1 = String.format("%d Erfahrungsstufen", i1);
}
sb.append((sb.length() != 0 ? "\n" : "") + TextColor.LGRAY.toString() + "" + s1);
}
// }
this.hover(sb.toString(), mouseX, mouseY);
break;
}
}
}
private String getRandomName()
{
int i = this.nameRand.zrange(2) + 3;
String s = "";
for (int j = 0; j < i; ++j)
{
if (j > 0)
{
s = s + " ";
}
String name = NAMES[this.nameRand.zrange(NAMES.length)];
for(int z = 0; z < name.length(); z++) {
s += (char)(name.charAt(z) - 0x61 + 0x80);
}
}
return s;
}
// private void updateAnimation()
// {
// ItemStack itemstack = this.inventorySlots.getSlot(0).getStack();
//
// if (!ItemStack.areItemStacksEqual(itemstack, this.field_147077_B))
// {
// this.field_147077_B = itemstack;
//
// while (true)
// {
// this.field_147082_x += (float)(this.random.zrange(4) - this.random.zrange(4));
//
// if (this.field_147071_v > this.field_147082_x + 1.0F || this.field_147071_v < this.field_147082_x - 1.0F)
// {
// break;
// }
// }
// }
//
// ++this.field_147073_u;
// this.field_147069_w = this.field_147071_v;
// this.field_147076_A = this.field_147080_z;
// boolean flag = false;
//
// for (int i = 0; i < 3; ++i)
// {
// if (this.container.enchantLevels[i] != 0)
// {
// flag = true;
// }
// }
//
// if (flag)
// {
// this.field_147080_z += 0.2F;
// }
// else
// {
// this.field_147080_z -= 0.2F;
// }
//
// this.field_147080_z = ExtMath.clampf(this.field_147080_z, 0.0F, 1.0F);
// float f1 = (this.field_147082_x - this.field_147071_v) * 0.4F;
// float f = 0.2F;
// f1 = ExtMath.clampf(f1, -f, f);
// this.field_147081_y += (f1 - this.field_147081_y) * 0.9F;
// this.field_147071_v += this.field_147081_y;
// }
}

View file

@ -0,0 +1,71 @@
package client.gui.container;
import common.inventory.ContainerFurnace;
import common.inventory.IInventory;
import common.inventory.InventoryPlayer;
import common.tileentity.TileEntityFurnace;
public class GuiFurnace extends GuiContainer
{
// private static final String furnaceGuiTextures = "textures/gui/furnace.png";
/** The player inventory bound to this GUI. */
private final InventoryPlayer playerInventory;
private IInventory tileFurnace;
public GuiFurnace(InventoryPlayer playerInv, IInventory furnaceInv)
{
super(new ContainerFurnace(playerInv, furnaceInv));
this.playerInventory = playerInv;
this.tileFurnace = furnaceInv;
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY
*/
public void drawGuiContainerForegroundLayer()
{
String s = this.tileFurnace.getCommandName();
this.drawString(s, 8, 6);
this.drawString(this.playerInventory.getCommandName(), 8, this.ySize - 96 + 2);
}
/**
* Args : renderPartialTicks, mouseX, mouseY
*/
public void drawGuiContainerBackgroundLayer()
{
this.rect(58, 36, 12, 14, 0x202020);
if (TileEntityFurnace.isBurning(this.tileFurnace))
{
int k = this.getBurnLeftScaled(13);
k = Math.min(k, 13);
this.rect(58, 36 + 13 - k, 12, k + 1, 0xff7f00);
}
int l = this.getCookProgressScaled(24);
this.rect(79, 39, 24, 8, 0x606060);
if(l > 0)
this.rect(79, 39, l + 1, 8, 0xffaf00);
}
private int getCookProgressScaled(int pixels)
{
int i = this.tileFurnace.getField(2);
int j = this.tileFurnace.getField(3);
return j != 0 && i != 0 ? i * pixels / j : 0;
}
private int getBurnLeftScaled(int pixels)
{
int i = this.tileFurnace.getField(1);
if (i == 0)
{
i = 200;
}
return this.tileFurnace.getField(0) * pixels / i;
}
}

View file

@ -0,0 +1,49 @@
package client.gui.container;
import client.Game;
import common.inventory.ContainerHopper;
import common.inventory.IInventory;
import common.inventory.InventoryPlayer;
public class GuiHopper extends GuiContainer
{
// /** The ResourceLocation containing the gui texture for the hopper */
// private static final String HOPPER_GUI_TEXTURE = "textures/gui/hopper.png";
/** The player inventory currently bound to this GUI instance */
private IInventory playerInventory;
/** The hopper inventory bound to this GUI instance */
private IInventory hopperInventory;
public GuiHopper(InventoryPlayer playerInv, IInventory hopperInv)
{
super(new ContainerHopper(playerInv, hopperInv, Game.getGame().thePlayer));
this.playerInventory = playerInv;
this.hopperInventory = hopperInv;
// this.allowUserInput = false;
this.ySize = 133;
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY
*/
public void drawGuiContainerForegroundLayer()
{
this.drawString(this.hopperInventory.getCommandName(), 8, 6);
this.drawString(this.playerInventory.getCommandName(), 8, this.ySize - 96 + 2);
}
// /**
// * Args : renderPartialTicks, mouseX, mouseY
// */
// protected void drawGuiContainerBackgroundLayer(int mouseX, int mouseY)
// {
// GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
// this.gm.getTextureManager().bindTexture(HOPPER_GUI_TEXTURE);
// int i = (this.width - this.xSize) / 2;
// int j = (this.height - this.ySize) / 2;
//// this.rect(i, j, 0, 0, this.xSize, this.ySize);
// }
}

View file

@ -0,0 +1,79 @@
package client.gui.container;
import client.Game;
import common.entity.animal.EntityHorse;
import common.inventory.ContainerHorseInventory;
import common.inventory.IInventory;
public class GuiHorse extends GuiContainer
{
// private static final String horseGuiTextures = "textures/gui/horse.png";
/** The player inventory bound to this GUI. */
private IInventory playerInventory;
/** The horse inventory bound to this GUI. */
private IInventory horseInventory;
// /** The EntityHorse whose inventory is currently being accessed. */
// private EntityHorse horseEntity;
// /** The mouse x-position recorded during the last rendered frame. */
// private float mousePosx;
//
// /** The mouse y-position recorded during the last renderered frame. */
// private float mousePosY;
public GuiHorse(IInventory playerInv, IInventory horseInv, EntityHorse horse)
{
super(new ContainerHorseInventory(playerInv, horseInv, horse, Game.getGame().thePlayer));
this.playerInventory = playerInv;
this.horseInventory = horseInv;
// this.horseEntity = horse;
// this.allowUserInput = false;
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY
*/
public void drawGuiContainerForegroundLayer()
{
this.drawString(this.horseInventory.getCommandName(), 8, 6);
this.drawString(this.playerInventory.getCommandName(), 8, this.ySize - 96 + 2);
}
// /**
// * Args : renderPartialTicks, mouseX, mouseY
// */
// protected void drawGuiContainerBackgroundLayer(int mouseX, int mouseY)
// {
// GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
// this.gm.getTextureManager().bindTexture(horseGuiTextures);
// int i = (this.width - this.xSize) / 2;
// int j = (this.height - this.ySize) / 2;
//// this.rect(i, j, 0, 0, this.xSize, this.ySize);
//
//// if (this.horseEntity.isChested())
//// {
//// this.rect(i + 79, j + 17, 0, this.ySize, 90, 54);
//// }
//
//// if (this.horseEntity.canWearArmor())
//// {
//// this.rect(i + 7, j + 35, 0, this.ySize + 54, 18, 18);
//// }
//
//// GuiInventory.drawEntityOnScreen(i + 51, j + 60, 17, (float)(i + 51) - this.mousePosx, (float)(j + 75 - 50) - this.mousePosY, this.horseEntity);
// }
// /**
// * Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
// */
// public void drawScreen(int mouseX, int mouseY)
// {
// this.mousePosx = (float)mouseX;
// this.mousePosY = (float)mouseY;
// super.drawScreen(mouseX, mouseY);
// }
}

View file

@ -0,0 +1,58 @@
package client.gui.container;
import common.entity.npc.EntityNPC;
public class GuiInventory extends GuiContainer
{
// private final GuiCheat cheat;
// private float oldMouseX;
// private float oldMouseY;
public GuiInventory(EntityNPC player)
{
super(player.inventoryContainer);
// this.allowUserInput = true;
// this.cheat = cheat;
}
// public void updateScreen()
// {
// this.updateActivePotionEffects();
// }
// public void initGui()
// {
//// this.buttonList.clear();
// super.initGui();
// if(this.cheat != null)
// this.buttonList.add(new Button(1, this.guiLeft + this.xSize - 16, this.guiTop + 4, 12, 12, "X"));
// }
public void drawGuiContainerForegroundLayer()
{
this.drawString("Handwerk", 86, 16);
}
// public void drawScreen(int mouseX, int mouseY, float partialTicks)
// {
// super.drawScreen(mouseX, mouseY, partialTicks);
// this.oldMouseX = (float)mouseX;
// this.oldMouseY = (float)mouseY;
// }
// protected void drawGuiContainerBackgroundLayer(int mouseX, int mouseY)
// {
// GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
// this.gm.getTextureManager().bindTexture(inventoryBackground);
// int i = this.guiLeft;
// int j = this.guiTop;
//// this.rect(i, j, 0, 0, this.xSize, this.ySize);
//// drawEntityOnScreen(i + 51, j + 75, 30, (float)(i + 51) - this.oldMouseX, (float)(j + 75 - 50) - this.oldMouseY, this.gm.thePlayer);
// }
// public void actionPerformed(int button)
// {
// if(button == 1 && this.cheat != null && this.gm.thePlayer.inventory.getItemStack() == null)
// this.gm.displayGuiScreen(this.cheat);
// }
}

View file

@ -0,0 +1,44 @@
package client.gui.container;
import client.Game;
import common.inventory.ContainerMachine;
import common.inventory.IInventory;
import common.inventory.InventoryPlayer;
import common.tileentity.TileEntityMachine;
public class GuiMachine extends GuiContainer
{
// private final String texture;
private final IInventory playerInv;
private final IInventory machineInv;
private final TileEntityMachine machine;
public GuiMachine(InventoryPlayer player, IInventory inv, TileEntityMachine machine)
{
super(new ContainerMachine(player, machine, inv, Game.getGame().thePlayer));
this.playerInv = player;
this.machineInv = machine;
// this.allowUserInput = false;
this.ySize = 153;
// this.texture = "textures/gui/" + texture + ".png";
this.machine = machine;
}
public void drawGuiContainerForegroundLayer()
{
this.drawString(this.machine.getStatus().color + this.machineInv.getCommandName() + " - " + this.machine.getStatus().name, 8, 6);
this.drawString(this.playerInv.getCommandName(), 8, this.ySize - 96 + 2);
this.drawString(String.format("Temperatur: %d °", this.machine.getTemperature()), 8, 18);
this.drawString(this.machine.formatDisplay(), 8, 28);
}
// protected void drawGuiContainerBackgroundLayer(int mouseX, int mouseY)
// {
// GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
// this.gm.getTextureManager().bindTexture(this.texture);
// int i = (this.width - this.xSize) / 2;
// int j = (this.height - this.ySize) / 2;
//// this.rect(i, j, 0, 0, this.xSize, this.ySize);
// }
}

View file

@ -0,0 +1,287 @@
package client.gui.container;
import org.lwjgl.opengl.GL11;
import client.renderer.GlState;
import client.renderer.ItemRenderer;
import common.inventory.ContainerMerchant;
import common.inventory.InventoryPlayer;
import common.item.ItemStack;
import common.packet.CPacketAction;
import common.village.MerchantRecipe;
import common.village.MerchantRecipeList;
import common.world.World;
public class GuiMerchant extends GuiContainer
{
// private static final String MERCHANT_GUI_TEXTURE = "textures/gui/trading.png";
private int selectedMerchantRecipe;
private String chatComponent;
public GuiMerchant(InventoryPlayer inv, String name, World worldIn)
{
super(new ContainerMerchant(inv, null, worldIn));
this.chatComponent = name != null ? name : "NSC";
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
// public void initGui()
// {
// super.initGui();
// }
public void addButtons() {
super.addButtons();
this.button(120 + 27, 24, 12, 16);
this.button(36 - 19, 24, 12, 16);
this.button(36 - 1, 24 - 1, 18, 18);
this.button(62 - 1, 24 - 1, 18, 18);
this.button(120 - 1, 24 - 1, 18, 18);
}
public void mouseClicked(int mouseX, int mouseY, int mouseButton)
{
if (mouseButton == 0)
{
// int i = (this.width - this.xSize) / 2;
// int j = (this.height - this.ySize) / 2;
if(mouseX >= 147 && mouseX < 147 + 12 && mouseY >= 24 && mouseY < 24 + 16) {
this.switchTrade(true);
return;
}
else if(mouseX >= 17 && mouseX < 17 + 12 && mouseY >= 24 && mouseY < 24 + 16) {
this.switchTrade(false);
return;
}
// this.buttonList.add(new Button(1, i + 120 + 27, j + 24 - 1, 12, 19, ">"));
// this.buttonList.add(new Button(2, i + 36 - 19, j + 24 - 1, 12, 19, "<"));
}
super.mouseClicked(mouseX, mouseY, mouseButton);
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY
*/
public void drawGuiContainerForegroundLayer()
{
String s = this.chatComponent;
this.drawString(s, 8, 6);
this.drawString("Inventar", 8, this.ySize - 96 + 2);
}
public void drawOverlays() {
super.drawOverlays();
MerchantRecipeList merchantrecipelist = this.getRecipes();
if (merchantrecipelist != null && !merchantrecipelist.isEmpty()) {
int k = this.selectedMerchantRecipe;
MerchantRecipe merchantrecipe = (MerchantRecipe)merchantrecipelist.get(k);
ItemStack itemstack = merchantrecipe.getItemToBuy();
ItemStack itemstack1 = merchantrecipe.getSecondItemToBuy();
ItemStack itemstack2 = merchantrecipe.getItemToSell();
this.renderItemOverlayIntoGUI(itemstack, 36, 24, null);
if(itemstack1 != null)
this.renderItemOverlayIntoGUI(itemstack1, 62, 24, null);
this.renderItemOverlayIntoGUI(itemstack2, 120, 24, null);
}
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
public void switchTrade(boolean forward)
{
boolean flag = false;
if (forward)
{
++this.selectedMerchantRecipe;
MerchantRecipeList merchantrecipelist = this.getRecipes();
if (merchantrecipelist != null && this.selectedMerchantRecipe >= merchantrecipelist.size())
{
this.selectedMerchantRecipe = merchantrecipelist.size() - 1;
}
flag = true;
}
else
{
--this.selectedMerchantRecipe;
if (this.selectedMerchantRecipe < 0)
{
this.selectedMerchantRecipe = 0;
}
flag = true;
}
if (flag)
{
((ContainerMerchant)this.inventorySlots).setCurrentRecipeIndex(this.selectedMerchantRecipe);
// PacketBuffer packetbuffer = new PacketBuffer(Unpooled.buffer());
// packetbuffer.writeInt(this.selectedMerchantRecipe);
this.gm.getNetHandler().addToSendQueue(new CPacketAction(CPacketAction.Action.SELECT_TRADE,
this.selectedMerchantRecipe));
}
}
// /**
// * Args : renderPartialTicks, mouseX, mouseY
// */
// protected void drawGuiContainerBackgroundLayer(int mouseX, int mouseY)
// {
// GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
// this.gm.getTextureManager().bindTexture(MERCHANT_GUI_TEXTURE);
// int i = (this.width - this.xSize) / 2;
// int j = (this.height - this.ySize) / 2;
//// this.rect(i, j, 0, 0, this.xSize, this.ySize);
//// MerchantRecipeList merchantrecipelist = this.merchant.getRecipes(this.gm.thePlayer);
//
//// if (merchantrecipelist != null && !merchantrecipelist.isEmpty())
//// {
//// int k = this.selectedMerchantRecipe;
////
//// if (k < 0 || k >= merchantrecipelist.size())
//// {
//// return;
//// }
//
//// MerchantRecipe merchantrecipe = (MerchantRecipe)merchantrecipelist.get(k);
//
//// if (merchantrecipe.isRecipeDisabled())
//// {
//// this.gm.getTextureManager().bindTexture(MERCHANT_GUI_TEXTURE);
//// GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
//// GlState.disableLighting();
//// this.rect(this.guiLeft + 83, this.guiTop + 21, 212, 0, 28, 21);
//// this.rect(this.guiLeft + 83, this.guiTop + 51, 212, 0, 28, 21);
//// }
//// }
// }
/**
* Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
*/
public void drawScreen(int mouseX, int mouseY)
{
super.drawScreen(mouseX, mouseY);
MerchantRecipeList merchantrecipelist = this.getRecipes();
if (merchantrecipelist != null && !merchantrecipelist.isEmpty())
{
// int i = (this.width - this.xSize) / 2;
// int j = (this.height - this.ySize) / 2;
int k = this.selectedMerchantRecipe;
MerchantRecipe merchantrecipe = (MerchantRecipe)merchantrecipelist.get(k);
ItemStack itemstack = merchantrecipe.getItemToBuy();
ItemStack itemstack1 = merchantrecipe.getSecondItemToBuy();
ItemStack itemstack2 = merchantrecipe.getItemToSell();
GL11.glPushMatrix();
ItemRenderer.enableGUIStandardItemLighting();
GlState.disableLighting();
GlState.enableRescaleNormal();
GlState.enableColorMaterial();
GlState.enableLighting();
this.itemRender.zLevel = 100.0F;
this.itemRender.renderItemAndEffectIntoGUI(itemstack, 36, 24);
// this.itemRender.renderItemOverlays(itemstack, 36, 24);
if (itemstack1 != null)
{
this.itemRender.renderItemAndEffectIntoGUI(itemstack1, 62, 24);
// this.itemRender.renderItemOverlays(itemstack1, 62, 24);
}
this.itemRender.renderItemAndEffectIntoGUI(itemstack2, 120, 24);
// this.itemRender.renderItemOverlays(itemstack2, 120, 24);
this.itemRender.zLevel = 0.0F;
GlState.disableLighting();
if (this.isPointInRegion(36, 24, 16, 16, mouseX, mouseY) && itemstack != null)
{
this.renderToolTip(itemstack, mouseX, mouseY);
}
else if (itemstack1 != null && this.isPointInRegion(62, 24, 16, 16, mouseX, mouseY) && itemstack1 != null)
{
this.renderToolTip(itemstack1, mouseX, mouseY);
}
else if (itemstack2 != null && this.isPointInRegion(120, 24, 16, 16, mouseX, mouseY) && itemstack2 != null)
{
this.renderToolTip(itemstack2, mouseX, mouseY);
}
// else if (merchantrecipe.isRecipeDisabled() && (this.isPointInRegion(83, 21, 28, 21, mouseX, mouseY) || this.isPointInRegion(83, 51, 28, 21, mouseX, mouseY)))
// {
// this.drawCreativeTabHoveringText(I18n.format("merchant.deprecated"), mouseX, mouseY);
// }
GL11.glPopMatrix();
GlState.enableLighting();
GlState.enableDepth();
ItemRenderer.enableStandardItemLighting();
// int i = (this.width - this.xSize) / 2;
// int j = (this.height - this.ySize) / 2;
// if(mouseX >= i + 147 && mouseX < i + 147 + 12 && mouseY >= j + 23 && mouseX < j + 23 + 19) {
// SKC.highlight(i + 147, j + 23, 12, 19);
// }
// else if(mouseX >= i + 17 && mouseX < i + 17 + 12 && mouseY >= j + 23 && mouseX < j + 23 + 19) {
// SKC.highlight(i + 17, j + 23, 12, 19);
// }
}
}
public void setRecipes(MerchantRecipeList recipes)
{
((ContainerMerchant)this.inventorySlots).getMerchantInventory().setRecipes(recipes);
}
private MerchantRecipeList getRecipes()
{
return ((ContainerMerchant)this.inventorySlots).getMerchantInventory().getRecipes();
}
// static class MerchantButton extends Button
// {
// private final boolean next;
//
// public MerchantButton(int buttonID, int x, int y, boolean isNext)
// {
// super(buttonID, x, y, 12, 19, "");
// this.next = isNext;
// }
//
// public void drawButton(Game gm, int mouseX, int mouseY)
// {
// if (this.visible)
// {
// gm.getTextureManager().bindTexture(GuiMerchant.MERCHANT_GUI_TEXTURE);
// GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
// boolean flag = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
// int i = 0;
// int j = 176;
//
// if (!this.enabled)
// {
// j += this.width * 2;
// }
// else if (flag)
// {
// j += this.width;
// }
//
// if (!this.next)
// {
// i += this.height;
// }
//
// this.rect(this.xPosition, this.yPosition, j, i, this.width, this.height);
// }
// }
// }
}

View file

@ -0,0 +1,218 @@
package client.gui.container;
import java.util.List;
import client.Game;
import common.inventory.Container;
import common.inventory.ContainerRepair;
import common.inventory.ICrafting;
import common.inventory.IInventory;
import common.inventory.InventoryPlayer;
import common.item.ItemStack;
import common.world.World;
public class GuiRepair extends GuiContainer implements ICrafting
{
// private static final String anvilResource = "textures/gui/anvil.png";
private ContainerRepair anvil;
// private TextField nameField;
private InventoryPlayer playerInventory;
public GuiRepair(InventoryPlayer inventoryIn, World worldIn)
{
super(new ContainerRepair(inventoryIn, worldIn, Game.getGame().thePlayer));
this.playerInventory = inventoryIn;
this.anvil = (ContainerRepair)this.inventorySlots;
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
super.initGui();
// Keyboard.enableRepeatEvents(true);
// int i = (this.width - this.xSize) / 2;
// int j = (this.height - this.ySize) / 2;
// this.nameField = new TextField(i + 62, j + 24, 103, 12);
// this.nameField.setTextColor(-1);
// this.nameField.setDisabledTextColour(-1);
// this.nameField.setEnableBackgroundDrawing(false);
// this.nameField.setMaxStringLength(30);
this.inventorySlots.removeCraftingFromCrafters(this);
this.inventorySlots.onCraftGuiOpened(this);
}
/**
* Called when the screen is unloaded. Used to disable keyboard repeat events
*/
public void onGuiClosed()
{
super.onGuiClosed();
// Keyboard.enableRepeatEvents(false);
this.inventorySlots.removeCraftingFromCrafters(this);
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY
*/
public void drawGuiContainerForegroundLayer()
{
// GlState.disableLighting();
// GlState.disableBlend();
this.drawString("Amboss", 60, 6);
if (this.anvil.maximumCost > 0)
{
int i = 8453920;
boolean flag = true;
String s = String.format("Erfahrungskosten: %d", this.anvil.maximumCost);
if (this.anvil.maximumCost >= 40) // && !this.gm.thePlayer.creative)
{
s = "Zu teuer!";
i = 16736352;
}
else if (!this.anvil.getSlot(2).getHasStack())
{
flag = false;
}
else if (!this.anvil.getSlot(2).canTakeStack(this.playerInventory.player))
{
i = 16736352;
}
if (flag)
{
int j = -16777216 | (i & 16579836) >> 2 | i & -16777216;
int k = this.xSize - 8 - this.getStringWidth(s);
int l = 67;
// if (FontRenderer.getUnicodeFlag())
// {
// drawRect(k - 3, l - 2, this.xSize - 7, l + 10, -16777216);
// drawRect(k - 2, l - 1, this.xSize - 8, l + 9, -12895429);
// }
// else
// {
this.drawString(s, k, l + 1);
this.drawString(s, k + 1, l);
this.drawString(s, k + 1, l + 1);
// }
this.drawString(s, k, l);
}
}
// GlState.enableLighting();
}
/**
* Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
* KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
*/
// protected void keyTyped(char typedChar, int keyCode)
// {
// if (this.nameField.textboxKeyTyped(typedChar, keyCode))
//// {
// this.renameItem();
//// }
//// else
//// {
//// super.keyTyped(typedChar, keyCode);
//// }
// }
//
// private void renameItem()
// {
// String s = this.nameField.getText();
// Slot slot = this.anvil.getSlot(0);
//
// if (slot != null && slot.getHasStack() && !slot.getStack().hasDisplayName() && s.equals(slot.getStack().getDisplayName()))
// {
// s = "";
// }
//
// this.anvil.updateItemName(s);
// this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketMessage(CPacketMessage.Type.ITEM, s));
// }
//
// /**
// * Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
// */
// protected void mouseClicked(int mouseX, int mouseY, int mouseButton)
// {
// super.mouseClicked(mouseX, mouseY, mouseButton);
// this.nameField.mouseClicked(mouseX, mouseY, mouseButton);
// }
/**
* Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
*/
// public void drawScreen(int mouseX, int mouseY, float partialTicks)
// {
// super.drawScreen(mouseX, mouseY, partialTicks);
// GlState.disableLighting();
// GlState.disableBlend();
// this.nameField.drawTextBox();
// }
// /**
// * Args : renderPartialTicks, mouseX, mouseY
// */
// protected void drawGuiContainerBackgroundLayer(int mouseX, int mouseY)
// {
// GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
// this.gm.getTextureManager().bindTexture(anvilResource);
// int i = (this.width - this.xSize) / 2;
// int j = (this.height - this.ySize) / 2;
//// this.rect(i, j, 0, 0, this.xSize, this.ySize);
//// this.rect(i + 59, j + 20, 0, this.ySize + (this.anvil.getSlot(0).getHasStack() ? 0 : 16), 110, 16);
//
//// if ((this.anvil.getSlot(0).getHasStack() || this.anvil.getSlot(1).getHasStack()) && !this.anvil.getSlot(2).getHasStack())
//// {
//// this.rect(i + 99, j + 45, this.xSize, 0, 28, 21);
//// }
// }
/**
* update the crafting window inventory with the items in the list
*/
public void updateCraftingInventory(Container containerToSend, List<ItemStack> itemsList)
{
this.sendSlotContents(containerToSend, 0, containerToSend.getSlot(0).getStack());
}
/**
* Sends the contents of an inventory slot to the client-side Container. This doesn't have to match the actual
* contents of that slot. Args: Container, slot number, slot contents
*/
public void sendSlotContents(Container containerToSend, int slotInd, ItemStack stack)
{
// if (slotInd == 0)
// {
// this.nameField.setText(stack == null ? "" : stack.getDisplayName());
// this.nameField.setEnabled(stack != null);
//
// if (stack != null)
// {
// this.renameItem();
// }
// }
}
/**
* Sends two ints to the client-side Container. Used for furnace burning time, smelting progress, brewing progress,
* and enchanting level. Normally the first int identifies which variable to update, and the second contains the new
* value. Both are truncated to shorts in non-local SMP.
*/
public void sendProgressBarUpdate(Container containerIn, int varToUpdate, int newValue)
{
}
public void sendAllWindowProperties(Container p_175173_1_, IInventory p_175173_2_)
{
}
}

View file

@ -0,0 +1,34 @@
package client.gui.element;
import client.gui.Formatter;
import client.window.Button;
public class ActButton extends Element {
public static enum Mode {
PRIMARY, SECONDARY, TERTIARY;
}
public static interface Callback {
void use(ActButton elem, Mode action);
}
private final Callback func;
public ActButton(int x, int y, int w, int h, Callback callback, Formatter<ActButton> formatter) {
super(x, y, w, h, formatter);
this.func = callback;
this.formatText();
}
public ActButton(int x, int y, int w, int h, Callback callback, String text) {
super(x, y, w, h, null);
this.func = callback;
this.setText(text);
}
public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift) {
this.func.use(this, (ctrl || (btn == Button.MOUSE_MIDDLE)) ? Mode.TERTIARY : ((shift || (btn == Button.MOUSE_RIGHT)) ? Mode.SECONDARY : Mode.PRIMARY));
this.formatText();
this.playSound();
}
}

View file

@ -12,12 +12,12 @@ import common.util.Util;
public class Dropdown<T> extends Element {
public class Handle extends Element {
private Handle(boolean up) {
super(Dropdown.this.pos_x, Dropdown.this.pos_y + (up ? -(Font.HEIGHT * Dropdown.this.values.length + 2) : Dropdown.this.size_y), Dropdown.this.size_x, Font.HEIGHT * Dropdown.this.values.length + 2, null);
super(Dropdown.this.pos_x, Dropdown.this.pos_y + (up ? -(Font.YGLYPH * Dropdown.this.values.length + 2) : Dropdown.this.size_y), Dropdown.this.size_x, Font.YGLYPH * Dropdown.this.values.length + 2, null);
StringBuilder sb = new StringBuilder();
for(T value : Dropdown.this.values) {
if(sb.length() > 0)
sb.append('\n');
sb.append(value instanceof Displayable disp ? disp.getDisplay() : value.toString());
sb.append(value instanceof Displayable ? ((Displayable)value).getDisplay() : value.toString());
}
this.setText(sb.toString());
this.visible = /* this.r_dirty = */ false;
@ -58,20 +58,24 @@ public class Dropdown<T> extends Element {
}
public void drawHover() {
int m = ((this.gm.mouseY - (this.pos_y + this.margin_y1)) * Dropdown.this.values.length / (this.size_y - (this.margin_y1 + this.margin_y2)));
int m = ((this.gm.mouse_y - (this.pos_y + this.margin_y1)) * Dropdown.this.values.length / (this.size_y - (this.margin_y1 + this.margin_y2)));
// if((sys.mouse_y - this.pos_y) < (this.size_y - this.margin_y2))
Drawing.drawRect(this.pos_x + this.margin_x1, this.pos_y + this.margin_y1 + ExtMath.clampi(m, 0, Dropdown.this.values.length - 1) * ((this.size_y - (this.margin_y1 + this.margin_y2)) / Dropdown.this.values.length), this.size_x - (this.margin_x1 + this.margin_x2), (this.size_y - (this.margin_y1 + this.margin_y2)) / Dropdown.this.values.length, Gui.HOVER_COLOR);
}
}
private final DropdownCallback<T> func;
public static interface Callback<T> {
void use(Dropdown<T> elem, T value);
}
private final Callback<T> func;
private final T[] values;
private final Handle handle;
private final int def;
private int value;
public Dropdown(int x, int y, int w, int h, boolean up, T[] values, T def, T init, DropdownCallback<T> callback, Formatter<Dropdown<T>> formatter) {
public Dropdown(int x, int y, int w, int h, boolean up, T[] values, T def, T init, Callback<T> callback, Formatter<Dropdown<T>> formatter) {
super(x, y, w, h, formatter);
this.func = callback;
this.values = values;
@ -81,16 +85,11 @@ public class Dropdown<T> extends Element {
this.formatText();
}
public Dropdown(int x, int y, int w, int h, boolean up, T[] values, T def, T init, DropdownCallback<T> callback, final String text) {
this(x, y, w, h, up, values, def, init, callback, text == null ? new Formatter<Dropdown<T>>() {
public Dropdown(int x, int y, int w, int h, boolean up, T[] values, T def, T init, Callback<T> callback, final String text) {
this(x, y, w, h, up, values, def, init, callback, new Formatter<Dropdown<T>>() {
public String use(Dropdown<T> elem) {
T value = elem.getValue();
return value instanceof Displayable disp ? disp.getDisplay() : value.toString();
}
} : new Formatter<Dropdown<T>>() {
public String use(Dropdown<T> elem) {
T value = elem.getValue();
return String.format("%s: %s", text, value instanceof Displayable disp ? disp.getDisplay() : value.toString());
return String.format("%s: %s", text, value instanceof Displayable ? ((Displayable)value).getDisplay() : value.toString());
}
});
}

View file

@ -2,7 +2,7 @@ package client.gui.element;
import org.lwjgl.opengl.GL11;
import client.Client;
import client.Game;
import client.gui.Formatter;
import client.gui.Gui;
import client.renderer.Drawing;
@ -15,9 +15,7 @@ import common.sound.PositionedSound;
import common.util.Util;
public abstract class Element {
public static final int BASE_HEIGHT = 18;
protected final Client gm = Client.CLIENT;
protected final Game gm = Game.getGame();
protected Gui gui;
protected Formatter format;
@ -38,11 +36,12 @@ public abstract class Element {
public boolean visible = true;
public boolean enabled = true;
public Element(int x, int y, int w, int h, Formatter formatter) {
this.pos_x = x;
this.pos_y = y;
this.size_x = w;
this.size_y = h <= 0 ? BASE_HEIGHT : h;
this.size_y = h;
this.format = formatter;
// gui_update_style(this, 1);
// if(type != ElemType.SLIDER) {
@ -113,8 +112,8 @@ public abstract class Element {
public void updateText() {
Vec2i size = Drawing.getSize(this.text);
this.text_x = ((this.size_x - (this.margin_x1 + this.margin_x2)) - size.xpos) / 2;
this.text_y = ((this.size_y - (this.margin_y1 + this.margin_y2)) - size.ypos + 1) / 2;
this.text_x = (this.size_x - size.xpos) / 2;
this.text_y = (this.size_y - size.ypos) / 2;
}
public void setText(String str) {
@ -221,7 +220,7 @@ public abstract class Element {
int x2 = this.size_x - (this.margin_x1 + this.margin_x2);
int y2 = this.size_y - (this.margin_y1 + this.margin_y2);
// if(elem.type == ElemType.FIELD) {
this.gm.scissor(x1 < 0 ? 0 : x1, (this.gm.fbY - (y1 + y2)) < 0 ? 0 : (this.gm.fbY - (y1 + y2)), x2 < 0 ? 0 : x2, y2 < 0 ? 0 : y2);
GL11.glScissor(x1 < 0 ? 0 : x1, (this.gm.fb_y - (y1 + y2)) < 0 ? 0 : (this.gm.fb_y - (y1 + y2)), x2 < 0 ? 0 : x2, y2 < 0 ? 0 : y2);
GL11.glEnable(GL11.GL_SCISSOR_TEST);
// }
// if(this.type == ElemType.CUSTOM)

View file

@ -50,8 +50,8 @@ public class Fill extends Element {
public void updateText() {
Vec2i size = Drawing.getSize(this.text);
if(!this.left)
this.text_x = ((this.size_x - (this.margin_x1 + this.margin_x2)) - size.xpos) / 2;
this.text_x = (this.size_x - size.xpos) / 2;
if(!this.top)
this.text_y = ((this.size_y - (this.margin_y1 + this.margin_y2)) - size.ypos + 1) / 2;
this.text_y = (this.size_y - size.ypos) / 2;
}
}

View file

@ -0,0 +1,413 @@
package client.gui.element;
import java.util.List;
import org.lwjgl.opengl.GL11;
import client.gui.Gui;
import client.renderer.DefaultVertexFormats;
import client.renderer.Drawing;
import client.renderer.GlState;
import client.renderer.RenderBuffer;
import client.renderer.Tessellator;
import client.window.Button;
import common.collect.Lists;
import common.util.ExtMath;
public abstract class GuiList<T extends ListEntry> extends Gui
{
protected final List<T> elements = Lists.newArrayList();
protected int width;
protected int height;
protected int top;
protected int bottom;
protected int right;
protected int left;
protected int mouseX;
protected int mouseY;
protected int initialClickY = -2;
protected float scrollMultiplier;
protected float amountScrolled;
protected int selectedElement = -1;
protected long lastClicked;
public abstract int getListWidth(); // 220
public abstract int getSlotHeight();
protected int getScrollBarX()
{
return 0;
}
public void setDimensions(int widthIn, int heightIn, int topIn, int bottomIn)
{
this.width = widthIn;
this.height = heightIn;
this.top = topIn;
this.bottom = bottomIn;
this.left = 0;
this.right = widthIn;
}
public void init(int width, int height) {
this.selectedElement = -1;
}
public void setSlotXBoundsFromLeft(int leftIn)
{
this.left = leftIn;
this.right = leftIn + this.width;
}
public final T getListEntry(int index) {
return this.elements.get(index);
}
public final T getSelected() {
return this.selectedElement < 0 ? null : this.elements.get(this.selectedElement);
}
public final int getSize() {
return this.elements.size();
}
public final void setSelected(int index) {
this.selectedElement = index;
}
protected int getContentHeight()
{
return this.getSize() * this.getSlotHeight();
}
public int getSlotIndexFromScreenCoords(int x, int y)
{
int i = this.left + this.width / 2 - this.getListWidth() / 2;
int j = this.left + this.width / 2 + this.getListWidth() / 2;
int k = y - this.top + (int)this.amountScrolled - 4;
int l = k / this.getSlotHeight();
return this.isInList(x, y) && x >= i && x <= j && l >= 0 && k >= 0 && l < this.getSize() ? l : -1;
}
protected boolean isInList(int x, int y)
{
return x >= this.getScrollBarX() + 6; // x < this.getScrollBarX();
}
protected final boolean isSelected(int slotIndex)
{
return slotIndex == this.selectedElement;
}
protected void bindAmountScrolled()
{
this.amountScrolled = ExtMath.clampf(this.amountScrolled, 0.0F, (float)this.getMaxScroll());
}
public int getMaxScroll()
{
return Math.max(0, this.getContentHeight() - (this.bottom - this.top - 4));
}
public int getAmountScrolled()
{
return (int)this.amountScrolled;
}
public boolean isMouseYWithinSlotBounds(int p_148141_1_)
{
return p_148141_1_ >= this.top && p_148141_1_ <= this.bottom && this.mouseX >= this.left && this.mouseX <= this.right;
}
public void scrollBy(int amount)
{
this.amountScrolled += (float)amount;
this.bindAmountScrolled();
this.initialClickY = -2;
}
// public void actionPerformed(Button button)
// {
// if (button.enabled)
// {
// if (button.id == this.scrollUpButtonID)
// {
// this.amountScrolled -= (float)(this.slotHeight * 2 / 3);
// this.initialClickY = -2;
// this.bindAmountScrolled();
// }
// else if (button.id == this.scrollDownButtonID)
// {
// this.amountScrolled += (float)(this.slotHeight * 2 / 3);
// this.initialClickY = -2;
// this.bindAmountScrolled();
// }
// }
// }
public void draw()
{
int mouseXIn = this.gm.mouse_x;
int mouseYIn = this.gm.mouse_y;
this.mouseX = mouseXIn;
this.mouseY = mouseYIn;
this.drawBackground();
int i = this.getScrollBarX();
int j = i + 6;
this.bindAmountScrolled();
GlState.disableLighting();
GlState.disableFog();
GlState.enableTexture2D();
RenderBuffer worldrenderer = Tessellator.getBuffer();
this.gm.getTextureManager().bindTexture(Gui.DIRT_BACKGROUND);
GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
float f = 32.0F;
worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
worldrenderer.pos((double)0, (double)this.bottom, 0.0D).tex((double)((float)0 / f), (double)((float)(this.bottom + (int)this.amountScrolled) / f)).color(32, 32, 32, 255).endVertex();
worldrenderer.pos((double)this.gm.fb_x, (double)this.bottom, 0.0D).tex((double)((float)this.gm.fb_x / f), (double)((float)(this.bottom + (int)this.amountScrolled) / f)).color(32, 32, 32, 255).endVertex();
worldrenderer.pos((double)this.gm.fb_x, (double)this.top, 0.0D).tex((double)((float)this.gm.fb_x / f), (double)((float)(this.top + (int)this.amountScrolled) / f)).color(32, 32, 32, 255).endVertex();
worldrenderer.pos((double)0, (double)this.top, 0.0D).tex((double)((float)0 / f), (double)((float)(this.top + (int)this.amountScrolled) / f)).color(32, 32, 32, 255).endVertex();
Tessellator.draw();
int x = this.left + this.width / 2 - this.getListWidth() / 2 + 2;
int y = this.top + 4 - (int)this.amountScrolled;
this.drawSelectionBox(x, y, mouseXIn, mouseYIn);
GlState.disableDepth();
this.overlayBackground(0, this.top, 255, 255);
this.overlayBackground(this.bottom, this.height, 255, 255);
GlState.enableBlend();
GlState.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ZERO, GL11.GL_ONE);
GlState.disableAlpha();
GlState.shadeModel(GL11.GL_SMOOTH);
GlState.disableTexture2D();
int i1 = 4;
worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
worldrenderer.pos((double)0, (double)(this.top + i1), 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 0).endVertex();
worldrenderer.pos((double)this.gm.fb_x, (double)(this.top + i1), 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 0).endVertex();
worldrenderer.pos((double)this.gm.fb_x, (double)this.top, 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex();
worldrenderer.pos((double)0, (double)this.top, 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex();
Tessellator.draw();
worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
worldrenderer.pos((double)0, (double)this.bottom, 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 255).endVertex();
worldrenderer.pos((double)this.gm.fb_x, (double)this.bottom, 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 255).endVertex();
worldrenderer.pos((double)this.gm.fb_x, (double)(this.bottom - i1), 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 0).endVertex();
worldrenderer.pos((double)0, (double)(this.bottom - i1), 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 0).endVertex();
Tessellator.draw();
int j1 = this.getMaxScroll();
if (j1 > 0)
{
int k1 = (this.bottom - this.top) * (this.bottom - this.top) / this.getContentHeight();
k1 = ExtMath.clampi(k1, 32, this.bottom - this.top - 8);
int l1 = (int)this.amountScrolled * (this.bottom - this.top - k1) / j1 + this.top;
if (l1 < this.top)
{
l1 = this.top;
}
worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
worldrenderer.pos((double)i, (double)this.bottom, 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 255).endVertex();
worldrenderer.pos((double)j, (double)this.bottom, 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 255).endVertex();
worldrenderer.pos((double)j, (double)this.top, 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex();
worldrenderer.pos((double)i, (double)this.top, 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex();
Tessellator.draw();
worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
worldrenderer.pos((double)i, (double)(l1 + k1), 0.0D).tex(0.0D, 1.0D).color(128, 128, 128, 255).endVertex();
worldrenderer.pos((double)j, (double)(l1 + k1), 0.0D).tex(1.0D, 1.0D).color(128, 128, 128, 255).endVertex();
worldrenderer.pos((double)j, (double)l1, 0.0D).tex(1.0D, 0.0D).color(128, 128, 128, 255).endVertex();
worldrenderer.pos((double)i, (double)l1, 0.0D).tex(0.0D, 0.0D).color(128, 128, 128, 255).endVertex();
Tessellator.draw();
worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
worldrenderer.pos((double)i, (double)(l1 + k1 - 1), 0.0D).tex(0.0D, 1.0D).color(192, 192, 192, 255).endVertex();
worldrenderer.pos((double)(j - 1), (double)(l1 + k1 - 1), 0.0D).tex(1.0D, 1.0D).color(192, 192, 192, 255).endVertex();
worldrenderer.pos((double)(j - 1), (double)l1, 0.0D).tex(1.0D, 0.0D).color(192, 192, 192, 255).endVertex();
worldrenderer.pos((double)i, (double)l1, 0.0D).tex(0.0D, 0.0D).color(192, 192, 192, 255).endVertex();
Tessellator.draw();
}
GlState.enableTexture2D();
GlState.shadeModel(GL11.GL_FLAT);
GlState.enableAlpha();
GlState.disableBlend();
super.draw();
}
public void handleMouseInput()
{
if (this.isMouseYWithinSlotBounds(this.mouseY))
{
// if (Button.MOUSE_LEFT.isDown() && this.getEnabled())
// {
if (this.initialClickY == -1)
{
boolean flag1 = true;
if (this.mouseY >= this.top && this.mouseY <= this.bottom)
{
int j2 = (this.width - this.getListWidth()) / 2;
int k2 = (this.width + this.getListWidth()) / 2;
int l2 = this.mouseY - this.top + (int)this.amountScrolled - 4;
int i1 = l2 / this.getSlotHeight();
if (i1 < this.getSize() && this.mouseX >= j2 && this.mouseX <= k2 && i1 >= 0 && l2 >= 0)
{
}
else if (this.mouseX >= j2 && this.mouseX <= k2 && l2 < 0)
{
flag1 = false;
}
int i3 = this.getScrollBarX();
int j1 = i3 + 6;
if (this.mouseX >= i3 && this.mouseX <= j1)
{
this.scrollMultiplier = -1.0F;
int k1 = this.getMaxScroll();
if (k1 < 1)
{
k1 = 1;
}
int l1 = (int)((float)((this.bottom - this.top) * (this.bottom - this.top)) / (float)this.getContentHeight());
l1 = ExtMath.clampi(l1, 32, this.bottom - this.top - 8);
this.scrollMultiplier /= (float)(this.bottom - this.top - l1) / (float)k1;
}
else
{
this.scrollMultiplier = 1.0F;
}
if (flag1)
{
this.initialClickY = this.mouseY;
}
else
{
this.initialClickY = -2;
}
}
else
{
this.initialClickY = -2;
}
}
else if (this.initialClickY >= 0)
{
this.amountScrolled -= (float)(this.mouseY - this.initialClickY) * this.scrollMultiplier;
this.initialClickY = this.mouseY;
}
// }
// else
// {
// this.initialClickY = -1;
// }
}
}
protected void drawSelectionBox(int x, int y, int mouseXIn, int mouseYIn)
{
int size = this.getSize();
RenderBuffer rb = Tessellator.getBuffer();
for (int z = 0; z < size; z++)
{
int y1 = y + z * this.getSlotHeight();
int h = this.getSlotHeight() - 4;
if (this.isSelected(z))
{
int x1 = this.left + (this.width / 2 - this.getListWidth() / 2);
int x2 = this.left + this.width / 2 + this.getListWidth() / 2;
GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
GlState.disableTexture2D();
rb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
rb.pos((double)x1, (double)(y1 + h + 2), 0.0D).tex(0.0D, 1.0D).color(128, 128, 128, 255).endVertex();
rb.pos((double)x2, (double)(y1 + h + 2), 0.0D).tex(1.0D, 1.0D).color(128, 128, 128, 255).endVertex();
rb.pos((double)x2, (double)(y1 - 2), 0.0D).tex(1.0D, 0.0D).color(128, 128, 128, 255).endVertex();
rb.pos((double)x1, (double)(y1 - 2), 0.0D).tex(0.0D, 0.0D).color(128, 128, 128, 255).endVertex();
rb.pos((double)(x1 + 1), (double)(y1 + h + 1), 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 255).endVertex();
rb.pos((double)(x2 - 1), (double)(y1 + h + 1), 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 255).endVertex();
rb.pos((double)(x2 - 1), (double)(y1 - 1), 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex();
rb.pos((double)(x1 + 1), (double)(y1 - 1), 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex();
Tessellator.draw();
GlState.enableTexture2D();
}
boolean hover = this.getSlotIndexFromScreenCoords(mouseXIn, mouseYIn) == z;
this.getListEntry(z).draw(x, y1, mouseXIn - x, mouseYIn - y1, hover);
if(hover)
Drawing.drawRect(x - 2, y1 - 2, this.getListWidth(), this.getSlotHeight(), Gui.HOVER_COLOR);
}
}
protected void overlayBackground(int startY, int endY, int startAlpha, int endAlpha)
{
RenderBuffer rb = Tessellator.getBuffer();
this.gm.getTextureManager().bindTexture(Gui.DIRT_BACKGROUND);
GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
float f = 32.0F;
rb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
rb.pos((double)0, (double)endY, 0.0D).tex(0.0D, (double)((float)endY / 32.0F)).color(64, 64, 64, endAlpha).endVertex();
rb.pos((double)this.gm.fb_x, (double)endY, 0.0D).tex((double)((float)this.gm.fb_x / 32.0F), (double)((float)endY / 32.0F)).color(64, 64, 64, endAlpha).endVertex();
rb.pos((double)this.gm.fb_x, (double)startY, 0.0D).tex((double)((float)this.gm.fb_x / 32.0F), (double)((float)startY / 32.0F)).color(64, 64, 64, startAlpha).endVertex();
rb.pos((double)0, (double)startY, 0.0D).tex(0.0D, (double)((float)startY / 32.0F)).color(64, 64, 64, startAlpha).endVertex();
Tessellator.draw();
}
public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift)
{
super.mouse(btn, x, y, ctrl, shift);
if (this.isMouseYWithinSlotBounds(y))
{
int i = this.getSlotIndexFromScreenCoords(x, y);
if (i >= 0)
{
int j = this.left + this.width / 2 - this.getListWidth() / 2 + 2;
int k = this.top + 4 - this.getAmountScrolled() + i * this.getSlotHeight();
int l = x - j;
int i1 = y - k;
boolean flag = i == this.selectedElement && System.currentTimeMillis() - this.lastClicked < (long)this.gm.dclickDelay;
this.selectedElement = i;
this.lastClicked = System.currentTimeMillis();
this.getListEntry(i).select(flag, l, i1);
}
}
if(btn == Button.MOUSE_LEFT && this.clicked(x, y) == null)
this.handleMouseInput();
}
public void mouserel(Button btn, int x, int y) {
super.mouserel(btn, x, y);
if(btn == Button.MOUSE_LEFT)
this.initialClickY = -1;
}
public void scroll(int scr_x, int scr_y, int x, int y, boolean ctrl, boolean shift) {
super.scroll(scr_x, scr_y, x, y, ctrl, shift);
if(scr_y != 0 && this.clicked(x, y) == null)
this.amountScrolled -= (float)(ExtMath.clampi(scr_y, -1, 1) * this.getSlotHeight() / 2);
}
public void drag(int x, int y) {
super.drag(x, y);
if(this.selected == null && Button.MOUSE_LEFT.isDown())
this.handleMouseInput();
}
}

View file

@ -0,0 +1,17 @@
package client.gui.element;
import client.renderer.Drawing;
public class InventoryButton extends Element {
public InventoryButton(int x, int y, int w, int h) {
super(x, y, w, h, null);
}
protected void drawBackground() {
// Drawing.drawRect2Border(this.pos_x, this.pos_y, this.size_x, this.size_y, 0xff6f6f6f, 0xffafafaf);
Drawing.drawRectBorder(this.pos_x, this.pos_y, this.size_x, this.size_y, 0xff6f6f6f, 0xff000000, 0xffafafaf, 0xff4f4f4f);
}
protected void drawForeground(int x1, int y1, int x2, int y2) {
}
}

View file

@ -0,0 +1,33 @@
package client.gui.element;
import client.renderer.Drawing;
import common.util.Util;
public class Label extends Fill {
public Label(int x, int y, int w, int h, String text, boolean top, boolean left) {
super(x, y, w, h, text, top, left);
}
public Label(int x, int y, int w, int h, String text, boolean left) {
super(x, y, w, h, text, left);
}
public Label(int x, int y, int w, int h, String text) {
super(x, y, w, h, text);
}
protected void drawBackground() {
}
protected void drawForeground(int x1, int y1, int x2, int y2) {
Drawing.drawText(this.text, x1 + this.text_x, y1 + this.text_y, this.enabled ? this.gm.style.text_label : Util.mulColor(this.gm.style.text_label, 0.5f));
}
protected int getMarginX() {
return 0;
}
protected int getMarginY() {
return 0;
}
}

View file

@ -0,0 +1,7 @@
package client.gui.element;
public interface ListEntry
{
void draw(int x, int y, int mouseX, int mouseY, boolean hovered);
void select(boolean dclick, int mx, int my);
}

View file

@ -1,6 +1,6 @@
package client.gui.element;
import client.Client;
import client.Game;
import client.gui.Gui;
import client.renderer.Drawing;
import common.util.Util;
@ -9,9 +9,9 @@ public class NavButton extends ActButton {
private final Gui navGui;
public NavButton(int x, int y, int w, int h, Gui gui, String text) {
super(x, y, w, h, new ButtonCallback() {
public void use(ActButton elem, PressType action) {
Client.CLIENT.show(gui);
super(x, y, w, h, new Callback() {
public void use(ActButton elem, Mode action) {
Game.getGame().displayGuiScreen(gui);
}
}, text);
this.navGui = gui;

View file

@ -6,7 +6,7 @@ import common.util.Util;
public class SelectableButton extends ActButton {
private boolean selected;
public SelectableButton(int x, int y, int w, int h, ButtonCallback callback, String text, boolean selected) {
public SelectableButton(int x, int y, int w, int h, Callback callback, String text, boolean selected) {
super(x, y, w, h, callback, text);
this.selected = selected;
}

View file

@ -7,9 +7,17 @@ import common.util.ExtMath;
import common.util.Util;
public class Slider extends Element {
private static final int SLIDER_WIDTH = 8;
public static interface Callback {
void use(Slider elem, int value);
}
public static interface FloatCallback {
void use(Slider elem, float value);
}
private final SliderCallback func;
private static final int SLIDER_WIDTH = 10;
private final Callback func;
private final int def;
private final int min;
private final int max;
@ -19,9 +27,9 @@ public class Slider extends Element {
private int value;
private int position;
public Slider(int x, int y, int w, int h, int prec, int min, int max, int def, int init, SliderCallback callback, Formatter<Slider> formatter) {
public Slider(int x, int y, int w, int h, int prec, int min, int max, int def, int init, Callback callback, Formatter<Slider> formatter) {
super(x, y, w, h, formatter);
this.handle = ((this.size_y * SLIDER_WIDTH) / BASE_HEIGHT) & ~1;
this.handle = ((this.size_y * SLIDER_WIDTH) / 24) & ~1;
this.func = callback;
this.precision = prec;
this.min = min;
@ -32,7 +40,7 @@ public class Slider extends Element {
this.formatText();
}
public Slider(int x, int y, int w, int h, int prec, int min, int max, int def, int init, SliderCallback callback, final String text) {
public Slider(int x, int y, int w, int h, int prec, int min, int max, int def, int init, Callback callback, final String text) {
this(x, y, w, h, prec, min, max, def, init, callback, new Formatter<Slider>() {
public String use(Slider elem) {
return String.format("%s: %d", text, elem.value);
@ -40,7 +48,7 @@ public class Slider extends Element {
});
}
public Slider(int x, int y, int w, int h, int prec, int min, int max, int def, int init, SliderCallback callback, final String text, final String unit) {
public Slider(int x, int y, int w, int h, int prec, int min, int max, int def, int init, Callback callback, final String text, final String unit) {
this(x, y, w, h, prec, min, max, def, init, callback, new Formatter<Slider>() {
private final String format = unit.isEmpty() ? "%s: %d" : "%s: %d %s";
@ -50,15 +58,15 @@ public class Slider extends Element {
});
}
public Slider(int x, int y, int w, int h, int prec, float min, float max, float def, float init, final SliderFloatCallback callback, Formatter<Slider> formatter) {
this(x, y, w, h, prec, (int)(min * 1000.0f), (int)(max * 1000.0f), (int)(def * 1000.0f), (int)(init * 1000.0f), new SliderCallback() {
public Slider(int x, int y, int w, int h, int prec, float min, float max, float def, float init, final FloatCallback callback, Formatter<Slider> formatter) {
this(x, y, w, h, prec, (int)(min * 1000.0f), (int)(max * 1000.0f), (int)(def * 1000.0f), (int)(init * 1000.0f), new Callback() {
public void use(Slider elem, int value) {
callback.use(elem, (float)value / 1000.0f);
}
}, formatter);
}
public Slider(int x, int y, int w, int h, final int prec, float min, float max, float def, float init, SliderFloatCallback callback, final String text, final String unit) {
public Slider(int x, int y, int w, int h, final int prec, float min, float max, float def, float init, FloatCallback callback, final String text, final String unit) {
this(x, y, w, h, prec < 0 ? 0 : prec, min, max, def, init, callback, new Formatter<Slider>() {
private final String format = "%s: " + (prec <= 0 ? "%d" : ("%." + prec + "f")) + (unit.isEmpty() ? "" : " %s");

View file

@ -6,13 +6,17 @@ import common.util.Displayable;
import common.util.Util;
public class Switch<T> extends Element {
private final SwitchCallback<T> func;
public static interface Callback<T> {
void use(Switch<T> elem, T value);
}
private final Callback<T> func;
private final T[] values;
private final int def;
private int value;
public Switch(int x, int y, int w, int h, T[] values, T def, T init, SwitchCallback<T> callback, Formatter<Switch<T>> formatter) {
public Switch(int x, int y, int w, int h, T[] values, T def, T init, Callback<T> callback, Formatter<Switch<T>> formatter) {
super(x, y, w, h, formatter);
this.func = callback;
this.values = values;
@ -21,11 +25,11 @@ public class Switch<T> extends Element {
this.formatText();
}
public Switch(int x, int y, int w, int h, T[] values, T def, T init, SwitchCallback<T> callback, final String text) {
public Switch(int x, int y, int w, int h, T[] values, T def, T init, Callback<T> callback, final String text) {
this(x, y, w, h, values, def, init, callback, new Formatter<Switch<T>>() {
public String use(Switch<T> elem) {
T value = elem.getValue();
return String.format("%s: %s", text, value instanceof Displayable disp ? disp.getDisplay() : value.toString());
return String.format("%s: %s", text, value instanceof Displayable ? ((Displayable)value).getDisplay() : value.toString());
}
});
}

View file

@ -0,0 +1,514 @@
package client.gui.element;
import org.lwjgl.opengl.GL11;
import client.Timing;
import client.gui.Font;
import client.renderer.Drawing;
import client.renderer.Drawing.Offset;
import client.renderer.Drawing.Vec2i;
import client.window.Button;
import client.window.Keysym;
import client.window.Window;
import common.util.CharValidator;
import common.util.ExtMath;
import common.util.Util;
public class Textbox extends Element {
public static enum Action {
FOCUS, UNFOCUS, PREVIOUS, NEXT, FUNCTION, SEND, LINE, FORWARD, BACKWARD;
}
public static interface Callback {
void use(Textbox elem, Action value);
}
private final Callback func;
private final CharValidator validator;
private final int capacity;
private final boolean xbreak;
private final boolean editable;
private long tmr_scroll;
private long tmr_leftmb;
private int scrollx;
private int scrolly;
private int sel_start = -1;
private int sel_end = -1;
private int sel_drag = -1;
private int cursorX = 0;
private int cursorY = 0;
private int tsize_x = 0;
private int tsize_y = 0;
private Textbox(int x, int y, int w, int h, int cap, boolean line, boolean editable, Callback callback, CharValidator validator, String text) {
super(x, y, w, h, null);
this.func = callback;
this.validator = validator;
this.capacity = cap;
this.xbreak = !line;
this.editable = editable;
if(line)
this.text_y = (this.size_y - (this.margin_y1 + this.margin_y2 + Font.YGLYPH)) / 2;
this.setText(text);
}
public Textbox(int x, int y, int w, int h, int cap, boolean line, Callback callback, String text) {
this(x, y, w, h, cap, line, true, callback, null, text);
}
public Textbox(int x, int y, int w, int h, int cap, boolean line, Callback callback, CharValidator validator, String text) {
this(x, y, w, h, cap, line, true, callback, validator, text);
}
public Textbox(int x, int y, int w, int h, int cap, Callback callback, String text) {
this(x, y, w, h, cap, false, true, callback, null, text);
}
public Textbox(int x, int y, int w, int h, String text) {
this(x, y, w, h, Integer.MAX_VALUE, false, false, null, null, text);
}
public Textbox(int x, int y, int w, int h, boolean line, String text) {
this(x, y, w, h, Integer.MAX_VALUE, line, false, null, null, text);
}
// public void setEditable(boolean editable) {
// this.editable = editable;
// }
// protected boolean isTextCenteredX() {
// return false;
// }
//
// protected boolean isTextCenteredY() {
// return false;
// }
// protected boolean hasLinebreak() {
// return this.xbreak;
// }
public void updateText() {
Vec2i size = Drawing.txt_size(this.pos_x + this.margin_x1, this.pos_y + this.margin_y1,
this.pos_x + this.margin_x1, this.pos_y + this.margin_y1,
this.xbreak ? (this.pos_x + (this.size_x - (this.margin_x1 + this.margin_x2))) : Integer.MAX_VALUE, Integer.MAX_VALUE, this.text);
this.tsize_x = size.xpos;
this.tsize_y = size.ypos;
}
public boolean canHover() {
return false;
}
protected int getMarginX() {
return 4;
}
public void setText(String str) {
if(this.validator != null)
str = this.validator.filter(str);
this.text = str.length() > this.capacity ? str.substring(0, this.capacity) : str;
this.updateText();
this.sel_start = this.sel_end = this.sel_drag = this.text.length();
gui_text_update_cur(this.sel_start, true);
}
public void scroll(int scr_x, int scr_y, int x, int y, boolean ctrl, boolean shift) {
if(scr_y != 0 && this.xbreak) {
int limit = Font.YGLYPH + this.tsize_y - (this.size_y - (this.margin_y1 + this.margin_y2));
limit = ExtMath.clampi(limit, 0, 0x7fffffff);
int prev = this.text_y;
this.text_y += (scr_y < 0 ? -1 : 1) * (ctrl ? 1 : Font.YGLYPH) * this.gm.scrollLines * (shift ? 10 : 1);
this.text_y = ExtMath.clampi(this.text_y, -limit, 0);
if(this.sel_start >= 0)
this.cursorY += (this.text_y - prev);
// this.r_dirty = true;
}
else if(scr_y != 0 || scr_x != 0) {
int limit = Font.XGLYPH + this.tsize_x - (this.size_x - (this.margin_x1 + this.margin_x2));
limit = ExtMath.clampi(limit, 0, 0x7fffffff);
int prev = this.text_x;
this.text_x += ((scr_y != 0 ? scr_y : (-scr_x)) < 0 ? -1 : 1) * (ctrl ? 1 : Font.XGLYPH) * this.gm.scrollLines * (shift ? 10 : 1);
this.text_x = ExtMath.clampi(this.text_x, -limit, 0);
if(this.sel_start >= 0)
this.cursorX += (this.text_x - prev);
// this.r_dirty = true;
}
}
public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift) {
if(btn == Button.MOUSE_LEFT) {
if(!shift && ((Timing.tmr_current - this.tmr_leftmb) <= (((long)this.gm.dclickDelay) * 1000L))) {
this.sel_start = this.sel_drag = 0;
this.sel_end = this.text.length();
// this.r_dirty = true;
}
else {
gui_text_select(x, y, shift);
}
this.tmr_leftmb = Timing.tmr_current;
}
else if((btn == Button.MOUSE_MIDDLE) && this.func != null) {
this.func.use(this, Action.FUNCTION);
}
}
public void mouserel() {
this.scrollx = this.scrolly = 0;
}
public void drag(int x, int y) {
gui_text_select(x, y, true);
}
public void character(char code) {
if(this.editable) {
// int pos = 0;
// char chr[8];
// utf_rwriten(chr, &pos, 8, code);
// chr[pos] = 0;
insertText(Character.toString(code));
}
}
public void key(Keysym key, boolean ctrl, boolean shift) {
if(ctrl && key == Keysym.A) {
this.sel_start = this.sel_drag = 0;
this.sel_end = this.text.length();
// this.r_dirty = true;
}
else if(ctrl && (key == Keysym.C) || (this.editable && (key == Keysym.X))) {
if(this.sel_start >= 0 && this.sel_start != this.sel_end) { // fix empty
// char end = this.text[this.sel_end];
// this.text[this.sel_end] = 0;
String str = Util.strip(this.text, this.sel_start, this.sel_end - this.sel_start, '\n', (char)0, '?');
Window.setClipboard(str);
// this.text[this.sel_end] = end;
if(key == Keysym.X)
insertText("");
}
}
else if(this.editable && ctrl && key == Keysym.V) {
insertText(Window.getClipboard());
}
else if(this.editable && !ctrl && key == Keysym.RETURN) {
if(this.xbreak) {
insertText("\n");
}
else if(this.func != null) {
this.func.use(this, shift ? Action.LINE : Action.SEND);
}
}
else if(this.editable && (!ctrl) && (key == Keysym.BACKSPACE || key == Keysym.DELETE)) {
if(this.sel_start != this.sel_end) {
insertText("");
}
else if(key == Keysym.DELETE && this.sel_start >= 0) {
if(this.sel_end < this.text.length()) {
this.sel_end += 1;
insertText("");
}
else {
this.sel_end = this.sel_start;
}
}
else if(key == Keysym.BACKSPACE && this.sel_start > 0) {
this.sel_start -= 1;
insertText("");
}
}
else if(!ctrl && (key == Keysym.RIGHT || key == Keysym.LEFT)) {
if(key == Keysym.RIGHT && this.sel_start != this.sel_end) {
this.sel_start = this.sel_drag = this.sel_end;
}
else if(key == Keysym.LEFT && this.sel_start != this.sel_end) {
this.sel_end = this.sel_drag = this.sel_start;
}
if(key == Keysym.RIGHT && this.sel_start >= 0) {
if(this.sel_end < this.text.length()) {
this.sel_start = this.sel_drag = this.sel_end += 1;
}
else {
this.sel_end = this.sel_drag = this.sel_start;
}
gui_text_update_cur(this.sel_end, true);
}
else if(key == Keysym.LEFT && this.sel_start >= 0) {
if(this.sel_start > 0)
this.sel_start -= 1;
this.sel_end = this.sel_drag = this.sel_start;
gui_text_update_cur(this.sel_end, true);
}
}
else if(!ctrl && (key == Keysym.DOWN || key == Keysym.UP)) {
if(this.xbreak) {
if(key == Keysym.DOWN && this.sel_start != this.sel_end) {
this.sel_start = this.sel_drag = this.sel_end;
}
else if(key == Keysym.UP && this.sel_start != this.sel_end) {
this.sel_end = this.sel_drag = this.sel_start;
}
if(key == Keysym.DOWN && this.sel_start >= 0) {
if(this.sel_end < this.text.length()) {
// char ch = this.text.charAt(this.sel_end);
// this.sel_end += 1;
int nl = this.text.indexOf('\n', this.sel_end);
// while(ch && ch != '\n') {
// ch = utf_readn(this.text, &this.sel_end);
// }
this.sel_end = nl >= 0 ? nl + 1 : this.text.length();
// else
// this.sel_end -= 1;
this.sel_start = this.sel_drag = this.sel_end;
}
else {
this.sel_end = this.sel_drag = this.sel_start;
}
gui_text_update_cur(this.sel_end, true);
}
else if(key == Keysym.UP && this.sel_start >= 0) {
// uint ch;
if(this.sel_start > 0) {
int nl = this.text.lastIndexOf('\n', this.sel_start);
this.sel_start = nl >= 0 ? nl : 0;
// do {
// ch = utf_rreadn(this.text, &this.sel_start);
// }
// while(ch && ch != '\n');
}
this.sel_end = this.sel_drag = this.sel_start;
gui_text_update_cur(this.sel_end, true);
}
}
else if(this.func != null) {
this.func.use(this, (key == Keysym.DOWN) ? Action.NEXT : Action.PREVIOUS);
}
}
else if((!ctrl) && key == Keysym.TAB) {
if(this.func != null) {
this.func.use(this, shift ? Action.BACKWARD : Action.FORWARD);
}
}
}
public void select() {
if(this.func != null) {
this.func.use(this, Action.FOCUS);
}
}
public void deselect() {
this.sel_start = this.sel_end = this.sel_drag = -1;
this.tmr_leftmb = 0L;
// this.r_dirty = true;
if(this.func != null) {
this.func.use(this, Action.UNFOCUS);
}
}
public void update() {
if((this.scrollx != 0 && !(this.xbreak)) || (this.scrolly != 0 && this.xbreak)) {
int n;
if(!this.xbreak)
this.text_x += (n = (int)((float)((float)this.tmr_scroll) / 1000000.0f * 4.0f * ((float)this.scrollx)));
else
this.text_y += (n = (int)((float)((float)this.tmr_scroll) / 1000000.0f * 4.0f * ((float)this.scrolly)));
if(n != 0) {
gui_text_clamp_scroll();
// this.r_dirty = true;
}
if((((long)n) * 1000000L) <= this.tmr_scroll)
this.tmr_scroll -= ((long)n) * 1000000L;
else
this.tmr_scroll = 0L;
this.tmr_scroll += Timing.tmr_delta;
}
}
public void shift(int shift_x, int shift_y) {
super.shift(shift_x, shift_y);
this.cursorX += shift_x;
this.cursorY += shift_y;
}
private void gui_text_clamp_scroll() {
int limit;
if(this.xbreak) {
limit = Font.YGLYPH + this.tsize_y - (this.size_y - (this.margin_y1 + this.margin_y2));
limit = ExtMath.clampi(limit, 0, 0x7fffffff);
this.text_y = ExtMath.clampi(this.text_y, -limit, 0);
}
else {
limit = Font.XGLYPH + this.tsize_x - (this.size_x - (this.margin_x1 + this.margin_x2));
limit = ExtMath.clampi(limit, 0, 0x7fffffff);
this.text_x = ExtMath.clampi(this.text_x, -limit, 0);
}
}
private void gui_text_update_cur(int offset, boolean shift) {
int x1 = this.pos_x + this.margin_x1;
int y1 = this.pos_y + this.margin_y1;
int x2 = this.size_x - (this.margin_x1 + this.margin_x2);
int y2 = this.size_y - (this.margin_y1 + this.margin_y2);
gui_text_clamp_scroll();
Vec2i coord = Drawing.txt_coord(offset, x1 + (this.xbreak ? 0 : this.text_x), y1 + this.text_y,
x1 + this.text_x, y1 + this.text_y, this.xbreak ? (this.pos_x + x2) : 0x7fffffff, 0x7fffffff, this.text);
this.cursorX = coord.xpos;
this.cursorY = coord.ypos;
if(shift) {
if(this.xbreak && this.cursorY < y1)
this.text_y += y1 - this.cursorY;
else if(this.xbreak && (this.cursorY + Font.YGLYPH) >= (y1 + y2))
this.text_y -= (this.cursorY + Font.YGLYPH) - (y1 + y2);
if(!(this.xbreak) && this.cursorX < x1)
this.text_x += x1 - this.cursorX;
else if(!(this.xbreak) && (this.cursorX + Font.XGLYPH) >= (x1 + x2))
this.text_x -= (this.cursorX + Font.XGLYPH) - (x1 + x2);
gui_text_update_cur(offset, false);
}
// else {
// this.r_dirty = true;
// }
}
public void insertText(String str) {
if(str == null || (this.sel_start == -1))
return;
str = Util.strip(str, 0, str.length(), this.xbreak ? '\n' : ' ', ' ', (char)0);
if(this.validator != null)
str = this.validator.filter(str);
// plen = strlen(&sys.work_buf[1 + olen - this.sel_end]);
// logd("t", "%d %d %d", olen, slen, plen);
if((str.length() + this.text.length() - (this.sel_end - this.sel_start)) > this.capacity)
return;
this.text = this.text.substring(0, this.sel_start) + str + this.text.substring(this.sel_end);
// memcpy(sys.work_buf, &this.text[this.sel_end], 1 + this.text.length() - this.sel_end);
// memcpy(&this.text[this.sel_start], &sys.work_buf[1 + this.text.length() - this.sel_end], str.length());
// memcpy(&this.text[this.sel_start + str.length()], sys.work_buf, 1 + this.text.length() - this.sel_end);
this.sel_start += str.length();
this.sel_end = this.sel_drag = this.sel_start;
this.updateText();
gui_text_update_cur(this.sel_end, true);
}
private void gui_text_select(int x, int y, boolean drag) {
int x1 = this.pos_x + this.margin_x1;
int y1 = this.pos_y + this.margin_y1;
int x2 = this.size_x - (this.margin_x1 + this.margin_x2);
int y2 = this.size_y - (this.margin_y1 + this.margin_y2);
Offset off = Drawing.txt_offset(x, y, x1 + (this.xbreak ? 0 : this.text_x), y1 + this.text_y,
x1 + this.text_x, y1 + this.text_y, this.xbreak ? (this.pos_x + x2) : 0x7fffffff, 0x7fffffff, this.text);
if(off != null) {
this.cursorX = off.xpos;
this.cursorY = off.ypos;
}
int offset = off == null ? 0 : off.offset;
// logd("tst", "@A %d %d -. %d %d", x1, y1, x2, y2);
// logd("tst", "@C %d %d -. %d, %d %d", x, y, offset, this.min, this.max);
if(!drag) {
this.sel_drag = this.sel_start = this.sel_end = offset;
}
else if(drag && this.sel_drag >= 0 && offset >= this.sel_drag) {
this.sel_start = this.sel_drag;
this.sel_end = offset;
}
else if(drag && this.sel_drag >= 0 && offset < this.sel_drag) {
this.sel_start = offset;
this.sel_end = this.sel_drag;
}
// logd("tst", "@S %d . %d . %d", this.sel_start, this.sel_drag, this.sel_end);
// this.r_dirty = true;
if(x < x1)
this.scrollx = x1 - x;
else if(x >= (x1 + x2))
this.scrollx = -(x - (x1 + x2));
if(y < y1)
this.scrolly = y1 - y;
else if(y >= (y1 + y2))
this.scrolly = -(y - (y1 + y2));
}
protected void drawBackground() {
if(this.enabled)
Drawing.drawGradientBorder(this.pos_x, this.pos_y, this.size_x, this.size_y, this.gm.style.field_top, this.gm.style.field_btm, 0xff000000, this.gm.style.brdr_top, this.gm.style.brdr_btm);
else
Drawing.drawGradientBorder(this.pos_x, this.pos_y, this.size_x, this.size_y, Util.mulColor(this.gm.style.field_top, 0.5f), Util.mulColor(this.gm.style.field_btm, 0.5f), 0xff000000, Util.mulColor(this.gm.style.brdr_top, 0.5f), Util.mulColor(this.gm.style.brdr_btm, 0.5f));
}
protected void drawForeground(int x1, int y1, int x2, int y2) {
Drawing.txt_draw(x1 + (this.xbreak ? 0 : this.text_x), y1 + this.text_y,
x1 + this.text_x, y1 + this.text_y,
this.xbreak ? (this.pos_x + x2) : Integer.MAX_VALUE, Integer.MAX_VALUE, this.enabled ? this.gm.style.text_field : Util.mulColor(this.gm.style.text_field, 0.5f), this.text);
if(this.sel_start >= 0 && this.sel_end != this.sel_start)
Drawing.txt_overlay(this.sel_start, this.sel_end, x1 + (this.xbreak ? 0 : this.text_x), y1 + this.text_y,
x1 + this.text_x, y1 + this.text_y,
this.xbreak ? (this.pos_x + x2) : Integer.MAX_VALUE, Integer.MAX_VALUE, this.enabled ? 0x808080ff : 0x80404040, this.text);
}
public void drawOverlay() {
if(this.editable && this.sel_start >= 0 && this.sel_end == this.sel_start && Util.ftime() % 1.0f < 0.5f) {
int x1 = this.pos_x + this.margin_x1;
int y1 = this.pos_y + this.margin_y1;
int x2 = this.size_x - (this.margin_x1 + this.margin_x2);
int y2 = this.size_y - (this.margin_y1 + this.margin_y2);
GL11.glScissor(x1 < 0 ? 0 : x1, (this.gm.fb_y - (y1 + y2)) < 0 ? 0 : (this.gm.fb_y - (y1 + y2)), x2 < 0 ? 0 : x2, y2 < 0 ? 0 : y2);
GL11.glEnable(GL11.GL_SCISSOR_TEST);
Drawing.drawRect(this.cursorX, this.cursorY, 1, Font.YGLYPH, 0xff000000 | (~Util.mixColor(this.gm.style.field_top, this.gm.style.field_btm)));
GL11.glDisable(GL11.GL_SCISSOR_TEST);
}
}
public void deleteFromCursor() {
int num = this.getNthCharFromPos() - this.sel_start;
if(this.text.length() != 0) {
if(this.sel_start != this.sel_end) {
this.insertText("");
}
else {
// boolean flag = num < 0;
int i = this.sel_start + num; // flag ? this.sel_start + num : this.sel_start;
int j = this.sel_start; // flag ? this.sel_start : this.sel_start + num;
String s = "";
if(i >= 0) {
s = this.text.substring(0, i);
}
if(j < this.text.length()) {
s = s + this.text.substring(j);
}
// this.setText(s);
this.text = s;
this.updateText();
this.sel_start = this.sel_end = this.sel_drag = i;
gui_text_update_cur(this.sel_start, true);
//
// if(flag) {
// this.moveCursorBy(num);
// }
}
}
}
public int getNthCharFromPos() {
int i = this.sel_start;
while(i > 0 && this.text.charAt(i - 1) != ' ') {
--i;
}
return i;
}
public int getCursorPosition() {
return this.sel_start == this.sel_end ? this.sel_start : -1;
}
}

View file

@ -6,12 +6,16 @@ import client.window.Button;
import common.util.Util;
public class Toggle extends Element {
private final ToggleCallback func;
public static interface Callback {
void use(Toggle elem, boolean value);
}
private final Callback func;
private final boolean def;
private boolean value;
public Toggle(int x, int y, int w, int h, boolean def, boolean init, ToggleCallback callback, Formatter<Toggle> formatter) {
public Toggle(int x, int y, int w, int h, boolean def, boolean init, Callback callback, Formatter<Toggle> formatter) {
super(x, y, w, h, formatter);
this.func = callback;
this.def = def;
@ -19,7 +23,7 @@ public class Toggle extends Element {
this.formatText();
}
public Toggle(int x, int y, int w, int h, boolean def, boolean init, ToggleCallback callback, final String text) {
public Toggle(int x, int y, int w, int h, boolean def, boolean init, Callback callback, final String text) {
this(x, y, w, h, def, init, callback, new Formatter<Toggle>() {
public String use(Toggle elem) {
return String.format("%s: %s", text, elem.value ? "An" : "Aus");
@ -34,8 +38,7 @@ public class Toggle extends Element {
// this.type = this.value != 0 ? ElemType.TOGGLE_ON : ElemType.TOGGLE_OFF;
// gui_update_style(this, 1);
// this.r_dirty = true;
if(this.func != null)
this.func.use(this, this.value);
this.func.use(this, this.value);
this.formatText();
this.playSound();
}
@ -51,15 +54,4 @@ public class Toggle extends Element {
else
super.drawBackground();
}
public void setValue(boolean value) {
if(this.value != value) {
this.value = value;
this.formatText();
}
}
public boolean getValue() {
return this.value;
}
}

View file

@ -0,0 +1,17 @@
package client.gui.element;
import client.renderer.Drawing;
public class TransparentBox extends Textbox {
private final boolean background;
public TransparentBox(int x, int y, int w, int h, String text, boolean background) {
super(x, y, w, h, text);
this.background = background;
}
protected void drawBackground() {
if(this.background)
Drawing.drawRect(this.pos_x, this.pos_y, this.size_x, this.size_y, 0x3f000000);
}
}

View file

@ -0,0 +1,40 @@
package client.gui.ingame;
import client.gui.Gui;
import client.gui.element.ActButton;
import client.gui.element.ActButton.Mode;
import common.color.TextColor;
import client.gui.element.Label;
public class GuiGameOver extends Gui {
public static final GuiGameOver INSTANCE = new GuiGameOver();
private ActButton button;
private int timer;
private GuiGameOver() {
}
public void init(int width, int height) {
this.timer = 0;
this.add(new Label(0, 0, 200, 20, "Du bist gestorben!"));
this.add(new Label(0, 32, 200, 20, "Punktestand: " + TextColor.YELLOW + this.gm.thePlayer.experienceLevel));
this.button = this.add(new ActButton(0, 100, 200, 24, new ActButton.Callback() {
public void use(ActButton elem, Mode action) {
GuiGameOver.this.gm.thePlayer.respawnPlayer();
GuiGameOver.this.gm.displayGuiScreen(null);
}
}, "Wiederbeleben"));
this.shift();
this.button.enabled = false;
}
public String getTitle() {
return "Game over";
}
public void updateScreen() {
if(++this.timer >= 20)
this.button.enabled = true;
}
}

View file

@ -0,0 +1,49 @@
package client.gui.ingame;
import client.gui.Gui;
import client.gui.element.NavButton;
import client.gui.element.Textbox;
import client.gui.element.Textbox.Action;
import client.network.ClientPlayer;
import common.packet.CPacketSign;
import common.world.BlockPos;
public class GuiSign extends Gui implements Textbox.Callback {
private final BlockPos position;
private final Textbox[] lines = new Textbox[4];
private final String[] tempLines = new String[this.lines.length];
public void init(int width, int height) {
for(int z = 0; z < this.lines.length; z++) {
this.lines[z] = this.add(new Textbox(0, 40 * z, 300, 24, 50, true, this, this.tempLines[z] == null ? "" : this.tempLines[z]));
}
this.add(new NavButton(0, 40 * (this.lines.length + 1), 300, 24, null, "Fertig"));
this.shift();
}
public String getTitle() {
return "Schild bearbeiten";
}
public void onGuiClosed() {
ClientPlayer nethandler = this.gm.getNetHandler();
if(nethandler != null) {
for(int z = 0; z < this.lines.length; z++) {
this.tempLines[z] = this.lines[z].getText();
}
nethandler.addToSendQueue(new CPacketSign(this.position, this.tempLines));
}
}
public GuiSign(BlockPos sign, String[] lines) {
this.position = sign;
System.arraycopy(lines, 0, this.tempLines, 0, this.lines.length);
}
public void use(Textbox elem, Action value) {
if(value == Action.SEND)
this.gm.displayGuiScreen(null);
}
}

View file

@ -0,0 +1,74 @@
package client.gui.options;
import client.gui.Formatter;
import client.gui.element.ActButton;
import client.gui.element.ActButton.Mode;
import client.gui.element.Label;
import client.window.Bind;
import common.color.TextColor;
public class GuiBinds extends GuiOptions {
protected GuiBinds() {
}
public void init(int width, int height) {
int y = 0;
int x = 0;
for(Bind bind : Bind.values()) {
this.add(new Label(10 + x * 190, 80 + y * 50, 180, 20, bind.getDisplay()));
this.add(new ActButton(10 + x * 190, 100 + y * 50, 180, 24, new ActButton.Callback() {
public void use(ActButton elem, Mode action) {
if(action == Mode.SECONDARY) {
if(!bind.isDefault()) {
bind.setDefault();
GuiBinds.this.gm.setDirty();
GuiBinds.this.reformat();
}
}
else if(action == Mode.TERTIARY) {
if(bind.getInput() != null) {
bind.setInput(null);
GuiBinds.this.gm.setDirty();
GuiBinds.this.reformat();
}
}
else {
Bind.disableInput(bind);
}
}
}, new Formatter<ActButton>() {
public String use(ActButton elem) {
if(bind == Bind.getWaiting())
return /* TextColor.BLINK + "" + */ TextColor.BLUE + "***";
else
return (bind.isDupe() ? TextColor.RED : TextColor.YELLOW) + (bind.getInput() == null ? "---" : bind.getInput().getDisplay());
}
}));
if(++x == 5) {
x = 0;
y++;
}
}
y += x != 0 ? 1 : 0;
this.add(new ActButton(200, 100 + y * 50, 560, 24, new ActButton.Callback() {
public void use(ActButton elem, Mode action) {
boolean flag = false;
for(Bind bind : Bind.values()) {
flag |= !bind.isDefault();
bind.setDefault();
}
if(flag) {
GuiBinds.this.gm.setDirty();
GuiBinds.this.reformat();
}
}
}, "Zurücksetzen"));
this.addSelector("phy_sensitivity", 30, 160 + y * 50, 440, 24);
this.addSelector("gui_dclick_delay", 490, 160 + y * 50, 440, 24);
super.init(width, height);
}
public String getTitle() {
return "Tastenbelegung und Maus";
}
}

View file

@ -0,0 +1,103 @@
package client.gui.options;
import client.gui.Formatter;
import client.gui.element.Dropdown;
import client.gui.element.Element;
import client.gui.element.Fill;
import client.gui.element.Slider;
import client.gui.element.Toggle;
import client.window.Button;
import client.window.DisplayMode;
import client.window.Window;
import common.color.TextColor;
public class GuiDisplay extends GuiOptions {
private static final String[] DISTANCES = new String[] {"Gruselig", "Winzig", "Gering", "Normal", "Weit"};
private Element distanceSlider;
protected GuiDisplay() {
}
public void init(int width, int height) {
DisplayMode[] dmodes = Window.getDisplayModes();
if(dmodes != null && dmodes.length > 0) {
int offset = 0;
int pos = 0;
int num = dmodes.length;
if(dmodes.length > DisplayMode.VID_MODES) {
offset = dmodes.length - DisplayMode.VID_MODES;
num = DisplayMode.VID_MODES;
}
DisplayMode[] modes = new DisplayMode[num];
DisplayMode selected = dmodes[num + offset - 1];
for(int z = 0; z < num; z++) {
modes[z] = dmodes[z + offset];
if(modes[z].equals(this.gm.vidMode))
selected = modes[z];
}
this.add(new Dropdown<DisplayMode>(30, 80, 440, 24, false, modes, modes[modes.length - 1], selected, new Dropdown.Callback<DisplayMode>() {
public void use(Dropdown<DisplayMode> elem, DisplayMode value) {
GuiDisplay.this.gm.vidMode = value;
GuiDisplay.this.gm.full(true);
}
}, "Auflösung"));
}
else {
this.add(new Fill(30, 80, 440, 24, TextColor.RED + "Auflösung: <?>"));
}
this.add(new Toggle(490, 80, 440, 24, false, GuiDisplay.this.gm.fullscreen, new Toggle.Callback() {
public void use(Toggle elem, boolean value) {
GuiDisplay.this.gm.full(value);
}
}, "Vollbild"));
this.add(new Slider(30, 120, 440, 24, 0, 0, 360 - 8, 0, (this.gm.sync < 0) ? (360 - 8) : (this.gm.sync != 0 ? ((this.gm.sync < 10) ? 1 : (this.gm.sync - 9)) : 0), new Slider.Callback() {
public void use(Slider elem, int value) {
GuiDisplay.this.gm.getVar("win_sync").parse("" + ((value > 0 && value < 360 - 8) ? (value + 9) : (value != 0 ? -1 : 0)));
GuiDisplay.this.gm.setDirty();
}
}, new Formatter<Slider>() {
public String use(Slider elem) {
int value = elem.getValue();
return "Max. Bildrate: " + (value > 0 && value < (360 - 8) ? (value + 9) + " FPS" : (value != 0 ? "Unbegrenzt" : "VSync"));
}
}));
this.addSelector("gl_vsync_flush", 490, 120, 440, 24);
this.addSelector("overlay_enabled", 30, 200, 440, 24);
this.addSelector("overlay_opacity", 490, 200, 440, 24);
this.addSelector("overlay_fadeout", 30, 240, 440, 24);
this.addSelector("chat_permanent", 490, 240, 440, 24);
this.addSelector("console_size", 30, 280, 440, 24);
this.addSelector("chat_size", 490, 280, 440, 24);
this.addSelector("feed_size", 30, 320, 440, 24);
this.addSelector("hotbar_size", 490, 320, 440, 24);
this.addSelector("gl_fov", 30, 400, 440, 24);
this.distanceSlider = this.addSelector("chunk_view_distance", 30, 440, 440, 24);
this.addSelector("chunk_build_time", 490, 440, 440, 24);
super.init(width, height);
}
public String getTitle() {
return "Grafik und Anzeige";
}
private String getDistanceName() {
int distance = this.gm.renderDistance;
distance = distance > 16 ? 16 : distance;
String str = distance < 0 ? DISTANCES[0] : DISTANCES[(distance + 1) / 4];
if(distance > 2 && (((distance + 1) / 2) & 1) == 1)
str = str + "+";
return String.format("Sichtweite: %d Chunks [%d Blöcke, %s]", this.gm.renderDistance, this.gm.renderDistance * 16, str);
}
public void updateScreen() {
if(!Button.isMouseDown())
this.distanceSlider.setText(this.getDistanceName());
}
}

Some files were not shown because too many files have changed in this diff Show more