[Freeciv-Dev] (PR#11335) [PATCH] New CMA dialogs
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: |
[Freeciv-Dev] (PR#11335) [PATCH] New CMA dialogs |
From: |
"Vasco Alexandre da Silva Costa" <vasc@xxxxxxxxxxxxxx> |
Date: |
Sat, 4 Dec 2004 12:48:10 -0800 |
Reply-to: |
rt@xxxxxxxxxxx |
<URL: http://rt.freeciv.org/Ticket/Display.html?id=11335 >
I've done this patch as suggested by Jason. But the CMA handling is a
bit broken as well as refreshing. Maybe someone which knows how the CMA
functions better than me can fix it.
Index: client/agents/cma_fec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/agents/cma_fec.c,v
retrieving revision 1.26
diff -u -u -r1.26 cma_fec.c
--- client/agents/cma_fec.c 6 Sep 2004 02:13:16 -0000 1.26
+++ client/agents/cma_fec.c 4 Dec 2004 20:45:32 -0000
@@ -36,12 +36,6 @@
#define RESULT_COLUMNS 10
#define BUFFER_SIZE 100
-#define MAX_LEN_PRESET_NAME 80
-
-struct cma_preset {
- char *descr;
- struct cm_parameter parameter;
-};
#define SPECLIST_TAG preset
#define SPECLIST_TYPE struct cma_preset
@@ -124,37 +118,72 @@
}
/**************************************************************************
+ Returns the indexed preset.
+**************************************************************************/
+struct cma_preset *cmafec_ppreset_get(int index)
+{
+ return preset_list_get(&preset_list, index);
+}
+
+/**************************************************************************
+ Sets the indexed preset's description.
+**************************************************************************/
+void cmafec_ppreset_set_descr(struct cma_preset *ppreset,
+ const char *descr_name)
+{
+ if (ppreset->descr) {
+ free(ppreset->descr);
+ }
+ ppreset->descr = mystrdup(descr_name);
+}
+
+/**************************************************************************
+ Sets the indexed preset's parameter.
+**************************************************************************/
+void cmafec_ppreset_set_parameter(struct cma_preset *ppreset,
+ const struct cm_parameter *pparam)
+{
+ cm_copy_parameter(&ppreset->parameter, pparam);
+}
+
+/**************************************************************************
Adds a preset.
**************************************************************************/
void cmafec_preset_add(const char *descr_name, struct cm_parameter *pparam)
{
- struct cma_preset *ppreset = fc_malloc(sizeof(struct cma_preset));
+ struct cma_preset *ppreset = fc_calloc(1, sizeof(*ppreset));
if (!preset_list_has_been_initialized) {
preset_list_init(&preset_list);
preset_list_has_been_initialized = TRUE;
}
- cm_copy_parameter(&ppreset->parameter, pparam);
- ppreset->descr = fc_malloc(MAX_LEN_PRESET_NAME);
- (void) mystrlcpy(ppreset->descr, descr_name, MAX_LEN_PRESET_NAME);
+ cmafec_ppreset_set_descr(ppreset, descr_name);
+ cmafec_ppreset_set_parameter(ppreset, pparam);
preset_list_insert(&preset_list, ppreset);
}
/**************************************************************************
Removes a preset.
**************************************************************************/
-void cmafec_preset_remove(int index)
+void cmafec_ppreset_remove(struct cma_preset *ppreset)
{
- struct cma_preset *ppreset;
+ if (ppreset) {
+ preset_list_unlink(&preset_list, ppreset);
- assert(index >= 0 && index < cmafec_preset_num());
+ free(ppreset->descr);
+ free(ppreset);
+ }
+}
- ppreset = preset_list_get(&preset_list, index);
- preset_list_unlink(&preset_list, ppreset);
+/**************************************************************************
+ Removes a preset.
+**************************************************************************/
+void cmafec_preset_remove(int index)
+{
+ struct cma_preset *ppreset = cmafec_ppreset_get(index);
- free(ppreset->descr);
- free(ppreset);
+ cmafec_ppreset_remove(ppreset);
}
/**************************************************************************
@@ -162,12 +191,13 @@
**************************************************************************/
char *cmafec_preset_get_descr(int index)
{
- struct cma_preset *ppreset;
+ struct cma_preset *ppreset = cmafec_ppreset_get(index);
- assert(index >= 0 && index < cmafec_preset_num());
-
- ppreset = preset_list_get(&preset_list, index);
- return ppreset->descr;
+ if (ppreset) {
+ return ppreset->descr;
+ } else {
+ return NULL;
+ }
}
/**************************************************************************
@@ -175,12 +205,13 @@
**************************************************************************/
const struct cm_parameter *cmafec_preset_get_parameter(int index)
{
- struct cma_preset *ppreset;
-
- assert(index >= 0 && index < cmafec_preset_num());
+ struct cma_preset *ppreset = cmafec_ppreset_get(index);
- ppreset = preset_list_get(&preset_list, index);
+ if (ppreset) {
return &ppreset->parameter;
+ } else {
+ return NULL;
+ }
}
/**************************************************************************
Index: client/agents/cma_fec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/agents/cma_fec.h,v
retrieving revision 1.7
diff -u -u -r1.7 cma_fec.h
--- client/agents/cma_fec.h 4 Sep 2004 18:39:38 -0000 1.7
+++ client/agents/cma_fec.h 4 Dec 2004 20:45:32 -0000
@@ -16,6 +16,11 @@
#include "cma_core.h"
+struct cma_preset {
+ char *descr;
+ struct cm_parameter parameter;
+};
+
void cmafec_init(void);
void cmafec_free(void);
@@ -35,7 +40,14 @@
/*
* Preset handling
*/
+struct cma_preset *cmafec_ppreset_get(int index);
+void cmafec_ppreset_set_descr(struct cma_preset *ppreset,
+ const char *descr_name);
+void cmafec_ppreset_set_parameter(struct cma_preset *ppreset,
+ const struct cm_parameter *pparam);
+
void cmafec_preset_add(const char *descr_name, struct cm_parameter *pparam);
+void cmafec_ppreset_remove(struct cma_preset *ppreset);
void cmafec_preset_remove(int index);
int cmafec_preset_get_index_of_parameter(const struct cm_parameter
*const parameter);
Index: client/gui-gtk-2.0/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/citydlg.c,v
retrieving revision 1.95.2.6
diff -u -u -r1.95.2.6 citydlg.c
--- client/gui-gtk-2.0/citydlg.c 3 Dec 2004 18:52:29 -0000 1.95.2.6
+++ client/gui-gtk-2.0/citydlg.c 4 Dec 2004 20:45:32 -0000
@@ -378,7 +378,7 @@
city_dialog_update_information(pdialog->happiness.info_label, pdialog);
refresh_happiness_dialog(pdialog->pcity);
- refresh_cma_dialog(pdialog->pcity, REFRESH_ALL);
+ refresh_cma_dialog(pdialog->pcity);
gtk_widget_set_sensitive(pdialog->show_units_command,
can_client_issue_orders() &&
Index: client/gui-gtk-2.0/cityrep.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/cityrep.c,v
retrieving revision 1.63.2.2
diff -u -u -r1.63.2.2 cityrep.c
--- client/gui-gtk-2.0/cityrep.c 31 Oct 2004 20:50:03 -0000 1.63.2.2
+++ client/gui-gtk-2.0/cityrep.c 4 Dec 2004 20:45:33 -0000
@@ -549,7 +549,7 @@
if (change_cma) {
for (i = -1; i < cmafec_preset_num(); i++) {
- w = (i == -1 ? gtk_menu_item_new_with_label(_("none"))
+ w = (i == -1 ? gtk_menu_item_new_with_label(_("<none>"))
: gtk_menu_item_new_with_label(cmafec_preset_get_descr(i)));
gtk_menu_shell_append(GTK_MENU_SHELL(menu), w);
g_signal_connect(w, "activate", G_CALLBACK(select_cma_callback),
@@ -568,7 +568,7 @@
} city_list_iterate_end;
if (found) {
- w = gtk_menu_item_new_with_label(_("none"));
+ w = gtk_menu_item_new_with_label(_("<none>"));
gtk_menu_shell_append(GTK_MENU_SHELL(menu), w);
g_signal_connect(w, "activate", G_CALLBACK(select_cma_callback),
GINT_TO_POINTER(CMA_NONE));
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 -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 4 Dec 2004 20:45:33 -0000
@@ -33,6 +33,7 @@
#include "cityrep.h"
#include "dialogs.h"
+#include "gui_main.h"
#include "gui_stuff.h"
#include "inputdlg.h"
@@ -51,33 +52,15 @@
static struct dialog_list dialog_list;
static bool dialog_list_has_been_initialised = FALSE;
-static int allow_refreshes = 1;
-
static struct cma_dialog *get_cma_dialog(struct city *pcity);
static void update_cma_preset_list(struct cma_dialog *pdialog);
-static gboolean cma_preset_key_pressed_callback(GtkWidget *w, GdkEventKey *ev,
- gpointer data);
-static void cma_del_preset_callback(GtkWidget *w, gpointer data);
-static void cma_preset_remove(struct cma_dialog *pdialog, int preset_index);
-static void cma_preset_remove_response(GtkWidget *w, gint response,
- gpointer data);
-
-static void cma_add_preset_callback(GtkWidget *w, gpointer data);
-static void cma_preset_add_callback_yes(GtkWidget *w, gpointer data);
-static void cma_preset_add_callback_no(GtkWidget *w, gpointer data);
-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_activate_preset_callback(GtkTreeView *view, GtkTreePath *path,
- GtkTreeViewColumn *col, gpointer data);
-
-static void hscale_changed(GtkAdjustment *get, gpointer data);
-static void set_hscales(const struct cm_parameter *const parameter,
- struct cma_dialog *pdialog);
+static void cma_selection_callback(GtkTreeSelection *selection, gpointer data);
+static GtkWidget *cma_shell;
/**************************************************************************
...
@@ -136,9 +119,8 @@
{
struct cma_dialog *pdialog;
struct cm_parameter param;
- GtkWidget *frame, *page, *hbox, *label, *table;
- GtkWidget *vbox, *sw, *hscale;
- int i;
+ GtkWidget *frame, *page, *hbox, *label;
+ GtkWidget *vbox, *sw;
GtkListStore *store;
GtkCellRenderer *rend;
GtkWidget *view;
@@ -167,7 +149,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_INT);
pdialog->store = store;
view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
@@ -190,31 +172,25 @@
label = g_object_new(GTK_TYPE_LABEL,
"use-underline", TRUE,
"mnemonic-widget", view,
- "label", _("_Presets:"),
+ "label", _("Selec_t a CMA Preset:"),
"xalign", 0.0, "yalign", 0.5, NULL);
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
gtk_container_add(GTK_CONTAINER(sw), view);
gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0);
- g_signal_connect(view, "row_activated",
- G_CALLBACK(cma_activate_preset_callback), pdialog);
- g_signal_connect(view, "key-press-event",
- G_CALLBACK(cma_preset_key_pressed_callback), pdialog);
+ g_signal_connect(pdialog->selection, "changed",
+ G_CALLBACK(cma_selection_callback), pdialog);
hbox = gtk_hbutton_box_new();
gtk_button_box_set_layout(GTK_BUTTON_BOX(hbox), GTK_BUTTONBOX_SPREAD);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
- pdialog->add_preset_command = gtk_button_new_from_stock(GTK_STOCK_NEW);
- gtk_container_add(GTK_CONTAINER(hbox), pdialog->add_preset_command);
- g_signal_connect(pdialog->add_preset_command, "clicked",
- G_CALLBACK(cma_add_preset_callback), pdialog);
-
- pdialog->del_preset_command = gtk_button_new_from_stock(GTK_STOCK_DELETE);
- gtk_container_add(GTK_CONTAINER(hbox), pdialog->del_preset_command);
- g_signal_connect(pdialog->del_preset_command, "clicked",
- G_CALLBACK(cma_del_preset_callback), pdialog);
+ pdialog->edit_presets_command = gtk_stockbutton_new(GTK_STOCK_INDEX,
+ _("Edit CM_A Presets"));
+ gtk_container_add(GTK_CONTAINER(hbox), pdialog->edit_presets_command);
+ g_signal_connect(pdialog->edit_presets_command, "clicked",
+ G_CALLBACK(popup_cma_report), NULL);
/* the right-hand side */
@@ -232,80 +208,6 @@
gtk_container_add(GTK_CONTAINER(frame), pdialog->result_label);
gtk_label_set_justify(GTK_LABEL(pdialog->result_label), GTK_JUSTIFY_LEFT);
- /* Minimal Surplus and Factor */
-
- table = gtk_table_new(NUM_STATS + 2, 3, FALSE);
- gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 2);
-
- label = gtk_label_new(_("Minimal Surplus"));
- gtk_misc_set_alignment(GTK_MISC(label), 0.1, 0.5);
- gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 2, 0, 1);
- label = gtk_label_new(_("Factor"));
- gtk_misc_set_alignment(GTK_MISC(label), 0.1, 0.5);
- gtk_table_attach_defaults(GTK_TABLE(table), label, 2, 3, 0, 1);
-
- for (i = 0; i < NUM_STATS; i++) {
- label = gtk_label_new(cm_get_stat_name(i));
- gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, i + 1, i + 2);
- gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
-
- pdialog->minimal_surplus[i] =
- GTK_ADJUSTMENT(gtk_adjustment_new(-20, -20, 20, 1, 1, 0));
-
- hscale = gtk_hscale_new(GTK_ADJUSTMENT(pdialog->minimal_surplus[i]));
- gtk_table_attach_defaults(GTK_TABLE(table), hscale, 1, 2, i + 1, i + 2);
- gtk_scale_set_digits(GTK_SCALE(hscale), 0);
- gtk_scale_set_value_pos(GTK_SCALE(hscale), GTK_POS_LEFT);
-
- g_signal_connect(pdialog->minimal_surplus[i],
- "value_changed",
- G_CALLBACK(hscale_changed), pdialog);
-
- pdialog->factor[i] =
- GTK_ADJUSTMENT(gtk_adjustment_new(1, 0, 25, 1, 1, 0));
-
- hscale = gtk_hscale_new(GTK_ADJUSTMENT(pdialog->factor[i]));
- gtk_table_attach_defaults(GTK_TABLE(table), hscale, 2, 3, i + 1, i + 2);
- gtk_scale_set_digits(GTK_SCALE(hscale), 0);
- gtk_scale_set_value_pos(GTK_SCALE(hscale), GTK_POS_LEFT);
-
- g_signal_connect(pdialog->factor[i], "value_changed",
- G_CALLBACK(hscale_changed), pdialog);
- }
-
- /* Happy Surplus and Factor */
-
- label = gtk_label_new(_("Celebrate"));
- gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1,
- NUM_STATS + 1, NUM_STATS + 2);
- gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
-
- hbox = gtk_hbox_new(FALSE, 0);
- gtk_table_attach_defaults(GTK_TABLE(table), hbox, 1, 2,
- NUM_STATS + 1, NUM_STATS + 2);
-
- pdialog->happy_button = gtk_check_button_new();
- gtk_box_pack_start(GTK_BOX(hbox), pdialog->happy_button, FALSE, FALSE,
- 20);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pdialog->happy_button),
- FALSE);
-
- g_signal_connect(pdialog->happy_button, "toggled",
- G_CALLBACK(hscale_changed), pdialog);
-
- pdialog->factor[NUM_STATS] =
- GTK_ADJUSTMENT(gtk_adjustment_new(0, 0, 50, 1, 0, 0));
-
- hscale = gtk_hscale_new(GTK_ADJUSTMENT(pdialog->factor[NUM_STATS]));
- gtk_table_attach_defaults(GTK_TABLE(table), hscale, 2, 3,
- NUM_STATS + 1, NUM_STATS + 2);
- gtk_scale_set_digits(GTK_SCALE(hscale), 0);
- gtk_scale_set_value_pos(GTK_SCALE(hscale), GTK_POS_LEFT);
-
- g_signal_connect(pdialog->factor[NUM_STATS],
- "value_changed",
- G_CALLBACK(hscale_changed), pdialog);
-
/* buttons */
hbox = gtk_hbutton_box_new();
@@ -343,13 +245,14 @@
/**************************************************************************
refreshes the cma dialog
**************************************************************************/
-void refresh_cma_dialog(struct city *pcity, enum cma_refresh refresh)
+void refresh_cma_dialog(struct city *pcity)
{
struct cm_result result;
struct cm_parameter param;
struct cma_dialog *pdialog = get_cma_dialog(pcity);
int controlled = cma_is_city_under_agent(pcity, NULL);
int preset_index;
+ GtkTreePath *path;
cmafec_get_fe_parameter(pcity, ¶m);
@@ -358,30 +261,16 @@
gtk_label_set_text(GTK_LABEL(pdialog->result_label),
cmafec_get_result_descr(pcity, &result, ¶m));
- /* if called from a hscale, we _don't_ want to do this */
- if (refresh != DONT_REFRESH_HSCALES) {
- 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;
+ /* highlight preset if parameter matches */
+ preset_index = cmafec_preset_get_index_of_parameter(¶m);
- gtk_tree_path_free(path);
- } else {
- gtk_tree_selection_unselect_all(pdialog->selection);
- }
- }
+ path = gtk_tree_path_new();
+ gtk_tree_path_append_index(path, preset_index + 1);
+
+ gtk_tree_view_set_cursor(GTK_TREE_VIEW(pdialog->preset_list), path,
+ NULL, FALSE);
+
+ gtk_tree_path_free(path);
gtk_widget_set_sensitive(pdialog->change_command,
can_client_issue_orders() &&
@@ -407,308 +296,580 @@
gtk_list_store_clear(pdialog->store);
/* Append the presets */
- if (cmafec_preset_num()) {
- gtk_tooltips_disable(pdialog->tips);
+ gtk_tooltips_disable(pdialog->tips);
- for (i = 0; i < cmafec_preset_num(); i++) {
- mystrlcpy(buf, cmafec_preset_get_descr(i), sizeof(buf));
- gtk_list_store_append(pdialog->store, &it);
- gtk_list_store_set(pdialog->store, &it, 0, buf, -1);
- }
- } else {
- gtk_tooltips_enable(pdialog->tips);
+ gtk_list_store_append(pdialog->store, &it);
+ gtk_list_store_set(pdialog->store, &it,
+ 0, _("<none>"), 1, CMA_NONE, -1);
+
+ for (i = 0; i < cmafec_preset_num(); i++) {
+ mystrlcpy(buf, cmafec_preset_get_descr(i), sizeof(buf));
+ gtk_list_store_append(pdialog->store, &it);
+ gtk_list_store_set(pdialog->store, &it,
+ 0, buf, 1, i, -1);
}
+
+ gtk_tooltips_enable(pdialog->tips);
}
/****************************************************************
callback for selecting a preset from the preset view
*****************************************************************/
-static void cma_activate_preset_callback(GtkTreeView *view, GtkTreePath *path,
- GtkTreeViewColumn *col, gpointer data)
+static void cma_selection_callback(GtkTreeSelection *selection, 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];
+ GtkTreeModel *model;
+ GtkTreeIter it;
- pparam = cmafec_preset_get_parameter(preset_index);
+ if (gtk_tree_selection_get_selected(selection, &model, &it)) {
+ int idx;
- /* save the change */
- cmafec_set_fe_parameter(pdialog->pcity, pparam);
+ gtk_tree_model_get(model, &it, 1, &idx, -1);
- if (allow_refreshes) {
- if (cma_is_city_under_agent(pdialog->pcity, NULL)) {
+ /* save the change */
+ if (idx == CMA_NONE) {
cma_release_city(pdialog->pcity);
- cma_put_city_under_agent(pdialog->pcity, pparam);
+ } else {
+ const struct cm_parameter *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);
- }
+ pparam = cmafec_preset_get_parameter(idx);
+ cma_put_city_under_agent(pdialog->pcity, pparam);
}
- refresh_cma_dialog(pdialog->pcity, DONT_REFRESH_SELECT);
+
+ refresh_city_dialog(pdialog->pcity);
+ city_report_dialog_update_city(pdialog->pcity);
}
}
/**************************************************************************
- pops up a dialog to allow to name your new preset
-**************************************************************************/
-static void cma_add_preset_callback(GtkWidget *w, gpointer data)
+ changes the workers of the city to the cma parameters
+ **************************************************************************/
+static void cma_change_to_callback(GtkWidget *w, gpointer data)
{
+ struct cm_result result;
struct cma_dialog *pdialog = (struct cma_dialog *) data;
- const char *default_name;
- GtkWidget *parent = gtk_widget_get_toplevel(pdialog->shell);
- int index;
+ struct cm_parameter param;
- if ((index = gtk_tree_selection_get_row(pdialog->selection)) != -1) {
- default_name = cmafec_preset_get_descr(index);
- } else {
- default_name = _("new preset");
- }
+ cmafec_get_fe_parameter(pdialog->pcity, ¶m);
+ cm_query_result(pdialog->pcity, ¶m, &result);
+ cma_apply_result(pdialog->pcity, &result);
+}
- pdialog->name_shell = input_dialog_create(GTK_WINDOW(parent),
- _("Name new preset"),
- _("What should we name the preset?"),
- default_name,
- G_CALLBACK(cma_preset_add_callback_yes),
- pdialog,
- G_CALLBACK(cma_preset_add_callback_no),
- pdialog);
+/**************************************************************************
+ changes the workers of the city to the cma parameters and puts the
+ city under agent control
+ **************************************************************************/
+static void cma_change_permanent_to_callback(GtkWidget *w, gpointer data)
+{
+ struct cma_dialog *pdialog = (struct cma_dialog *) data;
+ struct cm_parameter param;
- g_signal_connect(pdialog->name_shell, "destroy",
- G_CALLBACK(cma_preset_add_callback_destroy), data);
+ cmafec_get_fe_parameter(pdialog->pcity, ¶m);
+ cma_put_city_under_agent(pdialog->pcity, ¶m);
+ refresh_city_dialog(pdialog->pcity);
}
-/****************************************************************
- callback for the add_preset popup (delete popup)
-*****************************************************************/
-static void cma_preset_add_callback_destroy(GtkWidget *w, gpointer data)
+/**************************************************************************
+ releases the city from agent control
+ **************************************************************************/
+static void cma_release_callback(GtkWidget *w, gpointer data)
{
struct cma_dialog *pdialog = (struct cma_dialog *) data;
- pdialog->name_shell = NULL;
+ cma_release_city(pdialog->pcity);
+ refresh_city_dialog(pdialog->pcity);
}
+
+
+
+/****************************************************************
+...
+*****************************************************************/
+static GtkWidget *cma_preset_remove_shell;
+static GtkWidget *cma_list;
+
+enum {
+ CMA_NEW,
+ CMA_DELETE,
+ CMA_PROPERTIES,
+ CMA_CLOSE
+};
+
+static GtkListStore *cma_store;
+
+void popup_cma_report(void);
+
+static GHashTable *hash;
+
/****************************************************************
- callback for the add_preset popup (don't add it)
+...
*****************************************************************/
-static void cma_preset_add_callback_no(GtkWidget *w, gpointer data)
+static struct cma_dialog *get_cma_preset(struct cma_preset *ppreset)
{
- input_dialog_destroy(w);
+ if (hash) {
+ gpointer ret;
+
+ ret = g_hash_table_lookup(hash, ppreset);
+ return ret;
+ } else {
+ return NULL;
+ }
}
/****************************************************************
- callback for the add_preset popup (add it)
+...
*****************************************************************/
-static void cma_preset_add_callback_yes(GtkWidget *w, gpointer data)
+static void insert_cma_preset(struct cma_preset *ppreset,
+ struct cma_dialog *pdialog)
{
- struct cma_dialog *pdialog = (struct cma_dialog *) data;
-
- if (pdialog) {
- struct cm_parameter param;
-
- cmafec_get_fe_parameter(pdialog->pcity, ¶m);
- cmafec_preset_add(input_dialog_get_input(w), ¶m);
- update_cma_preset_list(pdialog);
- refresh_cma_dialog(pdialog->pcity, DONT_REFRESH_HSCALES);
- /* if this or other cities have this set as "custom" */
- city_report_dialog_update();
+ if (!hash) {
+ hash = g_hash_table_new(g_direct_hash, g_direct_equal);
}
-
- input_dialog_destroy(w);
+ g_hash_table_insert(hash, ppreset, pdialog);
}
/****************************************************************
- Key pressed in preset list
+...
*****************************************************************/
-static gboolean cma_preset_key_pressed_callback(GtkWidget *w, GdkEventKey *ev,
- gpointer data)
+static void delete_cma_preset(struct cma_preset *ppreset)
{
- struct cma_dialog *pdialog = (struct cma_dialog *) data;
- int index;
+ if (hash) {
+ g_hash_table_remove(hash, ppreset);
+ }
+}
- if ((index = gtk_tree_selection_get_row(pdialog->selection)) == -1) {
- return FALSE;
+/****************************************************************
+...
+*****************************************************************/
+static void popdown_cma_preset(struct cma_preset *ppreset)
+{
+ struct cma_dialog *pdialog;
+
+ if ((pdialog = get_cma_preset(ppreset))) {
+ gtk_widget_destroy(pdialog->shell);
}
+}
- if (ev->type == GDK_KEY_PRESS) {
- switch (ev->keyval) {
- case GDK_Delete:
- cma_preset_remove(pdialog, index);
- break;
- default:
- return FALSE;
+/****************************************************************
+ ...
+ *****************************************************************/
+static void update_cma_report_dialog(void)
+{
+ if (cma_shell) {
+ GtkTreeIter it;
+ int i;
+
+ /* Fill preset list */
+ gtk_list_store_clear(cma_store);
+
+ /* Append the presets */
+ for (i = 0; i < cmafec_preset_num(); i++) {
+ struct cma_preset *ppreset = cmafec_ppreset_get(i);
+
+ gtk_list_store_append(cma_store, &it);
+ gtk_list_store_set(cma_store, &it,
+ 0, ppreset->descr, 1, ppreset, -1);
}
- return TRUE;
}
- return FALSE;
}
-
/**************************************************************************
- callback for del_preset
+ refreshes the cma dialog
**************************************************************************/
-static void cma_del_preset_callback(GtkWidget *w, gpointer data)
+static void refresh_cma_preset(struct cma_dialog *pdialog)
{
- struct cma_dialog *pdialog = (struct cma_dialog *) data;
- int index;
+ const struct cm_parameter *param;
+ int i;
+
+ gtk_window_set_title(GTK_WINDOW(pdialog->shell), pdialog->ppreset->descr);
+
+ param = &pdialog->ppreset->parameter;
- if ((index = gtk_tree_selection_get_row(pdialog->selection)) == -1) {
- return;
+ for (i = 0; i < NUM_STATS; i++) {
+ gtk_adjustment_set_value(pdialog->minimal_surplus[i],
+ param->minimal_surplus[i]);
+ gtk_adjustment_set_value(pdialog->factor[i],
+ param->factor[i]);
}
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pdialog->happy_button),
+ param->require_happy);
+ gtk_adjustment_set_value(pdialog->factor[NUM_STATS],
+ param->happy_factor);
+}
+
+/****************************************************************
+...
+*****************************************************************/
+static void cma_preset_destroy(GtkWidget *shell, gpointer data)
+{
+ struct cma_dialog *pdialog = data;
+
+ if (pdialog->ppreset) {
+ delete_cma_preset(pdialog->ppreset);
+ }
+
+ g_object_unref(pdialog->tips);
- cma_preset_remove(pdialog, index);
+ free(pdialog);
+}
+
+/****************************************************************
+ callback for the cma_preset popup
+ *****************************************************************/
+static void cma_preset_response(GtkWidget *w, gint response, gpointer data)
+{
+ if (response == GTK_RESPONSE_OK) {
+ struct cma_dialog *pdialog = data;
+ struct cm_parameter *param;
+ int i;
+
+ param = &pdialog->ppreset->parameter;
+
+ for (i = 0; i < NUM_STATS; i++) {
+ param->minimal_surplus[i] = (int) (pdialog->minimal_surplus[i]->value);
+ param->factor[i] = (int) (pdialog->factor[i]->value);
+ }
+ param->require_happy =
+ (GTK_TOGGLE_BUTTON(pdialog->happy_button)->active ? 1 : 0);
+ param->happy_factor = (int) (pdialog->factor[NUM_STATS]->value);
+ }
+ gtk_widget_destroy(w);
}
/**************************************************************************
- pops up a dialog to remove a preset
+ instantiates a new struct for each city_dialog window that is open.
**************************************************************************/
-static void cma_preset_remove(struct cma_dialog *pdialog, int preset_index)
+static struct cma_dialog *create_cma_preset(struct cma_preset *ppreset)
{
- GtkWidget *parent = gtk_widget_get_toplevel(pdialog->shell), *shl;
+ struct cma_dialog *pdialog;
+ GtkWidget *page, *hbox, *label, *table;
+ GtkWidget *shell, *vbox, *hscale;
+ int i;
+
+ if (!ppreset) {
+ return NULL;
+ }
+
+ pdialog = fc_malloc(sizeof(*pdialog));
+ pdialog->pcity = NULL;
+ pdialog->ppreset = ppreset;
+
+ shell = gtk_dialog_new_with_buttons(NULL,
+ NULL,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OK,
+ GTK_RESPONSE_OK,
+ NULL);
+ setup_dialog(shell, cma_shell);
+ pdialog->shell = shell;
+
+ insert_cma_preset(ppreset, pdialog);
+
+ gtk_window_set_position(GTK_WINDOW(shell), GTK_WIN_POS_CENTER_ON_PARENT);
+ g_signal_connect(shell, "response",
+ G_CALLBACK(cma_preset_response), pdialog);
+ g_signal_connect(shell, "destroy",
+ G_CALLBACK(cma_preset_destroy), pdialog);
+
+ pdialog->tips = gtk_tooltips_new();
+ g_object_ref(pdialog->tips);
+ gtk_object_sink(GTK_OBJECT(pdialog->tips));
+
+ page = gtk_hbox_new(FALSE, 12);
+ gtk_box_pack_start(GTK_BOX(GTK_DIALOG(shell)->vbox), page, TRUE, TRUE, 0);
+
+ /* the right-hand side */
+
+ vbox = gtk_vbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(page), vbox, FALSE, FALSE, 2);
+
+ /* Minimal Surplus and Factor */
+
+ table = gtk_table_new(NUM_STATS + 2, 3, FALSE);
+ gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 2);
+
+ label = gtk_label_new(_("Minimal Surplus"));
+ gtk_misc_set_alignment(GTK_MISC(label), 0.1, 0.5);
+ gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 2, 0, 1);
+ label = gtk_label_new(_("Factor"));
+ gtk_misc_set_alignment(GTK_MISC(label), 0.1, 0.5);
+ gtk_table_attach_defaults(GTK_TABLE(table), label, 2, 3, 0, 1);
- pdialog->id = preset_index;
- shl = gtk_message_dialog_new(NULL,
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_QUESTION,
- GTK_BUTTONS_YES_NO,
- _("Remove this preset?"));
- setup_dialog(shl, parent);
- pdialog->preset_remove_shell = shl;
+ for (i = 0; i < NUM_STATS; i++) {
+ label = gtk_label_new(cm_get_stat_name(i));
+ gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, i + 1, i + 2);
+ gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
- gtk_window_set_title(GTK_WINDOW(shl), cmafec_preset_get_descr(preset_index));
- gtk_window_set_position(GTK_WINDOW(shl), GTK_WIN_POS_CENTER_ON_PARENT);
+ pdialog->minimal_surplus[i] =
+ GTK_ADJUSTMENT(gtk_adjustment_new(-20, -20, 20, 1, 1, 0));
- g_signal_connect(shl, "response",
- G_CALLBACK(cma_preset_remove_response), pdialog);
+ hscale = gtk_hscale_new(GTK_ADJUSTMENT(pdialog->minimal_surplus[i]));
+ gtk_widget_set_size_request(hscale, 100, -1);
+ gtk_table_attach_defaults(GTK_TABLE(table), hscale, 1, 2, i + 1, i + 2);
+ gtk_scale_set_digits(GTK_SCALE(hscale), 0);
+ gtk_scale_set_value_pos(GTK_SCALE(hscale), GTK_POS_LEFT);
+
+ pdialog->factor[i] =
+ GTK_ADJUSTMENT(gtk_adjustment_new(1, 0, 25, 1, 1, 0));
+
+ hscale = gtk_hscale_new(GTK_ADJUSTMENT(pdialog->factor[i]));
+ gtk_widget_set_size_request(hscale, 100, -1);
+ gtk_table_attach_defaults(GTK_TABLE(table), hscale, 2, 3, i + 1, i + 2);
+ gtk_scale_set_digits(GTK_SCALE(hscale), 0);
+ gtk_scale_set_value_pos(GTK_SCALE(hscale), GTK_POS_LEFT);
+ }
- gtk_window_present(GTK_WINDOW(shl));
+ /* Happy Surplus and Factor */
+
+ label = gtk_label_new(_("Celebrate"));
+ gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1,
+ NUM_STATS + 1, NUM_STATS + 2);
+ gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
+
+ hbox = gtk_hbox_new(FALSE, 0);
+ gtk_table_attach_defaults(GTK_TABLE(table), hbox, 1, 2,
+ NUM_STATS + 1, NUM_STATS + 2);
+
+ pdialog->happy_button = gtk_check_button_new();
+ gtk_box_pack_start(GTK_BOX(hbox), pdialog->happy_button, FALSE, FALSE,
+ 20);
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pdialog->happy_button),
+ FALSE);
+
+ pdialog->factor[NUM_STATS] =
+ GTK_ADJUSTMENT(gtk_adjustment_new(0, 0, 50, 1, 0, 0));
+
+ hscale = gtk_hscale_new(GTK_ADJUSTMENT(pdialog->factor[NUM_STATS]));
+ gtk_widget_set_size_request(hscale, 100, -1);
+ gtk_table_attach_defaults(GTK_TABLE(table), hscale, 2, 3,
+ NUM_STATS + 1, NUM_STATS + 2);
+ gtk_scale_set_digits(GTK_SCALE(hscale), 0);
+ gtk_scale_set_value_pos(GTK_SCALE(hscale), GTK_POS_LEFT);
+
+ gtk_widget_show_all(page);
+
+ return pdialog;
}
/****************************************************************
- callback for the remove_preset popup
+...
*****************************************************************/
+static void popup_cma_preset(struct cma_preset *ppreset)
+{
+ struct cma_dialog *pdialog = NULL;
+
+ if (!(pdialog = get_cma_preset(ppreset))) {
+ pdialog = create_cma_preset(ppreset);
+ }
+
+ if (pdialog) {
+ refresh_cma_preset(pdialog);
+ gtk_window_present(GTK_WINDOW(pdialog->shell));
+ }
+}
+
+/****************************************************************
+ callback for the remove_preset popup
+ *****************************************************************/
static void cma_preset_remove_response(GtkWidget *w, gint response,
gpointer data)
{
- struct cma_dialog *pdialog = (struct cma_dialog *) data;
-
if (response == GTK_RESPONSE_YES) {
- cmafec_preset_remove(pdialog->id);
- pdialog->id = -1;
- update_cma_preset_list(pdialog);
- refresh_cma_dialog(pdialog->pcity, DONT_REFRESH_HSCALES);
+ struct cma_preset *ppreset = data;
+
+ popdown_cma_preset(ppreset);
+ cmafec_ppreset_remove(ppreset);
+
+ update_cma_report_dialog();
/* if this or other cities have this set, reset to "custom" */
city_report_dialog_update();
}
gtk_widget_destroy(w);
-
- pdialog->preset_remove_shell = NULL;
}
/**************************************************************************
- changes the workers of the city to the cma parameters
-**************************************************************************/
-static void cma_change_to_callback(GtkWidget *w, gpointer data)
+ pops up a dialog to remove a preset
+ **************************************************************************/
+static void cma_preset_remove(struct cma_preset *ppreset)
{
- struct cm_result result;
- struct cma_dialog *pdialog = (struct cma_dialog *) data;
- struct cm_parameter param;
+ if (!cma_preset_remove_shell) {
+ GtkWidget *shl;
- cmafec_get_fe_parameter(pdialog->pcity, ¶m);
- cm_query_result(pdialog->pcity, ¶m, &result);
- cma_apply_result(pdialog->pcity, &result);
-}
+ shl = gtk_message_dialog_new(NULL,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_YES_NO,
+ _("Remove this preset?"));
+ setup_dialog(shl, cma_shell);
+ cma_preset_remove_shell = shl;
-/**************************************************************************
- changes the workers of the city to the cma parameters and puts the
- city under agent control
-**************************************************************************/
-static void cma_change_permanent_to_callback(GtkWidget *w, gpointer data)
-{
- struct cma_dialog *pdialog = (struct cma_dialog *) data;
- struct cm_parameter param;
+ g_signal_connect(shl, "destroy",
+ G_CALLBACK(gtk_widget_destroyed), &cma_preset_remove_shell);
- cmafec_get_fe_parameter(pdialog->pcity, ¶m);
- cma_put_city_under_agent(pdialog->pcity, ¶m);
- refresh_city_dialog(pdialog->pcity);
+ gtk_window_set_title(GTK_WINDOW(shl), ppreset->descr);
+ gtk_window_set_position(GTK_WINDOW(shl), GTK_WIN_POS_CENTER_ON_PARENT);
+
+ g_signal_connect(shl, "response",
+ G_CALLBACK(cma_preset_remove_response), ppreset);
+ }
+
+ gtk_window_present(GTK_WINDOW(cma_preset_remove_shell));
}
-/**************************************************************************
- releases the city from agent control
-**************************************************************************/
-static void cma_release_callback(GtkWidget *w, gpointer data)
+/****************************************************************
+ ...
+ *****************************************************************/
+static void cma_response(GtkWidget *w, gint response)
{
- struct cma_dialog *pdialog = (struct cma_dialog *) data;
+ int index;
+ GtkTreeSelection *selection;
- cma_release_city(pdialog->pcity);
- refresh_city_dialog(pdialog->pcity);
+ selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(cma_list));
+
+ index = gtk_tree_selection_get_row(selection);
+
+ switch (response) {
+ case CMA_NEW:
+ {
+ const char *default_name;
+ struct cm_parameter param;
+
+ default_name = _("new preset");
+
+ cm_init_parameter(¶m);
+ cmafec_preset_add(default_name, ¶m);
+
+ update_cma_report_dialog();
+ }
+ return;
+
+ case CMA_DELETE:
+ if (index != -1) {
+ cma_preset_remove(cmafec_ppreset_get(index));
+ }
+ return;
+
+ case CMA_PROPERTIES:
+ if (index != -1) {
+ popup_cma_preset(cmafec_ppreset_get(index));
+ }
+ return;
+
+ default:
+ gtk_widget_destroy(w);
+ return;
+ }
}
/****************************************************************
- called to adjust the sliders when a preset is selected
- notice that we don't want to call update_result here.
+...
*****************************************************************/
-static void set_hscales(const struct cm_parameter *const parameter,
- struct cma_dialog *pdialog)
+static void cell_edited(GtkCellRendererText *cell,
+ const gchar *spath,
+ const gchar *text, gpointer data)
{
- int i;
+ GtkTreePath *path;
+ GtkTreeIter it;
+ struct cma_preset *ppreset;
- allow_refreshes = 0;
- for (i = 0; i < NUM_STATS; i++) {
- gtk_adjustment_set_value(pdialog->minimal_surplus[i],
- parameter->minimal_surplus[i]);
- gtk_adjustment_set_value(pdialog->factor[i], parameter->factor[i]);
- }
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pdialog->happy_button),
- parameter->require_happy);
- gtk_adjustment_set_value(pdialog->factor[NUM_STATS],
- parameter->happy_factor);
- allow_refreshes = 1;
+ path = gtk_tree_path_new_from_string(spath);
+ gtk_tree_model_get_iter(GTK_TREE_MODEL(cma_store), &it, path);
+
+ gtk_tree_model_get(GTK_TREE_MODEL(cma_store), &it, 1, &ppreset, -1);
+
+ cmafec_ppreset_set_descr(ppreset, text);
+ gtk_list_store_set(cma_store, &it, 0, text, -1);
+
+ gtk_tree_path_free(path);
}
-/************************************************************************
- callback if we moved the sliders.
-*************************************************************************/
-static void hscale_changed(GtkAdjustment *get, gpointer data)
+/****************************************************************
+ Bring up the global worklist report.
+*****************************************************************/
+static GtkWidget *create_cma_report(void)
{
- struct cma_dialog *pdialog = (struct cma_dialog *) data;
- struct cm_parameter param;
- int i;
+ GtkWidget *shell, *list;
+ GtkWidget *vbox, *label, *sw;
+ GtkCellRenderer *rend;
- if (!allow_refreshes) {
- return;
- }
+ shell = gtk_dialog_new_with_buttons(_("Edit CMA Presets"),
+ NULL,
+ 0,
+ GTK_STOCK_NEW,
+ CMA_NEW,
+ GTK_STOCK_DELETE,
+ CMA_DELETE,
+ GTK_STOCK_PROPERTIES,
+ CMA_PROPERTIES,
+ GTK_STOCK_CLOSE,
+ CMA_CLOSE,
+ NULL);
+ cma_shell = shell;
+
+ setup_dialog(shell, NULL);
+ gtk_window_set_position(GTK_WINDOW(shell), GTK_WIN_POS_MOUSE);
+
+ g_signal_connect(shell, "response",
+ G_CALLBACK(cma_response), NULL);
+ g_signal_connect(shell, "destroy",
+ G_CALLBACK(gtk_widget_destroyed), &cma_shell);
- cmafec_get_fe_parameter(pdialog->pcity, ¶m);
- for (i = 0; i < NUM_STATS; i++) {
- param.minimal_surplus[i] = (int) (pdialog->minimal_surplus[i]->value);
- param.factor[i] = (int) (pdialog->factor[i]->value);
- }
- param.require_happy =
- (GTK_TOGGLE_BUTTON(pdialog->happy_button)->active ? 1 : 0);
- param.happy_factor = (int) (pdialog->factor[NUM_STATS]->value);
+ vbox = gtk_vbox_new(FALSE, 2);
+ gtk_container_add(GTK_CONTAINER(GTK_DIALOG(shell)->vbox), vbox);
- /* save the change */
- cmafec_set_fe_parameter(pdialog->pcity, ¶m);
+ cma_store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_POINTER);
- /* refreshes the cma */
- if (cma_is_city_under_agent(pdialog->pcity, NULL)) {
- cma_release_city(pdialog->pcity);
- cma_put_city_under_agent(pdialog->pcity, ¶m);
-
- /* 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 city refreshes cma */
- } else {
- city_report_dialog_update_city(pdialog->pcity);
- }
+ list = gtk_tree_view_new_with_model(GTK_TREE_MODEL(cma_store));
+ g_object_unref(cma_store);
+ gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(list), FALSE);
+
+ cma_list = list;
+
+ rend = gtk_cell_renderer_text_new();
+
+ g_object_set(rend, "editable", TRUE, NULL);
+ g_signal_connect(rend, "edited",
+ G_CALLBACK(cell_edited), NULL);
+
+ gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(list), -1, NULL,
+ rend, "text", 0, NULL);
+
+ sw = gtk_scrolled_window_new(NULL, NULL);
+ gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
+ GTK_SHADOW_ETCHED_IN);
+ gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
+ GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
+ gtk_container_add(GTK_CONTAINER(sw), list);
+
+ gtk_widget_set_size_request(sw, -1, 200);
+
+ label = g_object_new(GTK_TYPE_LABEL,
+ "use-underline", TRUE,
+ "mnemonic-widget", list,
+ "label", _("C_MA Presets:"),
+ "xalign", 0.0, "yalign", 0.5, NULL);
+
+ gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0);
+ gtk_widget_show_all(vbox);
+
+ return shell;
+}
+
+/****************************************************************
+...
+*****************************************************************/
+void popup_cma_report(void)
+{
+ if (!cma_shell) {
+ cma_shell = create_cma_report();
+
+ update_cma_report_dialog();
}
- refresh_cma_dialog(pdialog->pcity, DONT_REFRESH_HSCALES);
+ gtk_window_present(GTK_WINDOW(cma_shell));
}
+
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 -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 4 Dec 2004 20:45:33 -0000
@@ -18,13 +18,10 @@
#include "cma_core.h"
-struct city;
+#define CMA_NONE (-1)
+#define CMA_CUSTOM (-2)
-enum cma_refresh {
- REFRESH_ALL,
- DONT_REFRESH_SELECT,
- DONT_REFRESH_HSCALES
-};
+struct city;
struct cma_dialog {
struct city *pcity;
@@ -33,8 +30,7 @@
GtkWidget *preset_remove_shell;
GtkWidget *preset_list;
GtkWidget *result_label;
- GtkWidget *add_preset_command;
- GtkWidget *del_preset_command;
+ GtkWidget *edit_presets_command;
GtkWidget *change_command;
GtkWidget *perm_command;
GtkWidget *release_command;
@@ -45,10 +41,13 @@
GtkTreeSelection *selection;
GtkListStore *store;
int id; /* needed to pass a preset_index */
+ struct cma_preset *ppreset;
};
struct cma_dialog *create_cma_dialog(struct city *pcity);
void close_cma_dialog(struct city *pcity);
-void refresh_cma_dialog(struct city *pcity, enum cma_refresh refresh);
+void refresh_cma_dialog(struct city *pcity);
+
+void popup_cma_report(void);
#endif
Index: client/gui-gtk-2.0/gui_stuff.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/gui_stuff.c,v
retrieving revision 1.14.2.5
diff -u -u -r1.14.2.5 gui_stuff.c
--- client/gui-gtk-2.0/gui_stuff.c 23 Nov 2004 22:00:04 -0000 1.14.2.5
+++ client/gui-gtk-2.0/gui_stuff.c 4 Dec 2004 20:45:33 -0000
@@ -252,10 +252,12 @@
void setup_dialog(GtkWidget *shell, GtkWidget *parent)
{
if (dialogs_on_top || fullscreen_mode) {
- gtk_window_set_transient_for(GTK_WINDOW(shell),
- GTK_WINDOW(parent));
- gtk_window_set_type_hint(GTK_WINDOW(shell),
- GDK_WINDOW_TYPE_HINT_UTILITY);
+ if (parent) {
+ gtk_window_set_transient_for(GTK_WINDOW(shell),
+ GTK_WINDOW(parent));
+ gtk_window_set_type_hint(GTK_WINDOW(shell),
+ GDK_WINDOW_TYPE_HINT_UTILITY);
+ }
} else {
gtk_window_set_type_hint(GTK_WINDOW(shell),
GDK_WINDOW_TYPE_HINT_NORMAL);
Index: client/gui-gtk-2.0/menu.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/menu.c,v
retrieving revision 1.43.2.13
diff -u -u -r1.43.2.13 menu.c
--- client/gui-gtk-2.0/menu.c 23 Nov 2004 17:36:56 -0000 1.43.2.13
+++ client/gui-gtk-2.0/menu.c 4 Dec 2004 20:45:33 -0000
@@ -36,6 +36,7 @@
#include "clinet.h"
#include "connectdlg_common.h"
#include "connectdlg.h"
+#include "cma_fe.h"
#include "control.h"
#include "dialogs.h"
#include "finddlg.h"
@@ -87,6 +88,7 @@
MENU_GOVERNMENT_TAX_RATE,
MENU_GOVERNMENT_FIND_CITY,
MENU_GOVERNMENT_WORKLISTS,
+ MENU_GOVERNMENT_CMA_PRESETS,
MENU_GOVERNMENT_REVOLUTION,
MENU_VIEW_SHOW_MAP_GRID,
@@ -261,6 +263,9 @@
case MENU_GOVERNMENT_WORKLISTS:
popup_worklists_report();
break;
+ case MENU_GOVERNMENT_CMA_PRESETS:
+ popup_cma_report();
+ break;
case MENU_GOVERNMENT_REVOLUTION:
popup_revolution_dialog(-1);
break;
@@ -673,9 +678,14 @@
NULL, 0,
"<Separator>" },
{ "/" N_("Government") "/" N_("_Find City"), "<shift>f",
government_menu_callback, MENU_GOVERNMENT_FIND_CITY
},
+ { "/" N_("Government") "/sep2", NULL,
+ NULL, 0,
"<Separator>" },
{ "/" N_("Government") "/" N_("_Worklists"), "<control>l",
government_menu_callback, MENU_GOVERNMENT_WORKLISTS
},
- { "/" N_("Government") "/sep2", NULL,
+ { "/" N_("Government") "/" N_("CMA _Presets"), "<control>c",
+ government_menu_callback, MENU_GOVERNMENT_CMA_PRESETS
+ },
+ { "/" N_("Government") "/sep3", NULL,
NULL, 0,
"<Separator>" },
{ "/" N_("Government") "/" N_("_Change Government"), NULL,
NULL, 0,
"<Branch>" },
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#11335) [PATCH] New CMA dialogs,
Vasco Alexandre da Silva Costa <=
|
|