1 /* $Id: centers.c,v 1.2 2004-12-19 14:52:48 btb Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
17 * Dialog box stuff for control centers, material centers, etc.
23 static char rcsid[] = "$Id: centers.c,v 1.2 2004-12-19 14:52:48 btb Exp $";
58 //-------------------------------------------------------------------------
59 // Variables for this module...
60 //-------------------------------------------------------------------------
61 static UI_WINDOW *MainWindow = NULL;
62 static UI_GADGET_BUTTON *QuitButton;
63 static UI_GADGET_RADIO *CenterFlag[MAX_CENTER_TYPES];
64 static UI_GADGET_CHECKBOX *RobotMatFlag[MAX_ROBOT_TYPES];
66 static int old_seg_num;
68 char center_names[MAX_CENTER_TYPES][CENTER_STRING_LENGTH] = {
76 //-------------------------------------------------------------------------
77 // Called from the editor... does one instance of the centers dialog box
78 //-------------------------------------------------------------------------
79 int do_centers_dialog()
83 // Only open 1 instance of this window...
84 if ( MainWindow != NULL ) return 0;
86 // Close other windows.
87 close_trigger_window();
88 hostage_close_window();
92 // Open a window with a quit button
93 MainWindow = ui_open_window( TMAPBOX_X+20, TMAPBOX_Y+20, 765-TMAPBOX_X, 545-TMAPBOX_Y, WIN_DIALOG );
94 QuitButton = ui_add_gadget_button( MainWindow, 20, 252, 48, 40, "Done", NULL );
96 // These are the checkboxes for each door flag.
98 CenterFlag[0] = ui_add_gadget_radio( MainWindow, 18, i, 16, 16, 0, "NONE" ); i += 24;
99 CenterFlag[1] = ui_add_gadget_radio( MainWindow, 18, i, 16, 16, 0, "FuelCen" ); i += 24;
100 CenterFlag[2] = ui_add_gadget_radio( MainWindow, 18, i, 16, 16, 0, "RepairCen" ); i += 24;
101 CenterFlag[3] = ui_add_gadget_radio( MainWindow, 18, i, 16, 16, 0, "ControlCen" ); i += 24;
102 CenterFlag[4] = ui_add_gadget_radio( MainWindow, 18, i, 16, 16, 0, "RobotCen" ); i += 24;
104 // These are the checkboxes for each door flag.
105 for (i=0; i<N_robot_types; i++)
106 RobotMatFlag[i] = ui_add_gadget_checkbox( MainWindow, 128 + (i%2)*92, 20+(i/2)*24, 16, 16, 0, Robot_names[i]);
108 old_seg_num = -2; // Set to some dummy value so everything works ok on the first frame.
113 void close_centers_window()
115 if ( MainWindow!=NULL ) {
116 ui_close_window( MainWindow );
121 void do_centers_window()
127 if ( MainWindow == NULL ) return;
129 //------------------------------------------------------------
130 // Call the ui code..
131 //------------------------------------------------------------
132 ui_button_any_drawn = 0;
133 ui_window_do_gadgets(MainWindow);
135 //------------------------------------------------------------
136 // If we change walls, we need to reset the ui code for all
137 // of the checkboxes that control the wall flags.
138 //------------------------------------------------------------
139 if (old_seg_num != Cursegp-Segments) {
140 for ( i=0; i < MAX_CENTER_TYPES; i++ ) {
141 CenterFlag[i]->flag = 0; // Tells ui that this button isn't checked
142 CenterFlag[i]->status = 1; // Tells ui to redraw button
145 Assert(Cursegp->special < MAX_CENTER_TYPES);
146 CenterFlag[Cursegp->special]->flag = 1;
148 mprintf((0, "Cursegp->matcen_num = %i\n", Cursegp->matcen_num));
150 // Read materialization center robot bit flags
151 for ( i=0; i < N_robot_types; i++ ) {
152 RobotMatFlag[i]->status = 1; // Tells ui to redraw button
153 if (RobotCenters[Cursegp->matcen_num].robot_flags & (1 << i))
154 RobotMatFlag[i]->flag = 1; // Tells ui that this button is checked
156 RobotMatFlag[i]->flag = 0; // Tells ui that this button is not checked
161 //------------------------------------------------------------
162 // If any of the radio buttons that control the mode are set, then
163 // update the corresponding center.
164 //------------------------------------------------------------
167 for ( i=0; i < MAX_CENTER_TYPES; i++ ) {
168 if ( CenterFlag[i]->flag == 1 )
171 fuelcen_delete(Cursegp);
172 else if ( Cursegp->special != i ) {
173 fuelcen_delete(Cursegp);
175 fuelcen_activate( Cursegp, i );
180 for ( i=0; i < N_robot_types; i++ ) {
181 if ( RobotMatFlag[i]->flag == 1 ) {
182 if (!(RobotCenters[Cursegp->matcen_num].robot_flags & (1<<i) )) {
183 RobotCenters[Cursegp->matcen_num].robot_flags |= (1<<i);
184 mprintf((0,"Segment %i, matcen = %i, Robot_flags %d\n", Cursegp-Segments, Cursegp->matcen_num, RobotCenters[Cursegp->matcen_num].robot_flags));
186 } else if (RobotCenters[Cursegp->matcen_num].robot_flags & 1<<i) {
187 RobotCenters[Cursegp->matcen_num].robot_flags &= ~(1<<i);
188 mprintf((0,"Segment %i, matcen = %i, Robot_flags %d\n", Cursegp-Segments, Cursegp->matcen_num, RobotCenters[Cursegp->matcen_num].robot_flags));
192 //------------------------------------------------------------
193 // If anything changes in the ui system, redraw all the text that
194 // identifies this wall.
195 //------------------------------------------------------------
196 if (redraw_window || (old_seg_num != Cursegp-Segments ) ) {
198 // char temp_text[CENTER_STRING_LENGTH];
200 ui_wprintf_at( MainWindow, 12, 6, "Seg: %3d", Cursegp-Segments );
202 // for (i=0; i<CENTER_STRING_LENGTH; i++)
203 // temp_text[i] = ' ';
206 // Assert(Cursegp->special < MAX_CENTER_TYPES);
207 // strncpy(temp_text, Center_names[Cursegp->special], strlen(Center_names[Cursegp->special]));
208 // ui_wprintf_at( MainWindow, 12, 23, " Type: %s", temp_text );
209 Update_flags |= UF_WORLD_CHANGED;
212 if ( QuitButton->pressed || (last_keypress==KEY_ESC) ) {
213 close_centers_window();
217 old_seg_num = Cursegp-Segments;