Skip to content

Commit 57d10db

Browse files
authored
Merge pull request #440 from Hoikas/more_gui_controls
Implement Many, Many Game GUI Controls
2 parents 5fba7f2 + a9aa273 commit 57d10db

File tree

8 files changed

+1167
-69
lines changed

8 files changed

+1167
-69
lines changed

korman/exporter/locman.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# You should have received a copy of the GNU General Public License
1414
# along with Korman. If not, see <http://www.gnu.org/licenses/>.
1515

16+
from __future__ import annotations
17+
1618
import bpy
1719
from PyHSPlasma import *
1820

@@ -21,7 +23,7 @@
2123
import itertools
2224
from pathlib import Path
2325
import re
24-
from typing import NamedTuple, Union
26+
from typing import *
2527
from xml.sax.saxutils import escape as xml_escape
2628
import weakref
2729

@@ -91,6 +93,24 @@ def add_string(self, set_name, element_name, language, value):
9193

9294
self._strings[set_name][element_name][language] = value
9395

96+
def get_localized_string(self, translations: Dict[str, str]):
97+
# If there's only an English translation, just output this string directly.
98+
if translations.keys() == {"English"}:
99+
return translations["English"]
100+
101+
ignored_translations = frozenset(translations.keys()) - _SP_LANGUAGES
102+
if ignored_translations:
103+
self._report.warn(
104+
f"These translations are not supported in single player: "
105+
f"{', '.join(ignored_translations)}"
106+
)
107+
108+
return "".join(
109+
f"${lang[0:2]}${value}"
110+
for lang, value in translations.items()
111+
if lang in _SP_LANGUAGES
112+
)
113+
94114
@contextmanager
95115
def _generate_file(self, filename, **kwargs):
96116
if self._exporter is not None:
@@ -234,20 +254,27 @@ def run(self):
234254
def _run_harvest_journals(self):
235255
from ..properties.modifiers import TranslationMixin
236256

257+
def iter_subclasses(cls):
258+
for i in cls.__subclasses__():
259+
yield i
260+
if i.__subclasses__():
261+
yield from iter_subclasses(i)
262+
263+
237264
objects = bpy.context.scene.objects
238265
self._report.progress_advance()
239266
self._report.progress_range = len(objects)
240267
inc_progress = self._report.progress_increment
241268

242269
for i in objects:
243-
for mod_type in filter(None, (getattr(j, "pl_id", None) for j in TranslationMixin.__subclasses__())):
270+
for mod_type in filter(None, (getattr(j, "pl_id", None) for j in iter_subclasses(TranslationMixin))):
244271
modifier = getattr(i.plasma_modifiers, mod_type)
245272
if modifier.enabled:
246-
translations = [j for j in modifier.translations if j.text_id is not None]
273+
translations = [j for j in modifier.translations if j.text]
247274
if not translations:
248275
self._report.error(f"'{i.name}': No content translations available. The localization will not be exported.")
249276
for j in translations:
250-
self.add_string(modifier.localization_set, modifier.key_name, j.language, j.text_id)
277+
self.add_string(modifier.localization_set, modifier.key_name, j.language, j.text)
251278
inc_progress()
252279

253280
def _run_generate(self):

korman/idprops.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,22 @@ def poll_empty_objects(self, value):
133133
def poll_mesh_objects(self, value):
134134
return value.type == "MESH"
135135

136+
def poll_object_dyntexts(self, value):
137+
if value.type != "IMAGE":
138+
return False
139+
if value.image is not None:
140+
return False
141+
tex_materials = frozenset(value.users_material)
142+
obj_materials = frozenset(filter(None, (i.material for i in self.id_data.material_slots)))
143+
return bool(tex_materials & obj_materials)
144+
145+
def poll_object_image_textures(self, value):
146+
if value.type != "IMAGE":
147+
return False
148+
tex_materials = frozenset(value.users_material)
149+
obj_materials = frozenset(filter(None, (i.material for i in self.id_data.material_slots)))
150+
return bool(tex_materials & obj_materials)
151+
136152
def poll_softvolume_objects(self, value):
137153
return value.plasma_modifiers.softvolume.enabled
138154

korman/operators/op_toolbox.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,24 @@ def execute(self, context):
160160
return {"FINISHED"}
161161

162162

163+
class PlasmaSelectRadioGroupCheckboxesOperator(bpy.types.Operator):
164+
bl_idname = "object.plasma_select_radio_group"
165+
bl_label = "Select Radio Group"
166+
bl_description = "Selects all checkboxes in a radio group"
167+
168+
def execute(self, context):
169+
active_object = context.active_object
170+
for i in context.scene.objects:
171+
cb_mod = i.plasma_modifiers.gui_checkbox
172+
cb_rg = cb_mod.radio_group
173+
i.select = (
174+
(cb_mod.enabled and cb_rg is not None and cb_rg.name == active_object.name)
175+
or
176+
(i.name == active_object.name)
177+
)
178+
return {"FINISHED"}
179+
180+
163181
class PlasmaToggleAllPlasmaObjectsOperator(ToolboxOperator, bpy.types.Operator):
164182
bl_idname = "object.plasma_toggle_all_objects"
165183
bl_label = "Toggle All Plasma Objects"

korman/properties/modifiers/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@
2727
from .sound import *
2828
from .water import *
2929

30+
# Check our mixins to ensure that the subclasses have them first in their MRO.
31+
_mod_mixins = [game_gui._GameGuiMixin]
32+
for mixin in _mod_mixins:
33+
for sub in mixin.__subclasses__():
34+
mro = sub.__mro__
35+
if mro.index(mixin) > mro.index(PlasmaModifierProperties):
36+
raise ImportError(
37+
f"{sub.__name__} base class {mixin.__name__} isn't properly "
38+
"overriding PlasmaModifierProperties!"
39+
)
40+
3041
class PlasmaModifiers(bpy.types.PropertyGroup):
3142
def determine_next_id(self):
3243
"""Gets the ID for the next modifier in the UI"""

0 commit comments

Comments
 (0)