extends Node var debug:bool = true func _ready(): randomize() func get_time_text() -> String: var time = Time.get_datetime_dict_from_system() return "%s/%02d/%02d %02d:%02d:%02d" % [ time['year'], time['month'], time['day'], time['hour'], time['minute'], time['second'], ] func get_time_only_text() -> String: var time = Time.get_datetime_dict_from_system() return "%02d:%02d:%02d" % [ time['hour'], time['minute'], time['second'], ] func msg_debug(text): if debug: var frame = get_stack()[1] print("%s DEBUG [%s:%d] %s" % [get_time_text(), frame.source, frame.line, text] ) func msg_info(text): var frame = get_stack()[1] print("%s INFO [%s:%d] %s" % [get_time_text(), frame.source, frame.line, text] ) func msg_error(text): var frame = get_stack()[1] print("%s ERROR [%s:%d] %s" % [get_time_text(), frame.source, frame.line, text] ) func get_string_input_mousse_button(event:InputEventMouseButton) -> String: match event.get_button_index(): 1: return "BUTTON_LEFT" 3: return "BUTTON_MIDDLE" 2: return "BUTTON_RIGHT" 4: return "BUTTON_WHEEL_UP" 5: return "BUTTON_WHEEL_DOWN" 6: return "BUTTON_WHEEL_LEFT" 7: return "BUTTON_WHEEL_RIGHT" 8: return "BUTTON_XBUTTON1" 9: return "BUTTON_XBUTTON2" _: return "MOUSSE BUTTON: " + str(event.get_button_index()) func get_string_input_joypad_button(event:InputEventJoypadButton) -> String: match event.get_button_index(): 0: return "JOY_BUTTON_A" 1: return "JOY_BUTTON_B" 2: return "JOY_BUTTON_X" 3: return "JOY_BUTTON_Y" 4: return "JOY_BUTTON_BACK" 5: return "JOY_BUTTON_GUIDE" 6: return "JOY_BUTTON_START" 7: return "JOY_BUTTON_LEFT_STICK" 8: return "JOY_BUTTON_RIGHT_STICK" 9: return "JOY_BUTTON_LEFT_SHOULDER" 10: return "JOY_BUTTON_RIGHT_SHOULDER" 11: return "JOY_BUTTON_DPAD_UP" 12: return "JOY_BUTTON_DPAD_DOWN" 13: return "JOY_BUTTON_DPAD_LEFT" 14: return "JOY_BUTTON_DPAD_RIGHT" _: return "JOYPAD BUTTON: " + str(event.get_button_index()) func get_string_input_keyboard(event:InputEventKey) -> String: var option:String = "" if event.is_ctrl_pressed(): option += "Control+" if event.is_shift_pressed(): option += "Shift+" if event.is_alt_pressed(): option += "Alt+" if event.is_meta_pressed(): option += "MetaKey+" # if event.is_command_pressed(): # option += "Command+" if event.keycode == 0: if event.physical_keycode > 0: return option + OS.get_keycode_string(event.physical_keycode) else: print("Error Event unknown keycode:" , event.keycode, ", physical_keycode:", event.physical_keycode) return option + OS.get_keycode_string(event.keycode) func get_string_input(event) -> String: if event is InputEventKey: return get_string_input_keyboard(event) # OS.get_scancode_string(event.get_scancode_with_modifiers()) elif event is InputEventMouseButton: return get_string_input_mousse_button(event) elif event is InputEventJoypadButton: return get_string_input_joypad_button(event) else: return str(event) #func compare_type_event(event1, event2): # if event1 is InputEventKey and event2 is InputEventKey: # return true # elif event1 is InputEventMouseButton and event2 is InputEventMouseButton: # return true # elif event1 is InputEventJoypadButton and event2 is InputEventJoypadButton: # return true # return false func get_event_plus_ref(action:String, event_ref): if event_ref is InputEventMouseButton and InputMap.has_action(action + "_PLUS"): for z in InputMap.action_get_events(action + "_PLUS"): if z is InputEventMouseButton: return z return null func get_input_plus_event(action:String, event_ref): if event_ref is InputEventMouseButton and InputMap.has_action(action + "_PLUS"): for z in InputMap.action_get_events(action + "_PLUS"): if z is InputEventMouseButton: return " & " + tr(Common.get_string_input(z)) return "" func get_input_plus(action:String): var comment:String = "None" if InputMap.has_action(action): for z in InputMap.action_get_events(action): return tr(Common.get_string_input(z)) + get_input_plus_event(action, z) # Common.msg_debug(comment) # #$Window/Tab/MOUSE/HBox/SelectButton.set_text(text1) # break # if InputMap.has_action(action + "_PLUS"): # for z in InputMap.action_get_events(action + "_PLUS"): # if z is InputEventMouseButton: # comment = comment + " & " + tr(Common.get_string_input(z)) # Common.msg_debug(comment) # break return comment func set_input(action:String, event, origin, eraselast:bool): if eraselast: for curaction in InputMap.get_actions(): var text:String = curaction if text == action: for z in InputMap.action_get_events(curaction): if origin is InputEventMouseButton and z is InputEventMouseButton: InputMap.action_erase_event(text, z) if event != null: InputMap.action_add_event(action, event) func set_input_plus(action:String, event, eventplus, eraselast:bool): set_input(action, event, event, eraselast) set_input(action + "_PLUS", eventplus, event, eraselast)