From 957243be9ba5f485013afa967b2be16bc637ebdb Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sun, 3 Nov 2024 13:13:20 +0200
Subject: [PATCH 57/57] Add 'animations' gui property

- Add new gui_properties module
- Have only gtk4-client and gtk4x-client to have 'animations' property
- Draw animations other than focus unit selection only if gui has 'animations' property

See RM #1057

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 client/Makefile.am             |  2 ++
 client/client_main.c           |  3 +++
 client/gui-gtk-3.22/gui_main.c |  9 ++++++++
 client/gui-gtk-4.0/gui_main.c  |  9 ++++++++
 client/gui-gtk-5.0/gui_main.c  |  9 ++++++++
 client/gui-qt/gui_main.cpp     |  9 ++++++++
 client/gui-qt/qtg_cxxside.cpp  |  2 ++
 client/gui-qt/qtg_cxxside.h    |  2 ++
 client/gui-sdl2/gui_main.c     |  9 ++++++++
 client/gui-sdl3/gui_main.c     |  9 ++++++++
 client/gui-stub/gui_main.c     |  8 +++++++
 client/gui_cbsetter.c          |  2 ++
 client/gui_interface.c         |  8 +++++++
 client/gui_interface.h         |  2 ++
 client/gui_properties.c        | 38 ++++++++++++++++++++++++++++++++++
 client/gui_properties.h        | 32 ++++++++++++++++++++++++++++
 client/include/gui_main_g.h    |  4 +++-
 client/tilespec.c              | 10 +++++++++
 meson.build                    |  1 +
 19 files changed, 167 insertions(+), 1 deletion(-)
 create mode 100644 client/gui_properties.c
 create mode 100644 client/gui_properties.h

diff --git a/client/Makefile.am b/client/Makefile.am
index ee9c3d02f9..6c4c9d7f94 100644
--- a/client/Makefile.am
+++ b/client/Makefile.am
@@ -105,6 +105,8 @@ freeciv_client_src = $(AUDIO_SDL_FILES) \
 	global_worklist.h	\
 	goto.c		\
 	goto.h		\
+	gui_properties.c	\
+	gui_properties.h	\
 	luaconsole_common.c	\
 	luaconsole_common.h	\
 	mapctrl_common.c \
diff --git a/client/client_main.c b/client/client_main.c
index 0a75ba18e2..aec4b2179b 100644
--- a/client/client_main.c
+++ b/client/client_main.c
@@ -89,6 +89,7 @@
 #include "control.h" 
 #include "editor.h"
 #include "global_worklist.h"
+#include "gui_properties.h"
 #include "helpdata.h"           /* boot_help_texts() */
 #include "mapview_common.h"
 #include "music.h"
@@ -402,6 +403,8 @@ int client_main(int argc, char *argv[], bool postpone_tileset)
   bind_textdomain_codeset("freeciv-nations", get_internal_encoding());
 #endif
 
+  gui_properties_init();
+
   i = 1;
 
   announce = ANNOUNCE_DEFAULT;
diff --git a/client/gui-gtk-3.22/gui_main.c b/client/gui-gtk-3.22/gui_main.c
index de1b95a817..a7a2df3710 100644
--- a/client/gui-gtk-3.22/gui_main.c
+++ b/client/gui-gtk-3.22/gui_main.c
@@ -69,6 +69,7 @@
 #include "connectdlg_common.h"
 #include "control.h"
 #include "editor.h"
+#include "gui_properties.h"
 #include "options.h"
 #include "text.h"
 #include "tilespec.h"
@@ -2665,3 +2666,11 @@ static void adjust_default_options(void)
     }
   }
 }
+
+/**********************************************************************//**
+  Define properties of this gui.
+**************************************************************************/
+void setup_gui_properties(void)
+{
+  gui_properties.animations = FALSE;
+}
diff --git a/client/gui-gtk-4.0/gui_main.c b/client/gui-gtk-4.0/gui_main.c
index f30c70b66e..87bc70c8ed 100644
--- a/client/gui-gtk-4.0/gui_main.c
+++ b/client/gui-gtk-4.0/gui_main.c
@@ -69,6 +69,7 @@
 #include "connectdlg_common.h"
 #include "control.h"
 #include "editor.h"
+#include "gui_properties.h"
 #include "options.h"
 #include "text.h"
 #include "tilespec.h"
@@ -2683,3 +2684,11 @@ GtkApplication *gui_app(void)
 {
   return fc_app;
 }
+
+/**********************************************************************//**
+  Define properties of this gui.
+**************************************************************************/
+void setup_gui_properties(void)
+{
+  gui_properties.animations = TRUE;
+}
diff --git a/client/gui-gtk-5.0/gui_main.c b/client/gui-gtk-5.0/gui_main.c
index 5fb20f7f90..4684b04970 100644
--- a/client/gui-gtk-5.0/gui_main.c
+++ b/client/gui-gtk-5.0/gui_main.c
@@ -69,6 +69,7 @@
 #include "connectdlg_common.h"
 #include "control.h"
 #include "editor.h"
+#include "gui_properties.h"
 #include "options.h"
 #include "text.h"
 #include "tilespec.h"
@@ -2736,3 +2737,11 @@ GtkApplication *gui_app(void)
 {
   return fc_app;
 }
+
+/**********************************************************************//**
+  Define properties of this gui.
+**************************************************************************/
+void setup_gui_properties(void)
+{
+  gui_properties.animations = TRUE;
+}
diff --git a/client/gui-qt/gui_main.cpp b/client/gui-qt/gui_main.cpp
index 34a3dc44b0..3771f5eff3 100644
--- a/client/gui-qt/gui_main.cpp
+++ b/client/gui-qt/gui_main.cpp
@@ -44,6 +44,7 @@
 // client
 #include "client_main.h"
 #include "editgui_g.h"
+#include "gui_properties.h"
 #include "options.h"
 #include "sprite.h"
 #include "svgflag.h"
@@ -598,3 +599,11 @@ void qtg_insert_client_build_info(char *outbuf, size_t outlen)
   cat_snprintf(outbuf, outlen, _("\nBuilt in Qt6 mode."));
 #endif // FC_QT5_MODE
 }
+
+/**********************************************************************//**
+  Define properties of this gui.
+**************************************************************************/
+void qtg_setup_gui_properties()
+{
+  gui_properties.animations = FALSE;
+}
diff --git a/client/gui-qt/qtg_cxxside.cpp b/client/gui-qt/qtg_cxxside.cpp
index 058b879da7..acaa32e976 100644
--- a/client/gui-qt/qtg_cxxside.cpp
+++ b/client/gui-qt/qtg_cxxside.cpp
@@ -138,4 +138,6 @@ void setup_gui_funcs()
   funcs->endgame_report_dialog_player = qtg_endgame_report_dialog_player;
 
   funcs->popup_image = qtg_popup_image;
+
+  funcs->setup_gui_properties = qtg_setup_gui_properties;
 }
diff --git a/client/gui-qt/qtg_cxxside.h b/client/gui-qt/qtg_cxxside.h
index 46c1676c83..be22b65f23 100644
--- a/client/gui-qt/qtg_cxxside.h
+++ b/client/gui-qt/qtg_cxxside.h
@@ -168,4 +168,6 @@ void qtg_endgame_report_dialog_player(const struct packet_endgame_player *packet
 
 void qtg_popup_image(const char *tag);
 
+void qtg_setup_gui_properties();
+
 #endif // FC__QTG_CXXSIDE_H
diff --git a/client/gui-sdl2/gui_main.c b/client/gui-sdl2/gui_main.c
index 33308b8d9b..e8df07861f 100644
--- a/client/gui-sdl2/gui_main.c
+++ b/client/gui-sdl2/gui_main.c
@@ -61,6 +61,7 @@
 #include "climisc.h"
 #include "clinet.h"
 #include "editgui_g.h"
+#include "gui_properties.h"
 #include "spaceshipdlg_g.h"
 #include "tilespec.h"
 #include "update_queue.h"
@@ -1346,3 +1347,11 @@ bool flush_event(void)
 {
   return SDL_PushEvent(flush_user_event) >= 0;
 }
+
+/**********************************************************************//**
+  Define properties of this gui.
+**************************************************************************/
+void setup_gui_properties(void)
+{
+  gui_properties.animations = FALSE;
+}
diff --git a/client/gui-sdl3/gui_main.c b/client/gui-sdl3/gui_main.c
index e4a83330b7..f79247bd6e 100644
--- a/client/gui-sdl3/gui_main.c
+++ b/client/gui-sdl3/gui_main.c
@@ -57,6 +57,7 @@
 #include "climisc.h"
 #include "clinet.h"
 #include "editgui_g.h"
+#include "gui_properties.h"
 #include "spaceshipdlg_g.h"
 #include "tilespec.h"
 #include "update_queue.h"
@@ -1348,3 +1349,11 @@ bool flush_event(void)
 {
   return SDL_PushEvent(flush_user_event);
 }
+
+/**********************************************************************//**
+  Define properties of this gui.
+**************************************************************************/
+void setup_gui_properties(void)
+{
+  gui_properties.animations = FALSE;
+}
diff --git a/client/gui-stub/gui_main.c b/client/gui-stub/gui_main.c
index 3593e2fde1..ebfdb64015 100644
--- a/client/gui-stub/gui_main.c
+++ b/client/gui-stub/gui_main.c
@@ -278,3 +278,11 @@ void gui_insert_client_build_info(char *outbuf, size_t outlen)
 {
   /* PORTME */
 }
+
+/**********************************************************************//**
+  Define properties of this gui.
+**************************************************************************/
+void gui_setup_gui_properties(void)
+{
+  /* PORTME */
+}
diff --git a/client/gui_cbsetter.c b/client/gui_cbsetter.c
index 201cbbe95f..6c633ca53e 100644
--- a/client/gui_cbsetter.c
+++ b/client/gui_cbsetter.c
@@ -126,4 +126,6 @@ void setup_gui_funcs(void)
   funcs->get_usable_themes_in_directory = gui_get_usable_themes_in_directory;
 
   funcs->popup_image = gui_popup_image;
+
+  funcs->setup_gui_properties = gui_setup_gui_properties;
 }
diff --git a/client/gui_interface.c b/client/gui_interface.c
index 569aac1554..cdbaa25bc2 100644
--- a/client/gui_interface.c
+++ b/client/gui_interface.c
@@ -774,3 +774,11 @@ void popup_image(const char *tag)
 {
   funcs.popup_image(tag);
 }
+
+/**********************************************************************//**
+  Call setup_gui_properties callback
+**************************************************************************/
+void setup_gui_properties(void)
+{
+  funcs.setup_gui_properties();
+}
diff --git a/client/gui_interface.h b/client/gui_interface.h
index afb60e36b4..f7277555aa 100644
--- a/client/gui_interface.h
+++ b/client/gui_interface.h
@@ -175,6 +175,8 @@ struct gui_funcs {
   void (*endgame_report_dialog_player)(const struct packet_endgame_player *packet);
 
   void (*popup_image)(const char *tag);
+
+  void (*setup_gui_properties)(void);
 };
 
 struct gui_funcs *get_gui_funcs(void);
diff --git a/client/gui_properties.c b/client/gui_properties.c
new file mode 100644
index 0000000000..f2df67c614
--- /dev/null
+++ b/client/gui_properties.c
@@ -0,0 +1,38 @@
+/***********************************************************************
+ Freeciv - Copyright (C) 2005 - The Freeciv Team
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <fc_config.h>
+#endif
+
+#include <string.h>
+
+/* utility */
+#include "support.h"
+
+/* client/include */
+#include "gui_main_g.h"
+
+#include "gui_properties.h"
+
+struct client_properties gui_properties;
+
+/**********************************************************************//**
+  Initialize gui_properties
+**************************************************************************/
+void gui_properties_init(void)
+{
+  memset(&gui_properties, 0, sizeof(struct client_properties));
+
+  setup_gui_properties();
+}
diff --git a/client/gui_properties.h b/client/gui_properties.h
new file mode 100644
index 0000000000..836ca7dd07
--- /dev/null
+++ b/client/gui_properties.h
@@ -0,0 +1,32 @@
+/***********************************************************************
+ Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+#ifndef FC__GUI_PROPERTIES_H
+#define FC__GUI_PROPERTIES_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+struct client_properties {
+  bool animations;
+};
+
+extern struct client_properties gui_properties;
+
+void gui_properties_init(void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* FC__GUI_PROPERTIES_H */
diff --git a/client/include/gui_main_g.h b/client/include/gui_main_g.h
index dae1419838..f4d153a88e 100644
--- a/client/include/gui_main_g.h
+++ b/client/include/gui_main_g.h
@@ -43,9 +43,11 @@ GUI_FUNC_PROTO(void, insert_client_build_info, char *outbuf, size_t outlen)
 GUI_FUNC_PROTO(void, gui_update_font, const char *font_name,
                const char *font_value)
 
+GUI_FUNC_PROTO(void, setup_gui_properties, void);
+
 extern const char *client_string;
 
 /* Actually defined in update_queue.c */
 void conn_list_dialog_update(void);
 
-#endif  /* FC__GUI_MAIN_G_H */
+#endif /* FC__GUI_MAIN_G_H */
diff --git a/client/tilespec.c b/client/tilespec.c
index c82923dd03..db060db88e 100644
--- a/client/tilespec.c
+++ b/client/tilespec.c
@@ -71,6 +71,7 @@
 #include "control.h"            /* For fill_xxx */
 #include "editor.h"
 #include "goto.h"
+#include "gui_properties.h"
 #include "helpdata.h"
 #include "options.h"            /* For fill_xxx */
 #include "svgflag.h"
@@ -169,6 +170,7 @@ struct anim {
   int time;
   int time_per_frame;
   struct sprite **sprites;
+  bool show_always;
 };
 
 struct drawing_data {
@@ -2740,6 +2742,7 @@ static struct anim *anim_new(int frames, int time_per_frame)
   ret->time = 0;
   ret->time_per_frame = time_per_frame;
   ret->sprites = fc_malloc(frames * sizeof(struct sprite *));
+  ret->show_always = FALSE;
 
   return ret;
 }
@@ -3006,6 +3009,10 @@ static void anim_advance_time(struct anim *a)
 ****************************************************************************/
 static struct sprite *anim_get_current_frame(struct anim *a)
 {
+  if (!gui_properties.animations && !a->show_always) {
+    return a->sprites[0];
+  }
+
   return a->sprites[(a->time / a->time_per_frame) % a->frames];
 }
 
@@ -3422,6 +3429,9 @@ static void tileset_lookup_sprite_tags(struct tileset *t)
   }
 
   t->sprites.unit.select = anim_load(t, "unit.select", 1);
+  if (t->sprites.unit.select != nullptr) {
+    t->sprites.unit.select->show_always = TRUE;
+  }
 
   SET_SPRITE(citybar.shields, "citybar.shields");
   SET_SPRITE(citybar.food, "citybar.food");
diff --git a/meson.build b/meson.build
index 8c571fc9b2..bb333ac973 100644
--- a/meson.build
+++ b/meson.build
@@ -2188,6 +2188,7 @@ client_common = static_library('fc_client_common',
   'client/editor.c',
   'client/global_worklist.c',
   'client/goto.c',
+  'client/gui_properties.c',
   'client/helpdata.c',
   'client/luaconsole_common.c',
   'client/mapctrl_common.c',
-- 
2.45.2

