Cleanup P.focused handling

Fixes P.focused never becoming true after logging in with GTK dialogs, also fixes P.focused never becoming true on emscripten because it had accidentally been moved to the curl init code
This commit is contained in:
ROllerozxa 2025-12-28 19:15:23 +01:00
commit 55c32eb8f3
12 changed files with 22 additions and 59 deletions

View file

@ -2510,9 +2510,8 @@ game::render()
{
/* only delay on android */
#ifdef TMS_BACKEND_ANDROID
if (!P.focused) {
if (!P.focused)
SDL_Delay(500);
}
#endif
int ierr;
@ -9961,7 +9960,7 @@ game::handle_input(tms::event *ev, int action)
this->hov_text->active = false;
#endif
P.focused = 1;
P.focused = true;
break;
case TMS_EV_POINTER_UP:

View file

@ -1299,6 +1299,7 @@ tproject_init(void)
P.message = 0;
P.new_version_available = false;
P.curl = 0;
P.focused = true;
tms_infof("tproject_init called");
srand((unsigned)time(0));
@ -2020,18 +2021,3 @@ principia::get_light_normal()
tvec3_normalize(&light);
return light;
}
extern "C" void
P_focus(int focus)
{
P.focused = focus?true:false;
if (focus) sm::resume_all();
else sm::pause_all();
}
extern "C" void
P_add_action(int id, void *data)
{
P.add_action(id, data);
}

View file

@ -1,7 +1,5 @@
#pragma once
#ifdef __cplusplus
#include "misc.hh"
#include <tms/bindings/cpp/cpp.hh>
@ -16,7 +14,6 @@ class menu_play;
class loading_screen;
class settings;
class p_text;
#endif
class pkginfo;
@ -128,15 +125,6 @@ struct register_data {
char password[256];
};
/*
struct user {
char username[255];
bool logged_in;
};
*/
#ifdef __cplusplus
class intermediary : public tms::screen
{
public:
@ -174,7 +162,7 @@ extern class principia
struct action actions[MAX_ACTIONS];
int num_actions;
int focused;
bool focused;
bool loaded;
const char *community_host;
@ -237,9 +225,3 @@ class open_play_data
, is_main_puzzle(_is_main_puzzle)
{ }
};
#else
void P_add_action(int id, void *data);
void P_focus(int focus);
#endif

View file

@ -171,11 +171,8 @@ menu_base::render()
return T_OK;
#endif
if (!P.focused) {
#ifndef TMS_BACKEND_IOS
if (!P.focused)
SDL_Delay(100);
#endif
}
glDisable(GL_BLEND);
glDisable(GL_DEPTH_TEST);

View file

@ -125,7 +125,7 @@ menu_play::handle_input(tms::event *ev, int action)
if (ev->type == TMS_EV_POINTER_DOWN) {
if (!P.focused) {
if (prompt_is_open) return T_OK;
else P.focused = 1;
else P.focused = true;
}
}
#endif

View file

@ -254,7 +254,7 @@ menu_create::handle_input(tms::event *ev, int action)
if (ev->type == TMS_EV_POINTER_DOWN) {
if (!P.focused) {
if (prompt_is_open) return T_OK;
else P.focused = 1;
else P.focused = true;
}
}
#endif

View file

@ -133,7 +133,7 @@ menu_main::handle_input(tms::event *ev, int action)
if (ev->type == TMS_EV_POINTER_DOWN) {
if (!P.focused) {
if (prompt_is_open) return T_OK;
else P.focused = 1;
else P.focused = true;
}
}
#endif

View file

@ -83,8 +83,6 @@ init_curl()
tms_fatalf("Unable to create curl mutex.");
}
P.focused = 1;
tms_infof("Initializing curl (v" LIBCURL_VERSION ")...");
CURLcode r = curl_global_init(CURL_GLOBAL_ALL);
if (r != CURLE_OK) {

View file

@ -126,7 +126,7 @@ void ui::render(){};
#if defined(NO_UI)
int prompt_is_open = 0;
bool prompt_is_open = false;
void ui::init(){};
void ui::open_dialog(int num, void *data/*=0*/){}
void ui::open_sandbox_tips(){};

View file

@ -139,7 +139,7 @@ class ui
#endif
#if defined(TMS_BACKEND_PC) && !defined(NO_UI)
extern int prompt_is_open;
extern bool prompt_is_open;
#endif
extern const char* tips[];

View file

@ -81,7 +81,7 @@ typedef struct {
long time;
} oc_column;
int prompt_is_open = 0;
bool prompt_is_open = false;
GtkDialog *cur_prompt = 0;
enum mark_type {
@ -5796,7 +5796,8 @@ void
on_login_hide(GtkWidget *wdg, void *unused)
{
tms_infof("login hiding");
prompt_is_open = 0;
P.focused = true;
prompt_is_open = false;
}
gboolean
@ -5857,8 +5858,8 @@ activate_gettingstarted(GtkMenuItem *i, gpointer unused)
void
activate_login(GtkMenuItem *i, gpointer unused)
{
prompt_is_open = 1;
P.focused = 0;
prompt_is_open = true;
P.focused = false;
gtk_widget_show_all(GTK_WIDGET(login_window));
}
@ -10137,7 +10138,7 @@ _open_prompt_dialog(gpointer unused)
}
cur_prompt = d;
prompt_is_open = 1;
prompt_is_open = true;
P.focused = false;
@ -10173,7 +10174,7 @@ _open_prompt_dialog(gpointer unused)
}
cur_prompt = 0;
prompt_is_open = 0;
prompt_is_open = false;
return false;
}

View file

@ -2749,20 +2749,20 @@ namespace UiAnimal {
for (int i = 0; i < NUM_ANIMAL_TYPES; ++i) {
if (ImGui::MenuItem(animal_data[i].name)) {
entity* e = G->selection.e;
if (e && e->g_id == O_ANIMAL) {
W->add_action(e->id, ACTION_SET_ANIMAL_TYPE, UINT_TO_VOID((uint32_t)i));
P.add_action(ACTION_HIGHLIGHT_SELECTED, 0);
P.add_action(ACTION_RESELECT, 0);
}
}
}
ImGui::EndPopup();
}
}
}
static void ui_init() {
@ -2800,7 +2800,7 @@ static void ui_layout() {
//*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
#if defined(TMS_BACKEND_PC) && !defined(NO_UI)
int prompt_is_open = 0;
bool prompt_is_open = false;
#endif
static void update_imgui_ui_scale() {