[Freeciv-Dev] (PR#12041) CMA / preset tab
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12041 >
Here is a tentative patch.
Index: client/gui-gtk-2.0/cma_fe.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/cma_fe.c,v
retrieving revision 1.19.2.3
diff -u -r1.19.2.3 cma_fe.c
--- client/gui-gtk-2.0/cma_fe.c 25 Nov 2004 23:27:23 -0000 1.19.2.3
+++ client/gui-gtk-2.0/cma_fe.c 30 Jan 2005 01:06:28 -0000
@@ -70,8 +70,7 @@
static void cma_preset_add_callback_destroy(GtkWidget *w, gpointer data);
static void cma_change_to_callback(GtkWidget *w, gpointer data);
-static void cma_change_permanent_to_callback(GtkWidget *w, gpointer data);
-static void cma_release_callback(GtkWidget *w, gpointer data);
+static void cma_active_callback(GtkWidget *w, gpointer data);
static void cma_activate_preset_callback(GtkTreeView *view, GtkTreePath *path,
GtkTreeViewColumn *col, gpointer data);
@@ -130,6 +129,63 @@
}
/**************************************************************************
+...
+**************************************************************************/
+static void item_toggled(GtkCellRendererToggle *cell,
+ gchar *spath, gpointer data)
+{
+ struct cma_dialog *pdialog = (struct cma_dialog *) data;
+ int preset_index;
+ const struct cm_parameter *pparam;
+ GtkTreePath *path;
+
+ path = gtk_tree_path_new_from_string(spath);
+
+ preset_index = gtk_tree_path_get_indices(path) [0];
+
+ pparam = cmafec_preset_get_parameter(preset_index);
+
+ /* save the change */
+ cmafec_set_fe_parameter(pdialog->pcity, pparam);
+
+ if (cma_is_city_under_agent(pdialog->pcity, NULL)) {
+ cma_release_city(pdialog->pcity);
+ cma_put_city_under_agent(pdialog->pcity, pparam);
+ }
+ refresh_city_dialog(pdialog->pcity);
+
+ gtk_tree_path_free(path);
+}
+
+/**************************************************************************
+...
+**************************************************************************/
+static void cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *cell,
+ GtkTreeModel *model, GtkTreeIter *it, gpointer data)
+{
+ struct cma_dialog *pdialog = (struct cma_dialog *) data;
+ const char *s1, *s2;
+ int i1, i2;
+ struct cm_parameter param;
+ GtkTreePath *path;
+
+ gtk_tree_model_get(model, it, 0, &s1, -1);
+ path = gtk_tree_model_get_path(model, it);
+ i1 = gtk_tree_path_get_indices(path) [0];
+ gtk_tree_path_free(path);
+
+ cmafec_get_fe_parameter(pdialog->pcity, ¶m);
+ s2 = cmafec_get_short_descr(¶m);
+ i2 = cmafec_preset_get_index_of_parameter(¶m);
+
+ if (!strcmp(s1, s2) && i1 == i2) {
+ g_object_set(G_OBJECT(cell), "active", TRUE, NULL);
+ } else {
+ g_object_set(G_OBJECT(cell), "active", FALSE, NULL);
+ }
+}
+
+/**************************************************************************
instantiates a new struct for each city_dialog window that is open.
**************************************************************************/
struct cma_dialog *create_cma_dialog(struct city *pcity)
@@ -142,6 +198,7 @@
GtkListStore *store;
GtkCellRenderer *rend;
GtkWidget *view;
+ GtkTreeViewColumn *column;
cmafec_get_fe_parameter(pcity, ¶m);
pdialog = fc_malloc(sizeof(struct cma_dialog));
@@ -167,7 +224,7 @@
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
- store = gtk_list_store_new(1, G_TYPE_STRING);
+ store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_BOOLEAN);
pdialog->store = store;
view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
@@ -187,6 +244,22 @@
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), -1, NULL,
rend, "text", 0, NULL);
+ rend = gtk_cell_renderer_toggle_new();
+ gtk_cell_renderer_toggle_set_radio(GTK_CELL_RENDERER_TOGGLE(rend), TRUE);
+ column = gtk_tree_view_column_new_with_attributes(NULL, rend, NULL);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
+
+ gtk_tree_view_column_set_cell_data_func(column, rend, cell_data_func,
+ pdialog, NULL);
+ g_signal_connect(rend, "toggled", G_CALLBACK(item_toggled), pdialog);
+
+
+
+
+
+
+
+
label = g_object_new(GTK_TYPE_LABEL,
"use-underline", TRUE,
"mnemonic-widget", view,
@@ -317,15 +390,14 @@
g_signal_connect(pdialog->change_command, "clicked",
G_CALLBACK(cma_change_to_callback), pdialog);
- pdialog->perm_command = gtk_button_new_with_mnemonic(_("Control c_ity"));
- gtk_container_add(GTK_CONTAINER(hbox), pdialog->perm_command);
- g_signal_connect(pdialog->perm_command, "clicked",
- G_CALLBACK(cma_change_permanent_to_callback), pdialog);
-
- pdialog->release_command = gtk_button_new_with_mnemonic(_("_Release city"));
- gtk_container_add(GTK_CONTAINER(hbox), pdialog->release_command);
- g_signal_connect(pdialog->release_command, "clicked",
- G_CALLBACK(cma_release_callback), pdialog);
+ pdialog->active_image = gtk_image_new();
+
+ pdialog->active_command = gtk_button_new();
+ gtk_container_add(GTK_CONTAINER(pdialog->active_command),
+ pdialog->active_image);
+ g_signal_connect(pdialog->active_command, "clicked",
+ G_CALLBACK(cma_active_callback), pdialog);
+ gtk_container_add(GTK_CONTAINER(hbox), pdialog->active_command);
gtk_widget_show_all(pdialog->shell);
@@ -349,7 +421,6 @@
struct cm_parameter param;
struct cma_dialog *pdialog = get_cma_dialog(pcity);
int controlled = cma_is_city_under_agent(pcity, NULL);
- int preset_index;
cmafec_get_fe_parameter(pcity, ¶m);
@@ -363,35 +434,21 @@
set_hscales(¶m, pdialog);
}
- if (refresh != DONT_REFRESH_SELECT) {
- /* highlight preset if parameter matches */
- preset_index = cmafec_preset_get_index_of_parameter(¶m);
- if (preset_index != -1) {
- GtkTreePath *path;
-
- path = gtk_tree_path_new();
- gtk_tree_path_append_index(path, preset_index);
-
- allow_refreshes = 0;
- gtk_tree_view_set_cursor(GTK_TREE_VIEW(pdialog->preset_list), path,
- NULL, FALSE);
- allow_refreshes = 1;
-
- gtk_tree_path_free(path);
- } else {
- gtk_tree_selection_unselect_all(pdialog->selection);
- }
- }
+ gtk_widget_queue_draw(pdialog->preset_list);
gtk_widget_set_sensitive(pdialog->change_command,
can_client_issue_orders() &&
result.found_a_valid && !controlled);
- gtk_widget_set_sensitive(pdialog->perm_command,
- can_client_issue_orders() &&
- result.found_a_valid && !controlled);
- gtk_widget_set_sensitive(pdialog->release_command,
- can_client_issue_orders() &&
- controlled);
+
+ gtk_widget_set_sensitive(pdialog->active_command, can_client_issue_orders());
+
+ if (controlled) {
+ gtk_image_set_from_stock(GTK_IMAGE(pdialog->active_image),
+ GTK_STOCK_YES, GTK_ICON_SIZE_DIALOG);
+ } else {
+ gtk_image_set_from_stock(GTK_IMAGE(pdialog->active_image),
+ GTK_STOCK_NO, GTK_ICON_SIZE_DIALOG);
+ }
}
/**************************************************************************
@@ -426,32 +483,6 @@
static void cma_activate_preset_callback(GtkTreeView *view, GtkTreePath *path,
GtkTreeViewColumn *col, gpointer data)
{
- struct cma_dialog *pdialog = (struct cma_dialog *) data;
- int preset_index;
- const struct cm_parameter *pparam;
-
- preset_index = gtk_tree_path_get_indices(path) [0];
-
- pparam = cmafec_preset_get_parameter(preset_index);
-
- /* save the change */
- cmafec_set_fe_parameter(pdialog->pcity, pparam);
-
- if (allow_refreshes) {
- if (cma_is_city_under_agent(pdialog->pcity, NULL)) {
- cma_release_city(pdialog->pcity);
- cma_put_city_under_agent(pdialog->pcity, pparam);
-
- /* unfog the city map if we were unable to put back under */
- if (!cma_is_city_under_agent(pdialog->pcity, NULL)) {
- refresh_city_dialog(pdialog->pcity);
- return; /* refreshing the city, refreshes cma */
- } else {
- city_report_dialog_update_city(pdialog->pcity);
- }
- }
- refresh_cma_dialog(pdialog->pcity, DONT_REFRESH_SELECT);
- }
}
/**************************************************************************
@@ -625,28 +656,22 @@
}
/**************************************************************************
- changes the workers of the city to the cma parameters and puts the
- city under agent control
+ activates/deactivates agent control.
**************************************************************************/
-static void cma_change_permanent_to_callback(GtkWidget *w, gpointer data)
+static void cma_active_callback(GtkWidget *w, gpointer data)
{
struct cma_dialog *pdialog = (struct cma_dialog *) data;
- struct cm_parameter param;
- cmafec_get_fe_parameter(pdialog->pcity, ¶m);
- cma_put_city_under_agent(pdialog->pcity, ¶m);
- refresh_city_dialog(pdialog->pcity);
-}
-
-/**************************************************************************
- releases the city from agent control
-**************************************************************************/
-static void cma_release_callback(GtkWidget *w, gpointer data)
-{
- struct cma_dialog *pdialog = (struct cma_dialog *) data;
+ if (cma_is_city_under_agent(pdialog->pcity, NULL)) {
+ cma_release_city(pdialog->pcity);
+ refresh_city_dialog(pdialog->pcity);
+ } else {
+ struct cm_parameter param;
- cma_release_city(pdialog->pcity);
- refresh_city_dialog(pdialog->pcity);
+ cmafec_get_fe_parameter(pdialog->pcity, ¶m);
+ cma_put_city_under_agent(pdialog->pcity, ¶m);
+ refresh_city_dialog(pdialog->pcity);
+ }
}
/****************************************************************
Index: client/gui-gtk-2.0/cma_fe.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/cma_fe.h,v
retrieving revision 1.3
diff -u -r1.3 cma_fe.h
--- client/gui-gtk-2.0/cma_fe.h 16 Apr 2003 22:28:26 -0000 1.3
+++ client/gui-gtk-2.0/cma_fe.h 30 Jan 2005 01:06:28 -0000
@@ -36,8 +36,8 @@
GtkWidget *add_preset_command;
GtkWidget *del_preset_command;
GtkWidget *change_command;
- GtkWidget *perm_command;
- GtkWidget *release_command;
+ GtkWidget *active_image;
+ GtkWidget *active_command;
GtkAdjustment *minimal_surplus[NUM_STATS];
GtkWidget *happy_button;
GtkAdjustment *factor[NUM_STATS + 1];
- [Freeciv-Dev] Re: (PR#12041) CMA / preset tab, Vasco Alexandre da Silva Costa, 2005/01/29
- [Freeciv-Dev] Re: (PR#12041) CMA / preset tab, Christian Knoke, 2005/01/29
- [Freeciv-Dev] Re: (PR#12041) CMA / preset tab, Christian Knoke, 2005/01/29
- [Freeciv-Dev] Re: (PR#12041) CMA / preset tab, Christian Knoke, 2005/01/29
- [Freeciv-Dev] (PR#12041) CMA / preset tab,
Vasco Alexandre da Silva Costa <=
- [Freeciv-Dev] (PR#12041) CMA / preset tab, Vasco Alexandre da Silva Costa, 2005/01/29
- [Freeciv-Dev] (PR#12041) CMA / preset tab, Vasco Alexandre da Silva Costa, 2005/01/29
- [Freeciv-Dev] (PR#12041) CMA / preset tab, Vasco Alexandre da Silva Costa, 2005/01/29
- [Freeciv-Dev] (PR#12041) CMA / preset tab, Vasco Alexandre da Silva Costa, 2005/01/29
- [Freeciv-Dev] (PR#12041) CMA / preset tab, Vasco Alexandre da Silva Costa, 2005/01/29
- [Freeciv-Dev] (PR#12041) CMA / preset tab, Vasco Alexandre da Silva Costa, 2005/01/29
- [Freeciv-Dev] Re: (PR#12041) CMA / preset tab, Jason Short, 2005/01/29
- [Freeciv-Dev] Re: (PR#12041) CMA / preset tab, Jason Short, 2005/01/29
- [Freeciv-Dev] Re: (PR#12041) CMA / preset tab, Christian Knoke, 2005/01/30
- [Freeciv-Dev] Re: (PR#12041) CMA / preset tab, Vasco Alexandre da Silva Costa, 2005/01/30
|
|