Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2006:
[Freeciv-Dev] Re: (PR#15856) Editor: Edit nation info
Home

[Freeciv-Dev] Re: (PR#15856) Editor: Edit nation info

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#15856) Editor: Edit nation info
From: "Mike Kaufman" <kaufman@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 11 Mar 2006 08:31:28 -0800
Reply-to: bugs@xxxxxxxxxxx

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

making the changes jason wanted.

-mike

Index: server/srv_main.c
===================================================================
--- server/srv_main.c   (revision 11757)
+++ server/srv_main.c   (working copy)
@@ -1276,7 +1276,9 @@
   struct nation_type *old_nation, *new_nation;
   struct player *pplayer = get_player(player_no);
 
-  if (server_state != PRE_GAME_STATE || !pplayer) {
+  if (!(requestor->current_conn->access_level == ALLOW_HACK 
+        && game.info.is_edit_mode) 
+      && (server_state != PRE_GAME_STATE || !pplayer)) {
     return;
   }
 
Index: server/edithand.c
===================================================================
--- server/edithand.c   (revision 11757)
+++ server/edithand.c   (working copy)
@@ -51,6 +51,10 @@
     notify_conn(NULL, NULL, E_SETTING,
                _(" *** Server set to edit mode! *** "));
   }
+  if (game.info.is_edit_mode && !is_edit_mode) {
+    notify_conn(NULL, NULL, E_SETTING,
+               _(" *** Server is leaving edit mode. *** "));
+  }
   if (!EQ(game.info.is_edit_mode, is_edit_mode)) {
     game.info.is_edit_mode = is_edit_mode;
     send_game_info(NULL);
Index: common/nation.c
===================================================================
--- common/nation.c     (revision 11757)
+++ common/nation.c     (working copy)
@@ -396,7 +396,8 @@
 bool can_conn_edit_players_nation(const struct connection *pconn,
                                  const struct player *pplayer)
 {
-  return (game.info.is_new_game
-         && ((!pconn->observer && pconn->player == pplayer)
-             || pconn->access_level >= ALLOW_CTRL));
+  return ((pconn->access_level == ALLOW_HACK && game.info.is_edit_mode) 
+          || (game.info.is_new_game
+             && ((!pconn->observer && pconn->player == pplayer)
+                  || pconn->access_level >= ALLOW_CTRL)));
 }
Index: client/gui-gtk-2.0/dialogs.c
===================================================================
--- client/gui-gtk-2.0/dialogs.c        (revision 11757)
+++ client/gui-gtk-2.0/dialogs.c        (working copy)
@@ -760,11 +760,15 @@
   int i;
   
   shell =
-    gtk_dialog_new_with_buttons(_("What Nation Will You Be?"),
+    gtk_dialog_new_with_buttons(game.info.is_edit_mode 
+                                  ?  _("Edit Nation") 
+                                  :  _("What Nation Will You Be?"),
                                NULL,
                                0,
+                               GTK_STOCK_CANCEL,
+                               GTK_RESPONSE_CANCEL,
                                _("Random Nation"),
-                               GTK_RESPONSE_CANCEL,
+                                GTK_RESPONSE_NO, /* for lack of a better */
                                GTK_STOCK_OK,
                                GTK_RESPONSE_ACCEPT,
                                NULL);
@@ -925,8 +929,18 @@
   selected_nation = -1;
 
   /* Finish up. */
-  gtk_dialog_set_default_response(GTK_DIALOG(shell), GTK_RESPONSE_ACCEPT);
+  gtk_dialog_set_default_response(GTK_DIALOG(shell), GTK_RESPONSE_CANCEL);
 
+  /* Don't allow ok without a selection */
+  gtk_dialog_set_response_sensitive(GTK_DIALOG(shell), GTK_RESPONSE_ACCEPT,
+                                    FALSE);                                    
      
+  /* don't allow random nation selection in edit mode, since assigning
+   * NO_NATION while game is running is very bad */
+  if (game.info.is_edit_mode) {
+    gtk_dialog_set_response_sensitive(GTK_DIALOG(shell), GTK_RESPONSE_NO,
+                                      FALSE);
+  }
+
   gtk_widget_show_all(GTK_DIALOG(shell)->vbox);
 }
 
@@ -1144,6 +1158,9 @@
       gtk_text_buffer_set_text(races_text, nation->legend , -1);
     }
 
+    /* Once we've made a selection, allow user to ok */
+    gtk_dialog_set_response_sensitive(GTK_DIALOG(races_shell), 
+                                      GTK_RESPONSE_ACCEPT, TRUE);
   } else {
     selected_nation = -1;
   }
@@ -1212,11 +1229,8 @@
   if (response == GTK_RESPONSE_ACCEPT) {
     const char *s;
 
+    /* can this even happen? */
     if (selected_nation == -1) {
-      dsend_packet_nation_select_req(&aconnection,
-                                    races_player->player_no,
-                                    -1, FALSE, "", 0);
-      popdown_races_dialog();
       return;
     }
 
@@ -1242,11 +1256,12 @@
     dsend_packet_nation_select_req(&aconnection,
                                   races_player->player_no, selected_nation,
                                   selected_sex, s, selected_city_style);
-  } else if (response == GTK_RESPONSE_CANCEL) {
+  } else if (response == GTK_RESPONSE_NO) {
     dsend_packet_nation_select_req(&aconnection,
                                   races_player->player_no,
                                   -1, FALSE, "", 0);
   }
+
   popdown_races_dialog();
 }
 
Index: client/gui-gtk-2.0/plrdlg.c
===================================================================
--- client/gui-gtk-2.0/plrdlg.c (revision 11757)
+++ client/gui-gtk-2.0/plrdlg.c (working copy)
@@ -36,6 +36,8 @@
 #include "climisc.h"
 #include "clinet.h"
 #include "connectdlg_common.h"
+#include "dialogs.h"
+#include "editor.h"
 #include "gui_main.h"
 #include "gui_stuff.h"
 #include "inteldlg.h"
@@ -56,6 +58,9 @@
 static GtkWidget *players_war_command;
 static GtkWidget *players_vision_command;
 static GtkWidget *players_sship_command;
+static GtkWidget *players_edit_menu;
+static GtkWidget *players_edit_editable_command;
+static GtkWidget *players_edit_nation_command;
 static GtkListStore *store;
 static GtkTreeModel *model;
 
@@ -69,6 +74,8 @@
 static void players_sship_callback(GtkMenuItem *item, gpointer data);
 static void players_ai_toggle_callback(GtkMenuItem *item, gpointer data);
 static void players_ai_skill_callback(GtkMenuItem *item, gpointer data);
+static void players_edit_editable_callback(GtkMenuItem *item, gpointer data);
+static void players_edit_nation_callback(GtkMenuItem *item, gpointer data);
 
 
 static void update_views(void);
@@ -205,7 +212,10 @@
       plr = get_player(id);
 
       if (ev->button == 1) {
-       if (can_intel_with_player(plr)) {
+        if (game.info.is_edit_mode) {
+          editable_player = plr;
+          update_players_dialog();
+        } else if (can_intel_with_player(plr)) {
          popup_intel_dialog(plr);
        }
       } else {
@@ -313,7 +323,8 @@
   GtkWidget *menu = gtk_menu_new();
   GtkWidget *item;    
   
-  for (i = 1; i < num_player_dlg_columns; i++) {
+  /* index starting at one here to force playername to always be shown */
+  for (i = 2; i < num_player_dlg_columns; i++) {
     struct player_dlg_column *pcol;
     
     pcol = &player_dlg_columns[i];
@@ -508,8 +519,21 @@
   gtk_widget_set_sensitive(players_sship_command, FALSE);
   gtk_menu_shell_append(GTK_MENU_SHELL(menu), players_sship_command);
 
+  players_edit_menu = gtk_menu_item_new_with_mnemonic(_("_Editor"));
+  gtk_menu_shell_append(GTK_MENU_SHELL(menubar), players_edit_menu);
+  gtk_widget_set_sensitive(players_edit_menu, game.info.is_edit_mode);
 
+  menu = gtk_menu_new();
+  gtk_menu_item_set_submenu(GTK_MENU_ITEM(players_edit_menu), menu);
 
+  players_edit_editable_command = 
+                   gtk_menu_item_new_with_mnemonic(_("_Make player editable"));
+  gtk_menu_shell_append(GTK_MENU_SHELL(menu), players_edit_editable_command);
+
+  players_edit_nation_command = 
+                         gtk_menu_item_new_with_mnemonic(_("_Edit Nation..."));
+  gtk_menu_shell_append(GTK_MENU_SHELL(menu), players_edit_nation_command);
+
   gui_dialog_show_all(players_dialog_shell);
 
   g_signal_connect(players_meet_command, "activate",
@@ -522,6 +546,10 @@
     G_CALLBACK(players_intel_callback), NULL);
   g_signal_connect(players_sship_command, "activate",
     G_CALLBACK(players_sship_callback), NULL);
+  g_signal_connect(players_edit_editable_command, "activate",
+    G_CALLBACK(players_edit_editable_callback), NULL);
+  g_signal_connect(players_edit_nation_command, "activate",
+    G_CALLBACK(players_edit_nation_callback), NULL);
 
   gtk_list_store_clear(store);
   update_players_dialog();
@@ -708,6 +736,13 @@
       }
     } players_iterate_end;
 
+    /* menu needs to be updated with edit mode changes */
+    gtk_widget_set_sensitive(players_edit_menu, game.info.is_edit_mode);
+
+    /* this is a real hack */
+    player_dlg_columns[1].show = game.info.is_edit_mode;
+
+
     update_players_menu();
     update_views();
   }
@@ -842,6 +877,41 @@
 }
 
 /**************************************************************************
+ change the active player to the one selected
+**************************************************************************/
+static void players_edit_editable_callback(GtkMenuItem *item, gpointer data)
+{
+  GtkTreeModel *model;
+  GtkTreeIter it;
+  
+  if (gtk_tree_selection_get_selected(players_selection, &model, &it)) {
+    gint plrno;
+
+    gtk_tree_model_get(model, &it, ncolumns - 1, &plrno, -1);
+
+    editable_player = get_player(plrno);
+    update_players_dialog();
+  }
+}   
+
+/**************************************************************************
+ popup the races dialog for the selected player
+**************************************************************************/
+static void players_edit_nation_callback(GtkMenuItem *item, gpointer data)
+{
+  GtkTreeModel *model;
+  GtkTreeIter it;
+  
+  if (gtk_tree_selection_get_selected(players_selection, &model, &it)) {
+    gint plrno;
+
+    gtk_tree_model_get(model, &it, ncolumns - 1, &plrno, -1);
+
+    popup_races_dialog(get_player(plrno));
+  }
+}   
+
+/**************************************************************************
 ...
 **************************************************************************/
 static void update_views(void)
Index: client/packhand.c
===================================================================
--- client/packhand.c   (revision 11757)
+++ client/packhand.c   (working copy)
@@ -1402,6 +1402,7 @@
   }
   update_unit_focus();
   update_menus();
+  update_players_dialog();
   if (update_aifill_button) {
     update_start_page();
   }
Index: client/plrdlg_common.c
===================================================================
--- client/plrdlg_common.c      (revision 11757)
+++ client/plrdlg_common.c      (working copy)
@@ -23,6 +23,7 @@
 #include "support.h"
 
 #include "climisc.h"
+#include "editor.h"
 #include "text.h"
 
 #include "plrdlg_g.h"
@@ -69,6 +70,14 @@
 }
 
 /******************************************************************
+  TRUE if we are in edit mode and this player is active (editable).
+*******************************************************************/
+static bool col_edit(const struct player *plr)
+{
+  return game.info.is_edit_mode && plr == editable_player;
+}
+
+/******************************************************************
   The player-name (aka nation leader) column of the plrdlg.
 *******************************************************************/
 static const char *col_name(const struct player *player)
@@ -247,6 +256,7 @@
 *******************************************************************/
 struct player_dlg_column player_dlg_columns[] = {
   {TRUE, COL_TEXT, N_("?Player:Name"), col_name, NULL, NULL, "name"},
+  {FALSE, COL_BOOLEAN, N_("Editable"), NULL, col_edit, NULL, "editable"},
   {FALSE, COL_TEXT, N_("Username"), col_username, NULL, NULL, "username"},
   {TRUE, COL_FLAG, N_("Flag"), NULL, NULL, NULL,  "flag"},
   {TRUE, COL_TEXT, N_("Nation"), col_nation, NULL, NULL,  "nation"},
@@ -271,7 +281,7 @@
 *******************************************************************/
 int player_dlg_default_sort_column(void)
 {
-  return 3;
+  return 4;
 }
 
 /****************************************************************************
Index: client/editor.c
===================================================================
--- client/editor.c     (revision 11757)
+++ client/editor.c     (working copy)
@@ -31,6 +31,9 @@
 #include "control.h"
 #include "editor.h"
 
+/* a pointer to the player and his structures that can be currently edited */
+struct player *editable_player = &game.players[0];
+
 /* where the selected terrain and specials for editing are stored */
 static enum editor_tool_type selected_tool = ETOOL_PAINT;
 static enum tile_special_type selected_special = S_LAST;
Index: client/editor.h
===================================================================
--- client/editor.h     (revision 11757)
+++ client/editor.h     (working copy)
@@ -31,6 +31,8 @@
   EPAINT_LAST
 };
 
+extern struct player *editable_player;
+
 typedef void (*ToolFunction)(struct tile *ptile);
 
 void editor_init_tools(void);

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