Fix build error on Windows 32 bit.
[blender-staging.git] / release / scripts / startup / bl_ui / space_logic.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21 from bpy.types import Header, Menu, Panel
22
23
24 class LOGIC_PT_properties(Panel):
25     bl_space_type = 'LOGIC_EDITOR'
26     bl_region_type = 'UI'
27     bl_label = "Properties"
28
29     @classmethod
30     def poll(cls, context):
31         ob = context.active_object
32         return ob and ob.game
33
34     def draw(self, context):
35         layout = self.layout
36
37         ob = context.active_object
38         game = ob.game
39         is_font = (ob.type == 'FONT')
40
41         if is_font:
42             prop_index = game.properties.find("Text")
43             if prop_index != -1:
44                 layout.operator("object.game_property_remove", text="Remove Text Game Property", icon='X').index = prop_index
45                 row = layout.row()
46                 sub = row.row()
47                 sub.enabled = 0
48                 prop = game.properties[prop_index]
49                 sub.prop(prop, "name", text="")
50                 row.prop(prop, "type", text="")
51                 # get the property from the body, not the game property
52                 # note, don't do this - it's too slow and body can potentially be a really long string.
53                 #~ row.prop(ob.data, "body", text="")
54                 row.label("See Text Object")
55             else:
56                 props = layout.operator("object.game_property_new", text="Add Text Game Property", icon='ZOOMIN')
57                 props.name = "Text"
58                 props.type = 'STRING'
59
60         props = layout.operator("object.game_property_new", text="Add Game Property", icon='ZOOMIN')
61         props.name = ""
62
63         for i, prop in enumerate(game.properties):
64
65             if is_font and i == prop_index:
66                 continue
67
68             box = layout.box()
69             row = box.row()
70             row.prop(prop, "name", text="")
71             row.prop(prop, "type", text="")
72             row.prop(prop, "value", text="")
73             row.prop(prop, "show_debug", text="", toggle=True, icon='INFO')
74             sub = row.row(align=True)
75             props = sub.operator("object.game_property_move", text="", icon='TRIA_UP')
76             props.index = i
77             props.direction = 'UP'
78             props = sub.operator("object.game_property_move", text="", icon='TRIA_DOWN')
79             props.index = i
80             props.direction = 'DOWN'
81             row.operator("object.game_property_remove", text="", icon='X', emboss=False).index = i
82
83
84 class LOGIC_MT_logicbricks_add(Menu):
85     bl_label = "Add"
86
87     def draw(self, context):
88         layout = self.layout
89
90         layout.operator_menu_enum("logic.sensor_add", "type", text="Sensor")
91         layout.operator_menu_enum("logic.controller_add", "type", text="Controller")
92         layout.operator_menu_enum("logic.actuator_add", "type", text="Actuator")
93
94
95 class LOGIC_HT_header(Header):
96     bl_space_type = 'LOGIC_EDITOR'
97
98     def draw(self, context):
99         layout = self.layout.row(align=True)
100
101         layout.template_header()
102
103         LOGIC_MT_editor_menus.draw_collapsible(context, layout)
104
105
106 class LOGIC_MT_editor_menus(Menu):
107     bl_idname = "LOGIC_MT_editor_menus"
108     bl_label = ""
109
110     def draw(self, context):
111         self.draw_menus(self.layout, context)
112
113     @staticmethod
114     def draw_menus(layout, context):
115         layout.menu("LOGIC_MT_view")
116         layout.menu("LOGIC_MT_logicbricks_add")
117
118
119 class LOGIC_MT_view(Menu):
120     bl_label = "View"
121
122     def draw(self, context):
123         layout = self.layout
124
125         layout.operator("logic.properties", icon='MENU_PANEL')
126
127         layout.separator()
128
129         layout.operator("screen.area_dupli")
130         layout.operator("screen.screen_full_area")
131         layout.operator("screen.screen_full_area", text="Toggle Fullscreen Area").use_hide_panels = True
132
133
134 classes = (
135     LOGIC_PT_properties,
136     LOGIC_MT_logicbricks_add,
137     LOGIC_HT_header,
138     LOGIC_MT_editor_menus,
139     LOGIC_MT_view,
140 )
141
142 if __name__ == "__main__":  # only for live edit.
143     from bpy.utils import register_class
144     for cls in classes:
145         register_class(cls)