1 /*
2  *	s_prop.cc
3  *	Sector properties
4  *	Some of this was originally in editobj.c. It was moved here to
5  *	improve overlay granularity (therefore memory consumption).
6  *	AYM 1998-02-07
7  */
8 
9 
10 /*
11 This file is part of Yadex.
12 
13 Yadex incorporates code from DEU 5.21 that was put in the public domain in
14 1994 by Rapha�l Quinet and Brendon Wyber.
15 
16 The rest of Yadex is Copyright � 1997-2003 Andr� Majorel and others.
17 
18 This program is free software; you can redistribute it and/or modify it under
19 the terms of the GNU General Public License as published by the Free Software
20 Foundation; either version 2 of the License, or (at your option) any later
21 version.
22 
23 This program is distributed in the hope that it will be useful, but WITHOUT
24 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
25 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
26 
27 You should have received a copy of the GNU General Public License along with
28 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
29 Place, Suite 330, Boston, MA 02111-1307, USA.
30 */
31 
32 
33 #include "yadex.h"
34 #include "entry.h"
35 #include "flats.h"
36 #include "game.h"
37 #include "gfx.h"
38 #include "levels.h"
39 #include "menudata.h"
40 #include "objid.h"
41 #include "oldmenus.h"
42 #include "selectn.h"
43 
44 
45 class Menu_data_st : public Menu_data
46 {
47   public :
48     Menu_data_st (al_llist_t *list);
49     virtual size_t nitems () const;
50     virtual const char *operator[] (size_t n) const;
51 
52   private :
53     mutable char buf[100];
54     al_llist_t *list;
55 };
56 
57 
58 /*
59  *	Menu_data_st::Menu_data_st - ctor
60  */
Menu_data_st(al_llist_t * list)61 Menu_data_st::Menu_data_st (al_llist_t *list) : list (list)
62 {
63   al_lrewind (this->list);
64 }
65 
66 
67 /*
68  *	Menu_data_st::nitems - return the number of items
69  */
nitems() const70 size_t Menu_data_st::nitems () const
71 {
72   return al_lcount (list);
73 }
74 
75 
76 /*
77  *	Menu_data_st::operator[] - return the nth item
78  */
operator [](size_t n) const79 const char *Menu_data_st::operator[] (size_t n) const
80 {
81   if (al_lseek (list, n, SEEK_SET) != 0)
82   {
83     sprintf (buf, "BUG: al_lseek(%p, %lu): %s",
84       (void *) list,
85       (unsigned long) n,
86       al_astrerror (al_aerrno));
87     return buf;
88   }
89   const stdef_t *ptr = (const stdef_t *) al_lptr (list);
90   if (ptr == NULL)
91     sprintf (buf, "BUG: al_lptr(%p): %s",
92       (void *) list,
93       al_astrerror (al_aerrno));
94   else
95     sprintf (buf, "%2d - %.70s", ptr->number, ptr->longdesc);
96   return buf;
97 }
98 
99 
100 /*
101  *	SectorProperties
102  *	Sector properties "dialog"
103  */
SectorProperties(int x0,int y0,SelPtr obj)104 void SectorProperties (int x0, int y0, SelPtr obj)
105 {
106   char  *menustr[30];
107   char   texname[WAD_FLAT_NAME + 1];
108   int    n, val;
109   SelPtr cur;
110   int    subwin_y0;
111 
112   for (n = 0; n < 8; n++)
113     menustr[n] = (char *) GetMemory (60);
114   sprintf (menustr[7], "Edit sector #%d", obj->objnum);
115   sprintf (menustr[0], "Change floor height     (Current: %d)",
116 	  Sectors[obj->objnum].floorh);
117   sprintf (menustr[1], "Change ceiling height   (Current: %d)",
118 	  Sectors[obj->objnum].ceilh);
119   sprintf (menustr[2], "Change floor texture    (Current: %.*s)",
120 	  (int) WAD_FLAT_NAME, Sectors[obj->objnum].floort);
121   sprintf (menustr[3], "Change ceiling texture  (Current: %.*s)",
122 	  (int) WAD_FLAT_NAME, Sectors[obj->objnum].ceilt);
123   sprintf (menustr[4], "Change light level      (Current: %d)",
124 	  Sectors[obj->objnum].light);
125   sprintf (menustr[5], "Change type             (Current: %d)",
126 	  Sectors[obj->objnum].special);
127   sprintf (menustr[6], "Change linedef tag      (Current: %d)",
128 	  Sectors[obj->objnum].tag);
129   val = vDisplayMenu (x0, y0, menustr[7],
130     menustr[0], YK_, 0,
131     menustr[1], YK_, 0,
132     menustr[2], YK_, 0,
133     menustr[3], YK_, 0,
134     menustr[4], YK_, 0,
135     menustr[5], YK_, 0,
136     menustr[6], YK_, 0,
137     NULL);
138   for (n = 0; n < 8; n++)
139     FreeMemory (menustr[n]);
140   subwin_y0 = y0 + BOX_BORDER + (2 + val) * FONTH;
141   switch (val)
142   {
143     case 1:
144       val = InputIntegerValue (x0 + 42, subwin_y0, -32768, 32767,
145 	Sectors[obj->objnum].floorh);
146       if (val != IIV_CANCEL)
147       {
148 	for (cur = obj; cur; cur = cur->next)
149 	  Sectors[cur->objnum].floorh = val;
150 	MadeChanges = 1;
151       }
152       break;
153 
154     case 2:
155       val = InputIntegerValue (x0 + 42, subwin_y0, -32768, 32767,
156 	Sectors[obj->objnum].ceilh);
157       if (val != IIV_CANCEL)
158       {
159 	for (cur = obj; cur; cur = cur->next)
160 	  Sectors[cur->objnum].ceilh = val;
161 	MadeChanges = 1;
162       }
163       break;
164 
165     case 3:
166       {
167 	*texname = '\0';
168 	strncat (texname, Sectors[obj->objnum].floort, WAD_FLAT_NAME);
169 	ObjectsNeeded (0);
170 	char **flat_names =
171 	  (char **) GetMemory (NumFTexture * sizeof *flat_names);
172 	for (size_t n = 0; n < NumFTexture; n++)
173 	  flat_names[n] = flat_list[n].name;
174 	ChooseFloorTexture (x0 + 42, subwin_y0, "Choose a floor texture",
175 	  NumFTexture, flat_names, texname);
176 	FreeMemory (flat_names);
177 	ObjectsNeeded (OBJ_SECTORS, 0);
178 	if (strlen (texname) > 0)
179 	{
180 	  for (cur = obj; cur; cur = cur->next)
181 	    strncpy (Sectors[cur->objnum].floort, texname, WAD_FLAT_NAME);
182 	  MadeChanges = 1;
183 	}
184 	break;
185       }
186 
187     case 4:
188       {
189       *texname = '\0';
190       strncat (texname, Sectors[obj->objnum].ceilt, WAD_FLAT_NAME);
191       ObjectsNeeded (0);
192       char **flat_names =
193 	(char **) GetMemory (NumFTexture * sizeof *flat_names);
194       for (size_t n = 0; n < NumFTexture; n++)
195 	flat_names[n] = flat_list[n].name;
196       ChooseFloorTexture (x0 + 42, subwin_y0, "Choose a ceiling texture",
197 	NumFTexture, flat_names, texname);
198       FreeMemory (flat_names);
199       ObjectsNeeded (OBJ_SECTORS, 0);
200       if (strlen (texname) > 0)
201       {
202 	for (cur = obj; cur; cur = cur->next)
203 	  strncpy (Sectors[cur->objnum].ceilt, texname, WAD_FLAT_NAME);
204 	MadeChanges = 1;
205       }
206       break;
207       }
208 
209     case 5:
210       val = InputIntegerValue (x0 + 42, subwin_y0, 0, 255,
211 	Sectors[obj->objnum].light);
212       if (val != IIV_CANCEL)
213       {
214 	for (cur = obj; cur; cur = cur->next)
215 	  Sectors[cur->objnum].light = val;
216 	MadeChanges = 1;
217       }
218       break;
219 
220     case 6:
221       {
222 	val = 0;
223 	Menu_data_st menudata (stdef);
224 	if (DisplayMenuList (x0 + 42, subwin_y0, "Select type", menudata, &val)
225 	  < 0)
226 	  break;
227 	// KLUDGE last element of stdef means "enter value"
228 	if (val == al_lcount (stdef) - 1)
229 	{
230 	  val = InputIntegerValue (x0 + 84,
231 	    subwin_y0 + BOX_BORDER + (3 + val) * FONTH,
232 	    -32768, 32767, 0);
233 	  if (val == IIV_CANCEL)  // [Esc]
234 	    break;
235 	}
236 	else
237 	{
238 	  if (al_lseek (stdef, val, SEEK_SET))
239 	    fatal_error ("%s SP1 (%s)\n",
240 	      msg_unexpected, al_astrerror (al_aerrno));
241 	  val = CUR_STDEF->number;
242 	}
243 	for (cur = obj; cur; cur = cur->next)
244 	  Sectors[cur->objnum].special = val;
245 	MadeChanges = 1;
246 	break;
247       }
248 
249     case 7:
250       val = InputIntegerValue (x0 + 42, subwin_y0, -32768, 32767,
251 	Sectors[obj->objnum].tag);
252       if (val != IIV_CANCEL)
253       {
254 	for (cur = obj; cur; cur = cur->next)
255 	  Sectors[cur->objnum].tag = val;
256 	MadeChanges = 1;
257       }
258       break;
259   }
260 }
261 
262 
263