Author Topic: New Player List with Icons and status  (Read 4609 times)

What's the problem?
the icons delete as players leave, as they're supposed to. But getting them to move into place after someone leaves isn't working. Also there's no code for moving the icons if the player list sorting is changed, as I have no idea how to pull that part off as I can't even move them when someone leaves the game

Client.cs
Code: [Select]

package NotAnActualPackage
{
function gameConnection::onConnectionAccepted(%t)
{
schedule(0,0,swol_saveServerName());
return parent::onConnectionAccepted(%t);
}
function swol_saveServerName()
{
$Swol::ServerName = $ServerInfo::Name;
$Swol::ServerHostName = swol_getHostName();
}
function swol_getHostName()
{
%s = $Swol::ServerName;
if(%s $= "")
%s = $ServerInfo::Name;
%a = strPos(%s,"'s");
%b = strPos(%s,"s'");
if(%a >= %b)
%c = %a;
else
%c = %b;
if(%c == -1)
return "";
%n = getSubStr(%s,0,%c);
return %n;
}
function NewPlayerListGui::update(%this,%cl,%name,%blid,%a,%b,%c)
{
$qq=NPL_List.RowCount();
parent::update(%this,%cl,%name,%blid,%a,%b,%c);
// echo(%name);
// echo(%a SPC "-" SPC %b SPC "-" SPC %c);
}
function NPL_List::addRow(%this,%i,%t)
{
if(getField(%t,0) $= "S" && getField(%t,1) $= $Swol::ServerHostName)
{
%t = "H" @ getSubStr(%t,1,strLen(%t)-1);
%j = "<bitmap:add-ons/Script_Statuses/Icon_HostShield.png>";
}
else if(getField(%t,0) $= "S" && getField(%t,1) !$= $Swol::ServerHostName)
{
// %t = " " @ getSubStr(%t,1,strLen(%t)-1);
%j = "<bitmap:add-ons/Script_Statuses/Icon_SuperAdminShield.png>";
}
else if(getField(%t,0) $= "A")
{
// %t = " " @ getSubStr(%t,1,strLen(%t)-1);
%j = "<bitmap:add-ons/Script_Statuses/Icon_AdminShield.png>";
}
else
{
// %t = " " @ getSubStr(%t,1,strLen(%t)-1);
%j = "<bitmap:add-ons/Script_Statuses/Icon_PlayerShield.png>";
}
if($testfornow)
{
if(isObject($q[$qq]))
{
$q[$qq].delete();
}
//%i=NPL_List.getRowID();
//$testfornow=false;
$q[%i]=new GuiMLTextCtrl()
{
profile = "GuiMLTextCtrl";
horizSizing = "right";
vertSizing = "bottom";
position = "20" SPC 20*$qq;
extent = "16 16";
minExtent = "8 2";
enabled = "1";
visible = "1";
clipToParent = "1";
lineSpacing = "2";
allowColorChars = "0";
maxChars = "-1";
text = %j;
maxBitmapHeight = "-1";
selectable = "0";
autoResize = "0";
};
// %a=NPL_List.getRowID($q,NPL_List);
// $q_[$qq]=$qq;
// warn(%i);
NPL_Scroll.add($q[%i]);
$qq++;
}
parent::addRow(%this,%i,%t);
}
function NPL_list::removeRow(%this,%a)
{
parent::removeRow(%this,%a);
// warn(%a);
$q[%a].delete();
}
function NPL_list::removeRowByID(%this,%a)
{
parent::removeRowByID(%this,%a);
// warn(%a);
//NPL_List::ResetIcons();
$q[%a].delete();
}
function NPL_List::ResetIcons(%this)
{
if($qq<=0)
return;
for(%i=0;%i<$qq;%i++)
{
$q[%i].delete();
}
NewPlayerListGui::update();
}
};
activatePackage(NotAnActualPackage);
$testfornow=true;
$qq=-1;

function NPL_AddButtons()
{
%a = new GuiBitmapButtonCtrl(Legend_Icons) {
profile = "BlockButtonProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "380 33";
extent = "100 19";
minExtent = "8 2";
enabled = "1";
visible = "1";
clipToParent = "1";
command = "";
text = "Legend Icons";
groupNum = "-1";
buttonType = "PushButton";
bitmap = "base/client/ui/button1";
lockAspectRatio = "0";
alignLeft = "0";
alignTop = "0";
overflowImage = "0";
mKeepCached = "0";
mColor = "255 255 255 255";
};
%b = new GuiBitmapCtrl() {
profile = "GuiDefaultProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "52 33";
extent = "100 19";
minExtent = "8 2";
enabled = "1";
visible = "1";
clipToParent = "1";
command = "";
groupNum = "-1";
buttonType = "PushButton";
bitmap = "base/data/shapes/white";
lockAspectRatio = "0";
alignLeft = "0";
alignTop = "0";
overflowImage = "0";
mKeepCached = "0";
mColor = "200 200 200 255";
};
%c = new GuiBitmapButtonCtrl(Status) {
profile = "BlockButtonProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "56 33";
extent = "50 19";
minExtent = "8 2";
enabled = "1";
visible = "1";
clipToParent = "1";
command = "";
text = "Status";
groupNum = "-1";
buttonType = "PushButton";
bitmap = "base/client/ui/button1";
lockAspectRatio = "0";
alignLeft = "0";
alignTop = "0";
overflowImage = "0";
mKeepCached = "0";
mColor = "255 255 255 255";
};
%d = new GuiBitmapButtonCtrl() {
profile = "BlockButtonProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "110 33";
extent = "68 19";
minExtent = "8 2";
enabled = "1";
visible = "1";
clipToParent = "1";
command = "NewPlayerListGui.sortList(1);";
text = "Name";
groupNum = "-1";
buttonType = "PushButton";
bitmap = "base/client/ui/button1";
lockAspectRatio = "0";
alignLeft = "0";
alignTop = "0";
overflowImage = "0";
mKeepCached = "0";
mColor = "255 255 255 255";
};
NPL_Window.add(%a);
NPL_Window.add(%b);
NPL_Window.add(%c);
NPL_Window.add(%d);
}
NPL_AddButtons();

What's the problem?
Well for each player it creates a new GuiMLTextCtrl and sets the image using a packaged NPL_List::addRow(%this,%i,%t) which is all well and good and works. %i is the row ID so I have the GuiMLTextCtrl's in a variable using the %i which allows for them to be deleted easily when NPL_list::removeRowByID(%this,%a) is called. That all works well and good, but I can't get them to re-arrange themselves into the proper order again. Lets say there's three players, player 1 is host and on the top of the list. Player 2 is in the middle and an SA. Player 3 is a normal player. Player 2 leaves, and his SA shield gets removed, player 3 moves up below player 1, but player 3's icon stays where it was.

Lol Furling quoted me before I could post.

Well for each player it creates a new GuiMLTextCtrl and sets the image using a packaged NPL_List::addRow(%this,%i,%t) which is all well and good and works. %i is the row ID so I have the GuiMLTextCtrl's in a variable using the %i which allows for them to be deleted easily when NPL_list::removeRowByID(%this,%a) is called. That all works well and good, but I can't get them to re-arrange themselves into the proper order again. Lets say there's three players, player 1 is host and on the top of the list. Player 2 is in the middle and an SA. Player 3 is a normal player. Player 2 leaves, and his SA shield gets removed, player 3 moves up below player 1, but player 3's icon stays where it was.

Lol Furling quoted me before I could post.
I'd specify a variable on the shields of which of the rows it belongs to, then when someone leaves I'd loop through all the shields and recalculate their Y positional values by getting where the row is that they belong to and doing
%y = (%offset * %rowNum) + %baseValue;
Base Value would be the Y position of where the first shield created ends up.
Row Num would be the row number of where the shield should be.
Offset would be the space between shields.

Also, why are you using GuiMLTextCtrl's when you could use GuiBitmapCtrl's? Just curious.
« Last Edit: September 30, 2014, 02:28:40 PM by jes00 »

Also, why are you using GuiMLTextCtrl's when you could use GuiBitmapCtrl's? Just curious.
There's not really a specific reason.

There's not really a specific reason.
Hm. Seems to me like you would have used the GUI control that was made to display bitmaps rather than one that was mean't to display text.

Hm. Seems to me like you would have used the GUI control that was made to display bitmaps rather than one that was mean't to display text.
Well the default size of the text controls is perfect for what we're doing.

Well the default size of the text controls is perfect for what we're doing.
Still don't see why. What's wrong with changing the extent?

Nothing at all, it just kinda ended up being the text control.

Nothing at all, it just kinda ended up being the text control.
Great, I hope it will be fixed or not.