mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 02:25:32 -04:00
Make block select screen easier to use.
This commit is contained in:
parent
79690b405c
commit
4f01d562d0
@ -14,7 +14,7 @@ namespace ClassicalSharp {
|
|||||||
Block[] blocksTable;
|
Block[] blocksTable;
|
||||||
Texture blockInfoTexture;
|
Texture blockInfoTexture;
|
||||||
const int blocksPerRow = 10;
|
const int blocksPerRow = 10;
|
||||||
int selectedIndex, rows;
|
int selIndex, rows;
|
||||||
int startX, startY, blockSize;
|
int startX, startY, blockSize;
|
||||||
float selBlockExpand;
|
float selBlockExpand;
|
||||||
readonly Font font;
|
readonly Font font;
|
||||||
@ -34,15 +34,15 @@ namespace ClassicalSharp {
|
|||||||
GetCoords( i, out x, out y );
|
GetCoords( i, out x, out y );
|
||||||
|
|
||||||
// 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 == selectedIndex ) continue;
|
if( i == selIndex ) continue;
|
||||||
IsometricBlockDrawer.Draw( game, (byte)blocksTable[i], blockSize * 0.7f / 2f,
|
IsometricBlockDrawer.Draw( game, (byte)blocksTable[i], blockSize * 0.7f / 2f,
|
||||||
x + blockSize / 2, y + blockSize / 2 );
|
x + blockSize / 2, y + blockSize / 2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( selectedIndex != -1 ) {
|
if( selIndex != -1 ) {
|
||||||
int x, y;
|
int x, y;
|
||||||
GetCoords( selectedIndex, out x, out y );
|
GetCoords( selIndex, out x, out y );
|
||||||
IsometricBlockDrawer.Draw( game, (byte)blocksTable[selectedIndex], (blockSize + selBlockExpand) * 0.7f / 2,
|
IsometricBlockDrawer.Draw( game, (byte)blocksTable[selIndex], (blockSize + selBlockExpand) * 0.7f / 2,
|
||||||
x + blockSize / 2, y + blockSize / 2 );
|
x + blockSize / 2, y + blockSize / 2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,14 +79,28 @@ namespace ClassicalSharp {
|
|||||||
blockSize = (int)(50 * Math.Sqrt(game.GuiScale));
|
blockSize = (int)(50 * Math.Sqrt(game.GuiScale));
|
||||||
selBlockExpand = (float)(25 * Math.Sqrt(game.GuiScale));
|
selBlockExpand = (float)(25 * Math.Sqrt(game.GuiScale));
|
||||||
game.Events.BlockPermissionsChanged += BlockPermissionsChanged;
|
game.Events.BlockPermissionsChanged += BlockPermissionsChanged;
|
||||||
RecreateBlockTextures();
|
|
||||||
|
RecreateBlockTable();
|
||||||
|
Block held = game.Inventory.HeldBlock;
|
||||||
|
selIndex = Array.IndexOf<Block>( blocksTable, held );
|
||||||
|
MoveCursorToSelected();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MoveCursorToSelected() {
|
||||||
|
if( selIndex == -1 ) return;
|
||||||
|
int x, y;
|
||||||
|
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 ) {
|
||||||
RecreateBlockTextures();
|
RecreateBlockTable();
|
||||||
if( selectedIndex >= blocksTable.Length ) {
|
if( selIndex >= blocksTable.Length )
|
||||||
selectedIndex = blocksTable.Length - 1;
|
selIndex = blocksTable.Length - 1;
|
||||||
}
|
|
||||||
RecreateBlockInfoTexture();
|
RecreateBlockInfoTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,13 +137,13 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
int lastCreatedIndex = -1000;
|
int lastCreatedIndex = -1000;
|
||||||
void RecreateBlockInfoTexture() {
|
void RecreateBlockInfoTexture() {
|
||||||
if( selectedIndex == lastCreatedIndex ) return;
|
if( selIndex == lastCreatedIndex ) return;
|
||||||
lastCreatedIndex = selectedIndex;
|
lastCreatedIndex = selIndex;
|
||||||
|
|
||||||
graphicsApi.DeleteTexture( ref blockInfoTexture );
|
graphicsApi.DeleteTexture( ref blockInfoTexture );
|
||||||
if( selectedIndex == -1 ) return;
|
if( selIndex == -1 ) return;
|
||||||
|
|
||||||
Block block = blocksTable[selectedIndex];
|
Block block = blocksTable[selIndex];
|
||||||
UpdateBlockInfoString( block );
|
UpdateBlockInfoString( block );
|
||||||
string value = buffer.GetString();
|
string value = buffer.GetString();
|
||||||
|
|
||||||
@ -142,7 +156,7 @@ namespace ClassicalSharp {
|
|||||||
blockInfoTexture = game.Drawer2D.MakeTextTexture( ref args, x, y );
|
blockInfoTexture = game.Drawer2D.MakeTextTexture( ref args, x, y );
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecreateBlockTextures() {
|
void RecreateBlockTable() {
|
||||||
int blocksCount = 0;
|
int blocksCount = 0;
|
||||||
for( int tile = 1; tile < BlockInfo.BlocksCount; tile++ ) {
|
for( int tile = 1; tile < BlockInfo.BlocksCount; tile++ ) {
|
||||||
if( game.Inventory.CanPlace[tile] || game.Inventory.CanDelete[tile] )
|
if( game.Inventory.CanPlace[tile] || game.Inventory.CanDelete[tile] )
|
||||||
@ -166,14 +180,14 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandlesMouseMove( int mouseX, int mouseY ) {
|
public override bool HandlesMouseMove( int mouseX, int mouseY ) {
|
||||||
selectedIndex = -1;
|
selIndex = -1;
|
||||||
if( Contains( startX, startY, blocksPerRow * blockSize, rows * blockSize, mouseX, mouseY ) ) {
|
if( Contains( startX, startY, blocksPerRow * blockSize, rows * blockSize, mouseX, mouseY ) ) {
|
||||||
for( int i = 0; i < blocksTable.Length; i++ ) {
|
for( int i = 0; i < blocksTable.Length; i++ ) {
|
||||||
int x, y;
|
int x, y;
|
||||||
GetCoords( i, out x, out y );
|
GetCoords( i, out x, out y );
|
||||||
|
|
||||||
if( Contains( x, y, blockSize, blockSize, mouseX, mouseY ) ) {
|
if( Contains( x, y, blockSize, blockSize, mouseX, mouseY ) ) {
|
||||||
selectedIndex = i;
|
selIndex = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -183,8 +197,8 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandlesMouseClick( int mouseX, int mouseY, MouseButton button ) {
|
public override bool HandlesMouseClick( int mouseX, int mouseY, MouseButton button ) {
|
||||||
if( button == MouseButton.Left && selectedIndex != -1 ) {
|
if( button == MouseButton.Left && selIndex != -1 ) {
|
||||||
game.Inventory.HeldBlock = blocksTable[selectedIndex];
|
game.Inventory.HeldBlock = blocksTable[selIndex];
|
||||||
game.SetNewScreen( null );
|
game.SetNewScreen( null );
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -194,6 +208,33 @@ namespace ClassicalSharp {
|
|||||||
if( key == game.Mapping( KeyBinding.PauseOrExit ) ||
|
if( key == game.Mapping( KeyBinding.PauseOrExit ) ||
|
||||||
key == game.Mapping( KeyBinding.OpenInventory ) ) {
|
key == game.Mapping( KeyBinding.OpenInventory ) ) {
|
||||||
game.SetNewScreen( null );
|
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 ) {
|
||||||
|
selIndex--;
|
||||||
|
if( selIndex < 0 )
|
||||||
|
selIndex = 0;
|
||||||
|
RecreateBlockInfoTexture();
|
||||||
|
MoveCursorToSelected();
|
||||||
|
} else if( (key == Key.Right || key == Key.Keypad6) && selIndex != -1 ) {
|
||||||
|
selIndex++;
|
||||||
|
if( selIndex >= blocksTable.Length )
|
||||||
|
selIndex = blocksTable.Length - 1;
|
||||||
|
RecreateBlockInfoTexture();
|
||||||
|
MoveCursorToSelected();
|
||||||
|
} else if( (key == Key.Up || key == Key.Keypad8) && selIndex != -1 ) {
|
||||||
|
selIndex -= blocksPerRow;
|
||||||
|
if( selIndex < 0 )
|
||||||
|
selIndex += blocksPerRow;
|
||||||
|
RecreateBlockInfoTexture();
|
||||||
|
MoveCursorToSelected();
|
||||||
|
} else if( (key == Key.Down || key == Key.Keypad2) && selIndex != -1 ) {
|
||||||
|
selIndex += blocksPerRow;
|
||||||
|
if( selIndex >= blocksTable.Length )
|
||||||
|
selIndex -= blocksPerRow;
|
||||||
|
RecreateBlockInfoTexture();
|
||||||
|
MoveCursorToSelected();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -65,18 +65,19 @@ namespace ClassicalSharp {
|
|||||||
if( !game.Focused ) return;
|
if( !game.Focused ) return;
|
||||||
Point current = game.DesktopCursorPos;
|
Point current = game.DesktopCursorPos;
|
||||||
delta = new Point( current.X - previous.X, current.Y - previous.Y );
|
delta = new Point( current.X - previous.X, current.Y - previous.Y );
|
||||||
Rectangle bounds = game.Bounds;
|
Point topLeft = game.PointToScreen( Point.Empty );
|
||||||
int cenX = bounds.Left + bounds.Width / 2;
|
int cenX = topLeft.X + game.Width / 2;
|
||||||
int cenY = bounds.Top + bounds.Height / 2;
|
int cenY = topLeft.Y + game.Height / 2;
|
||||||
game.DesktopCursorPos = new Point( cenX, cenY );
|
game.DesktopCursorPos = new Point( cenX, cenY );
|
||||||
// Fixes issues with large DPI displays on Windows >= 8.0.
|
// Fixes issues with large DPI displays on Windows >= 8.0.
|
||||||
previous = game.DesktopCursorPos;
|
previous = game.DesktopCursorPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void RegrabMouse() {
|
public override void RegrabMouse() {
|
||||||
Rectangle bounds = game.Bounds;
|
if( !game.Exists ) return;
|
||||||
int cenX = bounds.Left + bounds.Width / 2;
|
Point topLeft = game.PointToScreen( Point.Empty );
|
||||||
int cenY = bounds.Top + bounds.Height / 2;
|
int cenX = topLeft.X + game.Width / 2;
|
||||||
|
int cenY = topLeft.Y + game.Height / 2;
|
||||||
game.DesktopCursorPos = new Point( cenX, cenY );
|
game.DesktopCursorPos = new Point( cenX, cenY );
|
||||||
previous = new Point( cenX, cenY );
|
previous = new Point( cenX, cenY );
|
||||||
delta = Point.Empty;
|
delta = Point.Empty;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user