2016-03-26 13:51:42 +11:00
|
|
|
|
// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
|
|
|
|
|
using System;
|
2015-10-31 19:03:25 +11:00
|
|
|
|
using System.Drawing;
|
|
|
|
|
using ClassicalSharp.GraphicsAPI;
|
|
|
|
|
using OpenTK.Input;
|
2014-12-17 14:47:17 +11:00
|
|
|
|
|
2016-03-27 09:33:51 +11:00
|
|
|
|
namespace ClassicalSharp.Gui {
|
2014-12-17 14:47:17 +11:00
|
|
|
|
|
2016-04-27 17:06:55 +10:00
|
|
|
|
public class HudScreen : Screen, IGameComponent {
|
2014-12-17 14:47:17 +11:00
|
|
|
|
|
2016-02-04 16:27:26 +11:00
|
|
|
|
public HudScreen( Game game ) : base( game ) { }
|
2014-12-17 14:47:17 +11:00
|
|
|
|
|
|
|
|
|
ChatScreen chat;
|
2015-12-25 13:23:59 +11:00
|
|
|
|
internal BlockHotbarWidget hotbar;
|
2015-10-31 19:03:25 +11:00
|
|
|
|
PlayerListWidget playerList;
|
2015-05-09 18:37:20 +10:00
|
|
|
|
Font playerFont;
|
2014-12-17 14:47:17 +11:00
|
|
|
|
|
2016-05-08 18:53:52 +10:00
|
|
|
|
public void Init( Game game ) { }
|
|
|
|
|
public void Ready( Game game) { Init(); }
|
2016-04-27 17:06:55 +10:00
|
|
|
|
public void Reset( Game game ) { }
|
2016-05-01 11:23:38 +10:00
|
|
|
|
public void OnNewMap( Game game ) { }
|
|
|
|
|
public void OnNewMapLoaded( Game game ) { }
|
2016-04-27 17:06:55 +10:00
|
|
|
|
|
2014-12-17 14:47:17 +11:00
|
|
|
|
public override void Render( double delta ) {
|
2015-09-11 19:39:48 +10:00
|
|
|
|
if( game.HideGui ) return;
|
2015-10-08 16:47:53 +11:00
|
|
|
|
|
2016-04-20 09:48:23 +10:00
|
|
|
|
bool showMinimal = game.ActiveScreen.BlocksWorld;
|
2016-05-28 23:39:54 +10:00
|
|
|
|
if( chat.HandlesAllInput && !game.PureClassic )
|
2015-10-10 18:21:41 +11:00
|
|
|
|
chat.RenderBackground();
|
2016-06-08 15:24:33 +10:00
|
|
|
|
|
2016-05-26 10:01:32 +10:00
|
|
|
|
api.Texturing = true;
|
2016-06-08 15:24:33 +10:00
|
|
|
|
if( !showMinimal ) hotbar.Render( delta );
|
2016-05-26 10:01:32 +10:00
|
|
|
|
chat.Render( delta );
|
2015-10-08 16:47:53 +11:00
|
|
|
|
|
2016-05-08 13:18:11 +10:00
|
|
|
|
if( playerList != null && game.ActiveScreen == this ) {
|
2014-12-17 14:47:17 +11:00
|
|
|
|
playerList.Render( delta );
|
|
|
|
|
// NOTE: Should usually be caught by KeyUp, but just in case.
|
2016-06-10 15:19:14 +10:00
|
|
|
|
if( !game.IsKeyDown( KeyBind.PlayerList ) ) {
|
2014-12-17 14:47:17 +11:00
|
|
|
|
playerList.Dispose();
|
|
|
|
|
playerList = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-11-08 17:03:44 +11:00
|
|
|
|
|
2016-03-30 22:43:08 +11:00
|
|
|
|
api.Texturing = false;
|
2015-11-08 17:03:44 +11:00
|
|
|
|
if( playerList == null && !showMinimal )
|
|
|
|
|
DrawCrosshairs();
|
2015-09-01 18:03:36 +10:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-12 16:56:13 +10:00
|
|
|
|
const int chExtent = 16, chWeight = 2;
|
|
|
|
|
static TextureRec chRec = new TextureRec( 0, 0, 16/256f, 16/256f );
|
2015-09-01 18:03:36 +10:00
|
|
|
|
void DrawCrosshairs() {
|
2016-05-12 16:56:13 +10:00
|
|
|
|
int cenX = game.Width / 2, cenY = game.Height / 2;
|
|
|
|
|
if( game.IconsTex > 0 ) {
|
|
|
|
|
api.Texturing = true;
|
|
|
|
|
int extent = (int)(chExtent * game.Scale( game.Height / 480f ) );
|
|
|
|
|
Texture chTex = new Texture( game.IconsTex, cenX - extent,
|
|
|
|
|
cenY - extent, extent * 2, extent * 2, chRec );
|
|
|
|
|
chTex.Render( api );
|
|
|
|
|
api.Texturing = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int curCol = 150 + (int)(50 * Math.Abs( Math.Sin( game.accumulator ) ));
|
2015-09-01 18:03:36 +10:00
|
|
|
|
FastColour col = new FastColour( curCol, curCol, curCol );
|
2016-05-12 16:56:13 +10:00
|
|
|
|
api.Draw2DQuad( cenX - chExtent, cenY - chWeight, chExtent * 2, chWeight * 2, col );
|
|
|
|
|
api.Draw2DQuad( cenX - chWeight, cenY - chExtent, chWeight * 2, chExtent * 2, col );
|
2014-12-17 14:47:17 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Dispose() {
|
2015-05-09 18:37:20 +10:00
|
|
|
|
playerFont.Dispose();
|
2014-12-17 14:47:17 +11:00
|
|
|
|
chat.Dispose();
|
|
|
|
|
hotbar.Dispose();
|
2015-11-08 17:03:44 +11:00
|
|
|
|
if( playerList != null )
|
|
|
|
|
playerList.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void GainFocus() {
|
2016-03-31 16:33:36 +11:00
|
|
|
|
game.CursorVisible = false;
|
2015-11-08 17:03:44 +11:00
|
|
|
|
game.Camera.RegrabMouse();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LoseFocus() {
|
2016-03-31 16:33:36 +11:00
|
|
|
|
game.CursorVisible = true;
|
2014-12-17 14:47:17 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnResize( int oldWidth, int oldHeight, int width, int height ) {
|
2015-11-14 22:02:45 +11:00
|
|
|
|
PlayerListWidget widget = playerList;
|
|
|
|
|
game.RefreshHud();
|
|
|
|
|
if( widget != null )
|
|
|
|
|
CreatePlayerListWidget();
|
2014-12-17 14:47:17 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Init() {
|
2016-04-20 11:19:37 +10:00
|
|
|
|
int size = game.Drawer2D.UseBitmappedChat ? 16 : 11;
|
|
|
|
|
playerFont = new Font( game.FontName, size );
|
2015-09-01 18:03:36 +10:00
|
|
|
|
chat = new ChatScreen( game );
|
2014-12-17 14:47:17 +11:00
|
|
|
|
chat.Init();
|
2015-09-01 18:03:36 +10:00
|
|
|
|
hotbar = new BlockHotbarWidget( game );
|
2014-12-17 14:47:17 +11:00
|
|
|
|
hotbar.Init();
|
2016-03-27 09:33:51 +11:00
|
|
|
|
game.WorldEvents.OnNewMap += OnNewMap;
|
2016-06-11 17:56:37 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnNewMap( object sender, EventArgs e ) {
|
|
|
|
|
if( playerList != null )
|
|
|
|
|
playerList.Dispose();
|
|
|
|
|
playerList = null;
|
2014-12-17 14:47:17 +11:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-04 16:27:26 +11:00
|
|
|
|
public override bool HandlesAllInput { get { return chat.HandlesAllInput; } }
|
2014-12-17 14:47:17 +11:00
|
|
|
|
|
|
|
|
|
public override bool HandlesKeyPress( char key ) {
|
|
|
|
|
return chat.HandlesKeyPress( key );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool HandlesKeyDown( Key key ) {
|
2016-06-10 15:19:14 +10:00
|
|
|
|
Key playerListKey = game.Mapping( KeyBind.PlayerList );
|
2016-01-15 22:18:11 +11:00
|
|
|
|
bool handles = playerListKey != Key.Tab || !game.TabAutocomplete || !chat.HandlesAllInput;
|
2016-01-10 12:57:32 +11:00
|
|
|
|
if( key == playerListKey && handles ) {
|
2016-05-26 21:17:19 +10:00
|
|
|
|
if( playerList == null && !game.Network.IsSinglePlayer )
|
2015-11-14 22:02:45 +11:00
|
|
|
|
CreatePlayerListWidget();
|
2016-01-10 12:57:32 +11:00
|
|
|
|
return true;
|
2014-12-17 14:47:17 +11:00
|
|
|
|
}
|
2015-11-14 22:02:45 +11:00
|
|
|
|
|
|
|
|
|
if( chat.HandlesKeyDown( key ) )
|
|
|
|
|
return true;
|
2014-12-17 14:47:17 +11:00
|
|
|
|
return hotbar.HandlesKeyDown( key );
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-14 22:02:45 +11:00
|
|
|
|
void CreatePlayerListWidget() {
|
2016-01-12 14:26:39 +11:00
|
|
|
|
if( game.UseClassicTabList ) {
|
|
|
|
|
playerList = new ClassicPlayerListWidget( game, playerFont );
|
|
|
|
|
} else if( game.Network.UsingExtPlayerList ) {
|
2015-11-14 22:02:45 +11:00
|
|
|
|
playerList = new ExtPlayerListWidget( game, playerFont );
|
|
|
|
|
} else {
|
|
|
|
|
playerList = new NormalPlayerListWidget( game, playerFont );
|
|
|
|
|
}
|
|
|
|
|
playerList.Init();
|
|
|
|
|
playerList.MoveTo( playerList.X, game.Height / 4 );
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-17 14:47:17 +11:00
|
|
|
|
public override bool HandlesKeyUp( Key key ) {
|
2016-06-10 15:19:14 +10:00
|
|
|
|
if( key == game.Mapping( KeyBind.PlayerList ) ) {
|
2014-12-17 14:47:17 +11:00
|
|
|
|
if( playerList != null ) {
|
|
|
|
|
playerList.Dispose();
|
|
|
|
|
playerList = null;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-07-08 07:06:21 +10:00
|
|
|
|
|
2015-10-25 19:28:27 +11:00
|
|
|
|
public void OpenTextInputBar( string text ) {
|
|
|
|
|
chat.OpenTextInputBar( text );
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-31 19:03:25 +11:00
|
|
|
|
public override bool HandlesMouseScroll( int delta ) {
|
|
|
|
|
return chat.HandlesMouseScroll( delta );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool HandlesMouseClick( int mouseX, int mouseY, MouseButton button ) {
|
2015-11-10 18:46:23 +11:00
|
|
|
|
if( button != MouseButton.Left || !HandlesAllInput ) return false;
|
2015-10-31 19:03:25 +11:00
|
|
|
|
|
2015-11-10 18:46:23 +11:00
|
|
|
|
string name;
|
|
|
|
|
if( playerList == null || (name = playerList.GetNameUnder( mouseX, mouseY )) == null )
|
|
|
|
|
return chat.HandlesMouseClick( mouseX, mouseY, button );
|
2015-10-31 19:03:25 +11:00
|
|
|
|
chat.AppendTextToInput( name + " " );
|
|
|
|
|
return true;
|
2015-07-08 07:06:21 +10:00
|
|
|
|
}
|
2014-12-17 14:47:17 +11:00
|
|
|
|
}
|
|
|
|
|
}
|