work on Global lists for GUI

This commit is contained in:
Robert Seifert 2013-04-25 04:28:31 -04:00
parent 2ba22f5417
commit ad29a6aa59
5 changed files with 201 additions and 15 deletions

View file

@ -0,0 +1,9 @@
package dark.library.access;
public class GlobalAccess
{
public GlobalAccess(String name)
{
}
}

View file

@ -29,9 +29,9 @@ public class GlobalAccessLoader implements INbtSave
@ServerStarting
public void serverStarting(FMLServerStartingEvent event)
{
if (!GlobalAccessList.hasLoaded)
if (!GlobalAccessManager.hasLoaded)
{
GlobalAccessList.getMasterSaveFile();
GlobalAccessManager.getMasterSaveFile();
}
}
@ -44,12 +44,12 @@ public class GlobalAccessLoader implements INbtSave
@Override
public NBTTagCompound getSaveData()
{
return GlobalAccessList.getMasterSaveFile();
return GlobalAccessManager.getMasterSaveFile();
}
@Override
public boolean shouldSave(boolean isServer)
{
return isServer && GlobalAccessList.hasLoaded && !GlobalAccessList.loading;
return isServer && GlobalAccessManager.hasLoaded && !GlobalAccessManager.loading;
}
}

View file

@ -2,13 +2,16 @@ package dark.library.access;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import net.minecraft.nbt.NBTTagCompound;
import universalelectricity.core.vector.Vector2;
import universalelectricity.prefab.flag.NBTFileLoader;
public class GlobalAccessList
public class GlobalAccessManager
{
/** Hash map of loaded lists **/
@ -43,6 +46,31 @@ public class GlobalAccessList
return list;
}
/**
* gets all the access list by name the user can edit
*/
public List<String> getUsersLists(String username)
{
List<String> lists = new ArrayList<String>();
Iterator<Entry<String, List<UserAccess>>> it = this.globalUserLists.entrySet().iterator();
while (it.hasNext())
{
Entry<String, List<UserAccess>> entry = it.next();
List<UserAccess> list = entry.getValue();
for (UserAccess access : list)
{
if (access.username.equalsIgnoreCase(username) && access.level.ordinal() >= AccessLevel.ADMIN.ordinal())
{
lists.add(entry.getKey());
break;
}
}
}
return lists;
}
/**
* creates a new user access list
*

View file

@ -0,0 +1,50 @@
package dark.library.access;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.world.World;
import universalelectricity.prefab.network.PacketManager;
import com.google.common.io.ByteArrayDataInput;
public class GuiPacketManager extends PacketManager
{
public enum GuiPacketType
{
USER_LISTS_REQUEST, USER_LISTS, LISTS_DATA, LISTS_DATA_REQUEST;
}
@Override
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
{
if (player != null)
{
World world = player.worldObj;
GuiPacketType packetID = GuiPacketType.values()[dataStream.readInt()];
if (world.isRemote)
{
if (packetID == GuiPacketType.USER_LISTS)
{
}
if (packetID == GuiPacketType.LISTS_DATA)
{
}
}
else
{
if (packetID == GuiPacketType.USER_LISTS_REQUEST)
{
}
}
}
}
public void requestData()
{
}
}

View file

@ -1,5 +1,11 @@
package dark.library.gui;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.entity.player.EntityPlayer;
@ -8,20 +14,26 @@ import net.minecraft.util.StringTranslate;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
import universalelectricity.core.vector.Vector2;
import universalelectricity.prefab.GuiBase;
import universalelectricity.prefab.vector.Region2;
import dark.library.DarkMain;
import dark.library.access.AccessLevel;
import dark.library.access.UserAccess;
import dark.library.access.interfaces.IScroll;
public class GuiGlobalList extends GuiBase
public class GuiGlobalList extends GuiBase implements IScroll
{
EntityPlayer player;
private GuiTextField stringInput;
int xSize;
int ySize;
public GuiGlobalList(EntityPlayer player) {
private int scroll = 0;
private static final int SPACING = 10;
private final HashMap<Object, Vector2> outputMap = new HashMap<Object, Vector2>();
public GuiGlobalList(EntityPlayer player)
{
super();
this.player = player;
this.xSize = 256;
this.ySize = 226;
}
@Override
@ -80,10 +92,34 @@ public class GuiGlobalList extends GuiBase
protected void mouseClicked(int x, int y, int type)
{
super.mouseClicked(x, y, type);
if (type == 0)
{
Iterator<Entry<Object, Vector2>> it = this.outputMap.entrySet().iterator();
while (it.hasNext())
{
Entry<Object, Vector2> entry = it.next();
Vector2 minPos = entry.getValue();
minPos.x -= 2;
minPos.y -= 2;
Vector2 maxPos = minPos.clone();
maxPos.x += 132;
maxPos.y += SPACING + 2;
if (new Region2(minPos, maxPos).isIn(new Vector2(x - this.guiLeft, y - this.guiTop)))
{
this.clickedEntry(entry.getKey());
}
}
}
this.stringInput.mouseClicked(x, y, type);
}
public void clickedEntry(Object entry)
{
}
@Override
protected void drawForegroundLayer(int x, int y, float var1)
{
@ -103,4 +139,67 @@ public class GuiGlobalList extends GuiBase
this.drawTexturedModalRect(containerWidth, containerHeight, 0, 0, this.xSize, this.ySize);
}
public void drawConsole(int x, int y, int lines)
{
int color = 14737632;
outputMap.clear();
// Draws Each Line
for (int i = 0; i < lines; i++)
{
int currentLine = i + this.getScroll();
if (currentLine < this.getListLength() && currentLine >= 0)
{
Object object = getDisplayList().get(currentLine);
String line = "-----";
if (object instanceof UserAccess)
{
UserAccess accesInfo = (UserAccess) object;
line = accesInfo.username + " (" + accesInfo.level.displayName + ")";
}
else if (object instanceof String)
{
String accesInfo = (String) object;
line = "List: " + accesInfo;
}
if (line != null && line != "")
{
Vector2 drawPosition = new Vector2(x, SPACING * i + y);
outputMap.put(object, drawPosition);
this.fontRenderer.drawString(line, drawPosition.intX(), drawPosition.intY(), color);
}
}
}
}
public int getListLength()
{
return 10;
}
public List getDisplayList()
{
return new ArrayList<>();
}
@Override
public void scroll(int amount)
{
this.setScroll(this.scroll + amount);
}
@Override
public void setScroll(int length)
{
this.scroll = Math.max(Math.min(length, this.getListLength()), 0);
}
@Override
public int getScroll()
{
return this.scroll;
}
}