Implement proper scrollbar for the block inventory, partially addresses #141.

This commit is contained in:
UnknownShadow200 2016-03-30 22:43:08 +11:00
parent 2ab0bba083
commit 32697c43ca
31 changed files with 132 additions and 116 deletions

View File

@ -14,14 +14,14 @@ namespace ClassicalSharp.Gui {
public abstract class GuiElement : IDisposable { public abstract class GuiElement : IDisposable {
protected Game game; protected Game game;
protected IGraphicsApi graphicsApi; protected IGraphicsApi api;
/// <summary> Object that represents any form of metadata attached to this widget. </summary> /// <summary> Object that represents any form of metadata attached to this widget. </summary>
public object Metadata = null; public object Metadata = null;
public GuiElement( Game game ) { public GuiElement( Game game ) {
this.game = game; this.game = game;
graphicsApi = game.Graphics; api = game.Graphics;
} }
public abstract void Init(); public abstract void Init();

View File

@ -9,17 +9,22 @@ namespace ClassicalSharp.Gui {
const int scrollbarWidth = 10; const int scrollbarWidth = 10;
static FastColour scrollCol = new FastColour( 10, 10, 10, 220 ); static FastColour scrollCol = new FastColour( 10, 10, 10, 220 );
static FastColour scrollUsedCol = new FastColour( 100, 100, 100, 220 ); static FastColour scrollUsedCol = new FastColour( 100, 100, 100, 220 );
void DrawScrollbar() { float ScrollbarScale { get { return TableHeight / (float)rows; } }
graphicsApi.Draw2DQuad( TableX, TableY, scrollbarWidth,
TableHeight, scrollCol );
float scale = TableHeight / (float)rows;
int yOffset = (int)Math.Ceiling( scrollY * scale );
int height = (int)Math.Ceiling( maxRows * scale );
if( yOffset + height > TableHeight ) void DrawScrollbar() {
height = TableHeight - yOffset; api.Draw2DQuad( TableX, TableY, scrollbarWidth, TableHeight, scrollCol );
graphicsApi.Draw2DQuad( TableX, TableY + yOffset, scrollbarWidth, int y, height;
height, scrollUsedCol ); GetScrollbarCoords( out y, out height );
api.Draw2DQuad( TableX, TableY + y, scrollbarWidth, height, scrollUsedCol );
}
void GetScrollbarCoords( out int y, out int height ) {
float scale = ScrollbarScale;
y = (int)Math.Ceiling( scrollY * scale );
height = (int)Math.Ceiling( maxRows * scale );
if( y + height > TableHeight )
height = TableHeight - y;
} }
public override bool HandlesMouseScroll( int delta ) { public override bool HandlesMouseScroll( int delta ) {
@ -49,15 +54,26 @@ namespace ClassicalSharp.Gui {
void ScrollbarClick( int mouseY ) { void ScrollbarClick( int mouseY ) {
mouseY -= TableY; mouseY -= TableY;
float scale = TableHeight / (float)rows; int y, height;
scrollY = (int)(mouseY / scale); GetScrollbarCoords( out y, out height );
if( mouseY < y ) {
scrollY -= maxRows;
} else if( mouseY >= y + height ) {
scrollY += maxRows;
} else {
draggingMouse = true;
mouseOffset = mouseY - y;
}
ClampScrollY(); ClampScrollY();
} }
bool draggingMouse = false; bool draggingMouse = false;
int mouseOffset = 0;
public override bool HandlesMouseUp( int mouseX, int mouseY, MouseButton button ) { public override bool HandlesMouseUp( int mouseX, int mouseY, MouseButton button ) {
draggingMouse = false; draggingMouse = false;
mouseOffset = 0;
return true; return true;
} }
} }

View File

@ -28,17 +28,16 @@ namespace ClassicalSharp.Gui {
static FastColour backCol = new FastColour( 30, 30, 30, 200 ); static FastColour backCol = new FastColour( 30, 30, 30, 200 );
public override void Render( double delta ) { public override void Render( double delta ) {
graphicsApi.Draw2DQuad( TableX, TableY, TableWidth, TableHeight, backCol ); api.Draw2DQuad( TableX, TableY, TableWidth, TableHeight, backCol );
if( rows > maxRows ) if( rows > maxRows )
DrawScrollbar(); DrawScrollbar();
graphicsApi.Texturing = true; api.Texturing = true;
graphicsApi.SetBatchFormat( VertexFormat.Pos3fTex2fCol4b ); api.SetBatchFormat( VertexFormat.Pos3fTex2fCol4b );
IsometricBlockDrawer.lastTexId = -1; IsometricBlockDrawer.lastTexId = -1;
for( int i = 0; i < blocksTable.Length; i++ ) { for( int i = 0; i < blocksTable.Length; i++ ) {
int x, y; int x, y;
if( !GetCoords( i, out x, out y ) ) if( !GetCoords( i, out x, out y ) ) continue;
continue;
// We want to always draw the selected block on top of others // We want to always draw the selected block on top of others
if( i == selIndex ) continue; if( i == selIndex ) continue;
@ -55,9 +54,9 @@ namespace ClassicalSharp.Gui {
} }
if( blockInfoTexture.IsValid ) if( blockInfoTexture.IsValid )
blockInfoTexture.Render( graphicsApi ); blockInfoTexture.Render( api );
game.hudScreen.RenderHotbar( delta ); game.hudScreen.RenderHotbar( delta );
graphicsApi.Texturing = false; api.Texturing = false;
} }
bool GetCoords( int i, out int x, out int y ) { bool GetCoords( int i, out int x, out int y ) {
@ -72,7 +71,7 @@ namespace ClassicalSharp.Gui {
public override void Dispose() { public override void Dispose() {
font.Dispose(); font.Dispose();
graphicsApi.DeleteTexture( ref blockInfoTexture ); api.DeleteTexture( ref blockInfoTexture );
game.Events.BlockPermissionsChanged -= BlockPermissionsChanged; game.Events.BlockPermissionsChanged -= BlockPermissionsChanged;
game.Keyboard.KeyRepeat = false; game.Keyboard.KeyRepeat = false;
} }
@ -181,7 +180,7 @@ namespace ClassicalSharp.Gui {
if( selIndex == lastCreatedIndex ) return; if( selIndex == lastCreatedIndex ) return;
lastCreatedIndex = selIndex; lastCreatedIndex = selIndex;
graphicsApi.DeleteTexture( ref blockInfoTexture ); api.DeleteTexture( ref blockInfoTexture );
if( selIndex == -1 ) return; if( selIndex == -1 ) return;
Block block = blocksTable[selIndex]; Block block = blocksTable[selIndex];
@ -226,7 +225,9 @@ namespace ClassicalSharp.Gui {
public override bool HandlesMouseMove( int mouseX, int mouseY ) { public override bool HandlesMouseMove( int mouseX, int mouseY ) {
if( draggingMouse ) { if( draggingMouse ) {
ScrollbarClick( mouseY ); mouseY -= TableY;
scrollY = (int)((mouseY - mouseOffset) / ScrollbarScale);
ClampScrollY();
return true; return true;
} }
@ -252,7 +253,6 @@ namespace ClassicalSharp.Gui {
return true; return true;
if( button == MouseButton.Left && mouseX >= TableX && mouseX < TableX + scrollbarWidth ) { if( button == MouseButton.Left && mouseX >= TableX && mouseX < TableX + scrollbarWidth ) {
ScrollbarClick( mouseY ); ScrollbarClick( mouseY );
draggingMouse = true;
} else if( button == MouseButton.Left ) { } else if( button == MouseButton.Left ) {
if( selIndex != -1 ) if( selIndex != -1 )
game.Inventory.HeldBlock = blocksTable[selIndex]; game.Inventory.HeldBlock = blocksTable[selIndex];

View File

@ -166,7 +166,7 @@ namespace ClassicalSharp.Gui {
DateTime received = game.Chat.Log[metadata[i]].Received; DateTime received = game.Chat.Log[metadata[i]].Received;
if( (now - received).TotalSeconds <= 10 ) if( (now - received).TotalSeconds <= 10 )
texture.Render( graphicsApi ); texture.Render( api );
} }
} }
@ -178,7 +178,7 @@ namespace ClassicalSharp.Gui {
y -= texture.Height; y -= texture.Height;
texture.Y1 = y; texture.Y1 = y;
texture.Render( graphicsApi ); texture.Render( api );
} }
} }
@ -193,7 +193,7 @@ namespace ClassicalSharp.Gui {
int boxHeight = height + clientStatus.GetUsedHeight(); int boxHeight = height + clientStatus.GetUsedHeight();
if( boxHeight > 0 ) if( boxHeight > 0 )
graphicsApi.Draw2DQuad( x, y, width, boxHeight + 10, backColour ); api.Draw2DQuad( x, y, width, boxHeight + 10, backColour );
} }
int inputOldHeight = -1; int inputOldHeight = -1;

View File

@ -21,10 +21,10 @@ namespace ClassicalSharp.Gui {
public override void Render( double delta ) { public override void Render( double delta ) {
UpdateReconnectState(); UpdateReconnectState();
graphicsApi.Texturing = true; api.Texturing = true;
for( int i = 0; i < widgets.Length; i++ ) for( int i = 0; i < widgets.Length; i++ )
widgets[i].Render( delta ); widgets[i].Render( delta );
graphicsApi.Texturing = false; api.Texturing = false;
} }
int lastSecsLeft; int lastSecsLeft;
@ -42,7 +42,7 @@ namespace ClassicalSharp.Gui {
} }
public override void Init() { public override void Init() {
graphicsApi.ClearColour( new FastColour( 65, 31, 31 ) ); api.ClearColour( new FastColour( 65, 31, 31 ) );
widgets = new Widget[] { widgets = new Widget[] {
ChatTextWidget.Create( game, 0, -30, title, Anchor.Centre, Anchor.Centre, titleFont ), ChatTextWidget.Create( game, 0, -30, title, Anchor.Centre, Anchor.Centre, titleFont ),
ChatTextWidget.Create( game, 0, 10, message, Anchor.Centre, Anchor.Centre, messageFont ), ChatTextWidget.Create( game, 0, 10, message, Anchor.Centre, Anchor.Centre, messageFont ),

View File

@ -104,12 +104,12 @@ namespace ClassicalSharp.Gui {
} }
public override void Render( double delta ) { public override void Render( double delta ) {
graphicsApi.Draw2DQuad( 0, 0, game.Width, game.Height, new FastColour( 60, 60, 60, 160 ) ); api.Draw2DQuad( 0, 0, game.Width, game.Height, new FastColour( 60, 60, 60, 160 ) );
graphicsApi.Texturing = true; api.Texturing = true;
title.Render( delta ); title.Render( delta );
for( int i = 0; i < buttons.Length; i++ ) for( int i = 0; i < buttons.Length; i++ )
buttons[i].Render( delta ); buttons[i].Render( delta );
graphicsApi.Texturing = false; api.Texturing = false;
} }
} }
} }

View File

@ -21,14 +21,14 @@ namespace ClassicalSharp.Gui {
UpdateFPS( delta ); UpdateFPS( delta );
if( game.HideGui || !game.ShowFPS ) return; if( game.HideGui || !game.ShowFPS ) return;
graphicsApi.Texturing = true; api.Texturing = true;
fpsTextWidget.Render( delta ); fpsTextWidget.Render( delta );
if( !game.ClassicMode && game.activeScreen == null ) { if( !game.ClassicMode && game.activeScreen == null ) {
UpdateHackState( false ); UpdateHackState( false );
DrawPosition(); DrawPosition();
hackStatesWidget.Render( delta ); hackStatesWidget.Render( delta );
} }
graphicsApi.Texturing = false; api.Texturing = false;
} }
double accumulator, maxDelta; double accumulator, maxDelta;
@ -106,7 +106,7 @@ namespace ClassicalSharp.Gui {
font.Dispose(); font.Dispose();
posFont.Dispose(); posFont.Dispose();
fpsTextWidget.Dispose(); fpsTextWidget.Dispose();
graphicsApi.DeleteTexture( ref posTexture ); api.DeleteTexture( ref posTexture );
game.Events.ChatFontChanged -= ChatFontChanged; game.Events.ChatFontChanged -= ChatFontChanged;
} }
@ -129,8 +129,8 @@ namespace ClassicalSharp.Gui {
AddInt( pos.Z, ref index, false ); AddInt( pos.Z, ref index, false );
AddChar( 14, ref index ); AddChar( 14, ref index );
graphicsApi.BindTexture( posTexture.ID ); api.BindTexture( posTexture.ID );
graphicsApi.UpdateDynamicIndexedVb( DrawMode.Triangles, api.UpdateDynamicIndexedVb( DrawMode.Triangles,
game.ModelCache.vb, game.ModelCache.vertices, index, index * 6 / 4 ); game.ModelCache.vb, game.ModelCache.vertices, index, index * 6 / 4 );
} }

View File

@ -17,14 +17,14 @@ namespace ClassicalSharp.Gui {
Font arrowFont, textFont; Font arrowFont, textFont;
public override void Render( double delta ) { public override void Render( double delta ) {
RenderMenuBounds(); RenderMenuBounds();
graphicsApi.Texturing = true; api.Texturing = true;
RenderMenuWidgets( delta ); RenderMenuWidgets( delta );
if( currentAction != null ) { if( currentAction != null ) {
currentAction.Render( delta ); currentAction.Render( delta );
currentMoreInputLabel.Render( delta ); currentMoreInputLabel.Render( delta );
} }
graphicsApi.Texturing = false; api.Texturing = false;
} }
public override bool HandlesMouseMove( int mouseX, int mouseY ) { public override bool HandlesMouseMove( int mouseX, int mouseY ) {

View File

@ -21,7 +21,7 @@ namespace ClassicalSharp.Gui {
bool showMinimal = game.GetActiveScreen != this; bool showMinimal = game.GetActiveScreen != this;
if( chat.HandlesAllInput ) if( chat.HandlesAllInput )
chat.RenderBackground(); chat.RenderBackground();
graphicsApi.Texturing = true; api.Texturing = true;
chat.Render( delta ); chat.Render( delta );
if( !showMinimal ) if( !showMinimal )
RenderHotbar( delta ); RenderHotbar( delta );
@ -39,7 +39,7 @@ namespace ClassicalSharp.Gui {
} }
} }
graphicsApi.Texturing = false; api.Texturing = false;
if( playerList == null && !showMinimal ) if( playerList == null && !showMinimal )
DrawCrosshairs(); DrawCrosshairs();
} }
@ -51,9 +51,9 @@ namespace ClassicalSharp.Gui {
int curCol = 150 + (int)( 50 * Math.Abs( Math.Sin( game.accumulator ) ) ); int curCol = 150 + (int)( 50 * Math.Abs( Math.Sin( game.accumulator ) ) );
FastColour col = new FastColour( curCol, curCol, curCol ); FastColour col = new FastColour( curCol, curCol, curCol );
float centreX = game.Width / 2, centreY = game.Height / 2; float centreX = game.Width / 2, centreY = game.Height / 2;
graphicsApi.Draw2DQuad( centreX - crosshairExtent, centreY - crosshairWeight, api.Draw2DQuad( centreX - crosshairExtent, centreY - crosshairWeight,
crosshairExtent * 2, crosshairWeight * 2, col ); crosshairExtent * 2, crosshairWeight * 2, col );
graphicsApi.Draw2DQuad( centreX - crosshairWeight, centreY - crosshairExtent, api.Draw2DQuad( centreX - crosshairWeight, centreY - crosshairExtent,
crosshairWeight * 2, crosshairExtent * 2, col ); crosshairWeight * 2, crosshairExtent * 2, col );
} }

View File

@ -26,16 +26,16 @@ namespace ClassicalSharp.Gui {
readonly FastColour progressCol = new FastColour( 128, 255, 128 ); readonly FastColour progressCol = new FastColour( 128, 255, 128 );
public override void Render( double delta ) { public override void Render( double delta ) {
graphicsApi.Texturing = true; api.Texturing = true;
DrawBackground(); DrawBackground();
titleWidget.Render( delta ); titleWidget.Render( delta );
messageWidget.Render( delta ); messageWidget.Render( delta );
graphicsApi.Texturing = false; api.Texturing = false;
int progX = game.Width / 2 - progWidth / 2; int progX = game.Width / 2 - progWidth / 2;
int progY = game.Height / 2 - progHeight / 2; int progY = game.Height / 2 - progHeight / 2;
graphicsApi.Draw2DQuad( progX, progY, progWidth, progHeight, backCol ); api.Draw2DQuad( progX, progY, progWidth, progHeight, backCol );
graphicsApi.Draw2DQuad( progX, progY, progWidth * progress, progHeight, progressCol ); api.Draw2DQuad( progX, progY, progWidth * progress, progHeight, progressCol );
} }
void DrawBackground() { void DrawBackground() {
@ -75,17 +75,17 @@ namespace ClassicalSharp.Gui {
if( index == 0 ) return; if( index == 0 ) return;
if( !bound ) { if( !bound ) {
bound = true; bound = true;
graphicsApi.BindTexture( game.TerrainAtlas1D.TexIds[atlasIndex] ); api.BindTexture( game.TerrainAtlas1D.TexIds[atlasIndex] );
} }
ModelCache cache = game.ModelCache; ModelCache cache = game.ModelCache;
graphicsApi.SetBatchFormat( VertexFormat.Pos3fTex2fCol4b ); api.SetBatchFormat( VertexFormat.Pos3fTex2fCol4b );
graphicsApi.UpdateDynamicIndexedVb( DrawMode.Triangles, cache.vb, cache.vertices, index, index * 6 / 4 ); api.UpdateDynamicIndexedVb( DrawMode.Triangles, cache.vb, cache.vertices, index, index * 6 / 4 );
index = 0; index = 0;
} }
public override void Init() { public override void Init() {
graphicsApi.Fog = false; api.Fog = false;
SetTitle( serverName ); SetTitle( serverName );
SetMessage( serverMotd ); SetMessage( serverMotd );
game.WorldEvents.MapLoading += MapLoading; game.WorldEvents.MapLoading += MapLoading;

View File

@ -20,13 +20,13 @@ namespace ClassicalSharp.Gui {
public override void Render( double delta ) { public override void Render( double delta ) {
RenderMenuBounds(); RenderMenuBounds();
graphicsApi.Texturing = true; api.Texturing = true;
RenderMenuWidgets( delta ); RenderMenuWidgets( delta );
for( int i = 0; i < inputs.Length; i++ ) for( int i = 0; i < inputs.Length; i++ )
inputs[i].Render( delta ); inputs[i].Render( delta );
for( int i = 0; i < labels.Length; i++ ) for( int i = 0; i < labels.Length; i++ )
labels[i].Render( delta ); labels[i].Render( delta );
graphicsApi.Texturing = false; api.Texturing = false;
} }
public override bool HandlesMouseClick( int mouseX, int mouseY, MouseButton button ) { public override bool HandlesMouseClick( int mouseX, int mouseY, MouseButton button ) {
@ -72,9 +72,9 @@ namespace ClassicalSharp.Gui {
TextWidget.Create( game, 0, -130, "Generate new level", Anchor.Centre, Anchor.Centre, titleFont ), TextWidget.Create( game, 0, -130, "Generate new level", Anchor.Centre, Anchor.Centre, titleFont ),
}; };
widgets = new [] { widgets = new [] {
ButtonWidget.Create( game, -90, 100, 120, 35, "Flatgrass", Anchor.Centre, ButtonWidget.Create( game, -90, 100, 130, 35, "Flatgrass", Anchor.Centre,
Anchor.Centre, titleFont, GenFlatgrassClick ), Anchor.Centre, titleFont, GenFlatgrassClick ),
ButtonWidget.Create( game, 90, 100, 120, 35, "Vanilla", Anchor.Centre, ButtonWidget.Create( game, 90, 100, 130, 35, "Vanilla", Anchor.Centre,
Anchor.Centre, titleFont, GenNotchyClick ), Anchor.Centre, titleFont, GenNotchyClick ),
MakeBack( false, titleFont, MakeBack( false, titleFont,
(g, w) => g.SetNewScreen( new PauseScreen( g ) ) ), (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ),

View File

@ -11,10 +11,10 @@ namespace ClassicalSharp.Gui {
public override void Render( double delta ) { public override void Render( double delta ) {
RenderMenuBounds(); RenderMenuBounds();
graphicsApi.Texturing = true; api.Texturing = true;
RenderMenuWidgets( delta ); RenderMenuWidgets( delta );
statusWidget.Render( delta ); statusWidget.Render( delta );
graphicsApi.Texturing = false; api.Texturing = false;
} }
Font keyFont; Font keyFont;

View File

@ -22,10 +22,10 @@ namespace ClassicalSharp.Gui {
if( extendedHelp != null && extEndY <= widgets[widgets.Length - 3].Y ) { if( extendedHelp != null && extEndY <= widgets[widgets.Length - 3].Y ) {
int x = game.Width / 2 - tableWidth / 2 - 5; int x = game.Width / 2 - tableWidth / 2 - 5;
int y = game.Height / 2 + extHelpY - 5; int y = game.Height / 2 + extHelpY - 5;
graphicsApi.Draw2DQuad( x, y, tableWidth + 10, tableHeight + 10, tableCol ); api.Draw2DQuad( x, y, tableWidth + 10, tableHeight + 10, tableCol );
} }
graphicsApi.Texturing = true; api.Texturing = true;
RenderMenuWidgets( delta ); RenderMenuWidgets( delta );
if( inputWidget != null ) if( inputWidget != null )
inputWidget.Render( delta ); inputWidget.Render( delta );
@ -34,7 +34,7 @@ namespace ClassicalSharp.Gui {
for( int i = 0; i < extendedHelp.Length; i++ ) for( int i = 0; i < extendedHelp.Length; i++ )
extendedHelp[i].Render( delta ); extendedHelp[i].Render( delta );
} }
graphicsApi.Texturing = false; api.Texturing = false;
} }
public override void Init() { public override void Init() {

View File

@ -13,7 +13,7 @@ namespace ClassicalSharp.Gui {
protected Font titleFont, regularFont; protected Font titleFont, regularFont;
protected void RenderMenuBounds() { protected void RenderMenuBounds() {
graphicsApi.Draw2DQuad( 0, 0, game.Width, game.Height, new FastColour( 60, 60, 60, 160 ) ); api.Draw2DQuad( 0, 0, game.Width, game.Height, new FastColour( 60, 60, 60, 160 ) );
} }
protected void RenderMenuWidgets( double delta ) { protected void RenderMenuWidgets( double delta ) {

View File

@ -59,9 +59,9 @@ namespace ClassicalSharp.Gui {
public override void Render( double delta ) { public override void Render( double delta ) {
base.Render( delta ); base.Render( delta );
graphicsApi.Texturing = true; api.Texturing = true;
infoWidget.Render( delta ); infoWidget.Render( delta );
graphicsApi.Texturing = false; api.Texturing = false;
} }
public override void Dispose() { public override void Dispose() {

View File

@ -14,11 +14,11 @@ namespace ClassicalSharp.Gui {
public override void Render( double delta ) { public override void Render( double delta ) {
RenderMenuBounds(); RenderMenuBounds();
graphicsApi.Texturing = true; api.Texturing = true;
RenderMenuWidgets( delta ); RenderMenuWidgets( delta );
if( descWidget != null ) if( descWidget != null )
descWidget.Render( delta ); descWidget.Render( delta );
graphicsApi.Texturing = false; api.Texturing = false;
} }
public override void Init() { public override void Init() {

View File

@ -12,9 +12,9 @@ namespace ClassicalSharp.Gui {
public override void Render( double delta ) { public override void Render( double delta ) {
RenderMenuBounds(); RenderMenuBounds();
graphicsApi.Texturing = true; api.Texturing = true;
RenderMenuWidgets( delta ); RenderMenuWidgets( delta );
graphicsApi.Texturing = false; api.Texturing = false;
} }
public override void Init() { public override void Init() {

View File

@ -17,12 +17,12 @@ namespace ClassicalSharp.Gui {
public override void Render( double delta ) { public override void Render( double delta ) {
RenderMenuBounds(); RenderMenuBounds();
graphicsApi.Texturing = true; api.Texturing = true;
RenderMenuWidgets( delta ); RenderMenuWidgets( delta );
inputWidget.Render( delta ); inputWidget.Render( delta );
if( descWidget != null ) if( descWidget != null )
descWidget.Render( delta ); descWidget.Render( delta );
graphicsApi.Texturing = false; api.Texturing = false;
if( textPath != null ) { if( textPath != null ) {
SaveMap( textPath ); SaveMap( textPath );

View File

@ -78,11 +78,11 @@ namespace ClassicalSharp.Gui {
public override void Render( double delta ) { public override void Render( double delta ) {
RenderMenuBounds(); RenderMenuBounds();
graphicsApi.Texturing = true; api.Texturing = true;
RenderMenuWidgets( delta ); RenderMenuWidgets( delta );
for( int i = 0; i < labels.Length; i++ ) for( int i = 0; i < labels.Length; i++ )
labels[i].Render( delta ); labels[i].Render( delta );
graphicsApi.Texturing = false; api.Texturing = false;
if( renderFrame != null ) if( renderFrame != null )
renderFrame( this ); renderFrame( this );

View File

@ -37,7 +37,7 @@ namespace ClassicalSharp.Gui {
} }
public override void Render( double delta ) { public override void Render( double delta ) {
graphicsApi.Texturing = true; api.Texturing = true;
RenderHotbar(); RenderHotbar();
IsometricBlockDrawer.lastTexId = -1; IsometricBlockDrawer.lastTexId = -1;
@ -49,20 +49,20 @@ namespace ClassicalSharp.Gui {
float scale = (elemSize * 13.5f/16f) / 2f; float scale = (elemSize * 13.5f/16f) / 2f;
IsometricBlockDrawer.Draw( game, block, scale, x, y ); IsometricBlockDrawer.Draw( game, block, scale, x, y );
} }
graphicsApi.Texturing = false; api.Texturing = false;
} }
void RenderHotbar() { void RenderHotbar() {
int texId = game.UseClassicGui ? game.GuiClassicTexId : game.GuiTexId; int texId = game.UseClassicGui ? game.GuiClassicTexId : game.GuiTexId;
backTex.ID = texId; backTex.ID = texId;
backTex.Render( graphicsApi ); backTex.Render( api );
int i = game.Inventory.HeldBlockIndex; int i = game.Inventory.HeldBlockIndex;
int x = (int)(X + barXOffset + (elemSize + borderSize) * i + elemSize / 2); int x = (int)(X + barXOffset + (elemSize + borderSize) * i + elemSize / 2);
selTex.ID = texId; selTex.ID = texId;
selTex.X1 = (int)(x - selBlockSize / 2); selTex.X1 = (int)(x - selBlockSize / 2);
graphicsApi.Draw2DTexture( ref selTex ); api.Draw2DTexture( ref selTex );
} }
public override void Dispose() { } public override void Dispose() { }

View File

@ -47,7 +47,7 @@ namespace ClassicalSharp.Gui {
new TextureRec( 0, 46/256f, 200/256f, 20/256f ) ); new TextureRec( 0, 46/256f, 200/256f, 20/256f ) );
public string Text; public string Text;
public void SetText( string text ) { public void SetText( string text ) {
graphicsApi.DeleteTexture( ref texture ); api.DeleteTexture( ref texture );
Text = text; Text = text;
if( String.IsNullOrEmpty( text ) ) { if( String.IsNullOrEmpty( text ) ) {
texture = new Texture(); texture = new Texture();
@ -71,14 +71,14 @@ namespace ClassicalSharp.Gui {
backTex.X1 = X; backTex.Y1 = Y; backTex.X1 = X; backTex.Y1 = Y;
backTex.Width = Width; backTex.Height = Height; backTex.Width = Width; backTex.Height = Height;
backTex.Render( graphicsApi ); backTex.Render( api );
FastColour col = Active ? FastColour.White : new FastColour( 200, 200, 200 ); FastColour col = Active ? FastColour.White : new FastColour( 200, 200, 200 );
if( Disabled ) col = new FastColour( 150, 150, 150 ); if( Disabled ) col = new FastColour( 150, 150, 150 );
texture.Render( graphicsApi, col ); texture.Render( api, col );
} }
public override void Dispose() { public override void Dispose() {
graphicsApi.DeleteTexture( ref texture ); api.DeleteTexture( ref texture );
} }
public override void MoveTo( int newX, int newY ) { public override void MoveTo( int newX, int newY ) {

View File

@ -32,7 +32,7 @@ namespace ClassicalSharp.Gui {
} }
public override void Render( double delta ) { public override void Render( double delta ) {
texture.Render( graphicsApi ); texture.Render( api );
} }
public override void Init() { public override void Init() {
@ -111,7 +111,7 @@ namespace ClassicalSharp.Gui {
} }
public override void Dispose() { public override void Dispose() {
graphicsApi.DeleteTexture( ref texture ); api.DeleteTexture( ref texture );
} }
} }
} }

View File

@ -27,7 +27,7 @@ namespace ClassicalSharp.Gui {
} }
public override void SetText( string text ) { public override void SetText( string text ) {
graphicsApi.DeleteTexture( ref texture ); api.DeleteTexture( ref texture );
if( String.IsNullOrEmpty( text ) ) { if( String.IsNullOrEmpty( text ) ) {
texture = new Texture(); texture = new Texture();
Height = defaultHeight; Height = defaultHeight;

View File

@ -8,7 +8,7 @@ namespace ClassicalSharp.Gui {
public sealed partial class TextGroupWidget : Widget { public sealed partial class TextGroupWidget : Widget {
public void SetText( int index, string text ) { public void SetText( int index, string text ) {
graphicsApi.DeleteTexture( ref Textures[index] ); api.DeleteTexture( ref Textures[index] );
DrawTextArgs args = new DrawTextArgs( text, font, true ); DrawTextArgs args = new DrawTextArgs( text, font, true );
linkData[index] = default(LinkData); linkData[index] = default(LinkData);
LinkFlags prevFlags = index > 0 ? linkData[index - 1].flags : 0; LinkFlags prevFlags = index > 0 ? linkData[index - 1].flags : 0;

View File

@ -50,7 +50,7 @@ namespace ClassicalSharp.Gui {
public void PushUpAndReplaceLast( string text ) { public void PushUpAndReplaceLast( string text ) {
int y = Y; int y = Y;
graphicsApi.DeleteTexture( ref Textures[0] ); api.DeleteTexture( ref Textures[0] );
for( int i = 0; i < Textures.Length - 1; i++ ) { for( int i = 0; i < Textures.Length - 1; i++ ) {
Textures[i] = Textures[i + 1]; Textures[i] = Textures[i + 1];
lines[i] = lines[i + 1]; lines[i] = lines[i + 1];
@ -115,13 +115,13 @@ namespace ClassicalSharp.Gui {
for( int i = 0; i < Textures.Length; i++ ) { for( int i = 0; i < Textures.Length; i++ ) {
Texture texture = Textures[i]; Texture texture = Textures[i];
if( texture.IsValid ) if( texture.IsValid )
texture.Render( graphicsApi ); texture.Render( api );
} }
} }
public override void Dispose() { public override void Dispose() {
for( int i = 0; i < Textures.Length; i++ ) for( int i = 0; i < Textures.Length; i++ )
graphicsApi.DeleteTexture( ref Textures[i] ); api.DeleteTexture( ref Textures[i] );
} }
public override void MoveTo( int newX, int newY ) { public override void MoveTo( int newX, int newY ) {

View File

@ -40,20 +40,20 @@ namespace ClassicalSharp.Gui {
FastColour caretCol; FastColour caretCol;
static FastColour backColour = new FastColour( 60, 60, 60, 200 ); static FastColour backColour = new FastColour( 60, 60, 60, 200 );
public override void Render( double delta ) { public override void Render( double delta ) {
graphicsApi.Texturing = false; api.Texturing = false;
int y = Y, x = X; int y = Y, x = X;
for( int i = 0; i < sizes.Length; i++ ) { for( int i = 0; i < sizes.Length; i++ ) {
bool caretAtEnd = caretTex.Y1 == y && (indexX == LineLength || caretPos == -1); bool caretAtEnd = caretTex.Y1 == y && (indexX == LineLength || caretPos == -1);
int offset = caretAtEnd ? defaultWidth : 0; int offset = caretAtEnd ? defaultWidth : 0;
graphicsApi.Draw2DQuad( x + 5, y, sizes[i].Width + offset, sizes[i].Height, backColour ); api.Draw2DQuad( x + 5, y, sizes[i].Width + offset, sizes[i].Height, backColour );
y += sizes[i].Height; y += sizes[i].Height;
} }
if( sizes.Length == 0 || sizes[0] == Size.Empty ) if( sizes.Length == 0 || sizes[0] == Size.Empty )
graphicsApi.Draw2DQuad( x + 5, y, defaultWidth, defaultHeight, backColour ); api.Draw2DQuad( x + 5, y, defaultWidth, defaultHeight, backColour );
graphicsApi.Texturing = true; api.Texturing = true;
inputTex.Render( graphicsApi ); inputTex.Render( api );
caretTex.Render( graphicsApi, caretCol ); caretTex.Render( api, caretCol );
if( altText.Active ) if( altText.Active )
altText.Render( delta ); altText.Render( delta );
} }
@ -169,12 +169,12 @@ namespace ClassicalSharp.Gui {
} }
public override void Dispose() { public override void Dispose() {
graphicsApi.DeleteTexture( ref inputTex ); api.DeleteTexture( ref inputTex );
} }
public void DisposeFully() { public void DisposeFully() {
Dispose(); Dispose();
graphicsApi.DeleteTexture( ref caretTex ); api.DeleteTexture( ref caretTex );
} }
public override void MoveTo( int newX, int newY ) { public override void MoveTo( int newX, int newY ) {

View File

@ -41,7 +41,7 @@ namespace ClassicalSharp.Gui {
double accumulator; double accumulator;
public override void Render( double delta ) { public override void Render( double delta ) {
chatInputTexture.Render( graphicsApi ); chatInputTexture.Render( api );
//if( (accumulator % 1) < 0.5 && Active ) { //if( (accumulator % 1) < 0.5 && Active ) {
// chatCaretTexture.Y1 = chatInputTexture.Y1 + yOffset; // chatCaretTexture.Y1 = chatInputTexture.Y1 + yOffset;
// chatCaretTexture.Render( graphicsApi ); // chatCaretTexture.Render( graphicsApi );
@ -101,8 +101,8 @@ namespace ClassicalSharp.Gui {
} }
public override void Dispose() { public override void Dispose() {
graphicsApi.DeleteTexture( ref chatCaretTexture ); api.DeleteTexture( ref chatCaretTexture );
graphicsApi.DeleteTexture( ref chatInputTexture ); api.DeleteTexture( ref chatInputTexture );
} }
public override void MoveTo( int newX, int newY ) { public override void MoveTo( int newX, int newY ) {
@ -129,7 +129,7 @@ namespace ClassicalSharp.Gui {
chatInputText.DeleteAt( chatInputText.Length - 1 ); chatInputText.DeleteAt( chatInputText.Length - 1 );
return true; return true;
} }
graphicsApi.DeleteTexture( ref chatInputTexture ); api.DeleteTexture( ref chatInputTexture );
SetText( chatInputText.ToString() ); SetText( chatInputText.ToString() );
} }
return true; return true;
@ -138,7 +138,7 @@ namespace ClassicalSharp.Gui {
public override bool HandlesKeyDown( Key key ) { public override bool HandlesKeyDown( Key key ) {
if( key == Key.BackSpace && !chatInputText.Empty ) { if( key == Key.BackSpace && !chatInputText.Empty ) {
chatInputText.DeleteAt( chatInputText.Length - 1 ); chatInputText.DeleteAt( chatInputText.Length - 1 );
graphicsApi.DeleteTexture( ref chatInputTexture ); api.DeleteTexture( ref chatInputTexture );
SetText( chatInputText.ToString() ); SetText( chatInputText.ToString() );
} }
return key < Key.F1 || key > Key.F35; return key < Key.F1 || key > Key.F35;

View File

@ -63,12 +63,12 @@ namespace ClassicalSharp.Gui {
} }
public override void Render( double delta ) { public override void Render( double delta ) {
graphicsApi.Texturing = false; api.Texturing = false;
int offset = overview.Height; int offset = overview.Height;
int height = namesPerColumn * (elemHeight + 1) + boundsSize * 2 + offset; int height = namesPerColumn * (elemHeight + 1) + boundsSize * 2 + offset;
graphicsApi.Draw2DQuad( X, Y - offset, Width, height, lightTableCol ); api.Draw2DQuad( X, Y - offset, Width, height, lightTableCol );
graphicsApi.Texturing = true; api.Texturing = true;
overview.MoveTo( game.Width / 2 - overview.Width / 2, overview.MoveTo( game.Width / 2 - overview.Width / 2,
Y - offset + boundsSize / 2 ); Y - offset + boundsSize / 2 );
overview.Render( delta ); overview.Render( delta );
@ -76,7 +76,7 @@ namespace ClassicalSharp.Gui {
for( int i = 0; i < namesCount; i++ ) { for( int i = 0; i < namesCount; i++ ) {
Texture texture = textures[i]; Texture texture = textures[i];
if( texture.IsValid ) if( texture.IsValid )
texture.Render( graphicsApi ); texture.Render( api );
} }
} }
@ -159,7 +159,7 @@ namespace ClassicalSharp.Gui {
if( pInfo.Id != e.Id ) continue; if( pInfo.Id != e.Id ) continue;
Texture tex = textures[i]; Texture tex = textures[i];
graphicsApi.DeleteTexture( ref tex ); api.DeleteTexture( ref tex );
AddPlayerInfo( new PlayerInfo( game.CpePlayersList[e.Id] ), i ); AddPlayerInfo( new PlayerInfo( game.CpePlayersList[e.Id] ), i );
SortPlayerInfo(); SortPlayerInfo();
return; return;

View File

@ -73,7 +73,7 @@ namespace ClassicalSharp.Gui {
PlayerInfo pInfo = info[i]; PlayerInfo pInfo = info[i];
if( !pInfo.IsGroup && pInfo.NameId == e.Id ) { if( !pInfo.IsGroup && pInfo.NameId == e.Id ) {
Texture tex = textures[i]; Texture tex = textures[i];
graphicsApi.DeleteTexture( ref tex ); api.DeleteTexture( ref tex );
AddPlayerInfo( game.CpePlayersList[e.Id], i ); AddPlayerInfo( game.CpePlayersList[e.Id], i );
SortPlayerInfo(); SortPlayerInfo();
return; return;
@ -151,7 +151,7 @@ namespace ClassicalSharp.Gui {
} }
void DeleteGroup( ref int i ) { void DeleteGroup( ref int i ) {
graphicsApi.DeleteTexture( ref textures[i] ); api.DeleteTexture( ref textures[i] );
RemoveItemAt( info, i ); RemoveItemAt( info, i );
RemoveItemAt( textures, i ); RemoveItemAt( textures, i );

View File

@ -30,13 +30,13 @@ namespace ClassicalSharp.Gui {
public abstract string GetNameUnder( int mouseX, int mouseY ); public abstract string GetNameUnder( int mouseX, int mouseY );
public override void Render( double delta ) { public override void Render( double delta ) {
graphicsApi.Texturing = false; api.Texturing = false;
graphicsApi.Draw2DQuad( X, Y, Width, Height, tableCol ); api.Draw2DQuad( X, Y, Width, Height, tableCol );
graphicsApi.Texturing = true; api.Texturing = true;
for( int i = 0; i < namesCount; i++ ) { for( int i = 0; i < namesCount; i++ ) {
Texture texture = textures[i]; Texture texture = textures[i];
if( texture.IsValid ) { if( texture.IsValid ) {
texture.Render( graphicsApi ); texture.Render( api );
} }
} }
} }
@ -44,7 +44,7 @@ namespace ClassicalSharp.Gui {
public override void Dispose() { public override void Dispose() {
for( int i = 0; i < namesCount; i++ ) { for( int i = 0; i < namesCount; i++ ) {
Texture tex = textures[i]; Texture tex = textures[i];
graphicsApi.DeleteTexture( ref tex ); api.DeleteTexture( ref tex );
textures[i] = tex; textures[i] = tex;
} }
} }
@ -111,7 +111,7 @@ namespace ClassicalSharp.Gui {
protected void RemoveInfoAt<T>( T[] info, int i ) { protected void RemoveInfoAt<T>( T[] info, int i ) {
Texture tex = textures[i]; Texture tex = textures[i];
graphicsApi.DeleteTexture( ref tex ); api.DeleteTexture( ref tex );
RemoveItemAt( info, i ); RemoveItemAt( info, i );
RemoveItemAt( textures, i ); RemoveItemAt( textures, i );
namesCount--; namesCount--;

View File

@ -35,7 +35,7 @@ namespace ClassicalSharp.Gui {
} }
public virtual void SetText( string text ) { public virtual void SetText( string text ) {
graphicsApi.DeleteTexture( ref texture ); api.DeleteTexture( ref texture );
if( String.IsNullOrEmpty( text ) ) { if( String.IsNullOrEmpty( text ) ) {
texture = new Texture(); texture = new Texture();
Height = defaultHeight; Height = defaultHeight;
@ -51,11 +51,11 @@ namespace ClassicalSharp.Gui {
public override void Render( double delta ) { public override void Render( double delta ) {
if( texture.IsValid ) if( texture.IsValid )
texture.Render( graphicsApi ); texture.Render( api );
} }
public override void Dispose() { public override void Dispose() {
graphicsApi.DeleteTexture( ref texture ); api.DeleteTexture( ref texture );
} }
public override void MoveTo( int newX, int newY ) { public override void MoveTo( int newX, int newY ) {