Fix bug with tab list when help down from map change (Thanks 123DMWM), don't show sides/edge block if it is air, add basis for new colours/emotes gui.

This commit is contained in:
UnknownShadow200 2015-11-10 18:46:23 +11:00
parent 48c8035094
commit c5a1f5a27e
11 changed files with 124 additions and 20 deletions

View File

@ -279,6 +279,11 @@ namespace ClassicalSharp {
return true;
}
public override bool HandlesMouseClick( int mouseX, int mouseY, MouseButton button ) {
if( !HandlesAllInput ) return false;
return textInput.HandlesMouseClick( mouseX, mouseY, button );
}
void ResetIndex() {
int maxIndex = game.Chat.Log.Count - chatLines;
int minIndex = Math.Min( 0, maxIndex );

View File

@ -94,6 +94,13 @@ namespace ClassicalSharp {
chat.Init();
hotbar = new BlockHotbarWidget( game );
hotbar.Init();
game.Events.OnNewMap += OnNewMap;
}
void OnNewMap( object sender, EventArgs e ) {
if( playerList != null )
playerList.Dispose();
playerList = null;
}
public override bool HandlesAllInput {
@ -142,10 +149,11 @@ namespace ClassicalSharp {
}
public override bool HandlesMouseClick( int mouseX, int mouseY, MouseButton button ) {
if( button != MouseButton.Left || playerList == null || !HandlesAllInput ) return false;
if( button != MouseButton.Left || !HandlesAllInput ) return false;
string name = playerList.GetNameUnder( mouseX, mouseY );
if( name == null ) return false;
string name;
if( playerList == null || (name = playerList.GetNameUnder( mouseX, mouseY )) == null )
return chat.HandlesMouseClick( mouseX, mouseY, button );
chat.AppendTextToInput( name + " " );
return true;
}

View File

@ -0,0 +1,75 @@
using System;
using System.Drawing;
using OpenTK.Input;
using System.Windows.Forms;
namespace ClassicalSharp {
public sealed partial class AltTextInputWidget : Widget {
public AltTextInputWidget( Game game, Font font, Font boldFont, TextInputWidget parent ) : base( game ) {
HorizontalAnchor = Anchor.LeftOrTop;
VerticalAnchor = Anchor.LeftOrTop;
this.font = font;
this.boldFont = boldFont;
this.parent = parent;
}
Texture chatInputTexture;
readonly Font font, boldFont;
TextInputWidget parent;
Size partSize;
public override void Render( double delta ) {
chatInputTexture.Render( graphicsApi );
}
public override void Init() {
X = 5; Y = 45;
DrawString();
}
static FastColour backColour = new FastColour( 60, 60, 60, 200 );
void DrawString() {
DrawTextArgs args = new DrawTextArgs( "Text ", font, false );
partSize = game.Drawer2D.MeasureChatSize( ref args );
Size size = new Size( partSize.Width * 6, partSize.Height * 3 );
using( Bitmap bmp = IDrawer2D.CreatePow2Bitmap( size ) ) {
using( IDrawer2D drawer = game.Drawer2D ) {
drawer.SetBitmap( bmp );
drawer.Clear( backColour, 0, 0, size.Width, size.Height );
for( int code = 0; code <= 15; code++ ) {
int c = code < 10 ? '0' + code : 'a' + (code - 10);
args.Text = "&" + (char)c + "Text";
int x = (code % 6);
int y = (code / 6);
drawer.DrawChatText( ref args, x * partSize.Width, y * partSize.Height );
}
chatInputTexture = drawer.Make2DTexture( bmp, size, X, Y );
}
}
Height = size.Height;
Width = size.Width;
}
public override bool HandlesMouseClick( int mouseX, int mouseY, MouseButton button ) {
mouseX -= X; mouseY -= Y;
mouseX /= partSize.Width; mouseY /= partSize.Height;
game.Chat.Add( "CLICKY CLICK" + mouseX + "," + mouseY );
int code = mouseY * 6 + mouseX;
if( code <= 15 ) {
int c = code < 10 ? '0' + code : 'a' + (code - 10);
string text = "&" + (char)c;
parent.AppendText( text );
}
return true;
}
public override void Dispose() {
graphicsApi.DeleteTexture( ref chatInputTexture );
}
}
}

View File

@ -36,6 +36,12 @@ namespace ClassicalSharp {
return true;
}
public override bool HandlesMouseClick( int mouseX, int mouseY, MouseButton button ) {
//if( altText.Bounds.Contains( mouseX, mouseY ) )
// altText.HandlesMouseClick( mouseX, mouseY, button );
return true;
}
void BackspaceKey() {
if( !chatInputText.Empty && caretPos != 0 ) {
if( caretPos == -1 ) {

View File

@ -9,6 +9,7 @@ namespace ClassicalSharp {
const int len = 64 * 3;
const int lines = 3;
//AltTextInputWidget altText;
public TextInputWidget( Game game, Font font, Font boldFont ) : base( game ) {
HorizontalAnchor = Anchor.LeftOrTop;
VerticalAnchor = Anchor.BottomOrRight;
@ -35,6 +36,7 @@ namespace ClassicalSharp {
public override void Render( double delta ) {
chatInputTexture.Render( graphicsApi );
caretTexture.Render( graphicsApi, caretCol );
//altText.Render( delta );
}
string[] parts = new string[lines];
@ -43,6 +45,8 @@ namespace ClassicalSharp {
int maxWidth = 0;
public override void Init() {
//altText = new AltTextInputWidget( game, font, boldFont, this );
//altText.Init();
X = 5;
DrawTextArgs args = new DrawTextArgs( "_", boldFont, false );
caretTexture = game.Drawer2D.UseBitmappedChat ?
@ -133,6 +137,7 @@ namespace ClassicalSharp {
public override void Dispose() {
graphicsApi.DeleteTexture( ref caretTexture );
graphicsApi.DeleteTexture( ref chatInputTexture );
//altText.Dispose();
}
public override void MoveTo( int newX, int newY ) {

View File

@ -106,6 +106,7 @@
<Compile Include="2D\Texture.cs" />
<Compile Include="2D\Widgets\BlockHotbarWidget.cs" />
<Compile Include="2D\Widgets\Chat\ChatTextWidget.cs" />
<Compile Include="2D\Widgets\Chat\AltTextInputWidget.cs" />
<Compile Include="2D\Widgets\Chat\TextGroupWidget.cs" />
<Compile Include="2D\Widgets\Chat\TextInputWidget.cs" />
<Compile Include="2D\Widgets\Chat\TextInputWidget.Handlers.cs" />
@ -198,7 +199,7 @@
<Compile Include="Rendering\MapRenderer.Rendering.cs" />
<Compile Include="Rendering\MinimalEnvRenderer.cs" />
<Compile Include="Rendering\FrustumCulling.cs" />
<Compile Include="Rendering\MapEnvRenderer.cs" />
<Compile Include="Rendering\MapBordersRenderer.cs" />
<Compile Include="Rendering\MapRenderer.cs" />
<Compile Include="Rendering\PickingRenderer.cs" />
<Compile Include="Rendering\StandardEnvRenderer.cs" />

View File

@ -152,7 +152,7 @@ namespace ClassicalSharp.Commands {
}
void SetNewRenderType( bool legacy, bool minimal ) {
game.MapEnvRenderer.SetUseLegacyMode( legacy );
game.MapBordersRenderer.SetUseLegacyMode( legacy );
if( minimal ) {
game.EnvRenderer.Dispose();
game.EnvRenderer = new MinimalEnvRenderer( game );

View File

@ -48,7 +48,7 @@ namespace ClassicalSharp {
public virtual BoundingBox CollisionBounds {
get {
Vector3 pos = Position;
Vector3 size = Model.CollisionSize;
Vector3 size = CollisionSize;
return new BoundingBox( pos.X - size.X / 2, pos.Y, pos.Z - size.Z / 2,
pos.X + size.X / 2, pos.Y + size.Y, pos.Z + size.Z / 2 );
}

View File

@ -35,7 +35,7 @@ namespace ClassicalSharp {
public int ChunkUpdates;
public MapRenderer MapRenderer;
public MapEnvRenderer MapEnvRenderer;
public MapBordersRenderer MapBordersRenderer;
public EnvRenderer EnvRenderer;
public WeatherRenderer WeatherRenderer;
public Inventory Inventory;
@ -141,7 +141,7 @@ namespace ClassicalSharp {
width = Width;
height = Height;
MapRenderer = new MapRenderer( this );
MapEnvRenderer = new MapEnvRenderer( this );
MapBordersRenderer = new MapBordersRenderer( this );
EnvRenderer = new StandardEnvRenderer( this );
if( IPAddress == null ) {
Network = new Singleplayer.SinglePlayerServer( this );
@ -174,7 +174,7 @@ namespace ClassicalSharp {
hudScreen.Init();
Culling = new FrustumCulling();
EnvRenderer.Init();
MapEnvRenderer.Init();
MapBordersRenderer.Init();
Picking = new PickingRenderer( this );
string connectString = "Connecting to " + IPAddress + ":" + Port + "..";
@ -376,7 +376,7 @@ namespace ClassicalSharp {
public override void Dispose() {
MapRenderer.Dispose();
MapEnvRenderer.Dispose();
MapBordersRenderer.Dispose();
EnvRenderer.Dispose();
WeatherRenderer.Dispose();
SetNewScreen( null );

View File

@ -6,13 +6,13 @@ using OpenTK;
namespace ClassicalSharp {
public unsafe sealed class MapEnvRenderer : IDisposable {
public unsafe sealed class MapBordersRenderer : IDisposable {
Map map;
Game game;
IGraphicsApi graphics;
public MapEnvRenderer( Game game ) {
public MapBordersRenderer( Game game ) {
this.game = game;
map = game.Map;
graphics = game.Graphics;
@ -47,8 +47,10 @@ namespace ClassicalSharp {
graphics.AlphaTest = true;
graphics.BindTexture( sideTexId );
graphics.SetBatchFormat( VertexFormat.Pos3fTex2fCol4b );
graphics.BindVb( sidesVb );
graphics.DrawIndexedVb_TrisT2fC4b( sidesVertices * 6 / 4, 0 );
if( game.Map.SidesBlock != Block.Air ) {
graphics.BindVb( sidesVb );
graphics.DrawIndexedVb_TrisT2fC4b( sidesVertices * 6 / 4, 0 );
}
graphics.AlphaBlending = true;
graphics.BindTexture( edgeTexId );
@ -58,10 +60,12 @@ namespace ClassicalSharp {
// Fixes some 'depth bleeding through' issues with 16 bit depth buffers on large maps.
Vector3 eyePos = game.LocalPlayer.EyePosition;
float yVisible = Math.Min( 0, map.SidesHeight );
if( game.Camera.GetCameraPos( eyePos ).Y >= yVisible ) {
graphics.DrawIndexedVb_TrisT2fC4b( edgesVertices * 6 / 4, 0 );
} else {
graphics.DrawIndexedVb_TrisT2fC4b( edgesVerVertices * 6 / 4, edgesBaseVertices * 6 / 4 );
if( game.Map.EdgeBlock != Block.Air ) {
if( game.Camera.GetCameraPos( eyePos ).Y >= yVisible ) {
graphics.DrawIndexedVb_TrisT2fC4b( edgesVertices * 6 / 4, 0 );
} else {
graphics.DrawIndexedVb_TrisT2fC4b( edgesVerVertices * 6 / 4, edgesBaseVertices * 6 / 4 );
}
}
graphics.AlphaBlending = false;
graphics.Texturing = false;
@ -144,7 +148,7 @@ namespace ClassicalSharp {
FastColour col = fullColSides ? FastColour.White : map.SunlightYBottom;
foreach( Rectangle rec in rects ) {
DrawY( rec.X, rec.Y, rec.X + rec.Width, rec.Y + rec.Height, groundLevel, axisSize, col, ref vertices );
}
}
// Work properly for when ground level is below 0
int y1 = 0, y2 = groundLevel;
if( groundLevel < 0 ) {

View File

@ -218,7 +218,7 @@ namespace ClassicalSharp {
UpdateChunks( deltaTime );
RenderNormal();
game.MapEnvRenderer.Render( deltaTime );
game.MapBordersRenderer.Render( deltaTime );
RenderTranslucent();
}