SceneCameraOptionsDropdown.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using BansheeEngine;
  4. using System.Linq;
  5. namespace BansheeEditor
  6. {
  7. /** @addtogroup Scene-Editor
  8. * @{
  9. */
  10. /// <summary>
  11. /// Drop down window that displays options used by the scene camera.
  12. /// </summary>
  13. [DefaultSize(200, 30)]
  14. internal class SceneCameraOptionsDropdown : DropDownWindow
  15. {
  16. private SceneWindow parent;
  17. private SceneCameraOptions CameraOptions;
  18. /// <summary>
  19. /// Initializes the drop down window by creating the necessary GUI. Must be called after construction and before
  20. /// use.
  21. /// </summary>
  22. /// <param name="parent">Scene window that this drop down window is a part of.</param>
  23. /// <param name="cameraOptions">Reference to the current scene camera options.</param>
  24. internal void Initialize(SceneWindow parent, SceneCameraOptions cameraOptions)
  25. {
  26. this.parent = parent;
  27. CameraOptions = cameraOptions;
  28. GUIListBoxField cameraScrollSpeedField = new GUIListBoxField(SceneCameraOptions.ScrollSpeeds.ToList().Select(o => o.ToString()).ToArray(),
  29. new LocEdString("Scroll speed"));
  30. cameraScrollSpeedField.SelectElement(SceneCameraOptions.ScrollSpeeds.ToList().FindIndex(item => item == CameraOptions.ScrollSpeed));
  31. cameraScrollSpeedField.OnSelectionChanged += OnCameraScrollSpeedChanged;
  32. GUILayoutY vertLayout = GUI.AddLayoutY();
  33. vertLayout.AddFlexibleSpace();
  34. GUILayoutX cameraScrollSpeedLayout = vertLayout.AddLayoutX();
  35. cameraScrollSpeedLayout.AddFlexibleSpace();
  36. cameraScrollSpeedLayout.AddElement(cameraScrollSpeedField);
  37. cameraScrollSpeedLayout.AddFlexibleSpace();
  38. vertLayout.AddFlexibleSpace();
  39. }
  40. /// <summary>
  41. /// Triggered when the scroll speed of the scene camera is changed.
  42. /// </summary>
  43. /// <param name="index">The index of the selected scroll speed.</param>
  44. private void OnCameraScrollSpeedChanged(int index)
  45. {
  46. CameraOptions.SetScrollSpeed(SceneCameraOptions.ScrollSpeeds[index]);
  47. }
  48. }
  49. }