Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends RSSubMenuButton
- class_name RSFloatingMenu
- const COL_ON := Color.LIGHT_GREEN
- const COL_OFF := Color.LIGHT_SALMON
- @onready var btn_panels: Button = %btn_panels
- @onready var indicators: Control = %indicators
- @onready var ico_mic: TextureRect = %ico_mic
- @onready var ico_brave: TextureRect = %ico_brave
- @onready var ico_stream: TextureRect = %ico_stream
- var is_anchored := true
- var anchored_position: Vector2
- func start(_main: RSMain, _main_menu_button: RSSubMenuButton = null) -> void:
- anchored_position = position
- var _parent : Control = get_parent()
- _parent.resized.connect(func(): calculate_anchored_pos(); is_anchored = false)
- main = _main
- generate_panels_buttons()
- super(_main, self)
- start_indicators()
- main.physic_scene.count_updated.connect(update_obj_count)
- func start_indicators() -> void:
- main.no_obs_ws.scenes_updated.connect(
- func(): ico_mic.modulate = COL_OFF if main.no_obs_ws.is_mic_muted else COL_ON)
- main.no_obs_ws.scenes_updated.connect(
- func(): ico_brave.modulate = COL_OFF if main.no_obs_ws.is_brave_muted else COL_ON)
- main.no_obs_ws.scenes_updated.connect(
- func(): ico_stream.modulate = COL_ON if main.no_obs_ws.is_stream_on else COL_OFF)
- var tot = indicators.get_child_count()
- for i in tot:
- var ind : TextureRect = indicators.get_child(i)
- ind.position = (size/2 - ind.size/2)
- ind.position += Vector2.from_angle(TAU*i/tot + PI/2) * (size.x/2 - ind.size.x/2)
- ico_mic.modulate = COL_OFF if main.no_obs_ws.is_mic_muted else COL_ON
- ico_brave.modulate = COL_OFF if main.no_obs_ws.is_brave_muted else COL_ON
- ico_stream.modulate = COL_ON if main.no_obs_ws.is_stream_on else COL_OFF
- func generate_panels_buttons() -> void:
- if !main.is_node_ready():
- await main.ready
- for pnl: Control in main.pnls:
- var btn := Button.new()
- btn.focus_mode = Control.FOCUS_NONE
- btn.text = pnl.name.lstrip("pnl_").left(3)
- btn.pressed.connect(func(): pnl.visible = !pnl.visible)
- btn_panels.add_child(btn)
- for btn in get_children():
- btn.custom_minimum_size = MIN_SIZE
- btn.add_to_group("UI")
- func update_obj_count(val: int) -> void:
- %lb_count.visible = (val != 0)
- %lb_count.text = str(val)
- 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():
- #var m_pos := get_global_mouse_position()
- var m_pos := global_position + size/2.0
- var w_size := get_window().size / get_tree().root.content_scale_factor
- # find the closest edge first
- 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
- # find the anchor position
- 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)
- func _on_btn_beans_pressed() -> void: main.custom.beans("")
- func _on_btn_laser_pressed() -> void: main.custom.laser()
- func _on_btn_nuke_pressed() -> void: main.physic_scene.nuke()
- func _on_btn_zerog_pressed() -> void: main.custom.zero_g()
- func _on_btn_names_pressed() -> void: main.custom.destructibles_names()
- func _on_btn_granade_pressed() -> void: main.physic_scene.spawn_grenade()
- func _on_btn_close_pressed() -> void:
- main.quit()
- func _on_btn_debug_pressed() -> void:
- main.debug_view.visible = !main.debug_view.visible
- func _on_btn_maximize_pressed() -> void:
- main.display.set_borderless_maximized(!main.display.is_maximized)
- func _on_btn_spam_form_pressed() -> void:
- main.twitcher.chat("Person, you have been invited to join the coolest team https://www.twitch.tv/team/indiegamedevs on Twitch. Compile this form to get an invitation link. Remember that when you get the link: you need to go to Creator Dashboard > Settings > Channel > Featured Content > scroll all the way to the bottom. Here is the form link https://forms.gle/bU2WXAYfoZyVpwWW9")
- OS.shell_open("https://www.twitch.tv/team/indiegamedevs")
- func _on_btn_cig_pressed() -> void:
- main.custom.suggest_no_ads()
- main.custom.toggle_cig_overlay()
- func _on_btn_mic_pressed() -> void:
- main.no_obs_ws.toggle_mic_mute()
- func _on_btn_brave_sound_pressed() -> void:
- main.no_obs_ws.toggle_brave_mute()
- func _on_btn_test_pressed() -> void:
- var param := RSBeansParam.new()
- param.img_paths = ["can.png"]
- param.sfx_paths = ["sfx_boom.wav"]
- param.scale = Vector2.ONE * 0.2
- param.spawn_range = [5, 200]
- param.is_pickable = true
- param.is_destroy = true
- #param.destroy_shard_params
- main.physic_scene.add_image_bodies(param)
- #main.alert_scene.wheel_of_random_raid()
- #var e_theme := EditorInterface.get_editor_theme()
- #ResourceSaver.save(e_theme, "res://godot_4_3.theme")
- #main.twitcher.api.create_custom_rewards()
- #var res := await main.twitcher.api.get_custom_reward([], false, str(TwitchSetting.broadcaster_id))
- #for reward : TwitchCustomReward in res.data:
- #if reward.image:
- #var icon_4 := await main.loader.load_texture_from_url(reward.image.url_4x, false)
- #var icon_2 := await main.loader.load_texture_from_url(reward.image.url_2x, false)
- #var icon_1 := await main.loader.load_texture_from_url(reward.image.url_1x, false)
- #var save_name = "res://ui/rewards_icons/" + reward.title.validate_filename()
- #ResourceSaver.save(icon_4, save_name + "4.png")
- #ResourceSaver.save(icon_2, save_name + "2.png")
- #ResourceSaver.save(icon_1, save_name + "1.png")
- #var u = await main.twitcher.get_teams_users("indiegamedevs")
- #print(u)
- #for username in u:
- #if not username.to_lower() in main.known_users.keys():
- #print(username)
- #var test_text = "{user} something {else}"
- #var prefix = "[color=#f00]"
- #var suffix = "[/color]"
- #var res = RSAlertOverlay.decorate_all_tags(test_text, prefix, suffix)
- #main.twitcher.chat(res)
- ==============================================================================================================
- @icon("res://ui/btn_sub_menu.png")
- extends Button
- class_name RSSubMenuButton
- @export var expand_on_hover := true:
- set(val):
- expand_on_hover = val
- if is_node_ready():
- if val:
- if not mouse_entered.is_connected(expand_menu):
- mouse_entered.connect(expand_menu.bind(true))
- else:
- if mouse_entered.is_connected(expand_menu):
- mouse_entered.disconnect(expand_menu)
- @export var is_radial := false
- @export_range (0.0, 64.0, 0.5) var offset_gap : float = 8:
- set(val):
- offset_gap = val
- expand_menu(is_open)
- @export_range (0.0, 360.0, 0.5) var radial_angle : float = 180:
- set(val):
- radial_angle = val
- _radial_angle_rad = deg_to_rad(radial_angle)
- expand_menu(is_open)
- @export_range (0.0, 0.6, 0.01) var anim_duration = 0.15
- @export_range (0.0, 0.1, 0.001) var anim_delay = 0.03
- const MIN_SIZE = Vector2(48, 48)
- var main: RSMain
- var main_menu_button: RSSubMenuButton
- var tw: Tween
- enum Edge{UP, LEFT, BOT, RIGHT}
- var closest_edge := Edge.RIGHT
- var _radial_angle_rad : float = PI
- var parent: RSSubMenuButton
- var parent_dir := Vector2.DOWN
- var custom_pos := Vector2()
- var is_open := false
- var is_sub_menu := false
- var is_dragged := false
- var is_mouse_click_down := false
- var grabbed_at := Vector2()
- var all_btns : Array[Button]
- signal btn_child_expanded(btn_child: RSSubMenuButton, is_open: bool)
- signal properly_pressed
- func start(_main: RSMain, _main_menu_button: RSSubMenuButton = null) -> void:
- main = _main
- main_menu_button = _main_menu_button
- #tw = create_tween()
- #tw.bind_node(self)
- gui_input.connect(_on_gui_input)
- properly_pressed.connect(toggle_menu)
- if expand_on_hover:
- mouse_entered.connect(expand_menu.bind(true))
- if get_parent() is RSSubMenuButton:
- parent = get_parent()
- is_sub_menu = true
- all_btns = []
- for child in get_children():
- if child is Button:
- all_btns.append(child)
- for btn in all_btns:
- if btn is RSSubMenuButton:
- btn.start(main, main_menu_button)
- btn.btn_child_expanded.connect(_on_btn_child_expanded)
- btn.focus_mode = Control.FOCUS_NONE
- btn.custom_minimum_size = MIN_SIZE
- RSSubMenuButton.assign_texture_to_button_from_icon(btn, 10)
- btn.add_to_group("UI")
- expand_menu(false)
- func _on_btn_child_expanded(btn_expanded: RSSubMenuButton, opened: bool) -> void:
- for btn in all_btns:
- if btn is RSSubMenuButton and btn != btn_expanded and opened:
- btn.expand_menu(false)
- #if not opened:
- #expand_menu(false, btn)
- #else:
- #expand_menu(true, btn)
- func expand_menu(value: bool, except : RSSubMenuButton = null) -> void:
- is_open = value
- if is_sub_menu:
- var parent_center : Vector2 = parent.size/2
- var this_center := size/2 + position
- parent_dir = parent_center.direction_to(this_center)
- var angle_start = 0
- var angle_step = 0
- if is_open and is_radial:
- angle_start = - _radial_angle_rad/2 + parent_dir.angle()
- angle_step = _radial_angle_rad / (all_btns.size()-1)
- if tw:
- tw.kill()
- tw = create_tween()
- tw.bind_node(self)
- tw.set_ease(Tween.EASE_IN_OUT)
- tw.set_trans(Tween.TRANS_CUBIC)
- for i in all_btns.size():
- var btn: Button = all_btns[i]
- if btn == except:
- continue
- var delay : float = i * anim_delay
- var new_pos := size / 2.0 -(btn.size / 2.0)
- if is_open:
- if btn is RSSubMenuButton and btn.custom_pos != Vector2():
- new_pos = btn.custom_pos.rotated(main_menu_button.parent_dir.angle())
- elif is_radial:
- new_pos += Vector2.from_angle(angle_start + i * angle_step) * (size.x + offset_gap)
- else:
- new_pos += parent_dir * (i+1) * (size.x + offset_gap)
- btn.visible = true
- else:
- if btn.has_method("expand_menu"):
- btn.expand_menu(false)
- tw.parallel().tween_property(btn, "visible", is_open, anim_duration).set_delay(delay)
- tw.parallel().tween_property(btn, "position", new_pos, anim_duration).set_delay(delay)
- tw.parallel().tween_property(btn, "modulate:a", 1 if is_open else 0, anim_duration).set_delay(delay)
- btn_child_expanded.emit(self, is_open)
- func toggle_menu():
- expand_menu(!is_open)
- func _process(d: float) -> void:
- if is_dragged:
- position = position.lerp(get_parent().get_local_mouse_position() - grabbed_at, d*10)
- func _on_gui_input(event: InputEvent) -> void:
- if event is InputEventMouseButton:
- if event.button_index == MOUSE_BUTTON_LEFT:
- is_mouse_click_down = event.is_pressed()
- if is_mouse_click_down:
- grabbed_at = event.position
- elif is_dragged:
- custom_pos = position.rotated(-main_menu_button.parent_dir.angle())
- is_dragged = false
- if event.button_index == MOUSE_BUTTON_RIGHT:
- custom_pos = Vector2()
- if is_sub_menu:
- expand_menu(false)
- parent.expand_menu(parent.is_open)
- if event is InputEventMouseMotion and is_mouse_click_down:
- is_dragged = true
- if is_open:
- expand_menu(false)
- func _pressed() -> void:
- if is_dragged: return
- properly_pressed.emit()
- static func assign_texture_to_button_from_icon(btn: Button, offset: float) -> void:
- var tex = btn.icon
- if not tex: return
- btn.icon = null
- var normal_col = btn.get_theme_color("icon_normal_color")
- var pressed_col = btn.get_theme_color("icon_pressed_color")
- var hover_col = btn.get_theme_color("icon_hover_color")
- var tex_rect = TextureRect.new()
- tex_rect.name = "ico"
- tex_rect.texture = tex
- tex_rect.mouse_filter = Control.MOUSE_FILTER_IGNORE
- tex_rect.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
- tex_rect.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
- tex_rect.modulate = normal_col
- tex_rect.set_anchor_and_offset(SIDE_TOP, 0, offset)
- tex_rect.set_anchor_and_offset(SIDE_LEFT, 0, offset)
- tex_rect.set_anchor_and_offset(SIDE_RIGHT, 1, -offset)
- tex_rect.set_anchor_and_offset(SIDE_BOTTOM, 1, -offset)
- btn.mouse_exited.connect(func(): tex_rect.modulate = normal_col)
- btn.mouse_entered.connect(func(): tex_rect.modulate = hover_col)
- btn.pressed.connect(func(): tex_rect.modulate = pressed_col)
- btn.add_child(tex_rect)
- btn.size = btn.custom_minimum_size
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement