1 /* $Id: centers.c,v 1.6 2005-01-24 22:05:14 schaffner 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.
22 static char rcsid[] = "$Id: centers.c,v 1.6 2005-01-24 22:05:14 schaffner Exp $";
61 //-------------------------------------------------------------------------
62 // Variables for this module...
63 //-------------------------------------------------------------------------
64 static UI_WINDOW *MainWindow = NULL;
65 static UI_GADGET_BUTTON *QuitButton;
66 static UI_GADGET_RADIO *CenterFlag[MAX_CENTER_TYPES];
67 static UI_GADGET_CHECKBOX *RobotMatFlag[64]; // 2 ints = 64 bits
69 static int old_seg_num;
71 char center_names[MAX_CENTER_TYPES][CENTER_STRING_LENGTH] = {
79 //-------------------------------------------------------------------------
80 // Called from the editor... does one instance of the centers dialog box
81 //-------------------------------------------------------------------------
82 int do_centers_dialog()
86 // Only open 1 instance of this window...
87 if ( MainWindow != NULL ) return 0;
89 // Close other windows.
90 close_trigger_window();
91 hostage_close_window();
95 // Open a window with a quit button
96 MainWindow = ui_open_window( TMAPBOX_X+20, TMAPBOX_Y+20, 765-TMAPBOX_X, 545-TMAPBOX_Y, WIN_DIALOG );
97 QuitButton = ui_add_gadget_button( MainWindow, 20, 252, 48, 40, "Done", NULL );
99 // These are the checkboxes for each door flag.
101 CenterFlag[0] = ui_add_gadget_radio( MainWindow, 18, i, 16, 16, 0, "NONE" ); i += 24;
102 CenterFlag[1] = ui_add_gadget_radio( MainWindow, 18, i, 16, 16, 0, "FuelCen" ); i += 24;
103 CenterFlag[2] = ui_add_gadget_radio( MainWindow, 18, i, 16, 16, 0, "RepairCen" ); i += 24;
104 CenterFlag[3] = ui_add_gadget_radio( MainWindow, 18, i, 16, 16, 0, "ControlCen" ); i += 24;
105 CenterFlag[4] = ui_add_gadget_radio( MainWindow, 18, i, 16, 16, 0, "RobotCen" ); i += 24;
107 // These are the checkboxes for each robot flag.
108 for (i=0; i < 64; i++)
109 RobotMatFlag[i] = ui_add_gadget_checkbox( MainWindow, 128 + (i%2)*92, 20+(i/2)*24, 16, 16, 0, Robot_names[i]);
111 old_seg_num = -2; // Set to some dummy value so everything works ok on the first frame.
116 void close_centers_window()
118 if ( MainWindow!=NULL ) {
119 ui_close_window( MainWindow );
124 void do_centers_window()
131 if ( MainWindow == NULL ) return;
133 //------------------------------------------------------------
134 // Call the ui code..
135 //------------------------------------------------------------
136 ui_button_any_drawn = 0;
137 ui_window_do_gadgets(MainWindow);
139 //------------------------------------------------------------
140 // If we change walls, we need to reset the ui code for all
141 // of the checkboxes that control the wall flags.
142 //------------------------------------------------------------
143 if (old_seg_num != Cursegp-Segments) {
144 for ( i=0; i < MAX_CENTER_TYPES; i++ ) {
145 CenterFlag[i]->flag = 0; // Tells ui that this button isn't checked
146 CenterFlag[i]->status = 1; // Tells ui to redraw button
149 Assert(Curseg2p->special < MAX_CENTER_TYPES);
150 CenterFlag[Curseg2p->special]->flag = 1;
152 mprintf((0, "Curseg2p->matcen_num = %i\n", Curseg2p->matcen_num));
154 // Read materialization center robot bit flags
155 for (i = 0; i < 2; i++)
157 robot_index = i * 32;
158 robot_flags = RobotCenters[Curseg2p->matcen_num].robot_flags[i];
161 RobotMatFlag[i]->status = 1; // Tells ui to redraw button
163 RobotMatFlag[i]->flag = 1; // Tells ui that this button is checked
165 RobotMatFlag[i]->flag = 0; // Tells ui that this button is not checked
173 //------------------------------------------------------------
174 // If any of the radio buttons that control the mode are set, then
175 // update the corresponding center.
176 //------------------------------------------------------------
179 for ( i=0; i < MAX_CENTER_TYPES; i++ ) {
180 if ( CenterFlag[i]->flag == 1 )
183 fuelcen_delete(Cursegp);
184 else if (Curseg2p->special != i)
186 fuelcen_delete(Cursegp);
188 fuelcen_activate( Cursegp, i );
193 for (i = 0; i < 2; i++)
195 robot_flags = RobotCenters[Curseg2p->matcen_num].robot_flags[i];
197 for (robot_index = 0; robot_index < 32; robot_index++)
199 if (RobotMatFlag[robot_index + i * 32]->flag == 1)
201 if (!(robot_flags & (1 << robot_index)))
203 robot_flags |= (1 << robot_index);
204 mprintf((0, "Segment %i, matcen = %i, robot_flags[%d] = %d\n", Cursegp - Segments, Curseg2p->matcen_num, i, robot_flags));
207 else if (robot_flags & 1 << robot_index)
209 robot_flags &= ~(1 << robot_index);
210 mprintf((0, "Segment %i, matcen = %i, robot_flags[%d] = %d\n", Cursegp - Segments, Curseg2p->matcen_num, i, robot_flags));
214 RobotCenters[Curseg2p->matcen_num].robot_flags[i] = robot_flags;
217 //------------------------------------------------------------
218 // If anything changes in the ui system, redraw all the text that
219 // identifies this wall.
220 //------------------------------------------------------------
221 if (redraw_window || (old_seg_num != Cursegp-Segments ) ) {
223 // char temp_text[CENTER_STRING_LENGTH];
225 ui_wprintf_at( MainWindow, 12, 6, "Seg: %3d", Cursegp-Segments );
227 // for (i=0; i<CENTER_STRING_LENGTH; i++)
228 // temp_text[i] = ' ';
231 // Assert(Curseg2p->special < MAX_CENTER_TYPES);
232 // strncpy(temp_text, Center_names[Curseg2p->special], strlen(Center_names[Curseg2p->special]));
233 // ui_wprintf_at( MainWindow, 12, 23, " Type: %s", temp_text );
234 Update_flags |= UF_WORLD_CHANGED;
237 if ( QuitButton->pressed || (last_keypress==KEY_ESC) ) {
238 close_centers_window();
242 old_seg_num = Cursegp-Segments;