1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
|
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2009 Blender Foundation.
* All rights reserved.
*
*
* Contributor(s): Blender Foundation
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/editors/space_logic/logic_window.c
* \ingroup splogic
*/
#include <string.h>
#include <stdio.h>
#include <stddef.h>
#include <float.h>
#include "DNA_actuator_types.h"
#include "DNA_controller_types.h"
#include "DNA_property_types.h"
#include "DNA_space_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_sensor_types.h"
#include "DNA_constraint_types.h"
#include "DNA_windowmanager_types.h"
#include "DNA_object_types.h"
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "BLI_utildefines.h"
#include "BKE_action.h"
#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_sca.h"
#include "ED_util.h"
#include "WM_types.h"
#include "BIF_gl.h"
#include "UI_interface.h"
#include "RNA_access.h"
/* XXX BAD BAD */
#include "../interface/interface_intern.h"
#include "logic_intern.h"
#define B_REDR 1
#define B_ADD_SENS 2703
#define B_CHANGE_SENS 2704
#define B_DEL_SENS 2705
#define B_ADD_CONT 2706
#define B_CHANGE_CONT 2707
#define B_DEL_CONT 2708
#define B_ADD_ACT 2709
#define B_CHANGE_ACT 2710
#define B_DEL_ACT 2711
#define B_SOUNDACT_BROWSE 2712
#define B_SETPROP 2714
#define B_SETACTOR 2715
#define B_SETMAINACTOR 2716
#define B_SETDYNA 2717
#define B_SET_STATE_BIT 2718
#define B_INIT_STATE_BIT 2719
/* proto */
static ID **get_selected_and_linked_obs(bContext *C, short *count, short scavisflag);
static int vergname(const void *v1, const void *v2)
{
char **x1, **x2;
x1= (char **)v1;
x2= (char **)v2;
return BLI_natstrcmp(*x1, *x2);
}
void make_unique_prop_names(bContext *C, char *str)
{
Object *ob;
bProperty *prop;
bSensor *sens;
bController *cont;
bActuator *act;
ID **idar;
short a, obcount, propcount=0, nr;
char **names;
/* this function is called by a Button, and gives the current
* stringpointer as an argument, this is the one that can change
*/
idar= get_selected_and_linked_obs(C, &obcount, BUTS_SENS_SEL|BUTS_SENS_ACT|BUTS_ACT_SEL|BUTS_ACT_ACT|BUTS_CONT_SEL|BUTS_CONT_ACT);
/* for each object, make properties and sca names unique */
/* count total names */
for (a=0; a<obcount; a++) {
ob= (Object *)idar[a];
propcount+= BLI_countlist(&ob->prop);
propcount+= BLI_countlist(&ob->sensors);
propcount+= BLI_countlist(&ob->controllers);
propcount+= BLI_countlist(&ob->actuators);
}
if (propcount==0) {
if (idar) MEM_freeN(idar);
return;
}
/* make names array for sorting */
names= MEM_callocN(propcount*sizeof(void *), "names");
/* count total names */
nr= 0;
for (a=0; a<obcount; a++) {
ob= (Object *)idar[a];
prop= ob->prop.first;
while (prop) {
names[nr++] = prop->name;
prop= prop->next;
}
sens= ob->sensors.first;
while (sens) {
names[nr++] = sens->name;
sens= sens->next;
}
cont= ob->controllers.first;
while (cont) {
names[nr++] = cont->name;
cont= cont->next;
}
act= ob->actuators.first;
while (act) {
names[nr++] = act->name;
act= act->next;
}
}
qsort(names, propcount, sizeof(void *), vergname);
/* now we check for double names, and change them */
for (nr=0; nr<propcount; nr++) {
if (names[nr]!=str && strcmp( names[nr], str )==0 ) {
BLI_newname(str, +1);
}
}
MEM_freeN(idar);
MEM_freeN(names);
}
static void do_logic_buts(bContext *C, void *UNUSED(arg), int event)
{
Main *bmain= CTX_data_main(C);
bSensor *sens;
bController *cont;
bActuator *act;
Object *ob;
int didit, bit;
ob= CTX_data_active_object(C);
if (ob==NULL) return;
switch (event) {
case B_SETPROP:
/* check for inconsistent types */
ob->gameflag &= ~(OB_SECTOR|OB_MAINACTOR|OB_DYNAMIC|OB_ACTOR);
break;
case B_SETACTOR:
case B_SETDYNA:
case B_SETMAINACTOR:
ob->gameflag &= ~(OB_SECTOR|OB_PROP);
break;
case B_ADD_SENS:
for (ob=bmain->object.first; ob; ob=ob->id.next) {
if (ob->scaflag & OB_ADDSENS) {
ob->scaflag &= ~OB_ADDSENS;
sens= new_sensor(SENS_ALWAYS);
BLI_addtail(&(ob->sensors), sens);
make_unique_prop_names(C, sens->name);
ob->scaflag |= OB_SHOWSENS;
}
}
ED_undo_push(C, "Add sensor");
break;
case B_CHANGE_SENS:
for (ob=bmain->object.first; ob; ob=ob->id.next) {
sens= ob->sensors.first;
while (sens) {
if (sens->type != sens->otype) {
init_sensor(sens);
sens->otype= sens->type;
break;
}
sens= sens->next;
}
}
break;
case B_DEL_SENS:
for (ob=bmain->object.first; ob; ob=ob->id.next) {
sens= ob->sensors.first;
while (sens) {
if (sens->flag & SENS_DEL) {
BLI_remlink(&(ob->sensors), sens);
free_sensor(sens);
break;
}
sens= sens->next;
}
}
ED_undo_push(C, "Delete sensor");
break;
case B_ADD_CONT:
for (ob=bmain->object.first; ob; ob=ob->id.next) {
if (ob->scaflag & OB_ADDCONT) {
ob->scaflag &= ~OB_ADDCONT;
cont= new_controller(CONT_LOGIC_AND);
make_unique_prop_names(C, cont->name);
ob->scaflag |= OB_SHOWCONT;
BLI_addtail(&(ob->controllers), cont);
/* set the controller state mask from the current object state.
* A controller is always in a single state, so select the lowest bit set
* from the object state */
for (bit=0; bit<32; bit++) {
if (ob->state & (1<<bit))
break;
}
cont->state_mask = (1<<bit);
if (cont->state_mask == 0) {
/* shouldn't happen, object state is never 0 */
cont->state_mask = 1;
}
}
}
ED_undo_push(C, "Add controller");
break;
case B_SET_STATE_BIT:
for (ob=bmain->object.first; ob; ob=ob->id.next) {
if (ob->scaflag & OB_ALLSTATE) {
ob->scaflag &= ~OB_ALLSTATE;
ob->state = 0x3FFFFFFF;
}
}
break;
case B_INIT_STATE_BIT:
for (ob=bmain->object.first; ob; ob=ob->id.next) {
if (ob->scaflag & OB_INITSTBIT) {
ob->scaflag &= ~OB_INITSTBIT;
ob->state = ob->init_state;
if (!ob->state)
ob->state = 1;
}
}
break;
case B_CHANGE_CONT:
for (ob=bmain->object.first; ob; ob=ob->id.next) {
cont= ob->controllers.first;
while (cont) {
if (cont->type != cont->otype) {
init_controller(cont);
cont->otype= cont->type;
break;
}
cont= cont->next;
}
}
break;
case B_DEL_CONT:
for (ob=bmain->object.first; ob; ob=ob->id.next) {
cont= ob->controllers.first;
while (cont) {
if (cont->flag & CONT_DEL) {
BLI_remlink(&(ob->controllers), cont);
unlink_controller(cont);
free_controller(cont);
break;
}
cont= cont->next;
}
}
ED_undo_push(C, "Delete controller");
break;
case B_ADD_ACT:
for (ob=bmain->object.first; ob; ob=ob->id.next) {
if (ob->scaflag & OB_ADDACT) {
ob->scaflag &= ~OB_ADDACT;
act= new_actuator(ACT_OBJECT);
make_unique_prop_names(C, act->name);
BLI_addtail(&(ob->actuators), act);
ob->scaflag |= OB_SHOWACT;
}
}
ED_undo_push(C, "Add actuator");
break;
case B_CHANGE_ACT:
for (ob=bmain->object.first; ob; ob=ob->id.next) {
act= ob->actuators.first;
while (act) {
if (act->type != act->otype) {
init_actuator(act);
act->otype= act->type;
break;
}
act= act->next;
}
}
break;
case B_DEL_ACT:
for (ob=bmain->object.first; ob; ob=ob->id.next) {
act= ob->actuators.first;
while (act) {
if (act->flag & ACT_DEL) {
BLI_remlink(&(ob->actuators), act);
unlink_actuator(act);
free_actuator(act);
break;
}
act= act->next;
}
}
ED_undo_push(C, "Delete actuator");
break;
case B_SOUNDACT_BROWSE:
/* since we don't know which... */
didit= 0;
for (ob=bmain->object.first; ob; ob=ob->id.next) {
act= ob->actuators.first;
while (act) {
if (act->type==ACT_SOUND) {
bSoundActuator *sa= act->data;
if (sa->sndnr) {
ID *sound= bmain->sound.first;
int nr= 1;
if (sa->sndnr == -2) {
// XXX activate_databrowse((ID *)bmain->sound.first, ID_SO, 0, B_SOUNDACT_BROWSE,
// &sa->sndnr, do_logic_buts);
break;
}
while (sound) {
if (nr==sa->sndnr)
break;
nr++;
sound= sound->next;
}
if (sa->sound)
((ID *)sa->sound)->us--;
sa->sound= (struct bSound *)sound;
if (sound)
sound->us++;
sa->sndnr= 0;
didit= 1;
}
}
act= act->next;
}
if (didit)
break;
}
break;
}
}
static const char *sensor_name(int type)
{
switch (type) {
case SENS_ALWAYS:
return "Always";
case SENS_TOUCH:
return "Touch";
case SENS_NEAR:
return "Near";
case SENS_KEYBOARD:
return "Keyboard";
case SENS_PROPERTY:
return "Property";
case SENS_ARMATURE:
return "Armature";
case SENS_ACTUATOR:
return "Actuator";
case SENS_DELAY:
return "Delay";
case SENS_MOUSE:
return "Mouse";
case SENS_COLLISION:
return "Collision";
case SENS_RADAR:
return "Radar";
case SENS_RANDOM:
return "Random";
case SENS_RAY:
return "Ray";
case SENS_MESSAGE:
return "Message";
case SENS_JOYSTICK:
return "Joystick";
}
return "unknown";
}
static const char *controller_name(int type)
{
switch (type) {
case CONT_LOGIC_AND:
return "And";
case CONT_LOGIC_OR:
return "Or";
case CONT_LOGIC_NAND:
return "Nand";
case CONT_LOGIC_NOR:
return "Nor";
case CONT_LOGIC_XOR:
return "Xor";
case CONT_LOGIC_XNOR:
return "Xnor";
case CONT_EXPRESSION:
return "Expression";
case CONT_PYTHON:
return "Python";
}
return "unknown";
}
static const char *actuator_name(int type)
{
switch (type) {
case ACT_SHAPEACTION:
return "Shape Action";
case ACT_ACTION:
return "Action";
case ACT_OBJECT:
return "Motion";
case ACT_IPO:
return "F-Curve";
case ACT_LAMP:
return "Lamp";
case ACT_CAMERA:
return "Camera";
case ACT_MATERIAL:
return "Material";
case ACT_SOUND:
return "Sound";
case ACT_PROPERTY:
return "Property";
case ACT_EDIT_OBJECT:
return "Edit Object";
case ACT_CONSTRAINT:
return "Constraint";
case ACT_SCENE:
return "Scene";
case ACT_GROUP:
return "Group";
case ACT_RANDOM:
return "Random";
case ACT_MESSAGE:
return "Message";
case ACT_GAME:
return "Game";
case ACT_VISIBILITY:
return "Visibility";
case ACT_2DFILTER:
return "Filter 2D";
case ACT_PARENT:
return "Parent";
case ACT_STATE:
return "State";
case ACT_ARMATURE:
return "Armature";
case ACT_STEERING:
return "Steering";
}
return "unknown";
}
static void set_sca_ob(Object *ob)
{
bController *cont;
bActuator *act;
cont= ob->controllers.first;
while (cont) {
cont->mynew= (bController *)ob;
cont= cont->next;
}
act= ob->actuators.first;
while (act) {
act->mynew= (bActuator *)ob;
act= act->next;
}
}
static ID **get_selected_and_linked_obs(bContext *C, short *count, short scavisflag)
{
Base *base;
Main *bmain= CTX_data_main(C);
Scene *scene= CTX_data_scene(C);
Object *ob, *obt, *obact= CTX_data_active_object(C);
ID **idar;
bSensor *sens;
bController *cont;
unsigned int lay;
int a, nr, do_it;
/* we need a sorted object list */
/* set scavisflags flags in Objects to indicate these should be evaluated */
/* also hide ob pointers in ->new entries of controllerss/actuators */
*count= 0;
if (scene==NULL) return NULL;
ob= bmain->object.first;
while (ob) {
ob->scavisflag= 0;
set_sca_ob(ob);
ob= ob->id.next;
}
/* XXX here it checked 3d lay */
lay= scene->lay;
base= FIRSTBASE;
while (base) {
if (base->lay & lay) {
if (base->flag & SELECT) {
if (scavisflag & BUTS_SENS_SEL) base->object->scavisflag |= OB_VIS_SENS;
if (scavisflag & BUTS_CONT_SEL) base->object->scavisflag |= OB_VIS_CONT;
if (scavisflag & BUTS_ACT_SEL) base->object->scavisflag |= OB_VIS_ACT;
}
}
base= base->next;
}
if (obact) {
if (scavisflag & BUTS_SENS_ACT) obact->scavisflag |= OB_VIS_SENS;
if (scavisflag & BUTS_CONT_ACT) obact->scavisflag |= OB_VIS_CONT;
if (scavisflag & BUTS_ACT_ACT) obact->scavisflag |= OB_VIS_ACT;
}
/* BUTS_XXX_STATE are similar to BUTS_XXX_LINK for selecting the object */
if (scavisflag & (BUTS_SENS_LINK|BUTS_CONT_LINK|BUTS_ACT_LINK|BUTS_SENS_STATE|BUTS_ACT_STATE)) {
do_it = TRUE;
while (do_it) {
do_it = FALSE;
ob= bmain->object.first;
while (ob) {
/* 1st case: select sensor when controller selected */
if ((scavisflag & (BUTS_SENS_LINK|BUTS_SENS_STATE)) && (ob->scavisflag & OB_VIS_SENS)==0) {
sens= ob->sensors.first;
while (sens) {
for (a=0; a<sens->totlinks; a++) {
if (sens->links[a]) {
obt= (Object *)sens->links[a]->mynew;
if (obt && (obt->scavisflag & OB_VIS_CONT)) {
do_it = TRUE;
ob->scavisflag |= OB_VIS_SENS;
break;
}
}
}
if (do_it) break;
sens= sens->next;
}
}
/* 2nd case: select cont when act selected */
if ((scavisflag & BUTS_CONT_LINK) && (ob->scavisflag & OB_VIS_CONT)==0) {
cont= ob->controllers.first;
while (cont) {
for (a=0; a<cont->totlinks; a++) {
if (cont->links[a]) {
obt= (Object *)cont->links[a]->mynew;
if (obt && (obt->scavisflag & OB_VIS_ACT)) {
do_it = TRUE;
ob->scavisflag |= OB_VIS_CONT;
break;
}
}
}
if (do_it) break;
cont= cont->next;
}
}
/* 3rd case: select controller when sensor selected */
if ((scavisflag & BUTS_CONT_LINK) && (ob->scavisflag & OB_VIS_SENS)) {
sens= ob->sensors.first;
while (sens) {
for (a=0; a<sens->totlinks; a++) {
if (sens->links[a]) {
obt= (Object *)sens->links[a]->mynew;
if (obt && (obt->scavisflag & OB_VIS_CONT)==0) {
do_it = TRUE;
obt->scavisflag |= OB_VIS_CONT;
}
}
}
sens= sens->next;
}
}
/* 4th case: select actuator when controller selected */
if ((scavisflag & (BUTS_ACT_LINK|BUTS_ACT_STATE)) && (ob->scavisflag & OB_VIS_CONT)) {
cont= ob->controllers.first;
while (cont) {
for (a=0; a<cont->totlinks; a++) {
if (cont->links[a]) {
obt= (Object *)cont->links[a]->mynew;
if (obt && (obt->scavisflag & OB_VIS_ACT)==0) {
do_it = TRUE;
obt->scavisflag |= OB_VIS_ACT;
}
}
}
cont= cont->next;
}
}
ob= ob->id.next;
}
}
}
/* now we count */
ob= bmain->object.first;
while (ob) {
if ( ob->scavisflag ) (*count)++;
ob= ob->id.next;
}
if (*count == 0) return NULL;
if (*count > 24) *count = 24; /* temporal */
idar= MEM_callocN((*count)*sizeof(void *), "idar");
ob= bmain->object.first;
nr= 0;
/* make the active object always the first one of the list */
if (obact) {
idar[0] = (ID *)obact;
nr++;
}
while (ob) {
if ((ob->scavisflag) && (ob != obact)) {
idar[nr] = (ID *)ob;
nr++;
}
if (nr >= 24) break;
ob= ob->id.next;
}
/* just to be sure... these were set in set_sca_done_ob() */
clear_sca_new_poins();
return idar;
}
static void get_armature_bone_constraint(Object *ob, const char *posechannel, const char *constraint_name, bConstraint **constraint)
{
/* check that bone exist in the active object */
if (ob->type == OB_ARMATURE && ob->pose) {
bPoseChannel *pchan= BKE_pose_channel_find_name(ob->pose, posechannel);
if (pchan) {
bConstraint *con= BLI_findstring(&pchan->constraints, constraint_name, offsetof(bConstraint, name));
if (con) {
*constraint= con;
}
}
}
/* didn't find any */
}
static void do_sensor_menu(bContext *C, void *UNUSED(arg), int event)
{
SpaceLogic *slogic= CTX_wm_space_logic(C);
ID **idar;
Object *ob;
bSensor *sens;
short count, a;
idar= get_selected_and_linked_obs(C, &count, slogic->scaflag);
for (a=0; a<count; a++) {
ob= (Object *)idar[a];
if (event==0 || event==2) ob->scaflag |= OB_SHOWSENS;
else if (event==1) ob->scaflag &= ~OB_SHOWSENS;
}
for (a=0; a<count; a++) {
ob= (Object *)idar[a];
sens= ob->sensors.first;
while (sens) {
if (event==2) sens->flag |= SENS_SHOW;
else if (event==3) sens->flag &= ~SENS_SHOW;
sens= sens->next;
}
}
if (idar) MEM_freeN(idar);
}
static uiBlock *sensor_menu(bContext *C, ARegion *ar, void *UNUSED(arg))
{
uiBlock *block;
int yco=0;
block= uiBeginBlock(C, ar, __func__, UI_EMBOSSP);
uiBlockSetButmFunc(block, do_sensor_menu, NULL);
uiDefBut(block, BUTM, 1, "Show Objects", 0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 0, "");
uiDefBut(block, BUTM, 1, "Hide Objects", 0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 1, "");
uiDefBut(block, SEPR, 0, "", 0, (short)(yco-=6), 160, 6, NULL, 0.0, 0.0, 0, 0, "");
uiDefBut(block, BUTM, 1, "Show Sensors", 0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 2, "");
uiDefBut(block, BUTM, 1, "Hide Sensors", 0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 3, "");
uiBlockSetDirection(block, UI_TOP);
uiEndBlock(C, block);
return block;
}
static void do_controller_menu(bContext *C, void *UNUSED(arg), int event)
{
SpaceLogic *slogic= CTX_wm_space_logic(C);
ID **idar;
Object *ob;
bController *cont;
short count, a;
idar= get_selected_and_linked_obs(C, &count, slogic->scaflag);
for (a=0; a<count; a++) {
ob= (Object *)idar[a];
if (event==0 || event==2) ob->scaflag |= OB_SHOWCONT;
else if (event==1) ob->scaflag &= ~OB_SHOWCONT;
}
for (a=0; a<count; a++) {
ob= (Object *)idar[a];
cont= ob->controllers.first;
while (cont) {
if (event==2) cont->flag |= CONT_SHOW;
else if (event==3) cont->flag &= ~CONT_SHOW;
cont= cont->next;
}
}
if (idar) MEM_freeN(idar);
}
static uiBlock *controller_menu(bContext *C, ARegion *ar, void *UNUSED(arg))
{
uiBlock *block;
int yco=0;
block= uiBeginBlock(C, ar, __func__, UI_EMBOSSP);
uiBlockSetButmFunc(block, do_controller_menu, NULL);
uiDefBut(block, BUTM, 1, "Show Objects", 0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 0, "");
uiDefBut(block, BUTM, 1, "Hide Objects", 0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 1, "");
uiDefBut(block, SEPR, 0, "", 0, (short)(yco-=6), 160, 6, NULL, 0.0, 0.0, 0, 0, "");
uiDefBut(block, BUTM, 1, "Show Controllers", 0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 2, 2, "");
uiDefBut(block, BUTM, 1, "Hide Controllers", 0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 3, 3, "");
uiBlockSetDirection(block, UI_TOP);
uiEndBlock(C, block);
return block;
}
static void do_actuator_menu(bContext *C, void *UNUSED(arg), int event)
{
SpaceLogic *slogic= CTX_wm_space_logic(C);
ID **idar;
Object *ob;
bActuator *act;
short count, a;
idar= get_selected_and_linked_obs(C, &count, slogic->scaflag);
for (a=0; a<count; a++) {
ob= (Object *)idar[a];
if (event==0 || event==2) ob->scaflag |= OB_SHOWACT;
else if (event==1) ob->scaflag &= ~OB_SHOWACT;
}
for (a=0; a<count; a++) {
ob= (Object *)idar[a];
act= ob->actuators.first;
while (act) {
if (event==2) act->flag |= ACT_SHOW;
else if (event==3) act->flag &= ~ACT_SHOW;
act= act->next;
}
}
if (idar) MEM_freeN(idar);
}
static uiBlock *actuator_menu(bContext *C, ARegion *ar, void *UNUSED(arg))
{
uiBlock *block;
int xco=0;
block= uiBeginBlock(C, ar, __func__, UI_EMBOSSP);
uiBlockSetButmFunc(block, do_actuator_menu, NULL);
uiDefBut(block, BUTM, 1, "Show Objects", 0, (short)(xco-=20), 160, 19, NULL, 0.0, 0.0, 1, 0, "");
uiDefBut(block, BUTM, 1, "Hide Objects", 0, (short)(xco-=20), 160, 19, NULL, 0.0, 0.0, 1, 1, "");
uiDefBut(block, SEPR, 0, "", 0, (short)(xco-=6), 160, 6, NULL, 0.0, 0.0, 0, 0, "");
uiDefBut(block, BUTM, 1, "Show Actuators", 0, (short)(xco-=20), 160, 19, NULL, 0.0, 0.0, 1, 2, "");
uiDefBut(block, BUTM, 1, "Hide Actuators", 0, (short)(xco-=20), 160, 19, NULL, 0.0, 0.0, 1, 3, "");
uiBlockSetDirection(block, UI_TOP);
uiEndBlock(C, block);
return block;
}
static void check_controller_state_mask(bContext *UNUSED(C), void *arg1_but, void *arg2_mask)
{
unsigned int *cont_mask = arg2_mask;
uiBut *but = arg1_but;
/* a controller is always in a single state */
*cont_mask = (1<<but->retval);
but->retval = B_REDR;
}
static uiBlock *controller_state_mask_menu(bContext *C, ARegion *ar, void *arg_cont)
{
uiBlock *block;
uiBut *but;
bController *cont = arg_cont;
short yco = 12, xco = 0, stbit, offset;
block= uiBeginBlock(C, ar, __func__, UI_EMBOSS);
/* use this for a fake extra empy space around the buttons */
uiDefBut(block, LABEL, 0, "", -5, -5, 200, 34, NULL, 0, 0, 0, 0, "");
for (offset=0; offset<15; offset+=5) {
uiBlockBeginAlign(block);
for (stbit=0; stbit<5; stbit++) {
but = uiDefButBitI(block, TOG, (1<<(stbit+offset)), (stbit+offset), "", (short)(xco+12*stbit+13*offset), yco, 12, 12, (int *)&(cont->state_mask), 0, 0, 0, 0, "");
uiButSetFunc(but, check_controller_state_mask, but, &(cont->state_mask));
}
for (stbit=0; stbit<5; stbit++) {
but = uiDefButBitI(block, TOG, (1<<(stbit+offset+15)), (stbit+offset+15), "", (short)(xco+12*stbit+13*offset), yco-12, 12, 12, (int *)&(cont->state_mask), 0, 0, 0, 0, "");
uiButSetFunc(but, check_controller_state_mask, but, &(cont->state_mask));
}
}
uiBlockEndAlign(block);
uiBlockSetDirection(block, UI_TOP);
uiEndBlock(C, block);
return block;
}
static int is_sensor_linked(uiBlock *block, bSensor *sens)
{
bController *cont;
int i;
for (i=0; i<sens->totlinks; i++) {
cont = sens->links[i];
if (uiFindInlink(block, cont) != NULL)
return 1;
}
return 0;
}
/* Sensors code */
static void draw_sensor_header(uiLayout *layout, PointerRNA *ptr, PointerRNA *logic_ptr)
{
uiLayout *box, *row, *sub;
bSensor *sens= (bSensor *)ptr->data;
box = uiLayoutBox(layout);
row = uiLayoutRow(box, FALSE);
uiItemR(row, ptr, "show_expanded", UI_ITEM_R_NO_BG, "", ICON_NONE);
if (RNA_boolean_get(ptr, "show_expanded")) {
uiItemR(row, ptr, "type", 0, "", ICON_NONE);
uiItemR(row, ptr, "name", 0, "", ICON_NONE);
}
else {
uiItemL(row, sensor_name(sens->type), ICON_NONE);
uiItemL(row, sens->name, ICON_NONE);
}
sub = uiLayoutRow(row, FALSE);
uiLayoutSetActive(sub, ((RNA_boolean_get(logic_ptr, "show_sensors_active_states") &&
RNA_boolean_get(ptr, "show_expanded")) || RNA_boolean_get(ptr, "pin")));
uiItemR(sub, ptr, "pin", UI_ITEM_R_NO_BG, "", ICON_NONE);
if (RNA_boolean_get(ptr, "show_expanded")==0) {
sub = uiLayoutRow(row, TRUE);
uiItemEnumO(sub, "LOGIC_OT_sensor_move", "", ICON_TRIA_UP, "direction", 1); // up
uiItemEnumO(sub, "LOGIC_OT_sensor_move", "", ICON_TRIA_DOWN, "direction", 2); // down
}
uiItemO(row, "", ICON_X, "LOGIC_OT_sensor_remove");
}
static void draw_sensor_internal_header(uiLayout *layout, PointerRNA *ptr)
{
uiLayout *box, *split, *sub, *row;
box = uiLayoutBox(layout);
split = uiLayoutSplit(box, 0.45f, FALSE);
row = uiLayoutRow(split, TRUE);
uiItemR(row, ptr, "use_pulse_true_level", 0, "", ICON_DOTSUP);
uiItemR(row, ptr, "use_pulse_false_level", 0, "", ICON_DOTSDOWN);
sub = uiLayoutRow(row, FALSE);
uiLayoutSetActive(sub, (RNA_boolean_get(ptr, "use_pulse_true_level") ||
RNA_boolean_get(ptr, "use_pulse_false_level")));
uiItemR(sub, ptr, "frequency", 0, "Freq", ICON_NONE);
row = uiLayoutRow(split, TRUE);
uiItemR(row, ptr, "use_level", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
uiItemR(row, ptr, "use_tap", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
uiItemR(split, ptr, "invert", UI_ITEM_R_TOGGLE, "Invert", ICON_NONE);
}
/* sensors in alphabetical order */
static void draw_sensor_actuator(uiLayout *layout, PointerRNA *ptr)
{
Object *ob = (Object *)ptr->id.data;
PointerRNA settings_ptr;
RNA_pointer_create((ID *)ob, &RNA_GameObjectSettings, ob, &settings_ptr);
uiItemPointerR(layout, ptr, "actuator", &settings_ptr, "actuators", NULL, ICON_LOGIC);
}
static void draw_sensor_armature(uiLayout *layout, PointerRNA *ptr)
{
bSensor *sens = (bSensor*)ptr->data;
bArmatureSensor *as = (bArmatureSensor *) sens->data;
Object *ob = (Object *)ptr->id.data;
PointerRNA pose_ptr, pchan_ptr;
PropertyRNA *bones_prop= NULL;
uiLayout *row;
if (ob->type != OB_ARMATURE) {
uiItemL(layout, "Sensor only available for armatures", ICON_NONE);
return;
}
if (ob->pose) {
RNA_pointer_create((ID *)ob, &RNA_Pose, ob->pose, &pose_ptr);
bones_prop = RNA_struct_find_property(&pose_ptr, "bones");
}
if (&pose_ptr.data) {
uiItemPointerR(layout, ptr, "bone", &pose_ptr, "bones", NULL, ICON_BONE_DATA);
if (RNA_property_collection_lookup_string(&pose_ptr, bones_prop, as->posechannel, &pchan_ptr))
uiItemPointerR(layout, ptr, "constraint", &pchan_ptr, "constraints", NULL, ICON_CONSTRAINT_BONE);
}
row = uiLayoutRow(layout, TRUE);
uiItemR(row, ptr, "test_type", 0, NULL, ICON_NONE);
if (RNA_enum_get(ptr, "test_type") != SENS_ARM_STATE_CHANGED)
uiItemR(row, ptr, "value", 0, NULL, ICON_NONE);
}
static void draw_sensor_collision(uiLayout *layout, PointerRNA *ptr, bContext *C)
{
uiLayout *row, *split;
PointerRNA main_ptr;
RNA_main_pointer_create(CTX_data_main(C), &main_ptr);
split = uiLayoutSplit(layout, 0.3f, FALSE);
row = uiLayoutRow(split, TRUE);
uiItemR(row, ptr, "use_pulse", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
uiItemR(row, ptr, "use_material", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
switch (RNA_boolean_get(ptr, "use_material")) {
case SENS_COLLISION_PROPERTY:
uiItemR(split, ptr, "property", 0, NULL, ICON_NONE);
break;
case SENS_COLLISION_MATERIAL:
uiItemPointerR(split, ptr, "material", &main_ptr, "materials", NULL, ICON_MATERIAL_DATA);
break;
}
}
static void draw_sensor_delay(uiLayout *layout, PointerRNA *ptr)
{
uiLayout *row;
row = uiLayoutRow(layout, FALSE);
uiItemR(row, ptr, "delay", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "duration", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "use_repeat", 0, NULL, ICON_NONE);
}
static void draw_sensor_joystick(uiLayout *layout, PointerRNA *ptr)
{
uiLayout *col, *row;
uiItemR(layout, ptr, "joystick_index", 0, NULL, ICON_NONE);
uiItemR(layout, ptr, "event_type", 0, NULL, ICON_NONE);
switch (RNA_enum_get(ptr, "event_type")) {
case SENS_JOY_BUTTON:
uiItemR(layout, ptr, "use_all_events", 0, NULL, ICON_NONE);
col = uiLayoutColumn(layout, FALSE);
uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_all_events") == FALSE);
uiItemR(col, ptr, "button_number", 0, NULL, ICON_NONE);
break;
case SENS_JOY_AXIS:
row = uiLayoutRow(layout, FALSE);
uiItemR(row, ptr, "axis_number", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "axis_threshold", 0, NULL, ICON_NONE);
uiItemR(layout, ptr, "use_all_events", 0, NULL, ICON_NONE);
col = uiLayoutColumn(layout, FALSE);
uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_all_events") == FALSE);
uiItemR(col, ptr, "axis_direction", 0, NULL, ICON_NONE);
break;
case SENS_JOY_HAT:
uiItemR(layout, ptr, "hat_number", 0, NULL, ICON_NONE);
uiItemR(layout, ptr, "use_all_events", 0, NULL, ICON_NONE);
col = uiLayoutColumn(layout, FALSE);
uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_all_events") == FALSE);
uiItemR(col, ptr, "hat_direction", 0, NULL, ICON_NONE);
break;
case SENS_JOY_AXIS_SINGLE:
row = uiLayoutRow(layout, FALSE);
uiItemR(row, ptr, "single_axis_number", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "axis_threshold", 0, NULL, ICON_NONE);
break;
}
}
static void draw_sensor_keyboard(uiLayout *layout, PointerRNA *ptr)
{
Object *ob = (Object *)ptr->id.data;
PointerRNA settings_ptr;
uiLayout *row, *col;
row = uiLayoutRow(layout, FALSE);
uiItemL(row, "Key:", ICON_NONE);
col = uiLayoutColumn(row, FALSE);
uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_all_keys") == FALSE);
uiItemR(col, ptr, "key", UI_ITEM_R_EVENT, "", ICON_NONE);
col = uiLayoutColumn(row, FALSE);
uiItemR(col, ptr, "use_all_keys", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
col = uiLayoutColumn(layout, FALSE);
uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_all_keys") == FALSE);
row = uiLayoutRow(col, FALSE);
uiItemL(row, "First Modifier:", ICON_NONE);
uiItemR(row, ptr, "modifier_key_1", UI_ITEM_R_EVENT, "", ICON_NONE);
row = uiLayoutRow(col, FALSE);
uiItemL(row, "Second Modifier:", ICON_NONE);
uiItemR(row, ptr, "modifier_key_2", UI_ITEM_R_EVENT, "", ICON_NONE);
RNA_pointer_create((ID *)ob, &RNA_GameObjectSettings, ob, &settings_ptr);
uiItemPointerR(layout, ptr, "log", &settings_ptr, "properties", NULL, ICON_NONE);
uiItemPointerR(layout, ptr, "target", &settings_ptr, "properties", NULL, ICON_NONE);
}
static void draw_sensor_message(uiLayout *layout, PointerRNA *ptr)
{
uiItemR(layout, ptr, "subject", 0, NULL, ICON_NONE);
}
static void draw_sensor_mouse(uiLayout *layout, PointerRNA *ptr)
{
uiLayout *split;
split = uiLayoutSplit(layout, 0.8f, FALSE);
uiItemR(split, ptr, "mouse_event", 0, NULL, ICON_NONE);
if (RNA_enum_get(ptr, "mouse_event") == BL_SENS_MOUSE_MOUSEOVER_ANY)
uiItemR(split, ptr, "use_pulse", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
}
static void draw_sensor_near(uiLayout *layout, PointerRNA *ptr)
{
uiLayout *row;
uiItemR(layout, ptr, "property", 0, NULL, ICON_NONE);
row = uiLayoutRow(layout, TRUE);
uiItemR(row, ptr, "distance", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "reset_distance", 0, NULL, ICON_NONE);
}
static void draw_sensor_property(uiLayout *layout, PointerRNA *ptr)
{
Object *ob = (Object *)ptr->id.data;
PointerRNA settings_ptr;
uiLayout *row;
uiItemR(layout, ptr, "evaluation_type", 0, NULL, ICON_NONE);
RNA_pointer_create((ID *)ob, &RNA_GameObjectSettings, ob, &settings_ptr);
uiItemPointerR(layout, ptr, "property", &settings_ptr, "properties", NULL, ICON_NONE);
switch (RNA_enum_get(ptr, "evaluation_type")) {
case SENS_PROP_INTERVAL:
row = uiLayoutRow(layout, FALSE);
uiItemR(row, ptr, "value_min", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "value_max", 0, NULL, ICON_NONE);
break;
case SENS_PROP_EQUAL:
uiItemR(layout, ptr, "value", 0, NULL, ICON_NONE);
break;
case SENS_PROP_NEQUAL:
uiItemR(layout, ptr, "value", 0, NULL, ICON_NONE);
break;
case SENS_PROP_CHANGED:
break;
}
}
static void draw_sensor_radar(uiLayout *layout, PointerRNA *ptr)
{
uiLayout *row;
uiItemR(layout, ptr, "property", 0, NULL, ICON_NONE);
uiItemR(layout, ptr, "axis", 0, NULL, ICON_NONE);
row = uiLayoutRow(layout, FALSE);
uiItemR(row, ptr, "angle", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "distance", 0, NULL, ICON_NONE);
}
static void draw_sensor_random(uiLayout *layout, PointerRNA *ptr)
{
uiItemR(layout, ptr, "seed", 0, NULL, ICON_NONE);
}
static void draw_sensor_ray(uiLayout *layout, PointerRNA *ptr, bContext *C)
{
uiLayout *split, *row;
PointerRNA main_ptr;
RNA_main_pointer_create(CTX_data_main(C), &main_ptr);
split = uiLayoutSplit(layout, 0.3f, FALSE);
uiItemR(split, ptr, "ray_type", 0, "", ICON_NONE);
switch (RNA_enum_get(ptr, "ray_type")) {
case SENS_RAY_PROPERTY:
uiItemR(split, ptr, "property", 0, "", ICON_NONE);
break;
case SENS_RAY_MATERIAL:
uiItemPointerR(split, ptr, "material", &main_ptr, "materials", "", ICON_MATERIAL_DATA);
break;
}
split = uiLayoutSplit(layout, 0.3, FALSE);
uiItemR(split, ptr, "axis", 0, "", ICON_NONE);
row = uiLayoutRow(split, FALSE);
uiItemR(row, ptr, "range", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "use_x_ray", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
}
static void draw_sensor_touch(uiLayout *layout, PointerRNA *ptr)
{
uiItemR(layout, ptr, "material", 0, NULL, ICON_NONE);
}
static void draw_brick_sensor(uiLayout *layout, PointerRNA *ptr, bContext *C)
{
uiLayout *box;
if (!RNA_boolean_get(ptr, "show_expanded"))
return;
draw_sensor_internal_header(layout, ptr);
box = uiLayoutBox(layout);
switch (RNA_enum_get(ptr, "type")) {
case SENS_ACTUATOR:
draw_sensor_actuator(box, ptr);
break;
case SENS_ALWAYS:
break;
case SENS_ARMATURE:
draw_sensor_armature(box, ptr);
break;
case SENS_COLLISION:
draw_sensor_collision(box, ptr, C);
break;
case SENS_DELAY:
draw_sensor_delay(box, ptr);
break;
case SENS_JOYSTICK:
draw_sensor_joystick(box, ptr);
break;
case SENS_KEYBOARD:
draw_sensor_keyboard(box, ptr);
break;
case SENS_MESSAGE:
draw_sensor_message(box, ptr);
break;
case SENS_MOUSE:
draw_sensor_mouse(box, ptr);
break;
case SENS_NEAR:
draw_sensor_near(box, ptr);
break;
case SENS_PROPERTY:
draw_sensor_property(box, ptr);
break;
case SENS_RADAR:
draw_sensor_radar(box, ptr);
break;
case SENS_RANDOM:
draw_sensor_random(box, ptr);
break;
case SENS_RAY:
draw_sensor_ray(box, ptr, C);
break;
case SENS_TOUCH:
draw_sensor_touch(box, ptr);
break;
}
}
/* Controller code */
static void draw_controller_header(uiLayout *layout, PointerRNA *ptr, int xco, int width, int yco)
{
uiLayout *box, *row, *sub;
bController *cont= (bController *)ptr->data;
char state[3];
BLI_snprintf(state, sizeof(state), "%d", RNA_int_get(ptr, "states"));
box = uiLayoutBox(layout);
row = uiLayoutRow(box, FALSE);
uiItemR(row, ptr, "show_expanded", UI_ITEM_R_NO_BG, "", ICON_NONE);
if (RNA_boolean_get(ptr, "show_expanded")) {
uiItemR(row, ptr, "type", 0, "", ICON_NONE);
uiItemR(row, ptr, "name", 0, "", ICON_NONE);
/* XXX provisory for Blender 2.50Beta */
uiDefBlockBut(uiLayoutGetBlock(layout), controller_state_mask_menu, cont, state, (short)(xco+width-44), yco, 22+22, UI_UNIT_Y, "Set controller state index (from 1 to 30)");
}
else {
uiItemL(row, controller_name(cont->type), ICON_NONE);
uiItemL(row, cont->name, ICON_NONE);
uiItemL(row, state, ICON_NONE);
}
uiItemR(row, ptr, "use_priority", 0, "", ICON_NONE);
if (RNA_boolean_get(ptr, "show_expanded")==0) {
sub = uiLayoutRow(row, TRUE);
uiItemEnumO(sub, "LOGIC_OT_controller_move", "", ICON_TRIA_UP, "direction", 1); // up
uiItemEnumO(sub, "LOGIC_OT_controller_move", "", ICON_TRIA_DOWN, "direction", 2); // down
}
uiItemO(row, "", ICON_X, "LOGIC_OT_controller_remove");
}
static void draw_controller_expression(uiLayout *layout, PointerRNA *ptr)
{
uiItemR(layout, ptr, "expression", 0, "", ICON_NONE);
}
static void draw_controller_python(uiLayout *layout, PointerRNA *ptr)
{
uiLayout *split, *sub;
split = uiLayoutSplit(layout, 0.3, TRUE);
uiItemR(split, ptr, "mode", 0, "", ICON_NONE);
if (RNA_enum_get(ptr, "mode") == CONT_PY_SCRIPT) {
uiItemR(split, ptr, "text", 0, "", ICON_NONE);
}
else {
sub = uiLayoutSplit(split, 0.8f, FALSE);
uiItemR(sub, ptr, "module", 0, "", ICON_NONE);
uiItemR(sub, ptr, "use_debug", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
}
}
static void draw_controller_state(uiLayout *UNUSED(layout), PointerRNA *UNUSED(ptr))
{
}
static void draw_brick_controller(uiLayout *layout, PointerRNA *ptr)
{
uiLayout *box;
if (!RNA_boolean_get(ptr, "show_expanded"))
return;
box = uiLayoutBox(layout);
draw_controller_state(box, ptr);
switch (RNA_enum_get(ptr, "type")) {
case CONT_LOGIC_AND:
break;
case CONT_LOGIC_OR:
break;
case CONT_EXPRESSION:
draw_controller_expression(box, ptr);
break;
case CONT_PYTHON:
draw_controller_python(box, ptr);
break;
case CONT_LOGIC_NAND:
break;
case CONT_LOGIC_NOR:
break;
case CONT_LOGIC_XOR:
break;
case CONT_LOGIC_XNOR:
break;
}
}
/* Actuator code */
static void draw_actuator_header(uiLayout *layout, PointerRNA *ptr, PointerRNA *logic_ptr)
{
uiLayout *box, *row, *sub;
bActuator *act= (bActuator *)ptr->data;
box = uiLayoutBox(layout);
row = uiLayoutRow(box, FALSE);
uiItemR(row, ptr, "show_expanded", UI_ITEM_R_NO_BG, "", ICON_NONE);
if (RNA_boolean_get(ptr, "show_expanded")) {
uiItemR(row, ptr, "type", 0, "", ICON_NONE);
uiItemR(row, ptr, "name", 0, "", ICON_NONE);
}
else {
uiItemL(row, actuator_name(act->type), ICON_NONE);
uiItemL(row, act->name, ICON_NONE);
}
sub = uiLayoutRow(row, FALSE);
uiLayoutSetActive(sub, ((RNA_boolean_get(logic_ptr, "show_actuators_active_states") &&
RNA_boolean_get(ptr, "show_expanded")) || RNA_boolean_get(ptr, "pin")));
uiItemR(sub, ptr, "pin", UI_ITEM_R_NO_BG, "", ICON_NONE);
if (RNA_boolean_get(ptr, "show_expanded")==0) {
sub = uiLayoutRow(row, TRUE);
uiItemEnumO(sub, "LOGIC_OT_actuator_move", "", ICON_TRIA_UP, "direction", 1); // up
uiItemEnumO(sub, "LOGIC_OT_actuator_move", "", ICON_TRIA_DOWN, "direction", 2); // down
}
uiItemO(row, "", ICON_X, "LOGIC_OT_actuator_remove");
}
static void draw_actuator_action(uiLayout *layout, PointerRNA *ptr)
{
Object *ob = (Object *)ptr->id.data;
PointerRNA settings_ptr;
uiLayout *row, *sub;
RNA_pointer_create((ID *)ob, &RNA_GameObjectSettings, ob, &settings_ptr);
row = uiLayoutRow(layout, FALSE);
uiItemR(row, ptr, "play_mode", 0, "", ICON_NONE);
sub = uiLayoutRow(row, TRUE);
uiItemR(sub, ptr, "use_force", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
uiItemR(sub, ptr, "use_additive", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
row = uiLayoutColumn(sub, FALSE);
uiLayoutSetActive(row, (RNA_boolean_get(ptr, "use_additive") || RNA_boolean_get(ptr, "use_force")));
uiItemR(row, ptr, "use_local", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
row = uiLayoutRow(layout, FALSE);
uiItemR(row, ptr, "action", 0, "", ICON_NONE);
uiItemR(row, ptr, "use_continue_last_frame", 0, NULL, ICON_NONE);
row = uiLayoutRow(layout, FALSE);
if ((RNA_enum_get(ptr, "play_mode") == ACT_ACTION_FROM_PROP))
uiItemPointerR(row, ptr, "property", &settings_ptr, "properties", NULL, ICON_NONE);
else {
uiItemR(row, ptr, "frame_start", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "frame_end", 0, NULL, ICON_NONE);
}
uiItemR(row, ptr, "apply_to_children", 0, NULL, ICON_NONE);
row = uiLayoutRow(layout, FALSE);
uiItemR(row, ptr, "frame_blend_in", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "priority", 0, NULL, ICON_NONE);
row = uiLayoutRow(layout, FALSE);
uiItemR(row, ptr, "layer", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "layer_weight", 0, NULL, ICON_NONE);
uiItemPointerR(layout, ptr, "frame_property", &settings_ptr, "properties", NULL, ICON_NONE);
#ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
uiItemR(layout, "stride_length", 0, NULL, ICON_NONE);
#endif
}
static void draw_actuator_armature(uiLayout *layout, PointerRNA *ptr)
{
bActuator *act = (bActuator*)ptr->data;
bArmatureActuator *aa = (bArmatureActuator *) act->data;
Object *ob = (Object *)ptr->id.data;
bConstraint *constraint = NULL;
PointerRNA pose_ptr, pchan_ptr;
PropertyRNA *bones_prop = NULL;
if (ob->type != OB_ARMATURE) {
uiItemL(layout, "Actuator only available for armatures", ICON_NONE);
return;
}
if (ob->pose) {
RNA_pointer_create((ID *)ob, &RNA_Pose, ob->pose, &pose_ptr);
bones_prop = RNA_struct_find_property(&pose_ptr, "bones");
}
uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE);
switch (RNA_enum_get(ptr, "mode")) {
case ACT_ARM_RUN:
break;
case ACT_ARM_ENABLE:
case ACT_ARM_DISABLE:
if (ob->pose) {
uiItemPointerR(layout, ptr, "bone", &pose_ptr, "bones", NULL, ICON_BONE_DATA);
if (RNA_property_collection_lookup_string(&pose_ptr, bones_prop, aa->posechannel, &pchan_ptr))
uiItemPointerR(layout, ptr, "constraint", &pchan_ptr, "constraints", NULL, ICON_CONSTRAINT_BONE);
}
break;
case ACT_ARM_SETTARGET:
if (ob->pose) {
uiItemPointerR(layout, ptr, "bone", &pose_ptr, "bones", NULL, ICON_BONE_DATA);
if (RNA_property_collection_lookup_string(&pose_ptr, bones_prop, aa->posechannel, &pchan_ptr))
uiItemPointerR(layout, ptr, "constraint", &pchan_ptr, "constraints", NULL, ICON_CONSTRAINT_BONE);
}
uiItemR(layout, ptr, "target", 0, NULL, ICON_NONE);
/* show second target only if the constraint supports it */
get_armature_bone_constraint(ob, aa->posechannel, aa->constraint, &constraint);
if (constraint && constraint->type == CONSTRAINT_TYPE_KINEMATIC) {
uiItemR(layout, ptr, "secondary_target", 0, NULL, ICON_NONE);
}
break;
case ACT_ARM_SETWEIGHT:
if (ob->pose) {
uiItemPointerR(layout, ptr, "bone", &pose_ptr, "bones", NULL, ICON_BONE_DATA);
if (RNA_property_collection_lookup_string(&pose_ptr, bones_prop, aa->posechannel, &pchan_ptr))
uiItemPointerR(layout, ptr, "constraint", &pchan_ptr, "constraints", NULL, ICON_CONSTRAINT_BONE);
}
uiItemR(layout, ptr, "weight", 0, NULL, ICON_NONE);
break;
case ACT_ARM_SETINFLUENCE:
if (ob->pose) {
uiItemPointerR(layout, ptr, "bone", &pose_ptr, "bones", NULL, ICON_BONE_DATA);
if (RNA_property_collection_lookup_string(&pose_ptr, bones_prop, aa->posechannel, &pchan_ptr))
uiItemPointerR(layout, ptr, "constraint", &pchan_ptr, "constraints", NULL, ICON_CONSTRAINT_BONE);
}
uiItemR(layout, ptr, "influence", 0, NULL, ICON_NONE);
break;
}
}
static void draw_actuator_camera(uiLayout *layout, PointerRNA *ptr)
{
uiLayout *row;
uiItemR(layout, ptr, "object", 0, NULL, ICON_NONE);
row = uiLayoutRow(layout, FALSE);
uiItemR(row, ptr, "height", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "axis", 0, NULL, ICON_NONE);
row = uiLayoutRow(layout, TRUE);
uiItemR(row, ptr, "min", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "max", 0, NULL, ICON_NONE);
uiItemR(layout, ptr, "damping", 0, NULL, ICON_NONE);
}
static void draw_actuator_constraint(uiLayout *layout, PointerRNA *ptr, bContext *C)
{
uiLayout *row, *col, *sub, *split;
PointerRNA main_ptr;
RNA_main_pointer_create(CTX_data_main(C), &main_ptr);
uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE);
switch (RNA_enum_get(ptr, "mode")) {
case ACT_CONST_TYPE_LOC:
uiItemR(layout, ptr, "limit", 0, NULL, ICON_NONE);
row = uiLayoutRow(layout, TRUE);
uiItemR(row, ptr, "limit_min", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "limit_max", 0, NULL, ICON_NONE);
uiItemR(layout, ptr, "damping", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
break;
case ACT_CONST_TYPE_DIST:
split = uiLayoutSplit(layout, 0.8, FALSE);
uiItemR(split, ptr, "direction", 0, NULL, ICON_NONE);
row = uiLayoutRow(split, TRUE);
uiItemR(row, ptr, "use_local", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
uiItemR(row, ptr, "use_normal", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
row = uiLayoutRow(layout, FALSE);
col = uiLayoutColumn(row, TRUE);
uiItemL(col, "Range:", ICON_NONE);
uiItemR(col, ptr, "range", 0, "", ICON_NONE);
col = uiLayoutColumn(row, TRUE);
uiItemR(col, ptr, "use_force_distance", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
sub = uiLayoutColumn(col, FALSE);
uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_force_distance") == TRUE);
uiItemR(sub, ptr, "distance", 0, "", ICON_NONE);
uiItemR(layout, ptr, "damping", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
split = uiLayoutSplit(layout, 0.15f, FALSE);
uiItemR(split, ptr, "use_material_detect", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
if (RNA_boolean_get(ptr, "use_material_detect"))
uiItemPointerR(split, ptr, "material", &main_ptr, "materials", NULL, ICON_MATERIAL_DATA);
else
uiItemR(split, ptr, "property", 0, NULL, ICON_NONE);
split = uiLayoutSplit(layout, 0.15, FALSE);
uiItemR(split, ptr, "use_persistent", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
row = uiLayoutRow(split, TRUE);
uiItemR(row, ptr, "time", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "damping_rotation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
break;
case ACT_CONST_TYPE_ORI:
uiItemR(layout, ptr, "direction_axis_pos", 0, NULL, ICON_NONE);
row=uiLayoutRow(layout, TRUE);
uiItemR(row, ptr, "damping", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
uiItemR(row, ptr, "time", 0, NULL, ICON_NONE);
row=uiLayoutRow(layout, FALSE);
uiItemR(row, ptr, "rotation_max", 0, NULL, ICON_NONE);
row=uiLayoutRow(layout, TRUE);
uiItemR(row, ptr, "angle_min", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "angle_max", 0, NULL, ICON_NONE);
break;
case ACT_CONST_TYPE_FH:
split = uiLayoutSplit(layout, 0.75, FALSE);
row = uiLayoutRow(split, FALSE);
uiItemR(row, ptr, "fh_damping", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
uiItemR(row, ptr, "fh_height", 0, NULL, ICON_NONE);
uiItemR(split, ptr, "use_fh_paralel_axis", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
row = uiLayoutRow(layout, FALSE);
uiItemR(row, ptr, "direction_axis", 0, NULL, ICON_NONE);
split = uiLayoutSplit(row, 0.9f, FALSE);
uiItemR(split, ptr, "fh_force", 0, NULL, ICON_NONE);
uiItemR(split, ptr, "use_fh_normal", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
split = uiLayoutSplit(layout, 0.15, FALSE);
uiItemR(split, ptr, "use_material_detect", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
if (RNA_boolean_get(ptr, "use_material_detect"))
uiItemPointerR(split, ptr, "material", &main_ptr, "materials", NULL, ICON_MATERIAL_DATA);
else
uiItemR(split, ptr, "property", 0, NULL, ICON_NONE);
split = uiLayoutSplit(layout, 0.15, FALSE);
uiItemR(split, ptr, "use_persistent", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
row = uiLayoutRow(split, FALSE);
uiItemR(row, ptr, "time", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "damping_rotation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
break;
}
}
static void draw_actuator_edit_object(uiLayout *layout, PointerRNA *ptr)
{
Object *ob = (Object *)ptr->id.data;
uiLayout *row, *split, *sub;
uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE);
switch (RNA_enum_get(ptr, "mode")) {
case ACT_EDOB_ADD_OBJECT:
row = uiLayoutRow(layout, FALSE);
uiItemR(row, ptr, "object", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "time", 0, NULL, ICON_NONE);
split = uiLayoutSplit(layout, 0.9, FALSE);
row = uiLayoutRow(split, FALSE);
uiItemR(row, ptr, "linear_velocity", 0, NULL, ICON_NONE);
uiItemR(split, ptr, "use_local_linear_velocity", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
split = uiLayoutSplit(layout, 0.9, FALSE);
row = uiLayoutRow(split, FALSE);
uiItemR(row, ptr, "angular_velocity", 0, NULL, ICON_NONE);
uiItemR(split, ptr, "use_local_angular_velocity", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
break;
case ACT_EDOB_END_OBJECT:
break;
case ACT_EDOB_REPLACE_MESH:
if (ob->type != OB_MESH) {
uiItemL(layout, "Mode only available for mesh objects", ICON_NONE);
break;
}
split = uiLayoutSplit(layout, 0.6, FALSE);
uiItemR(split, ptr, "mesh", 0, NULL, ICON_NONE);
row = uiLayoutRow(split, FALSE);
uiItemR(row, ptr, "use_replace_display_mesh", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
uiItemR(row, ptr, "use_replace_physics_mesh", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
break;
case ACT_EDOB_TRACK_TO:
split = uiLayoutSplit(layout, 0.5, FALSE);
uiItemR(split, ptr, "track_object", 0, NULL, ICON_NONE);
sub = uiLayoutSplit(split, 0.7f, FALSE);
uiItemR(sub, ptr, "time", 0, NULL, ICON_NONE);
uiItemR(sub, ptr, "use_3d_tracking", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
break;
case ACT_EDOB_DYNAMICS:
if (ob->type != OB_MESH) {
uiItemL(layout, "Mode only available for mesh objects", ICON_NONE);
break;
}
uiItemR(layout, ptr, "dynamic_operation", 0, NULL, ICON_NONE);
if (RNA_enum_get(ptr, "dynamic_operation") == ACT_EDOB_SET_MASS)
uiItemR(layout, ptr, "mass", 0, NULL, ICON_NONE);
break;
}
}
static void draw_actuator_filter_2d(uiLayout *layout, PointerRNA *ptr)
{
uiLayout *row, *split;
uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE);
switch (RNA_enum_get(ptr, "mode")) {
case ACT_2DFILTER_CUSTOMFILTER:
uiItemR(layout, ptr, "filter_pass", 0, NULL, ICON_NONE);
uiItemR(layout, ptr, "glsl_shader", 0, NULL, ICON_NONE);
break;
case ACT_2DFILTER_MOTIONBLUR:
split=uiLayoutSplit(layout, 0.75f, TRUE);
row = uiLayoutRow(split, FALSE);
uiLayoutSetActive(row, RNA_boolean_get(ptr, "use_motion_blur") == TRUE);
uiItemR(row, ptr, "motion_blur_factor", 0, NULL, ICON_NONE);
uiItemR(split, ptr, "use_motion_blur", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
break;
default: // all other 2D Filters
uiItemR(layout, ptr, "filter_pass", 0, NULL, ICON_NONE);
break;
}
}
static void draw_actuator_game(uiLayout *layout, PointerRNA *ptr)
{
uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE);
if (RNA_enum_get(ptr, "mode") == ACT_GAME_LOAD)
uiItemR(layout, ptr, "filename", 0, NULL, ICON_NONE);
}
static void draw_actuator_message(uiLayout *layout, PointerRNA *ptr, bContext *C)
{
Object *ob;
PointerRNA main_ptr, settings_ptr;
uiLayout *row;
RNA_main_pointer_create(CTX_data_main(C), &main_ptr);
ob = (Object *)ptr->id.data;
RNA_pointer_create((ID *)ob, &RNA_GameObjectSettings, ob, &settings_ptr);
uiItemPointerR(layout, ptr, "to_property", &main_ptr, "objects", NULL, ICON_OBJECT_DATA);
uiItemR(layout, ptr, "subject", 0, NULL, ICON_NONE);
row = uiLayoutRow(layout, TRUE);
uiItemR(row, ptr, "body_type", 0, NULL, ICON_NONE);
if (RNA_enum_get(ptr, "body_type") == ACT_MESG_MESG)
uiItemR(row, ptr, "body_message", 0, "", ICON_NONE);
else // mode == ACT_MESG_PROP
uiItemPointerR(row, ptr, "body_property", &settings_ptr, "properties", "", ICON_NONE);
}
static void draw_actuator_motion(uiLayout *layout, PointerRNA *ptr)
{
Object *ob;
PointerRNA settings_ptr;
uiLayout *split, *row, *col, *sub;
int physics_type;
ob = (Object *)ptr->id.data;
RNA_pointer_create((ID *)ob, &RNA_GameObjectSettings, ob, &settings_ptr);
physics_type = RNA_enum_get(&settings_ptr, "physics_type");
uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE);
switch (RNA_enum_get(ptr, "mode")) {
case ACT_OBJECT_NORMAL:
split = uiLayoutSplit(layout, 0.9, FALSE);
row = uiLayoutRow(split, FALSE);
uiItemR(row, ptr, "offset_location", 0, NULL, ICON_NONE);
uiItemR(split, ptr, "use_local_location", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
split = uiLayoutSplit(layout, 0.9, FALSE);
row = uiLayoutRow(split, FALSE);
uiItemR(row, ptr, "offset_rotation", 0, NULL, ICON_NONE);
uiItemR(split, ptr, "use_local_rotation", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
if (ELEM3(physics_type, OB_BODY_TYPE_DYNAMIC, OB_BODY_TYPE_RIGID, OB_BODY_TYPE_SOFT)) {
uiItemL(layout, "Dynamic Object Settings:", ICON_NONE);
split = uiLayoutSplit(layout, 0.9, FALSE);
row = uiLayoutRow(split, FALSE);
uiItemR(row, ptr, "force", 0, NULL, ICON_NONE);
uiItemR(split, ptr, "use_local_force", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
split = uiLayoutSplit(layout, 0.9, FALSE);
row = uiLayoutRow(split, FALSE);
uiItemR(row, ptr, "torque", 0, NULL, ICON_NONE);
uiItemR(split, ptr, "use_local_torque", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
split = uiLayoutSplit(layout, 0.9, FALSE);
row = uiLayoutRow(split, FALSE);
uiItemR(row, ptr, "linear_velocity", 0, NULL, ICON_NONE);
row = uiLayoutRow(split, TRUE);
uiItemR(row, ptr, "use_local_linear_velocity", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
uiItemR(row, ptr, "use_add_linear_velocity", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
split = uiLayoutSplit(layout, 0.9, FALSE);
row = uiLayoutRow(split, FALSE);
uiItemR(row, ptr, "angular_velocity", 0, NULL, ICON_NONE);
uiItemR(split, ptr, "use_local_angular_velocity", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
uiItemR(layout, ptr, "damping", 0, NULL, ICON_NONE);
}
break;
case ACT_OBJECT_SERVO:
uiItemR(layout, ptr, "reference_object", 0, NULL, ICON_NONE);
split = uiLayoutSplit(layout, 0.9, FALSE);
row = uiLayoutRow(split, FALSE);
uiItemR(row, ptr, "linear_velocity", 0, NULL, ICON_NONE);
uiItemR(split, ptr, "use_local_linear_velocity", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
row = uiLayoutRow(layout, FALSE);
col = uiLayoutColumn(row, FALSE);
uiItemR(col, ptr, "use_servo_limit_x", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
sub = uiLayoutColumn(col, TRUE);
uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_servo_limit_x") == TRUE);
uiItemR(sub, ptr, "force_max_x", 0, NULL, ICON_NONE);
uiItemR(sub, ptr, "force_min_x", 0, NULL, ICON_NONE);
col = uiLayoutColumn(row, FALSE);
uiItemR(col, ptr, "use_servo_limit_y", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
sub = uiLayoutColumn(col, TRUE);
uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_servo_limit_y") == TRUE);
uiItemR(sub, ptr, "force_max_y", 0, NULL, ICON_NONE);
uiItemR(sub, ptr, "force_min_y", 0, NULL, ICON_NONE);
col = uiLayoutColumn(row, FALSE);
uiItemR(col, ptr, "use_servo_limit_z", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
sub = uiLayoutColumn(col, TRUE);
uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_servo_limit_z") == TRUE);
uiItemR(sub, ptr, "force_max_z", 0, NULL, ICON_NONE);
uiItemR(sub, ptr, "force_min_z", 0, NULL, ICON_NONE);
//XXXACTUATOR missing labels from original 2.49 ui (e.g. Servo, Min, Max, Fast)
//Layout designers willing to help on that, please compare with 2.49 ui
// (since the old code is going to be deleted ... soon)
col = uiLayoutColumn(layout, TRUE);
uiItemR(col, ptr, "proportional_coefficient", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
uiItemR(col, ptr, "integral_coefficient", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
uiItemR(col, ptr, "derivate_coefficient", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
break;
}
}
static void draw_actuator_parent(uiLayout *layout, PointerRNA *ptr)
{
uiLayout *row, *sub;
uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE);
if (RNA_enum_get(ptr, "mode") == ACT_PARENT_SET) {
uiItemR(layout, ptr, "object", 0, NULL, ICON_NONE);
row = uiLayoutRow(layout, FALSE);
uiItemR(row, ptr, "use_compound", 0, NULL, ICON_NONE);
sub = uiLayoutRow(row, FALSE);
uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_compound") == TRUE);
uiItemR(sub, ptr, "use_ghost", 0, NULL, ICON_NONE);
}
}
static void draw_actuator_property(uiLayout *layout, PointerRNA *ptr)
{
Object *ob = (Object *)ptr->id.data;
bActuator *act = (bActuator *)ptr->data;
bPropertyActuator *pa = (bPropertyActuator *) act->data;
Object *ob_from= pa->ob;
PointerRNA settings_ptr, obj_settings_ptr;
uiLayout *row, *sub;
RNA_pointer_create((ID *)ob, &RNA_GameObjectSettings, ob, &settings_ptr);
uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE);
uiItemPointerR(layout, ptr, "property", &settings_ptr, "properties", NULL, ICON_NONE);
switch (RNA_enum_get(ptr, "mode")) {
case ACT_PROP_TOGGLE:
break;
case ACT_PROP_ADD:
uiItemR(layout, ptr, "value", 0, NULL, ICON_NONE);
break;
case ACT_PROP_ASSIGN:
uiItemR(layout, ptr, "value", 0, NULL, ICON_NONE);
break;
case ACT_PROP_COPY:
row = uiLayoutRow(layout, FALSE);
uiItemR(row, ptr, "object", 0, NULL, ICON_NONE);
if (ob_from) {
RNA_pointer_create((ID *)ob_from, &RNA_GameObjectSettings, ob_from, &obj_settings_ptr);
uiItemPointerR(row, ptr, "object_property", &obj_settings_ptr, "properties", NULL, ICON_NONE);
}
else {
sub = uiLayoutRow(row, FALSE);
uiLayoutSetActive(sub, FALSE);
uiItemR(sub, ptr, "object_property", 0, NULL, ICON_NONE);
}
break;
}
}
static void draw_actuator_random(uiLayout *layout, PointerRNA *ptr)
{
Object *ob;
PointerRNA settings_ptr;
uiLayout *row;
ob = (Object *)ptr->id.data;
RNA_pointer_create((ID *)ob, &RNA_GameObjectSettings, ob, &settings_ptr);
row = uiLayoutRow(layout, FALSE);
uiItemR(row, ptr, "seed", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "distribution", 0, NULL, ICON_NONE);
row = uiLayoutRow(layout, FALSE);
uiItemPointerR(row, ptr, "property", &settings_ptr, "properties", NULL, ICON_NONE);
row = uiLayoutRow(layout, FALSE);
switch (RNA_enum_get(ptr, "distribution")) {
case ACT_RANDOM_BOOL_CONST:
uiItemR(row, ptr, "use_always_true", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
break;
case ACT_RANDOM_BOOL_UNIFORM:
uiItemL(row, "Choose between true and false, 50% chance each", ICON_NONE);
break;
case ACT_RANDOM_BOOL_BERNOUILLI:
uiItemR(row, ptr, "chance", 0, NULL, ICON_NONE);
break;
case ACT_RANDOM_INT_CONST:
uiItemR(row, ptr, "int_value", 0, NULL, ICON_NONE);
break;
case ACT_RANDOM_INT_UNIFORM:
uiItemR(row, ptr, "int_min", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "int_max", 0, NULL, ICON_NONE);
break;
case ACT_RANDOM_INT_POISSON:
uiItemR(row, ptr, "int_mean", 0, NULL, ICON_NONE);
break;
case ACT_RANDOM_FLOAT_CONST:
uiItemR(row, ptr, "float_value", 0, NULL, ICON_NONE);
break;
case ACT_RANDOM_FLOAT_UNIFORM:
uiItemR(row, ptr, "float_min", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "float_max", 0, NULL, ICON_NONE);
break;
case ACT_RANDOM_FLOAT_NORMAL:
uiItemR(row, ptr, "float_mean", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "standard_derivation", 0, NULL, ICON_NONE);
break;
case ACT_RANDOM_FLOAT_NEGATIVE_EXPONENTIAL:
uiItemR(row, ptr, "half_life_time", 0, NULL, ICON_NONE);
break;
}
}
static void draw_actuator_scene(uiLayout *layout, PointerRNA *ptr)
{
uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE);
switch (RNA_enum_get(ptr, "mode")) {
case ACT_SCENE_CAMERA:
uiItemR(layout, ptr, "camera", 0, NULL, ICON_NONE);
break;
case ACT_SCENE_RESTART:
break;
default: // ACT_SCENE_SET|ACT_SCENE_ADD_FRONT|ACT_SCENE_ADD_BACK|ACT_SCENE_REMOVE|ACT_SCENE_SUSPEND|ACT_SCENE_RESUME
uiItemR(layout, ptr, "scene", 0, NULL, ICON_NONE);
break;
}
}
static void draw_actuator_shape_action(uiLayout *layout, PointerRNA *ptr)
{
Object *ob = (Object *)ptr->id.data;
PointerRNA settings_ptr;
uiLayout *row;
if (ob->type != OB_MESH) {
uiItemL(layout, "Actuator only available for mesh objects", ICON_NONE);
return;
}
RNA_pointer_create((ID *)ob, &RNA_GameObjectSettings, ob, &settings_ptr);
row = uiLayoutRow(layout, FALSE);
uiItemR(row, ptr, "mode", 0, "", ICON_NONE);
uiItemR(row, ptr, "action", 0, "", ICON_NONE);
uiItemR(row, ptr, "use_continue_last_frame", 0, NULL, ICON_NONE);
row = uiLayoutRow(layout, FALSE);
if ((RNA_enum_get(ptr, "mode") == ACT_ACTION_FROM_PROP))
uiItemPointerR(row, ptr, "property", &settings_ptr, "properties", NULL, ICON_NONE);
else {
uiItemR(row, ptr, "frame_start", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "frame_end", 0, NULL, ICON_NONE);
}
row = uiLayoutRow(layout, FALSE);
uiItemR(row, ptr, "frame_blend_in", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "priority", 0, NULL, ICON_NONE);
row = uiLayoutRow(layout, FALSE);
uiItemPointerR(row, ptr, "frame_property", &settings_ptr, "properties", NULL, ICON_NONE);
#ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
uiItemR(row, "stride_length", 0, NULL, ICON_NONE);
#endif
}
static void draw_actuator_sound(uiLayout *layout, PointerRNA *ptr, bContext *C)
{
uiLayout *row, *col;
uiTemplateID(layout, C, ptr, "sound", NULL, "SOUND_OT_open", NULL);
if (!RNA_pointer_get(ptr, "sound").data) {
uiItemL(layout, "Select a sound from the list or load a new one", ICON_NONE);
return;
}
uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE);
row = uiLayoutRow(layout, FALSE);
uiItemR(row, ptr, "volume", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "pitch", 0, NULL, ICON_NONE);
uiItemR(layout, ptr, "use_sound_3d", 0, NULL, ICON_NONE);
col = uiLayoutColumn(layout, FALSE);
uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_sound_3d") == TRUE);
row = uiLayoutRow(col, FALSE);
uiItemR(row, ptr, "gain_3d_min", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "gain_3d_max", 0, NULL, ICON_NONE);
row = uiLayoutRow(col, FALSE);
uiItemR(row, ptr, "distance_3d_reference", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "distance_3d_max", 0, NULL, ICON_NONE);
row = uiLayoutRow(col, FALSE);
uiItemR(row, ptr, "rolloff_factor_3d", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "cone_outer_gain_3d", 0, NULL, ICON_NONE);
row = uiLayoutRow(col, FALSE);
uiItemR(row, ptr, "cone_outer_angle_3d", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "cone_inner_angle_3d", 0, NULL, ICON_NONE);
}
static void draw_actuator_state(uiLayout *layout, PointerRNA *ptr)
{
uiLayout *split;
Object *ob = (Object *)ptr->id.data;
PointerRNA settings_ptr;
RNA_pointer_create((ID *)ob, &RNA_GameObjectSettings, ob, &settings_ptr);
split = uiLayoutSplit(layout, 0.35, FALSE);
uiItemR(split, ptr, "operation", 0, NULL, ICON_NONE);
uiTemplateLayers(split, ptr, "states", &settings_ptr, "used_states", 0);
}
static void draw_actuator_visibility(uiLayout *layout, PointerRNA *ptr)
{
uiLayout *row;
row = uiLayoutRow(layout, FALSE);
uiItemR(row, ptr, "use_visible", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "use_occlusion", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "apply_to_children", 0, NULL, ICON_NONE);
}
static void draw_actuator_steering(uiLayout *layout, PointerRNA *ptr)
{
uiLayout *row;
uiLayout *col;
uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE);
uiItemR(layout, ptr, "target", 0, NULL, ICON_NONE);
uiItemR(layout, ptr, "navmesh", 0, NULL, ICON_NONE);
row = uiLayoutRow(layout, FALSE);
uiItemR(row, ptr, "distance", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "velocity", 0, NULL, ICON_NONE);
row = uiLayoutRow(layout, FALSE);
uiItemR(row, ptr, "acceleration", 0, NULL, ICON_NONE);
uiItemR(row, ptr, "turn_speed", 0, NULL, ICON_NONE);
row = uiLayoutRow(layout, FALSE);
col = uiLayoutColumn(row, FALSE);
uiItemR(col, ptr, "facing", 0, NULL, ICON_NONE);
col = uiLayoutColumn(row, FALSE);
uiItemR(col, ptr, "facing_axis", 0, NULL, ICON_NONE);
if (!RNA_boolean_get(ptr, "facing")) {
uiLayoutSetActive(col, FALSE);
}
col = uiLayoutColumn(row, FALSE);
uiItemR(col, ptr, "normal_up", 0, NULL, ICON_NONE);
if (!RNA_pointer_get(ptr, "navmesh").data) {
uiLayoutSetActive(col, FALSE);
}
row = uiLayoutRow(layout, FALSE);
uiItemR(row, ptr, "self_terminated", 0, NULL, ICON_NONE);
if (RNA_enum_get(ptr, "mode")==ACT_STEERING_PATHFOLLOWING) {
uiItemR(row, ptr, "update_period", 0, NULL, ICON_NONE);
row = uiLayoutRow(layout, FALSE);
}
uiItemR(row, ptr, "show_visualization", 0, NULL, ICON_NONE);
}
static void draw_brick_actuator(uiLayout *layout, PointerRNA *ptr, bContext *C)
{
uiLayout *box;
if (!RNA_boolean_get(ptr, "show_expanded"))
return;
box = uiLayoutBox(layout);
switch (RNA_enum_get(ptr, "type")) {
case ACT_ACTION:
draw_actuator_action(box, ptr);
break;
case ACT_ARMATURE:
draw_actuator_armature(box, ptr);
break;
case ACT_CAMERA:
draw_actuator_camera(box, ptr);
break;
case ACT_CONSTRAINT:
draw_actuator_constraint(box, ptr, C);
break;
case ACT_EDIT_OBJECT:
draw_actuator_edit_object(box, ptr);
break;
case ACT_2DFILTER:
draw_actuator_filter_2d(box, ptr);
break;
case ACT_GAME:
draw_actuator_game(box, ptr);
break;
case ACT_MESSAGE:
draw_actuator_message(box, ptr, C);
break;
case ACT_OBJECT:
draw_actuator_motion(box, ptr);
break;
case ACT_PARENT:
draw_actuator_parent(box, ptr);
break;
case ACT_PROPERTY:
draw_actuator_property(box, ptr);
break;
case ACT_RANDOM:
draw_actuator_random(box, ptr);
break;
case ACT_SCENE:
draw_actuator_scene(box, ptr);
break;
case ACT_SHAPEACTION:
draw_actuator_shape_action(box, ptr);
break;
case ACT_SOUND:
draw_actuator_sound(box, ptr, C);
break;
case ACT_STATE:
draw_actuator_state(box, ptr);
break;
case ACT_VISIBILITY:
draw_actuator_visibility(box, ptr);
break;
case ACT_STEERING:
draw_actuator_steering(box, ptr);
}
}
void logic_buttons(bContext *C, ARegion *ar)
{
SpaceLogic *slogic= CTX_wm_space_logic(C);
Object *ob= CTX_data_active_object(C);
ID **idar;
PointerRNA logic_ptr, settings_ptr, object_ptr;
uiLayout *layout, *row, *box;
uiBlock *block;
uiBut *but;
char uiblockstr[32];
short a, count;
int xco, yco, width;
if (ob==NULL) return;
RNA_pointer_create(NULL, &RNA_SpaceLogicEditor, slogic, &logic_ptr);
idar= get_selected_and_linked_obs(C, &count, slogic->scaflag);
BLI_snprintf(uiblockstr, sizeof(uiblockstr), "buttonswin %p", (void *)ar);
block= uiBeginBlock(C, ar, uiblockstr, UI_EMBOSS);
uiBlockSetHandleFunc(block, do_logic_buts, NULL);
/* loop over all objects and set visible/linked flags for the logic bricks */
for (a=0; a<count; a++) {
bActuator *act;
bSensor *sens;
bController *cont;
int iact;
short flag;
ob= (Object *)idar[a];
/* clean ACT_LINKED and ACT_VISIBLE of all potentially visible actuators so that we can determine which is actually linked/visible */
act = ob->actuators.first;
while (act) {
act->flag &= ~(ACT_LINKED|ACT_VISIBLE);
act = act->next;
}
/* same for sensors */
sens= ob->sensors.first;
while (sens) {
sens->flag &= ~(SENS_VISIBLE);
sens = sens->next;
}
/* mark the linked and visible actuators */
cont= ob->controllers.first;
while (cont) {
flag = ACT_LINKED;
/* this controller is visible, mark all its actuator */
if ((ob->scaflag & OB_ALLSTATE) || (ob->state & cont->state_mask))
flag |= ACT_VISIBLE;
for (iact=0; iact<cont->totlinks; iact++) {
act = cont->links[iact];
if (act)
act->flag |= flag;
}
cont = cont->next;
}
}
/* ****************** Controllers ****************** */
xco= 420; yco= 170; width= 300;
layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, xco, yco, width, 20, UI_GetStyle());
row = uiLayoutRow(layout, TRUE);
uiDefBlockBut(block, controller_menu, NULL, "Controllers", xco-10, yco, 300, UI_UNIT_Y, ""); /* replace this with uiLayout stuff later */
uiItemR(row, &logic_ptr, "show_controllers_selected_objects", 0, "Sel", ICON_NONE);
uiItemR(row, &logic_ptr, "show_controllers_active_object", 0, "Act", ICON_NONE);
uiItemR(row, &logic_ptr, "show_controllers_linked_controller", 0, "Link", ICON_NONE);
for (a=0; a<count; a++) {
bController *cont;
PointerRNA ptr;
uiLayout *split, *subsplit, *col;
ob= (Object *)idar[a];
/* only draw the controller common header if "use_visible" */
if ( (ob->scavisflag & OB_VIS_CONT) == 0) {
continue;
}
/* Drawing the Controller Header common to all Selected Objects */
RNA_pointer_create((ID *)ob, &RNA_GameObjectSettings, ob, &settings_ptr);
split = uiLayoutSplit(layout, 0.05f, FALSE);
uiItemR(split, &settings_ptr, "show_state_panel", UI_ITEM_R_NO_BG, "", ICON_DISCLOSURE_TRI_RIGHT);
row = uiLayoutRow(split, TRUE);
uiDefButBitS(block, TOG, OB_SHOWCONT, B_REDR, ob->id.name+2, (short)(xco-10), yco, (short)(width-30), UI_UNIT_Y, &ob->scaflag, 0, 31, 0, 0, "Object name, click to show/hide controllers");
RNA_pointer_create((ID *)ob, &RNA_Object, ob, &object_ptr);
uiLayoutSetContextPointer(row, "object", &object_ptr);
uiItemMenuEnumO(row, "LOGIC_OT_controller_add", "type", "Add Controller", ICON_NONE);
if (RNA_boolean_get(&settings_ptr, "show_state_panel")) {
box = uiLayoutBox(layout);
split = uiLayoutSplit(box, 0.2f, FALSE);
col = uiLayoutColumn(split, FALSE);
uiItemL(col, "Visible", ICON_NONE);
uiItemL(col, "Initial", ICON_NONE);
subsplit = uiLayoutSplit(split, 0.85f, FALSE);
col = uiLayoutColumn(subsplit, FALSE);
row = uiLayoutRow(col, FALSE);
uiLayoutSetActive(row, RNA_boolean_get(&settings_ptr, "use_all_states") == FALSE);
uiTemplateGameStates(row, &settings_ptr, "states_visible", &settings_ptr, "used_states", 0);
row = uiLayoutRow(col, FALSE);
uiTemplateGameStates(row, &settings_ptr, "states_initial", &settings_ptr, "used_states", 0);
col = uiLayoutColumn(subsplit, FALSE);
uiItemR(col, &settings_ptr, "use_all_states", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
uiItemR(col, &settings_ptr, "show_debug_state", 0, "", ICON_NONE);
}
/* End of Drawing the Controller Header common to all Selected Objects */
if ((ob->scaflag & OB_SHOWCONT) == 0) continue;
uiItemS(layout);
for (cont= ob->controllers.first; cont; cont=cont->next) {
RNA_pointer_create((ID *)ob, &RNA_Controller, cont, &ptr);
if (!(ob->scaflag & OB_ALLSTATE) && !(ob->state & cont->state_mask))
continue;
/* use two nested splits to align inlinks/links properly */
split = uiLayoutSplit(layout, 0.05f, FALSE);
/* put inlink button to the left */
col = uiLayoutColumn(split, FALSE);
uiLayoutSetAlignment(col, UI_LAYOUT_ALIGN_LEFT);
uiDefIconBut(block, INLINK, 0, ICON_INLINK, 0, 0, UI_UNIT_X, UI_UNIT_Y, cont, LINK_CONTROLLER, 0, 0, 0, "");
//col = uiLayoutColumn(split, TRUE);
/* nested split for middle and right columns */
subsplit = uiLayoutSplit(split, 0.95f, FALSE);
col = uiLayoutColumn(subsplit, TRUE);
uiLayoutSetContextPointer(col, "controller", &ptr);
/* should make UI template for controller header.. function will do for now */
// draw_controller_header(col, &ptr);
draw_controller_header(col, &ptr, xco, width, yco); //provisory for 2.50 beta
/* draw the brick contents */
draw_brick_controller(col, &ptr);
/* put link button to the right */
col = uiLayoutColumn(subsplit, FALSE);
uiLayoutSetAlignment(col, UI_LAYOUT_ALIGN_LEFT);
but = uiDefIconBut(block, LINK, 0, ICON_LINK, 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
uiSetButLink(but, NULL, (void ***)&(cont->links), &cont->totlinks, LINK_CONTROLLER, LINK_ACTUATOR);
}
}
uiBlockLayoutResolve(block, NULL, &yco); /* stores final height in yco */
/* ****************** Sensors ****************** */
xco= 10; yco= 170; width= 340;
layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, xco, yco, width, 20, UI_GetStyle());
row = uiLayoutRow(layout, TRUE);
uiDefBlockBut(block, sensor_menu, NULL, "Sensors", xco-10, yco, 300, UI_UNIT_Y, ""); /* replace this with uiLayout stuff later */
uiItemR(row, &logic_ptr, "show_sensors_selected_objects", 0, "Sel", ICON_NONE);
uiItemR(row, &logic_ptr, "show_sensors_active_object", 0, "Act", ICON_NONE);
uiItemR(row, &logic_ptr, "show_sensors_linked_controller", 0, "Link", ICON_NONE);
uiItemR(row, &logic_ptr, "show_sensors_active_states", 0, "State", ICON_NONE);
for (a=0; a<count; a++) {
bSensor *sens;
PointerRNA ptr;
ob= (Object *)idar[a];
/* only draw the sensor common header if "use_visible" */
if ((ob->scavisflag & OB_VIS_SENS) == 0) continue;
row = uiLayoutRow(layout, TRUE);
uiDefButBitS(block, TOG, OB_SHOWSENS, B_REDR, ob->id.name+2, (short)(xco-10), yco, (short)(width-30), UI_UNIT_Y, &ob->scaflag, 0, 31, 0, 0, "Object name, click to show/hide sensors");
RNA_pointer_create((ID *)ob, &RNA_Object, ob, &object_ptr);
uiLayoutSetContextPointer(row, "object", &object_ptr);
uiItemMenuEnumO(row, "LOGIC_OT_sensor_add", "type", "Add Sensor", ICON_NONE);
if ((ob->scaflag & OB_SHOWSENS) == 0) continue;
uiItemS(layout);
for (sens= ob->sensors.first; sens; sens=sens->next) {
RNA_pointer_create((ID *)ob, &RNA_Sensor, sens, &ptr);
if ((ob->scaflag & OB_ALLSTATE) ||
!(slogic->scaflag & BUTS_SENS_STATE) ||
(sens->totlinks == 0) || /* always display sensor without links so that is can be edited */
(sens->flag & SENS_PIN && slogic->scaflag & BUTS_SENS_STATE) || /* states can hide some sensors, pinned sensors ignore the visible state */
(is_sensor_linked(block, sens))
)
{ // gotta check if the current state is visible or not
uiLayout *split, *col;
/* make as visible, for move operator */
sens->flag |= SENS_VISIBLE;
split = uiLayoutSplit(layout, 0.95f, FALSE);
col = uiLayoutColumn(split, TRUE);
uiLayoutSetContextPointer(col, "sensor", &ptr);
/* should make UI template for sensor header.. function will do for now */
draw_sensor_header(col, &ptr, &logic_ptr);
/* draw the brick contents */
draw_brick_sensor(col, &ptr, C);
/* put link button to the right */
col = uiLayoutColumn(split, FALSE);
/* use old-school uiButtons for links for now */
but = uiDefIconBut(block, LINK, 0, ICON_LINK, 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
uiSetButLink(but, NULL, (void ***)&(sens->links), &sens->totlinks, LINK_SENSOR, LINK_CONTROLLER);
}
}
}
uiBlockLayoutResolve(block, NULL, &yco); /* stores final height in yco */
/* ****************** Actuators ****************** */
xco= 800; yco= 170; width= 340;
layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, xco, yco, width, 20, UI_GetStyle());
row = uiLayoutRow(layout, TRUE);
uiDefBlockBut(block, actuator_menu, NULL, "Actuators", xco-10, yco, 300, UI_UNIT_Y, ""); /* replace this with uiLayout stuff later */
uiItemR(row, &logic_ptr, "show_actuators_selected_objects", 0, "Sel", ICON_NONE);
uiItemR(row, &logic_ptr, "show_actuators_active_object", 0, "Act", ICON_NONE);
uiItemR(row, &logic_ptr, "show_actuators_linked_controller", 0, "Link", ICON_NONE);
uiItemR(row, &logic_ptr, "show_actuators_active_states", 0, "State", ICON_NONE);
for (a=0; a<count; a++) {
bActuator *act;
PointerRNA ptr;
ob= (Object *)idar[a];
/* only draw the actuator common header if "use_visible" */
if ((ob->scavisflag & OB_VIS_ACT) == 0) {
continue;
}
row = uiLayoutRow(layout, TRUE);
uiDefButBitS(block, TOG, OB_SHOWACT, B_REDR, ob->id.name+2, (short)(xco-10), yco, (short)(width-30), UI_UNIT_Y, &ob->scaflag, 0, 31, 0, 0, "Object name, click to show/hide actuators");
RNA_pointer_create((ID *)ob, &RNA_Object, ob, &object_ptr);
uiLayoutSetContextPointer(row, "object", &object_ptr);
uiItemMenuEnumO(row, "LOGIC_OT_actuator_add", "type", "Add Actuator", ICON_NONE);
if ((ob->scaflag & OB_SHOWACT) == 0) continue;
uiItemS(layout);
for (act= ob->actuators.first; act; act=act->next) {
RNA_pointer_create((ID *)ob, &RNA_Actuator, act, &ptr);
if ((ob->scaflag & OB_ALLSTATE) ||
!(slogic->scaflag & BUTS_ACT_STATE) ||
!(act->flag & ACT_LINKED) || /* always display actuators without links so that is can be edited */
(act->flag & ACT_VISIBLE) || /* this actuator has visible connection, display it */
(act->flag & ACT_PIN && slogic->scaflag & BUTS_ACT_STATE) /* states can hide some sensors, pinned sensors ignore the visible state */
)
{ // gotta check if the current state is visible or not
uiLayout *split, *col;
/* make as visible, for move operator */
act->flag |= ACT_VISIBLE;
split = uiLayoutSplit(layout, 0.05f, FALSE);
/* put inlink button to the left */
col = uiLayoutColumn(split, FALSE);
uiDefIconBut(block, INLINK, 0, ICON_INLINK, 0, 0, UI_UNIT_X, UI_UNIT_Y, act, LINK_ACTUATOR, 0, 0, 0, "");
col = uiLayoutColumn(split, TRUE);
uiLayoutSetContextPointer(col, "actuator", &ptr);
/* should make UI template for actuator header.. function will do for now */
draw_actuator_header(col, &ptr, &logic_ptr);
/* draw the brick contents */
draw_brick_actuator(col, &ptr, C);
}
}
}
uiBlockLayoutResolve(block, NULL, &yco); /* stores final height in yco */
uiComposeLinks(block);
uiEndBlock(C, block);
uiDrawBlock(C, block);
if (idar) MEM_freeN(idar);
}
|