Permalink
Browse files

Fix tab list showing 1 group name entry as a player name entry due to…

… recent changes
  • Loading branch information...
UnknownShadow200 committed Jan 12, 2018
1 parent ad7caf4 commit 7c084db7d98d57c4750793090f8e53647b1e6144
Showing with 18 additions and 18 deletions.
  1. +18 −18 ClassicalSharp/2D/Widgets/PlayerListWidget.cs
@@ -21,10 +21,11 @@ public class PlayerListWidget : Widget {
const int columnPadding = 5;
const int boundsSize = 10;
const int namesPerColumn = 20;
const ushort groupNameID = 65535;
int elementOffset, namesCount = 0;
Texture[] textures = new Texture[512];
short[] IDs = new short[512];
ushort[] IDs = new ushort[512];
int xMin, xMax, yHeight;
static FastColour topCol = new FastColour(0, 0, 0, 180);
@@ -59,10 +60,7 @@ public class PlayerListWidget : Widget {
for (int i = 0; i < namesCount; i++) {
Texture tex = textures[i];
int texY = tex.Y;
tex.Y1 -= 10;
if (tex.IsValid) tex.Render(gfx);
tex.Y1 = texY;
}
}
@@ -82,7 +80,9 @@ public class PlayerListWidget : Widget {
public string GetNameUnder(int mouseX, int mouseY) {
for (int i = 0; i < namesCount; i++) {
Texture tex = textures[i];
if (tex.IsValid && tex.Bounds.Contains(mouseX, mouseY) && IDs[i] >= 0) {
if (!tex.IsValid || IDs[i] == groupNameID) continue;
if (tex.Bounds.Contains(mouseX, mouseY)) {
return TabList.Entries[IDs[i]].PlayerName;
}
}
@@ -145,11 +145,11 @@ public class PlayerListWidget : Widget {
for (; i < maxIndex; i++) {
Texture tex = textures[i];
tex.X1 = x; tex.Y1 = y;
tex.X1 = x; tex.Y1 = y - 10;
y += tex.Height + 1;
// offset player names a bit, compared to group name
if (!classic && IDs[i] >= 0) {
if (!classic && IDs[i] != groupNameID) {
tex.X1 += elementOffset;
}
textures[i] = tex;
@@ -239,9 +239,9 @@ public class PlayerListWidget : Widget {
return tex;
}
IComparer<short> comparer = new PlayerComparer();
class PlayerComparer : IComparer<short> {
public int Compare(short x, short y) {
IComparer<ushort> comparer = new PlayerComparer();
class PlayerComparer : IComparer<ushort> {
public int Compare(ushort x, ushort y) {
byte xRank = TabList.Entries[x].GroupRank;
byte yRank = TabList.Entries[y].GroupRank;
int rankOrder = xRank.CompareTo(yRank);
@@ -253,9 +253,9 @@ class PlayerComparer : IComparer<short> {
}
}
IComparer<short> grpComparer = new GroupComparer();
class GroupComparer : IComparer<short> {
public int Compare(short x, short y) {
IComparer<ushort> grpComparer = new GroupComparer();
class GroupComparer : IComparer<ushort> {
public int Compare(ushort x, ushort y) {
string xGroup = TabList.Entries[x].Group;
string yGroup = TabList.Entries[y].Group;
return xGroup.CompareTo(yGroup);
@@ -271,14 +271,14 @@ class GroupComparer : IComparer<short> {
// Sort the list into groups
for (int i = 0; i < namesCount; i++) {
if (IDs[i] < 0) DeleteGroup(ref i);
if (IDs[i] == groupNameID) DeleteGroup(ref i);
}
Array.Sort(IDs, textures, 0, namesCount, grpComparer);
// Sort the entries in each group
int index = 0;
while (index < namesCount) {
short id = IDs[index];
ushort id = IDs[index];
AddGroup(id, ref index);
int count = GetGroupCount(id, index);
Array.Sort(IDs, textures, index, count, comparer);
@@ -287,21 +287,21 @@ class GroupComparer : IComparer<short> {
}
void DeleteGroup(ref int i) { RemoveAt(i); i--; }
void AddGroup(short id, ref int index) {
void AddGroup(ushort id, ref int index) {
for (int i = IDs.Length - 1; i > index; i--) {
IDs[i] = IDs[i - 1];
textures[i] = textures[i - 1];
}
IDs[index] = (short)-id;
IDs[index] = groupNameID;
string group = TabList.Entries[id].Group;
textures[index] = DrawName(group, true);
index++;
namesCount++;
}
int GetGroupCount(short id, int idx) {
int GetGroupCount(ushort id, int idx) {
string group = TabList.Entries[id].Group;
int count = 0;
while (idx < namesCount && TabList.Entries[IDs[idx]].Group == group) {

0 comments on commit 7c084db

Please sign in to comment.