|
15 | 15 |
|
16 | 16 | from __future__ import annotations
|
17 | 17 |
|
18 |
| -import bmesh |
19 | 18 | import bpy
|
20 | 19 | from bpy.props import *
|
21 |
| -import mathutils |
22 | 20 | from PyHSPlasma import *
|
23 | 21 | from typing import *
|
24 | 22 |
|
|
28 | 26 | from ...nodes.node_messages import *
|
29 | 27 | from ...nodes.node_responder import *
|
30 | 28 |
|
| 29 | +from typing import * |
| 30 | + |
| 31 | +if TYPE_CHECKING: |
| 32 | + from ...exporter import Exporter |
| 33 | + |
31 | 34 | from ...addon_prefs import game_versions
|
32 | 35 | from .base import PlasmaModifierProperties, PlasmaModifierLogicWiz
|
33 | 36 | from ...exporter import ExportError, utils
|
@@ -191,6 +194,85 @@ def requires_actor(self):
|
191 | 194 | return True
|
192 | 195 |
|
193 | 196 |
|
| 197 | +class PlasmaSDLIntState(bpy.types.PropertyGroup): |
| 198 | + value: int = IntProperty( |
| 199 | + name="State Value", |
| 200 | + description="The object is shown when the SDL variable is set to this value", |
| 201 | + min=0, |
| 202 | + soft_max=255, |
| 203 | + options=set() |
| 204 | + ) |
| 205 | + |
| 206 | + |
| 207 | +class PlasmaSDLShowHide(PlasmaModifierProperties, PlasmaModifierLogicWiz): |
| 208 | + pl_id = "sdl_showhide" |
| 209 | + |
| 210 | + bl_category = "Logic" |
| 211 | + bl_label = "SDL Show/Hide" |
| 212 | + bl_description = "Show/Hide an object based on an SDL Variable" |
| 213 | + bl_object_types = {"MESH", "FONT"} |
| 214 | + bl_icon = "VISIBLE_IPO_OFF" |
| 215 | + |
| 216 | + sdl_variable: str = StringProperty( |
| 217 | + name="SDL Variable", |
| 218 | + description="Name of the SDL variable that controls visibility", |
| 219 | + options=set() |
| 220 | + ) |
| 221 | + variable_type: str = EnumProperty( |
| 222 | + name="Type", |
| 223 | + description="Data type of the SDL variable", |
| 224 | + items=[ |
| 225 | + ("bool", "Boolean", "A boolean, used to represent simple on/off for a single state"), |
| 226 | + ("int", "Integer", "An integer, used to represent multiple state combinations"), |
| 227 | + ], |
| 228 | + options=set() |
| 229 | + ) |
| 230 | + |
| 231 | + int_states = CollectionProperty(type=PlasmaSDLIntState) |
| 232 | + bool_state: bool = BoolProperty( |
| 233 | + name="Show When True", |
| 234 | + description="If checked, show this object when the SDL Variable is TRUE. If not, hide it when TRUE.", |
| 235 | + default=True, |
| 236 | + options=set() |
| 237 | + ) |
| 238 | + |
| 239 | + def created(self): |
| 240 | + # Ensure at least one SDL int state is precreated for ease of use. |
| 241 | + # REMEMBER: Blender's "sequences" don't do truthiness correctly... |
| 242 | + if len(self.int_states) == 0: |
| 243 | + self.int_states.add() |
| 244 | + |
| 245 | + def sanity_check(self, exporter: Exporter): |
| 246 | + if not exporter.age_sdl: |
| 247 | + raise ExportError(f"'{self.id_data.name}': Age Global SDL is required for the SDL Show/Hide modifier!") |
| 248 | + if not self.sdl_variable.strip(): |
| 249 | + raise ExportError(f"'{self.id_data.name}': A valid SDL variable is required for the SDL Show/Hide modifier!") |
| 250 | + |
| 251 | + def logicwiz(self, bo, tree): |
| 252 | + if self.variable_type == "bool": |
| 253 | + pfm_node = self._create_standard_python_file_node(tree, "xAgeSDLBoolShowHide.py") |
| 254 | + self._create_python_attribute(pfm_node, "sdlName", value=self.sdl_variable) |
| 255 | + self._create_python_attribute(pfm_node, "showOnTrue", value=self.bool_state) |
| 256 | + elif self.variable_type == "int": |
| 257 | + pfm_node = self._create_standard_python_file_node(tree, "xAgeSDLIntShowHide.py") |
| 258 | + self._create_python_attribute(pfm_node, "stringVarName", value=self.sdl_variable) |
| 259 | + self._create_python_attribute(pfm_node, "stringShowStates", value=",".join(self._states)) |
| 260 | + else: |
| 261 | + raise RuntimeError() |
| 262 | + |
| 263 | + @property |
| 264 | + def key_name(self): |
| 265 | + if self.variable_type == "bool": |
| 266 | + return f"cPythBoolShowHide_{self.sdl_variable}_{self.bool_state:d}" |
| 267 | + elif self.variable_type == "int": |
| 268 | + return f"cPythIntShowHide_{self.sdl_variable}_{'-'.join(self._states)}" |
| 269 | + |
| 270 | + @property |
| 271 | + def _states(self) -> Iterable[str]: |
| 272 | + """Returns a sorted, deduplicated iterable of the integer (converted to strings) states we should be visible in.""" |
| 273 | + return (str(i) for i in sorted(frozenset((i.value for i in self.int_states)))) |
| 274 | + |
| 275 | + |
194 | 276 | class PlasmaTelescope(PlasmaModifierProperties, PlasmaModifierLogicWiz):
|
195 | 277 | pl_id="telescope"
|
196 | 278 |
|
|
0 commit comments