Skip to content

Commit fb8cb15

Browse files
committed
Fixing checkboxes and hotkeys not working at all outside of coop. Suppressing full file reload whenever manual goals a checked off. Fixed issue with background texture of stat-categories not updating properly.
1 parent 366362b commit fb8cb15

4 files changed

Lines changed: 54 additions & 23 deletions

File tree

source/global_event_handler.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ void handle_global_events(Tracker *t, Overlay *o, AppSettings *app_settings,
6767
// CUSTOM GOAL HOTKEYS
6868
// Hotkeys don't work when in visual layout editing mode
6969
// Co-op: Receivers with host-only custom goals cannot use counter hotkeys
70-
bool coop_hotkeys_blocked = (app_settings->network_mode == NETWORK_RECEIVER &&
70+
bool rcv_in_lobby = (app_settings->network_mode == NETWORK_RECEIVER &&
71+
g_coop_ctx && coop_net_get_state(g_coop_ctx) == COOP_NET_CONNECTED);
72+
bool coop_hotkeys_blocked = (rcv_in_lobby &&
7173
app_settings->coop_custom_goal_mode == COOP_CUSTOM_HOST_ONLY);
7274
if (t && t->template_data && t->template_data->custom_goals &&
7375
!t->is_visual_layout_editing && !coop_hotkeys_blocked) {
@@ -98,9 +100,8 @@ void handle_global_events(Tracker *t, Overlay *o, AppSettings *app_settings,
98100

99101
if (mod_action >= 0) {
100102
// Co-op Receiver: send modification to host
101-
if (app_settings->network_mode == NETWORK_RECEIVER &&
102-
app_settings->coop_custom_goal_mode == COOP_CUSTOM_ANY_PLAYER &&
103-
g_coop_ctx) {
103+
if (rcv_in_lobby &&
104+
app_settings->coop_custom_goal_mode == COOP_CUSTOM_ANY_PLAYER) {
104105
CoopCustomGoalModMsg mod = {};
105106
snprintf(mod.goal_root_name, sizeof(mod.goal_root_name),
106107
"%s", target_goal->root_name);
@@ -114,6 +115,12 @@ void handle_global_events(Tracker *t, Overlay *o, AppSettings *app_settings,
114115
} else {
115116
target_goal->progress--;
116117
}
118+
// Recalculate done state immediately so the background
119+
// texture updates this frame (not deferred to file re-read)
120+
if (target_goal->goal > 0) {
121+
target_goal->done = (target_goal->progress >= target_goal->goal);
122+
}
123+
SDL_SetAtomicInt(&g_suppress_settings_watch, 1);
117124
settings_save(app_settings, t->template_data, SAVE_CONTEXT_ALL);
118125
SDL_SetAtomicInt(&g_coop_broadcast_needed, 1);
119126
SDL_SetAtomicInt(&g_game_data_changed, 1);

source/global_event_handler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ extern SDL_AtomicInt g_notes_changed; // To signal that the notes.txt file needs
3434
extern SDL_AtomicInt g_apply_button_clicked; // To signal when overlay window should restart (on apply button click)
3535
extern SDL_AtomicInt g_templates_changed; // To signal that the template list needs to be rescanned.
3636
extern SDL_AtomicInt g_coop_broadcast_needed; // Custom goal change: broadcast + IPC without full file re-merge
37+
extern SDL_AtomicInt g_suppress_settings_watch; // Suppress dmon settings watcher for app-initiated saves
3738
extern ForceOpenReason g_force_open_reason; // Flag to force settings open on invalid path
3839

3940
/**

source/main.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,10 @@ static void global_watch_callback(dmon_watch_id watch_id, dmon_action action, co
633633
/**
634634
* @brief Callback for dmon watching the CONFIG directory for settings.json.
635635
*/
636+
// Flag to suppress dmon settings watcher when the app itself writes to settings.json
637+
// (e.g. checkbox toggles, hotkey counters). Prevents a destructive full reinit cycle.
638+
SDL_AtomicInt g_suppress_settings_watch;
639+
636640
static void settings_watch_callback(dmon_watch_id watch_id, dmon_action action, const char *rootdir,
637641
const char *filepath, const char *oldfilepath, void *user) {
638642
(void) watch_id;
@@ -647,6 +651,12 @@ static void settings_watch_callback(dmon_watch_id watch_id, dmon_action action,
647651
log_message(LOG_INFO, "[DEBUG - DMON - MAIN] Settings Watcher triggered by file: %s\n", filepath);
648652
// ----------------
649653
if (strcmp(filepath, "settings.json") == 0) {
654+
// If the app itself wrote settings.json (e.g. checkbox toggle, counter hotkey),
655+
// suppress the watcher to avoid a destructive full template reinit.
656+
if (SDL_SetAtomicInt(&g_suppress_settings_watch, 0) == 1) {
657+
log_message(LOG_INFO, "[DMON - MAIN] settings.json modified by app — suppressed.\n");
658+
return;
659+
}
650660
log_message(LOG_INFO, "[DMON - MAIN] settings.json modified. Triggering update.\n");
651661

652662
SDL_SetAtomicInt(&g_settings_changed, 1);

source/tracker.cpp

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4282,10 +4282,8 @@ void tracker_apply_coop_mods(Tracker *t, const AppSettings *settings,
42824282

42834283
if (mod->action == COOP_MOD_TOGGLE) {
42844284
cat->is_manually_completed = !cat->is_manually_completed;
4285-
bool all_children_done = (cat->criteria_count > 0 &&
4286-
cat->completed_criteria_count >= cat->criteria_count);
4287-
cat->done = cat->is_manually_completed || all_children_done;
42884285

4286+
// Recalculate children FIRST so completed_criteria_count is correct
42894287
for (int j = 0; j < cat->criteria_count; j++) {
42904288
TrackableItem *crit = cat->criteria[j];
42914289
bool crit_naturally_done = (crit->goal > 0 && crit->progress >= crit->goal);
@@ -4295,6 +4293,11 @@ void tracker_apply_coop_mods(Tracker *t, const AppSettings *settings,
42954293
for (int k = 0; k < cat->criteria_count; k++) {
42964294
if (cat->criteria[k]->done) cat->completed_criteria_count++;
42974295
}
4296+
4297+
// Now calculate parent done based on updated children
4298+
bool all_children_done = (cat->criteria_count > 0 &&
4299+
cat->completed_criteria_count >= cat->criteria_count);
4300+
cat->done = cat->is_manually_completed || all_children_done;
42984301
any_applied = true;
42994302
}
43004303
break;
@@ -4331,6 +4334,7 @@ void tracker_apply_coop_mods(Tracker *t, const AppSettings *settings,
43314334
}
43324335

43334336
if (any_applied) {
4337+
SDL_SetAtomicInt(&g_suppress_settings_watch, 1);
43344338
settings_save(settings, td, SAVE_CONTEXT_ALL);
43354339
}
43364340
}
@@ -5958,12 +5962,13 @@ static void render_trackable_category_section(Tracker *t, const AppSettings *set
59585962
// Co-op: Receivers respect stat checkbox permission
59595963
if (is_hovered && ImGui::IsMouseClicked(ImGuiMouseButton_Left) && !t->
59605964
is_visual_layout_editing) {
5961-
if (settings->network_mode == NETWORK_RECEIVER &&
5965+
bool rcv_in_lobby = (settings->network_mode == NETWORK_RECEIVER &&
5966+
g_coop_ctx && coop_net_get_state(g_coop_ctx) == COOP_NET_CONNECTED);
5967+
if (rcv_in_lobby &&
59625968
settings->coop_stat_checkbox == COOP_STAT_CHECKBOX_HOST_ONLY) {
59635969
// Host-only mode: clicking disabled for receivers
5964-
} else if (settings->network_mode == NETWORK_RECEIVER &&
5965-
settings->coop_stat_checkbox == COOP_STAT_CHECKBOX_ANY_PLAYER &&
5966-
g_coop_ctx) {
5970+
} else if (rcv_in_lobby &&
5971+
settings->coop_stat_checkbox == COOP_STAT_CHECKBOX_ANY_PLAYER) {
59675972
// Any-player mode: send toggle request to host
59685973
CoopCustomGoalModMsg mod = {};
59695974
snprintf(mod.goal_root_name, sizeof(mod.goal_root_name), "%s", crit->root_name);
@@ -5985,6 +5990,7 @@ static void render_trackable_category_section(Tracker *t, const AppSettings *set
59855990
criteria_count);
59865991
cat->done = cat->is_manually_completed || all_children_done;
59875992

5993+
SDL_SetAtomicInt(&g_suppress_settings_watch, 1);
59885994
settings_save(settings, t->template_data, SAVE_CONTEXT_ALL);
59895995
SDL_SetAtomicInt(&g_coop_broadcast_needed, 1);
59905996
SDL_SetAtomicInt(&g_game_data_changed, 1);
@@ -6214,12 +6220,13 @@ static void render_trackable_category_section(Tracker *t, const AppSettings *set
62146220
// Co-op: Receivers respect stat checkbox permission
62156221
if (is_hovered_parent && ImGui::IsMouseClicked(ImGuiMouseButton_Left) && !t->
62166222
is_visual_layout_editing) {
6217-
if (settings->network_mode == NETWORK_RECEIVER &&
6223+
bool rcv_in_lobby = (settings->network_mode == NETWORK_RECEIVER &&
6224+
g_coop_ctx && coop_net_get_state(g_coop_ctx) == COOP_NET_CONNECTED);
6225+
if (rcv_in_lobby &&
62186226
settings->coop_stat_checkbox == COOP_STAT_CHECKBOX_HOST_ONLY) {
62196227
// Host-only mode: clicking disabled for receivers
6220-
} else if (settings->network_mode == NETWORK_RECEIVER &&
6221-
settings->coop_stat_checkbox == COOP_STAT_CHECKBOX_ANY_PLAYER &&
6222-
g_coop_ctx) {
6228+
} else if (rcv_in_lobby &&
6229+
settings->coop_stat_checkbox == COOP_STAT_CHECKBOX_ANY_PLAYER) {
62236230
// Any-player mode: send toggle request to host (parent stat)
62246231
CoopCustomGoalModMsg mod = {};
62256232
snprintf(mod.goal_root_name, sizeof(mod.goal_root_name), "%s", cat->root_name);
@@ -6229,10 +6236,8 @@ static void render_trackable_category_section(Tracker *t, const AppSettings *set
62296236
} else {
62306237
// Host or singleplayer: toggle locally
62316238
cat->is_manually_completed = !cat->is_manually_completed;
6232-
bool all_children_naturally_done = (
6233-
cat->criteria_count > 0 && cat->completed_criteria_count >= cat->criteria_count);
6234-
cat->done = cat->is_manually_completed || all_children_naturally_done;
62356239

6240+
// Recalculate children FIRST so completed_criteria_count is correct
62366241
for (int j = 0; j < cat->criteria_count; ++j) {
62376242
TrackableItem *crit = cat->criteria[j];
62386243
bool crit_naturally_done = (crit->goal > 0 && crit->progress >= crit->goal);
@@ -6244,6 +6249,12 @@ static void render_trackable_category_section(Tracker *t, const AppSettings *set
62446249
if (cat->criteria[k]->done) cat->completed_criteria_count++;
62456250
}
62466251

6252+
// Now calculate parent done based on updated children
6253+
bool all_children_done = (
6254+
cat->criteria_count > 0 && cat->completed_criteria_count >= cat->criteria_count);
6255+
cat->done = cat->is_manually_completed || all_children_done;
6256+
6257+
SDL_SetAtomicInt(&g_suppress_settings_watch, 1);
62476258
settings_save(settings, t->template_data, SAVE_CONTEXT_ALL);
62486259
SDL_SetAtomicInt(&g_coop_broadcast_needed, 1);
62496260
SDL_SetAtomicInt(&g_game_data_changed, 1);
@@ -7206,7 +7217,9 @@ static void render_custom_goals_section(Tracker *t, const AppSettings *settings,
72067217
// Deactivating when in visual layout editor mode
72077218
// Co-op: Receivers respect custom goal permission
72087219
// Co-op: Show tooltip for host-only custom goals
7209-
if (is_hovered && settings->network_mode == NETWORK_RECEIVER &&
7220+
bool rcv_in_lobby = (settings->network_mode == NETWORK_RECEIVER &&
7221+
g_coop_ctx && coop_net_get_state(g_coop_ctx) == COOP_NET_CONNECTED);
7222+
if (is_hovered && rcv_in_lobby &&
72107223
settings->coop_custom_goal_mode == COOP_CUSTOM_HOST_ONLY) {
72117224
char tooltip_buf[128];
72127225
snprintf(tooltip_buf, sizeof(tooltip_buf),
@@ -7215,12 +7228,11 @@ static void render_custom_goals_section(Tracker *t, const AppSettings *settings,
72157228
}
72167229

72177230
if (is_hovered && ImGui::IsMouseClicked(ImGuiMouseButton_Left) && !t->is_visual_layout_editing) {
7218-
if (settings->network_mode == NETWORK_RECEIVER &&
7231+
if (rcv_in_lobby &&
72197232
settings->coop_custom_goal_mode == COOP_CUSTOM_HOST_ONLY) {
72207233
// Host-only mode: clicking disabled for receivers
7221-
} else if (settings->network_mode == NETWORK_RECEIVER &&
7222-
settings->coop_custom_goal_mode == COOP_CUSTOM_ANY_PLAYER &&
7223-
g_coop_ctx) {
7234+
} else if (rcv_in_lobby &&
7235+
settings->coop_custom_goal_mode == COOP_CUSTOM_ANY_PLAYER) {
72247236
// Any-player mode: send toggle request to host
72257237
CoopCustomGoalModMsg mod = {};
72267238
snprintf(mod.goal_root_name, sizeof(mod.goal_root_name), "%s", item->root_name);
@@ -7239,6 +7251,7 @@ static void render_custom_goals_section(Tracker *t, const AppSettings *settings,
72397251
item->linked_goal_mode));
72407252
}
72417253
item->progress = item->done ? 1 : 0;
7254+
SDL_SetAtomicInt(&g_suppress_settings_watch, 1);
72427255
settings_save(settings, t->template_data, SAVE_CONTEXT_ALL);
72437256
// Lightweight broadcast path: no full file re-merge needed for custom goals
72447257
SDL_SetAtomicInt(&g_coop_broadcast_needed, 1);

0 commit comments

Comments
 (0)