Started Working on Security Gui. (incomplete)
This commit is contained in:
parent
7c9799320d
commit
dd37b28190
|
@ -20,6 +20,7 @@ import appeng.container.slot.AppEngSlot;
|
|||
import appeng.core.Configuration;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.parts.reporting.PartTerminal;
|
||||
import appeng.tile.misc.TileSecurity;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class GuiMEMonitorable extends AEBaseMEGui
|
||||
|
@ -29,6 +30,10 @@ public class GuiMEMonitorable extends AEBaseMEGui
|
|||
ItemRepo repo;
|
||||
|
||||
GuiText myName;
|
||||
|
||||
int xoffset = 9;
|
||||
int perRow = 9;
|
||||
|
||||
int rows = 0;
|
||||
int maxRows = Integer.MAX_VALUE;
|
||||
|
||||
|
@ -39,13 +44,14 @@ public class GuiMEMonitorable extends AEBaseMEGui
|
|||
xSize = 195;
|
||||
ySize = 204;
|
||||
|
||||
if ( te instanceof IPortableCell )
|
||||
if ( te instanceof TileSecurity )
|
||||
myName = GuiText.Security;
|
||||
else if ( te instanceof IPortableCell )
|
||||
myName = GuiText.PortableCell;
|
||||
if ( te instanceof IMEChest )
|
||||
else if ( te instanceof IMEChest )
|
||||
myName = GuiText.Chest;
|
||||
else if ( te instanceof PartTerminal )
|
||||
myName = GuiText.Terminal;
|
||||
|
||||
}
|
||||
|
||||
public void postUpdate(List<IAEItemStack> list)
|
||||
|
@ -60,7 +66,7 @@ public class GuiMEMonitorable extends AEBaseMEGui
|
|||
private void setScrollBar()
|
||||
{
|
||||
myScrollBar.setTop( 18 ).setLeft( 175 ).setHeight( rows * 18 - 2 );
|
||||
myScrollBar.setRange( 0, (repo.size() + 8) / 9 - rows, Math.max( 1, rows / 6 ) );
|
||||
myScrollBar.setRange( 0, (repo.size() + perRow - 1) / perRow - rows, Math.max( 1, rows / 6 ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -80,9 +86,9 @@ public class GuiMEMonitorable extends AEBaseMEGui
|
|||
meSlots.clear();
|
||||
for (int y = 0; y < rows; y++)
|
||||
{
|
||||
for (int x = 0; x < 9; x++)
|
||||
for (int x = 0; x < perRow; x++)
|
||||
{
|
||||
meSlots.add( new InternalSlotME( repo, x + y * 9, 9 + x * 18, 18 + y * 18 ) );
|
||||
meSlots.add( new InternalSlotME( repo, x + y * perRow, xoffset + x * 18, 18 + y * 18 ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,7 +104,7 @@ public class GuiMEMonitorable extends AEBaseMEGui
|
|||
buttonList.add( new GuiImgButton( this.guiLeft - 18, guiTop + 28, Settings.SORT_DIRECTION, Configuration.instance.settings
|
||||
.getSetting( Settings.SORT_DIRECTION ) ) );
|
||||
|
||||
searchField = new GuiTextField( this.fontRenderer, this.guiLeft + 82, this.guiTop + 6, 89, this.fontRenderer.FONT_HEIGHT );
|
||||
searchField = new GuiTextField( this.fontRenderer, this.guiLeft + Math.max( 82, xoffset ), this.guiTop + 6, 89, this.fontRenderer.FONT_HEIGHT );
|
||||
searchField.setEnableBackgroundDrawing( false );
|
||||
searchField.setMaxStringLength( 25 );
|
||||
searchField.setTextColor( 0xFFFFFF );
|
||||
|
@ -151,7 +157,7 @@ public class GuiMEMonitorable extends AEBaseMEGui
|
|||
@Override
|
||||
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY)
|
||||
{
|
||||
bindTexture( "guis/terminal.png" );
|
||||
bindTexture( getBackground() );
|
||||
this.drawTexturedModalRect( offsetX, offsetY, 0, 0, xSize, 18 );
|
||||
|
||||
for (int x = 0; x < rows; x++)
|
||||
|
@ -162,6 +168,11 @@ public class GuiMEMonitorable extends AEBaseMEGui
|
|||
searchField.drawTextBox();
|
||||
}
|
||||
|
||||
protected String getBackground()
|
||||
{
|
||||
return "guis/terminal.png";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY)
|
||||
{
|
||||
|
|
|
@ -1,31 +1,20 @@
|
|||
package appeng.client.gui.implementations;
|
||||
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import appeng.client.gui.AEBaseGui;
|
||||
import appeng.container.implementations.ContainerSecurity;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.tile.misc.TileSecurity;
|
||||
import appeng.api.storage.IStorageMonitorable;
|
||||
|
||||
public class GuiSecurity extends AEBaseGui
|
||||
public class GuiSecurity extends GuiMEMonitorable
|
||||
{
|
||||
|
||||
public GuiSecurity(InventoryPlayer inventoryPlayer, TileSecurity te) {
|
||||
super( new ContainerSecurity( inventoryPlayer, te ) );
|
||||
this.ySize = 199;
|
||||
public GuiSecurity(InventoryPlayer inventoryPlayer, IStorageMonitorable te) {
|
||||
super( inventoryPlayer, te );
|
||||
perRow = 5;
|
||||
xoffset = 81;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY)
|
||||
protected String getBackground()
|
||||
{
|
||||
bindTexture( "guis/security.png" );
|
||||
this.drawTexturedModalRect( offsetX, offsetY, 0, 0, xSize, ySize );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY)
|
||||
{
|
||||
fontRenderer.drawString( GuiText.Security.getLocal(), 8, 6, 4210752 );
|
||||
fontRenderer.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 );
|
||||
return "guis/security.png";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,19 +2,13 @@ package appeng.container.implementations;
|
|||
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.tile.misc.TileSecurity;
|
||||
import appeng.api.storage.IStorageMonitorable;
|
||||
|
||||
public class ContainerSecurity extends AEBaseContainer
|
||||
public class ContainerSecurity extends ContainerMEMonitorable
|
||||
{
|
||||
|
||||
TileSecurity myte;
|
||||
|
||||
public ContainerSecurity(InventoryPlayer ip, TileSecurity te) {
|
||||
super( ip, te, null );
|
||||
myte = te;
|
||||
|
||||
bindPlayerInventory( ip, 0, 199 - /* height of playerinventory */82 );
|
||||
public ContainerSecurity(InventoryPlayer ip, IStorageMonitorable montiorable) {
|
||||
super( ip, montiorable );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -16,6 +16,7 @@ import appeng.api.networking.IGridNode;
|
|||
import appeng.api.networking.energy.IEnergyGrid;
|
||||
import appeng.api.networking.events.MENetworkPowerIdleChange;
|
||||
import appeng.api.networking.pathing.IPathingGrid;
|
||||
import appeng.api.networking.security.ISecurityGrid;
|
||||
import appeng.api.networking.storage.IStorageGrid;
|
||||
import appeng.api.networking.ticking.ITickManager;
|
||||
import appeng.api.util.AEColor;
|
||||
|
@ -256,6 +257,20 @@ public class AENetworkProxy implements IGridBlock
|
|||
return pg;
|
||||
}
|
||||
|
||||
public ISecurityGrid getSecurity() throws GridAccessException
|
||||
{
|
||||
IGrid grid = getGrid();
|
||||
if ( grid == null )
|
||||
throw new GridAccessException();
|
||||
|
||||
ISecurityGrid sg = grid.getCache( ISecurityGrid.class );
|
||||
|
||||
if ( sg == null )
|
||||
throw new GridAccessException();
|
||||
|
||||
return sg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWorldAccessable()
|
||||
{
|
||||
|
|
128
me/storage/SecurityInventory.java
Normal file
128
me/storage/SecurityInventory.java
Normal file
|
@ -0,0 +1,128 @@
|
|||
package appeng.me.storage;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.AccessRestriction;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.security.PlayerSource;
|
||||
import appeng.api.storage.IMEInventoryHandler;
|
||||
import appeng.api.storage.StorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.tile.misc.TileSecurity;
|
||||
import appeng.util.item.ItemList;
|
||||
|
||||
public class SecurityInventory implements IMEInventoryHandler<IAEItemStack>
|
||||
{
|
||||
|
||||
final TileSecurity securityTile;
|
||||
final public IItemList<IAEItemStack> storedItems = new ItemList();
|
||||
|
||||
public SecurityInventory(TileSecurity ts) {
|
||||
securityTile = ts;
|
||||
}
|
||||
|
||||
private boolean hasPermission(BaseActionSource src)
|
||||
{
|
||||
if ( src.isPlayer() )
|
||||
{
|
||||
try
|
||||
{
|
||||
return securityTile.getProxy().getSecurity().hasPermission( ((PlayerSource) src).player, SecurityPermissions.SECURITY );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectItems(IAEItemStack input, Actionable type, BaseActionSource src)
|
||||
{
|
||||
if ( hasPermission( src ) && AEApi.instance().items().itemBiometricCard.sameAs( input.getItemStack() ) )
|
||||
{
|
||||
IAEItemStack stored = storedItems.findPrecise( input );
|
||||
if ( stored == null || !stored.isMeaninful() )
|
||||
{
|
||||
if ( type == Actionable.SIMULATE )
|
||||
return null;
|
||||
|
||||
storedItems.add( input );
|
||||
securityTile.inventoryChanged();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack extractItems(IAEItemStack request, Actionable mode, BaseActionSource src)
|
||||
{
|
||||
if ( hasPermission( src ) )
|
||||
{
|
||||
IAEItemStack target = storedItems.findPrecise( request );
|
||||
if ( target != null )
|
||||
{
|
||||
IAEItemStack output = target.copy();
|
||||
|
||||
if ( mode == Actionable.SIMULATE )
|
||||
return output;
|
||||
|
||||
target.setStackSize( 0 );
|
||||
securityTile.inventoryChanged();
|
||||
return output;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemList<IAEItemStack> getAvailableItems(IItemList out)
|
||||
{
|
||||
for (IAEItemStack ais : storedItems)
|
||||
out.add( ais );
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageChannel getChannel()
|
||||
{
|
||||
return StorageChannel.ITEMS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccessRestriction getAccess()
|
||||
{
|
||||
return AccessRestriction.READ_WRITE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPrioritized(IAEItemStack input)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAccept(IAEItemStack input)
|
||||
{
|
||||
return AEApi.instance().items().itemBiometricCard.sameAs( input.getItemStack() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlot()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
|
@ -6,28 +6,52 @@ import java.io.IOException;
|
|||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.api.features.IPlayerRegistry;
|
||||
import appeng.api.implementations.items.IBiometricCard;
|
||||
import appeng.api.networking.GridFlags;
|
||||
import appeng.api.networking.events.MENetworkChannelsChanged;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.api.networking.events.MENetworkSecurityChange;
|
||||
import appeng.api.storage.IMEInventoryHandler;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.IStorageMonitorable;
|
||||
import appeng.api.storage.MEMonitorHandler;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.DimensionalCoord;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.storage.SecurityInventory;
|
||||
import appeng.tile.events.AETileEventHandler;
|
||||
import appeng.tile.events.TileEventType;
|
||||
import appeng.tile.grid.AENetworkTile;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
public class TileSecurity extends AENetworkTile
|
||||
public class TileSecurity extends AENetworkTile implements IStorageMonitorable
|
||||
{
|
||||
|
||||
private static int diffrence = 0;
|
||||
|
||||
private SecurityInventory inventory = new SecurityInventory( this );
|
||||
private MEMonitorHandler<IAEItemStack> securityMonitor = new MEMonitorHandler<IAEItemStack>( inventory );
|
||||
|
||||
private boolean isActive = false;
|
||||
|
||||
public long securityKey;
|
||||
|
||||
IMEInventoryHandler<IAEItemStack> getSecurityInventory()
|
||||
{
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReady()
|
||||
{
|
||||
|
@ -76,17 +100,64 @@ public class TileSecurity extends AENetworkTile
|
|||
public void writeToNBT(NBTTagCompound data)
|
||||
{
|
||||
data.setLong( "securityKey", securityKey );
|
||||
NBTTagCompound storedItems = new NBTTagCompound();
|
||||
|
||||
int offset = 0;
|
||||
for (IAEItemStack ais : inventory.storedItems)
|
||||
{
|
||||
NBTTagCompound it = new NBTTagCompound();
|
||||
ais.getItemStack().writeToNBT( it );
|
||||
storedItems.setCompoundTag( "" + (offset++), it );
|
||||
}
|
||||
|
||||
data.setCompoundTag( "storedItems", storedItems );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data)
|
||||
{
|
||||
securityKey = data.getLong( "securityKey" );
|
||||
NBTTagCompound storedItems = data.getCompoundTag( "storedItems" );
|
||||
for (Object obj : storedItems.getTags())
|
||||
{
|
||||
if ( obj instanceof NBTTagCompound )
|
||||
{
|
||||
inventory.storedItems.add( AEItemStack.create( ItemStack.loadItemStackFromNBT( (NBTTagCompound) obj ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public void inventoryChanged()
|
||||
{
|
||||
try
|
||||
{
|
||||
saveChanges();
|
||||
gridProxy.getGrid().postEvent( new MENetworkSecurityChange() );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
public void readPermissions(HashMap<Integer, EnumSet<SecurityPermissions>> playerPerms)
|
||||
{
|
||||
IPlayerRegistry pr = AEApi.instance().registries().players();
|
||||
|
||||
// read permissions
|
||||
for (IAEItemStack ais : inventory.storedItems)
|
||||
{
|
||||
ItemStack is = ais.getItemStack();
|
||||
Item i = is.getItem();
|
||||
if ( i instanceof IBiometricCard )
|
||||
{
|
||||
IBiometricCard bc = (IBiometricCard) i;
|
||||
playerPerms.put( pr.getID( bc.getUserName( is ) ), bc.getPermissions( is ) );
|
||||
}
|
||||
}
|
||||
|
||||
// make sure thea admin is Boss.
|
||||
playerPerms.put( gridProxy.getNode().getPlayerID(), EnumSet.allOf( SecurityPermissions.class ) );
|
||||
}
|
||||
|
||||
|
@ -144,4 +215,16 @@ public class TileSecurity extends AENetworkTile
|
|||
return isActive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMEMonitor<IAEItemStack> getItemInventory()
|
||||
{
|
||||
return securityMonitor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMEMonitor<IAEFluidStack> getFluidInventory()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue