]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/bp_dlg.cpp
uncrustify! now the code is only ugly on the *inside*
[xonotic/netradiant.git] / radiant / bp_dlg.cpp
1 /*
2    Copyright (C) 1999-2007 id Software, Inc. and contributors.
3    For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5    This file is part of GtkRadiant.
6
7    GtkRadiant is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    GtkRadiant is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with GtkRadiant; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21
22 //-----------------------------------------------------------------------------
23 //
24 // DESCRIPTION
25 //
26 // custom Gtk dialog for brush primitives load/save
27
28 #include "stdafx.h"
29 #include <glib/gi18n.h>
30
31 void BP_dialog_button_callback( GtkWidget *widget, gpointer data ){
32         GtkWidget *parent;
33         int *loop, *ret;
34
35         parent = gtk_widget_get_toplevel( widget );
36         loop = (int*)g_object_get_data( G_OBJECT( parent ), "loop" );
37         ret = (int*)g_object_get_data( G_OBJECT( parent ), "ret" );
38
39         *loop = 0;
40         *ret = GPOINTER_TO_INT( data );
41 }
42
43 gint BP_dialog_delete_callback( GtkWidget *widget, GdkEvent* event, gpointer data ){
44         int *loop;
45
46         gtk_widget_hide( widget );
47         loop = (int*)g_object_get_data( G_OBJECT( widget ), "loop" );
48         *loop = 0;
49
50         return TRUE;
51 }
52
53 // ret: 0 = abort, 1 = load and convert, 2 = changed project settings, load and don't convert
54 // the user might decide to switch the BP mode in project settings
55 // status: 0 = loading regular, got conflict 1 = loading BP, got conflict
56 // int WINAPI gtk_MessageBox (GtkWidget *parent, const char* lpText, const char* lpCaption, guint32 uType)
57 int BP_MessageBox( int status ){
58         GtkWidget *window, *w, *vbox, *hbox;
59         GtkAccelGroup *accel;
60         int ret, loop = 1;
61
62         window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
63         gtk_signal_connect( GTK_OBJECT( window ), "delete_event",
64                                                 GTK_SIGNAL_FUNC( BP_dialog_delete_callback ), NULL );
65         gtk_signal_connect( GTK_OBJECT( window ), "destroy",
66                                                 GTK_SIGNAL_FUNC( gtk_widget_destroy ), NULL );
67
68         gtk_window_set_title( GTK_WINDOW( window ), _( "Current map format is incompatible" ) );
69
70         gtk_container_border_width( GTK_CONTAINER( window ), 10 );
71         g_object_set_data( G_OBJECT( window ), "loop", &loop );
72         g_object_set_data( G_OBJECT( window ), "ret", &ret );
73         gtk_widget_realize( window );
74
75         gtk_window_set_transient_for( GTK_WINDOW( window ), GTK_WINDOW( g_pParentWnd->m_pWidget ) );
76
77         accel = gtk_accel_group_new();
78         gtk_window_add_accel_group( GTK_WINDOW( window ), accel );
79
80         vbox = gtk_vbox_new( FALSE, 10 );
81         gtk_container_add( GTK_CONTAINER( window ), vbox );
82         gtk_widget_show( vbox );
83
84         if ( status == 0 ) {
85                 w = gtk_label_new( _( "This map was saved using brush primitives format\n"
86                                                           "and your project settings use the standard format.\n"
87                                                           "Do you want to convert the map, change default format or abort?\n"
88                                                           "NOTE: due to limitations of the standard format, "
89                                                           "some texture alignments may be lost after conversion." ) );
90         }
91         else
92         {
93                 w = gtk_label_new( _( "This map was saved using standard format\n"
94                                                           "and your project settings use the new \"brush primitives\" format.\n"
95                                                           "Do you want to convert the map, change default format or abort?\n"
96                                                           "NOTE: Next versions of Radiant will allow mixing the two formats"
97                                                           "in the same maps for a smooth transition." ) );
98         }
99         gtk_box_pack_start( GTK_BOX( vbox ), w, FALSE, FALSE, 2 );
100         gtk_label_set_justify( GTK_LABEL( w ), GTK_JUSTIFY_LEFT );
101         gtk_widget_show( w );
102
103         w = gtk_hseparator_new();
104         gtk_box_pack_start( GTK_BOX( vbox ), w, FALSE, FALSE, 2 );
105         gtk_widget_show( w );
106
107         hbox = gtk_hbox_new( FALSE, 10 );
108         gtk_box_pack_start( GTK_BOX( vbox ), hbox, FALSE, FALSE, 2 );
109         gtk_widget_show( hbox );
110
111         w = gtk_button_new_with_label( _( "Convert" ) );
112         gtk_box_pack_start( GTK_BOX( hbox ), w, TRUE, TRUE, 0 );
113         gtk_signal_connect( GTK_OBJECT( w ), "clicked",
114                                                 GTK_SIGNAL_FUNC( BP_dialog_button_callback ), GINT_TO_POINTER( 1 ) );
115         GTK_WIDGET_SET_FLAGS( w, GTK_CAN_DEFAULT );
116         gtk_widget_grab_default( w );
117         gtk_widget_show( w );
118
119         w = gtk_button_new_with_label( _( "Change default" ) );
120         gtk_box_pack_start( GTK_BOX( hbox ), w, TRUE, TRUE, 0 );
121         gtk_signal_connect( GTK_OBJECT( w ), "clicked",
122                                                 GTK_SIGNAL_FUNC( BP_dialog_button_callback ), GINT_TO_POINTER( 2 ) );
123         gtk_widget_show( w );
124
125         w = gtk_button_new_with_label( _( "Abort load" ) );
126         gtk_box_pack_start( GTK_BOX( hbox ), w, TRUE, TRUE, 0 );
127         gtk_signal_connect( GTK_OBJECT( w ), "clicked",
128                                                 GTK_SIGNAL_FUNC( BP_dialog_button_callback ), GINT_TO_POINTER( 0 ) );
129         gtk_widget_show( w );
130         ret = 0; // abort
131
132         gtk_widget_show( window );
133         gtk_grab_add( window );
134
135         while ( loop )
136                 gtk_main_iteration();
137
138         if ( ret == 2 ) {
139                 // change project settings
140                 if ( status == 0 ) {
141                         g_qeglobals.m_bBrushPrimitMode = TRUE;
142                 }
143                 else{
144                         g_qeglobals.m_bBrushPrimitMode = FALSE;
145                 }
146                 SetKeyValue( g_qeglobals.d_project_entity, "brush_primit", ( g_qeglobals.m_bBrushPrimitMode ? "1" : "0" ) );
147         }
148
149         gtk_grab_remove( window );
150         gtk_widget_destroy( window );
151
152         return ret;
153 }