Add additional entity name rendering modes - no names, hovered see through only.

This commit is contained in:
UnknownShadow200 2015-12-11 14:27:06 +11:00
parent 5f1ee54faf
commit f55f073b38
6 changed files with 58 additions and 42 deletions

View File

@ -13,24 +13,24 @@ namespace ClassicalSharp {
buttons = new ButtonWidget[] { buttons = new ButtonWidget[] {
// Column 1 // Column 1
Make( -140, -150, "Block in hand", Anchor.Centre, OnWidgetClick, Make( -140, -150, "Block in hand", OnWidgetClick,
g => g.ShowBlockInHand ? "yes" : "no", g => g.ShowBlockInHand ? "yes" : "no",
(g, v) => { g.ShowBlockInHand = v == "yes"; (g, v) => { g.ShowBlockInHand = v == "yes";
Options.Set( OptionsKey.ShowBlockInHand, v == "yes" ); Options.Set( OptionsKey.ShowBlockInHand, v == "yes" );
} ), } ),
Make( -140, -100, "Field of view", Anchor.Centre, OnWidgetClick, Make( -140, -100, "Field of view", OnWidgetClick,
g => g.FieldOfView.ToString(), g => g.FieldOfView.ToString(),
(g, v) => { g.FieldOfView = Int32.Parse( v ); (g, v) => { g.FieldOfView = Int32.Parse( v );
Options.Set( OptionsKey.FieldOfView, v ); Options.Set( OptionsKey.FieldOfView, v );
g.UpdateProjection(); g.UpdateProjection();
} ), } ),
Make( -140, -50, "Show FPS", Anchor.Centre, OnWidgetClick, Make( -140, -50, "Show FPS", OnWidgetClick,
g => g.ShowFPS ? "yes" : "no", g => g.ShowFPS ? "yes" : "no",
(g, v) => g.ShowFPS = v == "yes" ), (g, v) => g.ShowFPS = v == "yes" ),
Make( -140, 0, "Hud scale", Anchor.Centre, OnWidgetClick, Make( -140, 0, "Hud scale", OnWidgetClick,
g => g.HudScale.ToString(), g => g.HudScale.ToString(),
(g, v) => { g.HudScale = Single.Parse( v ); (g, v) => { g.HudScale = Single.Parse( v );
Options.Set( OptionsKey.HudScale, v ); Options.Set( OptionsKey.HudScale, v );
@ -38,27 +38,27 @@ namespace ClassicalSharp {
} ), } ),
// Column 2 // Column 2
Make( 140, -150, "Clickable chat", Anchor.Centre, OnWidgetClick, Make( 140, -150, "Clickable chat", OnWidgetClick,
g => g.ClickableChat ? "yes" : "no", g => g.ClickableChat ? "yes" : "no",
(g, v) => { g.ClickableChat = v == "yes"; (g, v) => { g.ClickableChat = v == "yes";
Options.Set( OptionsKey.ClickableChat, v == "yes" ); Options.Set( OptionsKey.ClickableChat, v == "yes" );
} ), } ),
Make( 140, -100, "Chat scale", Anchor.Centre, OnWidgetClick, Make( 140, -100, "Chat scale", OnWidgetClick,
g => g.ChatScale.ToString(), g => g.ChatScale.ToString(),
(g, v) => { g.ChatScale = Single.Parse( v ); (g, v) => { g.ChatScale = Single.Parse( v );
Options.Set( OptionsKey.ChatScale, v ); Options.Set( OptionsKey.ChatScale, v );
g.RefreshHud(); g.RefreshHud();
} ), } ),
Make( 140, -50, "Chat lines", Anchor.Centre, OnWidgetClick, Make( 140, -50, "Chat lines", OnWidgetClick,
g => g.ChatLines.ToString(), g => g.ChatLines.ToString(),
(g, v) => { g.ChatLines = Int32.Parse( v ); (g, v) => { g.ChatLines = Int32.Parse( v );
Options.Set( OptionsKey.ChatLines, v ); Options.Set( OptionsKey.ChatLines, v );
g.RefreshHud(); g.RefreshHud();
} ), } ),
Make( 140, 0, "Arial chat font", Anchor.Centre, OnWidgetClick, Make( 140, 0, "Arial chat font", OnWidgetClick,
g => g.Drawer2D.UseBitmappedChat ? "no" : "yes", g => g.Drawer2D.UseBitmappedChat ? "no" : "yes",
(g, v) => { (g, v) => {
g.Drawer2D.UseBitmappedChat = v == "no"; g.Drawer2D.UseBitmappedChat = v == "no";
@ -87,10 +87,10 @@ namespace ClassicalSharp {
okayIndex = buttons.Length - 1; okayIndex = buttons.Length - 1;
} }
ButtonWidget Make( int x, int y, string text, Anchor vDocking, Action<Game, Widget> onClick, ButtonWidget Make( int x, int y, string text, Action<Game, Widget> onClick,
Func<Game, string> getter, Action<Game, string> setter ) { Func<Game, string> getter, Action<Game, string> setter ) {
ButtonWidget widget = ButtonWidget.Create( game, x, y, 240, 35, text, ButtonWidget widget = ButtonWidget.Create( game, x, y, 240, 35, text, Anchor.Centre,
Anchor.Centre, vDocking, titleFont, onClick ); Anchor.Centre, titleFont, onClick );
widget.GetValue = getter; widget.GetValue = getter;
widget.SetValue = setter; widget.SetValue = setter;
return widget; return widget;

View File

@ -15,25 +15,25 @@ namespace ClassicalSharp {
buttons = new ButtonWidget[] { buttons = new ButtonWidget[] {
// Column 1 // Column 1
Make( -140, -100, "Hacks enabled", Anchor.Centre, OnWidgetClick, Make( -140, -100, "Hacks enabled", OnWidgetClick,
g => g.LocalPlayer.HacksEnabled ? "yes" : "no", g => g.LocalPlayer.HacksEnabled ? "yes" : "no",
(g, v) => { g.LocalPlayer.HacksEnabled = v == "yes"; (g, v) => { g.LocalPlayer.HacksEnabled = v == "yes";
Options.Set( OptionsKey.HacksEnabled, v == "yes" ); Options.Set( OptionsKey.HacksEnabled, v == "yes" );
g.LocalPlayer.CheckHacksConsistency(); g.LocalPlayer.CheckHacksConsistency();
} ), } ),
Make( -140, -50, "Speed multiplier", Anchor.Centre, OnWidgetClick, Make( -140, -50, "Speed multiplier", OnWidgetClick,
g => g.LocalPlayer.SpeedMultiplier.ToString(), g => g.LocalPlayer.SpeedMultiplier.ToString(),
(g, v) => { g.LocalPlayer.SpeedMultiplier = Single.Parse( v ); (g, v) => { g.LocalPlayer.SpeedMultiplier = Single.Parse( v );
Options.Set( OptionsKey.Speed, v ); } ), Options.Set( OptionsKey.Speed, v ); } ),
// Column 2 // Column 2
Make( 140, -100, "Liquids breakable", Anchor.Centre, OnWidgetClick, Make( 140, -100, "Liquids breakable", OnWidgetClick,
g => g.LiquidsBreakable ? "yes" : "no", g => g.LiquidsBreakable ? "yes" : "no",
(g, v) => { g.LiquidsBreakable = v == "yes"; (g, v) => { g.LiquidsBreakable = v == "yes";
Options.Set( OptionsKey.LiquidsBreakable, v == "yes" ); } ), Options.Set( OptionsKey.LiquidsBreakable, v == "yes" ); } ),
Make( 140, -50, "Pushback placing", Anchor.Centre, OnWidgetClick, Make( 140, -50, "Pushback placing", OnWidgetClick,
g => g.LocalPlayer.PushbackPlacing g => g.LocalPlayer.PushbackPlacing
&& g.LocalPlayer.CanPushbackBlocks ? "yes" : "no", && g.LocalPlayer.CanPushbackBlocks ? "yes" : "no",
(g, v) => { (g, v) => {
@ -58,10 +58,10 @@ namespace ClassicalSharp {
okayIndex = buttons.Length - 1; okayIndex = buttons.Length - 1;
} }
ButtonWidget Make( int x, int y, string text, Anchor vDocking, Action<Game, Widget> onClick, ButtonWidget Make( int x, int y, string text, Action<Game, Widget> onClick,
Func<Game, string> getter, Action<Game, string> setter ) { Func<Game, string> getter, Action<Game, string> setter ) {
ButtonWidget widget = ButtonWidget.Create( game, x, y, 240, 35, text, ButtonWidget widget = ButtonWidget.Create( game, x, y, 240, 35, text, Anchor.Centre,
Anchor.Centre, vDocking, titleFont, onClick ); Anchor.Centre, titleFont, onClick );
widget.GetValue = getter; widget.GetValue = getter;
widget.SetValue = setter; widget.SetValue = setter;
return widget; return widget;

View File

@ -16,52 +16,53 @@ namespace ClassicalSharp {
buttons = new ButtonWidget[] { buttons = new ButtonWidget[] {
// Column 1 // Column 1
Make( -140, -100, "Use sound (WIP)", Anchor.Centre, OnWidgetClick, Make( -140, -100, "Use sound (WIP)", OnWidgetClick,
g => g.UseSound ? "yes" : "no", g => g.UseSound ? "yes" : "no",
(g, v) => { g.UseSound = v == "yes"; (g, v) => { g.UseSound = v == "yes";
g.AudioPlayer.SetSound( g.UseSound ); g.AudioPlayer.SetSound( g.UseSound );
Options.Set( OptionsKey.UseSound, v == "yes" ); }), Options.Set( OptionsKey.UseSound, v == "yes" ); }),
Make( -140, -50, "Show hover names", Anchor.Centre, OnWidgetClick, Make( -140, -50, "Names mode", OnWidgetClick,
g => g.Players.ShowHoveredNames ? "yes" : "no", g => g.Players.NamesMode.ToString(),
(g, v) => { g.Players.ShowHoveredNames = v == "yes"; (g, v) => { object raw = Enum.Parse( typeof(NameMode), v );
Options.Set( OptionsKey.ShowHoveredNames, v == "yes" ); }), g.Players.NamesMode = (NameMode)raw;
Options.Set( OptionsKey.NamesMode, v ); } ),
Make( -140, 0, "FPS limit", Anchor.Centre, OnWidgetClick, Make( -140, 0, "FPS limit", OnWidgetClick,
g => g.FpsLimit.ToString(), g => g.FpsLimit.ToString(),
(g, v) => { object raw = Enum.Parse( typeof(FpsLimitMethod), v ); (g, v) => { object raw = Enum.Parse( typeof(FpsLimitMethod), v );
g.SetFpsLimitMethod( (FpsLimitMethod)raw ); g.SetFpsLimitMethod( (FpsLimitMethod)raw );
Options.Set( OptionsKey.FpsLimit, v ); } ), Options.Set( OptionsKey.FpsLimit, v ); } ),
Make( -140, 50, "View distance", Anchor.Centre, OnWidgetClick, Make( -140, 50, "View distance", OnWidgetClick,
g => g.ViewDistance.ToString(), g => g.ViewDistance.ToString(),
(g, v) => g.SetViewDistance( Int32.Parse( v ) ) ), (g, v) => g.SetViewDistance( Int32.Parse( v ) ) ),
// Column 2 // Column 2
!network.IsSinglePlayer ? null : !network.IsSinglePlayer ? null :
Make( 140, -150, "Block physics", Anchor.Centre, OnWidgetClick, Make( 140, -150, "Block physics", OnWidgetClick,
g => ((SinglePlayerServer)network).physics.Enabled ? "yes" : "no", g => ((SinglePlayerServer)network).physics.Enabled ? "yes" : "no",
(g, v) => { (g, v) => {
((SinglePlayerServer)network).physics.Enabled = v == "yes"; ((SinglePlayerServer)network).physics.Enabled = v == "yes";
Options.Set( OptionsKey.SingleplayerPhysics, v == "yes" ); Options.Set( OptionsKey.SingleplayerPhysics, v == "yes" );
}), }),
Make( 140, -100, "Use music", Anchor.Centre, OnWidgetClick, Make( 140, -100, "Use music", OnWidgetClick,
g => g.UseMusic ? "yes" : "no", g => g.UseMusic ? "yes" : "no",
(g, v) => { g.UseMusic = v == "yes"; (g, v) => { g.UseMusic = v == "yes";
g.AudioPlayer.SetMusic( g.UseMusic ); g.AudioPlayer.SetMusic( g.UseMusic );
Options.Set( OptionsKey.UseMusic, v == "yes" ); }), Options.Set( OptionsKey.UseMusic, v == "yes" ); }),
Make( 140, -50, "View bobbing", Anchor.Centre, OnWidgetClick, Make( 140, -50, "View bobbing", OnWidgetClick,
g => g.ViewBobbing ? "yes" : "no", g => g.ViewBobbing ? "yes" : "no",
(g, v) => { g.ViewBobbing = v == "yes"; (g, v) => { g.ViewBobbing = v == "yes";
Options.Set( OptionsKey.ViewBobbing, v == "yes" ); }), Options.Set( OptionsKey.ViewBobbing, v == "yes" ); }),
Make( 140, 0, "Auto close launcher", Anchor.Centre, OnWidgetClick, Make( 140, 0, "Auto close launcher", OnWidgetClick,
g => Options.GetBool( OptionsKey.AutoCloseLauncher, false ) ? "yes" : "no", g => Options.GetBool( OptionsKey.AutoCloseLauncher, false ) ? "yes" : "no",
(g, v) => Options.Set( OptionsKey.AutoCloseLauncher, v == "yes" ) ), (g, v) => Options.Set( OptionsKey.AutoCloseLauncher, v == "yes" ) ),
Make( 140, 50, "Mouse sensitivity", Anchor.Centre, OnWidgetClick, Make( 140, 50, "Mouse sensitivity", OnWidgetClick,
g => g.MouseSensitivity.ToString(), g => g.MouseSensitivity.ToString(),
(g, v) => { g.MouseSensitivity = Int32.Parse( v ); (g, v) => { g.MouseSensitivity = Int32.Parse( v );
Options.Set( OptionsKey.Sensitivity, v ); } ), Options.Set( OptionsKey.Sensitivity, v ); } ),
@ -70,11 +71,12 @@ namespace ClassicalSharp {
(g, w) => g.SetNewScreen( new PauseScreen( g ) ) ), (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ),
null, null,
}; };
buttons[1].Metadata = typeof(NameMode);
buttons[2].Metadata = typeof(FpsLimitMethod); buttons[2].Metadata = typeof(FpsLimitMethod);
validators = new MenuInputValidator[] { validators = new MenuInputValidator[] {
new BooleanValidator(), new BooleanValidator(),
new BooleanValidator(), new EnumValidator(),
new EnumValidator(), new EnumValidator(),
new IntegerValidator( 16, 4096 ), new IntegerValidator( 16, 4096 ),
@ -87,10 +89,10 @@ namespace ClassicalSharp {
okayIndex = buttons.Length - 1; okayIndex = buttons.Length - 1;
} }
ButtonWidget Make( int x, int y, string text, Anchor vDocking, Action<Game, Widget> onClick, ButtonWidget Make( int x, int y, string text, Action<Game, Widget> onClick,
Func<Game, string> getter, Action<Game, string> setter ) { Func<Game, string> getter, Action<Game, string> setter ) {
ButtonWidget widget = ButtonWidget.Create( game, x, y, 240, 35, text, ButtonWidget widget = ButtonWidget.Create( game, x, y, 240, 35, text, Anchor.Centre,
Anchor.Centre, vDocking, titleFont, onClick ); Anchor.Centre, titleFont, onClick );
widget.GetValue = getter; widget.GetValue = getter;
widget.SetValue = setter; widget.SetValue = setter;
return widget; return widget;

View File

@ -4,6 +4,13 @@ using ClassicalSharp.GraphicsAPI;
namespace ClassicalSharp { namespace ClassicalSharp {
public enum NameMode {
NoNames,
HoveredOnly,
AllNames,
AllNamesAndHovered,
}
public class EntityList : IDisposable { public class EntityList : IDisposable {
public const int MaxCount = 256; public const int MaxCount = 256;
@ -11,13 +18,14 @@ namespace ClassicalSharp {
public Game game; public Game game;
byte closestId; byte closestId;
/// <summary> Whether the names of entities that the player is looking at /// <summary> Mode of how names of hovered entities are rendered (with or without depth testing),
/// should be rendered through everything else without depth testing. </summary> /// and how other entity names are rendered. </summary>
public bool ShowHoveredNames; public NameMode NamesMode = NameMode.AllNames;
public EntityList( Game game ) { public EntityList( Game game ) {
this.game = game; this.game = game;
game.Events.ChatFontChanged += ChatFontChanged; game.Events.ChatFontChanged += ChatFontChanged;
NamesMode = Options.GetEnum( OptionsKey.NamesMode, NameMode.AllNamesAndHovered );
} }
/// <summary> Performs a tick call for all player entities contained in this list. </summary> /// <summary> Performs a tick call for all player entities contained in this list. </summary>
@ -44,17 +52,23 @@ namespace ClassicalSharp {
/// If ShowHoveredNames is false, this method only renders names of entities that are /// If ShowHoveredNames is false, this method only renders names of entities that are
/// not currently being looked at by the user. </summary> /// not currently being looked at by the user. </summary>
public void RenderNames( IGraphicsApi api, double delta, float t ) { public void RenderNames( IGraphicsApi api, double delta, float t ) {
if( NamesMode == NameMode.NoNames )
return;
api.Texturing = true; api.Texturing = true;
api.AlphaTest = true; api.AlphaTest = true;
LocalPlayer localP = game.LocalPlayer; LocalPlayer localP = game.LocalPlayer;
Vector3 eyePos = localP.EyePosition; Vector3 eyePos = localP.EyePosition;
Vector3 dir = Utils.GetDirVector( localP.YawRadians, localP.PitchRadians ); Vector3 dir = Utils.GetDirVector( localP.YawRadians, localP.PitchRadians );
if( ShowHoveredNames ) closestId = 255;
if( NamesMode != NameMode.AllNames )
closestId = GetClosetPlayer( game.LocalPlayer ); closestId = GetClosetPlayer( game.LocalPlayer );
if( NamesMode == NameMode.HoveredOnly )
return;
for( int i = 0; i < Players.Length; i++ ) { for( int i = 0; i < Players.Length; i++ ) {
if( Players[i] == null ) continue; if( Players[i] == null ) continue;
if( !ShowHoveredNames || (i != closestId || i == 255) ) if( i != closestId || i == 255 )
Players[i].RenderName(); Players[i].RenderName();
} }
api.Texturing = false; api.Texturing = false;
@ -62,7 +76,8 @@ namespace ClassicalSharp {
} }
public void RenderHoveredNames( IGraphicsApi api, double delta, float t ) { public void RenderHoveredNames( IGraphicsApi api, double delta, float t ) {
if( !ShowHoveredNames ) return; if( NamesMode == NameMode.NoNames || NamesMode == NameMode.AllNames )
return;
api.Texturing = true; api.Texturing = true;
api.AlphaTest = true; api.AlphaTest = true;
api.DepthTest = false; api.DepthTest = false;

View File

@ -43,7 +43,6 @@ namespace ClassicalSharp {
Options.Load(); Options.Load();
AcceptedUrls.Load(); AcceptedUrls.Load();
Players.ShowHoveredNames = Options.GetBool( OptionsKey.ShowHoveredNames, true );
ViewDistance = Options.GetInt( OptionsKey.ViewDist, 16, 4096, 512 ); ViewDistance = Options.GetInt( OptionsKey.ViewDist, 16, 4096, 512 );
InputHandler = new InputHandler( this ); InputHandler = new InputHandler( this );
Chat = new ChatLog( this ); Chat = new ChatLog( this );

View File

@ -17,11 +17,11 @@ namespace ClassicalSharp {
public const string ArialChatFont = "arialchatfont"; public const string ArialChatFont = "arialchatfont";
public const string DefaultTexturePack = "defaulttexpack"; public const string DefaultTexturePack = "defaulttexpack";
public const string SingleplayerPhysics = "singleplayerphysics"; public const string SingleplayerPhysics = "singleplayerphysics";
public const string ShowHoveredNames = "showhoverednames";
public const string ShowBlockInHand = "blockinhand"; public const string ShowBlockInHand = "blockinhand";
public const string UseMusic = "usemusic"; public const string UseMusic = "usemusic";
public const string UseSound = "usesound"; public const string UseSound = "usesound";
public const string HacksEnabled = "hacksenabled"; public const string HacksEnabled = "hacksenabled";
public const string NamesMode = "namesmode";
public const string MouseLeft = "mouseleft"; public const string MouseLeft = "mouseleft";
public const string MouseMiddle = "mousemiddle"; public const string MouseMiddle = "mousemiddle";