mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-18 03:55:19 -04:00
Don't clamp the cursor to the centre of the block when scrolling in the inventory screen. (Thanks FabTheZen)
This commit is contained in:
parent
785222cc8f
commit
3f146a15e6
89
ClassicalSharp/2D/Screens/Inventory/InventoryScreen.Input.cs
Normal file
89
ClassicalSharp/2D/Screens/Inventory/InventoryScreen.Input.cs
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
|
||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
using ClassicalSharp.GraphicsAPI;
|
||||||
|
using OpenTK.Input;
|
||||||
|
|
||||||
|
namespace ClassicalSharp.Gui {
|
||||||
|
|
||||||
|
public partial class InventoryScreen : Screen {
|
||||||
|
|
||||||
|
public override bool HandlesAllInput { get { return true; } }
|
||||||
|
|
||||||
|
public override bool HandlesMouseMove( int mouseX, int mouseY ) {
|
||||||
|
if( draggingMouse ) {
|
||||||
|
mouseY -= TableY;
|
||||||
|
scrollY = (int)((mouseY - mouseOffset) / ScrollbarScale);
|
||||||
|
ClampScrollY();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
selIndex = -1;
|
||||||
|
if( Contains( startX, startY, blocksPerRow * blockSize,
|
||||||
|
maxRows * blockSize, mouseX, mouseY ) ) {
|
||||||
|
for( int i = 0; i < blocksTable.Length; i++ ) {
|
||||||
|
int x, y;
|
||||||
|
GetCoords( i, out x, out y );
|
||||||
|
|
||||||
|
if( Contains( x, y, blockSize, blockSize, mouseX, mouseY ) ) {
|
||||||
|
selIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RecreateBlockInfoTexture();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool HandlesMouseClick( int mouseX, int mouseY, MouseButton button ) {
|
||||||
|
if( draggingMouse || game.hudScreen.hotbar.HandlesMouseClick( mouseX, mouseY, button ) )
|
||||||
|
return true;
|
||||||
|
if( button == MouseButton.Left && mouseX >= TableX && mouseX < TableX + scrollbarWidth ) {
|
||||||
|
ScrollbarClick( mouseY );
|
||||||
|
} else if( button == MouseButton.Left ) {
|
||||||
|
if( selIndex != -1 )
|
||||||
|
game.Inventory.HeldBlock = blocksTable[selIndex];
|
||||||
|
else if( Contains( TableX, TableY, TableWidth, TableHeight, mouseX, mouseY ) )
|
||||||
|
return true;
|
||||||
|
game.SetNewScreen( null );
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool HandlesKeyDown( Key key ) {
|
||||||
|
if( key == game.Mapping( KeyBinding.PauseOrExit ) ||
|
||||||
|
key == game.Mapping( KeyBinding.OpenInventory ) ) {
|
||||||
|
game.SetNewScreen( null );
|
||||||
|
} else if( key == Key.Enter && selIndex != -1 ) {
|
||||||
|
game.Inventory.HeldBlock = blocksTable[selIndex];
|
||||||
|
game.SetNewScreen( null );
|
||||||
|
} else if( (key == Key.Left || key == Key.Keypad4) && selIndex != -1 ) {
|
||||||
|
ArrowKeyMove( -1 );
|
||||||
|
} else if( (key == Key.Right || key == Key.Keypad6) && selIndex != -1 ) {
|
||||||
|
ArrowKeyMove( 1 );
|
||||||
|
} else if( (key == Key.Up || key == Key.Keypad8) && selIndex != -1 ) {
|
||||||
|
ArrowKeyMove( -blocksPerRow );
|
||||||
|
} else if( (key == Key.Down || key == Key.Keypad2) && selIndex != -1 ) {
|
||||||
|
ArrowKeyMove( blocksPerRow );
|
||||||
|
} else if( key >= Key.Number1 && key <= Key.Number9 ) {
|
||||||
|
game.Inventory.HeldBlockIndex = (int)key - (int)Key.Number1;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ArrowKeyMove( int delta ) {
|
||||||
|
int startIndex = selIndex;
|
||||||
|
selIndex += delta;
|
||||||
|
if( selIndex < 0 )
|
||||||
|
selIndex -= delta;
|
||||||
|
if( selIndex >= blocksTable.Length )
|
||||||
|
selIndex -= delta;
|
||||||
|
|
||||||
|
int scrollDelta = (selIndex / blocksPerRow) - (startIndex / blocksPerRow);
|
||||||
|
scrollY += scrollDelta;
|
||||||
|
ClampScrollY();
|
||||||
|
RecreateBlockInfoTexture();
|
||||||
|
MoveCursorToSelected();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,11 @@
|
|||||||
// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
|
// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
|
||||||
using System;
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
using OpenTK.Input;
|
using OpenTK.Input;
|
||||||
|
|
||||||
namespace ClassicalSharp.Gui {
|
namespace ClassicalSharp.Gui {
|
||||||
|
|
||||||
public partial class BlockSelectScreen : Screen {
|
public partial class InventoryScreen : Screen {
|
||||||
|
|
||||||
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 );
|
||||||
@ -36,10 +37,11 @@ namespace ClassicalSharp.Gui {
|
|||||||
|
|
||||||
selIndex = scrollY * blocksPerRow + (selIndex % blocksPerRow);
|
selIndex = scrollY * blocksPerRow + (selIndex % blocksPerRow);
|
||||||
for( int row = 0; row < rowY; row++ ) {
|
for( int row = 0; row < rowY; row++ ) {
|
||||||
if( selIndex + blocksPerRow >= blocksTable.Length ) break;
|
|
||||||
selIndex += blocksPerRow;
|
selIndex += blocksPerRow;
|
||||||
}
|
}
|
||||||
MoveCursorToSelected();
|
|
||||||
|
if( selIndex >= blocksTable.Length )
|
||||||
|
selIndex = -1;
|
||||||
RecreateBlockInfoTexture();
|
RecreateBlockInfoTexture();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
@ -6,15 +6,15 @@ using OpenTK.Input;
|
|||||||
|
|
||||||
namespace ClassicalSharp.Gui {
|
namespace ClassicalSharp.Gui {
|
||||||
|
|
||||||
public partial class BlockSelectScreen : Screen {
|
public partial class InventoryScreen : Screen {
|
||||||
|
|
||||||
public BlockSelectScreen( Game game ) : base( game ) {
|
public InventoryScreen( Game game ) : base( game ) {
|
||||||
font = new Font( game.FontName, 13 );
|
font = new Font( game.FontName, 13 );
|
||||||
}
|
}
|
||||||
|
|
||||||
Block[] blocksTable;
|
Block[] blocksTable;
|
||||||
Texture blockInfoTexture;
|
Texture blockInfoTexture;
|
||||||
const int blocksPerRow = 10, maxRows = 8;
|
const int blocksPerRow = 10, maxRows = 4;
|
||||||
int selIndex, rows;
|
int selIndex, rows;
|
||||||
int startX, startY, blockSize;
|
int startX, startY, blockSize;
|
||||||
float selBlockExpand;
|
float selBlockExpand;
|
||||||
@ -69,6 +69,16 @@ namespace ClassicalSharp.Gui {
|
|||||||
return row >= 0 && row < maxRows;
|
return row >= 0 && row < maxRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Point GetMouseCoords( int i ) {
|
||||||
|
int x, y;
|
||||||
|
GetCoords( i, out x, out y );
|
||||||
|
x += blockSize / 2; y += blockSize / 2;
|
||||||
|
|
||||||
|
Point topLeft = game.PointToScreen( Point.Empty );
|
||||||
|
x += topLeft.X; y += topLeft.Y;
|
||||||
|
return new Point( x, y );
|
||||||
|
}
|
||||||
|
|
||||||
public override void Dispose() {
|
public override void Dispose() {
|
||||||
font.Dispose();
|
font.Dispose();
|
||||||
api.DeleteTexture( ref blockInfoTexture );
|
api.DeleteTexture( ref blockInfoTexture );
|
||||||
@ -107,13 +117,7 @@ namespace ClassicalSharp.Gui {
|
|||||||
|
|
||||||
void MoveCursorToSelected() {
|
void MoveCursorToSelected() {
|
||||||
if( selIndex == -1 ) return;
|
if( selIndex == -1 ) return;
|
||||||
int x, y;
|
game.DesktopCursorPos = GetMouseCoords( selIndex );
|
||||||
GetCoords( selIndex, out x, out y );
|
|
||||||
x += blockSize / 2; y += blockSize / 2;
|
|
||||||
|
|
||||||
Point topLeft = game.PointToScreen( Point.Empty );
|
|
||||||
x += topLeft.X; y += topLeft.Y;
|
|
||||||
game.DesktopCursorPos = new Point( x, y );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlockPermissionsChanged( object sender, EventArgs e ) {
|
void BlockPermissionsChanged( object sender, EventArgs e ) {
|
||||||
@ -220,83 +224,5 @@ namespace ClassicalSharp.Gui {
|
|||||||
return false;
|
return false;
|
||||||
return tile < BlockInfo.CpeBlocksCount || game.BlockInfo.Name[tile] != "Invalid";
|
return tile < BlockInfo.CpeBlocksCount || game.BlockInfo.Name[tile] != "Invalid";
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandlesAllInput { get { return true; } }
|
|
||||||
|
|
||||||
public override bool HandlesMouseMove( int mouseX, int mouseY ) {
|
|
||||||
if( draggingMouse ) {
|
|
||||||
mouseY -= TableY;
|
|
||||||
scrollY = (int)((mouseY - mouseOffset) / ScrollbarScale);
|
|
||||||
ClampScrollY();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
selIndex = -1;
|
|
||||||
if( Contains( startX, startY, blocksPerRow * blockSize,
|
|
||||||
maxRows * blockSize, mouseX, mouseY ) ) {
|
|
||||||
for( int i = 0; i < blocksTable.Length; i++ ) {
|
|
||||||
int x, y;
|
|
||||||
GetCoords( i, out x, out y );
|
|
||||||
|
|
||||||
if( Contains( x, y, blockSize, blockSize, mouseX, mouseY ) ) {
|
|
||||||
selIndex = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
RecreateBlockInfoTexture();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool HandlesMouseClick( int mouseX, int mouseY, MouseButton button ) {
|
|
||||||
if( draggingMouse || game.hudScreen.hotbar.HandlesMouseClick( mouseX, mouseY, button ) )
|
|
||||||
return true;
|
|
||||||
if( button == MouseButton.Left && mouseX >= TableX && mouseX < TableX + scrollbarWidth ) {
|
|
||||||
ScrollbarClick( mouseY );
|
|
||||||
} else if( button == MouseButton.Left ) {
|
|
||||||
if( selIndex != -1 )
|
|
||||||
game.Inventory.HeldBlock = blocksTable[selIndex];
|
|
||||||
else if( Contains( TableX, TableY, TableWidth, TableHeight, mouseX, mouseY ) )
|
|
||||||
return true;
|
|
||||||
game.SetNewScreen( null );
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool HandlesKeyDown( Key key ) {
|
|
||||||
if( key == game.Mapping( KeyBinding.PauseOrExit ) ||
|
|
||||||
key == game.Mapping( KeyBinding.OpenInventory ) ) {
|
|
||||||
game.SetNewScreen( null );
|
|
||||||
} else if( key == Key.Enter && selIndex != -1 ) {
|
|
||||||
game.Inventory.HeldBlock = blocksTable[selIndex];
|
|
||||||
game.SetNewScreen( null );
|
|
||||||
} else if( (key == Key.Left || key == Key.Keypad4) && selIndex != -1 ) {
|
|
||||||
ArrowKeyMove( -1 );
|
|
||||||
} else if( (key == Key.Right || key == Key.Keypad6) && selIndex != -1 ) {
|
|
||||||
ArrowKeyMove( 1 );
|
|
||||||
} else if( (key == Key.Up || key == Key.Keypad8) && selIndex != -1 ) {
|
|
||||||
ArrowKeyMove( -blocksPerRow );
|
|
||||||
} else if( (key == Key.Down || key == Key.Keypad2) && selIndex != -1 ) {
|
|
||||||
ArrowKeyMove( blocksPerRow );
|
|
||||||
} else if( key >= Key.Number1 && key <= Key.Number9 ) {
|
|
||||||
game.Inventory.HeldBlockIndex = (int)key - (int)Key.Number1;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ArrowKeyMove( int delta ) {
|
|
||||||
int startIndex = selIndex;
|
|
||||||
selIndex += delta;
|
|
||||||
if( selIndex < 0 )
|
|
||||||
selIndex -= delta;
|
|
||||||
if( selIndex >= blocksTable.Length )
|
|
||||||
selIndex -= delta;
|
|
||||||
|
|
||||||
int scrollDelta = (selIndex / blocksPerRow) - (startIndex / blocksPerRow);
|
|
||||||
scrollY += scrollDelta;
|
|
||||||
ClampScrollY();
|
|
||||||
RecreateBlockInfoTexture();
|
|
||||||
MoveCursorToSelected();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -97,7 +97,7 @@ namespace ClassicalSharp.Gui {
|
|||||||
public override bool HandlesMouseClick( int mouseX, int mouseY, MouseButton button ) {
|
public override bool HandlesMouseClick( int mouseX, int mouseY, MouseButton button ) {
|
||||||
if( button != MouseButton.Left || !Bounds.Contains( mouseX, mouseY ) )
|
if( button != MouseButton.Left || !Bounds.Contains( mouseX, mouseY ) )
|
||||||
return false;
|
return false;
|
||||||
BlockSelectScreen screen = game.GetActiveScreen as BlockSelectScreen;
|
InventoryScreen screen = game.GetActiveScreen as InventoryScreen;
|
||||||
if( screen == null ) return false;
|
if( screen == null ) return false;
|
||||||
|
|
||||||
for( int i = 0; i < hotbarCount; i++ ) {
|
for( int i = 0; i < hotbarCount; i++ ) {
|
||||||
|
@ -86,14 +86,15 @@
|
|||||||
<Compile Include="2D\Drawing\DrawTextArgs.cs" />
|
<Compile Include="2D\Drawing\DrawTextArgs.cs" />
|
||||||
<Compile Include="2D\Drawing\GdiPlusDrawer2D.cs" />
|
<Compile Include="2D\Drawing\GdiPlusDrawer2D.cs" />
|
||||||
<Compile Include="2D\Drawing\IDrawer2D.cs" />
|
<Compile Include="2D\Drawing\IDrawer2D.cs" />
|
||||||
<Compile Include="2D\Screens\BlockSelectScreen.cs" />
|
|
||||||
<Compile Include="2D\Screens\BlockSelectScreen.Scrolling.cs" />
|
|
||||||
<Compile Include="2D\Screens\ChatScreen.cs" />
|
<Compile Include="2D\Screens\ChatScreen.cs" />
|
||||||
<Compile Include="2D\Screens\ClickableScreen.cs" />
|
<Compile Include="2D\Screens\ClickableScreen.cs" />
|
||||||
<Compile Include="2D\Screens\ErrorScreen.cs" />
|
<Compile Include="2D\Screens\ErrorScreen.cs" />
|
||||||
<Compile Include="2D\Screens\FilesScreen.cs" />
|
<Compile Include="2D\Screens\FilesScreen.cs" />
|
||||||
<Compile Include="2D\Screens\FpsScreen.cs" />
|
<Compile Include="2D\Screens\FpsScreen.cs" />
|
||||||
<Compile Include="2D\Screens\HotkeyScreen.cs" />
|
<Compile Include="2D\Screens\HotkeyScreen.cs" />
|
||||||
|
<Compile Include="2D\Screens\Inventory\InventoryScreen.cs" />
|
||||||
|
<Compile Include="2D\Screens\Inventory\InventoryScreen.Input.cs" />
|
||||||
|
<Compile Include="2D\Screens\Inventory\InventoryScreen.Scrolling.cs" />
|
||||||
<Compile Include="2D\Screens\LoadingMapScreen.cs" />
|
<Compile Include="2D\Screens\LoadingMapScreen.cs" />
|
||||||
<Compile Include="2D\Screens\Menu\ClassicOptionsScreen.cs" />
|
<Compile Include="2D\Screens\Menu\ClassicOptionsScreen.cs" />
|
||||||
<Compile Include="2D\Screens\Menu\EnvSettingsScreen.cs" />
|
<Compile Include="2D\Screens\Menu\EnvSettingsScreen.cs" />
|
||||||
@ -291,6 +292,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="2D\Drawing" />
|
<Folder Include="2D\Drawing" />
|
||||||
|
<Folder Include="2D\Screens\Inventory" />
|
||||||
<Folder Include="2D\Utils" />
|
<Folder Include="2D\Utils" />
|
||||||
<Folder Include="2D\Screens" />
|
<Folder Include="2D\Screens" />
|
||||||
<Folder Include="2D\Screens\Menu" />
|
<Folder Include="2D\Screens\Menu" />
|
||||||
|
@ -78,6 +78,9 @@ namespace ClassicalSharp.Entities {
|
|||||||
/// <summary> Determines whether any of the blocks that intersect the
|
/// <summary> Determines whether any of the blocks that intersect the
|
||||||
/// bounding box of this entity are water or still water. </summary>
|
/// bounding box of this entity are water or still water. </summary>
|
||||||
public bool TouchesAnyWater() {
|
public bool TouchesAnyWater() {
|
||||||
|
// TODO: proper way to check seems to be:
|
||||||
|
// If liquid block above, leave height same
|
||||||
|
// otherwise reduce water BB height by 0.5 blocks
|
||||||
BoundingBox bounds = CollisionBounds.Expand( liqExpand );
|
BoundingBox bounds = CollisionBounds.Expand( liqExpand );
|
||||||
AdjustLiquidTestBounds( ref bounds );
|
AdjustLiquidTestBounds( ref bounds );
|
||||||
return TouchesAny( bounds,
|
return TouchesAny( bounds,
|
||||||
|
@ -350,7 +350,7 @@ namespace ClassicalSharp {
|
|||||||
} else if( key == Keys[KeyBinding.PauseOrExit] && !game.World.IsNotLoaded ) {
|
} else if( key == Keys[KeyBinding.PauseOrExit] && !game.World.IsNotLoaded ) {
|
||||||
game.SetNewScreen( new PauseScreen( game ) );
|
game.SetNewScreen( new PauseScreen( game ) );
|
||||||
} else if( key == Keys[KeyBinding.OpenInventory] ) {
|
} else if( key == Keys[KeyBinding.OpenInventory] ) {
|
||||||
game.SetNewScreen( new BlockSelectScreen( game ) );
|
game.SetNewScreen( new InventoryScreen( game ) );
|
||||||
} else if( key == Key.F9 ) {
|
} else if( key == Key.F9 ) {
|
||||||
game.ShowClock = !game.ShowClock;
|
game.ShowClock = !game.ShowClock;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user