mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-19 12:25:56 +00:00
Quick save and quick load with no menu on the screen
F6 asks the game for its own autosave, as the sequence node OneShotAutoSaveMgrRequestAutoSave does, after the game's own check (its wait between autosaves skipped), from the pad read: the game itself makes that request from several threads. The slot the commit wrote is copied to <profile>/quicksave; a request the game holds back for 5 s is taken back. F7 holds the window on its last picture, runs the game's load list underneath and, from the confirmation until the load is over, opens the quick save's files for every read of a slot folder. A toast at the top of the picture says what happened. The two keys are set on the Controls tab by pressing them. Keyboard and mouse keys only, game 1.4.3. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6151ac4fbc
commit
7bd1c539bd
20 files changed
+863
-20
No files matched your search
@@ -3,6 +3,7 @@
|
||||
// gamepad cells show and change the table of the button layout in use (TOTK_PAD_LAYOUT).
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
|
||||
#include "imgui.h"
|
||||
#include "ui/binds_page.h"
|
||||
@@ -34,16 +35,22 @@ static const int kButtons[] = {B_A, B_B, B_X, B_Y, B_L, B_R, B_ZL, B_ZR, B_STICK
|
||||
static const int kMove[] = {B_SL_UP, B_SL_DOWN, B_SL_LEFT, B_SL_RIGHT};
|
||||
static const int kCamera[] = {B_SR_UP, B_SR_DOWN, B_SR_LEFT, B_SR_RIGHT};
|
||||
|
||||
// A key setting's row (binds_key_row) waits as this action, with the setting and its label beside it
|
||||
enum { ACTION_SETTING = ACTION_COUNT };
|
||||
static struct {
|
||||
int action = -1, cell; // the cell waiting for a press (0, 1 keys, 2 the controller); action -1 none
|
||||
bool reset; // the next capture poll takes what is held as the start
|
||||
uint64_t start, done; // plat_now_ns of the start and of the press, timeout or Esc (0 still waiting)
|
||||
const char *setting; // ACTION_SETTING: the TOTK_ name the key goes to
|
||||
UiTextId label; // and its row's label
|
||||
} g_cap;
|
||||
static char g_note[160]; // what the last change took or swapped, after its row's description
|
||||
static int g_note_action = -1;
|
||||
static uint64_t g_note_until;
|
||||
|
||||
static const char *action_label(int a) { return menu_text((UiTextId)(UI_BIND_A + a)); }
|
||||
static const char *action_label(int a) {
|
||||
return a == ACTION_SETTING ? menu_text(g_cap.label) : menu_text((UiTextId)(UI_BIND_A + a));
|
||||
}
|
||||
|
||||
static UiTextId action_desc(int a) {
|
||||
if (a <= B_MINUS) return (UiTextId)(UI_BIND_DESC_A + a);
|
||||
@@ -196,7 +203,11 @@ static void capture_window(void) {
|
||||
if (!g_cap.done) {
|
||||
int id = 0, got = input_capture(g_cap.reset, &id);
|
||||
g_cap.reset = false;
|
||||
if (got == INPUT_CAPTURE_KEY && !pad_cell) change(g_cap.action, g_cap.cell, id);
|
||||
if (got == INPUT_CAPTURE_KEY && g_cap.action == ACTION_SETTING) {
|
||||
cfg_set(g_cap.setting, input_key_name(id));
|
||||
opt_save_soon();
|
||||
rt_log("menu: %s = %s", g_cap.setting + 5, input_key_name(id));
|
||||
} else if (got == INPUT_CAPTURE_KEY && !pad_cell) change(g_cap.action, g_cap.cell, id);
|
||||
if (got == INPUT_CAPTURE_PAD && pad_cell) change(g_cap.action, g_cap.cell, id);
|
||||
if (got != INPUT_CAPTURE_NONE && !(got == INPUT_CAPTURE_KEY && pad_cell)) g_cap.done = now;
|
||||
if (now - g_cap.start > CAPTURE_SECONDS * 1000000000ull) g_cap.done = now;
|
||||
@@ -213,7 +224,8 @@ static void capture_window(void) {
|
||||
if (g_cap.done && now - g_cap.done > kDoneNs) {
|
||||
ImGui::CloseCurrentPopup();
|
||||
char id[48];
|
||||
snprintf(id, sizeof id, "BIND_%s#%d", input_action_name(g_cap.action), g_cap.cell);
|
||||
if (g_cap.action == ACTION_SETTING) snprintf(id, sizeof id, "%s#0", g_cap.setting + 5);
|
||||
else snprintf(id, sizeof id, "BIND_%s#%d", input_action_name(g_cap.action), g_cap.cell);
|
||||
opt_focus_key(id); // back on the cell it came from
|
||||
g_cap.action = -1;
|
||||
}
|
||||
@@ -223,6 +235,29 @@ static void capture_window(void) {
|
||||
|
||||
bool binds_modal(void) { return g_cap.action >= 0; }
|
||||
|
||||
// A key setting (quick save's keys): its key in the first cell, taken by the same capture window as a binding's key;
|
||||
// Delete, Backspace or X sets it to none. The other two cells stay empty (no controller button for it). note: e.g. the
|
||||
// binding that also uses the key.
|
||||
void binds_key_row(const char *setting, UiTextId label, UiTextId desc, const char *note) {
|
||||
const char *cur = cfg_value(setting);
|
||||
int key = KEY_NONE;
|
||||
for (int k = KEY_A; k < KEY_COUNT && key == KEY_NONE; k++)
|
||||
if (input_key_name(k) && !strcasecmp(input_key_name(k), cur)) key = k;
|
||||
char b[48];
|
||||
const char *cells[3] = {key != KEY_NONE ? key_label(key, b, sizeof b) : strcasecmp(cur, "none") ? cur : "", "", ""};
|
||||
const bool enabled[3] = {true, false, false};
|
||||
int r = opt_bind_row(setting + 5, menu_text(label), desc, cells, enabled, note);
|
||||
if (g_cap.action >= 0 || r < 0) return;
|
||||
if (r == 0) {
|
||||
g_cap.action = ACTION_SETTING, g_cap.cell = 0, g_cap.setting = setting, g_cap.label = label;
|
||||
g_cap.reset = true, g_cap.start = plat_now_ns(), g_cap.done = 0;
|
||||
} else if (r == 10) {
|
||||
cfg_set(setting, "none");
|
||||
opt_save_soon();
|
||||
rt_log("menu: %s = none", setting + 5);
|
||||
}
|
||||
}
|
||||
|
||||
static bool g_reset_asked; // the reset row was chosen this frame (acted on after the page)
|
||||
|
||||
void binds_rows(float scale) {
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
// The remapping rows of the menu's Controls tab (ui/binds_page.cpp). Present path only (ImGui).
|
||||
#pragma once
|
||||
|
||||
extern "C" {
|
||||
#include "ui_text.h"
|
||||
}
|
||||
|
||||
// Inside the page's opt_begin / opt_end: every action's two keys and its controller button, remapped by selecting a
|
||||
// cell and pressing the new one, and the reset of them all. binds_after_page, after opt_end: the window that waits for
|
||||
// the press.
|
||||
@@ -8,3 +12,6 @@ void binds_rows(float scale);
|
||||
void binds_after_page(void);
|
||||
// A cell waits for a press (or its press is still reaching the menu): B, Esc, L / R and the tab keys stay on the page.
|
||||
bool binds_modal(void);
|
||||
// A key setting (TOTK_ name) as a row of one key cell, set by pressing the key as a binding's cell is; Delete sets it
|
||||
// to none. note (NULL none) follows the description.
|
||||
void binds_key_row(const char *setting, UiTextId label, UiTextId desc, const char *note);
|
||||
+62
-11
@@ -838,6 +838,21 @@ static int key_action(const InputMap *m, int key) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// "also <action>" when the bindings also use the key the setting names, else NULL; note holds the text
|
||||
static const char *key_taken(const char *setting, char *note, size_t size) {
|
||||
const char *cur = cfg_value(setting);
|
||||
InputMap m;
|
||||
input_map_snapshot(&m);
|
||||
for (int k = KEY_A; k < KEY_COUNT; k++) {
|
||||
if (!input_key_name(k) || strcasecmp(input_key_name(k), cur)) continue;
|
||||
int a = key_action(&m, k);
|
||||
if (a < 0 || !input_action_name(a)) return nullptr;
|
||||
snprintf(note, size, menu_text(UI_MENU_WALK_KEY_TAKEN), input_action_name(a));
|
||||
return note;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// The walk key as the handful of keys a player is likely to pick. "none" rather than an empty value closes it: an
|
||||
// unset key falls back to the default in the settings table, the same as a fresh installation. totk.ini takes any name
|
||||
// input_map.c knows (walks of the keyboard sticks, not of the gamepad). A key the current bindings also use says which
|
||||
@@ -845,18 +860,20 @@ static int key_action(const InputMap *m, int key) {
|
||||
static void row_walk_key(void) {
|
||||
static const char *const keys[] = {"none", "lshift", "lalt", "lctrl", "tab", "capslock"};
|
||||
const char *names[sizeof keys / sizeof *keys] = {menu_text(UI_MENU_OFF), "Shift", "Alt", "Ctrl", "Tab", "Caps Lock"};
|
||||
const char *cur = cfg_value("TOTK_WALK_KEY");
|
||||
static char note[64];
|
||||
const char *n = nullptr;
|
||||
InputMap m;
|
||||
input_map_snapshot(&m);
|
||||
for (int k = KEY_A; k < KEY_COUNT && !n; k++) {
|
||||
if (!input_key_name(k) || strcasecmp(input_key_name(k), cur)) continue;
|
||||
int a = key_action(&m, k);
|
||||
if (a >= 0 && input_action_name(a)) snprintf(note, sizeof note, menu_text(UI_MENU_WALK_KEY_TAKEN), input_action_name(a)), n = note;
|
||||
}
|
||||
opt_choice_list("TOTK_WALK_KEY", UI_MENU_WALK_KEY, keys, names, sizeof keys / sizeof *keys, UI_MENU_WALK_KEY_DESC,
|
||||
-1, n);
|
||||
-1, key_taken("TOTK_WALK_KEY", note, sizeof note));
|
||||
}
|
||||
|
||||
// Quick save's two keys (quicksave.c), F6 and F7 by default as Half-Life has them: any key or mouse button, taken by
|
||||
// the bindings' capture window (binds_key_row); Delete leaves that one without a key. A key the bindings also use says
|
||||
// which action it presses: while quick save is on it no longer does.
|
||||
static void row_quicksave_keys(void) {
|
||||
static char note[2][64];
|
||||
binds_key_row("TOTK_QUICKSAVE_KEY", UI_MENU_QUICKSAVE_KEY, UI_MENU_QUICKSAVE_KEY_DESC,
|
||||
key_taken("TOTK_QUICKSAVE_KEY", note[0], sizeof note[0]));
|
||||
binds_key_row("TOTK_QUICKLOAD_KEY", UI_MENU_QUICKLOAD_KEY, UI_MENU_QUICKSAVE_KEY_DESC,
|
||||
key_taken("TOTK_QUICKLOAD_KEY", note[1], sizeof note[1]));
|
||||
}
|
||||
|
||||
// The note under the prompts. The settings name a folder of prompts (input_prompts_folder: the prompts and the pad
|
||||
@@ -988,6 +1005,8 @@ static void tab_controls(float scale) {
|
||||
opt_toggle("TOTK_MAP_CLICK", UI_MENU_MAP_CLICK, UI_MENU_MAP_CLICK_DESC);
|
||||
opt_toggle("TOTK_DIALOGUE_CLICK", UI_MENU_DIALOGUE_CLICK, UI_MENU_DIALOGUE_CLICK_DESC);
|
||||
opt_toggle("TOTK_POINTER_IMAGE", UI_MENU_POINTER_IMAGE, UI_MENU_POINTER_IMAGE_DESC);
|
||||
opt_toggle("TOTK_QUICKSAVE", UI_MENU_QUICKSAVE, UI_MENU_QUICKSAVE_DESC);
|
||||
row_quicksave_keys();
|
||||
row_walk_key();
|
||||
opt_slider("TOTK_WALK_SCALE", UI_MENU_WALK_SCALE, 0.2f, 0.9f, UI_MENU_WALK_SCALE_DESC, 0.01f, "%.2f");
|
||||
rows_gameplay_tweaks();
|
||||
@@ -1656,6 +1675,37 @@ static void perf_draw(const MenuTarget *t, float scale) {
|
||||
dl->AddText(ImVec2(p.x + pad, p.y + pad), IM_COL32(255, 255, 255, 235), g_perf_text);
|
||||
}
|
||||
|
||||
// ---- a toast: one short line of ui_text at the top centre of the picture, over the game, for a few seconds and fading
|
||||
// out in its last half second (quick save's "Game saved", quicksave.c). Any thread sets it; the overlay draws it.
|
||||
static std::atomic<int> g_toast_text{-1};
|
||||
static std::atomic<uint64_t> g_toast_until{0};
|
||||
extern "C" void menu_toast(int text, int ms) {
|
||||
g_toast_until.store(plat_now_ns() + (uint64_t)(ms > 0 ? ms : 1) * 1000000ull, std::memory_order_relaxed);
|
||||
g_toast_text.store(text, std::memory_order_release);
|
||||
}
|
||||
|
||||
static bool toast_live(void) {
|
||||
return g_toast_text.load(std::memory_order_acquire) >= 0 &&
|
||||
plat_now_ns() < g_toast_until.load(std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
static void toast_draw(const MenuTarget *t, float scale) {
|
||||
int id = g_toast_text.load(std::memory_order_acquire);
|
||||
uint64_t now = plat_now_ns(), until = g_toast_until.load(std::memory_order_relaxed);
|
||||
if (id < 0 || id >= UI_TEXT_COUNT || now >= until) return;
|
||||
double left_ms = (until - now) / 1e6;
|
||||
float a = left_ms < 500 ? (float)(left_ms / 500) : 1.0f;
|
||||
const char *text = ui_text((UiTextId)id);
|
||||
ImDrawList *dl = ImGui::GetForegroundDrawList();
|
||||
ImFont *font = ImGui::GetFont();
|
||||
float size = ImGui::GetFontSize() * 1.25f, pad = 10 * scale;
|
||||
ImVec2 sz = font->CalcTextSizeA(size, FLT_MAX, 0, text);
|
||||
ImVec2 p((t->width - sz.x) / 2 - pad, 48 * scale); // under the top edge, between the hearts and the corner
|
||||
ImVec2 q(p.x + sz.x + 2 * pad, p.y + sz.y + 2 * pad);
|
||||
dl->AddRectFilled(p, q, IM_COL32(0, 0, 0, (int)(160 * a)), 6 * scale);
|
||||
dl->AddText(font, size, ImVec2(p.x + pad, p.y + pad), IM_COL32(255, 255, 255, (int)(240 * a)), text);
|
||||
}
|
||||
|
||||
extern "C" int menu_overlay_frame(uint64_t frame, const MenuTarget *t, const char **shot) {
|
||||
*shot = NULL;
|
||||
cheats_frame(frame); // the data cheats and the buttons of the cheats that need them held
|
||||
@@ -1673,7 +1723,7 @@ extern "C" int menu_overlay_frame(uint64_t frame, const MenuTarget *t, const cha
|
||||
g_tab_request = 0;
|
||||
set_open(1);
|
||||
open = true;
|
||||
} else if (!g_perf_mode) {
|
||||
} else if (!g_perf_mode && !toast_live()) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1725,6 +1775,7 @@ extern "C" int menu_overlay_frame(uint64_t frame, const MenuTarget *t, const cha
|
||||
ImGui::NewFrame();
|
||||
if (open) layout_menu(t->width, t->height, scale);
|
||||
perf_draw(t, scale);
|
||||
toast_draw(t, scale);
|
||||
ImGui::Render();
|
||||
if (open) g_save_pending = opt_save_tick(0);
|
||||
g_cost_ns += plat_now_ns() - t0;
|
||||
|
||||
@@ -26,6 +26,7 @@ extern "C" {
|
||||
int menu_is_open(void);
|
||||
void menu_toggle(void); // F1 / Esc on the keyboard, Minus+Plus on the pad
|
||||
void menu_perf_cycle(void); // F10: the performance overlay off, fps, full
|
||||
void menu_toast(int text, int ms); // a short line (a UiTextId) at the top of the picture for ms, any thread
|
||||
|
||||
// ---- events from the window adapter, used only while the menu is open. key: an ImGuiKey; coordinates in pixels of the
|
||||
// window's client area, which is the swapchain image.
|
||||
|
||||
Reference in new issue
Block a user