]> icculus.org git repositories - btb/d2x.git/blob - main/editor/centers.c
use the orientation parameter of g3_draw_bitmap
[btb/d2x.git] / main / editor / centers.c
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14 /*
15  *
16  * Dialog box stuff for control centers, material centers, etc.
17  *
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include "conf.h"
22 #endif
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <math.h>
27 #include <string.h>
28
29 #include "inferno.h"
30 #include "editor.h"
31 #include "timer.h"
32 #include "maths.h"
33 #include "mono.h"
34 #include "dxxerror.h"
35 #include "key.h"
36
37
38 //-------------------------------------------------------------------------
39 // Variables for this module...
40 //-------------------------------------------------------------------------
41 static UI_WINDOW                                *MainWindow = NULL;
42 static UI_GADGET_BUTTON         *QuitButton;
43 static UI_GADGET_RADIO          *CenterFlag[MAX_CENTER_TYPES];
44 static UI_GADGET_CHECKBOX       *RobotMatFlag[64];      // 2 ints = 64 bits
45
46 static int old_seg_num;
47
48 char    center_names[MAX_CENTER_TYPES][CENTER_STRING_LENGTH] = {
49         "Nothing",
50         "FuelCen",
51         "RepairCen",
52         "ControlCen",
53         "RobotMaker"
54 };
55
56 //-------------------------------------------------------------------------
57 // Called from the editor... does one instance of the centers dialog box
58 //-------------------------------------------------------------------------
59 int do_centers_dialog()
60 {
61         int i;
62
63         // Only open 1 instance of this window...
64         if ( MainWindow != NULL ) return 0;
65
66         // Close other windows. 
67         close_trigger_window();
68         hostage_close_window();
69         close_wall_window();
70         robot_close_window();
71
72         // Open a window with a quit button
73         MainWindow = ui_open_window( TMAPBOX_X+20, TMAPBOX_Y+20, 765-TMAPBOX_X, 545-TMAPBOX_Y, WIN_DIALOG );
74         QuitButton = ui_add_gadget_button( MainWindow, 20, 252, 48, 40, "Done", NULL );
75
76         // These are the checkboxes for each door flag.
77         i = 80;
78         CenterFlag[0] = ui_add_gadget_radio( MainWindow, 18, i, 16, 16, 0, "NONE" );                    i += 24;
79         CenterFlag[1] = ui_add_gadget_radio( MainWindow, 18, i, 16, 16, 0, "FuelCen" );         i += 24;
80         CenterFlag[2] = ui_add_gadget_radio( MainWindow, 18, i, 16, 16, 0, "RepairCen" );       i += 24;
81         CenterFlag[3] = ui_add_gadget_radio( MainWindow, 18, i, 16, 16, 0, "ControlCen" );      i += 24;
82         CenterFlag[4] = ui_add_gadget_radio( MainWindow, 18, i, 16, 16, 0, "RobotCen" );                i += 24;
83
84         // These are the checkboxes for each robot flag.
85         for (i=0; i < 64; i++)
86                 RobotMatFlag[i] = ui_add_gadget_checkbox( MainWindow, 128 + (i%2)*92, 20+(i/2)*24, 16, 16, 0, Robot_names[i]);
87                                                                                                                                                                                                           
88         old_seg_num = -2;               // Set to some dummy value so everything works ok on the first frame.
89
90         return 1;
91 }
92
93 void close_centers_window()
94 {
95         if ( MainWindow!=NULL ) {
96                 ui_close_window( MainWindow );
97                 MainWindow = NULL;
98         }
99 }
100
101 void do_centers_window()
102 {
103         int i;
104         int robot_flags;
105         int redraw_window;
106         int robot_index;
107
108         if ( MainWindow == NULL ) return;
109
110         //------------------------------------------------------------
111         // Call the ui code..
112         //------------------------------------------------------------
113         ui_button_any_drawn = 0;
114         ui_window_do_gadgets(MainWindow);
115
116         //------------------------------------------------------------
117         // If we change walls, we need to reset the ui code for all
118         // of the checkboxes that control the wall flags.  
119         //------------------------------------------------------------
120         if (old_seg_num != SEGMENT_NUMBER(Cursegp)) {
121                 Assert(Curseg2p->special < MAX_CENTER_TYPES);
122                 ui_radio_set_value(CenterFlag[Curseg2p->special], 1);
123
124                 mprintf((0, "Curseg2p->matcen_num = %i\n", Curseg2p->matcen_num));
125
126                 //      Read materialization center robot bit flags
127                 for (i = 0; i < 2; i++)
128                 {
129                         robot_index = i * 32;
130                         robot_flags = RobotCenters[Curseg2p->matcen_num].robot_flags[i];
131                         while (robot_flags)
132                         {
133                                 ui_checkbox_check(RobotMatFlag[i], robot_flags & 1);
134                                 robot_flags >>= 1;
135                                 robot_index++;
136                         }
137                 }
138
139         }
140
141         //------------------------------------------------------------
142         // If any of the radio buttons that control the mode are set, then
143         // update the corresponding center.
144         //------------------------------------------------------------
145
146         redraw_window=0;
147         for (   i=0; i < MAX_CENTER_TYPES; i++ )        {
148                 if ( CenterFlag[i]->flag == 1 )
149                  {
150                         if ( i == 0)
151                                 fuelcen_delete(Cursegp);
152                         else if (Curseg2p->special != i)
153                         {
154                                 fuelcen_delete(Cursegp);
155                                 redraw_window = 1;
156                                 fuelcen_activate( Cursegp, i );
157                         }
158                  }
159         }
160
161         for (i = 0; i < 2; i++)
162         {
163                 robot_flags = RobotCenters[Curseg2p->matcen_num].robot_flags[i];
164
165                 for (robot_index = 0; robot_index < 32; robot_index++)
166                 {
167                         if (RobotMatFlag[robot_index + i * 32]->flag == 1)
168                         {
169                                 if (!(robot_flags & (1 << robot_index)))
170                                 {
171                                         robot_flags |= (1 << robot_index);
172                                         mprintf((0, "Segment %i, matcen = %i, robot_flags[%d] = %d\n", SEGMENT_NUMBER(Cursegp), Curseg2p->matcen_num, i, robot_flags));
173                                 }
174                         }
175                         else if (robot_flags & 1 << robot_index)
176                         {
177                                 robot_flags &= ~(1 << robot_index);
178                                 mprintf((0, "Segment %i, matcen = %i, robot_flags[%d] = %d\n", SEGMENT_NUMBER(Cursegp), Curseg2p->matcen_num, i, robot_flags));
179                         }
180                 }
181
182                 RobotCenters[Curseg2p->matcen_num].robot_flags[i] = robot_flags;
183         }
184         
185         //------------------------------------------------------------
186         // If anything changes in the ui system, redraw all the text that
187         // identifies this wall.
188         //------------------------------------------------------------
189         if ( redraw_window || (old_seg_num != SEGMENT_NUMBER(Cursegp)) ) {
190 //              int     i;
191 //              char    temp_text[CENTER_STRING_LENGTH];
192         
193                 ui_wprintf_at( MainWindow, 12, 6, "Seg: %3d", SEGMENT_NUMBER(Cursegp) );
194
195 //              for (i=0; i<CENTER_STRING_LENGTH; i++)
196 //                      temp_text[i] = ' ';
197 //              temp_text[i] = 0;
198
199 //              Assert(Curseg2p->special < MAX_CENTER_TYPES);
200 //              strncpy(temp_text, Center_names[Curseg2p->special], strlen(Center_names[Curseg2p->special]));
201 //              ui_wprintf_at( MainWindow, 12, 23, " Type: %s", temp_text );
202                 Update_flags |= UF_WORLD_CHANGED;
203         }
204
205         if ( QuitButton->pressed || (last_keypress==KEY_ESC) )  {
206                 close_centers_window();
207                 return;
208         }               
209
210         old_seg_num = SEGMENT_NUMBER(Cursegp);
211 }
212
213
214