Advertisement
Guest User

camera_control_gui.gd

a guest
Jun 11th, 2020
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.44 KB | None | 0 0
  1. # camera_control_gui.gd. Modified by Tobias Lindström to make the GUI not appear
  2.  
  3. # Licensed under the MIT License.
  4. # Copyright (c) 2018 Jaccomo Lorenz (Maujoe)
  5.  
  6. extends Control
  7.  
  8. # Constant Gui Settings
  9. #*******************************************************************************
  10. const GUI_POS = Vector2(10, 10)
  11. const GUI_SIZE = Vector2(200, 0)
  12. const DRAGGABLE = true
  13.  
  14. const CUSTOM_BACKGROUND = false
  15. const BACKGROUND_COLOR = Color(0.15, 0.17, 0.23, 0.75)
  16.  
  17. const MAX_SPEED = 50
  18. #*******************************************************************************
  19.  
  20. var camera
  21. var shortcut
  22. var node_list
  23. var privot
  24. var panel
  25.  
  26. var mouse_over = false
  27. var mouse_pressed = false
  28.  
  29. func _init(camera, shortcut):
  30. self.camera = camera
  31. self.shortcut = shortcut
  32.  
  33. func _ready():
  34. if camera.enabled:
  35. set_process_input(true)
  36.  
  37. # Create Gui
  38. # panel = PanelContainer.new()
  39. # panel.set_begin(GUI_POS)
  40. # panel.set_custom_minimum_size(GUI_SIZE)
  41. #
  42. # if CUSTOM_BACKGROUND:
  43. # var style = StyleBoxFlat.new()
  44. # style.set_bg_color(BACKGROUND_COLOR)
  45. # style.set_expand_margin_all(5)
  46. # panel.add_stylebox_override("panel", style)
  47. #
  48. # var container = VBoxContainer.new()
  49. #
  50. # var lbl_mouse = Label.new()
  51. # lbl_mouse.set_text("Mousemode")
  52. #
  53. # var mouse = OptionButton.new()
  54. # mouse.add_item("Visible")
  55. # mouse.add_item("Hidden")
  56. # mouse.add_item("Captured")
  57. # mouse.add_item("Confined")
  58. # mouse.select(camera.mouse_mode)
  59. # mouse.connect("item_selected",self,"_on_opt_mouse_item_selected")
  60.  
  61. # Mouselook
  62. var mouselook = CheckButton.new()
  63. mouselook.set_text("Mouselook")
  64. mouselook.set_toggle_mode(true)
  65. mouselook.set_pressed(camera.mouselook)
  66. mouselook.connect("toggled",self,"_on_btn_mouselook_toggled")
  67.  
  68. var lbl_sensitivity = Label.new()
  69. lbl_sensitivity.set_text("Sensitivity")
  70.  
  71. var sensitivity = HScrollBar.new()
  72. sensitivity.set_max(1)
  73. sensitivity.set_value(camera.sensitivity)
  74. sensitivity.connect("value_changed",self,"_on_hsb_sensitivity_value_changed")
  75.  
  76. var lbl_smoothless = Label.new()
  77. lbl_smoothless.set_text("Smoothness")
  78.  
  79. var smoothness = HScrollBar.new()
  80. smoothness.set_max(0.999)
  81. smoothness.set_min(0.5)
  82. smoothness.set_value(camera.smoothness)
  83. smoothness.connect("value_changed",self,"_on_hsb_smoothness_value_changed")
  84.  
  85. var lbl_privot = Label.new()
  86. lbl_privot.set_text("Privot")
  87.  
  88. privot = OptionButton.new()
  89. privot.set_text("Privot")
  90. _update_privots(privot)
  91. privot.connect("item_selected",self,"_on_opt_privot_item_selected")
  92. privot.connect("pressed",self,"_on_opt_privot_pressed")
  93.  
  94. var btn_rot_privot = CheckButton.new()
  95. btn_rot_privot.set_text("Rotate Privot")
  96. btn_rot_privot.set_toggle_mode(true)
  97. btn_rot_privot.set_pressed(camera.rotate_privot)
  98. btn_rot_privot.connect("toggled",self,"_on_btn_rot_privot_toggled")
  99.  
  100. var lbl_distance = Label.new()
  101. lbl_distance.set_text("Distance")
  102.  
  103. var distance = SpinBox.new()
  104. distance.set_value(camera.distance)
  105. distance.connect("value_changed",self,"_on_box_distance_value_changed")
  106.  
  107. var lbl_yaw = Label.new()
  108. lbl_yaw.set_text("Yaw Limit")
  109.  
  110. var yaw = SpinBox.new()
  111. yaw.set_max(360)
  112. yaw.set_value(camera.yaw_limit)
  113. yaw.connect("value_changed",self,"_on_box_yaw_value_changed")
  114.  
  115. var lbl_pitch = Label.new()
  116. lbl_pitch.set_text("Pitch Limit")
  117.  
  118. var pitch = SpinBox.new()
  119. pitch.set_max(360)
  120. pitch.set_value(camera.pitch_limit)
  121. pitch.connect("value_changed",self,"_on_box_pitch_value_changed")
  122.  
  123. var collisions = CheckButton.new()
  124. collisions.set_text("Collisions")
  125. collisions.set_toggle_mode(true)
  126. collisions.set_pressed(camera.collisions)
  127. collisions.connect("toggled",self,"_on_btn_collisions_toggled")
  128.  
  129. # Movement
  130. var lbl_movement = Label.new()
  131. lbl_movement.set_text("Movement")
  132.  
  133. var movement = CheckButton.new()
  134. movement.set_pressed(camera.movement)
  135. movement.connect("toggled",self,"_on_btn_movement_toggled")
  136.  
  137. var lbl_speed = Label.new()
  138. lbl_speed.set_text("Max Speed")
  139.  
  140. var speed = HScrollBar.new()
  141. speed.set_max(MAX_SPEED)
  142. speed.set_value(camera.max_speed.x)
  143. speed.connect("value_changed",self,"_on_hsb_speed_value_changed")
  144.  
  145. var lbl_acceleration = Label.new()
  146. lbl_acceleration.set_text("Acceleration")
  147.  
  148. var acceleration = HScrollBar.new()
  149. acceleration.set_max(1.0)
  150. acceleration.set_value(camera.acceleration)
  151. acceleration.connect("value_changed", self, "_in_hsb_acceleration_value_changed")
  152.  
  153. var lbl_deceleration = Label.new()
  154. lbl_deceleration.set_text("Deceleration")
  155.  
  156. var deceleration = HScrollBar.new()
  157. deceleration.set_max(1.0)
  158. deceleration.set_value(camera.deceleration)
  159. deceleration.connect("value_changed", self, "_in_hsb_deceleration_value_changed")
  160.  
  161. # add_child(panel)
  162. # panel.add_child(container)
  163. # container.add_child(lbl_mouse)
  164. # container.add_child(mouse)
  165. # container.add_child(mouselook)
  166. # container.add_child(lbl_sensitivity)
  167. # container.add_child(sensitivity)
  168. # container.add_child(lbl_smoothless)
  169. # container.add_child(smoothness)
  170. # container.add_child(lbl_privot)
  171. # container.add_child(privot)
  172. # container.add_child(btn_rot_privot)
  173. # container.add_child(lbl_distance)
  174. # container.add_child(distance)
  175. # container.add_child(lbl_yaw)
  176. # container.add_child(yaw)
  177. # container.add_child(lbl_pitch)
  178. # container.add_child(pitch)
  179. # container.add_child(collisions)
  180. # container.add_child(lbl_movement)
  181. # container.add_child(movement)
  182. # container.add_child(lbl_speed)
  183. # container.add_child(speed)
  184. # container.add_child(lbl_acceleration)
  185. # container.add_child(acceleration)
  186. # container.add_child(lbl_deceleration)
  187. # container.add_child(deceleration)
  188.  
  189. # if DRAGGABLE:
  190. # panel.connect("mouse_entered", self, "_panel_entered")
  191. # panel.connect("mouse_exited", self, "_panel_exited")
  192. # container.connect("mouse_entered", self, "_panel_entered")
  193. # container.connect("mouse_exited", self, "_panel_exited")
  194.  
  195. self.hide()
  196. else:
  197. set_process_input(false)
  198.  
  199. func _input(event):
  200. if event.is_action_pressed(shortcut):
  201. if camera.enabled:
  202. camera.enabled = false
  203. Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
  204. self.show()
  205. else:
  206. camera.enabled = true
  207. self.hide()
  208.  
  209. if DRAGGABLE:
  210. if event is InputEventMouseButton and event.button_index == BUTTON_LEFT:
  211. mouse_pressed = event.pressed
  212.  
  213. elif event is InputEventMouseMotion and mouse_over and mouse_pressed:
  214. panel.set_begin(panel.get_begin() + event.relative)
  215.  
  216. func _update_privots(privot):
  217. privot.clear()
  218. privot.add_item("None")
  219. node_list = _get_spatials_recusiv(get_tree().get_root(), [get_name(), camera.get_name()])
  220.  
  221. var size = node_list.size()
  222. for i in range(0, size):
  223. var node = node_list[i]
  224. privot.add_item(node.get_name())
  225. if node == camera.privot:
  226. privot.select(i+1)
  227.  
  228. if not camera.privot:
  229. privot.select(0)
  230.  
  231.  
  232. func _get_spatials_recusiv(node, exceptions=[]):
  233. var list = []
  234. for child in node.get_children():
  235. if not child.get_name() in exceptions:
  236. if child is Spatial:
  237. list.append(child)
  238. if not child.get_children().empty():
  239. for subchild in _get_spatials_recusiv(child, exceptions):
  240. list.append(subchild)
  241. return list
  242.  
  243. func _panel_entered():
  244. mouse_over = true
  245.  
  246. func _panel_exited():
  247. mouse_over = false
  248.  
  249. func _on_opt_mouse_item_selected(id):
  250. camera.mouse_mode = id
  251.  
  252. func _on_btn_mouselook_toggled(pressed):
  253. camera.mouselook = pressed
  254.  
  255. func _on_hsb_sensitivity_value_changed(value):
  256. camera.sensitivity = value
  257.  
  258. func _on_hsb_smoothness_value_changed(value):
  259. camera.smoothness = value
  260.  
  261. func _on_opt_privot_pressed():
  262. _update_privots(privot)
  263.  
  264. func _on_opt_privot_item_selected(id):
  265. if id > 0:
  266. camera.privot = node_list[id-1]
  267. else:
  268. camera.privot = null
  269. privot.select(id)
  270.  
  271. func _on_btn_rot_privot_toggled(pressed):
  272. camera.rotate_privot = pressed
  273.  
  274. func _on_box_distance_value_changed(value):
  275. camera.distance = value
  276.  
  277. func _on_box_yaw_value_changed(value):
  278. camera.yaw_limit = value
  279.  
  280. func _on_box_pitch_value_changed(value):
  281. camera.pitch_limit = value
  282.  
  283. func _on_btn_collisions_toggled(pressed):
  284. camera.collisions = pressed
  285.  
  286. func _on_btn_movement_toggled(pressed):
  287. camera.movement = pressed
  288.  
  289. func _on_hsb_speed_value_changed(value):
  290. camera.max_speed.x = value
  291. camera.max_speed.y = value
  292. camera.max_speed.z = value
  293.  
  294. func _in_hsb_acceleration_value_changed(value):
  295. camera.acceleration = value
  296.  
  297. func _in_hsb_deceleration_value_changed(value):
  298. camera.deceleration = value
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement