Author: cazfi
Date: Mon Jul 25 22:04:43 2016
New Revision: 33325

URL: http://svn.gna.org/viewcvs/freeciv?rev=33325&view=rev
Log:
Added client option for message window to show messages from the previous turn 
too.

See patch #7498

Modified:
    trunk/client/client_main.c
    trunk/client/climisc.c
    trunk/client/gui-sdl2/chatline.c
    trunk/client/messagewin_common.c
    trunk/client/messagewin_common.h
    trunk/client/options.c
    trunk/client/options.h
    trunk/client/packhand.c

Modified: trunk/client/client_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/client_main.c?rev=33325&r1=33324&r2=33325&view=diff
==============================================================================
--- trunk/client/client_main.c  (original)
+++ trunk/client/client_main.c  Mon Jul 25 22:04:43 2016
@@ -861,7 +861,7 @@
     popdown_all_city_dialogs();
     close_all_diplomacy_dialogs();
     popdown_all_game_dialogs();
-    meswin_clear();
+    meswin_clear_older(MESWIN_CLEAR_ALL, 0);
 
     if (oldstate > C_S_DISCONNECTED) {
       unit_focus_set(NULL);
@@ -882,7 +882,7 @@
     popdown_all_city_dialogs();
     close_all_diplomacy_dialogs();
     popdown_all_game_dialogs();
-    meswin_clear();
+    meswin_clear_older(MESWIN_CLEAR_ALL, 0);
 
     if (oldstate < C_S_PREPARING) {
       client_game_init();

Modified: trunk/client/climisc.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/climisc.c?rev=33325&r1=33324&r2=33325&view=diff
==============================================================================
--- trunk/client/climisc.c      (original)
+++ trunk/client/climisc.c      Mon Jul 25 22:04:43 2016
@@ -1039,7 +1039,7 @@
   if (BOOL_VAL(where & MW_MESSAGES)) {
     /* When the game isn't running, the messages dialog isn't present. */
     if (C_S_RUNNING <= client_state()) {
-      meswin_add(plain_text, tags, ptile, event);
+      meswin_add(plain_text, tags, ptile, event, turn, phase);
       shown = TRUE;
     } else {
       /* Force to chatline instead. */

Modified: trunk/client/gui-sdl2/chatline.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl2/chatline.c?rev=33325&r1=33324&r2=33325&view=diff
==============================================================================
--- trunk/client/gui-sdl2/chatline.c    (original)
+++ trunk/client/gui-sdl2/chatline.c    Mon Jul 25 22:04:43 2016
@@ -398,7 +398,8 @@
 
     add_to_chat_list(buffer, n);
   } else {
-    meswin_add(astring, tags, NULL, E_CHAT_MSG);
+    meswin_add(astring, tags, NULL, E_CHAT_MSG,
+               game.info.turn, game.info.phase);
   }
 }
 

Modified: trunk/client/messagewin_common.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/messagewin_common.c?rev=33325&r1=33324&r2=33325&view=diff
==============================================================================
--- trunk/client/messagewin_common.c    (original)
+++ trunk/client/messagewin_common.c    Mon Jul 25 22:04:43 2016
@@ -37,7 +37,7 @@
 
 #include "messagewin_common.h"
 
-static struct message *messages = NULL;
+static struct message **messages = NULL;
 static int messages_total = 0;
 static int messages_alloc = 0;
 
@@ -62,18 +62,35 @@
 /****************************************************************************
   Clear all messages.
 ****************************************************************************/
-void meswin_clear(void)
+void meswin_clear_older(int turn, int phase)
 {
   int i;
-
-  for (i = 0; i < messages_total; i++) {
-    free(messages[i].descr);
-    messages[i].descr = NULL;
-
-    text_tag_list_destroy(messages[i].tags);
-    messages[i].tags = NULL;
-  }
-  messages_total = 0;
+  int j = 0;
+
+  if (!gui_options.show_previous_turn_messages) {
+    turn = MESWIN_CLEAR_ALL;
+  }
+
+  for (i = 0;
+       i < messages_total
+       && (turn < 0
+           || (messages[i]->turn < turn
+               || (messages[i]->turn == turn && messages[i]->phase < phase))) 
; i++) {
+    free(messages[i]->descr);
+
+    text_tag_list_destroy(messages[i]->tags);
+    free(messages[i]);
+    messages[i] = NULL;
+  }
+
+  if (i != 0) {
+    for (; i < messages_total; i++, j++) {
+      messages[j] = messages[i];
+      messages[i] = NULL;
+    }
+    messages_total = j;
+  }
+
   meswin_dialog_update();
 }
 
@@ -81,18 +98,21 @@
   Add a message.
 ****************************************************************************/
 void meswin_add(const char *message, const struct text_tag_list *tags,
-                struct tile *ptile, enum event_type event)
+                struct tile *ptile, enum event_type event,
+                int turn, int phase)
 {
   const size_t min_msg_len = 50;
   size_t msg_len = strlen(message);
   char *s = fc_malloc(MAX(msg_len, min_msg_len) + 1);
   int i, nspc;
+  struct message *msg;
 
   if (messages_total + 2 > messages_alloc) {
     messages_alloc = messages_total + 32;
-    messages = fc_realloc(messages, messages_alloc * sizeof(*messages));
-  }
-
+    messages = fc_realloc(messages, messages_alloc * sizeof(struct message *));
+  }
+
+  msg = fc_malloc(sizeof(struct message));
   strcpy(s, message);
 
   nspc = min_msg_len - strlen(s);
@@ -100,26 +120,28 @@
     strncat(s, "                                                  ", nspc);
   }
 
-  messages[messages_total].tile = ptile;
-  messages[messages_total].event = event;
-  messages[messages_total].descr = s;
-  messages[messages_total].tags = text_tag_list_copy(tags);
-  messages[messages_total].location_ok = (ptile != NULL);
-  messages[messages_total].visited = FALSE;
-  messages_total++;
+  msg->tile = ptile;
+  msg->event = event;
+  msg->descr = s;
+  msg->tags = text_tag_list_copy(tags);
+  msg->location_ok = (ptile != NULL);
+  msg->visited = FALSE;
+  msg->turn = turn;
+  msg->phase = phase;
+  messages[messages_total++] = msg;
 
   /* Update the city_ok fields of all messages since the city may have
    * changed owner. */
   for (i = 0; i < messages_total; i++) {
-    if (messages[i].location_ok) {
-      struct city *pcity = tile_city(messages[i].tile);
-
-      messages[i].city_ok =
+    if (messages[i]->location_ok) {
+      struct city *pcity = tile_city(messages[i]->tile);
+
+      messages[i]->city_ok =
           (pcity
            && (!client_has_player()
                || can_player_see_city_internals(client_player(), pcity)));
     } else {
-      messages[i].city_ok = FALSE;
+      messages[i]->city_ok = FALSE;
     }
   }
 
@@ -132,7 +154,7 @@
 const struct message *meswin_get_message(int message_index)
 {
   if (message_index >= 0 && message_index < messages_total) {
-    return &messages[message_index];
+    return messages[message_index];
   } else {
     /* Can happen in turn change... */
     return NULL;
@@ -154,7 +176,7 @@
 {
   fc_assert_ret(0 <= message_index && message_index < messages_total);
 
-  messages[message_index].visited = state;
+  messages[message_index]->visited = state;
 }
 
 /****************************************************************************
@@ -164,8 +186,8 @@
 {
   fc_assert_ret(0 <= message_index && message_index < messages_total);
 
-  if (messages[message_index].city_ok) {
-    struct tile *ptile = messages[message_index].tile;
+  if (messages[message_index]->city_ok) {
+    struct tile *ptile = messages[message_index]->tile;
     struct city *pcity = tile_city(ptile);
 
     if (gui_options.center_when_popup_city) {
@@ -192,8 +214,8 @@
 {
   fc_assert_ret(0 <= message_index && message_index < messages_total);
 
-  if (messages[message_index].location_ok) {
-    center_tile_mapcanvas(messages[message_index].tile);
+  if (messages[message_index]->location_ok) {
+    center_tile_mapcanvas(messages[message_index]->tile);
   }
 }
 
@@ -204,10 +226,10 @@
 {
   fc_assert_ret(0 <= message_index && message_index < messages_total);
 
-  if (messages[message_index].city_ok
-      && is_city_event(messages[message_index].event)) {
+  if (messages[message_index]->city_ok
+      && is_city_event(messages[message_index]->event)) {
     meswin_popup_city(message_index);
-  } else if (messages[message_index].location_ok) {
+  } else if (messages[message_index]->location_ok) {
     meswin_goto(message_index);
   }
 }

Modified: trunk/client/messagewin_common.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/messagewin_common.h?rev=33325&r1=33324&r2=33325&view=diff
==============================================================================
--- trunk/client/messagewin_common.h    (original)
+++ trunk/client/messagewin_common.h    Mon Jul 25 22:04:43 2016
@@ -1,4 +1,4 @@
-/**********************************************************************
+/***********************************************************************
  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
@@ -31,12 +31,19 @@
   struct text_tag_list *tags;
   struct tile *tile;
   enum event_type event;
-  bool location_ok, city_ok, visited;
+  bool location_ok;
+  bool city_ok;
+  bool visited;
+  int turn;
+  int phase;
 };
 
-void meswin_clear(void);
+#define MESWIN_CLEAR_ALL (-1)
+
+void meswin_clear_older(int turn, int phase);
 void meswin_add(const char *message, const struct text_tag_list *tags,
-                       struct tile *ptile, enum event_type event);
+                struct tile *ptile, enum event_type event,
+                int turn, int phase);
 
 const struct message *meswin_get_message(int message_index);
 int meswin_get_num_messages(void);

Modified: trunk/client/options.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/options.c?rev=33325&r1=33324&r2=33325&view=diff
==============================================================================
--- trunk/client/options.c      (original)
+++ trunk/client/options.c      Mon Jul 25 22:04:43 2016
@@ -114,6 +114,7 @@
   .wakeup_focus = TRUE,
   .goto_into_unknown = TRUE,
   .center_when_popup_city = TRUE,
+  .show_previous_turn_messages = TRUE,
   .concise_city_production = FALSE,
   .auto_turn_done = FALSE,
   .meta_accelerators = TRUE,
@@ -2172,6 +2173,11 @@
                   N_("Setting this option makes the mapview center on a "
                      "city when its city dialog is popped up."),
                   COC_INTERFACE, GUI_STUB, TRUE, NULL),
+  GEN_BOOL_OPTION(show_previous_turn_messages, N_("Show messages from previous 
turn"),
+                  N_("Message Window shows messages also from previous turn. "
+                     "This makes sure you don't miss messages received in the 
end of "
+                     "the turn, just before the window gets cleared."),
+                  COC_INTERFACE, GUI_STUB, TRUE, NULL),
   GEN_BOOL_OPTION(concise_city_production, N_("Concise city production"),
                   N_("Set this option to make the city production (as shown "
                      "in the city dialog) to be more compact."),

Modified: trunk/client/options.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/options.h?rev=33325&r1=33324&r2=33325&view=diff
==============================================================================
--- trunk/client/options.h      (original)
+++ trunk/client/options.h      Mon Jul 25 22:04:43 2016
@@ -135,6 +135,7 @@
   bool wakeup_focus;
   bool goto_into_unknown;
   bool center_when_popup_city;
+  bool show_previous_turn_messages;
   bool concise_city_production;
   bool auto_turn_done;
   bool meta_accelerators;

Modified: trunk/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/packhand.c?rev=33325&r1=33324&r2=33325&view=diff
==============================================================================
--- trunk/client/packhand.c     (original)
+++ trunk/client/packhand.c     Mon Jul 25 22:04:43 2016
@@ -1261,7 +1261,7 @@
 {
   /* Messagewindow will contain events happened since our own phase ended,
    * so player of the first phase and last phase are in equal situation. */
-  meswin_clear();
+  meswin_clear_older(game.info.turn, game.info.phase);
 }
 
 /**************************************************************************


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to