mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-16 11:06:06 -04:00
Tab list redesign #1: Always have classic tab list sized box, show 'connected players' at top.
This commit is contained in:
parent
416247c0b0
commit
9066bf55ae
@ -88,9 +88,7 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
|
||||
if (!hadPlayerList) return;
|
||||
|
||||
if (game.UseClassicTabList) {
|
||||
playerList = new ClassicPlayerListWidget(game, playerFont);
|
||||
} else if (game.Server.UsingExtPlayerList) {
|
||||
if (game.Server.UsingExtPlayerList && !game.UseClassicTabList) {
|
||||
playerList = new ExtPlayerListWidget(game, playerFont);
|
||||
} else {
|
||||
playerList = new NormalPlayerListWidget(game, playerFont);
|
||||
|
@ -1,71 +0,0 @@
|
||||
// Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
namespace ClassicalSharp.Gui.Widgets {
|
||||
public sealed class ClassicPlayerListWidget : NormalPlayerListWidget {
|
||||
|
||||
TextWidget overview;
|
||||
static FastColour topCol = new FastColour(0, 0, 0, 180);
|
||||
static FastColour bottomCol = new FastColour(50, 50, 50, 205);
|
||||
public ClassicPlayerListWidget(Game game, Font font) : base(game, font) {
|
||||
}
|
||||
|
||||
protected override void OnSort() {
|
||||
int width = 0, centreX = game.Width / 2;
|
||||
for (int col = 0; col < columns; col++)
|
||||
width += GetColumnWidth(col);
|
||||
if (width < 480) width = 480;
|
||||
|
||||
xMin = centreX - width / 2;
|
||||
xMax = centreX + width / 2;
|
||||
|
||||
int x = xMin, y = game.Height / 2 - yHeight / 2;
|
||||
for (int col = 0; col < columns; col++) {
|
||||
SetColumnPos(col, x, y);
|
||||
x += GetColumnWidth(col);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Render(double delta) {
|
||||
gfx.Texturing = false;
|
||||
int offset = overview.Height + 10;
|
||||
int height = Math.Max(300, Height + overview.Height);
|
||||
gfx.Draw2DQuad(X, Y - offset, Width, height, topCol, bottomCol);
|
||||
|
||||
gfx.Texturing = true;
|
||||
overview.YOffset = Y - offset + 5;
|
||||
overview.Reposition();
|
||||
overview.Render(delta);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Init() {
|
||||
overview = TextWidget.Create(game, "Connected players:", font)
|
||||
.SetLocation(Anchor.Centre, Anchor.LeftOrTop, 0, 0);
|
||||
base.Init();
|
||||
}
|
||||
|
||||
protected override Texture DrawName(PlayerInfo pInfo) {
|
||||
string name = pInfo.ColouredName;
|
||||
if (game.PureClassic) name = Utils.StripColours(name);
|
||||
|
||||
DrawTextArgs args = new DrawTextArgs(name, font, false);
|
||||
Texture tex = game.Drawer2D.MakeTextTexture(ref args, 0, 0);
|
||||
game.Drawer2D.ReducePadding(ref tex, Utils.Floor(font.Size), 3);
|
||||
return tex;
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
base.Dispose();
|
||||
overview.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
@ -10,7 +10,6 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
|
||||
public ExtPlayerListWidget(Game game, Font font) : base(game, font) {
|
||||
textures = new Texture[512];
|
||||
titleFont = new Font(game.FontName, font.Size);
|
||||
elementOffset = 10;
|
||||
}
|
||||
|
||||
@ -57,7 +56,6 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
return info[i] == null || !info[i].IsGroup;
|
||||
}
|
||||
|
||||
Font titleFont;
|
||||
public override void Init() {
|
||||
base.Init();
|
||||
game.EntityEvents.TabListEntryAdded += TabEntryAdded;
|
||||
@ -70,7 +68,6 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
game.EntityEvents.TabListEntryAdded -= TabEntryAdded;
|
||||
game.EntityEvents.TabListEntryChanged -= TabEntryChanged;
|
||||
game.EntityEvents.TabListEntryRemoved -= TabEntryRemoved;
|
||||
titleFont.Dispose();
|
||||
}
|
||||
|
||||
void TabEntryChanged(object sender, IdEventArgs e) {
|
||||
@ -112,10 +109,10 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
|
||||
public override string GetNameUnder(int mouseX, int mouseY) {
|
||||
for (int i = 0; i < namesCount; i++) {
|
||||
Texture texture = textures[i];
|
||||
if (texture.IsValid && texture.Bounds.Contains(mouseX, mouseY)
|
||||
&& info[i].PlayerName != null)
|
||||
Texture tex = textures[i];
|
||||
if (tex.IsValid && tex.Bounds.Contains(mouseX, mouseY) && !info[i].IsGroup) {
|
||||
return Utils.StripColours(info[i].PlayerName);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -166,9 +163,9 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
}
|
||||
|
||||
void AddGroup(string group, ref int index) {
|
||||
DrawTextArgs args = new DrawTextArgs(group, titleFont, true);
|
||||
DrawTextArgs args = new DrawTextArgs(group, font, true);
|
||||
Texture tex = game.Drawer2D.MakeTextTexture(ref args, 0, 0);
|
||||
game.Drawer2D.ReducePadding(ref tex, Utils.Floor(titleFont.Size), 3);
|
||||
game.Drawer2D.ReducePadding(ref tex, Utils.Floor(font.Size), 3);
|
||||
|
||||
for (int i = info.Length - 1; i > index; i--) {
|
||||
info[i] = info[i - 1];
|
||||
|
@ -69,8 +69,11 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual Texture DrawName(PlayerInfo pInfo) {
|
||||
DrawTextArgs args = new DrawTextArgs(pInfo.ColouredName, font, false);
|
||||
Texture DrawName(PlayerInfo pInfo) {
|
||||
string name = pInfo.ColouredName;
|
||||
if (game.PureClassic) name = Utils.StripColours(name);
|
||||
|
||||
DrawTextArgs args = new DrawTextArgs(name, font, false);
|
||||
Texture tex = game.Drawer2D.MakeTextTexture(ref args, 0, 0);
|
||||
game.Drawer2D.ReducePadding(ref tex, Utils.Floor(font.Size), 3);
|
||||
return tex;
|
||||
|
@ -12,18 +12,24 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
this.font = font;
|
||||
}
|
||||
|
||||
protected int columnPadding = 5;
|
||||
protected int elementOffset = 0;
|
||||
|
||||
protected const int columnPadding = 5;
|
||||
protected const int boundsSize = 10;
|
||||
protected const int namesPerColumn = 20;
|
||||
|
||||
protected int elementOffset = 0;
|
||||
protected int namesCount = 0;
|
||||
protected Texture[] textures;
|
||||
protected int columns;
|
||||
protected int xMin, xMax, yHeight;
|
||||
protected static FastColour tableCol = new FastColour(50, 50, 50, 205);
|
||||
|
||||
static FastColour topCol = new FastColour(0, 0, 0, 180);
|
||||
static FastColour bottomCol = new FastColour(50, 50, 50, 205);
|
||||
TextWidget overview;
|
||||
|
||||
public override void Init() {
|
||||
overview = TextWidget.Create(game, "Connected players:", font)
|
||||
.SetLocation(Anchor.Centre, Anchor.LeftOrTop, 0, 0);
|
||||
|
||||
CreateInitialPlayerInfo();
|
||||
SortPlayerInfo();
|
||||
}
|
||||
@ -32,12 +38,21 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
|
||||
public override void Render(double delta) {
|
||||
gfx.Texturing = false;
|
||||
gfx.Draw2DQuad(X, Y, Width, Height, tableCol);
|
||||
int offset = overview.Height + 10;
|
||||
int height = Math.Max(300, Height + overview.Height);
|
||||
gfx.Draw2DQuad(X, Y - offset, Width, height, topCol, bottomCol);
|
||||
|
||||
gfx.Texturing = true;
|
||||
overview.YOffset = Y - offset + 5;
|
||||
overview.Reposition();
|
||||
overview.Render(delta);
|
||||
|
||||
for (int i = 0; i < namesCount; i++) {
|
||||
Texture texture = textures[i];
|
||||
if (texture.IsValid)
|
||||
texture.Render(gfx);
|
||||
Texture tex = textures[i];
|
||||
int texY = tex.Y;
|
||||
tex.Y1 -= 10;
|
||||
if (tex.IsValid) tex.Render(gfx);
|
||||
tex.Y1 = texY;
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,6 +62,7 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
gfx.DeleteTexture(ref tex);
|
||||
textures[i] = tex;
|
||||
}
|
||||
overview.Dispose();
|
||||
}
|
||||
|
||||
protected void UpdateTableDimensions() {
|
||||
@ -166,6 +182,20 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
Reposition();
|
||||
}
|
||||
|
||||
protected virtual void OnSort() { }
|
||||
protected virtual void OnSort() {
|
||||
int width = 0, centreX = game.Width / 2;
|
||||
for (int col = 0; col < columns; col++)
|
||||
width += GetColumnWidth(col);
|
||||
if (width < 480) width = 480;
|
||||
|
||||
xMin = centreX - width / 2;
|
||||
xMax = centreX + width / 2;
|
||||
|
||||
int x = xMin, y = game.Height / 2 - yHeight / 2;
|
||||
for (int col = 0; col < columns; col++) {
|
||||
SetColumnPos(col, x, y);
|
||||
x += GetColumnWidth(col);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -127,7 +127,6 @@
|
||||
<Compile Include="2D\Widgets\Menu\MenuInputValidator.cs" />
|
||||
<Compile Include="2D\Widgets\Menu\MenuInputWidget.cs" />
|
||||
<Compile Include="2D\Widgets\ButtonWidget.cs" />
|
||||
<Compile Include="2D\Widgets\PlayerList\ClassicPlayerListWidget.cs" />
|
||||
<Compile Include="2D\Widgets\PlayerList\ExtPlayerListWidget.cs" />
|
||||
<Compile Include="2D\Widgets\PlayerList\NormalPlayerListWidget.cs" />
|
||||
<Compile Include="2D\Widgets\PlayerList\PlayerListWidget.cs" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user