ToolsController.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using UnityEngine;
  6. using UnityEngine.EventSystems;
  7. using UnityEngine.UI;
  8. using SimpleFileBrowser;
  9. public class ToolsController : MonoBehaviour
  10. {
  11. public WallCreate Cursor;
  12. public int Rounding = 1;
  13. public Button Mouse;
  14. public Button Hammer;
  15. public Button Undo;
  16. public Button Redo;
  17. public Button ButtonGrid;
  18. public Button ButtonBeacon;
  19. public Button ButtonZone;
  20. public Button ButtonBuild;
  21. public Button ButtonRoom;
  22. public Button ButtonWall;
  23. public GameObject GroundSettings;
  24. public GameObject Grid;
  25. public GameObject BuildTools;
  26. public GameObject ZonesScroll;
  27. public GameObject BeaconsScroll;
  28. Button old_btn_tools;
  29. Button old_btn_build;
  30. GameObject old_panel;
  31. bool cursor_active;
  32. bool ground_active;
  33. enum Tools { Wall, Room, Del, Cursor};
  34. // Tools tools = Tools.Cursor;
  35. // Start is called before the first frame update
  36. void Start()
  37. {
  38. Mouse.onClick.AddListener(CursorOff);
  39. Hammer.onClick.AddListener(CursorOff);
  40. Undo.onClick.AddListener(CursorOff);
  41. Redo.onClick.AddListener(CursorOff);
  42. ButtonGrid.onClick.AddListener(GridOnOff);
  43. ButtonRoom.onClick.AddListener(RoomEdit);
  44. ButtonWall.onClick.AddListener(WallEdit);
  45. }
  46. // Update is called once per frame
  47. void Update()
  48. {
  49. if (EventSystem.current.IsPointerOverGameObject())
  50. {
  51. if (cursor_active) Cursor.gameObject.SetActive(!cursor_active);
  52. }
  53. else if (cursor_active) Cursor.gameObject.SetActive(cursor_active);
  54. if (ground_active != GroundSettings.activeSelf) GroundSettings.SetActive(ground_active);
  55. }
  56. public void CursorOff()
  57. {
  58. cursor_active=false;
  59. Cursor.mode = WallCreate.Mode.Cursor;
  60. }
  61. public void WallEdit()
  62. {
  63. cursor_active = true;
  64. Cursor.mode = WallCreate.Mode.Wall;
  65. ground_active = false;
  66. }
  67. public void RoomEdit()
  68. {
  69. cursor_active = true;
  70. Cursor.mode = WallCreate.Mode.Room;
  71. ground_active = false;
  72. }
  73. public void BuildEdit()
  74. {
  75. SelectButton(ButtonBuild, old_btn_build);
  76. if (old_panel != null) old_panel.SetActive(false);
  77. BuildTools.SetActive(true);
  78. old_panel = BuildTools;
  79. old_btn_build = ButtonBuild;
  80. }
  81. public void GroundEdit()
  82. {
  83. if (cursor_active)
  84. {
  85. Cursor.gameObject.SetActive(false);
  86. cursor_active = false;
  87. }
  88. ground_active = true;
  89. }
  90. public void ZoneEdit()
  91. {
  92. cursor_active = true;
  93. SelectButton(ButtonZone, old_btn_build);
  94. Cursor.mode = WallCreate.Mode.Zone;
  95. if (old_panel != null) old_panel.SetActive(false);
  96. ZonesScroll.SetActive(true);
  97. old_panel = ZonesScroll;
  98. old_btn_build = ButtonZone;
  99. ground_active = false;
  100. }
  101. public void BeaconEdit()
  102. {
  103. if (cursor_active)
  104. {
  105. Cursor.gameObject.SetActive(false);
  106. cursor_active = false;
  107. }
  108. SelectButton(ButtonBeacon,old_btn_build);
  109. if (old_panel != null) old_panel.SetActive(false);
  110. BeaconsScroll.SetActive(true);
  111. old_panel = BeaconsScroll;
  112. old_btn_build = ButtonBeacon;
  113. ground_active = false;
  114. }
  115. bool grid_active = false;
  116. public void GridOnOff()
  117. {
  118. grid_active = !grid_active;
  119. Grid.SetActive(grid_active);
  120. if(grid_active) ButtonGrid.GetComponent<Image>().color = Color.gray;
  121. else ButtonGrid.GetComponent<Image>().color = Color.white;
  122. }
  123. public void Delete()
  124. {
  125. //tools = Tools.Del;
  126. }
  127. public void SelectButton(GameObject button)
  128. {
  129. GameObject old_button = null;
  130. switch (Cursor.mode)
  131. {
  132. case WallCreate.Mode.Cursor:
  133. old_button = transform.GetChild(0).gameObject;
  134. break;
  135. case WallCreate.Mode.Room:
  136. old_button = transform.GetChild(1).gameObject;
  137. break;
  138. case WallCreate.Mode.Wall:
  139. old_button = transform.GetChild(2).gameObject;
  140. break;
  141. case WallCreate.Mode.Zone:
  142. old_button = transform.GetChild(3).gameObject;
  143. break;
  144. }
  145. if (old_button != null) old_button.GetComponent<Image>().color = Color.white;
  146. button.GetComponent<Image>().color = Color.gray;
  147. }
  148. public static void SelectButton(Button button, Button old_button)
  149. {
  150. //var color = new Color();
  151. ColorUtility.TryParseHtmlString("#C8C8C8", out var color);
  152. if (old_button != null) old_button.GetComponent<Image>().color = Color.white;
  153. button.GetComponent<Image>().color = color;
  154. }
  155. public void mouse()
  156. {
  157. SelectButton(Mouse, old_btn_tools);
  158. old_btn_tools = Mouse;
  159. }
  160. public void hammer()
  161. {
  162. SelectButton(Hammer, old_btn_tools);
  163. old_btn_tools = Hammer;
  164. }
  165. /// <summary>
  166. /// old
  167. /// </summary>
  168. //public void OpenFileBrowser()
  169. //{
  170. // StartCoroutine(ShowLoadDialogCoroutine($"Выбор карты"));
  171. //}
  172. /// <summary>
  173. /// old
  174. /// </summary>
  175. /// <param name="name_view"></param>
  176. /// <returns></returns>
  177. //IEnumerator ShowLoadDialogCoroutine(string name_view)
  178. //{
  179. // FileBrowser.SetFilters(true, new FileBrowser.Filter("Images", ".jpg", ".png"));
  180. // FileBrowser.SetDefaultFilter(".jpg");
  181. // //FileBrowser.AddQuickLink("Users", "C:\\Users", null);
  182. // // Show a load file dialog and wait for a response from user
  183. // // Load file/folder: file, Initial path: default (Documents), Title: "Load File", submit button text: "Load"
  184. // yield return FileBrowser.WaitForLoadDialog(false, null, name_view, "Load");
  185. // // Dialog is closed
  186. // // Print whether a file is chosen (FileBrowser.Success)
  187. // // and the path to the selected file (FileBrowser.Result) (null, if FileBrowser.Success is false)
  188. // Debug.Log(FileBrowser.Success + " " + FileBrowser.Result);
  189. // if (FileBrowser.Success)
  190. // {
  191. // var go = GameObject.Find("InputField_Image");
  192. // if (go != null)
  193. // {
  194. // var ifield = go.GetComponent<InputField>();
  195. // if (ifield != null)
  196. // {
  197. // ifield.text = FileBrowser.Result;
  198. // }
  199. // }
  200. // // If a file was chosen, read its bytes via FileBrowserHelpers
  201. // // Contrary to File.ReadAllBytes, this function works on Android 10+, as well
  202. // byte[] bytes = FileBrowserHelpers.ReadBytesFromFile(FileBrowser.Result);
  203. // var loc = CompanyController.instance.GetActiveLocation();
  204. // if (loc != null)
  205. // {
  206. // loc.SaveTexture(bytes);
  207. // }
  208. // }
  209. //}
  210. }