mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-18 12:05:14 -04:00
Port GameMode to C.
This commit is contained in:
parent
7dc579e551
commit
f84c96ad28
@ -54,7 +54,7 @@ namespace ClassicalSharp.Mode {
|
||||
if (!inv.CanChangeSelected() || inv.Selected == old) return;
|
||||
|
||||
// Is the currently selected block an empty slot
|
||||
if (inv.Hotbar[inv.SelectedIndex] == Block.Air) {
|
||||
if (inv[inv.SelectedIndex] == Block.Air) {
|
||||
inv.Selected = old; return;
|
||||
}
|
||||
|
||||
|
@ -201,6 +201,7 @@
|
||||
<ClInclude Include="Formats.h" />
|
||||
<ClInclude Include="FrustumCulling.h" />
|
||||
<ClInclude Include="Deflate.h" />
|
||||
<ClInclude Include="GameMode.h" />
|
||||
<ClInclude Include="Gui.h" />
|
||||
<ClInclude Include="IModel.h" />
|
||||
<ClInclude Include="Input.h" />
|
||||
@ -272,6 +273,7 @@
|
||||
<ClCompile Include="ExtMath.c" />
|
||||
<ClCompile Include="Formats.c" />
|
||||
<ClCompile Include="Game.c" />
|
||||
<ClCompile Include="GameMode.c" />
|
||||
<ClCompile Include="Gui.c" />
|
||||
<ClCompile Include="Inventory.c" />
|
||||
<ClCompile Include="MapGenerator.c" />
|
||||
|
@ -372,6 +372,9 @@
|
||||
<ClInclude Include="Screens.h">
|
||||
<Filter>Header Files\2D</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="GameMode.h">
|
||||
<Filter>Header Files\Game</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Noise.c">
|
||||
@ -575,5 +578,8 @@
|
||||
<ClCompile Include="Screens.c">
|
||||
<Filter>Source Files\2D</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GameMode.c">
|
||||
<Filter>Source Files\Game</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -1,13 +1,87 @@
|
||||
#include "GameMode.h"
|
||||
#include "Inventory.h"
|
||||
#include "Widgets.h"
|
||||
#include "Game.h"
|
||||
#include "Screens.h"
|
||||
#include "Block.h"
|
||||
#include "Events.h"
|
||||
|
||||
IGameComponent GameMode_MakeComponent(void);
|
||||
void GameMode_Init(void) {
|
||||
BlockID* inv = Inventory_Table;
|
||||
inv[0] = BlockID_Stone; inv[1] = BlockID_Cobblestone; inv[2] = BlockID_Brick;
|
||||
inv[3] = BlockID_Dirt; inv[4] = BlockID_Wood; inv[5] = BlockID_Log;
|
||||
inv[6] = BlockID_Leaves; inv[7] = BlockID_Grass; inv[8] = BlockID_Slab;
|
||||
}
|
||||
|
||||
bool GameMode_HandlesKeyDown(Key key);
|
||||
bool GameMode_PickingLeft(void);
|
||||
bool GameMode_PickingRight(void);
|
||||
void GameMode_PickLeft(BlockID old);
|
||||
void GameMode_PickMiddle(BlockID old);
|
||||
void GameMode_PickRight(BlockID old, BlockID block);
|
||||
HotbarWidget* GameMode_MakeHotbar(void);
|
||||
void GameMode_BeginFrame(Real64 delta);
|
||||
void GameMode_EndFrame(Real64 delta);
|
||||
IGameComponent GameMode_MakeComponent(void) {
|
||||
IGameComponent comp = IGameComponent_MakeEmpty();
|
||||
comp.Init = GameMode_Init;
|
||||
return comp;
|
||||
}
|
||||
|
||||
bool GameMode_HandlesKeyDown(Key key) {
|
||||
Screen* activeScreen = Gui_GetActiveScreen();
|
||||
if (key == KeyBind_Get(KeyBind_Inventory) && activeScreen == Gui_HUD) {
|
||||
Screen* screen = InventoryScreen_MakeInstance();
|
||||
Gui_SetNewScreen(screen);
|
||||
return true;
|
||||
} else if (key == KeyBind_Get(KeyBind_DropBlock) && !Game_ClassicMode) {
|
||||
if (Inventory_CanChangeSelected()) {
|
||||
/* Don't assign SelectedIndex directly, because we don't want held block
|
||||
switching positions if they already have air in their inventory hotbar. */
|
||||
Inventory_Set(Inventory_SelectedIndex, BlockID_Air);
|
||||
Event_RaiseVoid(&UserEvents_HeldBlockChanged);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GameMode_PickingLeft(void) {
|
||||
/* always play delete animations, even if we aren't picking a block */
|
||||
game.HeldBlockRenderer.ClickAnim(true);
|
||||
return false;
|
||||
}
|
||||
bool GameMode_PickingRight(void) { return false; }
|
||||
|
||||
void GameMode_PickLeft(BlockID old) {
|
||||
Vector3I pos = Game_SelectedPos.BlockPos;
|
||||
Game_UpdateBlock(pos.X, pos.Y, pos.Z, BlockID_Air);
|
||||
Event_RaiseBlock(&UserEvents_BlockChanged, pos, old, BlockID_Air);
|
||||
}
|
||||
|
||||
void GameMode_PickMiddle(BlockID old) {
|
||||
if (Block_Draw[old] == DrawType_Gas) return;
|
||||
if (!(Block_CanPlace[old] || Block_CanDelete[old])) return;
|
||||
if (!Inventory_CanChangeSelected() || Inventory_SelectedBlock == old) return;
|
||||
|
||||
// Is the currently selected block an empty slot
|
||||
if (Inventory_Get(Inventory_SelectedIndex) == BlockID_Air) {
|
||||
Inventory_SetSelectedBlock(old);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Try to replace same block or empty slots first */
|
||||
UInt32 i;
|
||||
for (i = 0; i < INVENTORY_BLOCKS_PER_HOTBAR; i++) {
|
||||
if (Inventory_Get(i) != old && Inventory_Get(i) != BlockID_Air) continue;
|
||||
|
||||
Inventory_Set(i, old);
|
||||
Inventory_SetSelectedIndex(i);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Finally, replace the currently selected block */
|
||||
Inventory_SetSelectedBlock(old);
|
||||
}
|
||||
|
||||
void GameMode_PickRight(BlockID old, BlockID block) {
|
||||
Vector3I pos = Game_SelectedPos.TranslatedPos;
|
||||
Game_UpdateBlock(pos.X, pos.Y, pos.Z, block);
|
||||
Event_RaiseBlock(&UserEvents_BlockChanged, pos, old, block);
|
||||
}
|
||||
|
||||
HotbarWidget GameMode_Hotbar;
|
||||
HotbarWidget* GameMode_MakeHotbar(void) { return &GameMode_Hotbar; }
|
||||
void GameMode_BeginFrame(Real64 delta) { }
|
||||
void GameMode_EndFrame(Real64 delta) { }
|
Loading…
x
Reference in New Issue
Block a user