mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-09 15:28:21 -04:00
Add basic keyboard-only aiming support
This commit is contained in:
parent
aefa0e93e0
commit
c0628d4a68
@ -21,6 +21,13 @@ static void Camera_OnRawMovement(float deltaX, float deltaY) {
|
||||
cam_deltaX += deltaX; cam_deltaY += deltaY;
|
||||
}
|
||||
|
||||
void Camera_KeyLookUpdate(cc_bool up, cc_bool down, cc_bool right, cc_bool left) {
|
||||
if (up) cam_deltaY -= 10.0;
|
||||
if (down) cam_deltaY += 10.0;
|
||||
if (right) cam_deltaX += 10.0;
|
||||
if (left) cam_deltaX -= 10.0;
|
||||
}
|
||||
|
||||
/*########################################################################################################################*
|
||||
*--------------------------------------------------Perspective camera-----------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
|
@ -80,4 +80,5 @@ CC_API void Camera_Register(struct Camera* camera);
|
||||
void Camera_CheckFocus(void);
|
||||
void Camera_UpdateProjection(void);
|
||||
void Camera_SetFov(int fov);
|
||||
void Camera_KeyLookUpdate(cc_bool up, cc_bool down, cc_bool right, cc_bool left);
|
||||
#endif
|
||||
|
14
src/Input.c
14
src/Input.c
@ -325,7 +325,8 @@ const cc_uint8 KeyBind_Defaults[KEYBIND_COUNT] = {
|
||||
KEY_F5, KEY_F1, KEY_F7, 'C',
|
||||
KEY_LCTRL, KEY_LMOUSE, KEY_MMOUSE, KEY_RMOUSE,
|
||||
KEY_F6, KEY_LALT, KEY_F8,
|
||||
'G', KEY_F10, 0
|
||||
'G', KEY_F10, 0,
|
||||
0, 0, 0, 0
|
||||
};
|
||||
static const char* const keybindNames[KEYBIND_COUNT] = {
|
||||
"Forward", "Back", "Left", "Right",
|
||||
@ -336,7 +337,8 @@ static const char* const keybindNames[KEYBIND_COUNT] = {
|
||||
"ThirdPerson", "HideGUI", "AxisLines", "ZoomScrolling",
|
||||
"HalfSpeed", "DeleteBlock", "PickBlock", "PlaceBlock",
|
||||
"AutoRotate", "HotbarSwitching", "SmoothCamera",
|
||||
"DropBlock", "IDOverlay", "BreakableLiquids"
|
||||
"DropBlock", "IDOverlay", "BreakableLiquids",
|
||||
"LookUp", "LookDown", "LookRight", "LookLeft"
|
||||
};
|
||||
|
||||
cc_bool KeyBind_IsPressed(KeyBind binding) { return Input_Pressed[KeyBinds[binding]]; }
|
||||
@ -770,9 +772,17 @@ void InputHandler_PickBlock(void) {
|
||||
|
||||
void InputHandler_Tick(void) {
|
||||
cc_bool left, middle, right;
|
||||
cc_bool look_up, look_down, look_right, look_left;
|
||||
TimeMS now = DateTime_CurrentUTC_MS();
|
||||
int delta = (int)(now - input_lastClick);
|
||||
|
||||
look_up = KeyBind_IsPressed(KEYBIND_LOOK_UP);
|
||||
look_down = KeyBind_IsPressed(KEYBIND_LOOK_DOWN);
|
||||
look_right = KeyBind_IsPressed(KEYBIND_LOOK_RIGHT);
|
||||
look_left = KeyBind_IsPressed(KEYBIND_LOOK_LEFT);
|
||||
|
||||
Camera_KeyLookUpdate(look_up, look_down, look_right, look_left);
|
||||
|
||||
if (delta < 250) return; /* 4 times per second */
|
||||
input_lastClick = now;
|
||||
if (Gui.InputGrab) return;
|
||||
|
@ -132,6 +132,7 @@ enum KeyBind_ {
|
||||
KEYBIND_HALF_SPEED, KEYBIND_DELETE_BLOCK, KEYBIND_PICK_BLOCK, KEYBIND_PLACE_BLOCK,
|
||||
KEYBIND_AUTOROTATE, KEYBIND_HOTBAR_SWITCH, KEYBIND_SMOOTH_CAMERA,
|
||||
KEYBIND_DROP_BLOCK, KEYBIND_IDOVERLAY, KEYBIND_BREAK_LIQUIDS,
|
||||
KEYBIND_LOOK_UP, KEYBIND_LOOK_DOWN, KEYBIND_LOOK_RIGHT, KEYBIND_LOOK_LEFT,
|
||||
KEYBIND_COUNT
|
||||
};
|
||||
typedef int KeyBind;
|
||||
|
@ -2005,11 +2005,11 @@ void OtherKeyBindingsScreen_Show(void) {
|
||||
*------------------------------------------------MouseKeyBindingsScreen---------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
void MouseKeyBindingsScreen_Show(void) {
|
||||
static const cc_uint8 binds[3] = { KEYBIND_DELETE_BLOCK, KEYBIND_PICK_BLOCK, KEYBIND_PLACE_BLOCK };
|
||||
static const char* const descs[3] = { "Delete block", "Pick block", "Place block" };
|
||||
static const cc_uint8 binds[7] = { KEYBIND_DELETE_BLOCK, KEYBIND_PICK_BLOCK, KEYBIND_PLACE_BLOCK, KEYBIND_LOOK_UP, KEYBIND_LOOK_DOWN, KEYBIND_LOOK_RIGHT, KEYBIND_LOOK_LEFT };
|
||||
static const char* const descs[7] = { "Delete block", "Pick block", "Place block", "Look Up", "Look Down", "Look Right", "Look Left" };
|
||||
|
||||
KeyBindsScreen_Reset(Menu_SwitchKeysOther, NULL, 260);
|
||||
KeyBindsScreen_SetLayout(-40, 10, -1);
|
||||
KeyBindsScreen_SetLayout(-140, 10, 5);
|
||||
KeyBindsScreen.msgText = "&ePress escape to reset the binding";
|
||||
KeyBindsScreen_Show(Array_Elems(binds), binds, descs, "Mouse key bindings");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user