"""
VNGE CustomWindow skin
1.0

you must set
- funcSetup (optionally)
- funcWindowGUI (must!)
before call game.set_skin(skin) call

1.1 (Countd360)
- all window using this skin will be dragable and eat mouse input within the window by default
- you can disable these feature by set dragWindow or eatMouseInput to False
- Notice, if enable eatMouseInput, some input infomation may lost

1.2 (Countd360)
- do not eat keyboard input when eatMouseInput = True

1.3 (Countd360)
- load global scale setting as default

"""

from vngameengine import *

import UnityEngine
#import GameCursor, CameraControl
from UnityEngine import GUI, GUILayout, GUIStyle, GUIContent, GUIUtility, Screen, Rect, Vector3, Input, KeyCode, Vector2
from UnityEngine import Event, EventType, WaitForSeconds, GameObject, Mathf, Time, Matrix4x4
import System

def get_skin():
    return SkinCustomWindow()

class SkinCustomWindow(SkinBase):
    def __init__(self):
        SkinBase.__init__(self)
        self.name = "skin_customwindow"

        self.isCustomFuncWindowGUI = True

        self.funcSetup = None
        self.funcWindowGUI = None

        self.controller = None
        
        self.eatMouseInput = True
        self.dragWindow = True

    def setup(self,controller):
        self.controller = controller

        from vngameengine import vnge_game
        self.controller.SetWindowScale(vnge_game.windowScale)
        self.controller.windowPosLimit = vnge_game.windowPosLimit

        #controller.call_game_func(self.funcSetup)
        self.funcSetup(self.controller)

    def customWindowGUI(self, windowid):
        if self.funcWindowGUI:
            # call GUI function
            self.funcWindowGUI(self.controller, windowid)

            # drag window
            if self.dragWindow:
                GUI.DragWindow()
            
            # eat mouse input
            if self.eatMouseInput and (Input.GetMouseButton(0) or Input.GetMouseButton(1) or Input.GetMouseButton(2)) and self.controller.ScaledWindowRect.Contains(Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y)):
                Input.ResetInputAxes()


