diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e5ec633 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.directory +.vscode/ +__pycache__/ diff --git a/__init__.py b/__init__.py index c1400ba..cd10fef 100644 --- a/__init__.py +++ b/__init__.py @@ -28,89 +28,12 @@ bl_info = { "category": "Generic" } -import os -import bpy - - -# global variable to store icons in -custom_icons = {} - -# UI__init__.py - -class MY_PT_khanat_tools(bpy.types.Panel): - bl_label = 'Khanat tools' - bl_space_type = 'VIEW_3D' - bl_region_type = 'UI' - bl_context = '' - bl_category = 'Khanat' - - - def draw_header(self, context): - global custom_icons - print(custom_icons) - layout = self.layout - layout.label(icon_value=custom_icons["khanat"].icon_id) - - def draw(self, context): - layout = self.layout - - row = layout.row() - row.operator(MY_OT_khanat_export_gltf.bl_idname) - layout.separator() - - row = layout.row() - row.operator(MY_OT_khanat_get_online_doc.bl_idname, icon_value=72) - layout.separator() - -# Operators - -class MY_OT_khanat_export_gltf(bpy.types.Operator): - """Export collections to gltf""" - bl_idname = "object.export2gltf" - bl_label = "Export to gltf" - bl_options = {'REGISTER', 'UNDO'} - - def execute(self, context): - return {"FINISHED"} - - def invoke(self, context, event): - return self.execute(context) - -class MY_OT_khanat_get_online_doc(bpy.types.Operator): - """Check online documentation""" - bl_idname = "object.readthedocs" - bl_label = "Online documentation" - bl_description = "Go to Khanat Development Guide" - bl_options = {"REGISTER", "UNDO"} - - def execute(self, context): - bpy.ops.wm.url_open('INVOKE_DEFAULT', url='https://git.numenaute.org/khaganat/mmorpg_khanat/khanat_gamedev_guide') - return {"FINISHED"} - - def invoke(self, context, event): - return self.execute(context) - - -# Register / Unregister def register(): - global custom_icons - custom_icons = bpy.utils.previews.new() - addon_path = os.path.dirname(__file__) - icons_dir = os.path.join(addon_path, "icons") - custom_icons.load("khanat", os.path.join(icons_dir, "khanat.png"), 'IMAGE') - bpy.utils.register_class(MY_OT_khanat_export_gltf) - bpy.utils.register_class(MY_OT_khanat_get_online_doc) - bpy.utils.register_class(MY_PT_khanat_tools) + from addon.register import register_addon + register_addon() + def unregister(): - global custom_icons - bpy.utils.previews.remove(custom_icons) - bpy.utils.register_class(MY_OT_khanat_export_gltf) - bpy.utils.register_class(MY_OT_khanat_get_online_doc) - bpy.utils.register_class(MY_PT_khanat_tools) - - -if __name__ == "__main__": - __file__ = bpy.data.filepath - register() + from addon.register import unregister_addon + unregister_addon() diff --git a/addon/__init__.py b/addon/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/addon/icons/__init__.py b/addon/icons/__init__.py new file mode 100644 index 0000000..18222aa --- /dev/null +++ b/addon/icons/__init__.py @@ -0,0 +1,29 @@ +import bpy +import os + +icons_collection = None +icons_directory = os.path.dirname(__file__) + +def initialize_icons_collection(): + import bpy.utils.previews + global icons_collection + print("icons_collection : {}".format(icons_collection)) + icons_collection = bpy.utils.previews.new() + +def unload_icons(): + bpy.utils.previews.remove(icons_collection) + +def get_icon_id(identifier): + # The initialize_icons_collection function needs to be called first. + return get_icon(identifier).icon_id + +def get_icon(identifier): + if identifier in icons_collection: + return icons_collection[identifier] + return icons_collection.load(identifier, os.path.join(icons_directory, identifier + ".png"), "IMAGE") + +def register_icons(): + initialize_icons_collection() + +def unregister_icons(): + unload_icons() \ No newline at end of file diff --git a/icons/khanat.png b/addon/icons/khanat.png similarity index 100% rename from icons/khanat.png rename to addon/icons/khanat.png diff --git a/addon/menus/__init__.py b/addon/menus/__init__.py new file mode 100644 index 0000000..700b418 --- /dev/null +++ b/addon/menus/__init__.py @@ -0,0 +1,18 @@ +import bpy + +from .panel_main import KH_PT_panel_main + +classes = ( + KH_PT_panel_main, +) + +def register_menus(): + from bpy.utils import register_class + for cls in classes: + register_class(cls) + + +def unregister_menus(): + from bpy.utils import unregister_class + for cls in classes: + unregister_class(cls) \ No newline at end of file diff --git a/addon/menus/panel_main.py b/addon/menus/panel_main.py new file mode 100644 index 0000000..887ec0d --- /dev/null +++ b/addon/menus/panel_main.py @@ -0,0 +1,26 @@ +import bpy +from ..operators import readthedocs, export2godot +from ..icons import get_icon_id + +class KH_PT_panel_main(bpy.types.Panel): + bl_label = 'Khanat tools' + bl_space_type = 'VIEW_3D' + bl_region_type = 'UI' + bl_context = '' + bl_category = 'Khanat' + + + def draw_header(self, context): + layout = self.layout + layout.label(icon_value=get_icon_id("khanat")) + + def draw(self, context): + layout = self.layout + + row = layout.row() + row.operator(export2godot.KH_OP_export2godot.bl_idname) + layout.separator() + + row = layout.row() + row.operator(readthedocs.KH_OP_readthedocs.bl_idname, icon_value=72) + layout.separator() \ No newline at end of file diff --git a/addon/operators/__init__.py b/addon/operators/__init__.py new file mode 100644 index 0000000..ea22e08 --- /dev/null +++ b/addon/operators/__init__.py @@ -0,0 +1,20 @@ +import bpy + +from .readthedocs import KH_OP_readthedocs +from .export2godot import KH_OP_export2godot + +classes = ( + KH_OP_readthedocs, + KH_OP_export2godot +) + +def register_operators(): + print(classes) + from bpy.utils import register_class + for cls in classes: + register_class(cls) + +def unregister_operators(): + from bpy.utils import unregister_class + for cls in classes: + unregister_class(cls) \ No newline at end of file diff --git a/addon/operators/export2godot.py b/addon/operators/export2godot.py new file mode 100644 index 0000000..57f9d0a --- /dev/null +++ b/addon/operators/export2godot.py @@ -0,0 +1,14 @@ +import bpy + +class KH_OP_export2godot(bpy.types.Operator): + """Export collections to Godot throught glTF""" + bl_idname = "kh.export2godot" + bl_label = "Export to gltf" + bl_options = {'REGISTER', 'UNDO'} + + def invoke(self, context, event): + return self.execute(context) + + def execute(self, context): + print("TOTOR IS NOT HERE") + return {"FINISHED"} diff --git a/addon/operators/readthedocs.py b/addon/operators/readthedocs.py new file mode 100644 index 0000000..5e2b94f --- /dev/null +++ b/addon/operators/readthedocs.py @@ -0,0 +1,20 @@ +import bpy + + +class KH_OP_readthedocs(bpy.types.Operator): + """Check online documentation""" + + bl_idname = "kh.readthedocs" + bl_label = "Online documentation" + bl_description = "Go to Khanat Development Guide" + bl_options = {"REGISTER", "UNDO"} + + def invoke(self, context, event): + return self.execute(context) + + + def execute(self, context): + bpy.ops.wm.url_open('INVOKE_DEFAULT', url='https://git.numenaute.org/khaganat/mmorpg_khanat/khanat_gamedev_guide') + return {"FINISHED"} + + diff --git a/addon/register/__init__.py b/addon/register/__init__.py new file mode 100644 index 0000000..ba82caf --- /dev/null +++ b/addon/register/__init__.py @@ -0,0 +1,30 @@ + +def register_addon(): + + # Icons + from ..icons import register_icons + register_icons() + + # Operators + from ..operators import register_operators + register_operators() + + # Menus + from ..menus import register_menus + register_menus() + + + +def unregister_addon(): + + # Menus + from ..menus import unregister_menus + unregister_menus() + + # Operators + from ..operators import unregister_operators + unregister_operators() + + # Icons + from ..icons import unregister_icons + unregister_icons() \ No newline at end of file