Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2006:
[Freeciv-Dev] (PR#15559) SDL cient: Not possible to change government
Home

[Freeciv-Dev] (PR#15559) SDL cient: Not possible to change government

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Martin.Gerdes@xxxxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#15559) SDL cient: Not possible to change government
From: "Christian Prochaska" <cp.ml.freeciv.dev@xxxxxxxxxxxxxx>
Date: Tue, 14 Feb 2006 11:42:28 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=15559 >

> [Martin.Gerdes@xxxxxxxxxxxxx - Di 14. Feb 2006, 18:47:39]:
> 
> > Please report it to the bug tracker and I'll try to figure out a way
>    to fix it.
> 
> Alright.
> I have done a revolution ("I wanna revolution"). The following turn,
>    the log tells me "you should choose a new government from the
>    government menu". This "government menu" isn't accessible in any
>    way, if it even exists.
> 
> Proposed solution: Change the "I wanna revolution" button to a
>    different icon (take gimp and put a big "G" on some background -
>    good enough for now!), and make it access this "government menu"
>    for the turn in which the above log message appears.
> Just an idea of course. Anything making changing government possible
>    at all, would be highly welcomed.
> 
> Played with freeciv-HEAD + SDL client.
> 

Here is a patch. You can click the revolution button like before to
start the revolution and when you click the button again you can choose
the new government. You can choose it immediately after starting the
revolution or wait until the log message tells you so. Of course, in the
first case you still have to wait for the end of the revolution before
the government gets changed in the game.
Index: client/gui-sdl/mapview.c
===================================================================
--- client/gui-sdl/mapview.c    (Revision 11583)
+++ client/gui-sdl/mapview.c    (Arbeitskopie)
@@ -296,23 +296,22 @@
              2 * pBuf->size.w + 2, 2 * pBuf->size.h + 2);
 #endif
 
-  if (SDL_Client_Flags & CF_REVOLUTION) {
-    pBuf = get_revolution_widget();
-    set_new_icon2_theme(pBuf, adj_surf(GET_SURF(gov)), FALSE);    
-    
-    if (game.player_ptr) {
+
+  pBuf = get_revolution_widget();
+  set_new_icon2_theme(pBuf, adj_surf(GET_SURF(gov)), FALSE);    
+  
+  if (game.player_ptr) {
     my_snprintf(cBuf, sizeof(cBuf), _("Revolution (Shift + R)\n%s"),
-                               get_gov_pplayer(game.player_ptr)->name);
-    } else {
-      my_snprintf(cBuf, sizeof(cBuf), _("Revolution (Shift + R)\n%s"), "None");
-    }        
-    copy_chars_to_string16(pBuf->string16, cBuf);
-        
-    redraw_widget(pBuf);
-    sdl_dirty_rect(pBuf->size);
-    SDL_Client_Flags &= ~CF_REVOLUTION;
-  }
+                              get_gov_pplayer(game.player_ptr)->name);
+  } else {
+    my_snprintf(cBuf, sizeof(cBuf), _("Revolution (Shift + R)\n%s"), "None");
+  }        
+  copy_chars_to_string16(pBuf->string16, cBuf);
+      
+  redraw_widget(pBuf);
+  sdl_dirty_rect(pBuf->size);
 
+  
   pBuf = get_tax_rates_widget();
   if(!pBuf->theme) {
 #if 0    
@@ -351,9 +350,9 @@
     my_snprintf(cBuf, sizeof(cBuf), _("Research (F6)\n%s (%d/%d)"),
                 "None", 0, 0);
   } else if (get_player_research(game.player_ptr)->researching != A_UNSET) {  
-  my_snprintf(cBuf, sizeof(cBuf), _("Research (F6)\n%s (%d/%d)"),
+    my_snprintf(cBuf, sizeof(cBuf), _("Research (F6)\n%s (%d/%d)"),
                get_tech_name(game.player_ptr,
-                           get_player_research(game.player_ptr)->researching),
+                get_player_research(game.player_ptr)->researching),
                get_player_research(game.player_ptr)->bulbs_researched,
                total_bulbs_required(game.player_ptr));
   } else {
Index: client/gui-sdl/gui_main.c
===================================================================
--- client/gui-sdl/gui_main.c   (Revision 11584)
+++ client/gui-sdl/gui_main.c   (Arbeitskopie)
@@ -1065,7 +1065,6 @@
   net_socket = sock;
   autoconnect = FALSE;
   enable_focus_animation();
-  SDL_Client_Flags |= CF_REVOLUTION; /* force update revolution icon */
 }
 
 /**************************************************************************
Index: client/gui-sdl/gui_main.h
===================================================================
--- client/gui-sdl/gui_main.h   (Revision 11583)
+++ client/gui-sdl/gui_main.h   (Arbeitskopie)
@@ -40,7 +40,7 @@
 #define CF_OPTION_OPEN                 (1<<4)
 #define CF_OPTION_MAIN                 (1<<5)
 #define CF_GANE_JUST_STARTED           (1<<6)
-#define CF_REVOLUTION                  (1<<7)
+
 #define CF_TOGGLED_FULLSCREEN          (1<<8)
 #define CF_FOCUS_ANIMATION             (1<<9)
 #define CF_CHANGED_PROD                        (1<<10)
Index: client/gui-sdl/dialogs.c
===================================================================
--- client/gui-sdl/dialogs.c    (Revision 11583)
+++ client/gui-sdl/dialogs.c    (Arbeitskopie)
@@ -32,6 +32,7 @@
 
 /* common */
 #include "combat.h"
+#include "government.h"
 #include "movement.h"
 #include "unitlist.h"
 
@@ -3432,7 +3433,7 @@
                                   Revolutions
 **************************************************************************/
 static struct SMALL_DLG *pRevolutionDlg = NULL;
-
+  
 /**************************************************************************
   ...
 **************************************************************************/
@@ -3442,8 +3443,6 @@
 
   popdown_revolution_dialog();
   
-  SDL_Client_Flags |= CF_REVOLUTION;
-  
   flush_dirty();
   return (-1);
 }
@@ -3482,6 +3481,141 @@
 /* ==================== Public ========================= */
 
 /**************************************************************************
+                           Sellect Goverment Type
+**************************************************************************/
+static struct SMALL_DLG *pGov_Dlg = NULL;
+
+/**************************************************************************
+  Close the government dialog.
+**************************************************************************/
+static void popdown_government_dialog(void)
+{
+  if(pGov_Dlg) {
+    popdown_window_group_dialog(pGov_Dlg->pBeginWidgetList,
+                                pGov_Dlg->pEndWidgetList);
+    FC_FREE(pGov_Dlg);
+    enable_and_redraw_revolution_button();  
+  }
+}
+
+/**************************************************************************
+  ...
+**************************************************************************/
+static int government_dlg_callback(struct GUI *pGov_Button)
+{
+  set_government_choice(get_government(MAX_ID - pGov_Button->ID));
+  
+  popdown_government_dialog();
+  return (-1);
+}
+
+/**************************************************************************
+  ...
+**************************************************************************/
+static int move_government_dlg_callback(struct GUI *pWindow)
+{
+  return std_move_window_group_callback(pGov_Dlg->pBeginWidgetList, pWindow);
+}
+
+/**************************************************************************
+  Public -
+
+  Popup a dialog asking the player what government to switch to (this
+  happens after a revolution completes).
+**************************************************************************/
+static void popup_government_dialog(void)
+{
+  SDL_Surface *pLogo = NULL;
+  struct SDL_String16 *pStr = NULL;
+  struct GUI *pGov_Button = NULL;
+  struct GUI *pWindow = NULL;
+  struct government *pGov = NULL;
+  int i, j;
+  Uint16 max_w, max_h = 0;
+
+  if (pGov_Dlg) {
+    return;
+  }
+
+  pGov_Dlg = fc_calloc(1, sizeof(struct SMALL_DLG));
+  
+  /* create window */
+  pStr = create_str16_from_char(_("Choose Your New Government"), 12);
+  pStr->style |= TTF_STYLE_BOLD;
+  /* this win. size is temp. */
+  pWindow = create_window(NULL, pStr, 10, 30, 0);
+  pWindow->action = move_government_dlg_callback;
+  pGov_Dlg->pEndWidgetList = pWindow;
+  max_w = pWindow->size.w;
+  add_to_gui_list(ID_GOVERNMENT_DLG_WINDOW, pWindow);
+
+  /* create gov. buttons */
+  j = 0;
+  for (i = 0; i < game.control.government_count; i++) {
+
+    if (i == game.government_when_anarchy->index) {
+      continue;
+    }
+
+    if (can_change_to_government(game.player_ptr, get_government(i))) {
+
+      pGov = get_government(i);
+      pStr = create_str16_from_char(pGov->name, 12);
+      pGov_Button =
+          create_icon_button(GET_SURF(get_government_sprite(tileset, pGov)), 
pWindow->dst, pStr, 0);
+      pGov_Button->action = government_dlg_callback;
+
+      max_w = MAX(max_w, pGov_Button->size.w);
+      max_h = MAX(max_h, pGov_Button->size.h);
+      
+      /* ugly hack */
+      add_to_gui_list((MAX_ID - i), pGov_Button);
+      j++;
+
+    }
+  }
+
+  pGov_Dlg->pBeginWidgetList = pGov_Button;
+
+  max_w += 10;
+  max_h += 4;
+
+  /* set window start positions */
+  pWindow->size.x = (Main.screen->w - pWindow->size.w) / 2;
+  pWindow->size.y = (Main.screen->h - pWindow->size.h) / 2;
+
+  /* create window background */
+  pLogo = get_logo_gfx();
+  if (resize_window(pWindow, pLogo, NULL, max_w + 20,
+                    j * (max_h + 10) + WINDOW_TILE_HIGH + 6)) {
+    FREESURFACE(pLogo);
+  }
+  
+  pWindow->size.w = max_w + 20;
+  pWindow->size.h = j * (max_h + 10) + WINDOW_TILE_HIGH + 6;
+  
+  /* set buttons start positions and size */
+  j = 1;
+  while (pGov_Button != pGov_Dlg->pEndWidgetList) {
+    pGov_Button->size.w = max_w;
+    pGov_Button->size.h = max_h;
+    pGov_Button->size.x = pWindow->size.x + 10;
+    pGov_Button->size.y = pWindow->size.y + pWindow->size.h -
+        (j++) * (max_h + 10);
+    set_wstate(pGov_Button, FC_WS_NORMAL);
+
+    pGov_Button = pGov_Button->next;
+  }
+
+  set_wstate(pWindow, FC_WS_NORMAL);
+
+  /* redraw */
+  redraw_group(pGov_Dlg->pBeginWidgetList, pWindow, 0);
+
+  flush_rect(pWindow->size);
+}
+
+/**************************************************************************
   Popup a dialog asking if the player wants to start a revolution.
 **************************************************************************/
 void popup_revolution_dialog(void)
@@ -3498,6 +3632,11 @@
     return;
   }
   
+  if (game.player_ptr->revolution_finishes >= 0) {
+    popup_government_dialog();
+    return;
+  }
+  
   pRevolutionDlg = fc_calloc(1, sizeof(struct SMALL_DLG));
     
   /* create ok button */

[Prev in Thread] Current Thread [Next in Thread]