Implement the old classic player list.

This commit is contained in:
UnknownShadow200 2016-01-12 14:26:39 +11:00
parent 2398dded54
commit 6621f81cda
10 changed files with 229 additions and 25 deletions

View File

@ -123,7 +123,9 @@ namespace ClassicalSharp {
}
void CreatePlayerListWidget() {
if( game.Network.UsingExtPlayerList ) {
if( game.UseClassicTabList ) {
playerList = new ClassicPlayerListWidget( game, playerFont );
} else if( game.Network.UsingExtPlayerList ) {
playerList = new ExtPlayerListWidget( game, playerFont );
} else {
playerList = new NormalPlayerListWidget( game, playerFont );

View File

@ -27,6 +27,12 @@ namespace ClassicalSharp {
Options.Set( OptionsKey.UseClassicGui, v == "yes" );
} ),
Make( -140, -50, "Classic player list", OnWidgetClick,
g => g.UseClassicTabList ? "yes" : "no",
(g, v) => { g.UseClassicTabList = v == "yes";
Options.Set( OptionsKey.UseClassicTabList, v == "yes" );
} ),
// Column 2
Make( 140, -100, "Allow custom blocks", OnWidgetClick,
g => g.AllowCustomBlocks ? "yes" : "no",
@ -50,11 +56,12 @@ namespace ClassicalSharp {
(g, w) => g.SetNewScreen( new PauseScreen( g ) ) ),
null,
};
buttons[3].Disabled = true;
buttons[4].Disabled = true;
validators = new MenuInputValidator[] {
new BooleanValidator(),
new BooleanValidator(),
new BooleanValidator(),
new BooleanValidator(),
new BooleanValidator(),

View File

@ -0,0 +1,188 @@
using System;
using System.Collections.Generic;
using System.Drawing;
namespace ClassicalSharp {
public sealed class ClassicPlayerListWidget : PlayerListWidget {
bool extList;
int elemHeight;
ChatTextWidget overview;
static FastColour lightTableCol = new FastColour( 20, 20, 20, 180 );
public ClassicPlayerListWidget( Game game, Font font ) : base( game, font ) {
textures = new Texture[256];
extList = game.Network.UsingExtPlayerList;
}
PlayerInfo[] info = new PlayerInfo[256];
class PlayerInfo {
public string Name, ColouredName;
public byte Id;
public PlayerInfo( Player p ) {
ColouredName = p.DisplayName;
Name = Utils.StripColours( p.DisplayName );
Id = p.ID;
}
public PlayerInfo( CpeListInfo p ) {
ColouredName = p.PlayerName;
Name = Utils.StripColours( p.PlayerName );
Id = p.NameId;
}
}
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 ) )
return Utils.StripColours( info[i].Name );
}
return null;
}
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 ) {
graphicsApi.Texturing = false;
int offset = overview.Height;
int height = namesPerColumn * (elemHeight + 1) + boundsSize * 2 + offset;
graphicsApi.Draw2DQuad( X, Y - offset, Width, height, lightTableCol );
graphicsApi.Texturing = true;
overview.MoveTo( game.Width / 2 - overview.Width / 2,
Y - offset + boundsSize / 2 );
overview.Render( delta );
for( int i = 0; i < namesCount; i++ ) {
Texture texture = textures[i];
if( texture.IsValid )
texture.Render( graphicsApi );
}
}
public override void Init() {
DrawTextArgs measureArgs = new DrawTextArgs( "ABC", font, false );
elemHeight = game.Drawer2D.MeasureChatSize( ref measureArgs ).Height;
overview = ChatTextWidget.Create( game, 0, 0, "Connected players:",
Anchor.Centre, Anchor.Centre, font );
base.Init();
if( !extList ) {
game.EntityEvents.EntityAdded += PlayerSpawned;
game.EntityEvents.EntityRemoved += PlayerDespawned;
} else {
game.EntityEvents.CpeListInfoAdded += PlayerListInfoAdded;
game.EntityEvents.CpeListInfoRemoved += PlayerDespawned;
game.EntityEvents.CpeListInfoChanged += PlayerListInfoChanged;
}
}
public override void Dispose() {
base.Dispose();
overview.Dispose();
if( !extList ) {
game.EntityEvents.EntityAdded -= PlayerSpawned;
game.EntityEvents.EntityRemoved -= PlayerDespawned;
} else {
game.EntityEvents.CpeListInfoAdded -= PlayerListInfoAdded;
game.EntityEvents.CpeListInfoChanged -= PlayerListInfoChanged;
game.EntityEvents.CpeListInfoRemoved -= PlayerDespawned;
}
}
protected override void CreateInitialPlayerInfo() {
for( int i = 0; i < EntityList.MaxCount; i++ ) {
PlayerInfo info = null;
if( extList ) {
CpeListInfo player = game.CpePlayersList[i];
if( player != null )
info = new PlayerInfo( player );
} else {
Player player = game.Players[i];
if( player != null )
info = new PlayerInfo( player );
}
if( info != null )
AddPlayerInfo( info, -1 );
}
}
void AddPlayerInfo( PlayerInfo pInfo, int index ) {
DrawTextArgs args = new DrawTextArgs( pInfo.ColouredName, font, false );
Texture tex = game.Drawer2D.MakeChatTextTexture( ref args, 0, 0 );
if( index < 0 ) {
info[namesCount] = pInfo;
textures[namesCount] = tex;
namesCount++;
} else {
info[index] = pInfo;
textures[index] = tex;
}
}
void PlayerSpawned( object sender, IdEventArgs e ) {
AddPlayerInfo( new PlayerInfo( game.Players[e.Id] ), -1 );
columns = Utils.CeilDiv( namesCount, namesPerColumn );
SortPlayerInfo();
}
void PlayerListInfoAdded( object sender, IdEventArgs e ) {
AddPlayerInfo( new PlayerInfo( game.CpePlayersList[e.Id] ), -1 );
columns = Utils.CeilDiv( namesCount, namesPerColumn );
SortPlayerInfo();
}
void PlayerListInfoChanged( object sender, IdEventArgs e ) {
for( int i = 0; i < namesCount; i++ ) {
PlayerInfo pInfo = info[i];
if( pInfo.Id != e.Id ) continue;
Texture tex = textures[i];
graphicsApi.DeleteTexture( ref tex );
AddPlayerInfo( new PlayerInfo( game.CpePlayersList[e.Id] ), i );
SortPlayerInfo();
return;
}
}
void PlayerDespawned( object sender, IdEventArgs e ) {
for( int i = 0; i < namesCount; i++ ) {
PlayerInfo pInfo = info[i];
if( pInfo.Id == e.Id ) {
RemoveInfoAt( info, i );
return;
}
}
}
PlayerInfoComparer comparer = new PlayerInfoComparer();
class PlayerInfoComparer : IComparer<PlayerInfo> {
public int Compare( PlayerInfo x, PlayerInfo y ) {
return x.Name.CompareTo( y.Name );
}
}
protected override void SortInfoList() {
Array.Sort( info, textures, 0, namesCount, comparer );
}
}
}

View File

@ -83,13 +83,7 @@ namespace ClassicalSharp {
for( int i = 0; i < namesCount; i++ ) {
PlayerInfo pInfo = info[i];
if( !pInfo.IsGroup && pInfo.NameId == e.Id ) {
Texture tex = textures[i];
graphicsApi.DeleteTexture( ref tex );
RemoveItemAt( textures, i );
RemoveItemAt( info, i );
namesCount--;
columns = Utils.CeilDiv( namesCount, namesPerColumn );
SortPlayerInfo();
RemoveInfoAt( info, i );
return;
}
}

View File

@ -71,13 +71,7 @@ namespace ClassicalSharp {
for( int i = 0; i < namesCount; i++ ) {
PlayerInfo pInfo = info[i];
if( pInfo.PlayerId == e.Id ) {
Texture tex = textures[i];
graphicsApi.DeleteTexture( ref tex );
RemoveItemAt( info, i );
RemoveItemAt( textures, i );
namesCount--;
columns = Utils.CeilDiv( namesCount, namesPerColumn );
SortPlayerInfo();
RemoveInfoAt( info, i );
return;
}
}

View File

@ -70,7 +70,7 @@ namespace ClassicalSharp {
for( ; i < maxIndex; i++ )
maxWidth = Math.Max( maxWidth, textures[i].Width );
return maxWidth;
return maxWidth + 5;
}
protected int GetColumnHeight( int column ) {
@ -79,7 +79,7 @@ namespace ClassicalSharp {
int maxIndex = Math.Min( namesCount, i + namesPerColumn );
for( ; i < maxIndex; i++ )
total += textures[i].Height;
total += textures[i].Height + 1;
return total;
}
@ -90,7 +90,7 @@ namespace ClassicalSharp {
for( ; i < maxIndex; i++ ) {
Texture tex = textures[i];
tex.X1 = x; tex.Y1 = y;
y += tex.Height;
y += tex.Height + 1;
textures[i] = tex;
}
}
@ -108,6 +108,16 @@ namespace ClassicalSharp {
protected abstract void SortInfoList();
protected void RemoveInfoAt<T>( T[] info, int i ) {
Texture tex = textures[i];
graphicsApi.DeleteTexture( ref tex );
RemoveItemAt( info, i );
RemoveItemAt( textures, i );
namesCount--;
columns = Utils.CeilDiv( namesCount, namesPerColumn );
SortPlayerInfo();
}
protected void RemoveItemAt<T>( T[] array, int index ) {
for( int i = index; i < namesCount - 1; i++ ) {
array[i] = array[i + 1];
@ -139,8 +149,12 @@ namespace ClassicalSharp {
xMax += GetColumnWidth( col );
}
OnSort();
UpdateTableDimensions();
MoveTo( X, game.Height / 4 );
}
protected virtual void OnSort() {
}
}
}

View File

@ -122,12 +122,13 @@
<Compile Include="2D\Widgets\Chat\TextGroupWidget.Formatter.cs" />
<Compile Include="2D\Widgets\Chat\TextInputWidget.cs" />
<Compile Include="2D\Widgets\Chat\TextInputWidget.Handlers.cs" />
<Compile Include="2D\Widgets\ExtPlayerListWidget.cs" />
<Compile Include="2D\Widgets\Menu\MenuInputValidator.cs" />
<Compile Include="2D\Widgets\Menu\MenuInputWidget.cs" />
<Compile Include="2D\Widgets\NormalPlayerListWidget.cs" />
<Compile Include="2D\Widgets\ButtonWidget.cs" />
<Compile Include="2D\Widgets\PlayerListWidget.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" />
<Compile Include="2D\Widgets\TextWidget.cs" />
<Compile Include="2D\Widgets\Widget.cs" />
<Compile Include="Audio\AudioPlayer.cs" />
@ -279,6 +280,7 @@
<Folder Include="2D\Widgets" />
<Folder Include="2D\Widgets\Menu" />
<Folder Include="2D\Widgets\Chat" />
<Folder Include="2D\Widgets\PlayerList" />
<Folder Include="Blocks" />
<Folder Include="Events" />
<Folder Include="Generator" />

View File

@ -125,9 +125,9 @@ namespace ClassicalSharp {
/// <summary> How sensitive the client is to changes in the player's mouse position. </summary>
public int MouseSensitivity = 30;
public bool UseClassicGui = false;
public bool TabAutocomplete;
public bool TabAutocomplete = false;
public bool UseClassicGui, UseClassicTabList;
public bool AllowCustomBlocks, AllowCPEBlocks, AllowServerTextures;

View File

@ -57,8 +57,10 @@ namespace ClassicalSharp {
ChatScale = Options.GetFloat( OptionsKey.ChatScale, 0.35f, 5f, 1f );
defaultIb = Graphics.MakeDefaultIb();
MouseSensitivity = Options.GetInt( OptionsKey.Sensitivity, 1, 100, 30 );
UseClassicGui = Options.GetBool( OptionsKey.UseClassicGui, true );
TabAutocomplete = Options.GetBool( OptionsKey.TabAutocomplete, false );
UseClassicGui = Options.GetBool( OptionsKey.UseClassicGui, true );
UseClassicTabList = Options.GetBool( OptionsKey.UseClassicTabList, false );
AllowCustomBlocks = Options.GetBool( OptionsKey.AllowCustomBlocks, true );
AllowCPEBlocks = Options.GetBool( OptionsKey.AllowCPEBlocks, true );
AllowServerTextures = Options.GetBool( OptionsKey.AllowServerTextures, true );

View File

@ -45,6 +45,7 @@ namespace ClassicalSharp {
public const string AllowServerTextures = "nostalgia-servertextures";
public const string UseClassicGui = "nostalgia-classicgui";
public const string SimpleArmsAnim = "nostalgia-simplearms";
public const string UseClassicTabList = "nostalgia-classictablist";
}
// TODO: implement this