# 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.
#

import bpy
import os
from . import kex_utils
from bpy_extras.image_utils import load_image

# -----------------------------------------------------------------------------
#
class TurokShadingSettings(bpy.types.PropertyGroup):
    samplerIndex: bpy.props.IntProperty(name="Texture Sampler Index", min=0, max=3, description='If you only have 1 texture node which almost all Turok shaders only support then keep this at 0', default=0)
    mirrored: bpy.props.BoolProperty(name="Mirrored", description='Overrides texture wrapping to "mirrored" which flips the texture on the x and y when it repeats')
#end class
# -----------------------------------------------------------------------------
#
class TurokShadingPanel(bpy.types.Panel):
    bl_label = "Turok Shading Node"
    bl_idname = "BONE_PT_TurokShadingNodeProp"
    bl_space_type = 'NODE_EDITOR'
    bl_region_type = 'UI'
    bl_context = "Node"
    bl_category = "Turok"
    
    @classmethod
    def poll(cls, context):
        return context.active_node is not None

    def draw(self, context):
        node = context.active_node
        if node.type != "TEX_IMAGE":
            return
        
        layout = self.layout
        row = layout.row()
        row.prop(node.t1, "samplerIndex")
        row = layout.row()
        row.prop(node.t1, "mirrored")
    #end func
    
#end class

# -----------------------------------------------------------------------------
#
def register():
    bpy.utils.register_class(TurokShadingSettings)
    bpy.utils.register_class(TurokShadingPanel)
    bpy.types.ShaderNodeTexImage.t1 = bpy.props.PointerProperty(type=TurokShadingSettings)
#end func

# -----------------------------------------------------------------------------
#     
def unregister():
    bpy.utils.unregister_class(TurokShadingSettings)
    bpy.utils.unregister_class(TurokShadingPanel)
    del bpy.types.ShaderNodeTexImage.t1
#end func
