Advertisement
iRadEntertainment

Iradoverlaythingveryhot

Nov 3rd, 2024
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
GDScript 12.69 KB | Gaming | 0 0
  1. extends RSSubMenuButton
  2. class_name RSFloatingMenu
  3.  
  4. const COL_ON := Color.LIGHT_GREEN
  5. const COL_OFF := Color.LIGHT_SALMON
  6.  
  7. @onready var btn_panels: Button = %btn_panels
  8. @onready var indicators: Control = %indicators
  9. @onready var ico_mic: TextureRect = %ico_mic
  10. @onready var ico_brave: TextureRect = %ico_brave
  11. @onready var ico_stream: TextureRect = %ico_stream
  12.  
  13. var is_anchored := true
  14. var anchored_position: Vector2
  15.  
  16.  
  17. func start(_main: RSMain, _main_menu_button: RSSubMenuButton = null) -> void:
  18.     anchored_position = position
  19.     var _parent : Control = get_parent()
  20.     _parent.resized.connect(func(): calculate_anchored_pos(); is_anchored = false)
  21.     main = _main
  22.     generate_panels_buttons()
  23.     super(_main, self)
  24.     start_indicators()
  25.     main.physic_scene.count_updated.connect(update_obj_count)
  26.  
  27. func start_indicators() -> void:
  28.     main.no_obs_ws.scenes_updated.connect(
  29.         func(): ico_mic.modulate = COL_OFF if main.no_obs_ws.is_mic_muted else COL_ON)
  30.     main.no_obs_ws.scenes_updated.connect(
  31.         func(): ico_brave.modulate = COL_OFF if main.no_obs_ws.is_brave_muted else COL_ON)
  32.     main.no_obs_ws.scenes_updated.connect(
  33.         func(): ico_stream.modulate = COL_ON if main.no_obs_ws.is_stream_on else COL_OFF)
  34.    
  35.     var tot = indicators.get_child_count()
  36.     for i in tot:
  37.         var ind : TextureRect = indicators.get_child(i)
  38.         ind.position = (size/2 - ind.size/2)
  39.         ind.position += Vector2.from_angle(TAU*i/tot + PI/2) * (size.x/2 - ind.size.x/2)
  40.    
  41.     ico_mic.modulate = COL_OFF if main.no_obs_ws.is_mic_muted else COL_ON
  42.     ico_brave.modulate = COL_OFF if main.no_obs_ws.is_brave_muted else COL_ON
  43.     ico_stream.modulate = COL_ON if main.no_obs_ws.is_stream_on else COL_OFF
  44.  
  45. func generate_panels_buttons() -> void:
  46.     if !main.is_node_ready():
  47.         await main.ready
  48.     for pnl: Control in main.pnls:
  49.         var btn := Button.new()
  50.         btn.focus_mode = Control.FOCUS_NONE
  51.         btn.text = pnl.name.lstrip("pnl_").left(3)
  52.         btn.pressed.connect(func(): pnl.visible = !pnl.visible)
  53.         btn_panels.add_child(btn)
  54.     for btn in get_children():
  55.         btn.custom_minimum_size = MIN_SIZE
  56.         btn.add_to_group("UI")
  57.  
  58.  
  59. func update_obj_count(val: int) -> void:
  60.     %lb_count.visible = (val != 0)
  61.     %lb_count.text = str(val)
  62.  
  63.  
  64. func _process(d: float) -> void:
  65.     super(d)
  66.     if not is_anchored and not is_dragged:
  67.         position = position.lerp(anchored_position, d*10)
  68.         if position.distance_squared_to(anchored_position) < 1:
  69.             position = anchored_position
  70.             is_anchored = true
  71.  
  72. func _on_gui_input(event: InputEvent) -> void:
  73.     super(event)
  74.     if event is InputEventMouseButton:
  75.         if event.button_index == MOUSE_BUTTON_LEFT:
  76.             if not event.is_pressed():
  77.                 is_anchored = false
  78.                 calculate_anchored_pos()
  79.     if event is InputEventMouseMotion and is_mouse_click_down:
  80.         if is_open:
  81.             expand_menu(false)
  82.  
  83.  
  84. func calculate_anchored_pos():
  85.     #var m_pos := get_global_mouse_position()
  86.     var m_pos := global_position + size/2.0
  87.     var w_size := get_window().size / get_tree().root.content_scale_factor
  88.     # find the closest edge first
  89.     if min(m_pos.x, abs(w_size.x - m_pos.x)) < min(m_pos.y, abs(w_size.y - m_pos.y)):
  90.         closest_edge = Edge.LEFT if m_pos.x < abs(w_size.x - m_pos.x) else Edge.RIGHT
  91.     else:
  92.         closest_edge = Edge.UP if m_pos.y < abs(w_size.y - m_pos.y) else Edge.BOT
  93.     # find the anchor position
  94.     match closest_edge:
  95.         Edge.UP:
  96.             anchored_position = Vector2(position.x, 0)
  97.             parent_dir = Vector2.DOWN
  98.         Edge.RIGHT:
  99.             anchored_position = Vector2(w_size.x - size.x, position.y)
  100.             parent_dir = Vector2.LEFT
  101.         Edge.BOT:
  102.             anchored_position = Vector2(position.x, w_size.y - size.y)
  103.             parent_dir = Vector2.UP
  104.         Edge.LEFT:
  105.             anchored_position = Vector2(0, position.y)
  106.             parent_dir = Vector2.RIGHT
  107.    
  108.     anchored_position = anchored_position.clamp(Vector2(), Vector2(w_size)-size)
  109.  
  110.  
  111. func _on_btn_beans_pressed() -> void: main.custom.beans("")
  112. func _on_btn_laser_pressed() -> void: main.custom.laser()
  113. func _on_btn_nuke_pressed() -> void: main.physic_scene.nuke()
  114. func _on_btn_zerog_pressed() -> void: main.custom.zero_g()
  115. func _on_btn_names_pressed() -> void: main.custom.destructibles_names()
  116. func _on_btn_granade_pressed() -> void: main.physic_scene.spawn_grenade()
  117.  
  118. func _on_btn_close_pressed() -> void:
  119.     main.quit()
  120. func _on_btn_debug_pressed() -> void:
  121.     main.debug_view.visible = !main.debug_view.visible
  122. func _on_btn_maximize_pressed() -> void:
  123.     main.display.set_borderless_maximized(!main.display.is_maximized)
  124.  
  125. func _on_btn_spam_form_pressed() -> void:
  126.     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")
  127.     OS.shell_open("https://www.twitch.tv/team/indiegamedevs")
  128. func _on_btn_cig_pressed() -> void:
  129.     main.custom.suggest_no_ads()
  130.     main.custom.toggle_cig_overlay()
  131. func _on_btn_mic_pressed() -> void:
  132.     main.no_obs_ws.toggle_mic_mute()
  133. func _on_btn_brave_sound_pressed() -> void:
  134.     main.no_obs_ws.toggle_brave_mute()
  135.  
  136.  
  137. func _on_btn_test_pressed() -> void:
  138.     var param := RSBeansParam.new()
  139.     param.img_paths = ["can.png"]
  140.     param.sfx_paths = ["sfx_boom.wav"]
  141.     param.scale = Vector2.ONE * 0.2
  142.     param.spawn_range = [5, 200]
  143.     param.is_pickable = true
  144.     param.is_destroy = true
  145.    
  146.     #param.destroy_shard_params
  147.    
  148.    
  149.     main.physic_scene.add_image_bodies(param)
  150.    
  151.    
  152.     #main.alert_scene.wheel_of_random_raid()
  153.     #var e_theme := EditorInterface.get_editor_theme()
  154.     #ResourceSaver.save(e_theme, "res://godot_4_3.theme")
  155.     #main.twitcher.api.create_custom_rewards()
  156.    
  157.     #var res := await main.twitcher.api.get_custom_reward([], false, str(TwitchSetting.broadcaster_id))
  158.     #for reward : TwitchCustomReward in res.data:
  159.         #if reward.image:
  160.             #var icon_4 := await main.loader.load_texture_from_url(reward.image.url_4x, false)
  161.             #var icon_2 := await main.loader.load_texture_from_url(reward.image.url_2x, false)
  162.             #var icon_1 := await main.loader.load_texture_from_url(reward.image.url_1x, false)
  163.             #var save_name = "res://ui/rewards_icons/" + reward.title.validate_filename()
  164.             #ResourceSaver.save(icon_4, save_name + "4.png")
  165.             #ResourceSaver.save(icon_2, save_name + "2.png")
  166.             #ResourceSaver.save(icon_1, save_name + "1.png")
  167.    
  168.     #var u = await main.twitcher.get_teams_users("indiegamedevs")
  169.     #print(u)
  170.     #for username in u:
  171.         #if not username.to_lower() in main.known_users.keys():
  172.             #print(username)
  173.     #var test_text = "{user} something {else}"
  174.     #var prefix = "[color=#f00]"
  175.     #var suffix = "[/color]"
  176.     #var res = RSAlertOverlay.decorate_all_tags(test_text, prefix, suffix)
  177.     #main.twitcher.chat(res)
  178.  
  179. ==============================================================================================================
  180. @icon("res://ui/btn_sub_menu.png")
  181. extends Button
  182. class_name RSSubMenuButton
  183.  
  184. @export var expand_on_hover := true:
  185.     set(val):
  186.         expand_on_hover = val
  187.         if is_node_ready():
  188.             if val:
  189.                 if not mouse_entered.is_connected(expand_menu):
  190.                     mouse_entered.connect(expand_menu.bind(true))
  191.             else:
  192.                 if mouse_entered.is_connected(expand_menu):
  193.                     mouse_entered.disconnect(expand_menu)
  194. @export var is_radial := false
  195. @export_range (0.0, 64.0, 0.5) var offset_gap : float = 8:
  196.     set(val):
  197.         offset_gap = val
  198.         expand_menu(is_open)
  199. @export_range (0.0, 360.0, 0.5) var radial_angle : float = 180:
  200.     set(val):
  201.         radial_angle = val
  202.         _radial_angle_rad = deg_to_rad(radial_angle)
  203.         expand_menu(is_open)
  204.  
  205. @export_range (0.0, 0.6, 0.01) var anim_duration = 0.15
  206. @export_range (0.0, 0.1, 0.001) var anim_delay = 0.03
  207. const MIN_SIZE = Vector2(48, 48)
  208.  
  209. var main: RSMain
  210. var main_menu_button: RSSubMenuButton
  211. var tw: Tween
  212.  
  213. enum Edge{UP, LEFT, BOT, RIGHT}
  214. var closest_edge := Edge.RIGHT
  215.  
  216. var _radial_angle_rad : float = PI
  217. var parent: RSSubMenuButton
  218. var parent_dir := Vector2.DOWN
  219. var custom_pos := Vector2()
  220.  
  221. var is_open := false
  222. var is_sub_menu := false
  223. var is_dragged := false
  224. var is_mouse_click_down := false
  225. var grabbed_at := Vector2()
  226. var all_btns : Array[Button]
  227.  
  228. signal btn_child_expanded(btn_child: RSSubMenuButton, is_open: bool)
  229. signal properly_pressed
  230.  
  231.  
  232. func start(_main: RSMain, _main_menu_button: RSSubMenuButton = null) -> void:
  233.     main = _main
  234.     main_menu_button = _main_menu_button
  235.     #tw = create_tween()
  236.     #tw.bind_node(self)
  237.    
  238.     gui_input.connect(_on_gui_input)
  239.     properly_pressed.connect(toggle_menu)
  240.     if expand_on_hover:
  241.         mouse_entered.connect(expand_menu.bind(true))
  242.    
  243.     if get_parent() is RSSubMenuButton:
  244.         parent = get_parent()
  245.         is_sub_menu = true
  246.    
  247.     all_btns = []
  248.     for child in get_children():
  249.         if child is Button:
  250.             all_btns.append(child)
  251.    
  252.     for btn in all_btns:
  253.         if btn is RSSubMenuButton:
  254.             btn.start(main, main_menu_button)
  255.             btn.btn_child_expanded.connect(_on_btn_child_expanded)
  256.         btn.focus_mode = Control.FOCUS_NONE
  257.         btn.custom_minimum_size = MIN_SIZE
  258.         RSSubMenuButton.assign_texture_to_button_from_icon(btn, 10)
  259.         btn.add_to_group("UI")
  260.     expand_menu(false)
  261.  
  262. func _on_btn_child_expanded(btn_expanded: RSSubMenuButton, opened: bool) -> void:
  263.     for btn in all_btns:
  264.         if btn is RSSubMenuButton and btn != btn_expanded and opened:
  265.             btn.expand_menu(false)
  266.     #if not opened:
  267.         #expand_menu(false, btn)
  268.     #else:
  269.         #expand_menu(true, btn)
  270.  
  271. func expand_menu(value: bool, except : RSSubMenuButton = null) -> void:
  272.     is_open = value
  273.     if is_sub_menu:
  274.         var parent_center : Vector2 = parent.size/2
  275.         var this_center := size/2 + position
  276.         parent_dir = parent_center.direction_to(this_center)
  277.    
  278.     var angle_start = 0
  279.     var angle_step = 0
  280.     if is_open and is_radial:
  281.         angle_start = - _radial_angle_rad/2 + parent_dir.angle()
  282.         angle_step = _radial_angle_rad / (all_btns.size()-1)
  283.    
  284.     if tw:
  285.         tw.kill()
  286.     tw = create_tween()
  287.     tw.bind_node(self)
  288.     tw.set_ease(Tween.EASE_IN_OUT)
  289.     tw.set_trans(Tween.TRANS_CUBIC)
  290.     for i in all_btns.size():
  291.         var btn: Button = all_btns[i]
  292.         if btn == except:
  293.             continue
  294.         var delay : float = i * anim_delay
  295.         var new_pos := size / 2.0 -(btn.size / 2.0)
  296.         if is_open:
  297.             if btn is RSSubMenuButton and btn.custom_pos != Vector2():
  298.                 new_pos = btn.custom_pos.rotated(main_menu_button.parent_dir.angle())
  299.             elif is_radial:
  300.                 new_pos += Vector2.from_angle(angle_start + i * angle_step) * (size.x + offset_gap)
  301.             else:
  302.                 new_pos += parent_dir * (i+1) * (size.x + offset_gap)
  303.             btn.visible = true
  304.         else:
  305.             if btn.has_method("expand_menu"):
  306.                 btn.expand_menu(false)
  307.             tw.parallel().tween_property(btn, "visible", is_open, anim_duration).set_delay(delay)
  308.         tw.parallel().tween_property(btn, "position", new_pos, anim_duration).set_delay(delay)
  309.         tw.parallel().tween_property(btn, "modulate:a", 1 if is_open else 0, anim_duration).set_delay(delay)
  310.        
  311.         btn_child_expanded.emit(self, is_open)
  312.  
  313.  
  314. func toggle_menu():
  315.     expand_menu(!is_open)
  316.  
  317.  
  318. func _process(d: float) -> void:
  319.     if is_dragged:
  320.         position = position.lerp(get_parent().get_local_mouse_position() - grabbed_at, d*10)
  321.  
  322. func _on_gui_input(event: InputEvent) -> void:
  323.     if event is InputEventMouseButton:
  324.         if event.button_index == MOUSE_BUTTON_LEFT:
  325.             is_mouse_click_down = event.is_pressed()
  326.             if is_mouse_click_down:
  327.                 grabbed_at = event.position
  328.             elif is_dragged:
  329.                 custom_pos = position.rotated(-main_menu_button.parent_dir.angle())
  330.                 is_dragged = false
  331.         if event.button_index == MOUSE_BUTTON_RIGHT:
  332.             custom_pos = Vector2()
  333.             if is_sub_menu:
  334.                 expand_menu(false)
  335.                 parent.expand_menu(parent.is_open)
  336.     if event is InputEventMouseMotion and is_mouse_click_down:
  337.         is_dragged = true
  338.         if is_open:
  339.             expand_menu(false)
  340.  
  341. func _pressed() -> void:
  342.     if is_dragged: return
  343.     properly_pressed.emit()
  344.  
  345.  
  346. static func assign_texture_to_button_from_icon(btn: Button, offset: float) -> void:
  347.     var tex = btn.icon
  348.     if not tex: return
  349.     btn.icon = null
  350.     var normal_col = btn.get_theme_color("icon_normal_color")
  351.     var pressed_col = btn.get_theme_color("icon_pressed_color")
  352.     var hover_col = btn.get_theme_color("icon_hover_color")
  353.     var tex_rect = TextureRect.new()
  354.     tex_rect.name = "ico"
  355.     tex_rect.texture = tex
  356.     tex_rect.mouse_filter = Control.MOUSE_FILTER_IGNORE
  357.     tex_rect.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
  358.     tex_rect.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
  359.     tex_rect.modulate = normal_col
  360.     tex_rect.set_anchor_and_offset(SIDE_TOP, 0, offset)
  361.     tex_rect.set_anchor_and_offset(SIDE_LEFT, 0, offset)
  362.     tex_rect.set_anchor_and_offset(SIDE_RIGHT, 1, -offset)
  363.     tex_rect.set_anchor_and_offset(SIDE_BOTTOM, 1, -offset)
  364.     btn.mouse_exited.connect(func(): tex_rect.modulate = normal_col)
  365.     btn.mouse_entered.connect(func(): tex_rect.modulate = hover_col)
  366.     btn.pressed.connect(func(): tex_rect.modulate = pressed_col)
  367.     btn.add_child(tex_rect)
  368.     btn.size = btn.custom_minimum_size
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement