[Freeciv-Dev] (PR#13769) gui-xaw: implement settable options dialog
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: |
[Freeciv-Dev] (PR#13769) gui-xaw: implement settable options dialog |
From: |
"Egor Vyscrebentsov" <evyscr@xxxxxxxxx> |
Date: |
Wed, 24 Aug 2005 17:03:19 -0700 |
Reply-to: |
bugs@xxxxxxxxxxx |
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13769 >
Good daytime!
Attached patch implements settable options dialog for gui-xaw.
This dialog has not support categories, however.
Thanks, evyscr.
Index: client/gui-xaw/actions.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/actions.c,v
retrieving revision 1.30
diff -u -r1.30 actions.c
--- client/gui-xaw/actions.c 21 Aug 2005 20:00:00 -0000 1.30
+++ client/gui-xaw/actions.c 24 Aug 2005 23:58:38 -0000
@@ -708,6 +708,15 @@
sciencereport_msg_close(w);
}
+/****************************************************************************
+ Action for msg-close-settable-options
+****************************************************************************/
+static void xaw_msg_close_settable_options(Widget w, XEvent *event,
+ String *argv, Cardinal *argc)
+{
+ settable_options_msg_close(w);
+}
+
static void xaw_msg_close_spaceship(Widget w, XEvent *event, String *argv,
Cardinal *argc)
{
spaceshipdlg_msg_close(w);
@@ -823,6 +832,7 @@
{ "msg-close-intel", xaw_msg_close_intel },
{ "msg-close-intel-diplo", xaw_msg_close_intel_diplo },
{ "msg-close-science-report", xaw_msg_close_science_report },
+ { "msg-close-settable-options", xaw_msg_close_settable_options },
{ "msg-close-spaceship", xaw_msg_close_spaceship },
{ "msg-close-units-report", xaw_msg_close_units_report },
{ "msg-close-start-page", xaw_msg_close_start_page },
Index: client/gui-xaw/repodlgs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/repodlgs.c,v
retrieving revision 1.73
diff -u -r1.73 repodlgs.c
--- client/gui-xaw/repodlgs.c 28 Jul 2005 18:03:59 -0000 1.73
+++ client/gui-xaw/repodlgs.c 24 Aug 2005 23:58:39 -0000
@@ -23,37 +23,50 @@
#include <X11/Intrinsic.h>
#include <X11/Shell.h>
#include <X11/StringDefs.h>
+#include <X11/Xaw/AsciiText.h>
+#include <X11/Xaw/Command.h>
#include <X11/Xaw/Form.h>
#include <X11/Xaw/Label.h>
-#include <X11/Xaw/SimpleMenu.h>
-#include <X11/Xaw/Command.h>
#include <X11/Xaw/List.h>
#include <X11/Xaw/MenuButton.h>
+#include <X11/Xaw/SimpleMenu.h>
#include <X11/Xaw/SmeBSB.h>
#include <X11/Xaw/Toggle.h>
+#include <X11/Xaw/Viewport.h>
-#include "city.h"
#include "fcintl.h"
+#include "shared.h"
+#include "support.h"
+
+#include "city.h"
#include "game.h"
#include "government.h"
#include "packets.h"
-#include "shared.h"
-#include "support.h"
-#include "cityrep.h"
+#include "chatline_common.h" /* for send_chat() */
#include "climisc.h"
#include "clinet.h"
+#include "text.h"
+
+#include "cityrep.h"
#include "dialogs.h"
#include "gui_main.h"
#include "gui_stuff.h"
#include "helpdlg.h"
#include "optiondlg.h"
-#include "text.h"
-#include "repodlgs.h"
#include "repodlgs_common.h"
+#include "repodlgs.h"
/******************************************************************/
+static Widget science_dialog_shell;
+static Widget science_label;
+static Widget science_current_label, science_goal_label;
+static Widget science_change_menu_button, science_goal_menu_button;
+static Widget science_list, science_help_toggle;
+static Widget science_help_note;
+static Widget popupmenu, goalmenu;
+static int science_dialog_shell_is_modal;
void create_science_dialog(bool make_modal);
void science_close_callback(Widget w, XtPointer client_data,
@@ -67,16 +80,13 @@
/******************************************************************/
-static Widget science_dialog_shell;
-static Widget science_label;
-static Widget science_current_label, science_goal_label;
-static Widget science_change_menu_button, science_goal_menu_button;
-static Widget science_list, science_help_toggle;
-static Widget science_help_note;
-static int science_dialog_shell_is_modal;
-static Widget popupmenu, goalmenu;
+static Widget economy_dialog_shell;
+static Widget economy_label, economy_label2;
+static Widget economy_list, economy_list_label;
+static Widget sellall_command, sellobsolete_command;
+static int economy_dialog_shell_is_modal;
+static int economy_improvement_type[B_LAST];
-/******************************************************************/
void create_economy_report_dialog(bool make_modal);
void economy_close_callback(Widget w, XtPointer client_data,
XtPointer call_data);
@@ -84,15 +94,15 @@
XtPointer call_data);
void economy_list_callback(Widget w, XtPointer client_data,
XtPointer call_data);
-static int economy_improvement_type[B_LAST];
-
-static Widget economy_dialog_shell;
-static Widget economy_label, economy_label2;
-static Widget economy_list, economy_list_label;
-static Widget sellall_command, sellobsolete_command;
-static int economy_dialog_shell_is_modal;
/******************************************************************/
+static Widget activeunits_dialog_shell;
+static Widget activeunits_label, activeunits_label2;
+static Widget activeunits_list, activeunits_list_label;
+static Widget upgrade_command;
+static int activeunits_dialog_shell_is_modal;
+static int activeunits_type[U_LAST];
+
void create_activeunits_report_dialog(bool make_modal);
void activeunits_close_callback(Widget w, XtPointer client_data,
XtPointer call_data);
@@ -102,15 +112,24 @@
XtPointer call_data);
void activeunits_list_callback(Widget w, XtPointer client_data,
XtPointer call_data);
-static int activeunits_type[U_LAST];
-
-static Widget activeunits_dialog_shell;
-static Widget activeunits_label, activeunits_label2;
-static Widget activeunits_list, activeunits_list_label;
-static Widget upgrade_command;
-
-static int activeunits_dialog_shell_is_modal;
/******************************************************************/
+static Widget settable_options_dialog_shell;
+static Widget settable_options_form;
+static Widget settable_options_label;
+static Widget settable_options_viewport;
+static Widget settable_options_scrollform;
+static Widget *settable_options_widgets = NULL;
+static Widget settable_options_ok_command;
+static Widget settable_options_cancel_command;
+
+void create_settable_options_dialog(void);
+void update_settable_options_dialog(void);
+void settable_options_toggle_callback(Widget w, XtPointer client_data,
+ XtPointer call_data);
+void settable_options_ok_callback(Widget w, XtPointer client_data,
+ XtPointer call_data);
+void settable_options_cancel_callback(Widget w, XtPointer client_data,
+ XtPointer call_data);
/******************************************************************
...
@@ -1159,10 +1178,329 @@
buffer);
}
-/*************************************************************************
- Server options dialog
-*************************************************************************/
+/****************************************************************************
+ SERVER OPTIONS DIALOG
+****************************************************************************/
+
+/****************************************************************************
+ Show a dialog with the server options.
+****************************************************************************/
void popup_settable_options_dialog(void)
{
- /* PORT ME */
+ if (!settable_options_dialog_shell) {
+ create_settable_options_dialog();
+ }
+
+ update_settable_options_dialog();
+
+ XtPopup(settable_options_dialog_shell, XtGrabNone);
+}
+
+/****************************************************************************
+ Popdown server options dialog.
+****************************************************************************/
+void popdown_settable_options_dialog(void)
+{
+ if (settable_options_dialog_shell) {
+ XtDestroyWidget(settable_options_dialog_shell);
+ settable_options_dialog_shell = NULL;
+ }
+}
+
+/****************************************************************************
+ Server options dialog.
+****************************************************************************/
+void create_settable_options_dialog(void)
+{
+ Widget prev_widget, longest_label = NULL;
+ size_t longest_len = 0;
+ Dimension width;
+ int i;
+
+ settable_options_dialog_shell =
+ I_T(XtCreatePopupShell("settableoptionspopup", transientShellWidgetClass,
+ toplevel, NULL, 0));
+ settable_options_form =
+ XtVaCreateManagedWidget("settableoptionsform", formWidgetClass,
+ settable_options_dialog_shell, NULL);
+
+ settable_options_label =
+ I_L(XtVaCreateManagedWidget("settableoptionslabel", labelWidgetClass,
+ settable_options_form, NULL));
+
+ settable_options_viewport =
+ XtVaCreateManagedWidget("settableoptionsviewport", viewportWidgetClass,
+ settable_options_form, NULL);
+ settable_options_scrollform =
+ XtVaCreateManagedWidget("settableoptionsscrollform", formWidgetClass,
+ settable_options_viewport, NULL);
+
+ if (!settable_options_widgets) {
+ settable_options_widgets = fc_calloc(num_settable_options, sizeof(Widget));
+ }
+
+ prev_widget = NULL; /* init the prev-Widget */
+
+ for (i = 0; i < num_settable_options; i++) {
+ char buf[256];
+ size_t len;
+
+ my_snprintf(buf, sizeof(buf), "%s: %s", settable_options[i].name,
+ _(settable_options[i].short_help));
+ len = strlen(buf);
+
+ /*
+ * Remember widget so we can reset the vertical position.
+ */
+ settable_options_widgets[i] = prev_widget;
+
+ if (prev_widget) {
+ prev_widget =
+ XtVaCreateManagedWidget("label", labelWidgetClass,
+ settable_options_scrollform,
+ XtNlabel, buf,
+ XtNfromVert, prev_widget,
+ NULL);
+ } else {
+ prev_widget =
+ XtVaCreateManagedWidget("label", labelWidgetClass,
+ settable_options_scrollform,
+ XtNlabel, buf,
+ NULL);
+ }
+
+ if (len > longest_len) {
+ longest_len = len;
+ longest_label = prev_widget;
+ }
+
+ /*
+ * The addition of a scrollbar screws things up. There must be a
+ * better way to do this.
+ */
+ XtVaGetValues(prev_widget, XtNwidth, &width, NULL);
+ XtVaSetValues(prev_widget, XtNwidth, width + 15, NULL);
+ }
+
+ XtVaGetValues(longest_label, XtNwidth, &width, NULL);
+ XtVaSetValues(settable_options_label, XtNwidth, width + 15, NULL);
+
+ for (i = 0; i < num_settable_options; i++) {
+ if (setting_class_is_changeable(settable_options[i].class)
+ && settable_options[i].is_visible) {
+ switch (settable_options[i].type) {
+ case SSET_BOOL:
+ if (settable_options_widgets[i]) {
+ prev_widget =
+ XtVaCreateManagedWidget("toggle", toggleWidgetClass,
+ settable_options_scrollform,
+ XtNfromHoriz, settable_options_label,
+ XtNfromVert, settable_options_widgets[i],
+ NULL);
+ } else {
+ prev_widget =
+ XtVaCreateManagedWidget("toggle", toggleWidgetClass,
+ settable_options_scrollform,
+ XtNfromHoriz, settable_options_label,
+ NULL);
+ }
+ XtAddCallback(prev_widget, XtNcallback,
+ settable_options_toggle_callback, NULL);
+ break;
+ case SSET_INT:
+ case SSET_STRING:
+ if (settable_options_widgets[i]) {
+ prev_widget =
+ XtVaCreateManagedWidget("input", asciiTextWidgetClass,
+ settable_options_scrollform,
+ XtNfromHoriz, settable_options_label,
+ XtNfromVert, settable_options_widgets[i],
+ NULL);
+ } else {
+ prev_widget =
+ XtVaCreateManagedWidget("input", asciiTextWidgetClass,
+ settable_options_scrollform,
+ XtNfromHoriz, settable_options_label,
+ NULL);
+ }
+ break;
+ }
+
+ } else {
+ if (settable_options_widgets[i]) {
+ prev_widget =
+ XtVaCreateManagedWidget("rlabel", labelWidgetClass,
+ settable_options_scrollform,
+ XtNfromHoriz, settable_options_label,
+ XtNfromVert, settable_options_widgets[i],
+ NULL);
+ } else {
+ prev_widget =
+ XtVaCreateManagedWidget("rlabel", labelWidgetClass,
+ settable_options_scrollform,
+ XtNfromHoriz, settable_options_label,
+ NULL);
+ }
+ }
+ /* store the final widget */
+ settable_options_widgets[i] = prev_widget;
+ }
+
+ settable_options_ok_command =
+ I_L(XtVaCreateManagedWidget("settableoptionsokcommand",
+ commandWidgetClass,
+ settable_options_form,
+ NULL));
+
+ settable_options_cancel_command =
+ I_L(XtVaCreateManagedWidget("settableoptionscancelcommand",
+ commandWidgetClass,
+ settable_options_form,
+ NULL));
+
+ XtAddCallback(settable_options_ok_command, XtNcallback,
+ settable_options_ok_callback, NULL);
+ XtAddCallback(settable_options_cancel_command, XtNcallback,
+ settable_options_cancel_callback, NULL);
+
+ XtRealizeWidget(settable_options_dialog_shell);
+
+ XSetWMProtocols(display, XtWindow(settable_options_dialog_shell),
+ &wm_delete_window, 1);
+ XtOverrideTranslations(settable_options_dialog_shell,
+ XtParseTranslationTable("<Message>WM_PROTOCOLS:
msg-close-settable-options()"));
+
+ xaw_horiz_center(settable_options_label);
+}
+
+/****************************************************************************
+ Update server options dialog.
+****************************************************************************/
+void update_settable_options_dialog(void)
+{
+ if (settable_options_dialog_shell) {
+ char buf[256];
+ int i;
+
+ for (i = 0; i < num_settable_options; i++) {
+ if (setting_class_is_changeable(settable_options[i].class)
+ && settable_options[i].is_visible) {
+ switch (settable_options[i].type) {
+ case SSET_BOOL:
+ XtVaSetValues(settable_options_widgets[i],
+ XtNstate, settable_options[i].val ? True : False,
+ XtNlabel,
+ settable_options[i].val ? _("Yes") : _("No"), NULL);
+ break;
+ case SSET_INT:
+ my_snprintf(buf, sizeof(buf), "%d", settable_options[i].val);
+ XtVaSetValues(settable_options_widgets[i], XtNstring, buf, NULL);
+ break;
+ case SSET_STRING:
+ my_snprintf(buf, sizeof(buf), "%s", settable_options[i].strval);
+ XtVaSetValues(settable_options_widgets[i], XtNstring, buf, NULL);
+ break;
+ }
+ } else {
+ if (settable_options[i].is_visible) {
+ switch (settable_options[i].type) {
+ case SSET_BOOL:
+ my_snprintf(buf, sizeof(buf), "%s",
+ settable_options[i].val != 0 ? _("true") : _("false"));
+ break;
+ case SSET_INT:
+ my_snprintf(buf, sizeof(buf), "%d", settable_options[i].val);
+ break;
+ case SSET_STRING:
+ my_snprintf(buf, sizeof(buf), "%s", settable_options[i].strval);
+ break;
+ }
+ } else {
+ my_snprintf(buf, sizeof(buf), _("(hidden)"));
+ }
+ XtVaSetValues(settable_options_widgets[i], XtNlabel, buf, NULL);
+ }
+ }
+ }
+}
+
+/****************************************************************************
+ Changes the label of the toggle widget to Yes/No depending on the state of
+ the toggle.
+****************************************************************************/
+void settable_options_toggle_callback(Widget w, XtPointer client_data,
+ XtPointer call_data)
+{
+ Boolean b;
+
+ XtVaGetValues(w, XtNstate, &b, NULL);
+ XtVaSetValues(w, XtNlabel, b ? _("Yes") : _("No"), NULL);
+}
+
+/****************************************************************************
+ OK button callback.
+****************************************************************************/
+void settable_options_ok_callback(Widget w, XtPointer client_data,
+ XtPointer call_data)
+{
+ if (settable_options_dialog_shell) {
+ Boolean b, old_b;
+ int val, i;
+ XtPointer dp;
+
+ for (i = 0; i < num_settable_options; i++) {
+ if (setting_class_is_changeable(settable_options[i].class)
+ && settable_options[i].is_visible) {
+ char buffer[MAX_LEN_MSG];
+
+ switch (settable_options[i].type) {
+ case SSET_BOOL:
+ old_b = settable_options[i].val ? True: False;
+ XtVaGetValues(settable_options_widgets[i], XtNstate, &b, NULL);
+ if (b != old_b) {
+ my_snprintf(buffer, MAX_LEN_MSG, "/set %s %s",
+ settable_options[i].name, b ? "1" : "0");
+ send_chat(buffer);
+ }
+ break;
+ case SSET_INT:
+ XtVaGetValues(settable_options_widgets[i], XtNstring, &dp, NULL);
+ sscanf(dp, "%d", &val);
+ if (val != settable_options[i].val) {
+ my_snprintf(buffer, MAX_LEN_MSG, "/set %s %d",
+ settable_options[i].name, val);
+ send_chat(buffer);
+ }
+ break;
+ case SSET_STRING:
+ XtVaGetValues(settable_options_widgets[i], XtNstring, &dp, NULL);
+ if (strcmp(settable_options[i].strval, dp)) {
+ my_snprintf(buffer, MAX_LEN_MSG, "/set %s %s",
+ settable_options[i].name, (char *)dp);
+ send_chat(buffer);
+ }
+ break;
+ }
+ }
+ }
+
+ popdown_settable_options_dialog();
+ }
+}
+
+/****************************************************************************
+ Cancel button callback.
+****************************************************************************/
+void settable_options_cancel_callback(Widget w, XtPointer client_data,
+ XtPointer call_data)
+{
+ popdown_settable_options_dialog();
+}
+
+/****************************************************************************
+ Callback for overrided wm_delete_window of server options dialog.
+****************************************************************************/
+void settable_options_msg_close(Widget w)
+{
+ popdown_settable_options_dialog();
}
Index: client/gui-xaw/repodlgs.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/repodlgs.h,v
retrieving revision 1.11
diff -u -r1.11 repodlgs.h
--- client/gui-xaw/repodlgs.h 13 May 2004 18:14:22 -0000 1.11
+++ client/gui-xaw/repodlgs.h 24 Aug 2005 23:58:39 -0000
@@ -20,10 +20,12 @@
void popdown_science_dialog(void);
void popdown_economy_report_dialog(void);
void popdown_activeunits_report_dialog(void);
+void popdown_settable_options_dialog(void);
void activeunits_msg_close(Widget w);
void sciencereport_msg_close(Widget w);
void economyreport_msg_close(Widget w);
+void settable_options_msg_close(Widget w);
const char *get_centered_report_title(const char *report_name);
#endif /* FC__REPODLGS_H */
Index: data/Freeciv.in
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/Freeciv.in,v
retrieving revision 1.10
diff -u -r1.10 Freeciv.in
--- data/Freeciv.in 24 Aug 2005 19:19:52 -0000 1.10
+++ data/Freeciv.in 24 Aug 2005 23:58:39 -0000
@@ -3396,3 +3396,41 @@
Freeciv*startpagestartcommand.left: chainLeft
Freeciv*startpagestartcommand.right: chainLeft
+!
+! Settable options dialog
+!
+Freeciv*settableoptionspopup.title: _("Game Settings")
+
+Freeciv*settableoptionspopup*Label.background: gray84
+
+Freeciv*settableoptionspopup*Toggle.background: white
+Freeciv*settableoptionspopup*Toggle.shapeStyle: oval
+Freeciv*settableoptionspopup*Toggle.width: 50
+Freeciv*settableoptionspopup*Toggle.internalHeight: 0
+
+Freeciv*settableoptionslabel.label: _("Game Settings")
+Freeciv*settableoptionslabel.borderWidth: 0
+
+Freeciv*settableoptionsviewport.fromVert: settableoptionslabel
+Freeciv*settableoptionsviewport.height: 510
+Freeciv*settableoptionsviewport.useRight: True
+Freeciv*settableoptionsviewport.allowVert: True
+
+! dummy labels:
+Freeciv*settableoptionspopup*label.label: XXXXXXXXXXXXXXXXXXXXXXXXXXX
+Freeciv*settableoptionspopup*label.borderWidth: 0
+
+Freeciv*settableoptionspopup*input.*.foreground: black
+Freeciv*settableoptionspopup*input.*.background: white
+Freeciv*settableoptionspopup*input.width: 120
+Freeciv*settableoptionspopup*input.*.editType: edit
+
+Freeciv*settableoptionspopup*rlabel.width: 120
+Freeciv*settableoptionspopup*rlabel.borderWidth: 1
+
+Freeciv*settableoptionsokcommand.label: _("Ok")
+Freeciv*settableoptionsokcommand.fromVert: settableoptionsviewport
+
+Freeciv*settableoptionscancelcommand.label: _("Cancel")
+Freeciv*settableoptionscancelcommand.fromHoriz: settableoptionsokcommand
+Freeciv*settableoptionscancelcommand.fromVert: settableoptionsviewport
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#13769) gui-xaw: implement settable options dialog,
Egor Vyscrebentsov <=
|
|