97f07c7553cbfef28a1ee386979c6054006d8bfb
[blender-staging.git] / source / blender / src / buttons_logic.c
1 /**
2  * $Id$ 
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29
30 #include <stdlib.h>
31 #include <math.h>
32 #include <string.h>
33
34 #ifndef WIN32
35 #include <unistd.h>
36 #else
37 #include <io.h>
38 #endif   
39
40 #include "MEM_guardedalloc.h"
41
42 #include "BLI_blenlib.h"
43 #include "BLI_arithb.h"
44
45 #include "DNA_action_types.h"
46 #include "DNA_material_types.h"
47 #include "DNA_sensor_types.h"
48 #include "DNA_actuator_types.h"
49 #include "DNA_controller_types.h"
50 #include "DNA_property_types.h"
51 #include "DNA_object_types.h"
52 #include "DNA_object_force.h"
53 #include "DNA_screen_types.h"
54 #include "DNA_space_types.h"
55 #include "DNA_scene_types.h"
56 #include "DNA_sound_types.h"
57 #include "DNA_text_types.h"
58 #include "DNA_userdef_types.h"
59 #include "DNA_view3d_types.h"
60 #include "DNA_mesh_types.h"
61 #include "DNA_world_types.h"
62
63 #include "BKE_library.h"
64 #include "BKE_global.h"
65 #include "BKE_main.h"
66 #include "BKE_sca.h"
67 #include "BKE_property.h"
68 #include "BKE_property.h"
69 #include "BKE_utildefines.h"
70 #include "BKE_bullet.h"
71
72 #include "BIF_gl.h"
73 #include "BIF_resources.h"
74 #include "BIF_space.h"
75 #include "BIF_interface.h"
76 #include "BIF_butspace.h"
77 #include "BIF_screen.h"
78 #include "BIF_keyval.h"
79 #include "BIF_editsound.h"
80
81 #include "BIF_editsca.h"
82
83
84 #include "BDR_editcurve.h"
85 #include "BDR_editobject.h"
86 #include "BSE_headerbuttons.h"
87 #include "BSE_filesel.h"
88
89 #include "blendef.h"
90 #include "mydevice.h"
91 #include "nla.h"        /* For __NLA : Important, do not remove */
92 #include "butspace.h" // own module
93 #include "interface.h"
94
95 /* internals */
96 static void buttons_enji(uiBlock *, Object *);
97 static void buttons_ketsji(uiBlock *, Object *);
98 static void buttons_bullet(uiBlock *, Object *);
99
100 /****/
101
102 static ID **get_selected_and_linked_obs(short *count, short scavisflag);
103 static char *actuator_pup(Object *owner);
104
105 /****/
106
107
108 static void del_property(void *selpropv, void *data2_unused)
109 {
110         bProperty *prop, *selprop= selpropv;
111         Object *ob;
112         int a=0;
113                 
114         ob= OBACT;
115         if(ob==NULL) return;
116
117         prop= ob->prop.first;
118         while(prop) {
119                 if(prop==selprop) {
120                         if (strcmp(prop->name,"Text") == 0) {
121                                 allqueue(REDRAWVIEW3D, 0);
122                         }
123                         BLI_remlink(&ob->prop, prop);
124                         free_property(prop);
125                         break;
126                 }
127                 a++;
128                 prop= prop->next;
129         }
130         BIF_undo_push("Delete property");
131         allqueue(REDRAWBUTSLOGIC, 0);
132         
133 }
134
135 static int vergname(const void *v1, const void *v2)
136 {
137         char **x1, **x2;
138         
139         x1= (char **)v1;
140         x2= (char **)v2;
141         
142         return strcmp(*x1, *x2);
143 }
144
145 void make_unique_prop_names(char *str)
146 {
147         Object *ob;
148         bProperty *prop;
149         bSensor *sens;
150         bController *cont;
151         bActuator *act;
152         ID **idar;
153         short a, obcount, propcount=0, nr;
154         char **names;
155         
156         /* this function is called by a Button, and gives the current
157          * stringpointer as an argument, this is the one that can change
158          */
159
160         idar= get_selected_and_linked_obs(&obcount, BUTS_SENS_SEL|BUTS_SENS_ACT|BUTS_ACT_SEL|BUTS_ACT_ACT|BUTS_CONT_SEL|BUTS_CONT_ACT);
161         
162         /* for each object, make properties and sca names unique */
163         
164         /* count total names */
165         for(a=0; a<obcount; a++) {
166                 ob= (Object *)idar[a];
167                 propcount+= BLI_countlist(&ob->prop);
168                 propcount+= BLI_countlist(&ob->sensors);
169                 propcount+= BLI_countlist(&ob->controllers);
170                 propcount+= BLI_countlist(&ob->actuators);
171         }       
172         if(propcount==0) {
173                 if(idar) MEM_freeN(idar);
174                 return;
175         }
176         
177         /* make names array for sorting */
178         names= MEM_callocN(propcount*sizeof(void *), "names");
179
180         /* count total names */
181         nr= 0;
182         for(a=0; a<obcount; a++) {
183                 ob= (Object *)idar[a];
184                 prop= ob->prop.first;
185                 while(prop) {
186                         names[nr++]= prop->name;
187                         prop= prop->next;
188                 }
189                 sens= ob->sensors.first;
190                 while(sens) {
191                         names[nr++]= sens->name;
192                         sens= sens->next;
193                 }
194                 cont= ob->controllers.first;
195                 while(cont) {
196                         names[nr++]= cont->name;
197                         cont= cont->next;
198                 }
199                 act= ob->actuators.first;
200                 while(act) {
201                         names[nr++]= act->name;
202                         act= act->next;
203                 }
204         }
205
206         qsort(names, propcount, sizeof(void *), vergname);
207         
208         /* now we check for double names, and change them */
209         
210         for(nr=0; nr<propcount; nr++) {
211                 if(names[nr]!=str && strcmp( names[nr], str )==0 ) {
212                         BLI_newname(str, +1);
213                 }
214         }
215         
216         MEM_freeN(idar);
217         MEM_freeN(names);
218 }
219
220 static void make_unique_prop_names_cb(void *strv, void *redraw_view3d_flagv)
221 {
222         char *str= strv;
223         int redraw_view3d_flag= GET_INT_FROM_POINTER(redraw_view3d_flagv);
224
225         make_unique_prop_names(str);
226         if (redraw_view3d_flag) allqueue(REDRAWVIEW3D, 0);
227 }
228
229 static void sca_move_sensor(void *datav, void *data2_unused)
230 {
231         bSensor *sens_to_delete= datav;
232         int val;
233         Base *base;
234         bSensor *sens, *tmp;
235         
236         val= pupmenu("Move up%x1|Move down %x2");
237         
238         if(val>0) {
239                 /* now find out which object has this ... */
240                 base= FIRSTBASE;
241                 while(base) {
242                 
243                         sens= base->object->sensors.first;
244                         while(sens) {
245                                 if(sens == sens_to_delete) break;
246                                 sens= sens->next;
247                         }
248                         
249                         if(sens) {
250                                 if( val==1 && sens->prev) {
251                                         for (tmp=sens->prev; tmp; tmp=tmp->prev) {
252                                                 if (tmp->flag & SENS_VISIBLE)
253                                                         break;
254                                         }
255                                         if (tmp) {
256                                                 BLI_remlink(&base->object->sensors, sens);
257                                                 BLI_insertlinkbefore(&base->object->sensors, tmp, sens);
258                                         }
259                                 }
260                                 else if( val==2 && sens->next) {
261                                         for (tmp=sens->next; tmp; tmp=tmp->next) {
262                                                 if (tmp->flag & SENS_VISIBLE)
263                                                         break;
264                                         }
265                                         if (tmp) {
266                                                 BLI_remlink(&base->object->sensors, sens);
267                                                 BLI_insertlink(&base->object->sensors, tmp, sens);
268                                         }
269                                 }
270                                 BIF_undo_push("Move sensor");
271                                 allqueue(REDRAWBUTSLOGIC, 0);
272                                 break;
273                         }
274                         
275                         base= base->next;
276                 }
277         }
278 }
279
280 static void sca_move_controller(void *datav, void *data2_unused)
281 {
282         bController *controller_to_del= datav;
283         int val;
284         Base *base;
285         bController *cont, *tmp;
286         
287         val= pupmenu("Move up%x1|Move down %x2");
288         
289         if(val>0) {
290                 /* now find out which object has this ... */
291                 base= FIRSTBASE;
292                 while(base) {
293                 
294                         cont= base->object->controllers.first;
295                         while(cont) {
296                                 if(cont == controller_to_del) break;
297                                 cont= cont->next;
298                         }
299                         
300                         if(cont) {
301                                 if( val==1 && cont->prev) {
302                                         /* locate the controller that has the same state mask but is earlier in the list */
303                                         tmp = cont->prev;
304                                         while(tmp) {
305                                                 if(tmp->state_mask & cont->state_mask) 
306                                                         break;
307                                                 tmp = tmp->prev;
308                                         }
309                                         if (tmp) {
310                                                 BLI_remlink(&base->object->controllers, cont);
311                                                 BLI_insertlinkbefore(&base->object->controllers, tmp, cont);
312                                         }
313                                 }
314                                 else if( val==2 && cont->next) {
315                                         tmp = cont->next;
316                                         while(tmp) {
317                                                 if(tmp->state_mask & cont->state_mask) 
318                                                         break;
319                                                 tmp = tmp->next;
320                                         }
321                                         BLI_remlink(&base->object->controllers, cont);
322                                         BLI_insertlink(&base->object->controllers, tmp, cont);
323                                 }
324                                 BIF_undo_push("Move controller");
325                                 allqueue(REDRAWBUTSLOGIC, 0);
326                                 break;
327                         }
328                         
329                         base= base->next;
330                 }
331         }
332 }
333
334 static void sca_move_actuator(void *datav, void *data2_unused)
335 {
336         bActuator *actuator_to_move= datav;
337         int val;
338         Base *base;
339         bActuator *act, *tmp;
340         
341         val= pupmenu("Move up%x1|Move down %x2");
342         
343         if(val>0) {
344                 /* now find out which object has this ... */
345                 base= FIRSTBASE;
346                 while(base) {
347                 
348                         act= base->object->actuators.first;
349                         while(act) {
350                                 if(act == actuator_to_move) break;
351                                 act= act->next;
352                         }
353                         
354                         if(act) {
355                                 if( val==1 && act->prev) {
356                                         /* locate the first visible actuators before this one */
357                                         for (tmp = act->prev; tmp; tmp=tmp->prev) {
358                                                 if (tmp->flag & ACT_VISIBLE)
359                                                         break;
360                                         }
361                                         if (tmp) {
362                                                 BLI_remlink(&base->object->actuators, act);
363                                                 BLI_insertlinkbefore(&base->object->actuators, tmp, act);
364                                         }
365                                 }
366                                 else if( val==2 && act->next) {
367                                         for (tmp=act->next; tmp; tmp=tmp->next) {
368                                                 if (tmp->flag & ACT_VISIBLE)
369                                                         break;
370                                         }
371                                         if (tmp) {
372                                                 BLI_remlink(&base->object->actuators, act);
373                                                 BLI_insertlink(&base->object->actuators, tmp, act);
374                                         }
375                                 }
376                                 BIF_undo_push("Move actuator");
377                                 allqueue(REDRAWBUTSLOGIC, 0);
378                                 break;
379                         }
380                         
381                         base= base->next;
382                 }
383         }
384 }
385
386 void do_logic_buts(unsigned short event)
387 {
388         bProperty *prop;
389         bSensor *sens;
390         bController *cont;
391         bActuator *act;
392         Object *ob;
393         int didit, bit;
394         
395         ob= OBACT;
396         if(ob==0) return;
397         
398         switch(event) {
399
400         case B_SETSECTOR:
401                 /* check for inconsistant types */
402                 ob->gameflag &= ~(OB_PROP|OB_MAINACTOR|OB_DYNAMIC|OB_ACTOR);
403                 ob->dtx |= OB_BOUNDBOX;
404                 allqueue(REDRAWBUTSGAME, 0);
405                 allqueue(REDRAWVIEW3D, 0);
406                 break;
407                 
408         case B_SETPROP:
409                 /* check for inconsistant types */
410                 ob->gameflag &= ~(OB_SECTOR|OB_MAINACTOR|OB_DYNAMIC|OB_ACTOR);
411                 allqueue(REDRAWBUTSGAME, 0);
412                 allqueue(REDRAWVIEW3D, 0);
413                 break;
414
415         case B_SETACTOR:
416         case B_SETDYNA:
417         case B_SETMAINACTOR:
418                 ob->gameflag &= ~(OB_SECTOR|OB_PROP);
419                 allqueue(REDRAWBUTSGAME, 0);
420                 allqueue(REDRAWVIEW3D, 0);
421                 break;
422
423
424         case B_ADD_PROP:
425                 prop= new_property(PROP_FLOAT);
426                 make_unique_prop_names(prop->name);
427                 BLI_addtail(&ob->prop, prop);
428                 BIF_undo_push("Add property");
429                 allqueue(REDRAWBUTSLOGIC, 0);
430                 break;
431         
432         case B_CHANGE_PROP:
433                 prop= ob->prop.first;
434                 while(prop) {
435                         if(prop->type!=prop->otype) {
436                                 init_property(prop);
437                                 if (strcmp(prop->name, "Text") == 0) {
438                                         allqueue(REDRAWVIEW3D, 0);
439                                 }
440                         }
441                         prop= prop->next;
442                 }
443                 allqueue(REDRAWBUTSLOGIC, 0);
444                 break;
445         
446         case B_ADD_SENS:
447                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
448                         if(ob->scaflag & OB_ADDSENS) {
449                                 ob->scaflag &= ~OB_ADDSENS;
450                                 sens= new_sensor(SENS_ALWAYS);
451                                 BLI_addtail(&(ob->sensors), sens);
452                                 make_unique_prop_names(sens->name);
453                                 ob->scaflag |= OB_SHOWSENS;
454                         }
455                 }
456                 
457                 BIF_undo_push("Add sensor");
458                 allqueue(REDRAWBUTSLOGIC, 0);
459                 break;
460
461         case B_CHANGE_SENS:
462                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
463                         sens= ob->sensors.first;
464                         while(sens) {
465                                 if(sens->type != sens->otype) {
466                                         init_sensor(sens);
467                                         sens->otype= sens->type;
468                                         break;
469                                 }
470                                 sens= sens->next;
471                         }
472                 }
473                 allqueue(REDRAWBUTSLOGIC, 0);
474                 break;
475         
476         case B_DEL_SENS:
477                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
478                         sens= ob->sensors.first;
479                         while(sens) {
480                                 if(sens->flag & SENS_DEL) {
481                                         BLI_remlink(&(ob->sensors), sens);
482                                         free_sensor(sens);
483                                         break;
484                                 }
485                                 sens= sens->next;
486                         }
487                 }
488                 BIF_undo_push("Delete sensor");
489                 allqueue(REDRAWBUTSLOGIC, 0);
490                 break;
491         
492         case B_ADD_CONT:
493                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
494                         if(ob->scaflag & OB_ADDCONT) {
495                                 ob->scaflag &= ~OB_ADDCONT;
496                                 cont= new_controller(CONT_LOGIC_AND);
497                                 make_unique_prop_names(cont->name);
498                                 ob->scaflag |= OB_SHOWCONT;
499                                 BLI_addtail(&(ob->controllers), cont);
500                                 /* set the controller state mask from the current object state.
501                                    A controller is always in a single state, so select the lowest bit set
502                                    from the object state */
503                                 for (bit=0; bit<32; bit++) {
504                                         if (ob->state & (1<<bit))
505                                                 break;
506                                 }
507                                 cont->state_mask = (1<<bit);
508                                 if (cont->state_mask == 0) {
509                                         /* shouldn't happen, object state is never 0 */
510                                         cont->state_mask = 1;
511                                 }
512                         }
513                 }
514                 BIF_undo_push("Add controller");
515                 allqueue(REDRAWBUTSLOGIC, 0);
516                 break;
517
518         case B_SET_STATE_BIT:
519                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
520                         if(ob->scaflag & OB_SETSTBIT) {
521                                 ob->scaflag &= ~OB_SETSTBIT;
522                                 ob->state = 0x3FFFFFFF;
523                         }
524                 }
525                 allqueue(REDRAWBUTSLOGIC, 0);
526                 break;
527
528         case B_INIT_STATE_BIT:
529                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
530                         if(ob->scaflag & OB_INITSTBIT) {
531                                 ob->scaflag &= ~OB_INITSTBIT;
532                                 ob->state = ob->init_state;
533                                 if (!ob->state)
534                                         ob->state = 1;
535                         }
536                 }
537                 allqueue(REDRAWBUTSLOGIC, 0);
538                 break;
539
540         case B_CHANGE_CONT:
541                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
542                         cont= ob->controllers.first;
543                         while(cont) {
544                                 if(cont->type != cont->otype) {
545                                         init_controller(cont);
546                                         cont->otype= cont->type;
547                                         break;
548                                 }
549                                 cont= cont->next;
550                         }
551                 }
552                 allqueue(REDRAWBUTSLOGIC, 0);
553                 break;
554         
555
556         case B_DEL_CONT:
557                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
558                         cont= ob->controllers.first;
559                         while(cont) {
560                                 if(cont->flag & CONT_DEL) {
561                                         BLI_remlink(&(ob->controllers), cont);
562                                         unlink_controller(cont);
563                                         free_controller(cont);
564                                         break;
565                                 }
566                                 cont= cont->next;
567                         }
568                 }
569                 BIF_undo_push("Delete controller");
570                 allqueue(REDRAWBUTSLOGIC, 0);
571                 break;
572
573         case B_ADD_ACT:
574                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
575                         if(ob->scaflag & OB_ADDACT) {
576                                 ob->scaflag &= ~OB_ADDACT;
577                                 act= new_actuator(ACT_OBJECT);
578                                 make_unique_prop_names(act->name);
579                                 BLI_addtail(&(ob->actuators), act);
580                                 ob->scaflag |= OB_SHOWACT;
581                         }
582                 }
583                 BIF_undo_push("Add actuator");
584                 allqueue(REDRAWBUTSLOGIC, 0);
585                 break;
586
587         case B_CHANGE_ACT:
588                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
589                         act= ob->actuators.first;
590                         while(act) {
591                                 if(act->type != act->otype) {
592                                         init_actuator(act);
593                                         act->otype= act->type;
594                                         break;
595                                 }
596                                 act= act->next;
597                         }
598                 }
599                 allqueue(REDRAWBUTSLOGIC, 0);
600                 break;
601
602         case B_DEL_ACT:
603                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
604                         act= ob->actuators.first;
605                         while(act) {
606                                 if(act->flag & ACT_DEL) {
607                                         BLI_remlink(&(ob->actuators), act);
608                                         unlink_actuator(act);
609                                         free_actuator(act);
610                                         break;
611                                 }
612                                 act= act->next;
613                         }
614                 }
615                 BIF_undo_push("Delete actuator");
616                 allqueue(REDRAWBUTSLOGIC, 0);
617                 break;
618         
619         case B_SOUNDACT_BROWSE:
620                 /* since we don't know which... */
621                 didit= 0;
622                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
623                         act= ob->actuators.first;
624                         while(act)
625                         {
626                                 if(act->type==ACT_SOUND)
627                                 {
628                                         bSoundActuator *sa= act->data;
629                                         if(sa->sndnr)
630                                         {
631                                                 bSound *sound= G.main->sound.first;
632                                                 int nr= 1;
633
634                                                 if(sa->sndnr == -2) {
635                                                         activate_databrowse((ID *)G.main->sound.first, ID_SO, 0, B_SOUNDACT_BROWSE,
636                                                                                         &sa->sndnr, do_logic_buts);
637                                                         break;
638                                                 }
639
640                                                 while(sound)
641                                                 {
642                                                         if(nr==sa->sndnr)
643                                                                 break;
644                                                         nr++;
645                                                         sound= sound->id.next;
646                                                 }
647                                                 
648                                                 if(sa->sound)
649                                                         sa->sound->id.us--;
650                                                 
651                                                 sa->sound= sound;
652                                                 
653                                                 if(sound)
654                                                         sound->id.us++;
655                                                 
656                                                 sa->sndnr= 0;
657                                                 didit= 1;
658                                         }
659                                 }
660                                 act= act->next;
661                         }
662                         if(didit)
663                                 break;
664                 }
665                 allqueue(REDRAWBUTSLOGIC, 0);
666                 allqueue(REDRAWSOUND, 0);
667
668                 break;
669         }
670 }
671
672
673 static char *sensor_name(int type)
674 {
675         switch (type) {
676         case SENS_ALWAYS:
677                 return "Always";
678         case SENS_TOUCH:
679                 return "Touch";
680         case SENS_NEAR:
681                 return "Near";
682         case SENS_KEYBOARD:
683                 return "Keyboard";
684         case SENS_PROPERTY:
685                 return "Property";
686         case SENS_ACTUATOR:
687                 return "Actuator";
688         case SENS_DELAY:
689                 return "Delay";
690         case SENS_MOUSE:
691                 return "Mouse";
692         case SENS_COLLISION:
693                 return "Collision";
694         case SENS_RADAR:
695                 return "Radar";
696         case SENS_RANDOM:
697                 return "Random";
698         case SENS_RAY:
699                 return "Ray";
700         case SENS_MESSAGE:
701                 return "Message";
702         case SENS_JOYSTICK:
703                 return "Joystick";
704         }
705         return "unknown";
706 }
707
708 static char *sensor_pup(void)
709 {
710         /* the number needs to match defines in game.h */
711         return "Sensors %t|Always %x0|Delay %x13|Keyboard %x3|Mouse %x5|"
712                 "Touch %x1|Collision %x6|Near %x2|Radar %x7|"
713                 "Property %x4|Random %x8|Ray %x9|Message %x10|Joystick %x11|Actuator %x12";
714 }
715
716 static char *controller_name(int type)
717 {
718         switch (type) {
719         case CONT_LOGIC_AND:
720                 return "AND";
721         case CONT_LOGIC_OR:
722                 return "OR";
723         case CONT_LOGIC_NAND:
724                 return "NAND";
725         case CONT_LOGIC_NOR:
726                 return "NOR";
727         case CONT_LOGIC_XOR:
728                 return "XOR";
729         case CONT_LOGIC_XNOR:
730                 return "XNOR";
731         case CONT_EXPRESSION:
732                 return "Expression";
733         case CONT_PYTHON:
734                 return "Python";
735         }
736         return "unknown";
737 }
738
739 static char *controller_pup(void)
740 {
741         return "Controllers   %t|AND %x0|OR %x1|XOR %x6|NAND %x4|NOR %x5|XNOR %x7|Expression %x2|Python %x3";
742 }
743
744 static char *actuator_name(int type)
745 {
746         switch (type) {
747         case ACT_SHAPEACTION:
748                 return "Shape Action";
749         case ACT_ACTION:
750                 return "Action";
751         case ACT_OBJECT:
752                 return "Motion";
753         case ACT_IPO:
754                 return "Ipo";
755         case ACT_LAMP:
756                 return "Lamp";
757         case ACT_CAMERA:
758                 return "Camera";
759         case ACT_MATERIAL:
760                 return "Material";
761         case ACT_SOUND:
762                 return "Sound";
763         case ACT_CD:
764                 return "CD";
765         case ACT_PROPERTY:
766                 return "Property";
767         case ACT_EDIT_OBJECT:
768                 return "Edit Object";
769         case ACT_CONSTRAINT:
770                 return "Constraint";
771         case ACT_SCENE:
772                 return "Scene";
773         case ACT_GROUP:
774                 return "Group";
775         case ACT_RANDOM:
776                 return "Random";
777         case ACT_MESSAGE:
778                 return "Message";
779         case ACT_GAME:
780                 return "Game";
781         case ACT_VISIBILITY:
782                 return "Visibility";
783         case ACT_2DFILTER:
784                 return "2D Filter";
785         case ACT_PARENT:
786                 return "Parent";
787         case ACT_STATE:
788                 return "State";
789         }
790         return "unknown";
791 }
792
793
794
795
796 static char *actuator_pup(Object *owner)
797 {
798         switch (owner->type)
799         {
800         case OB_ARMATURE:
801                 return "Actuators  %t|Action %x15|Motion %x0|Constraint %x9|Ipo %x1"
802                         "|Camera %x3|Sound %x5|Property %x6|Edit Object %x10"
803                         "|Scene %x11|Random %x13|Message %x14|CD %x16|Game %x17"
804                         "|Visibility %x18|2D Filter %x19|Parent %x20|State %x22";
805                 break;
806
807         case OB_MESH:
808                 return "Actuators  %t|Shape Action %x21|Motion %x0|Constraint %x9|Ipo %x1"
809                         "|Camera %x3|Sound %x5|Property %x6|Edit Object %x10"
810                         "|Scene %x11|Random %x13|Message %x14|CD %x16|Game %x17"
811                         "|Visibility %x18|2D Filter %x19|Parent %x20|State %x22";
812                 break;
813
814         default:
815                 return "Actuators  %t|Motion %x0|Constraint %x9|Ipo %x1"
816                         "|Camera %x3|Sound %x5|Property %x6|Edit Object %x10"
817                         "|Scene %x11|Random %x13|Message %x14|CD %x16|Game %x17"
818                         "|Visibility %x18|2D Filter %x19|Parent %x20|State %x22";
819         }
820 }
821
822
823
824 static void set_sca_ob(Object *ob)
825 {
826         bController *cont;
827         bActuator *act;
828
829         cont= ob->controllers.first;
830         while(cont) {
831                 cont->mynew= (bController *)ob;
832                 cont= cont->next;
833         }
834         act= ob->actuators.first;
835         while(act) {
836                 act->mynew= (bActuator *)ob;
837                 act= act->next;
838         }
839 }
840
841 static ID **get_selected_and_linked_obs(short *count, short scavisflag)
842 {
843         Base *base;
844         Object *ob, *obt;
845         ID **idar;
846         bSensor *sens;
847         bController *cont;
848         unsigned int lay;
849         int a, nr, doit;
850         
851         /* we need a sorted object list */
852         /* set scavisflags flags in Objects to indicate these should be evaluated */
853         /* also hide ob pointers in ->new entries of controllerss/actuators */
854         
855         *count= 0;
856         
857         if(G.scene==NULL) return NULL;
858         
859         ob= G.main->object.first;
860         while(ob) {
861                 ob->scavisflag= 0;
862                 set_sca_ob(ob);
863                 ob= ob->id.next;
864         }
865         
866         if(G.vd) lay= G.vd->lay;
867         else lay= G.scene->lay;
868         
869         base= FIRSTBASE;
870         while(base) {
871                 if(base->lay & lay) {
872                         if(base->flag & SELECT) {
873                                 if(scavisflag & BUTS_SENS_SEL) base->object->scavisflag |= OB_VIS_SENS;
874                                 if(scavisflag & BUTS_CONT_SEL) base->object->scavisflag |= OB_VIS_CONT;
875                                 if(scavisflag & BUTS_ACT_SEL) base->object->scavisflag |= OB_VIS_ACT;
876                         }
877                 }
878                 base= base->next;
879         }
880
881         if(OBACT) {
882                 if(scavisflag & BUTS_SENS_ACT) OBACT->scavisflag |= OB_VIS_SENS;
883                 if(scavisflag & BUTS_CONT_ACT) OBACT->scavisflag |= OB_VIS_CONT;
884                 if(scavisflag & BUTS_ACT_ACT) OBACT->scavisflag |= OB_VIS_ACT;
885         }
886         
887         /* BUTS_XXX_STATE are similar to BUTS_XXX_LINK for selecting the object */
888         if(scavisflag & (BUTS_SENS_LINK|BUTS_CONT_LINK|BUTS_ACT_LINK|BUTS_SENS_STATE|BUTS_ACT_STATE)) {
889                 doit= 1;
890                 while(doit) {
891                         doit= 0;
892                         
893                         ob= G.main->object.first;
894                         while(ob) {
895                         
896                                 /* 1st case: select sensor when controller selected */
897                                 if((scavisflag & (BUTS_SENS_LINK|BUTS_SENS_STATE)) && (ob->scavisflag & OB_VIS_SENS)==0) {
898                                         sens= ob->sensors.first;
899                                         while(sens) {
900                                                 for(a=0; a<sens->totlinks; a++) {
901                                                         if(sens->links[a]) {
902                                                                 obt= (Object *)sens->links[a]->mynew;
903                                                                 if(obt && (obt->scavisflag & OB_VIS_CONT)) {
904                                                                         doit= 1;
905                                                                         ob->scavisflag |= OB_VIS_SENS;
906                                                                         break;
907                                                                 }
908                                                         }
909                                                 }
910                                                 if(doit) break;
911                                                 sens= sens->next;
912                                         }
913                                 }
914                                 
915                                 /* 2nd case: select cont when act selected */
916                                 if((scavisflag & BUTS_CONT_LINK)  && (ob->scavisflag & OB_VIS_CONT)==0) {
917                                         cont= ob->controllers.first;
918                                         while(cont) {
919                                                 for(a=0; a<cont->totlinks; a++) {
920                                                         if(cont->links[a]) {
921                                                                 obt= (Object *)cont->links[a]->mynew;
922                                                                 if(obt && (obt->scavisflag & OB_VIS_ACT)) {
923                                                                         doit= 1;
924                                                                         ob->scavisflag |= OB_VIS_CONT;
925                                                                         break;
926                                                                 }
927                                                         }
928                                                 }
929                                                 if(doit) break;
930                                                 cont= cont->next;
931                                         }
932                                 }
933                                 
934                                 /* 3rd case: select controller when sensor selected */
935                                 if((scavisflag & BUTS_CONT_LINK) && (ob->scavisflag & OB_VIS_SENS)) {
936                                         sens= ob->sensors.first;
937                                         while(sens) {
938                                                 for(a=0; a<sens->totlinks; a++) {
939                                                         if(sens->links[a]) {
940                                                                 obt= (Object *)sens->links[a]->mynew;
941                                                                 if(obt && (obt->scavisflag & OB_VIS_CONT)==0) {
942                                                                         doit= 1;
943                                                                         obt->scavisflag |= OB_VIS_CONT;
944                                                                 }
945                                                         }
946                                                 }
947                                                 sens= sens->next;
948                                         }
949                                 }
950                                 
951                                 /* 4th case: select actuator when controller selected */
952                                 if( (scavisflag & (BUTS_ACT_LINK|BUTS_ACT_STATE))  && (ob->scavisflag & OB_VIS_CONT)) {
953                                         cont= ob->controllers.first;
954                                         while(cont) {
955                                                 for(a=0; a<cont->totlinks; a++) {
956                                                         if(cont->links[a]) {
957                                                                 obt= (Object *)cont->links[a]->mynew;
958                                                                 if(obt && (obt->scavisflag & OB_VIS_ACT)==0) {
959                                                                         doit= 1;
960                                                                         obt->scavisflag |= OB_VIS_ACT;
961                                                                 }
962                                                         }
963                                                 }
964                                                 cont= cont->next;
965                                         }
966                                         
967                                 }
968                                 ob= ob->id.next;
969                         }
970                 }
971         } 
972         
973         /* now we count */
974         ob= G.main->object.first;
975         while(ob) {
976                 if( ob->scavisflag ) (*count)++;
977                 ob= ob->id.next;
978         }
979
980         if(*count==0) return NULL;
981         if(*count>24) *count= 24;               /* temporal */
982         
983         idar= MEM_callocN( (*count)*sizeof(void *), "idar");
984         
985         ob= G.main->object.first;
986         nr= 0;
987         while(ob) {
988                 if( ob->scavisflag ) {
989                         idar[nr]= (ID *)ob;
990                         nr++;
991                 }
992                 if(nr>=24) break;
993                 ob= ob->id.next;
994         }
995         
996         /* just to be sure... these were set in set_sca_done_ob() */
997         clear_sca_new_poins();
998         
999         return idar;
1000 }
1001
1002
1003 static int get_col_sensor(int type)
1004 {
1005         switch(type) {
1006         case SENS_ALWAYS:               return TH_BUT_ACTION;
1007         case SENS_DELAY:                return TH_BUT_ACTION;
1008         case SENS_TOUCH:                return TH_BUT_NEUTRAL;
1009         case SENS_COLLISION:    return TH_BUT_SETTING;
1010         case SENS_NEAR:                 return TH_BUT_SETTING1; 
1011         case SENS_KEYBOARD:             return TH_BUT_SETTING2;
1012         case SENS_PROPERTY:             return TH_BUT_NUM;
1013         case SENS_ACTUATOR:             return TH_BUT_NUM;
1014         case SENS_MOUSE:                return TH_BUT_TEXTFIELD;
1015         case SENS_RADAR:                return TH_BUT_POPUP;
1016         case SENS_RANDOM:               return TH_BUT_NEUTRAL;
1017         case SENS_RAY:                  return TH_BUT_SETTING1;
1018         case SENS_MESSAGE:              return TH_BUT_SETTING2;
1019         case SENS_JOYSTICK:             return TH_BUT_NEUTRAL;
1020         default:                                return TH_BUT_NEUTRAL;
1021         }
1022 }
1023 static void set_col_sensor(int type, int medium)
1024 {
1025         int col= get_col_sensor(type);
1026         BIF_ThemeColorShade(col, medium?30:0);
1027 }
1028
1029 /**
1030  * Draws a toggle for pulse mode, a frequency field and a toggle to invert
1031  * the value of this sensor. Operates on the shared data block of sensors.
1032  */
1033 static void draw_default_sensor_header(bSensor *sens,
1034                                                                 uiBlock *block,
1035                                                                 short x,
1036                                                                 short y,
1037                                                                 short w) 
1038 {
1039         /* Pulsing and frequency */
1040         uiDefIconButBitS(block, TOG, SENS_PULSE_REPEAT, 1, ICON_DOTSUP,
1041                          (short)(x + 10 + 0. * (w-20)), (short)(y - 21), (short)(0.15 * (w-20)), 19,
1042                          &sens->pulse, 0.0, 0.0, 0, 0,
1043                          "Activate TRUE level triggering (pulse mode)");
1044
1045         uiDefIconButBitS(block, TOG, SENS_NEG_PULSE_MODE, 1, ICON_DOTSDOWN,
1046                          (short)(x + 10 + 0.15 * (w-20)), (short)(y - 21), (short)(0.15 * (w-20)), 19,
1047                          &sens->pulse, 0.0, 0.0, 0, 0,
1048                          "Activate FALSE level triggering (pulse mode)");
1049         uiDefButS(block, NUM, 1, "f:",
1050                          (short)(x + 10 + 0.3 * (w-20)), (short)(y - 21), (short)(0.275 * (w-20)), 19,
1051                          &sens->freq, 0.0, 10000.0, 0, 0,
1052                          "Delay between repeated pulses (in logic tics, 0 = no delay)");
1053         
1054         /* value or shift? */
1055         uiDefButS(block, TOG, 1, "Inv",
1056                          (short)(x + 10 + 0.85 * (w-20)), (short)(y - 21), (short)(0.15 * (w-20)), 19,
1057                          &sens->invert, 0.0, 0.0, 0, 0,
1058                          "Invert the level (output) of this sensor");
1059         uiDefButS(block, TOG, 1, "Level",
1060                          (short)(x + 10 + 0.65 * (w-20)), (short)(y - 21), (short)(0.20 * (w-20)), 19,
1061                          &sens->level, 0.0, 0.0, 0, 0,
1062                          "Level detector, trigger controllers of new states (only applicable upon logic state transition)");
1063 }
1064
1065 static short draw_sensorbuttons(bSensor *sens, uiBlock *block, short xco, short yco, short width,char* objectname)
1066 {
1067         bNearSensor      *ns           = NULL;
1068         bTouchSensor     *ts           = NULL;
1069         bKeyboardSensor  *ks           = NULL;
1070         bPropertySensor  *ps           = NULL;
1071         bMouseSensor     *ms           = NULL;
1072         bCollisionSensor *cs           = NULL;
1073         bRadarSensor     *rs           = NULL;
1074         bRandomSensor    *randomSensor = NULL;
1075         bRaySensor       *raySens      = NULL;
1076         bMessageSensor   *mes          = NULL;
1077         bJoystickSensor  *joy              = NULL;
1078         bActuatorSensor  *as           = NULL;
1079         bDelaySensor     *ds               = NULL;
1080         short ysize;
1081         char *str;
1082         
1083         /* yco is at the top of the rect, draw downwards */
1084         
1085         uiBlockSetEmboss(block, UI_EMBOSSM);
1086         
1087         set_col_sensor(sens->type, 0);
1088         
1089         switch (sens->type)
1090         {
1091         case SENS_ALWAYS:
1092                 {
1093                         ysize= 24;
1094                         
1095                         glRects(xco, yco-ysize, xco+width, yco);
1096                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1097                         
1098                         draw_default_sensor_header(sens, block, xco, yco, width);
1099                         
1100                         yco-= ysize;
1101                         
1102                         break;
1103                 }
1104         case SENS_TOUCH:
1105                 {
1106                         ysize= 48; 
1107                         
1108                         glRects(xco, yco-ysize, xco+width, yco); 
1109                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1110                         
1111                         draw_default_sensor_header(sens, block, xco, yco, width);
1112                         
1113                         ts= sens->data; 
1114                         
1115                         /* uiDefBut(block, TEX, 1, "Property:", xco,yco-22,width, 19, &ts->name, 0, 31, 0, 0, "Only look for Objects with this property"); */
1116                         uiDefIDPoinBut(block, test_matpoin_but, ID_MA, 1, "MA:",(short)(xco + 10),(short)(yco-44), (short)(width - 20), 19, &ts->ma,  "Only look for floors with this Material"); 
1117                         ///* uiDefButF(block, NUM, 1, "Margin:",        xco+width/2,yco-44,width/2, 19, &ts->dist, 0.0, 10.0, 100, 0, "Extra margin (distance) for larger sensitivity"); 
1118                         yco-= ysize; 
1119                         break; 
1120                 }
1121         case SENS_COLLISION:
1122                 {
1123                         ysize= 48;
1124                         
1125                         glRects(xco, yco-ysize, xco+width, yco);
1126                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1127                         
1128                         draw_default_sensor_header(sens, block, xco, yco, width);
1129                         cs= sens->data;
1130                         
1131                         /* The collision sensor will become a generic collision (i.e. it     */
1132                         /* absorb the old touch sensor).                                     */
1133
1134                         uiDefButBitS(block, TOG, SENS_COLLISION_PULSE, B_REDR, "Pulse",(short)(xco + 10),(short)(yco - 44),
1135                                 (short)(0.20 * (width-20)), 19, &cs->mode, 0.0, 0.0, 0, 0,
1136                                 "Changes to the set of colliding objects generate pulses");
1137                         
1138                         uiDefButBitS(block, TOG, SENS_COLLISION_MATERIAL, B_REDR, "M/P",(short)(xco + 10 + (0.20 * (width-20))),(short)(yco - 44),
1139                                 (short)(0.20 * (width-20)), 19, &cs->mode, 0.0, 0.0, 0, 0,
1140                                 "Toggle collision on material or property.");
1141                         
1142                         if (cs->mode & SENS_COLLISION_MATERIAL) {
1143                                 uiDefBut(block, TEX, 1, "Material:", (short)(xco + 10 + 0.40 * (width-20)),
1144                                         (short)(yco-44), (short)(0.6*(width-20)), 19, &cs->materialName, 0, 31, 0, 0,
1145                                         "Only look for Objects with this material");
1146                         } else {
1147                                 uiDefBut(block, TEX, 1, "Property:", (short)(xco + 10 + 0.40 * (width-20)), (short)(yco-44),
1148                                         (short)(0.6*(width-20)), 19, &cs->name, 0, 31, 0, 0,
1149                                         "Only look for Objects with this property");
1150                         }
1151         
1152                         /*              uiDefButS(block, NUM, 1, "Damp:",       xco+10+width-90,yco-24, 70, 19, &cs->damp, 0, 250, 0, 0, "For 'damp' time don't detect another collision"); */
1153                         
1154                         yco-= ysize;
1155                         break;
1156                 }
1157         case SENS_NEAR:
1158                 {
1159                         ysize= 72;
1160                         
1161                         glRects(xco, yco-ysize, xco+width, yco);
1162                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1163                         
1164                         draw_default_sensor_header(sens, block, xco, yco, width);
1165                         ns= sens->data;
1166                         
1167                         uiDefBut(block, TEX, 1, "Property:",(short)(10+xco),(short)(yco-44), (short)(width-20), 19,
1168                                 &ns->name, 0, 31, 0, 0, "Only look for Objects with this property");
1169                         uiDefButF(block, NUM, 1, "Dist",(short)(10+xco),(short)(yco-68),(short)((width-22)/2), 19,
1170                                 &ns->dist, 0.0, 1000.0, 1000, 0, "Trigger distance");
1171                         uiDefButF(block, NUM, 1, "Reset",(short)(10+xco+(width-22)/2), (short)(yco-68), (short)((width-22)/2), 19,
1172                                 &ns->resetdist, 0.0, 1000.0, 1000, 0, "Reset distance"); 
1173                         yco-= ysize;
1174                         break;
1175                 }
1176         case SENS_RADAR:
1177                 {
1178                         ysize= 72; 
1179                         
1180                         glRects(xco, yco-ysize, xco+width, yco);
1181                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1182                         
1183                         draw_default_sensor_header(sens, block, xco, yco, width);
1184                         
1185                         rs= sens->data;
1186                         
1187                         uiDefBut(block, TEX, 1, "Prop:",
1188                                          (short)(10+xco),(short)(yco-44), (short)(0.7 * (width-20)), 19,
1189                                          &rs->name, 0, 31, 0, 0,
1190                                          "Only look for Objects with this property");
1191
1192                         str = "Type %t|+X axis %x0|+Y axis %x1|+Z axis %x2|-X axis %x3|-Y axis %x4|-Z axis %x5"; 
1193                         uiDefButS(block, MENU, B_REDR, str,
1194                                 (short)(10+xco+0.7 * (width-20)), (short)(yco-44), (short)(0.3 * (width-22)), 19,
1195                                 &rs->axis, 2.0, 31, 0, 0,
1196                                 "Specify along which axis the radar cone is cast.");
1197                                 
1198                         uiDefButF(block, NUM, 1, "Ang:",
1199                                          (short)(10+xco), (short)(yco-68), (short)((width-20)/2), 19,
1200                                          &rs->angle, 0.0, 179.9, 10, 0,
1201                                          "Opening angle of the radar cone.");
1202                         uiDefButF(block, NUM, 1, "Dist:",
1203                                          (short)(xco+10 + (width-20)/2), (short)(yco-68), (short)((width-20)/2), 19,
1204                                          &rs->range, 0.01, 10000.0, 100, 0,
1205                                          "Depth of the radar cone");
1206                         yco-= ysize;
1207                         break;
1208                 }
1209         case SENS_KEYBOARD:
1210                 {
1211                         ks= sens->data;
1212                         
1213                         /* 5 lines: 120 height */
1214                         ysize= (ks->type&1) ? 96:120;
1215                         
1216                         glRects(xco, yco-ysize, xco+width, yco);
1217                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1218                         
1219                         /* header line */
1220                         draw_default_sensor_header(sens, block, xco, yco, width);
1221                         
1222                         /* part of line 1 */
1223                         uiBlockSetCol(block, TH_BUT_SETTING2);
1224                         uiDefBut(block, LABEL, 0, "Key",          xco, yco-44, 40, 19, NULL, 0, 0, 0, 0, "");
1225                         uiDefButBitS(block, TOG, 1, B_REDR, "All keys",   xco+40+(width/2), yco-44, (width/2)-50, 19,
1226                                 &ks->type, 0, 0, 0, 0, "");
1227                         
1228                         
1229                         if ((ks->type&1)==0) { /* is All Keys option off? */
1230                                 /* line 2: hotkey and allkeys toggle */
1231                                 uiDefKeyevtButS(block, B_DIFF, "", xco+40, yco-44, (width)/2, 19, &ks->key, "Key code");
1232                                 
1233                                 /* line 3: two key modifyers (qual1, qual2) */
1234                                 uiDefBut(block, LABEL, 0, "Hold",         xco, yco-68, 40, 19, NULL, 0, 0, 0, 0, "");
1235                                 uiDefKeyevtButS(block, B_DIFF, "", xco+40, yco-68, (width-50)/2, 19, &ks->qual, "Modifier key code");
1236                                 uiDefKeyevtButS(block, B_DIFF, "", xco+40+(width-50)/2, yco-68, (width-50)/2, 19, &ks->qual2, "Second Modifier key code");
1237                         }
1238                         
1239                         /* line 4: toggle property for string logging mode */
1240                         uiDefBut(block, TEX, 1, "LogToggle: ",
1241                                 xco+10, yco-((ks->type&1) ? 68:92), (width-20), 19,
1242                                 ks->toggleName, 0, 31, 0, 0,
1243                                 "Property that indicates whether to log "
1244                                 "keystrokes as a string.");
1245                         
1246                         /* line 5: target property for string logging mode */
1247                         uiDefBut(block, TEX, 1, "Target: ",
1248                                 xco+10, yco-((ks->type&1) ? 92:116), (width-20), 19,
1249                                 ks->targetName, 0, 31, 0, 0,
1250                                 "Property that receives the keystrokes in case "
1251                                 "a string is logged.");
1252                         
1253                         yco-= ysize;
1254                         break;
1255                 }
1256         case SENS_PROPERTY:
1257                 {
1258                         ysize= 96;
1259                         
1260                         glRects(xco, yco-ysize, xco+width, yco);
1261                         uiEmboss((float)xco, (float)yco-ysize,
1262                                 (float)xco+width, (float)yco, 1);
1263                         
1264                         draw_default_sensor_header(sens, block, xco, yco, width);
1265                         ps= sens->data;
1266                         
1267                         str= "Type %t|Equal %x0|Not Equal %x1|Interval %x2|Changed %x3"; 
1268                         /* str= "Type %t|Equal %x0|Not Equal %x1"; */
1269                         uiDefButI(block, MENU, B_REDR, str,                     xco+30,yco-44,width-60, 19,
1270                                 &ps->type, 0, 31, 0, 0, "Type");
1271                         
1272                         if (ps->type != SENS_PROP_EXPRESSION)
1273                         {
1274                                 uiDefBut(block, TEX, 1, "Prop: ",                       xco+30,yco-68,width-60, 19,
1275                                         ps->name, 0, 31, 0, 0,  "Property name");
1276                         }
1277                         
1278                         if(ps->type == SENS_PROP_INTERVAL)
1279                         {
1280                                 uiDefBut(block, TEX, 1, "Min: ",                xco,yco-92,width/2, 19,
1281                                         ps->value, 0, 31, 0, 0, "check for min value");
1282                                 uiDefBut(block, TEX, 1, "Max: ",                xco+width/2,yco-92,width/2, 19,
1283                                         ps->maxvalue, 0, 31, 0, 0, "check for max value");
1284                         }
1285                         else if(ps->type == SENS_PROP_CHANGED);
1286                         else
1287                         {
1288                                 uiDefBut(block, TEX, 1, "Value: ",              xco+30,yco-92,width-60, 19,
1289                                         ps->value, 0, 31, 0, 0, "check for value");
1290                         }
1291                         
1292                         yco-= ysize;
1293                         break;
1294                 }
1295         case SENS_ACTUATOR:
1296                 {
1297                         ysize= 48;
1298                         
1299                         glRects(xco, yco-ysize, xco+width, yco);
1300                         uiEmboss((float)xco, (float)yco-ysize,
1301                                 (float)xco+width, (float)yco, 1);
1302                         
1303                         draw_default_sensor_header(sens, block, xco, yco, width);
1304                         as= sens->data;
1305                         
1306                         uiDefBut(block, TEX, 1, "Act: ",                        xco+30,yco-44,width-60, 19,
1307                                         as->name, 0, 31, 0, 0,  "Actuator name, actuator active state modifications will be detected");
1308                         yco-= ysize;
1309                         break;
1310                 }
1311         case SENS_DELAY:
1312                 {
1313                         ysize= 48;
1314                         
1315                         glRects(xco, yco-ysize, xco+width, yco);
1316                         uiEmboss((float)xco, (float)yco-ysize,
1317                                 (float)xco+width, (float)yco, 1);
1318                         
1319                         draw_default_sensor_header(sens, block, xco, yco, width);
1320                         ds = sens->data;
1321                         
1322                         uiDefButS(block, NUM, 0, "Delay",(short)(10+xco),(short)(yco-44),(short)((width-22)*0.4+10), 19,
1323                                 &ds->delay, 0.0, 5000.0, 0, 0, "Delay in number of logic tics before the positive trigger (default 60 per second)");
1324                         uiDefButS(block, NUM, 0, "Dur",(short)(10+xco+(width-22)*0.4+10),(short)(yco-44),(short)((width-22)*0.4-10), 19,
1325                                 &ds->duration, 0.0, 5000.0, 0, 0, "If >0, delay in number of logic tics before the negative trigger following the positive trigger");
1326                         uiDefButBitS(block, TOG, SENS_DELAY_REPEAT, 0, "REP",(short)(xco + 10 + (width-22)*0.8),(short)(yco - 44),
1327                                 (short)(0.20 * (width-22)), 19, &ds->flag, 0.0, 0.0, 0, 0,
1328                                 "Toggle repeat option. If selected, the sensor restarts after Delay+Dur logic tics");
1329                         yco-= ysize;
1330                         break;
1331                 }
1332         case SENS_MOUSE:
1333                 {
1334                         ms= sens->data;
1335                         /* Two lines: 48 pixels high. */
1336                         ysize = 48;
1337                         
1338                         glRects(xco, yco-ysize, xco+width, yco);
1339                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1340                         
1341                         /* line 1: header */
1342                         draw_default_sensor_header(sens, block, xco, yco, width);
1343                         
1344                         /* Line 2: type selection. The number are a bit mangled to get
1345                         * proper compatibility with older .blend files. */
1346                         str= "Type %t|Left button %x1|Middle button %x2|"
1347                                 "Right button %x4|Wheel Up %x5|Wheel Down %x6|Movement %x8|Mouse over %x16|Mouse over any%x32"; 
1348                         uiDefButS(block, MENU, B_REDR, str, xco+10, yco-44, width-20, 19,
1349                                 &ms->type, 0, 31, 0, 0,
1350                                 "Specify the type of event this mouse sensor should trigger on.");
1351                         
1352                         yco-= ysize;
1353                         break;
1354                 }
1355         case SENS_RANDOM:
1356                 {
1357                         ysize = 48;
1358                         
1359                         glRects(xco, yco-ysize, xco+width, yco);
1360                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1361                         
1362                         draw_default_sensor_header(sens, block, xco, yco, width);
1363                         randomSensor = sens->data;
1364                         /* some files were wrongly written, avoid crash now */
1365                         if (randomSensor)
1366                         {
1367                                 uiDefButI(block, NUM, 1, "Seed: ",              xco+10,yco-44,(width-20), 19,
1368                                         &randomSensor->seed, 0, 1000, 0, 0,
1369                                         "Initial seed of the generator. (Choose 0 for not random)");
1370                         }
1371                         yco-= ysize;
1372                         break;
1373                 }
1374         case SENS_RAY:
1375                 {
1376                         ysize = 72;
1377                         glRects(xco, yco-ysize, xco+width, yco);
1378                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1379                         
1380                         draw_default_sensor_header(sens, block, xco, yco, width);
1381                         raySens = sens->data;
1382                         
1383                         /* 1. property or material */
1384                         uiDefButBitS(block, TOG, SENS_COLLISION_MATERIAL, B_REDR, "M/P",
1385                                 xco + 10,yco - 44, 0.20 * (width-20), 19,
1386                                 &raySens->mode, 0.0, 0.0, 0, 0,
1387                                 "Toggle collision on material or property.");
1388                         
1389                         if (raySens->mode & SENS_COLLISION_MATERIAL)
1390                         {
1391                                 uiDefBut(block, TEX, 1, "Material:", xco + 10 + 0.20 * (width-20), yco-44, 0.8*(width-20), 19,
1392                                         &raySens->matname, 0, 31, 0, 0,
1393                                         "Only look for Objects with this material");
1394                         }
1395                         else
1396                         {
1397                                 uiDefBut(block, TEX, 1, "Property:", xco + 10 + 0.20 * (width-20), yco-44, 0.8*(width-20), 19,
1398                                         &raySens->propname, 0, 31, 0, 0,
1399                                         "Only look for Objects with this property");
1400                         }
1401
1402                         /* X-Ray option */
1403                         uiDefButBitS(block, TOG, SENS_RAY_XRAY, 1, "X",
1404                                 xco + 10,yco - 68, 0.10 * (width-20), 19,
1405                                 &raySens->mode, 0.0, 0.0, 0, 0,
1406                                 "Toggle X-Ray option (see through objects that don't have the property)");
1407                         /* 2. sensing range */
1408                         uiDefButF(block, NUM, 1, "Range", xco+10 + 0.10 * (width-20), yco-68, 0.5 * (width-20), 19,
1409                                 &raySens->range, 0.01, 10000.0, 100, 0,
1410                                 "Sense objects no farther than this distance");
1411                         
1412                         /* 3. axis choice */
1413                         str = "Type %t|+ X axis %x1|+ Y axis %x0|+ Z axis %x2|- X axis %x3|- Y axis %x4|- Z axis %x5"; 
1414                         uiDefButI(block, MENU, B_REDR, str, xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1415                                 &raySens->axisflag, 2.0, 31, 0, 0,
1416                                 "Specify along which axis the ray is cast.");
1417                         
1418                         yco-= ysize;            
1419                         break;
1420                 }
1421         case SENS_MESSAGE:
1422                 {
1423                         mes = sens->data;
1424                         ysize = 2 * 24; /* total number of lines * 24 pixels/line */
1425                         
1426                         glRects(xco, yco-ysize, xco+width, yco);
1427                         uiEmboss((float)xco, (float)yco-ysize,
1428                                 (float)xco+width, (float)yco, 1);
1429                         
1430                         /* line 1: header line */
1431                         draw_default_sensor_header(sens, block, xco, yco, width);
1432                         
1433                         /* line 2: Subject filter */
1434                         uiDefBut(block, TEX, 1, "Subject: ",
1435                                 (xco+10), (yco-44), (width-20), 19,
1436                                 mes->subject, 0, 31, 0, 0,
1437                                 "Optional subject filter: only accept messages with this subject"
1438                                 ", or empty for all");
1439                         
1440                         yco -= ysize;
1441                         break;
1442                 }
1443                 case SENS_JOYSTICK:
1444                 {
1445
1446                         ysize =  72;
1447                         
1448                         glRects(xco, yco-ysize, xco+width, yco);
1449                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1450                         
1451                         /* line 1: header */
1452                         draw_default_sensor_header(sens, block, xco, yco, width);
1453
1454                         joy= sens->data;
1455
1456                         uiDefButC(block, NUM, 1, "Index:", xco+10, yco-44, 0.33 * (width-20), 19,
1457                         &joy->joyindex, 0, SENS_JOY_MAXINDEX-1, 100, 0,
1458                         "Specify which joystick to use");                       
1459
1460                         str= "Type %t|Button %x0|Axis %x1|Single Axis %x3|Hat%x2"; 
1461                         uiDefButC(block, MENU, B_REDR, str, xco+87, yco-44, 0.26 * (width-20), 19,
1462                                 &joy->type, 0, 31, 0, 0,
1463                                 "The type of event this joystick sensor is triggered on.");
1464                         
1465                         if (joy->type != SENS_JOY_AXIS_SINGLE) {
1466                                 if (joy->flag & SENS_JOY_ANY_EVENT) {
1467                                         switch (joy->type) {
1468                                         case SENS_JOY_AXIS:     
1469                                                 str = "All Axis Events";
1470                                                 break;
1471                                         case SENS_JOY_BUTTON:   
1472                                                 str = "All Button Events";
1473                                                 break;
1474                                         default:
1475                                                 str = "All Hat Events";
1476                                                 break;
1477                                         }
1478                                 } else {
1479                                         str = "All";
1480                                 }
1481                                 
1482                                 uiDefButBitS(block, TOG, SENS_JOY_ANY_EVENT, B_REDR, str,
1483                                         xco+10 + 0.475 * (width-20), yco-68, ((joy->flag & SENS_JOY_ANY_EVENT) ? 0.525 : 0.12) * (width-20), 19,
1484                                         &joy->flag, 0, 0, 0, 0,
1485                                         "Triggered by all events on this joysticks current type (axis/button/hat)");
1486                         }
1487                         if(joy->type == SENS_JOY_BUTTON)
1488                         {
1489                                 if ((joy->flag & SENS_JOY_ANY_EVENT)==0) {
1490                                         uiDefButI(block, NUM, 1, "Number:", xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1491                                         &joy->button, 0, 18, 100, 0,
1492                                         "Specify which button to use");
1493                                 }
1494                         }
1495                         else if(joy->type == SENS_JOY_AXIS)
1496                         {
1497                                 uiDefButS(block, NUM, 1, "Number:", xco+10, yco-68, 0.46 * (width-20), 19,
1498                                 &joy->axis, 1, 8.0, 100, 0,
1499                                 "Specify which axis pair to use, 1 is useually the main direction input.");
1500
1501                                 uiDefButI(block, NUM, 1, "Threshold:", xco+10 + 0.6 * (width-20),yco-44, 0.4 * (width-20), 19,
1502                                 &joy->precision, 0, 32768.0, 100, 0,
1503                                 "Specify the precision of the axis");
1504
1505                                 if ((joy->flag & SENS_JOY_ANY_EVENT)==0) {
1506                                         str = "Type %t|Up Axis %x1 |Down Axis %x3|Left Axis %x2|Right Axis %x0"; 
1507                                         uiDefButI(block, MENU, B_REDR, str, xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1508                                         &joy->axisf, 2.0, 31, 0, 0,
1509                                         "The direction of the axis, use 'All Events' to recieve events on any direction");
1510                                 }
1511                         }
1512                         else if (joy->type == SENS_JOY_HAT)
1513                         {
1514                                 uiDefButI(block, NUM, 1, "Number:", xco+10, yco-68, 0.46 * (width-20), 19,
1515                                 &joy->hat, 1, 2.0, 100, 0,
1516                                 "Specify which hat to use");
1517                                 
1518                                 if ((joy->flag & SENS_JOY_ANY_EVENT)==0) {
1519                                         uiDefButI(block, NUM, 1, "Direction:", xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1520                                         &joy->hatf, 0, 12, 100, 0,
1521                                         "Specify hat direction");
1522                                 }
1523                         }
1524                         else { /* (joy->type == SENS_JOY_AXIS_SINGLE)*/
1525                                 uiDefButS(block, NUM, 1, "Number:", xco+10, yco-68, 0.46 * (width-20), 19,
1526                                 &joy->axis_single, 1, 16.0, 100, 0,
1527                                 "Specify a single axis (verticle/horizontal/other) to detect");
1528                                 
1529                                 uiDefButI(block, NUM, 1, "Threshold:", xco+10 + 0.6 * (width-20),yco-44, 0.4 * (width-20), 19,
1530                                 &joy->precision, 0, 32768.0, 100, 0,
1531                                 "Specify the precision of the axis");
1532                         }
1533                         yco-= ysize;
1534                         break;
1535                 }
1536         }
1537         
1538         uiBlockSetEmboss(block, UI_EMBOSSM);
1539         uiBlockSetCol(block, TH_AUTO);
1540         
1541         return yco-4;
1542 }
1543
1544
1545
1546 static short draw_controllerbuttons(bController *cont, uiBlock *block, short xco, short yco, short width)
1547 {
1548         bExpressionCont *ec;
1549         bPythonCont *pc;
1550         short ysize;
1551         
1552         uiBlockSetEmboss(block, UI_EMBOSSM);
1553         
1554         switch (cont->type) {
1555         case CONT_EXPRESSION:
1556                 ysize= 28;
1557
1558                 BIF_ThemeColor(TH_BUT_SETTING);
1559                 glRects(xco, yco-ysize, xco+width, yco);
1560                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1561                 
1562                 /* uiDefBut(block, LABEL, 1, "Not yet...", xco,yco-24,80, 19, NULL, 0, 0, 0, 0, ""); */
1563                 ec= cont->data; 
1564                 /* uiDefBut(block, BUT, 1, "Variables", xco,yco-24,80, 19, NULL, 0, 0, 0, 0, "Available variables for expression"); */
1565                 uiDefBut(block, TEX, 1, "Exp:",         xco + 10 , yco-21, width-20, 19,
1566                                  ec->str, 0, 127, 0, 0,
1567                                  "Expression"); 
1568                 
1569                 yco-= ysize;
1570                 break;
1571         case CONT_PYTHON:
1572                 ysize= 28;
1573                 
1574                 if(cont->data==NULL) init_controller(cont);
1575                 pc= cont->data;
1576                 
1577                 BIF_ThemeColor(TH_BUT_SETTING1);
1578                 glRects(xco, yco-ysize, xco+width, yco);
1579                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1580
1581                 uiDefIDPoinBut(block, test_scriptpoin_but, ID_SCRIPT, 1, "Script: ", xco+45,yco-24,width-90, 19, &pc->text, "");
1582                 
1583                 yco-= ysize;
1584                 break;
1585                 
1586         default:
1587                 ysize= 4;
1588
1589                 BIF_ThemeColor(TH_BUT_NEUTRAL);
1590                 glRects(xco, yco-ysize, xco+width, yco);
1591                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1592                 
1593                 yco-= ysize;
1594         }
1595         
1596         uiBlockSetEmboss(block, UI_EMBOSSM);
1597         uiBlockSetCol(block, TH_AUTO);
1598
1599         return yco;
1600 }
1601
1602 static int get_col_actuator(int type)
1603 {
1604         switch(type) {
1605         case ACT_ACTION:                return TH_BUT_ACTION;
1606         case ACT_SHAPEACTION:   return TH_BUT_ACTION;
1607         case ACT_OBJECT:                return TH_BUT_NEUTRAL;
1608         case ACT_IPO:                   return TH_BUT_SETTING;
1609         case ACT_PROPERTY:              return TH_BUT_SETTING1;
1610         case ACT_SOUND:                 return TH_BUT_SETTING2;
1611         case ACT_CD:                    return TH_BUT_NUM;
1612         case ACT_CAMERA:                return TH_BUT_TEXTFIELD;
1613         case ACT_EDIT_OBJECT:           return TH_BUT_POPUP;
1614         case ACT_GROUP:                 return TH_BUT_ACTION;
1615         case ACT_RANDOM:                return TH_BUT_NEUTRAL;
1616         case ACT_SCENE:                 return TH_BUT_SETTING;
1617         case ACT_MESSAGE:               return TH_BUT_SETTING1;
1618         case ACT_GAME:                  return TH_BUT_SETTING2;
1619         case ACT_VISIBILITY:            return TH_BUT_NUM;
1620         case ACT_CONSTRAINT:            return TH_BUT_ACTION;
1621         case ACT_STATE:                 return TH_BUT_SETTING2;
1622         default:                                return TH_BUT_NEUTRAL;
1623         }
1624 }
1625 static void set_col_actuator(int item, int medium) 
1626 {
1627         int col= get_col_actuator(item);
1628         BIF_ThemeColorShade(col, medium?30:10);
1629         
1630 }
1631
1632 static void change_object_actuator(void *act, void *arg)
1633 {
1634         bObjectActuator *oa = act;
1635
1636         if (oa->type != oa->otype) {
1637                 switch (oa->type) {
1638                 case ACT_OBJECT_NORMAL:
1639                         memset(oa, 0, sizeof(bObjectActuator));
1640                         oa->flag = ACT_FORCE_LOCAL|ACT_TORQUE_LOCAL|ACT_DLOC_LOCAL|ACT_DROT_LOCAL;
1641                         oa->type = ACT_OBJECT_NORMAL;
1642                         break;
1643
1644                 case ACT_OBJECT_SERVO:
1645                         memset(oa, 0, sizeof(bObjectActuator));
1646                         oa->flag = ACT_LIN_VEL_LOCAL;
1647                         oa->type = ACT_OBJECT_SERVO;
1648                         oa->forcerot[0] = 30.0f;
1649                         oa->forcerot[1] = 0.5f;
1650                         oa->forcerot[2] = 0.0f;
1651                         break;
1652                 }
1653         }
1654 }
1655
1656 static void change_ipo_actuator(void *arg1_but, void *arg2_ia)
1657 {
1658         bIpoActuator *ia = arg2_ia;
1659         uiBut *but = arg1_but;
1660
1661         if (but->retval & ACT_IPOFORCE)
1662                 ia->flag &= ~ACT_IPOADD;
1663         else if (but->retval & ACT_IPOADD)
1664                 ia->flag &= ~ACT_IPOFORCE;
1665         but->retval = B_REDR;
1666 }
1667
1668 void update_object_actuator_PID(void *act, void *arg)
1669 {
1670         bObjectActuator *oa = act;
1671         oa->forcerot[0] = 60.0f*oa->forcerot[1];
1672 }
1673
1674 char *get_state_name(Object *ob, short bit)
1675 {
1676         bController *cont;
1677         unsigned int mask;
1678
1679         mask = (1<<bit);
1680         cont = ob->controllers.first;
1681         while (cont) {
1682                 if (cont->state_mask & mask) {
1683                         return cont->name;
1684                 }
1685                 cont = cont->next;
1686         }
1687         return (char*)"";
1688 }
1689
1690 static void check_state_mask(void *arg1_but, void *arg2_mask)
1691 {
1692         unsigned int *cont_mask = arg2_mask;
1693         uiBut *but = arg1_but;
1694
1695         if (*cont_mask == 0 || !(G.qual & LR_SHIFTKEY))
1696                 *cont_mask = (1<<but->retval);
1697         but->retval = B_REDR;
1698 }
1699
1700 static short draw_actuatorbuttons(Object *ob, bActuator *act, uiBlock *block, short xco, short yco, short width)
1701 {
1702         bSoundActuator      *sa      = NULL;
1703         bCDActuator                     *cda     = NULL;
1704         bObjectActuator     *oa      = NULL;
1705         bIpoActuator        *ia      = NULL;
1706         bPropertyActuator   *pa      = NULL;
1707         bCameraActuator     *ca      = NULL;
1708         bEditObjectActuator *eoa     = NULL;
1709         bConstraintActuator *coa     = NULL;
1710         bSceneActuator      *sca     = NULL;
1711         bGroupActuator      *ga      = NULL;
1712         bRandomActuator     *randAct = NULL;
1713         bMessageActuator    *ma      = NULL;
1714         bActionActuator     *aa      = NULL;
1715         bGameActuator       *gma     = NULL;
1716         bVisibilityActuator *visAct  = NULL;
1717         bTwoDFilterActuator     *tdfa    = NULL;
1718         bParentActuator     *parAct  = NULL;
1719         bStateActuator          *staAct  = NULL;
1720         
1721         float *fp;
1722         short ysize = 0, wval;
1723         char *str;
1724         int myline, stbit;
1725         uiBut *but;
1726
1727
1728         /* yco is at the top of the rect, draw downwards */
1729         uiBlockSetEmboss(block, UI_EMBOSSM);
1730         set_col_actuator(act->type, 0);
1731         
1732         switch (act->type)
1733         {
1734         case ACT_OBJECT:
1735                 {
1736                         oa = act->data;
1737                         wval = (width-100)/3;
1738                         if (oa->type == ACT_OBJECT_NORMAL)
1739                         {
1740                                 if ( ob->gameflag & OB_DYNAMIC )
1741                                 {
1742                                         ysize= 175;
1743                                 }
1744                                 else
1745                                 {
1746                                         ysize= 72;
1747                                 }
1748
1749                                 glRects(xco, yco-ysize, xco+width, yco);
1750                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1751                                 
1752                                 uiDefBut(block, LABEL, 0, "Loc",        xco, yco-45, 45, 19, NULL, 0, 0, 0, 0, "Sets the location");
1753                                 uiDefButF(block, NUM, 0, "",            xco+45, yco-45, wval, 19, oa->dloc, -10000.0, 10000.0, 10, 0, "");
1754                                 uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-45, wval, 19, oa->dloc+1, -10000.0, 10000.0, 10, 0, "");
1755                                 uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-45, wval, 19, oa->dloc+2, -10000.0, 10000.0, 10, 0, "");
1756                                 
1757                                 uiDefBut(block, LABEL, 0, "Rot",        xco, yco-64, 45, 19, NULL, 0, 0, 0, 0, "Sets the rotation");
1758                                 uiDefButF(block, NUM, 0, "",            xco+45, yco-64, wval, 19, oa->drot, -10000.0, 10000.0, 10, 0, "");
1759                                 uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-64, wval, 19, oa->drot+1, -10000.0, 10000.0, 10, 0, "");
1760                                 uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-64, wval, 19, oa->drot+2, -10000.0, 10000.0, 10, 0, "");
1761
1762                                 uiDefButBitS(block, TOG, ACT_DLOC_LOCAL, 0, "L",                xco+45+3*wval, yco-45, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
1763                                 uiDefButBitS(block, TOG, ACT_DROT_LOCAL, 0, "L",                xco+45+3*wval, yco-64, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
1764         
1765                                 if ( ob->gameflag & OB_DYNAMIC )
1766                                 {
1767                                         uiDefBut(block, LABEL, 0, "Force",      xco, yco-87, 55, 19, NULL, 0, 0, 0, 0, "Sets the force");
1768                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-87, wval, 19, oa->forceloc, -10000.0, 10000.0, 10, 0, "");
1769                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-87, wval, 19, oa->forceloc+1, -10000.0, 10000.0, 10, 0, "");
1770                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-87, wval, 19, oa->forceloc+2, -10000.0, 10000.0, 10, 0, "");
1771                                 
1772                                         uiDefBut(block, LABEL, 0, "Torque", xco, yco-106, 55, 19, NULL, 0, 0, 0, 0, "Sets the torque");
1773                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-106, wval, 19, oa->forcerot, -10000.0, 10000.0, 10, 0, "");
1774                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-106, wval, 19, oa->forcerot+1, -10000.0, 10000.0, 10, 0, "");
1775                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-106, wval, 19, oa->forcerot+2, -10000.0, 10000.0, 10, 0, "");                                
1776                                 }
1777                                 
1778                                 if ( ob->gameflag & OB_DYNAMIC )
1779                                 {
1780                                         uiDefBut(block, LABEL, 0, "LinV",       xco, yco-129, 45, 19, NULL, 0, 0, 0, 0, "Sets the linear velocity");
1781                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-129, wval, 19, oa->linearvelocity, -10000.0, 10000.0, 10, 0, "");
1782                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-129, wval, 19, oa->linearvelocity+1, -10000.0, 10000.0, 10, 0, "");
1783                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-129, wval, 19, oa->linearvelocity+2, -10000.0, 10000.0, 10, 0, "");
1784                                 
1785                                         uiDefBut(block, LABEL, 0, "AngV",       xco, yco-148, 45, 19, NULL, 0, 0, 0, 0, "Sets the angular velocity");
1786                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-148, wval, 19, oa->angularvelocity, -10000.0, 10000.0, 10, 0, "");
1787                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-148, wval, 19, oa->angularvelocity+1, -10000.0, 10000.0, 10, 0, "");
1788                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-148, wval, 19, oa->angularvelocity+2, -10000.0, 10000.0, 10, 0, "");
1789                                 
1790                                         uiDefBut(block, LABEL, 0, "Damp",       xco, yco-171, 45, 19, NULL, 0, 0, 0, 0, "Number of frames to reach the target velocity");
1791                                         uiDefButS(block, NUM, 0, "",            xco+45, yco-171, wval, 19, &oa->damping, 0.0, 1000.0, 100, 0, "");
1792
1793                                         uiDefButBitS(block, TOG, ACT_FORCE_LOCAL, 0, "L",               xco+45+3*wval, yco-87, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
1794                                         uiDefButBitS(block, TOG, ACT_TORQUE_LOCAL, 0, "L",              xco+45+3*wval, yco-106, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
1795                                         uiDefButBitS(block, TOG, ACT_LIN_VEL_LOCAL, 0, "L",             xco+45+3*wval, yco-129, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
1796                                         uiDefButBitS(block, TOG, ACT_ANG_VEL_LOCAL, 0, "L",             xco+45+3*wval, yco-148, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
1797                                 
1798                                         uiDefButBitS(block, TOG, ACT_ADD_LIN_VEL, 0, "add",xco+45+3*wval+15, yco-129, 35, 19, &oa->flag, 0.0, 0.0, 0, 0, "Toggles between ADD and SET linV");
1799                                 }                               
1800                         } else if (oa->type == ACT_OBJECT_SERVO)
1801                         {
1802                                 ysize= 172;
1803                                 
1804                                 glRects(xco, yco-ysize, xco+width, yco);
1805                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1806                                 
1807                                 uiDefBut(block, LABEL, 0, "linV",       xco, yco-45, 45, 19, NULL, 0, 0, 0, 0, "Sets the target linear velocity, it will be achieve by automatic application of force. Null velocity is a valid target");
1808                                 uiDefButF(block, NUM, 0, "",            xco+45, yco-45, wval, 19, oa->linearvelocity, -10000.0, 10000.0, 10, 0, "");
1809                                 uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-45, wval, 19, oa->linearvelocity+1, -10000.0, 10000.0, 10, 0, "");
1810                                 uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-45, wval, 19, oa->linearvelocity+2, -10000.0, 10000.0, 10, 0, "");
1811                                 uiDefButBitS(block, TOG, ACT_LIN_VEL_LOCAL, 0, "L",             xco+45+3*wval, yco-45, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Velocity is defined in local coordinates");
1812
1813                                 uiDefBut(block, LABEL, 0, "Limit",      xco, yco-68, 45, 19, NULL, 0, 0, 0, 0, "Select if the force need to be limited along certain axis (local or global depending on LinV Local flag)");
1814                                 uiDefButBitS(block, TOG, ACT_SERVO_LIMIT_X, B_REDR, "X",                xco+45, yco-68, wval, 19, &oa->flag, 0.0, 0.0, 0, 0, "Set limit to force along the X axis");
1815                                 uiDefButBitS(block, TOG, ACT_SERVO_LIMIT_Y, B_REDR, "Y",                xco+45+wval, yco-68, wval, 19, &oa->flag, 0.0, 0.0, 0, 0, "Set limit to force along the Y axis");
1816                                 uiDefButBitS(block, TOG, ACT_SERVO_LIMIT_Z, B_REDR, "Z",                xco+45+2*wval, yco-68, wval, 19, &oa->flag, 0.0, 0.0, 0, 0, "Set limit to force along the Z axis");
1817                                 uiDefBut(block, LABEL, 0, "Max",        xco, yco-87, 45, 19, NULL, 0, 0, 0, 0, "Set the upper limit for force");
1818                                 uiDefBut(block, LABEL, 0, "Min",        xco, yco-106, 45, 19, NULL, 0, 0, 0, 0, "Set the lower limit for force");
1819                                 if (oa->flag & ACT_SERVO_LIMIT_X) {
1820                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-87, wval, 19, oa->dloc, -10000.0, 10000.0, 10, 0, "");
1821                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-106, wval, 19, oa->drot, -10000.0, 10000.0, 10, 0, "");
1822                                 }
1823                                 if (oa->flag & ACT_SERVO_LIMIT_Y) {
1824                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-87, wval, 19, oa->dloc+1, -10000.0, 10000.0, 10, 0, "");
1825                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-106, wval, 19, oa->drot+1, -10000.0, 10000.0, 10, 0, "");
1826                                 }
1827                                 if (oa->flag & ACT_SERVO_LIMIT_Z) {
1828                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-87, wval, 19, oa->dloc+2, -10000.0, 10000.0, 10, 0, "");
1829                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-106, wval, 19, oa->drot+2, -10000.0, 10000.0, 10, 0, "");
1830                                 }
1831                                 uiDefBut(block, LABEL, 0, "Servo",      xco, yco-129, 45, 19, NULL, 0, 0, 0, 0, "Coefficients of the PID servo controller");
1832                                 uiDefButF(block, NUMSLI, B_REDR, "P: ",         xco+45, yco-129, wval*3, 19, oa->forcerot, 0.00, 200.0, 100, 0, "Proportional coefficient, typical value is 60x Integral coefficient");
1833                                 uiDefBut(block, LABEL, 0, "Slow",       xco, yco-148, 45, 19, NULL, 0, 0, 0, 0, "Low value of I coefficient correspond to slow response");
1834                                 but = uiDefButF(block, NUMSLI, B_REDR, " I : ",         xco+45, yco-148, wval*3, 19, oa->forcerot+1, 0.0, 3.0, 1, 0, "Integral coefficient, low value (0.01) for slow response, high value (0.5) for fast response");
1835                                 uiButSetFunc(but, update_object_actuator_PID, oa, NULL);
1836                                 uiDefBut(block, LABEL, 0, "Fast",       xco+45+3*wval, yco-148, 45, 19, NULL, 0, 0, 0, 0, "High value of I coefficient correspond to fast response");
1837                                 uiDefButF(block, NUMSLI, B_REDR, "D: ",         xco+45, yco-167, wval*3, 19, oa->forcerot+2, -100.0, 100.0, 100, 0, "Derivate coefficient, not required, high values can cause instability");
1838                         }
1839                         str= "Motion Type %t|Simple motion %x0|Servo Control %x1";
1840                         but = uiDefButS(block, MENU, B_REDR, str,               xco+40, yco-23, (width-80), 19, &oa->type, 0.0, 0.0, 0, 0, "");
1841                         oa->otype = oa->type;
1842                         uiButSetFunc(but, change_object_actuator, oa, NULL);
1843                         yco-= ysize;
1844                         break;
1845                 }
1846         case ACT_ACTION:
1847         case ACT_SHAPEACTION:
1848                 {
1849                         /* DrawAct */
1850 #ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
1851                         ysize = 112;
1852 #else
1853                         ysize= 92;
1854 #endif
1855                         
1856                         glRects(xco, yco-ysize, xco+width, yco);
1857                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1858                         
1859                         aa = act->data;
1860                         wval = (width-60)/3;
1861                         
1862                         //              str= "Action types   %t|Play %x0|Ping Pong %x1|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6";
1863 #ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
1864                         str= "Action types   %t|Play %x0|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6|Displacement %x7";
1865 #else
1866                         str= "Action types   %t|Play %x0|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6";
1867 #endif
1868                         uiDefButS(block, MENU, B_REDR, str, xco+10, yco-24, width/3, 19, &aa->type, 0.0, 0.0, 0.0, 0.0, "Action playback type");
1869                         uiDefIDPoinBut(block, test_actionpoin_but, ID_AC, 1, "AC: ", xco+10+ (width/3), yco-24, ((width/3)*2) - (20 + 60), 19, &aa->act, "Action name");
1870                         
1871                         uiDefButBitS(block, TOGN, 1, 0, "Continue", xco+((width/3)*2)+20, yco-24, 60, 19,
1872                                          &aa->end_reset, 0.0, 0.0, 0, 0, "Restore last frame when switching on/off, otherwise play from the start each time");
1873                         
1874                         
1875                         if(aa->type == ACT_ACTION_FROM_PROP)
1876                         {
1877                                 uiDefBut(block, TEX, 0, "Prop: ",xco+10, yco-44, width-20, 19, aa->name, 0.0, 31.0, 0, 0, "Use this property to define the Action position");
1878                         }
1879                         else
1880                         {
1881                                 uiDefButI(block, NUM, 0, "Sta: ",xco+10, yco-44, (width-20)/2, 19, &aa->sta, 0.0, MAXFRAMEF, 0, 0, "Start frame");
1882                                 uiDefButI(block, NUM, 0, "End: ",xco+10+(width-20)/2, yco-44, (width-20)/2, 19, &aa->end, 0.0, MAXFRAMEF, 0, 0, "End frame");
1883                         }
1884                                                 
1885                         uiDefButS(block, NUM, 0, "Blendin: ", xco+10, yco-64, (width-20)/2, 19, &aa->blendin, 0.0, 32767, 0.0, 0.0, "Number of frames of motion blending");
1886                         uiDefButS(block, NUM, 0, "Priority: ", xco+10+(width-20)/2, yco-64, (width-20)/2, 19, &aa->priority, 0.0, 100.0, 0.0, 0.0, "Execution priority - lower numbers will override actions with higher numbers, With 2 or more actions at once, the overriding channels must be lower in the stack");
1887                         
1888                         uiDefBut(block, TEX, 0, "FrameProp: ",xco+10, yco-84, width-20, 19, aa->frameProp, 0.0, 31.0, 0, 0, "Assign the action's current frame number to this property");
1889
1890                         
1891 #ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
1892                         if(aa->type == ACT_ACTION_MOTION)
1893                         {
1894                                 uiDefButF(block, NUM, 0, "Cycle: ",xco+30, yco-84, (width-60)/2, 19, &aa->stridelength, 0.0, 2500.0, 0, 0, "Distance covered by a single cycle of the action");
1895                         }
1896 #endif
1897                         
1898                         
1899                         
1900                         yco-=ysize;
1901                         break;
1902                 }
1903         case ACT_IPO:
1904                 {
1905                         ia= act->data;
1906                         
1907                         ysize= 72;
1908                         
1909                         glRects(xco, yco-ysize, xco+width, yco);
1910                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1911                         
1912                         str = "Ipo types   %t|Play %x0|Ping Pong %x1|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6";
1913                         
1914                         uiDefButS(block, MENU, B_REDR, str,             xco+10, yco-24, (width-20)/2, 19, &ia->type, 0, 0, 0, 0, "");
1915
1916                         but = uiDefButBitS(block, TOG, ACT_IPOFORCE, ACT_IPOFORCE, 
1917                                 "Force", xco+10+(width-20)/2, yco-24, (width-20)/4-10, 19, 
1918                                 &ia->flag, 0, 0, 0, 0, 
1919                                 "Apply Ipo as a global or local force depending on the local option (dynamic objects only)"); 
1920                         uiButSetFunc(but, change_ipo_actuator, but, ia);
1921
1922                         but = uiDefButBitS(block, TOG, ACT_IPOADD, ACT_IPOADD, 
1923                                 "Add", xco+3*(width-20)/4, yco-24, (width-20)/4-10, 19, 
1924                                 &ia->flag, 0, 0, 0, 0, 
1925                                 "Ipo is added to the current loc/rot/scale in global or local coordinate according to Local flag"); 
1926                         uiButSetFunc(but, change_ipo_actuator, but, ia);
1927                         
1928                         /* Only show the do-force-local toggle if force is requested */
1929                         if (ia->flag & (ACT_IPOFORCE|ACT_IPOADD)) {
1930                                 uiDefButBitS(block, TOG, ACT_IPOLOCAL, 0, 
1931                                         "L", xco+width-30, yco-24, 20, 19, 
1932                                         &ia->flag, 0, 0, 0, 0, 
1933                                         "Let the ipo acts in local coordinates, used in Force and Add mode."); 
1934                         }
1935
1936                         if(ia->type==ACT_IPO_FROM_PROP) {
1937                                 uiDefBut(block, TEX, 0, 
1938                                         "Prop: ",               xco+10, yco-44, width-80, 19, 
1939                                         ia->name, 0.0, 31.0, 0, 0, 
1940                                         "Use this property to define the Ipo position");
1941                         }
1942                         else {
1943                                 uiDefButI(block, NUM, 0, 
1944                                         "Sta",          xco+10, yco-44, (width-80)/2, 19, 
1945                                         &ia->sta, 1.0, MAXFRAMEF, 0, 0, 
1946                                         "Start frame");
1947                                 uiDefButI(block, NUM, 0, 
1948                                         "End",          xco+10+(width-80)/2, yco-44, (width-80)/2, 19, 
1949                                         &ia->end, 1.0, MAXFRAMEF, 0, 0, 
1950                                         "End frame");
1951                         }
1952                         uiDefButBitS(block, TOG, ACT_IPOCHILD,  B_REDR, 
1953                                 "Child",        xco+10+(width-80), yco-44, 60, 19, 
1954                                 &ia->flag, 0, 0, 0, 0, 
1955                                 "Update IPO on all children Objects as well");
1956                         uiDefBut(block, TEX, 0, 
1957                                 "FrameProp: ",          xco+10, yco-64, width-20, 19, 
1958                                 ia->frameProp, 0.0, 31.0, 0, 0, 
1959                                 "Assign this property this action current frame number");
1960
1961                         yco-= ysize;
1962                         break;
1963                 }
1964         case ACT_PROPERTY:
1965                 {
1966                         ysize= 68;
1967                         
1968                         glRects(xco, yco-ysize, xco+width, yco);
1969                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1970                         
1971                         pa= act->data;
1972                         
1973                         str= "Type%t|Assign%x0|Add %x1|Copy %x2|Toggle (bool/int/float/timer)%x3";
1974                         uiDefButI(block, MENU, B_REDR, str,             xco+30,yco-24,width-60, 19, &pa->type, 0, 31, 0, 0, "Type");
1975                         
1976                         uiDefBut(block, TEX, 1, "Prop: ",               xco+30,yco-44,width-60, 19, pa->name, 0, 31, 0, 0, "Property name");
1977                         
1978                         
1979                         if(pa->type==ACT_PROP_TOGGLE) {
1980                                 /* no ui */
1981                                 ysize -= 22;
1982                         }
1983                         else if(pa->type==ACT_PROP_COPY) {
1984                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:", xco+10, yco-64, (width-20)/2, 19, &(pa->ob), "Copy from this Object");
1985                                 uiDefBut(block, TEX, 1, "Prop: ",               xco+10+(width-20)/2, yco-64, (width-20)/2, 19, pa->value, 0, 31, 0, 0, "Copy this property");
1986                         }
1987                         else {
1988                                 uiDefBut(block, TEX, 1, "Value: ",              xco+30,yco-64,width-60, 19, pa->value, 0, 31, 0, 0, "change with this value, use \"\" around strings");
1989                         }
1990                         yco-= ysize;
1991                         
1992                         break;
1993                 }
1994     case ACT_SOUND:
1995                 {
1996                         ysize = 70;
1997                         
1998                         sa = act->data;
1999                         sa->sndnr = 0;
2000                         
2001                         wval = (width-20)/2;
2002                         glRects(xco, yco-ysize, xco+width, yco);
2003                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2004                         
2005                         if(G.main->sound.first) {
2006                                 IDnames_to_pupstring(&str, "Sound files", NULL, &(G.main->sound), (ID *)sa->sound, &(sa->sndnr));
2007                                 /* reset this value, it is for handling the event */
2008                                 sa->sndnr = 0;
2009                                 uiDefButS(block, MENU, B_SOUNDACT_BROWSE, str, xco+10,yco-22,20,19, &(sa->sndnr), 0, 0, 0, 0, "");      
2010
2011                                 if(sa->sound) {
2012                                         char dummy_str[] = "Sound mode %t|Play Stop %x0|Play End %x1|Loop Stop %x2|Loop End %x3|Loop Ping Pong Stop %x5|Loop Ping Pong %x4";
2013                                         uiDefBut(block, TEX, B_IDNAME, "SO:",xco+30,yco-22,width-40,19, sa->sound->id.name+2,    0.0, 21.0, 0, 0, "");
2014                                         uiDefButS(block, MENU, 1, dummy_str,xco+10,yco-44,width-20, 19, &sa->type, 0.0, 0.0, 0, 0, "");
2015                                         uiDefButF(block, NUM, 0, "Volume:", xco+10,yco-66,wval, 19, &sa->sound->volume, 0.0,  1.0, 0, 0, "Sets the volume of this sound");
2016                                         uiDefButF(block, NUM, 0, "Pitch:",xco+wval+10,yco-66,wval, 19, &sa->sound->pitch,-12.0, 12.0, 0, 0, "Sets the pitch of this sound");
2017                                 }
2018                                 MEM_freeN(str);
2019                         } 
2020                         else {
2021                                 uiDefBut(block, LABEL, 0, "Use Sound window (F10) to load samples", xco, yco-24, width, 19, NULL, 0, 0, 0, 0, "");
2022                         }
2023                                         
2024                         yco-= ysize;
2025                         
2026                         break;
2027                 }
2028         case ACT_CD:
2029                 {
2030                         char cd_type_str[] = "Sound mode %t|Play all tracks %x0|Play one track %x1|"
2031                                 "Volume %x3|Stop %x4|Pause %x5|Resume %x6";
2032                         cda = act->data;
2033
2034                         if (cda) {
2035                                 if (cda->track == 0) {
2036                                         cda->track = 1;
2037                                         cda->volume = 1;
2038                                         cda->type = ACT_CD_PLAY_ALL;
2039                                 }
2040                                 
2041                                 if (cda->type == ACT_CD_PLAY_TRACK || cda->type == ACT_CD_LOOP_TRACK) {
2042                                         ysize = 48;
2043                                         glRects(xco, yco-ysize, xco+width, yco);
2044                                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2045                                         uiDefButS(block, NUM, 0, "Track:", xco+10,yco-44,width-20, 19, &cda->track, 1, 99, 0, 0, "Select the track to be played");
2046                                 }
2047                                 else if (cda->type == ACT_CD_VOLUME) {
2048                                         ysize = 48;
2049                                         glRects(xco, yco-ysize, xco+width, yco);
2050                                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2051                                         uiDefButF(block, NUM, 0, "Volume:", xco+10,yco-44,width-20, 19, &cda->volume, 0, 1, 0, 0, "Set the volume for CD playback");
2052                                 }
2053                                 else {
2054                                         ysize = 28;
2055                                         glRects(xco, yco-ysize, xco+width, yco);
2056                                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2057                                 }
2058                                 uiDefButS(block, MENU, B_REDR, cd_type_str,xco+10,yco-22,width-20, 19, &cda->type, 0.0, 0.0, 0, 0, "");
2059                         }
2060                         yco-= ysize;
2061                         break;
2062                 }
2063         case ACT_CAMERA:
2064
2065                 ysize= 48;
2066         
2067                 glRects(xco, yco-ysize, xco+width, yco);
2068                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2069                 
2070                 ca= act->data;
2071         
2072                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:",         xco+10, yco-24, (width-20)/2, 19, &(ca->ob), "Look at this Object");
2073                 uiDefButF(block, NUM, 0, "Height:",     xco+10+(width-20)/2, yco-24, (width-20)/2, 19, &ca->height, 0.0, 20.0, 0, 0, "");
2074                 
2075                 uiDefButF(block, NUM, 0, "Min:",        xco+10, yco-44, (width-60)/2, 19, &ca->min, 0.0, 20.0, 0, 0, "");
2076                 
2077                 if(ca->axis==0) ca->axis= 'x';
2078                 uiDefButS(block, ROW, 0, "X",   xco+10+(width-60)/2, yco-44, 20, 19, &ca->axis, 4.0, (float)'x', 0, 0, "Camera tries to get behind the X axis");
2079                 uiDefButS(block, ROW, 0, "Y",   xco+30+(width-60)/2, yco-44, 20, 19, &ca->axis, 4.0, (float)'y', 0, 0, "Camera tries to get behind the Y axis");
2080                 
2081                 uiDefButF(block, NUM, 0, "Max:",        xco+20+(width)/2, yco-44, (width-60)/2, 19, &ca->max, 0.0, 20.0, 0, 0, "");
2082
2083                 yco-= ysize;
2084         
2085          break;
2086                                 
2087         case ACT_EDIT_OBJECT:
2088                 
2089                 eoa= act->data;
2090
2091                 if(eoa->type==ACT_EDOB_ADD_OBJECT) {
2092                         int wval; /* just a temp width */
2093                         ysize = 92;
2094                         glRects(xco, yco-ysize, xco+width, yco);
2095                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2096          
2097                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:",         xco+10, yco-44, (width-20)/2, 19, &(eoa->ob), "Add this Object and all its children (cant be on an visible layer)");
2098                         uiDefButI(block, NUM, 0, "Time:",       xco+10+(width-20)/2, yco-44, (width-20)/2, 19, &eoa->time, 0.0, 2000.0, 0, 0, "Duration the new Object lives");
2099
2100                         wval= (width-60)/3;
2101                         uiDefBut(block, LABEL, 0, "linV",       xco,           yco-68,   45, 19,
2102                                          NULL, 0, 0, 0, 0,
2103                                          "Velocity upon creation.");
2104                         uiDefButF(block, NUM, 0, "",            xco+45,        yco-68, wval, 19,
2105                                          eoa->linVelocity, -100.0, 100.0, 10, 0,
2106                                          "Velocity upon creation, x component.");
2107                         uiDefButF(block, NUM, 0, "",            xco+45+wval,   yco-68, wval, 19,
2108                                          eoa->linVelocity+1, -100.0, 100.0, 10, 0,
2109                                          "Velocity upon creation, y component.");
2110                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-68, wval, 19,
2111                                          eoa->linVelocity+2, -100.0, 100.0, 10, 0,
2112                                          "Velocity upon creation, z component.");
2113                         uiDefButBitS(block, TOG, ACT_EDOB_LOCAL_LINV, 0, "L", xco+45+3*wval, yco-68, 15, 19,
2114                                          &eoa->localflag, 0.0, 0.0, 0, 0,
2115                                          "Apply the transformation locally");
2116                         
2117                         
2118                         uiDefBut(block, LABEL, 0, "AngV",       xco,           yco-90,   45, 19,
2119                                          NULL, 0, 0, 0, 0,
2120                                          "Angular velocity upon creation.");
2121                         uiDefButF(block, NUM, 0, "",            xco+45,        yco-90, wval, 19,
2122                                          eoa->angVelocity, -10000.0, 10000.0, 10, 0,
2123                                          "Angular velocity upon creation, x component.");
2124                         uiDefButF(block, NUM, 0, "",            xco+45+wval,   yco-90, wval, 19,
2125                                          eoa->angVelocity+1, -10000.0, 10000.0, 10, 0,
2126                                          "Angular velocity upon creation, y component.");
2127                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-90, wval, 19,
2128                                          eoa->angVelocity+2, -10000.0, 10000.0, 10, 0,
2129                                          "Angular velocity upon creation, z component.");
2130                         uiDefButBitS(block, TOG, ACT_EDOB_LOCAL_ANGV, 0, "L", xco+45+3*wval, yco-90, 15, 19,
2131                                          &eoa->localflag, 0.0, 0.0, 0, 0,
2132                                          "Apply the rotation locally");
2133                                          
2134
2135                 }
2136                 else if(eoa->type==ACT_EDOB_END_OBJECT) {
2137                         ysize= 28;
2138                         glRects(xco, yco-ysize, xco+width, yco);
2139                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2140                 }
2141                 else if(eoa->type==ACT_EDOB_REPLACE_MESH) {
2142                         ysize= 48;
2143                         glRects(xco, yco-ysize, xco+width, yco);
2144                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2145          
2146                         uiDefIDPoinBut(block, test_meshpoin_but, ID_ME, 1, "ME:",               xco+40, yco-44, (width-80), 19, &(eoa->me), "replace the existing mesh with this one");
2147                 }
2148                 else if(eoa->type==ACT_EDOB_TRACK_TO) {
2149                         ysize= 48;
2150                         glRects(xco, yco-ysize, xco+width, yco);
2151                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2152          
2153                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:",         xco+10, yco-44, (width-20)/2, 19, &(eoa->ob), "Track to this Object");
2154                         uiDefButI(block, NUM, 0, "Time:",       xco+10+(width-20)/2, yco-44, (width-20)/2-40, 19, &eoa->time, 0.0, 2000.0, 0, 0, "Duration the tracking takes");
2155                         uiDefButS(block, TOG, 0, "3D",  xco+width-50, yco-44, 40, 19, &eoa->flag, 0.0, 0.0, 0, 0, "Enable 3D tracking");
2156                 }
2157                 else if(eoa->type==ACT_EDOB_DYNAMICS) {
2158                         ysize= 69;
2159                         glRects(xco, yco-ysize, xco+width, yco);
2160                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2161                         
2162                         str= "Dynamic Operation %t|Restore Dynamics %x0|Suspend Dynamics %x1|Enable Rigid Body %x2|Disable Rigid Body %x3|Set Mass %x4";
2163                         uiDefButS(block, MENU, B_REDR, str,             xco+40, yco-44, (width-80), 19,  &(eoa->dyn_operation), 0.0, 0.0, 0, 0, "");
2164                         if(eoa->dyn_operation==4) {
2165                                 uiDefButF(block, NUM, 0, "",            xco+40, yco-63, width-80, 19,
2166                                          &eoa->mass, 0.0, 10000.0, 10, 0,
2167                                          "Mass for object.");
2168                         }
2169                 }
2170                 str= "Edit Object %t|Add Object %x0|End Object %x1|Replace Mesh %x2|Track to %x3|Dynamics %x4";
2171                 uiDefButS(block, MENU, B_REDR, str,             xco+40, yco-24, (width-80), 19, &eoa->type, 0.0, 0.0, 0, 0, "");
2172
2173                 yco-= ysize;
2174         
2175         break;
2176  
2177         case ACT_CONSTRAINT:
2178                 coa= act->data;
2179         
2180                 if (coa->type == ACT_CONST_TYPE_LOC) {
2181                         ysize= 69;
2182         
2183                         glRects(xco, yco-ysize, xco+width, yco);
2184                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2185                         
2186         /*              str= "Limit %t|None %x0|Loc X %x1|Loc Y %x2|Loc Z %x4|Rot X %x8|Rot Y %x16|Rot Z %x32"; */
2187         /*                      coa->flag &= ~(63); */
2188                         str= "Limit %t|None %x0|Loc X %x1|Loc Y %x2|Loc Z %x4";
2189                         coa->flag &= 7;
2190                         coa->time = 0;
2191                         uiDefButS(block, MENU, 1, str,          xco+10, yco-65, 70, 19, &coa->flag, 0.0, 0.0, 0, 0, "");
2192                 
2193                         uiDefButS(block, NUM,           0, "damp",      xco+10, yco-45, 70, 19, &coa->damp, 0.0, 100.0, 0, 0, "Damping factor: time constant (in frame) of low pass filter");
2194                         uiDefBut(block, LABEL,                  0, "Min",       xco+80, yco-45, (width-90)/2, 19, NULL, 0.0, 0.0, 0, 0, "");
2195                         uiDefBut(block, LABEL,                  0, "Max",       xco+80+(width-90)/2, yco-45, (width-90)/2, 19, NULL, 0.0, 0.0, 0, 0, "");
2196
2197                         if(coa->flag & ACT_CONST_LOCX) fp= coa->minloc;
2198                         else if(coa->flag & ACT_CONST_LOCY) fp= coa->minloc+1;
2199                         else if(coa->flag & ACT_CONST_LOCZ) fp= coa->minloc+2;
2200                         else if(coa->flag & ACT_CONST_ROTX) fp= coa->minrot;
2201                         else if(coa->flag & ACT_CONST_ROTY) fp= coa->minrot+1;
2202                         else fp= coa->minrot+2;
2203                         
2204                         uiDefButF(block, NUM, 0, "",            xco+80, yco-65, (width-90)/2, 19, fp, -2000.0, 2000.0, 10, 0, "");
2205                         uiDefButF(block, NUM, 0, "",            xco+80+(width-90)/2, yco-65, (width-90)/2, 19, fp+3, -2000.0, 2000.0, 10, 0, "");
2206                 } else if (coa->type == ACT_CONST_TYPE_DIST) {
2207                         ysize= 106;
2208
2209                         glRects(xco, yco-ysize, xco+width, yco);
2210                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2211                         
2212                         str= "Direction %t|None %x0|X axis %x1|Y axis %x2|Z axis %x4|-X axis %x8|-Y axis %x16|-Z axis %x32";
2213                         uiDefButS(block, MENU, B_REDR, str,             xco+10, yco-65, 70, 19, &coa->mode, 0.0, 0.0, 0, 0, "Set the direction of the ray");
2214                 
2215                         uiDefButS(block, NUM,           0, "damp",      xco+10, yco-45, 70, 19, &coa->damp, 0.0, 100.0, 0, 0, "Damping factor: time constant (in frame) of low pass filter");
2216                         uiDefBut(block, LABEL,                  0, "Range",     xco+80, yco-45, (width-115)/2, 19, NULL, 0.0, 0.0, 0, 0, "Set the maximum length of ray");
2217                         uiDefButBitS(block, TOG, ACT_CONST_DISTANCE, B_REDR, "Dist",    xco+80+(width-115)/2, yco-45, (width-115)/2, 19, &coa->flag, 0.0, 0.0, 0, 0, "Force distance of object to point of impact of ray");
2218                         uiDefButBitS(block, TOG, ACT_CONST_LOCAL, 0, "L", xco+80+(width-115), yco-45, 25, 19,
2219                                          &coa->flag, 0.0, 0.0, 0, 0, "Set ray along object's axis or global axis");
2220
2221                         if(coa->mode & (ACT_CONST_DIRPX|ACT_CONST_DIRNX)) fp= coa->minloc;
2222                         else if(coa->mode & (ACT_CONST_DIRPY|ACT_CONST_DIRNY)) fp= coa->minloc+1;
2223                         else fp= coa->minloc+2;
2224
2225                         uiDefButF(block, NUM, 0, "",            xco+80, yco-65, (width-115)/2, 19, fp+3, 0.0, 2000.0, 10, 0, "Maximum length of ray");
2226                         if (coa->flag & ACT_CONST_DISTANCE)
2227                                 uiDefButF(block, NUM, 0, "",            xco+80+(width-115)/2, yco-65, (width-115)/2, 19, fp, -2000.0, 2000.0, 10, 0, "Keep this distance to target");
2228                         uiDefButBitS(block, TOG, ACT_CONST_NORMAL, 0, "N", xco+80+(width-115), yco-65, 25, 19,
2229                                          &coa->flag, 0.0, 0.0, 0, 0, "Set object axis along (local axis) or parallel (global axis) to the normal at hit position");
2230                         uiDefButBitS(block, TOG, ACT_CONST_MATERIAL, B_REDR, "M/P", xco+10, yco-84, 40, 19,
2231                                          &coa->flag, 0.0, 0.0, 0, 0, "Detect material instead of property");
2232                         if (coa->flag & ACT_CONST_MATERIAL)
2233                         {
2234                                 uiDefBut(block, TEX, 1, "Material:", xco + 50, yco-84, (width-60), 19,
2235                                         coa->matprop, 0, 31, 0, 0,
2236                                         "Ray detects only Objects with this material");
2237                         }
2238                         else
2239                         {
2240                                 uiDefBut(block, TEX, 1, "Property:", xco + 50, yco-84, (width-60), 19,
2241                                         coa->matprop, 0, 31, 0, 0,
2242                                         "Ray detect only Objects with this property");
2243                         }
2244                         uiDefButBitS(block, TOG, ACT_CONST_PERMANENT, 0, "PER", xco+10, yco-103, 40, 19,
2245                                 &coa->flag, 0.0, 0.0, 0, 0, "Persistent actuator: stays active even if ray does not reach target");
2246                         uiDefButS(block, NUM, 0, "time", xco+50, yco-103, (width-60)/2, 19, &(coa->time), 0.0, 1000.0, 0, 0, "Maximum activation time in frame, 0 for unlimited");
2247                         uiDefButS(block, NUM, 0, "rotDamp", xco+50+(width-60)/2, yco-103, (width-60)/2, 19, &(coa->rotdamp), 0.0, 100.0, 0, 0, "Use a different damping for orientation");
2248                 } else if (coa->type == ACT_CONST_TYPE_ORI) {
2249                         ysize= 87;
2250
2251                         glRects(xco, yco-ysize, xco+width, yco);
2252                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2253                         
2254                         str= "Direction %t|None %x0|X axis %x1|Y axis %x2|Z axis %x4";
2255                         uiDefButS(block, MENU, B_REDR, str,             xco+10, yco-65, 70, 19, &coa->mode, 0.0, 0.0, 0, 0, "Select the axis to be aligned along the reference direction");
2256                 
2257                         uiDefButS(block, NUM,           0, "damp",      xco+10, yco-45, 70, 19, &coa->damp, 0.0, 100.0, 0, 0, "Damping factor: time constant (in frame) of low pass filter");
2258                         uiDefBut(block, LABEL,                  0, "X", xco+80, yco-45, (width-115)/3, 19, NULL, 0.0, 0.0, 0, 0, "");
2259                         uiDefBut(block, LABEL,                  0, "Y", xco+80+(width-115)/3, yco-45, (width-115)/3, 19, NULL, 0.0, 0.0, 0, 0, "");
2260                         uiDefBut(block, LABEL,                  0, "Z", xco+80+2*(width-115)/3, yco-45, (width-115)/3, 19, NULL, 0.0, 0.0, 0, 0, "");
2261
2262                         uiDefButF(block, NUM, 0, "",            xco+80, yco-65, (width-115)/3, 19, &coa->maxrot[0], -2000.0, 2000.0, 10, 0, "X component of reference direction");
2263                         uiDefButF(block, NUM, 0, "",            xco+80+(width-115)/3, yco-65, (width-115)/3, 19, &coa->maxrot[1], -2000.0, 2000.0, 10, 0, "Y component of reference direction");
2264                         uiDefButF(block, NUM, 0, "",            xco+80+2*(width-115)/3, yco-65, (width-115)/3, 19, &coa->maxrot[2], -2000.0, 2000.0, 10, 0, "Z component of reference direction");
2265
2266                         uiDefButS(block, NUM, 0, "time", xco+10, yco-84, 70, 19, &(coa->time), 0.0, 1000.0, 0, 0, "Maximum activation time in frame, 0 for unlimited");
2267                         uiDefButF(block, NUM, 0, "min", xco+80, yco-84, (width-115)/2, 19, &(coa->minloc[0]), 0.0, 180.0, 10, 1, "Minimum angle (in degree) to maintain with target direction. No correction is done if angle with target direction is between min and max");
2268                         uiDefButF(block, NUM, 0, "max", xco+80+(width-115)/2, yco-84, (width-115)/2, 19, &(coa->maxloc[0]), 0.0, 180.0, 10, 1, "Maximum angle (in degree) allowed with target direction. No correction is done if angle with target direction is between min and max");
2269                 } else if (coa->type == ACT_CONST_TYPE_FH) {
2270                         ysize= 106;
2271
2272                         glRects(xco, yco-ysize, xco+width, yco);
2273                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2274                         
2275                         str= "Direction %t|None %x0|X axis %x1|Y axis %x2|Z axis %x4|-X axis %x8|-Y axis %x16|-Z axis %x32";
2276                         uiDefButS(block, MENU, B_REDR, str,             xco+10, yco-65, 70, 19, &coa->mode, 0.0, 0.0, 0, 0, "Set the direction of the ray (in world coordinate)");
2277
2278                         if(coa->mode & (ACT_CONST_DIRPX|ACT_CONST_DIRNX)) fp= coa->minloc;
2279                         else if(coa->mode & (ACT_CONST_DIRPY|ACT_CONST_DIRNY)) fp= coa->minloc+1;
2280                         else fp= coa->minloc+2;
2281
2282                         uiDefButF(block, NUM,           0, "damp",      xco+10, yco-45, (width-70)/2, 19, &coa->maxrot[0], 0.0, 1.0, 1, 0, "Damping factor of the Fh spring force");
2283                         uiDefButF(block, NUM,           0, "dist",      xco+10+(width-70)/2, yco-45, (width-70)/2, 19, fp, 0.010, 2000.0, 10, 0, "Height of the Fh area");
2284                         uiDefButBitS(block, TOG, ACT_CONST_DOROTFH, 0, "Rot Fh",        xco+10+(width-70), yco-45, 50, 19, &coa->flag, 0.0, 0.0, 0, 0, "Keep object axis parallel to normal");
2285
2286                         uiDefButF(block, NUMSLI, 0, "Fh ",              xco+80, yco-65, (width-115), 19, fp+3, 0.0, 1.0, 0, 0, "Spring force within the Fh area");
2287                         uiDefButBitS(block, TOG, ACT_CONST_NORMAL, 0, "N", xco+80+(width-115), yco-65, 25, 19,
2288                                          &coa->flag, 0.0, 0.0, 0, 0, "Add a horizontal spring force on slopes");
2289                         uiDefButBitS(block, TOG, ACT_CONST_MATERIAL, B_REDR, "M/P", xco+10, yco-84, 40, 19,
2290                                          &coa->flag, 0.0, 0.0, 0, 0, "Detect material instead of property");
2291                         if (coa->flag & ACT_CONST_MATERIAL)
2292                         {
2293                                 uiDefBut(block, TEX, 1, "Material:", xco + 50, yco-84, (width-60), 19,
2294                                         coa->matprop, 0, 31, 0, 0,
2295                                         "Ray detects only Objects with this material");
2296                         }
2297                         else
2298                         {
2299                                 uiDefBut(block, TEX, 1, "Property:", xco + 50, yco-84, (width-60), 19,
2300                                         coa->matprop, 0, 31, 0, 0,
2301                                         "Ray detect only Objects with this property");
2302                         }
2303                         uiDefButBitS(block, TOG, ACT_CONST_PERMANENT, 0, "PER", xco+10, yco-103, 40, 19,
2304                                 &coa->flag, 0.0, 0.0, 0, 0, "Persistent actuator: stays active even if ray does not reach target");
2305                         uiDefButS(block, NUM, 0, "time", xco+50, yco-103, 90, 19, &(coa->time), 0.0, 1000.0, 0, 0, "Maximum activation time in frame, 0 for unlimited");
2306                         uiDefButF(block, NUM, 0, "rotDamp", xco+140, yco-103, (width-150), 19, &coa->maxrot[1], 0.0, 1.0, 1, 0, "Use a different damping for rotation");
2307                 }
2308                 str= "Constraint Type %t|Location %x0|Distance %x1|Orientation %x2|Force field %x3";
2309                 but = uiDefButS(block, MENU, B_REDR, str,               xco+40, yco-23, (width-80), 19, &coa->type, 0.0, 0.0, 0, 0, "");
2310                 yco-= ysize;
2311         break;
2312  
2313         case ACT_SCENE:
2314                 sca= act->data; 
2315                 
2316                 if(sca->type==ACT_SCENE_RESTART) { 
2317                         ysize= 28; 
2318                         glRects(xco, yco-ysize, xco+width, yco); 
2319                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2320                 } 
2321                 else if(sca->type==ACT_SCENE_CAMERA) { 
2322                         
2323                         ysize= 48; 
2324                         glRects(xco, yco-ysize, xco+width, yco); 
2325                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2326          
2327                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:",         xco+40, yco-44, (width-80), 19, &(sca->camera), "Set this Camera. Leave empty to refer to self object"); 
2328                 } 
2329                 else if(sca->type==ACT_SCENE_SET) { 
2330                         
2331                         ysize= 48; 
2332                         glRects(xco, yco-ysize, xco+width, yco); 
2333                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2334         
2335                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Set this Scene"); 
2336                 } 
2337                 else if(sca->type==ACT_SCENE_ADD_FRONT) { 
2338                         
2339                         ysize= 48; 
2340                         glRects(xco, yco-ysize, xco+width, yco); 
2341                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2342         
2343                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Add an Overlay Scene"); 
2344                 } 
2345                 else if(sca->type==ACT_SCENE_ADD_BACK) { 
2346                         
2347                         ysize= 48; 
2348                         glRects(xco, yco-ysize, xco+width, yco); 
2349                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2350         
2351                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Add a Background Scene"); 
2352                 } 
2353                 else if(sca->type==ACT_SCENE_REMOVE) { 
2354                         
2355                         ysize= 48; 
2356                         glRects(xco, yco-ysize, xco+width, yco); 
2357                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2358         
2359                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Remove a Scene");
2360                 } 
2361                 else if(sca->type==ACT_SCENE_SUSPEND) { 
2362                         
2363                         ysize= 48; 
2364                         glRects(xco, yco-ysize, xco+width, yco); 
2365                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2366         
2367                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Pause a Scene");
2368                 } 
2369                 else if(sca->type==ACT_SCENE_RESUME) { 
2370                         
2371                         ysize= 48; 
2372                         glRects(xco, yco-ysize, xco+width, yco); 
2373                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2374         
2375                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Unpause a Scene");
2376                 } 
2377
2378                 str= "Scene %t|Restart %x0|Set Scene %x1|Set Camera %x2|Add OverlayScene %x3|Add BackgroundScene %x4|Remove Scene %x5|Suspend Scene %x6|Resume Scene %x7";
2379                 uiDefButS(block, MENU, B_REDR, str,             xco+40, yco-24, (width-80), 19, &sca->type, 0.0, 0.0, 0, 0, ""); 
2380
2381                 yco-= ysize; 
2382                 break; 
2383         case ACT_GAME:
2384                 {
2385                         gma = act->data; 
2386                         if (gma->type == ACT_GAME_LOAD)
2387                         {
2388                                 //ysize = 68;
2389                                 ysize = 48;
2390                                 glRects(xco, yco-ysize, xco+width, yco); 
2391                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2392                                 uiDefBut(block, TEX, 1, "File: ", xco+10, yco-44,width-20,19, &(gma->filename), 0, 63, 0, 0, "Load this file");
2393 //                              uiDefBut(block, TEX, 1, "Anim: ", xco+10, yco-64,width-20,19, &(gma->loadaniname), 0, 63, 0, 0, "Use this loadinganimation");
2394                         }
2395 /*                      else if (gma->type == ACT_GAME_START)
2396                         {
2397                                 ysize = 68; 
2398                                 glRects(xco, yco-ysize, xco+width, yco); 
2399                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2400
2401                                 uiDefBut(block, TEX, 1, "File: ", xco+10, yco-44,width-20,19, &(gma->filename), 0, 63, 0, 0, "Load this file");
2402                                 uiDefBut(block, TEX, 1, "Anim: ", xco+10, yco-64,width-20,19, &(gma->loadaniname), 0, 63, 0, 0, "Use this loadinganimation");
2403                         }
2404 */                      else if (ELEM4(gma->type, ACT_GAME_RESTART, ACT_GAME_QUIT, ACT_GAME_SAVECFG, ACT_GAME_LOADCFG))
2405                         {
2406                                 ysize = 28; 
2407                                 glRects(xco, yco-ysize, xco+width, yco); 
2408                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2409                         }
2410
2411                         //str = "Scene %t|Load game%x0|Start loaded game%x1|Restart this game%x2|Quit this game %x3";
2412                         str = "Scene %t|Start new game%x0|Restart this game%x2|Quit this game %x3|Save GameLogic.globalDict %x4|Load GameLogic.globalDict %x5";
2413                         uiDefButS(block, MENU, B_REDR, str, xco+40, yco-24, (width-80), 19, &gma->type, 0.0, 0.0, 0, 0, ""); 
2414                         
2415                         yco -= ysize; 
2416                         break; 
2417                 }
2418         case ACT_GROUP:
2419                 ga= act->data;
2420
2421                 ysize= 52;
2422
2423                 glRects(xco, yco-ysize, xco+width, yco);
2424                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2425                 
2426                 str= "GroupKey types   %t|Set Key %x6|Play %x0|Ping Pong %x1|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x5";
2427
2428                 uiDefButS(block, MENU, 1, str,                  xco+20, yco-24, width-40, 19, &ga->type, 0, 0, 0, 0, "");
2429                 if(ga->type==ACT_GROUP_SET) {
2430                         uiDefBut(block, TEX, 0, "Key: ",                xco+20, yco-44, (width-10)/2, 19, ga->name, 0.0, 31.0, 0, 0, "This name defines groupkey to be set");
2431                         uiDefButI(block, NUM, 0, "Frame:",      xco+20+(width-10)/2, yco-44, (width-70)/2, 19, &ga->sta, 0.0, 2500.0, 0, 0, "Set this frame");
2432                 }
2433                 else if(ga->type==ACT_GROUP_FROM_PROP) {
2434                         uiDefBut(block, TEX, 0, "Prop: ",               xco+20, yco-44, width-40, 19, ga->name, 0.0, 31.0, 0, 0, "Use this property to define the Group position");
2435                 }
2436                 else {
2437                         uiDefButI(block, NUM, 0, "State",               xco+20, yco-44, (width-40)/2, 19, &ga->sta, 0.0, 2500.0, 0, 0, "Start frame");
2438                         uiDefButI(block, NUM, 0, "End",         xco+20+(width-40)/2, yco-44, (width-40)/2, 19, &ga->end, 0.0, 2500.0, 0, 0, "End frame");
2439                 }
2440                 yco-= ysize;
2441                 break;
2442
2443         case ACT_VISIBILITY:
2444                 ysize = 24;
2445
2446                 glRects(xco, yco-ysize, xco+width, yco);
2447                 uiEmboss((float)xco,
2448                          (float)yco-ysize, (float)xco+width, (float)yco, 1);
2449                 
2450                 visAct = act->data;
2451
2452                 uiBlockBeginAlign(block);
2453                 uiDefButBitI(block, TOGN, ACT_VISIBILITY_INVISIBLE, B_REDR,
2454                           "Visible",
2455                           xco + 10, yco - 20, (width - 20)/3, 19, &visAct->flag,
2456                           0.0, 0.0, 0, 0,
2457                           "Set the objects visible. Initialized from the objects render restriction toggle (access in the outliner)");
2458                 uiDefButBitI(block, TOG, ACT_VISIBILITY_INVISIBLE, B_REDR,
2459                           "Invisible",
2460                           xco + 10 + ((width - 20)/3), yco - 20, (width - 20)/3, 19, &visAct->flag,
2461                           0.0, 0.0, 0, 0,
2462                           "Set the object invisible. Initialized from the objects render restriction toggle (access in the outliner)");
2463                 uiBlockEndAlign(block);
2464                 
2465                 uiDefButBitI(block, TOG, ACT_VISIBILITY_RECURSIVE, B_NOP,
2466                           "Children",
2467                           xco + 10 + (((width - 20)/3)*2)+10, yco - 20, ((width - 20)/3)-10, 19, &visAct->flag,
2468                           0.0, 0.0, 0, 0,
2469                           "Sets all the children of this object to the same visibility recursively");
2470
2471                 yco-= ysize;
2472
2473                 break;
2474                 
2475         case ACT_STATE:
2476                 ysize = 34;
2477
2478                 glRects(xco, yco-ysize, xco+width, yco);
2479                 uiEmboss((float)xco,
2480                          (float)yco-ysize, (float)xco+width, (float)yco, 1);
2481                 
2482                 staAct = act->data;
2483
2484                 str= "Operation %t|Cpy %x0|Add %x1|Sub %x2|Inv %x3";
2485
2486                 uiDefButI(block, MENU, B_REDR, str,
2487                           xco + 10, yco - 24, 65, 19, &staAct->type,
2488                           0.0, 0.0, 0, 0,
2489                           "Select the bit operation on object state mask");
2490
2491                 for (wval=0; wval<15; wval+=5) {
2492                         uiBlockBeginAlign(block);
2493                         for (stbit=0; stbit<5; stbit++) {
2494                                 but = uiDefButBitI(block,  TOG, 1<<(stbit+wval), stbit+wval, "",        (short)(xco+85+12*stbit+13*wval), yco-17, 12, 12, (int *)&(staAct->mask), 0, 0, 0, 0, get_state_name(ob, (short)(stbit+wval)));
2495                                 uiButSetFunc(but, check_state_mask, but, &(staAct->mask));
2496                         }
2497                         for (stbit=0; stbit<5; stbit++) {
2498                                 but = uiDefButBitI(block, TOG, 1<<(stbit+wval+15), stbit+wval+15, "",   (short)(xco+85+12*stbit+13*wval), yco-29, 12, 12, (int *)&(staAct->mask), 0, 0, 0, 0, get_state_name(ob, (short)(stbit+wval+15)));
2499                                 uiButSetFunc(but, check_state_mask, but, &(staAct->mask));
2500                         }
2501                 }
2502                 uiBlockEndAlign(block);
2503
2504                 yco-= ysize;
2505
2506                 break;
2507
2508         case ACT_RANDOM:
2509                 ysize  = 69;
2510
2511                 glRects(xco, yco-ysize, xco+width, yco);
2512                 uiEmboss((float)xco,
2513                                   (float)yco-ysize, (float)xco+width, (float)yco, 1);
2514                 
2515                 randAct = act->data;
2516
2517                 /* 1. seed */
2518                 uiDefButI(block, NUM, 1, "Seed: ",              (xco+10),yco-24, 0.4 *(width-20), 19,
2519                                  &randAct->seed, 0, 1000, 0, 0,
2520                                  "Initial seed of the random generator. Use Python for more freedom. "
2521                                  " (Choose 0 for not random)");
2522
2523                 /* 2. distribution type */
2524                 /* One pick per distribution. These numbers MUST match the #defines  */
2525                 /* in game.h !!!                                                     */
2526                 str= "Distribution %t|Bool Constant %x0|Bool Uniform %x1"
2527                         "|Bool Bernoulli %x2|Int Constant %x3|Int Uniform %x4"
2528                         "|Int Poisson %x5|Float Constant %x6|Float Uniform %x7"
2529                         "|Float Normal %x8|Float Neg. Exp. %x9";
2530                 uiDefButI(block, MENU, B_REDR, str, (xco+10) + 0.4 * (width-20), yco-24, 0.6 * (width-20), 19,
2531                                  &randAct->distribution, 0.0, 0.0, 0, 0,
2532                                  "Choose the type of distribution");
2533
2534                 /* 3. property */
2535                 uiDefBut(block, TEX, 1, "Property:", (xco+10), yco-44, (width-20), 19,
2536                                  &randAct->propname, 0, 31, 0, 0,
2537                                  "Assign the random value to this property"); 
2538
2539                 /*4. and 5. arguments for the distribution*/
2540                 switch (randAct->distribution) {
2541                 case ACT_RANDOM_BOOL_CONST:
2542                         uiDefButBitI(block, TOG, 1, 1, "Always true", (xco+10), yco-64, (width-20), 19,
2543                                          &randAct->int_arg_1, 2.0, 1, 0, 0,
2544                                          "Always false or always true");                        
2545                         break;
2546                 case ACT_RANDOM_BOOL_UNIFORM:
2547                         uiDefBut(block, LABEL, 0, "     Do a 50-50 pick.",      (xco+10), yco-64, (width-20), 19,
2548                                          NULL, 0, 0, 0, 0,
2549                                          "Choose between true and false, 50% chance each.");
2550                         break;
2551                 case ACT_RANDOM_BOOL_BERNOUILLI:
2552                         uiDefButF(block, NUM, 1, "Chance", (xco+10), yco-64, (width-20), 19,
2553                                          &randAct->float_arg_1, 0.0, 1.0, 0, 0,
2554                                          "Pick a number between 0 and 1. Success if you stay "
2555                                          "below this value");                   
2556                         break;
2557                 case ACT_RANDOM_INT_CONST:
2558                         uiDefButI(block, NUM, 1, "Value: ",             (xco+10), yco-64, (width-20), 19,
2559                                          &randAct->int_arg_1, -1000, 1000, 0, 0,
2560                                          "Always return this number");
2561                         break;
2562                 case ACT_RANDOM_INT_UNIFORM:
2563                         uiDefButI(block, NUM, 1, "Min: ",               (xco+10), yco-64, (width-20)/2, 19,
2564                                          &randAct->int_arg_1, -1000, 1000, 0, 0,
2565                                          "Choose a number from a range. "
2566                                          "Lower boundary of the range.");
2567                         uiDefButI(block, NUM, 1, "Max: ",               (xco+10) + (width-20)/2, yco-64, (width-20)/2, 19,
2568                                          &randAct->int_arg_2, -1000, 1000, 0, 0,
2569                                          "Choose a number from a range. "
2570                                          "Upper boundary of the range.");
2571                         break;
2572                 case ACT_RANDOM_INT_POISSON:
2573                         uiDefButF(block, NUM, 1, "Mean: ", (xco+10), yco-64, (width-20), 19,
2574                                          &randAct->float_arg_1, 0.01, 100.0, 0, 0,
2575                                          "Expected mean value of the distribution.");                                           
2576                         break;
2577                 case ACT_RANDOM_FLOAT_CONST:
2578                         uiDefButF(block, NUM, 1, "Value: ", (xco+10), yco-64, (width-20), 19,
2579                                          &randAct->float_arg_1, 0.0, 1.0, 0, 0,
2580                                          "Always return this number");
2581                         break;
2582                 case ACT_RANDOM_FLOAT_UNIFORM:
2583                         uiDefButF(block, NUM, 1, "Min: ",               (xco+10), yco-64, (width-20)/2, 19,
2584                                          &randAct->float_arg_1, -10000.0, 10000.0, 0, 0,
2585                                          "Choose a number from a range. "
2586                                          "Lower boundary of the range.");
2587                         uiDefButF(block, NUM, 1, "Max: ",               (xco+10) + (width-20)/2, yco-64, (width-20)/2, 19,
2588                                          &randAct->float_arg_2, -10000.0, 10000.0, 0, 0,
2589                                          "Choose a number from a range. "
2590                                          "Upper boundary of the range.");
2591                         break;
2592                 case ACT_RANDOM_FLOAT_NORMAL:
2593                         uiDefButF(block, NUM, 1, "Mean: ",              (xco+10), yco-64, (width-20)/2, 19,
2594                                          &randAct->float_arg_1, -10000.0, 10000.0, 0, 0,
2595                                          "A normal distribution. Mean of the distribution.");
2596                         uiDefButF(block, NUM, 1, "SD: ",                (xco+10) + (width-20)/2, yco-64, (width-20)/2, 19,
2597                                          &randAct->float_arg_2, 0.0, 10000.0, 0, 0,
2598                                          "A normal distribution. Standard deviation of the "
2599                                          "distribution.");
2600                         break;
2601                 case ACT_RANDOM_FLOAT_NEGATIVE_EXPONENTIAL:
2602                         uiDefButF(block, NUM, 1, "Half-life time: ", (xco+10), yco-64, (width-20), 19,
2603                                          &randAct->float_arg_1, 0.001, 10000.0, 0, 0,
2604                                          "Negative exponential dropoff.");
2605                         break;
2606                 default:
2607                         ; /* don't know what this distro is... can be useful for testing */
2608                         /* though :)                                                     */
2609                 }
2610
2611                 yco-= ysize;
2612                 break;
2613         case ACT_MESSAGE:
2614