-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevel_menu.py
217 lines (145 loc) · 6.38 KB
/
level_menu.py
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
##############################################################################
# Imports Order: 3rd Party Imports, Python Built-ins, Custom Modules
##############################################################################
import bpy
import typing
import re
import os
import json
from . import export
from . import config_controller
##############################################################################
# Constants
##############################################################################
# Path read out of the json config
CUSTLVL = config_controller.read_from_config("Working Directory")
##############################################################################
# Classes
##############################################################################
classes = [] # Initialize the class array to be registered
class LevelProperties(bpy.types.PropertyGroup):
level_title: bpy.props.StringProperty(
name="Level Title",
description="The name of your custom level.\nOnly letters and dashes are allowed, case will be ignored.\nDefault: my-level",
default="my-level",
maxlen=1024,
)
level_nickname: bpy.props.StringProperty(
name="Level Nickname",
description="The nickname of your custom level.\nThree letters, case will be ignored.\nDefault: lvl",
default="lvl",
maxlen=3,
)
custom_levels_path: bpy.props.StringProperty(
name="Working Directory",
description="The path to \\custom_levels\\ in the OpenGOAL distribution",
default="",
maxlen=1024,
subtype="DIR_PATH",
)
should_export_level_info: bpy.props.BoolProperty(
name="Level Info",
description="Check if you'd like the level info to be included when you export",
default=True,
)
should_export_actor_info: bpy.props.BoolProperty(
name="Actor Info",
description="Check if you'd like the actor info to be included when you export",
default=True,
)
should_export_geometry: bpy.props.BoolProperty(
name="Level Geometry",
description="Check if you'd like the level geometry to be included when you export",
default=True,
)
should_playtest_level: bpy.props.BoolProperty(
name="Playtest Level",
description="Check if you'd like to launch the level immediately after export",
default=True,
)
automatic_wall_detection: bpy.props.BoolProperty(
name="Auto Wall Detection",
description="Check if you'd like the level to automatically create walls above a certain angle",
default=True,
)
automatic_wall_angle: bpy.props.FloatProperty(
name="Auto Wall Angle",
description="The angle you'd like the level to automatically create walls above",
min=0.0,
max=90.0,
default=45.0,
)
double_sided_collide: bpy.props.BoolProperty(
name="Double Sided Collision",
description="Check if you'd like to make all collision mesh triangles double sided",
default=False,
)
classes.append(LevelProperties) # Add the class to the array
class OBJECT_PT_LevelInfoMenu(bpy.types.Panel):
""""""
bl_idname = "OBJECT_PT_LevelInfoMenu"
bl_label = "Level Info"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "Level Editor"
bl_context = "objectmode"
#@classmethod
#def poll(self, context):
# should_update_config = True
# return should_update_config
def __init__(self):
props = bpy.context.scene.level_properties
custom_levels_path = props.custom_levels_path
# If custom_levels_path is set to empty, immediately replace it with the config default value
if len(custom_levels_path) < 1:
try: # Try to update the config settings from the json
props.custom_levels_path = CUSTLVL
except Exception as e: # Catch the errors
print(f"Unable to load values from config\nError: {e}")
def draw(self, context):
layout = self.layout
scene = context.scene
level_properties = scene.level_properties
def input_invalid(chars, value):
return not (bool(re.match(chars, value)) and value)
# set these properties manually
title = layout.row()
title.alert = input_invalid("^[A-Za-z-]*$", level_properties.level_title)
title.prop(level_properties, "level_title", icon="TEXT")
nick = layout.row()
nick.alert = input_invalid("^[A-Za-z]*$", level_properties.level_nickname)
nick.prop(level_properties, "level_nickname", icon="TEXT")
# layout.operator("wm.create_world_reference")
layout.prop(level_properties, "custom_levels_path")
layout.prop(level_properties, "double_sided_collide")
layout.prop(level_properties, "automatic_wall_detection")
layout.prop(level_properties, "automatic_wall_angle")
layout.separator()
layout.operator("wm.export")
layout.prop(level_properties, "should_export_level_info")
layout.prop(level_properties, "should_export_actor_info")
layout.prop(level_properties, "should_export_geometry")
# layout.prop(level_properties, "should_playtest_level")
classes.append(OBJECT_PT_LevelInfoMenu) # Add the class to the array
##############################################################################
# Functions
##############################################################################
# Need to implement a singleton pattern so this only shows once per error
def show_message(message, title="Message", icon="INFO"):
"""Make a little popup"""
def draw(self, context):
self.layout.label(text=message)
bpy.context.window_manager.popup_menu(draw, title=title, icon=icon)
##############################################################################
# Registration
##############################################################################
def register():
for cls in classes: # Register all the classes
bpy.utils.register_class(cls)
bpy.types.Scene.level_properties = bpy.props.PointerProperty(type=LevelProperties)
def unregister():
for cls in reversed(classes): # Unregister all the classes
bpy.utils.unregister_class(cls)
del bpy.types.Scene.level_properties
# if __name__ == "__main__": # For internal Blender script testing
# register()