core: base elements for the plugin (panel and some buttons)
This commit is contained in:
parent
32d58cc678
commit
760e4ccaf7
1 changed files with 116 additions and 0 deletions
116
__init__.py
Normal file
116
__init__.py
Normal file
|
@ -0,0 +1,116 @@
|
|||
# BEGIN GPL LICENSE BLOCK #####
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# END GPL LICENSE BLOCK #####
|
||||
|
||||
|
||||
bl_info = {
|
||||
"name": "Khanat Tools",
|
||||
"author": "Yann Kervran",
|
||||
"version": (1, 0),
|
||||
"blender": (3, 4, 0),
|
||||
"location": "View3D > UI > Tools",
|
||||
"description": "Toolset for Khanat project",
|
||||
"doc_url": "https://git.numenaute.org/yannk/khanat-tools",
|
||||
"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)
|
||||
|
||||
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()
|
Loading…
Reference in a new issue