extends GDSubMenuButton class_name GDFloatingMenu const COL_ON := Color.LIGHT_GREEN const COL_OFF := Color.LIGHT_SALMON const SETTINGS_PANEL = preload("res://UI/settings_panel.tscn") const SCRIPT_EDITOR = preload("res://UI/Controls/script_editor.tscn") # Indicators @onready var indicators: Control = %indicators @onready var ind_stream: TextureRect = %ind_stream @onready var ind_mic: TextureRect = %ind_mic @onready var ind_pixelate: TextureRect = %ind_pixelate @onready var ind_browser: TextureRect = %ind_browser # Buttons @onready var btn_obs: GDSubMenuButton = %btn_obs @onready var btn_run_obs: GDSubMenuButton = %btn_run_obs @onready var btn_step_away: GDSubMenuButton = %btn_step_away @onready var btn_tuber: GDSubMenuButton = %btn_tuber @onready var btn_chat: GDSubMenuButton = %btn_chat @onready var btn_script_editor: GDSubMenuButton = %btn_script_editor @onready var btn_user_list: GDSubMenuButton = %btn_user_list @onready var btn_settings: GDSubMenuButton = %btn_settings @onready var btn_end: GDSubMenuButton = %btn_end var is_anchored := true var anchored_position: Vector2 var _set_win: Window var _edit_win: Window func start(_main_menu_button: GDSubMenuButton = null) -> void: anchored_position = position var _parent: Control = get_parent() _parent.resized.connect(func(): calculate_anchored_pos(); is_anchored = false) generate_panels_buttons() super(self) start_indicators() _connect_signals() func start_indicators() -> void: # TODO: Setup NO-OBS-WS Stuff var tot = indicators.get_child_count() for i in tot: var ind: TextureRect = indicators.get_child(i) ind.show() ind.position = (size/2 - ind.size/2) ind.position += Vector2.from_angle(TAU*i/tot + PI/2) * (size.x/2 - ind.size.x/2) pass func generate_panels_buttons() -> void: # TODO: Generate Panels? pass func _process(d: float) -> void: super(d) if not is_anchored and not is_dragged: position = position.lerp(anchored_position, d*10) if position.distance_squared_to(anchored_position) < 1: position = anchored_position is_anchored = true func _on_gui_input(event: InputEvent) -> void: super(event) if event is InputEventMouseButton: if event.button_index == MOUSE_BUTTON_LEFT: if not event.is_pressed(): is_anchored = false calculate_anchored_pos() if event is InputEventMouseMotion and is_mouse_click_down: if is_open: expand_menu(false) func calculate_anchored_pos() -> void: var m_pos := global_position + size/2.0 var w_size := get_window().size / get_tree().root.content_scale_factor if min(m_pos.x, abs(w_size.x - m_pos.x)) < min(m_pos.y, abs(w_size.y - m_pos.y)): closest_edge = Edge.LEFT if m_pos.x < abs(w_size.x - m_pos.x) else Edge.RIGHT else: closest_edge = Edge.UP if m_pos.y < abs(w_size.y - m_pos.y) else Edge.BOT match closest_edge: Edge.UP: anchored_position = Vector2(position.x, 0) parent_dir = Vector2.DOWN Edge.RIGHT: anchored_position = Vector2(w_size.x - size.x, position.y) parent_dir = Vector2.LEFT Edge.BOT: anchored_position = Vector2(position.x, w_size.y - size.y) parent_dir = Vector2.UP Edge.LEFT: anchored_position = Vector2(0, position.y) parent_dir = Vector2.RIGHT anchored_position = anchored_position.clamp(Vector2(), Vector2(w_size)-size) #region Hnadle Button Functions func _connect_signals() -> void: btn_end.properly_pressed.connect(func(): get_tree().quit()) btn_settings.properly_pressed.connect(_handle_settings) btn_script_editor.properly_pressed.connect(_handle_script_editor) btn_run_obs.properly_pressed.connect(_handle_run_obs) func _handle_settings() -> void: if _set_win: return var win := Window.new() win.borderless = false win.always_on_top = false win.mode = Window.MODE_WINDOWED var pnl := SETTINGS_PANEL.instantiate() #Globals.disable_mouse_passthrough() win.add_child(pnl) win.size = Vector2i(1000,800) win.close_requested.connect(func(): win.queue_free(); _set_win = null) win.name = "SettingsWindow" win.title = "Settings" get_tree().root.add_child(win) win.show() _set_win = win func _handle_script_editor() -> void: if _edit_win: return var win := Window.new() win.borderless = false win.always_on_top = false win.mode = Window.MODE_WINDOWED var pnl := SCRIPT_EDITOR.instantiate() win.name = "ScriptEditorWindow" win.title = "Script Editor" win.add_child(pnl) win.size = Vector2i(800,600) win.close_requested.connect(func(): win.queue_free(); _edit_win = null) get_tree().root.add_child(win) win.show() _edit_win = win func _handle_run_obs() -> void: EventManager.test_notification("Hello World!") #endregion