| 1 |
/* |
| 2 |
Copyright (C) 2002/2004/2007 Kai Sterker <[email protected]> |
| 3 |
Part of the Adonthell Project <http://adonthell.nongnu.org> |
| 4 |
|
| 5 |
Dlgedit is free software; you can redistribute it and/or modify |
| 6 |
it under the terms of the GNU General Public License as published by |
| 7 |
the Free Software Foundation; either version 2 of the License, or |
| 8 |
(at your option) any later version. |
| 9 |
|
| 10 |
Dlgedit is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
GNU General Public License for more details. |
| 14 |
|
| 15 |
You should have received a copy of the GNU General Public License |
| 16 |
along with Dlgedit. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
|
| 19 |
#include <string.h> |
| 20 |
#include "gui_circle.h" |
| 21 |
#include "gui_circle_events.h" |
| 22 |
|
| 23 |
/** |
| 24 |
* @file gui_circle.cc |
| 25 |
* |
| 26 |
* @author Kai Sterker |
| 27 |
* @brief The Edit Circle window |
| 28 |
*/ |
| 29 |
|
| 30 |
static gint sort_strings (GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer unused) |
| 31 |
{ |
| 32 |
GValue val_a = {0}; |
| 33 |
GValue val_b = {0}; |
| 34 |
|
| 35 |
gtk_tree_model_get_value (model, a, 0, &val_a); |
| 36 |
gtk_tree_model_get_value (model, b, 0, &val_b); |
| 37 |
|
| 38 |
// sort "Default" entry to the top of the list |
| 39 |
if (strcmp ("Default", g_value_get_string (&val_a)) == 0) return -1; |
| 40 |
if (strcmp ("Default", g_value_get_string (&val_b)) == 0) return 1; |
| 41 |
|
| 42 |
return strcmp(g_value_get_string (&val_a), g_value_get_string (&val_b)); |
| 43 |
} |
| 44 |
|
| 45 |
GuiCircle::GuiCircle (GtkWindow *parent, node_type *t, DlgCircleEntry *e, DlgModuleEntry *dme) : GuiModalDialog (parent) |
| 46 |
{ |
| 47 |
entry = e; |
| 48 |
type = t; |
| 49 |
|
| 50 |
GtkWidget *vbox1; |
| 51 |
GtkWidget *notebook1; |
| 52 |
GtkWidget *vbox2; |
| 53 |
GtkWidget *scrolledwindow; |
| 54 |
GtkWidget *label; |
| 55 |
GSList *character_group = NULL; |
| 56 |
GtkWidget *player_button; |
| 57 |
GtkWidget *narrator_button; |
| 58 |
GtkWidget *hbox1; |
| 59 |
GtkWidget *npc_button; |
| 60 |
GtkWidget *npc_mood; |
| 61 |
GtkWidget *frame1; |
| 62 |
GtkWidget *hbuttonbox1; |
| 63 |
GtkWidget *ok_button; |
| 64 |
GtkWidget *cancel_button; |
| 65 |
GtkWidget *ebox; |
| 66 |
GtkWidget *text_view; |
| 67 |
GtkWidget *annotation_view; |
| 68 |
|
| 69 |
// color to use for Player and Narrator text and labels |
| 70 |
GdkColor dark_blue = { 0, 0, 0, 35000 }; |
| 71 |
GdkColor green = { 0, 0, 27300, 15600 }; |
| 72 |
GdkColor dark_green = { 0, 0, 27500, 0 }; |
| 73 |
|
| 74 |
GtkStyle *style = NULL; |
| 75 |
|
| 76 |
// the "Edit Dialogue Node" window |
| 77 |
window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
| 78 |
g_object_set_data (G_OBJECT (window), "window", window); |
| 79 |
gtk_widget_set_size_request (window, 400, 320); |
| 80 |
gtk_window_set_title (GTK_WINDOW (window), "Edit Dialogue Node"); |
| 81 |
gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_MOUSE); |
| 82 |
gtk_window_set_modal (GTK_WINDOW (window), TRUE); |
| 83 |
gtk_window_set_resizable (GTK_WINDOW (window), FALSE); |
| 84 |
|
| 85 |
vbox1 = gtk_vbox_new (FALSE, 0); |
| 86 |
g_object_ref (vbox1); |
| 87 |
g_object_set_data_full (G_OBJECT (window), "vbox1", vbox1, (GDestroyNotify) g_object_unref); |
| 88 |
gtk_widget_show (vbox1); |
| 89 |
gtk_container_add (GTK_CONTAINER (window), vbox1); |
| 90 |
|
| 91 |
// the GtkNotebook with the different 'pages' of the window |
| 92 |
notebook1 = gtk_notebook_new (); |
| 93 |
g_object_ref (notebook1); |
| 94 |
g_object_set_data_full (G_OBJECT (window), "notebook1", notebook1, (GDestroyNotify) g_object_unref); |
| 95 |
gtk_widget_show (notebook1); |
| 96 |
gtk_box_pack_start (GTK_BOX (vbox1), notebook1, TRUE, TRUE, 0); |
| 97 |
gtk_notebook_set_show_border (GTK_NOTEBOOK (notebook1), FALSE); |
| 98 |
gtk_widget_set_can_focus (notebook1, FALSE); |
| 99 |
|
| 100 |
// Page 1: Edit Text |
| 101 |
vbox2 = gtk_vbox_new (FALSE, 0); |
| 102 |
g_object_ref (vbox2); |
| 103 |
g_object_set_data_full (G_OBJECT (window), "vbox2", vbox2, (GDestroyNotify) g_object_unref); |
| 104 |
gtk_widget_show (vbox2); |
| 105 |
gtk_container_add (GTK_CONTAINER (notebook1), vbox2); |
| 106 |
gtk_container_set_border_width (GTK_CONTAINER (vbox2), 4); |
| 107 |
|
| 108 |
// Scrollbar for the text entry |
| 109 |
scrolledwindow = gtk_scrolled_window_new (NULL, NULL); |
| 110 |
g_object_ref (scrolledwindow); |
| 111 |
g_object_set_data_full (G_OBJECT (window), "scrolledwindow1", scrolledwindow, (GDestroyNotify) g_object_unref); |
| 112 |
gtk_widget_show (scrolledwindow); |
| 113 |
gtk_box_pack_start (GTK_BOX (vbox2), scrolledwindow, TRUE, TRUE, 0); |
| 114 |
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); |
| 115 |
|
| 116 |
// the text entry |
| 117 |
text_entry = gtk_text_buffer_new (NULL); |
| 118 |
text_view = gtk_text_view_new_with_buffer (GTK_TEXT_BUFFER (text_entry)); |
| 119 |
g_object_ref (text_view); |
| 120 |
g_object_set_data_full (G_OBJECT (window), "text_view", text_view, (GDestroyNotify) g_object_unref); |
| 121 |
gtk_widget_show (text_view); |
| 122 |
gtk_container_add (GTK_CONTAINER (scrolledwindow), text_view); |
| 123 |
gtk_widget_set_can_default (text_view, TRUE); |
| 124 |
gtk_widget_set_tooltip_text (text_view, "Enter the Text to appear within the conversation"); |
| 125 |
gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), TRUE); |
| 126 |
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text_view), GTK_WRAP_WORD); |
| 127 |
|
| 128 |
// set the text of the entry |
| 129 |
gtk_text_buffer_set_text (GTK_TEXT_BUFFER (text_entry), e->text ().c_str (), -1); |
| 130 |
|
| 131 |
// The radiobuttons to chose the text-type from |
| 132 |
label = gtk_label_new ("Narrator"); |
| 133 |
gtk_label_set_justify ((GtkLabel *) label, GTK_JUSTIFY_LEFT); |
| 134 |
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); |
| 135 |
|
| 136 |
// make the narrator-radiobutton-text green |
| 137 |
style = gtk_style_copy (gtk_widget_get_default_style ()); |
| 138 |
style->fg[GTK_STATE_NORMAL] = dark_green; |
| 139 |
style->fg[GTK_STATE_ACTIVE] = dark_green; |
| 140 |
style->fg[GTK_STATE_PRELIGHT] = dark_green; |
| 141 |
style->fg[GTK_STATE_SELECTED] = dark_green; |
| 142 |
gtk_widget_set_style (label, style); |
| 143 |
gtk_widget_show (label); |
| 144 |
|
| 145 |
narrator_button = gtk_radio_button_new (character_group); |
| 146 |
gtk_container_add (GTK_CONTAINER(narrator_button), label); |
| 147 |
character_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (narrator_button)); |
| 148 |
g_object_ref (narrator_button); |
| 149 |
g_object_set_data_full (G_OBJECT (window), "narrator_button", narrator_button, (GDestroyNotify) g_object_unref); |
| 150 |
g_object_set_data (G_OBJECT (narrator_button), "type", GINT_TO_POINTER (NARRATOR)); |
| 151 |
gtk_widget_show (narrator_button); |
| 152 |
gtk_box_pack_start (GTK_BOX (vbox2), narrator_button, FALSE, FALSE, 0); |
| 153 |
gtk_widget_set_can_focus (narrator_button, FALSE); |
| 154 |
|
| 155 |
// activate the narrator button if neccessary |
| 156 |
if (*type == NARRATOR) |
| 157 |
{ |
| 158 |
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (narrator_button), TRUE); |
| 159 |
on_radio_button_pressed (GTK_BUTTON (narrator_button), text_view); |
| 160 |
} |
| 161 |
// the player button |
| 162 |
label = gtk_label_new ("Player"); |
| 163 |
gtk_label_set_justify ((GtkLabel *) label, GTK_JUSTIFY_LEFT); |
| 164 |
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); |
| 165 |
|
| 166 |
// make the player-radiobutton-text blue |
| 167 |
style = gtk_style_copy (gtk_widget_get_default_style ()); |
| 168 |
style->fg[GTK_STATE_NORMAL] = dark_blue; |
| 169 |
style->fg[GTK_STATE_ACTIVE] = dark_blue; |
| 170 |
style->fg[GTK_STATE_PRELIGHT] = dark_blue; |
| 171 |
style->fg[GTK_STATE_SELECTED] = dark_blue; |
| 172 |
gtk_widget_set_style (label, style); |
| 173 |
gtk_widget_show (label); |
| 174 |
|
| 175 |
player_button = gtk_radio_button_new (character_group); |
| 176 |
gtk_container_add (GTK_CONTAINER(player_button), label); |
| 177 |
character_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (player_button)); |
| 178 |
g_object_ref (player_button); |
| 179 |
g_object_set_data_full (G_OBJECT (window), "player_button", player_button, (GDestroyNotify) g_object_unref); |
| 180 |
g_object_set_data (G_OBJECT (player_button), "type", GINT_TO_POINTER (PLAYER)); |
| 181 |
gtk_widget_show (player_button); |
| 182 |
gtk_box_pack_start (GTK_BOX (vbox2), player_button, FALSE, FALSE, 0); |
| 183 |
gtk_widget_set_can_focus (player_button, FALSE); |
| 184 |
|
| 185 |
// activate the player button if neccessary |
| 186 |
if (*type == PLAYER) |
| 187 |
{ |
| 188 |
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (player_button), TRUE); |
| 189 |
on_radio_button_pressed (GTK_BUTTON (player_button), text_view); |
| 190 |
} |
| 191 |
|
| 192 |
hbox1 = gtk_hbox_new (FALSE, 10); |
| 193 |
g_object_ref (hbox1); |
| 194 |
g_object_set_data_full (G_OBJECT (window), "hbox1", hbox1, (GDestroyNotify) g_object_unref); |
| 195 |
gtk_widget_show (hbox1); |
| 196 |
gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, TRUE, 0); |
| 197 |
|
| 198 |
// the NPC radiobutton |
| 199 |
npc_button = gtk_radio_button_new_with_label (character_group, "NPC:"); |
| 200 |
character_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (npc_button)); |
| 201 |
g_object_ref (npc_button); |
| 202 |
g_object_set_data_full (G_OBJECT (window), "npc_button", npc_button, (GDestroyNotify) g_object_unref); |
| 203 |
g_object_set_data (G_OBJECT (npc_button), "type", GINT_TO_POINTER (NPC)); |
| 204 |
gtk_widget_show (npc_button); |
| 205 |
gtk_box_pack_start (GTK_BOX (hbox1), npc_button, FALSE, FALSE, 0); |
| 206 |
gtk_widget_set_can_focus (npc_button, FALSE); |
| 207 |
|
| 208 |
// activate the NPC button if neccessary |
| 209 |
if (*type == NPC) |
| 210 |
{ |
| 211 |
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (npc_button), TRUE); |
| 212 |
on_radio_button_pressed (GTK_BUTTON (npc_button), text_view); |
| 213 |
} |
| 214 |
|
| 215 |
// the option menu with the available NPC's |
| 216 |
GtkTreeIter iter; |
| 217 |
GtkListStore *npc_list = gtk_list_store_new (1, G_TYPE_STRING); |
| 218 |
|
| 219 |
npc_selection = GTK_COMBO_BOX (gtk_combo_box_new_with_model (GTK_TREE_MODEL (npc_list))); |
| 220 |
g_object_ref (GTK_WIDGET (npc_selection)); |
| 221 |
g_object_set_data_full (G_OBJECT (window), "npc_selection", npc_selection, (GDestroyNotify) g_object_unref); |
| 222 |
gtk_widget_show (GTK_WIDGET (npc_selection)); |
| 223 |
gtk_box_pack_start (GTK_BOX (hbox1), GTK_WIDGET (npc_selection), TRUE, TRUE, 0); |
| 224 |
gtk_widget_set_tooltip_text (GTK_WIDGET (npc_selection), "Select the speaker"); |
| 225 |
|
| 226 |
GtkCellRenderer *renderer = gtk_cell_renderer_text_new (); |
| 227 |
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (npc_selection), renderer, TRUE); |
| 228 |
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (npc_selection), renderer, "text", 0, NULL); |
| 229 |
|
| 230 |
// add "default" entry |
| 231 |
gtk_list_store_append (GTK_LIST_STORE (npc_list), &iter); |
| 232 |
gtk_list_store_set (GTK_LIST_STORE (npc_list), &iter, 0, "Default", -1); |
| 233 |
gtk_combo_box_set_active_iter (npc_selection, &iter); |
| 234 |
|
| 235 |
for (std::string name = dme->character (); name != ""; name = dme->character ()) |
| 236 |
{ |
| 237 |
gtk_list_store_append (GTK_LIST_STORE (npc_list), &iter); |
| 238 |
gtk_list_store_set (GTK_LIST_STORE (npc_list), &iter, 0, name.c_str(), -1); |
| 239 |
|
| 240 |
if (name == e->npc ()) |
| 241 |
{ |
| 242 |
gtk_combo_box_set_active_iter (npc_selection, &iter); |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
// set sorting |
| 247 |
gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE(npc_list), 0, sort_strings, NULL, NULL); |
| 248 |
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE(npc_list), 0, GTK_SORT_ASCENDING); |
| 249 |
|
| 250 |
// the option menu with the available moods |
| 251 |
label = gtk_label_new ("Mood: "); |
| 252 |
g_object_ref (label); |
| 253 |
g_object_set_data_full (G_OBJECT (window), "label", label, (GDestroyNotify) g_object_unref); |
| 254 |
gtk_widget_show (label); |
| 255 |
gtk_box_pack_start (GTK_BOX (hbox1), label, TRUE, FALSE, 0); |
| 256 |
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_RIGHT); |
| 257 |
gtk_misc_set_alignment (GTK_MISC (label), 0.01, 0.5); |
| 258 |
|
| 259 |
GtkListStore *mood_list = gtk_list_store_new (1, G_TYPE_STRING); |
| 260 |
|
| 261 |
npc_mood = gtk_combo_box_new_with_model (GTK_TREE_MODEL (mood_list)); |
| 262 |
g_object_ref (GTK_WIDGET (npc_mood)); |
| 263 |
g_object_set_data_full (G_OBJECT (window), "npc_mood", npc_mood, (GDestroyNotify) g_object_unref); |
| 264 |
gtk_widget_show (GTK_WIDGET (npc_mood)); |
| 265 |
gtk_box_pack_start (GTK_BOX (hbox1), GTK_WIDGET (npc_mood), TRUE, TRUE, 0); |
| 266 |
gtk_widget_set_tooltip_text (GTK_WIDGET (npc_mood), "How the speaker's image appears to the player"); |
| 267 |
|
| 268 |
renderer = gtk_cell_renderer_text_new (); |
| 269 |
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (npc_mood), renderer, TRUE); |
| 270 |
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (npc_mood), renderer, "text", 0, NULL); |
| 271 |
|
| 272 |
// add "default" entry |
| 273 |
gtk_list_store_append (GTK_LIST_STORE (mood_list), &iter); |
| 274 |
gtk_list_store_set (GTK_LIST_STORE (mood_list), &iter, 0, "Default", -1); |
| 275 |
gtk_combo_box_set_active_iter (GTK_COMBO_BOX(npc_mood), &iter); |
| 276 |
|
| 277 |
// The heading of this page |
| 278 |
label = gtk_label_new ("Text"); |
| 279 |
g_object_ref (label); |
| 280 |
g_object_set_data_full (G_OBJECT (window), "label", label, (GDestroyNotify) g_object_unref); |
| 281 |
gtk_widget_show (label); |
| 282 |
gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook1), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook1), 0), label); |
| 283 |
|
| 284 |
// the entry for annotations |
| 285 |
frame1 = gtk_frame_new ("Annotations:"); |
| 286 |
g_object_ref (frame1); |
| 287 |
g_object_set_data_full (G_OBJECT (window), "frame1", frame1, (GDestroyNotify) g_object_unref); |
| 288 |
gtk_widget_show (frame1); |
| 289 |
gtk_box_pack_start (GTK_BOX (vbox2), frame1, TRUE, TRUE, 0); |
| 290 |
|
| 291 |
scrolledwindow = gtk_scrolled_window_new (NULL, NULL); |
| 292 |
g_object_ref (scrolledwindow); |
| 293 |
g_object_set_data_full (G_OBJECT (window), "scrolledwindow4", scrolledwindow, (GDestroyNotify) g_object_unref); |
| 294 |
gtk_widget_show (scrolledwindow); |
| 295 |
gtk_container_add (GTK_CONTAINER (frame1), scrolledwindow); |
| 296 |
gtk_container_set_border_width (GTK_CONTAINER (scrolledwindow), 4); |
| 297 |
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); |
| 298 |
|
| 299 |
annotation_entry = gtk_text_buffer_new (NULL); |
| 300 |
annotation_view = gtk_text_view_new_with_buffer (annotation_entry); |
| 301 |
g_object_ref (annotation_view); |
| 302 |
g_object_set_data_full (G_OBJECT (window), "annotation_view", annotation_view, (GDestroyNotify) g_object_unref); |
| 303 |
gtk_widget_show (annotation_view); |
| 304 |
gtk_container_add (GTK_CONTAINER (scrolledwindow), annotation_view); |
| 305 |
gtk_widget_set_tooltip_text (annotation_view, "Here is room for comments and other reminders"); |
| 306 |
gtk_text_view_set_editable (GTK_TEXT_VIEW (annotation_view), TRUE); |
| 307 |
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (annotation_view), GTK_WRAP_WORD); |
| 308 |
|
| 309 |
// insert text |
| 310 |
gtk_text_buffer_set_text (GTK_TEXT_BUFFER (annotation_entry), e->annotation ().c_str (), -1); |
| 311 |
|
| 312 |
// the loop checkbox |
| 313 |
ebox = gtk_event_box_new (); |
| 314 |
g_object_ref (ebox); |
| 315 |
gtk_widget_show (ebox); |
| 316 |
g_object_set_data_full (G_OBJECT (window), "ebox", ebox, (GDestroyNotify) g_object_unref); |
| 317 |
gtk_box_pack_end (GTK_BOX (vbox2), ebox, FALSE, FALSE, 0); |
| 318 |
gtk_widget_set_tooltip_text (ebox, "Unless this is checked, the text becomes unavailable after being uttered."); |
| 319 |
|
| 320 |
loop = gtk_check_button_new_with_label ("Loop"); |
| 321 |
g_object_ref (loop); |
| 322 |
g_object_set_data_full (G_OBJECT (window), "loop", loop, (GDestroyNotify) g_object_unref); |
| 323 |
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (loop), e->loop ()); |
| 324 |
gtk_widget_show (loop); |
| 325 |
gtk_container_add (GTK_CONTAINER (ebox), loop); |
| 326 |
|
| 327 |
// Condition-editor |
| 328 |
cond_edit = new GuiEdit (notebook1); |
| 329 |
|
| 330 |
// append tooltips |
| 331 |
gtk_widget_set_tooltip_text (cond_edit->widget (), |
| 332 |
"Enter the conditions that have to be met before this node is available in the dialogue"); |
| 333 |
|
| 334 |
// display the current conditios |
| 335 |
cond_edit->setText (entry->condition ()); |
| 336 |
|
| 337 |
style = gtk_style_copy (gtk_widget_get_default_style ()); |
| 338 |
style->fg[GTK_STATE_NORMAL] = green; |
| 339 |
style->fg[GTK_STATE_ACTIVE] = green; |
| 340 |
style->fg[GTK_STATE_PRELIGHT] = green; |
| 341 |
style->fg[GTK_STATE_SELECTED] = green; |
| 342 |
|
| 343 |
label = gtk_label_new ("Conditions"); |
| 344 |
g_object_ref (label); |
| 345 |
g_object_set_data_full (G_OBJECT (window), "label", label, (GDestroyNotify) g_object_unref); |
| 346 |
if (e->condition () != "") gtk_widget_set_style (label, style); |
| 347 |
gtk_widget_show (label); |
| 348 |
gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook1), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook1), 1), label); |
| 349 |
|
| 350 |
// Code-editor |
| 351 |
code_edit = new GuiEdit (notebook1); |
| 352 |
|
| 353 |
// append tooltips |
| 354 |
gtk_widget_set_tooltip_text (code_edit->widget (), |
| 355 |
"Here you can enter arbitrary Python code to be executed when this line of dialogue is uttered."); |
| 356 |
|
| 357 |
// display the current code |
| 358 |
code_edit->setText (entry->code ()); |
| 359 |
|
| 360 |
label = gtk_label_new ("Variables"); |
| 361 |
g_object_ref (label); |
| 362 |
g_object_set_data_full (G_OBJECT (window), "label", label, (GDestroyNotify) g_object_unref); |
| 363 |
if (e->code () != "") gtk_widget_set_style (label, style); |
| 364 |
gtk_widget_show (label); |
| 365 |
gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook1), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook1), 2), label); |
| 366 |
|
| 367 |
hbuttonbox1 = gtk_hbutton_box_new (); |
| 368 |
g_object_ref (hbuttonbox1); |
| 369 |
g_object_set_data_full (G_OBJECT (window), "hbuttonbox1", hbuttonbox1, (GDestroyNotify) g_object_unref); |
| 370 |
gtk_widget_show (hbuttonbox1); |
| 371 |
gtk_box_pack_start (GTK_BOX (vbox1), hbuttonbox1, FALSE, TRUE, 0); |
| 372 |
gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox1), GTK_BUTTONBOX_END); |
| 373 |
gtk_box_set_spacing (GTK_BOX (hbuttonbox1), 0); |
| 374 |
|
| 375 |
// ok button |
| 376 |
ok_button = gtk_button_new_with_label ("OK"); |
| 377 |
g_object_ref (ok_button); |
| 378 |
g_object_set_data_full (G_OBJECT (window), "ok_button", ok_button, (GDestroyNotify) g_object_unref); |
| 379 |
gtk_widget_show (ok_button); |
| 380 |
gtk_container_add (GTK_CONTAINER (hbuttonbox1), ok_button); |
| 381 |
gtk_widget_set_can_default (ok_button, TRUE); |
| 382 |
|
| 383 |
// cancel button |
| 384 |
cancel_button = gtk_button_new_with_label ("Cancel"); |
| 385 |
g_object_ref (cancel_button); |
| 386 |
g_object_set_data_full (G_OBJECT (window), "cancel_button", cancel_button, (GDestroyNotify) g_object_unref); |
| 387 |
gtk_widget_show (cancel_button); |
| 388 |
gtk_container_add (GTK_CONTAINER (hbuttonbox1), cancel_button); |
| 389 |
gtk_widget_set_can_default (cancel_button, TRUE); |
| 390 |
|
| 391 |
// the various input handlers |
| 392 |
g_signal_connect (G_OBJECT (player_button), "clicked", G_CALLBACK (on_radio_button_pressed), text_view); |
| 393 |
g_signal_connect (G_OBJECT (npc_button), "clicked", G_CALLBACK (on_radio_button_pressed), text_view); |
| 394 |
g_signal_connect (G_OBJECT (narrator_button), "clicked", G_CALLBACK (on_radio_button_pressed), text_view); |
| 395 |
g_signal_connect (G_OBJECT (ok_button), "clicked", G_CALLBACK (on_circle_ok_button_pressed), this); |
| 396 |
g_signal_connect (G_OBJECT (cancel_button), "clicked", G_CALLBACK (gtk_main_quit), NULL); |
| 397 |
g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL); |
| 398 |
g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_widget_destroyed), &window); |
| 399 |
|
| 400 |
// give focus to the text entry |
| 401 |
gtk_widget_grab_focus (text_view); |
| 402 |
gtk_widget_grab_default (text_view); |
| 403 |
} |
| 404 |
|
| 405 |
// Apply the user's changes to the DlgCircle |
| 406 |
void GuiCircle::applyChanges () |
| 407 |
{ |
| 408 |
GtkTextIter start, end; |
| 409 |
gchar *text; |
| 410 |
|
| 411 |
// set the circle's type |
| 412 |
*type = (node_type) GPOINTER_TO_INT (g_object_get_data (G_OBJECT (text_entry), "type")); |
| 413 |
|
| 414 |
// get the contents of the different entries |
| 415 |
gtk_text_buffer_get_bounds (text_entry, &start, &end); |
| 416 |
text = gtk_text_buffer_get_text (text_entry, &start, &end, TRUE); |
| 417 |
entry->setText (text); |
| 418 |
g_free (text); |
| 419 |
|
| 420 |
gtk_text_buffer_get_bounds (annotation_entry, &start, &end); |
| 421 |
text = gtk_text_buffer_get_text (annotation_entry, &start, &end, TRUE); |
| 422 |
entry->setAnnotation (text); |
| 423 |
g_free (text); |
| 424 |
|
| 425 |
entry->setCode (code_edit->getText ()); |
| 426 |
entry->setCondition (cond_edit->getText ()); |
| 427 |
entry->setNpc (getOption (npc_selection)); |
| 428 |
entry->setLoop (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (loop))); |
| 429 |
} |
| 430 |
|
| 431 |
// returns selected option |
| 432 |
const gchar *GuiCircle::getOption (GtkComboBox *cbox) |
| 433 |
{ |
| 434 |
GtkTreeIter iter; |
| 435 |
gchar *option = NULL; |
| 436 |
if (gtk_combo_box_get_active_iter (cbox, &iter)) |
| 437 |
{ |
| 438 |
GtkTreeModel *model = gtk_combo_box_get_model (cbox); |
| 439 |
gtk_tree_model_get (model, &iter, 0, &option, -1); |
| 440 |
} |
| 441 |
|
| 442 |
return option ? option : "Default"; |
| 443 |
} |
| 444 |
|
| 445 |
// sets a default option |
| 446 |
void GuiCircle::setOption (GtkComboBox *cbox, const gchar *label) |
| 447 |
{ |
| 448 |
GtkTreeIter iter; |
| 449 |
gchar *option = NULL; |
| 450 |
GtkTreeModel *model = gtk_combo_box_get_model (cbox); |
| 451 |
|
| 452 |
if (gtk_tree_model_get_iter_first(model, &iter)) |
| 453 |
{ |
| 454 |
do |
| 455 |
{ |
| 456 |
gtk_tree_model_get (model, &iter, 0, &option, -1); |
| 457 |
if (strcmp(option, label) == 0) |
| 458 |
{ |
| 459 |
gtk_combo_box_set_active_iter(cbox, &iter); |
| 460 |
break; |
| 461 |
} |
| 462 |
} |
| 463 |
while (gtk_tree_model_iter_next(model, &iter)); |
| 464 |
} |
| 465 |
} |