2015-10-31 19:03:25 +11:00
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using ClassicalSharp.GraphicsAPI;
|
|
|
|
|
using OpenTK.Input;
|
2014-12-17 14:47:17 +11:00
|
|
|
|
|
|
|
|
|
namespace ClassicalSharp {
|
|
|
|
|
|
2015-11-08 17:03:44 +11:00
|
|
|
|
public class HudScreen : Screen {
|
2014-12-17 14:47:17 +11:00
|
|
|
|
|
2015-11-08 17:03:44 +11:00
|
|
|
|
public HudScreen( Game game ) : base( game ) {
|
2014-12-17 14:47:17 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ChatScreen chat;
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2015-11-08 17:03:44 +11:00
|
|
|
|
bool showMinimal = game.GetActiveScreen != this;
|
2015-10-10 18:21:41 +11:00
|
|
|
|
if( chat.HandlesAllInput )
|
|
|
|
|
chat.RenderBackground();
|
2015-09-01 18:03:36 +10:00
|
|
|
|
graphicsApi.Texturing = true;
|
2014-12-17 14:47:17 +11:00
|
|
|
|
chat.Render( delta );
|
2015-11-08 17:03:44 +11:00
|
|
|
|
if( !showMinimal )
|
2015-11-09 19:53:24 +11:00
|
|
|
|
RenderHotbar( delta );
|
2015-10-08 16:47:53 +11:00
|
|
|
|
|
|
|
|
|
//graphicsApi.BeginVbBatch( VertexFormat.Pos3fTex2fCol4b );
|
|
|
|
|
//graphicsApi.BindTexture( game.TerrainAtlas.TexId );
|
|
|
|
|
//IsometricBlockDrawer.Draw( game, (byte)Block.Brick, 30, game.Width - 50, game.Height - 20 );
|
|
|
|
|
|
2014-12-17 14:47:17 +11:00
|
|
|
|
if( playerList != null ) {
|
|
|
|
|
playerList.Render( delta );
|
|
|
|
|
// NOTE: Should usually be caught by KeyUp, but just in case.
|
2015-10-25 20:34:47 +11:00
|
|
|
|
if( !game.IsKeyDown( KeyBinding.PlayerList ) ) {
|
2014-12-17 14:47:17 +11:00
|
|
|
|
playerList.Dispose();
|
|
|
|
|
playerList = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-11-08 17:03:44 +11:00
|
|
|
|
|
|
|
|
|
graphicsApi.Texturing = false;
|
|
|
|
|
if( playerList == null && !showMinimal )
|
|
|
|
|
DrawCrosshairs();
|
2015-09-01 18:03:36 +10:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-09 19:53:24 +11:00
|
|
|
|
public void RenderHotbar( double delta ) { hotbar.Render( delta ); }
|
|
|
|
|
|
2015-09-04 06:55:12 +10:00
|
|
|
|
const int crosshairExtent = 15, crosshairWeight = 2;
|
2015-09-01 18:03:36 +10:00
|
|
|
|
void DrawCrosshairs() {
|
|
|
|
|
int curCol = 150 + (int)( 50 * Math.Abs( Math.Sin( game.accumulator ) ) );
|
|
|
|
|
FastColour col = new FastColour( curCol, curCol, curCol );
|
|
|
|
|
float centreX = game.Width / 2, centreY = game.Height / 2;
|
|
|
|
|
graphicsApi.Draw2DQuad( centreX - crosshairExtent, centreY - crosshairWeight,
|
|
|
|
|
crosshairExtent * 2, crosshairWeight * 2, col );
|
|
|
|
|
graphicsApi.Draw2DQuad( centreX - crosshairWeight, centreY - crosshairExtent,
|
2015-09-10 06:34:24 +10:00
|
|
|
|
crosshairWeight * 2, crosshairExtent * 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() {
|
|
|
|
|
if( game.CursorVisible )
|
|
|
|
|
game.CursorVisible = false;
|
|
|
|
|
game.Camera.RegrabMouse();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LoseFocus() {
|
2014-12-17 14:47:17 +11:00
|
|
|
|
if( playerList != null ) {
|
|
|
|
|
playerList.Dispose();
|
|
|
|
|
}
|
2015-09-10 06:34:24 +10:00
|
|
|
|
if( !game.CursorVisible )
|
|
|
|
|
game.CursorVisible = true;
|
2014-12-17 14:47:17 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnResize( int oldWidth, int oldHeight, int width, int height ) {
|
|
|
|
|
chat.OnResize( oldWidth, oldHeight, width, height );
|
|
|
|
|
hotbar.OnResize( oldWidth, oldHeight, width, height );
|
|
|
|
|
if( playerList != null ) {
|
2015-10-09 16:47:39 +11:00
|
|
|
|
int deltaX = CalcDelta( width, oldWidth, Anchor.Centre );
|
|
|
|
|
playerList.MoveTo( playerList.X + deltaX, height / 4 );
|
2014-12-17 14:47:17 +11:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Init() {
|
2015-05-09 18:37:20 +10:00
|
|
|
|
playerFont = new Font( "Arial", 12 );
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool HandlesAllInput {
|
|
|
|
|
get { return chat.HandlesAllInput; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool HandlesKeyPress( char key ) {
|
|
|
|
|
return chat.HandlesKeyPress( key );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool HandlesKeyDown( Key key ) {
|
2015-10-25 20:34:47 +11:00
|
|
|
|
if( key == game.Mapping( KeyBinding.PlayerList ) ) {
|
2014-12-17 14:47:17 +11:00
|
|
|
|
if( playerList == null ) {
|
2015-09-01 18:03:36 +10:00
|
|
|
|
if( game.Network.UsingExtPlayerList ) {
|
|
|
|
|
playerList = new ExtPlayerListWidget( game, playerFont );
|
2014-12-17 14:47:17 +11:00
|
|
|
|
} else {
|
2015-09-01 18:03:36 +10:00
|
|
|
|
playerList = new NormalPlayerListWidget( game, playerFont );
|
2014-12-17 14:47:17 +11:00
|
|
|
|
}
|
|
|
|
|
playerList.Init();
|
2015-10-09 16:47:39 +11:00
|
|
|
|
playerList.MoveTo( playerList.X, game.Height / 4 );
|
2014-12-17 14:47:17 +11:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if( chat.HandlesKeyDown( key ) ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return hotbar.HandlesKeyDown( key );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool HandlesKeyUp( Key key ) {
|
2015-10-25 20:34:47 +11:00
|
|
|
|
if( key == game.Mapping( KeyBinding.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 ) {
|
|
|
|
|
if( button != MouseButton.Left || playerList == null || !HandlesAllInput ) return false;
|
|
|
|
|
|
|
|
|
|
string name = playerList.GetNameUnder( mouseX, mouseY );
|
|
|
|
|
if( name == null ) return false;
|
|
|
|
|
chat.AppendTextToInput( name + " " );
|
|
|
|
|
return true;
|
2015-07-08 07:06:21 +10:00
|
|
|
|
}
|
2014-12-17 14:47:17 +11:00
|
|
|
|
}
|
|
|
|
|
}
|