Brief access info is now displayed under two circumstances: if you have been granted explicit access to the territory you are in ("access granted"), or if you are a normal member of the faction which owns the territory and access is denied to you ("access restricted"). This info will be displayed through Spout under the faction tag if possible, otherwise it will be displayed through chat.

New conf.json setting:
"spoutTerritoryAccessShow": true,  - whether to show brief access info using Spout
This commit is contained in:
Brettflan
2012-05-16 15:29:00 -05:00
parent 01d9f62bdd
commit 4460438365
7 changed files with 117 additions and 11 deletions

View File

@ -268,6 +268,27 @@ public class SpoutFeatures
return mainListener.updateTerritoryDisplay(player, true);
}
// update access info for all players inside a specified chunk; if specified chunk is null, then simply update everyone online
public static void updateAccessInfoLoc(FLocation fLoc)
{
if ( ! isEnabled()) return;
Set<FPlayer> players = FPlayers.i.getOnline();
for (FPlayer player : players)
{
if (fLoc == null || player.getLastStoodAt().equals(fLoc))
mainListener.updateAccessInfo(player);
}
}
// update owner list for specified player
public static boolean updateAccessInfo(FPlayer player)
{
if ( ! isEnabled()) return false;
return mainListener.updateAccessInfo(player);
}
public static void playerDisconnect(FPlayer player)
{
if ( ! isEnabled()) return;

View File

@ -15,8 +15,10 @@ import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.TerritoryAccess;
import org.getspout.spoutapi.event.spout.SpoutCraftEnableEvent;
import org.getspout.spoutapi.gui.Color;
import org.getspout.spoutapi.gui.GenericLabel;
import org.getspout.spoutapi.player.SpoutPlayer;
import org.getspout.spoutapi.SpoutManager;
@ -40,7 +42,7 @@ public class SpoutMainListener implements Listener
private transient static Map<String, GenericLabel> territoryLabels = new HashMap<String, GenericLabel>();
private transient static Map<String, NoticeLabel> territoryChangeLabels = new HashMap<String, NoticeLabel>();
private transient static Map<String, GenericLabel> ownerLabels = new HashMap<String, GenericLabel>();
private transient static Map<String, GenericLabel> accessLabels = new HashMap<String, GenericLabel>();
private final static int SCREEN_WIDTH = 427;
// private final static int SCREEN_HEIGHT = 240;
@ -60,11 +62,28 @@ public class SpoutMainListener implements Listener
return true;
}
public boolean updateAccessInfo(FPlayer player)
{
Player p = player.getPlayer();
if (p == null)
return false;
SpoutPlayer sPlayer = SpoutManager.getPlayer(p);
if (!sPlayer.isSpoutCraftEnabled() || (Conf.spoutTerritoryDisplaySize <= 0 && ! Conf.spoutTerritoryNoticeShow))
return false;
FLocation here = new FLocation(player);
doAccessInfo(player, sPlayer, here);
return true;
}
public void removeTerritoryLabels(String playerName)
{
territoryLabels.remove(playerName);
territoryChangeLabels.remove(playerName);
ownerLabels.remove(playerName);
accessLabels.remove(playerName);
}
@ -130,6 +149,53 @@ public class SpoutMainListener implements Listener
label.resetNotice();
label.setDirty(true);
}
// and access info, of course
doAccessInfo(player, sPlayer, here);
}
private static final Color accessGrantedColor = new Color(0.2f, 1.0f, 0.2f);
private static final Color accessDeniedColor = new Color(1.0f, 0.2f, 0.2f);
private void doAccessInfo(FPlayer player, SpoutPlayer sPlayer, FLocation here)
{
if (Conf.spoutTerritoryDisplayPosition <= 0 || Conf.spoutTerritoryDisplaySize <= 0 || ! Conf.spoutTerritoryAccessShow) return;
// -----------
// Access Info
// -----------
GenericLabel label;
if (accessLabels.containsKey(player.getName()))
label = accessLabels.get(player.getName());
else
{
label = new GenericLabel();
label.setWidth(1).setHeight(1); // prevent Spout's questionable new "no default size" warning
label.setScale(Conf.spoutTerritoryDisplaySize);
label.setY((int)(10 * Conf.spoutTerritoryDisplaySize));
sPlayer.getMainScreen().attachWidget(P.p, label);
accessLabels.put(player.getName(), label);
}
String msg = "";
TerritoryAccess access = Board.getTerritoryAccessAt(here);
if ( ! access.isDefault())
{
if (access.subjectHasAccess(player))
{
msg = "access granted";
label.setTextColor(accessGrantedColor);
}
else if (access.subjectAccessIsRestricted(player))
{
msg = "access restricted";
label.setTextColor(accessDeniedColor);
}
}
label.setText(msg);
alignLabel(label, msg);
label.setDirty(true);
}
// this is only necessary because Spout text size scaling is currently bugged and breaks their built-in alignment methods