Fix keyboard camera movement having a large jump in rotation if a camera movement key is held down when exiting a menu that held input lock

Also
- Fix the launcher main menu showing 'Checking..' afer going to Updates menu, waiting a bit, and then going back to main menu
- The centre box in the check/fetch resources menu is now appropriately coloured based on the launcher theme background
This commit is contained in:
UnknownShadow200 2023-12-22 22:02:09 +11:00
parent 0d24afb9b8
commit d2a43e4f0e
4 changed files with 45 additions and 39 deletions

View File

@ -17,24 +17,20 @@ static struct RayTracer cameraClipPos;
static Vec2 cam_rotOffset;
static cc_bool cam_isForwardThird;
static float cam_deltaX, cam_deltaY;
static double last_time;
static void Camera_OnRawMovement(float deltaX, float deltaY) {
cam_deltaX += deltaX; cam_deltaY += deltaY;
}
void Camera_KeyLookUpdate(void) {
float delta;
void Camera_KeyLookUpdate(double delta) {
if (Gui.InputGrab) return;
/* divide by 25 to have reasonable sensitivity for default mouse sens */
delta = (Camera.Sensitivity / 25.0f) * (1000 * (Game.Time - last_time));
delta = (Camera.Sensitivity / 25.0f) * (1000 * delta);
if (KeyBind_IsPressed(KEYBIND_LOOK_UP)) cam_deltaY -= delta;
if (KeyBind_IsPressed(KEYBIND_LOOK_DOWN)) cam_deltaY += delta;
if (KeyBind_IsPressed(KEYBIND_LOOK_LEFT)) cam_deltaX -= delta;
if (KeyBind_IsPressed(KEYBIND_LOOK_RIGHT)) cam_deltaX += delta;
last_time = Game.Time;
}
/*########################################################################################################################*

View File

@ -80,5 +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(void);
void Camera_KeyLookUpdate(double delta);
#endif

View File

@ -511,7 +511,7 @@ static void Game_Render3D(double delta, float t) {
Selections_Render();
EntityNames_RenderHovered();
Camera_KeyLookUpdate();
Camera_KeyLookUpdate(delta);
InputHandler_Tick();
if (!Game_HideGui) HeldBlockRenderer_Render(delta);
}

View File

@ -790,6 +790,37 @@ static void MainScreen_ResumeUnhover(void* w) {
LLabel_SetConst(&s->lblStatus, "");
}
CC_NOINLINE static cc_uint32 MainScreen_GetVersion(const cc_string* version) {
cc_uint8 raw[4] = { 0, 0, 0, 0 };
cc_string parts[4];
int i, count;
/* 1.0.1 -> { 1, 0, 1, 0 } */
count = String_UNSAFE_Split(version, '.', parts, 4);
for (i = 0; i < count; i++)
{
Convert_ParseUInt8(&parts[i], &raw[i]);
}
return Stream_GetU32_BE(raw);
}
static void MainScreen_ApplyUpdateLabel(struct MainScreen* s) {
static const cc_string currentStr = String_FromConst(GAME_APP_VER);
cc_uint32 latest, current;
if (CheckUpdateTask.Base.success) {
latest = MainScreen_GetVersion(&CheckUpdateTask.latestRelease);
current = MainScreen_GetVersion(&currentStr);
#ifdef CC_BUILD_FLATPAK
LLabel_SetConst(&s->lblUpdate, latest > current ? "&aUpdate available" : "&eUp to date");
#else
LLabel_SetConst(&s->lblUpdate, latest > current ? "&aNew release" : "&eUp to date");
#endif
} else {
LLabel_SetConst(&s->lblUpdate, "&cCheck failed");
}
}
static void MainScreen_Activated(struct LScreen* s_) {
struct MainScreen* s = (struct MainScreen*)s_;
@ -825,6 +856,9 @@ static void MainScreen_Activated(struct LScreen* s_) {
s->btnResume.OnHover = MainScreen_ResumeHover;
s->btnResume.OnUnhover = MainScreen_ResumeUnhover;
if (CheckUpdateTask.Base.completed)
MainScreen_ApplyUpdateLabel(s);
}
static void MainScreen_Load(struct LScreen* s_) {
@ -844,39 +878,12 @@ static void MainScreen_Load(struct LScreen* s_) {
MainScreen_DoLogin();
}
CC_NOINLINE static cc_uint32 MainScreen_GetVersion(const cc_string* version) {
cc_uint8 raw[4] = { 0, 0, 0, 0 };
cc_string parts[4];
int i, count;
/* 1.0.1 -> { 1, 0, 1, 0 } */
count = String_UNSAFE_Split(version, '.', parts, 4);
for (i = 0; i < count; i++)
{
Convert_ParseUInt8(&parts[i], &raw[i]);
}
return Stream_GetU32_BE(raw);
}
static void MainScreen_TickCheckUpdates(struct MainScreen* s) {
static const cc_string currentStr = String_FromConst(GAME_APP_VER);
cc_uint32 latest, current;
if (!CheckUpdateTask.Base.working) return;
LWebTask_Tick(&CheckUpdateTask.Base, NULL);
if (!CheckUpdateTask.Base.completed) return;
if (CheckUpdateTask.Base.success) {
latest = MainScreen_GetVersion(&CheckUpdateTask.latestRelease);
current = MainScreen_GetVersion(&currentStr);
#ifdef CC_BUILD_FLATPAK
LLabel_SetConst(&s->lblUpdate, latest > current ? "&aUpdate available" : "&eUp to date");
#else
LLabel_SetConst(&s->lblUpdate, latest > current ? "&aNew release" : "&eUp to date");
#endif
} else {
LLabel_SetConst(&s->lblUpdate, "&cCheck failed");
}
if (!CheckUpdateTask.Base.completed) return;
MainScreen_ApplyUpdateLabel(s);
}
static void MainScreen_LoginPhase2(struct MainScreen* s, const cc_string* user) {
@ -1027,9 +1034,12 @@ static void CheckResourcesScreen_Activated(struct LScreen* s_) {
LLabel_SetText(&s->lblStatus, &str);
}
#define RESOURCES_FORE_COLOR BitmapColor_RGB(120, 85, 151)
static void CheckResourcesScreen_ResetArea(struct Context2D* ctx, int x, int y, int width, int height) {
Gradient_Noise(ctx, RESOURCES_FORE_COLOR, 4, x, y, width, height);
int R = BitmapCol_R(Launcher_Theme.BackgroundColor) * 0.78f; /* 153 -> 120 */
int G = BitmapCol_G(Launcher_Theme.BackgroundColor) * 0.70f; /* 127 -> 89 */
int B = BitmapCol_B(Launcher_Theme.BackgroundColor) * 0.88f; /* 172 -> 151 */
Gradient_Noise(ctx, BitmapColor_RGB(R, G, B), 4, x, y, width, height);
}
static void CheckResourcesScreen_DrawBackground(struct LScreen* s, struct Context2D* ctx) {