Skip to content

Commit

Permalink
RFW now uses GuiScreens to render Player and Objective listing. See #30
Browse files Browse the repository at this point in the history
…. Also really fixes nightVision. Fixes #28.
  • Loading branch information
entropitor committed Aug 4, 2013
1 parent f46cf6a commit e38b9fc
Show file tree
Hide file tree
Showing 10 changed files with 356 additions and 32 deletions.
Binary file modified AutoReferee.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 30 additions & 12 deletions net/minecraft/src/AutoReferee.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -16,22 +17,27 @@
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;
import org.apache.commons.lang3.StringUtils;

import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;

public class AutoReferee {
public static final String CHANNEL = "autoref:referee";
public static final String DELIMITER = "\\|";
public static final char DELIMITER_SEND = '|';
public static final String PLUGIN_CHANNEL_ENC = "UTF-8";

public static final int MAX_NUMBER_OF_PLAYERS_ON_SCREEN = 4;

public static final int AUTOREFEREE_ICON_NUMBER_IN_WIDTH = 2;
public static final int AUTOREFEREE_ICON_NUMBER_IN_HEIGHT = 2;
public static final int AUTOREFEREE_ICON_TEXTURE_SIZE = 2;
public static final int AUTOREFEREE_ICON_NUMBER_IN_WIDTH = 4;
public static final int AUTOREFEREE_ICON_NUMBER_IN_HEIGHT = 4;
public static final int AUTOREFEREE_ICON_TEXTURE_SIZE = 4;
public static final int AUTOREFEREE_WINNERS_ICON = 0;
public static final int AUTOREFEREE_KILL_STREAK_ICON = 2;
public static final int AUTOREFEREE_DOMINATION_ICON = 3;
public static final int AUTOREFEREE_SKULL_ICON = 1;
public static final int AUTOREFEREE_ARROW_ICON = 2;
public static final int AUTOREFEREE_KILL_STREAK_ICON = 4;
public static final int AUTOREFEREE_DOMINATION_ICON = 5;
public static final int AUTOREFEREE_ICON_SIZE = 13;

public static final int PLAYER_NAMETAG_HEARTS_X_OFFSET = -40;
Expand Down Expand Up @@ -96,7 +102,7 @@ public void resetValues() {
this.messages.clear();
this.lastMessage = null;
this.gameType = "RFW";
this.nightVision = false;
this.nightVision = true;
this.swapTeams = false;
this.registeredChannel = false;
this.closestPlayers = null;
Expand Down Expand Up @@ -133,8 +139,8 @@ public void registerAutoRefereeChannel() {
this.netClientHandler.addToSendQueue(p);
}

public void handleCustomPayload(Packet250CustomPayload par1Packet250CustomPayload) {
String s = new String(par1Packet250CustomPayload.data, Charset.forName("UTF-8"));
public void handleCustomPayload(Packet250CustomPayload customPayloadPackage) {
String s = new String(customPayloadPackage.data, Charset.forName(PLUGIN_CHANNEL_ENC));
Logger.getLogger("Minecraft").info("Received package: '" + s + "'.");
String[] command = s.split(DELIMITER);
if ("player".equals(command[0])) {
Expand Down Expand Up @@ -289,12 +295,13 @@ else if ("target".equalsIgnoreCase(command[4]))
swapTeams = !swapTeams;
} else if ("nightvis".equals(command[2])){
if(command.length >= 4){
if(command[3]=="1")
if("1".equalsIgnoreCase(command[3]))
nightVision = true;
else if(command[3]=="0")
else if("0".equalsIgnoreCase(command[3]))
nightVision = false;
} else
} else {
nightVision = !nightVision;
}
} else if ("gametype".equals(command[2])) {
gameType = command[3].toUpperCase();
} else if("gameplay".equals(command[2])){
Expand All @@ -314,6 +321,17 @@ else if(command[3]=="0")
}
}

public void messageServer(String ...parts) {
String msg = StringUtils.join(parts, DELIMITER_SEND);
Packet250CustomPayload packet;
try {
packet = new Packet250CustomPayload(CHANNEL, msg.getBytes(PLUGIN_CHANNEL_ENC));
this.netClientHandler.addToSendQueue(packet);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}

public Minecraft getMinecraft(){
return mc;
}
Expand Down Expand Up @@ -574,7 +592,7 @@ public void loseObjectiveForPlayer(String name, int id, int dataValue) {
public void addObjectiveForTeam(String name, int id, int dataValue) {
AutoRefereeTeam at = teams.get(name);
if (at != null)
at.addObjective(new AutoRefereeObjective(id, dataValue));
at.addObjective(new AutoRefereeObjective(id, dataValue, at));
}

public void removeObjectiveForTeam(String name, int id, int dataValue) {
Expand Down
97 changes: 97 additions & 0 deletions net/minecraft/src/AutoRefereeButton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package net.minecraft.src;

import net.minecraft.src.FontRenderer;
import net.minecraft.src.GuiButton;
import net.minecraft.src.Minecraft;

import org.lwjgl.opengl.GL11;

public class AutoRefereeButton extends GuiButton {

public String[] message;
private String type;

private float scale = 1.0F;

private AutoRefereePlayer player;
private AutoRefereeObjective obj;
private AutoRefereeTeam team;

public AutoRefereeButton(int xPos, int yPos, float scale, String name){
super(1, xPos, yPos, 0, 0, name);

if("TP".equalsIgnoreCase(type))
scale *= 20.0F/AutoReferee.AUTOREFEREE_ICON_SIZE;
else if("OBJ".equalsIgnoreCase(type) || "VM".equalsIgnoreCase(type) || "SPAWN".equalsIgnoreCase(type))
scale *= 16.0F/AutoReferee.AUTOREFEREE_ICON_SIZE;

this.width = (int)(AutoReferee.AUTOREFEREE_ICON_SIZE*scale);
this.height = (int)(AutoReferee.AUTOREFEREE_ICON_SIZE*scale);
this.scale = scale;

}

public AutoRefereeButton(float xPos, float yPos, float scale, String type){
this((int) xPos, (int) yPos, scale, "");
this.type = type;
}

public AutoRefereeButton(float xPos, float yPos, float scale, AutoRefereePlayer player, String type){
this(xPos, yPos, scale, type);
this.player = player;
if("TP".equalsIgnoreCase(type)){
message = new String[]{"tp","player", player.getName(),"player"};
}else if("TPBed".equalsIgnoreCase(type)){
message = new String[]{"tp","player", player.getName(),"bed"};
}else if("TPDeath".equalsIgnoreCase(type)){
message = new String[]{"tp","player", player.getName(),"death"};
}else if("VI".equalsIgnoreCase(type)){
message = new String[]{"inventory","player", player.getName()};
}else if("VIDeath".equalsIgnoreCase(type)){
message = new String[]{"inventory","player", player.getName(),"prev"};
}
}

public AutoRefereeButton(float xPos, float yPos, float scale, AutoRefereeObjective obj, String type){
this(xPos, yPos, scale, type);
this.obj = obj;
if("OBJ".equalsIgnoreCase(type)){
message = new String[]{"tp","team", obj.getTeam().getName(), "obj", obj.toString()};
}
}

public AutoRefereeButton(float xPos, float yPos, float scale, AutoRefereeTeam team, String type){
this(xPos, yPos, scale, type);
this.team = team;
if("VM".equalsIgnoreCase(type)){
message = new String[]{"tp","team", team.getName(), "vm"};
}else if("SPAWN".equalsIgnoreCase(type)){
message = new String[]{"tp","team", team.getName(), "spawn"};
}
}

public void drawButton(Minecraft mc, int mouseX, int mouseY)
{
//TODO add coloring if disabled..

float xTop = xPosition + width/2 - AutoReferee.AUTOREFEREE_ICON_SIZE*scale/2;
float yTop = yPosition + height/2 - AutoReferee.AUTOREFEREE_ICON_SIZE*scale/2;
if("TP".equalsIgnoreCase(type))
AutoReferee.get().renderSkinHead(player, xTop, yTop, scale);
else if("TPBed".equalsIgnoreCase(type))
AutoReferee.get().renderItem(355, 0, (int)(xTop), (int)(yTop), scale*AutoReferee.AUTOREFEREE_ICON_SIZE/16);
else if("TPDeath".equalsIgnoreCase(type))
AutoReferee.get().renderAutoRefereeIcon(AutoReferee.AUTOREFEREE_SKULL_ICON, 0, xTop, yTop, scale);
else if("VI".equalsIgnoreCase(type))
AutoReferee.get().renderItem(54, 0, (int)(xTop), (int)(yTop), scale*AutoReferee.AUTOREFEREE_ICON_SIZE/16);
else if("VIDeath".equalsIgnoreCase(type))
AutoReferee.get().renderItem(130, 0, (int)(xTop), (int)(yTop), scale*AutoReferee.AUTOREFEREE_ICON_SIZE/16);
else if("OBJ".equalsIgnoreCase(type))
AutoReferee.get().renderItem(obj.getId(), obj.getData(), (int) xTop, (int) yTop, scale);
else if("SPAWN".equalsIgnoreCase(type))
AutoReferee.get().renderAutoRefereeIcon(AutoReferee.AUTOREFEREE_ARROW_ICON, 0, xTop, yTop, scale);
else if("VM".equalsIgnoreCase(type))
AutoReferee.get().renderAutoRefereeIcon(AutoReferee.AUTOREFEREE_WINNERS_ICON, 0, xTop, yTop, scale);

}
}
7 changes: 5 additions & 2 deletions net/minecraft/src/AutoRefereeHUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class AutoRefereeHUD {
public static float AUTOREFEREE_HUD_SCALE_CUP_ICON = (float) AUTOREFEREE_HUD_HEIGHT / AutoReferee.AUTOREFEREE_ICON_SIZE;
public static float AUTOREFEREE_HUD_WIDTH_CUP_ICON = AutoReferee.AUTOREFEREE_ICON_SIZE * AUTOREFEREE_HUD_SCALE_CUP_ICON;

public static int PLAYER_LIST_BOX_WIDTH = 150;
public static int PLAYER_LIST_BOX_WIDTH = 160;
public static int PLAYER_LIST_BOX_HEIGHT = 230;
public static int PLAYER_LIST_BOX_PADDING = 5;
public static int PLAYER_LIST_TEAM_OFFSET = 8;
Expand All @@ -24,7 +24,7 @@ public class AutoRefereeHUD {
public static int PLAYER_LIST_ARMOR_X_OFFSET = PLAYER_LIST_HEALTH_X_OFFSET;
public static int PLAYER_LIST_ARMOR_Y_OFFSET = 16;
public static int PLAYER_LIST_HEAD_X_OFFSET = 105;
public static int PLAYER_LIST_HEAD_Y_OFFSET = 25;
public static int PLAYER_LIST_HEAD_Y_OFFSET = 27;
public static int PLAYER_LIST_OBJECTIVES_X_OFFSET = 10;
public static int PLAYER_LIST_OBJECTIVES_Y_OFFSET = 27;
public static int PLAYER_LIST_OBJECTIVE_OFFSET = 16;
Expand All @@ -34,6 +34,9 @@ public class AutoRefereeHUD {
public static int PLAYER_LIST_DOMINATION_Y_OFFSET = 24;
public static int PLAYER_LIST_KILL_STREAK_X_OFFSET = PLAYER_LIST_DOMINATION_X_OFFSET;
public static int PLAYER_LIST_KILL_STREAK_Y_OFFSET = 38;
public static int PLAYER_LIST_BUTTONS_OFFSET = 145;
public static int PLAYER_LIST_BED_BUTTON_OFFSET = 13;
public static int PLAYER_LIST_DEATH_INV_BUTTON_OFFSET = 35;

public static int TEAM_LIST_BOX_WIDTH = 150;
public static int TEAM_LIST_BOX_PADDING = 5;
Expand Down
41 changes: 29 additions & 12 deletions net/minecraft/src/AutoRefereeHUDRFW.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
public class AutoRefereeHUDRFW extends AutoRefereeHUD {

public static void renderPlayerList(Minecraft mc) {
ScaledResolution scaledResolution = new ScaledResolution(mc.gameSettings, mc.displayWidth, mc.displayHeight);
mc.displayGuiScreen(new AutoRefereeHUDRFWPlayerListGui());
/*ScaledResolution scaledResolution = new ScaledResolution(mc.gameSettings, mc.displayWidth, mc.displayHeight);
GL11.glEnable(GL11.GL_ALPHA_TEST);
AutoReferee autoReferee = AutoReferee.get();
float scale = (float) (scaledResolution.getScaledHeight() - 45) / (float) PLAYER_LIST_BOX_HEIGHT;
Expand Down Expand Up @@ -40,10 +41,10 @@ public static void renderPlayerList(Minecraft mc) {
GL11.glScalef(scale, scale, scale);
renderTeamInPlayerList(at2, scaleName, mc);
GL11.glPopMatrix();
}
}*/
}

private static void renderTeamInPlayerList(AutoRefereeTeam at, float scaleName, Minecraft mc) {
protected static void renderTeamInPlayerList(AutoRefereeTeam at, float scaleName, Minecraft mc) {
AutoReferee autoReferee = AutoReferee.get();
String name = at.getName();
mc.ingameGUI.drawRect(0, 0, PLAYER_LIST_BOX_WIDTH, PLAYER_LIST_BOX_HEIGHT, at.getBoxColor());
Expand All @@ -60,14 +61,14 @@ private static void renderTeamInPlayerList(AutoRefereeTeam at, float scaleName,
}
GL11.glTranslatef(0, PLAYER_LIST_PLAYERS_Y_OFFSET + i * PLAYER_LIST_PLAYER_HEIGHT, 0);
autoReferee.renderString(apl.getName(), PLAYER_LIST_NAME_OFFSET, 0, 1F, textcolor, true);
autoReferee.renderString(apl.getDeaths() + "", PLAYER_LIST_DEATHS_OFFSET, PLAYER_LIST_HEALTH_Y_OFFSET, 1F, textcolor, true);
autoReferee.renderString(apl.getKills() + "", PLAYER_LIST_KILLS_OFFSET, PLAYER_LIST_HEALTH_Y_OFFSET, 1F, textcolor, true);
autoReferee.renderString(apl.getAccuracyString(), PLAYER_LIST_ACC_OFFSET, PLAYER_LIST_ARMOR_Y_OFFSET, 1F, textcolor, true);
autoReferee.renderString("K "+apl.getKills(), PLAYER_LIST_KILLS_OFFSET, 0, 1F, textcolor, true);
autoReferee.renderString("D "+apl.getDeaths(), PLAYER_LIST_KILLS_OFFSET, PLAYER_LIST_HEALTH_Y_OFFSET, 1F, textcolor, true);
autoReferee.renderString(apl.getAccuracyString(), PLAYER_LIST_KILLS_OFFSET, PLAYER_LIST_ARMOR_Y_OFFSET, 1F, textcolor, true);
health = apl.getHealth();
armor = apl.getArmor();
autoReferee.renderHearts(health, PLAYER_LIST_HEALTH_X_OFFSET, PLAYER_LIST_HEALTH_Y_OFFSET, 1F, true);
autoReferee.renderArmor(armor, PLAYER_LIST_ARMOR_X_OFFSET, PLAYER_LIST_ARMOR_Y_OFFSET, 1F);
autoReferee.renderSkinHead(apl, PLAYER_LIST_HEAD_X_OFFSET, PLAYER_LIST_HEAD_Y_OFFSET, 1F);
//autoReferee.renderSkinHead(apl, PLAYER_LIST_HEAD_X_OFFSET, PLAYER_LIST_HEAD_Y_OFFSET, 1F);

j = 0;
for (AutoRefereeObjective obj : apl.getObjectives()) {
Expand All @@ -89,7 +90,8 @@ private static void renderTeamInPlayerList(AutoRefereeTeam at, float scaleName,
}

public static void renderTeamList(Minecraft mc) {
ScaledResolution scaledResolution = new ScaledResolution(mc.gameSettings, mc.displayWidth, mc.displayHeight);
mc.displayGuiScreen(new AutoRefereeHUDRFWObjectiveListGui());
/*ScaledResolution scaledResolution = new ScaledResolution(mc.gameSettings, mc.displayWidth, mc.displayHeight);
GL11.glEnable(GL11.GL_ALPHA_TEST);
AutoReferee autoReferee = AutoReferee.get();
float scale = (float) (scaledResolution.getScaledHeight() - 45) / (float) TEAM_LIST_BOX_HEIGHT;
Expand Down Expand Up @@ -122,25 +124,40 @@ public static void renderTeamList(Minecraft mc) {
GL11.glScalef(scale, scale, scale);
renderTeamInTeamList(at2, scaleName, mc);
GL11.glPopMatrix();
}
}*/
}

private static void renderTeamInTeamList(AutoRefereeTeam at, float nameScale, Minecraft mc) {
protected static void renderTeamInTeamList(AutoRefereeTeam at, float nameScale, Minecraft mc) {
AutoReferee autoReferee = AutoReferee.get();
String name = at.getName();
int height = TEAM_LIST_OBJECTIVES_Y_OFFSET + at.getObjectives().size() * TEAM_LIST_OBJECTIVES_HEIGHT + 20;
int height = TEAM_LIST_OBJECTIVES_Y_OFFSET + (at.getObjectives().size()+2) * TEAM_LIST_OBJECTIVES_HEIGHT + 20;
mc.ingameGUI.drawRect(0, 0, TEAM_LIST_BOX_WIDTH, height, at.getBoxColor());
autoReferee.renderCenteredString(name, TEAM_LIST_BOX_WIDTH / 2, TEAM_LIST_TEAM_OFFSET, nameScale, 16777215, true);
int i = 0;
for (AutoRefereeObjective obj : at.getObjectives()) {
GL11.glPushMatrix();
GL11.glTranslatef(0, TEAM_LIST_OBJECTIVES_Y_OFFSET + i * TEAM_LIST_OBJECTIVES_HEIGHT, 0);
mc.ingameGUI.drawRect(TEAM_LIST_OBJ_X_OFFSET - TEAM_LIST_OBJ_BORDER_WIDTH, TEAM_LIST_OBJ_Y_OFFSET - TEAM_LIST_OBJ_BORDER_WIDTH, TEAM_LIST_OBJ_X_OFFSET + TEAM_LIST_OBJ_RECT_WIDTH + TEAM_LIST_OBJ_BORDER_WIDTH, TEAM_LIST_OBJ_Y_OFFSET + TEAM_LIST_OBJ_RECT_WIDTH + TEAM_LIST_OBJ_BORDER_WIDTH, 0x33FFFFFF);
autoReferee.renderItem(obj.getId(), obj.getData(), TEAM_LIST_OBJ_X_OFFSET, TEAM_LIST_OBJ_Y_OFFSET, 1F);
//autoReferee.renderItem(obj.getId(), obj.getData(), TEAM_LIST_OBJ_X_OFFSET, TEAM_LIST_OBJ_Y_OFFSET, 1F);
autoReferee.renderString(obj.getStatus().getName(), TEAM_LIST_OBJ_X_OFFSET + TEAM_LIST_TEXT_OFFSET, 0, 1F, 16777215, true);
GL11.glPopMatrix();
++i;
}

GL11.glPushMatrix();
GL11.glTranslatef(0, TEAM_LIST_OBJECTIVES_Y_OFFSET + i * TEAM_LIST_OBJECTIVES_HEIGHT, 0);
mc.ingameGUI.drawRect(TEAM_LIST_OBJ_X_OFFSET - TEAM_LIST_OBJ_BORDER_WIDTH, TEAM_LIST_OBJ_Y_OFFSET - TEAM_LIST_OBJ_BORDER_WIDTH, TEAM_LIST_OBJ_X_OFFSET + TEAM_LIST_OBJ_RECT_WIDTH + TEAM_LIST_OBJ_BORDER_WIDTH, TEAM_LIST_OBJ_Y_OFFSET + TEAM_LIST_OBJ_RECT_WIDTH + TEAM_LIST_OBJ_BORDER_WIDTH, 0x33FFFFFF);
autoReferee.renderString("Go to Victory Monument", TEAM_LIST_OBJ_X_OFFSET + TEAM_LIST_TEXT_OFFSET, 0, 1F, 16777215, true);
GL11.glPopMatrix();
++i;

GL11.glPushMatrix();
GL11.glTranslatef(0, TEAM_LIST_OBJECTIVES_Y_OFFSET + i * TEAM_LIST_OBJECTIVES_HEIGHT, 0);
mc.ingameGUI.drawRect(TEAM_LIST_OBJ_X_OFFSET - TEAM_LIST_OBJ_BORDER_WIDTH, TEAM_LIST_OBJ_Y_OFFSET - TEAM_LIST_OBJ_BORDER_WIDTH, TEAM_LIST_OBJ_X_OFFSET + TEAM_LIST_OBJ_RECT_WIDTH + TEAM_LIST_OBJ_BORDER_WIDTH, TEAM_LIST_OBJ_Y_OFFSET + TEAM_LIST_OBJ_RECT_WIDTH + TEAM_LIST_OBJ_BORDER_WIDTH, 0x33FFFFFF);
autoReferee.renderString("Go to spawn", TEAM_LIST_OBJ_X_OFFSET + TEAM_LIST_TEXT_OFFSET, 0, 1F, 16777215, true);
GL11.glPopMatrix();
++i;

}

public static void renderGeneralHUD(Minecraft mc) {
Expand Down

0 comments on commit e38b9fc

Please sign in to comment.