SCKeyboard2DMono.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  1. using LitJson;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UnityEngine.EventSystems;
  7. using UnityEngine.UI;
  8. namespace SC.XR.Unity.Module_Keyboard
  9. {
  10. public class SCKeyboard2DMono : SCKeyboardMono
  11. {
  12. #region Initialize
  13. public override void Initialize(SCKeyboardType keyboardType = SCKeyboardType.Default)
  14. {
  15. base.Initialize(keyboardType);
  16. InitializePromptWords();
  17. Keyboard2DPrompt.isOpen = false;
  18. }
  19. protected override void DefaultKeyboardInitialize()
  20. {
  21. switch (SCKeyboard.currentSystemLanguage)
  22. {
  23. case KeyboardSystemLanguage.Chinese:
  24. ActiveKeyboard(KeyboardEnum.ABC, KeyboardState.Cn);
  25. break;
  26. default:
  27. ActiveKeyboard(KeyboardEnum.ABC, KeyboardState.En);
  28. break;
  29. }
  30. ActiveKeyboard(KeyboardEnum.Delete);
  31. ActiveKeyboard(KeyboardEnum.Number);
  32. }
  33. protected override void ASCIICapableKeyboardInitialize()
  34. {
  35. ActiveKeyboard(KeyboardEnum.ABC, KeyboardState.En);
  36. ActiveKeyboard(KeyboardEnum.Delete);
  37. ActiveKeyboard(KeyboardEnum.Number);
  38. }
  39. protected override void URLKeyboardInitialize()
  40. {
  41. switch (SCKeyboard.currentSystemLanguage)
  42. {
  43. case KeyboardSystemLanguage.Chinese:
  44. ActiveKeyboard(KeyboardEnum.ABC, KeyboardState.Cn);
  45. break;
  46. default:
  47. ActiveKeyboard(KeyboardEnum.ABC, KeyboardState.En);
  48. break;
  49. }
  50. ActiveKeyboard(KeyboardEnum.Delete);
  51. ActiveKeyboard(KeyboardEnum.Number);
  52. ActiveKeyboard(KeyboardEnum.Prompt);
  53. }
  54. protected override void SearchKeyboardInitialize()
  55. {
  56. switch (SCKeyboard.currentSystemLanguage)
  57. {
  58. case KeyboardSystemLanguage.Chinese:
  59. ActiveKeyboard(KeyboardEnum.ABC, KeyboardState.Cn);
  60. break;
  61. default:
  62. ActiveKeyboard(KeyboardEnum.ABC, KeyboardState.En);
  63. break;
  64. }
  65. ActiveKeyboard(KeyboardEnum.Delete);
  66. ActiveKeyboard(KeyboardEnum.Number);
  67. }
  68. #endregion
  69. #region Keyboards
  70. protected SCKeyboard2DPrompt Keyboard2DPrompt
  71. {
  72. get
  73. {
  74. return keyboard_prompt as SCKeyboard2DPrompt;
  75. }
  76. }
  77. public GameObject keyboard_symbol;
  78. public GameObject keyboard_meme;
  79. public GameObject keyboard_morePrompt;
  80. public GameObject keyboard_language;
  81. public GameObject keyboard_delete;
  82. public GameObject keyboard_num;
  83. #endregion
  84. #region Key Clicks
  85. public override void OnNumberKeyClick(string value)
  86. {
  87. if (preInputStringBuilder.Length != 0)
  88. {
  89. OnPinyinKeyClick(value);
  90. }
  91. else
  92. {
  93. base.OnNumberKeyClick(value);
  94. }
  95. }
  96. public override void OnPinyinKeyClick(string value)
  97. {
  98. chinesePagesDic = new Dictionary<int, Dictionary<int, Dictionary<int, string>>>();
  99. preInputStringBuilder.Append(value);
  100. ActiveKeyboard(KeyboardEnum.Prompt);
  101. Keyboard2DPrompt.SetEnteredText(preInputStringBuilder.ToString());
  102. PinyinKeyHandler(preInputStringBuilder.ToString());
  103. }
  104. public override void OnPromptKeyClick(string value)
  105. {
  106. base.OnPromptKeyClick(value);
  107. InitializePromptWords();
  108. }
  109. #endregion
  110. #region Special Key Click Events
  111. public override void OnDeleteClick()
  112. {
  113. if (keyboard_prompt.isActiveAndEnabled)
  114. {
  115. if (preInputStringBuilder.Length == 0)
  116. {
  117. OnWebKeyClick?.Invoke("Backspace");
  118. OnDeleteKeyClick?.Invoke();
  119. return;
  120. }
  121. preInputStringBuilder.Remove(preInputStringBuilder.Length - 1, 1);
  122. Keyboard2DPrompt.SetEnteredText(preInputStringBuilder.ToString());
  123. if (preInputStringBuilder.Length == 0)
  124. {
  125. InitializePromptWords();
  126. return;
  127. }
  128. PinyinKeyHandler(preInputStringBuilder.ToString());
  129. }
  130. else
  131. {
  132. OnWebKeyClick?.Invoke("Backspace");
  133. OnDeleteKeyClick?.Invoke();
  134. }
  135. }
  136. public override void OnEnterClick()
  137. {
  138. OnKeyClick?.Invoke(preInputStringBuilder.ToString());
  139. for (int i = 0; i < preInputStringBuilder.Length; i++)
  140. {
  141. OnWebKeyClick?.Invoke(preInputStringBuilder[i].ToString());
  142. }
  143. base.OnEnterClick();
  144. OnEnterKeyClick?.Invoke();
  145. }
  146. public override void OnLanguageClick()
  147. {
  148. base.OnLanguageClick();
  149. InitializePromptWords();
  150. }
  151. public override void OnCnClick()
  152. {
  153. base.OnCnClick();
  154. InitializePromptWords();
  155. //HideKeyboardPrompt();
  156. }
  157. public override void OnEnClick()
  158. {
  159. base.OnEnClick();
  160. InitializePromptWords();
  161. // HideKeyboardPrompt();
  162. }
  163. private int currentPage = 1;
  164. private int minPage = 1;
  165. private int maxPage = 10000;
  166. public override void OnPromptPageDownClick()
  167. {
  168. currentPage++;
  169. if (currentPage > maxPage)
  170. {
  171. currentPage = maxPage;
  172. }
  173. GenerateChinesePages(currentPage);
  174. }
  175. public override void OnPromptPageUpClick()
  176. {
  177. currentPage--;
  178. if (currentPage < minPage)
  179. {
  180. currentPage = minPage;
  181. }
  182. GenerateChinesePages(currentPage);
  183. }
  184. #endregion
  185. #region UGUI Key Click Events
  186. protected override void OnOpenMoreClick()
  187. {
  188. if (!Keyboard2DPrompt.isOpen)
  189. {
  190. if (preInputStringBuilder.Length != 0)
  191. {
  192. Keyboard2DPrompt.isOpen = true;
  193. ActiveKeyboard(KeyboardEnum.MorePrompt);
  194. GenerateChinesePages(1);
  195. }
  196. //GenerateMorePromptKeys(1);
  197. LayoutRebuilder.ForceRebuildLayoutImmediate(keyboard_morePrompt.transform.GetChild(0).GetChild(0).transform as RectTransform);
  198. }
  199. else
  200. {
  201. Keyboard2DPrompt.isOpen = false;
  202. ActiveKeyboard(KeyboardEnum.ABC, KeyboardState.Cn);
  203. }
  204. }
  205. #endregion
  206. #region Key Handlers
  207. private Text m_font;
  208. private RectTransform m_PromptPage;
  209. private RectTransform m_MorePromptPage;
  210. public Text Font
  211. {
  212. get
  213. {
  214. if (m_font == null)
  215. {
  216. m_font = Resources.Load<SCKeyboard2DKey>(keyPath).GetComponentInChildren<Text>();
  217. }
  218. return m_font;
  219. }
  220. }
  221. public RectTransform PromptPage
  222. {
  223. get
  224. {
  225. if (m_PromptPage == null)
  226. {
  227. m_PromptPage = Keyboard2DPrompt.promptInput;
  228. }
  229. return m_PromptPage;
  230. }
  231. }
  232. public RectTransform MorePromptPage
  233. {
  234. get
  235. {
  236. if (m_MorePromptPage == null)
  237. {
  238. m_MorePromptPage = keyboard_morePrompt.transform.GetChild(0).GetChild(0).GetComponent<RectTransform>();
  239. }
  240. return m_MorePromptPage;
  241. }
  242. }
  243. private int maxChineseWordCount;
  244. private static int currentChineseWordIndex = 0;
  245. public virtual void GenerateURLPages(int page = 0)
  246. {
  247. Keyboard2DPrompt.alreadyInput.gameObject.transform.parent.parent.gameObject.SetActive(false); //隐藏AlreadyInput
  248. Keyboard2DPrompt.promptInput.sizeDelta = new Vector2(484.88f, Keyboard2DPrompt.promptInput.sizeDelta.y); //拉长promptRow长度
  249. GenerateURLKeys();
  250. }
  251. public virtual void GenerateChinesePages(int page)
  252. {
  253. Keyboard2DPrompt.alreadyInput.gameObject.transform.parent.parent.gameObject.SetActive(true); //显示AlreadyInput
  254. Keyboard2DPrompt.promptInput.sizeDelta = new Vector2(268.88f, Keyboard2DPrompt.promptInput.sizeDelta.y); //缩短promptRow长度
  255. if (chinesePagesDic.ContainsKey(page))
  256. {
  257. if (page == 0)
  258. {
  259. HideAllPromptPages();
  260. foreach (int row in chinesePagesDic[page].Keys)
  261. {
  262. foreach (int word in chinesePagesDic[page][row].Keys)
  263. {
  264. SCKeyboardBaseKey key = promptPagesDic[0][row][word];
  265. string text = chinesePagesDic[page][row][word];
  266. key.Value = text;
  267. key.gameObject.SetActive(true);
  268. }
  269. }
  270. }
  271. else
  272. {
  273. HidePromptPage(1);
  274. foreach (int row in chinesePagesDic[page].Keys)
  275. {
  276. foreach (int word in chinesePagesDic[page][row].Keys)
  277. {
  278. SCKeyboardBaseKey key = promptPagesDic[1][row][word];
  279. string text = chinesePagesDic[page][row][word];
  280. key.Value = text;
  281. key.gameObject.SetActive(true);
  282. }
  283. }
  284. }
  285. StartCoroutine(RebuildLayout(PromptPage));
  286. }
  287. else
  288. {
  289. // Prompte Keys
  290. if (page == 0)
  291. {
  292. GenerateChineseKeys();
  293. }
  294. // More Prompt Keys
  295. else
  296. {
  297. GenerateMoreChineseKeys(page);
  298. }
  299. }
  300. }
  301. private void GenerateChineseKeys()
  302. {
  303. maxPage = 10000;
  304. HideAllPromptPages();
  305. maxChineseWordCount = Keyboard2DPrompt.GetChinese(preInputStringBuilder.ToString());
  306. currentChineseWordIndex = 0;
  307. GenerateChineseKeys(0, PromptPage, new List<string>());
  308. StartCoroutine(RebuildLayout(PromptPage));
  309. }
  310. private void GenerateURLKeys()
  311. {
  312. HideAllPromptPages();
  313. GenerateURLKeys(0, PromptPage, new List<string>());
  314. StartCoroutine(RebuildLayout(PromptPage));
  315. }
  316. private void GenerateMoreChineseKeys(int pageIndex = 1)
  317. {
  318. HidePromptPage(1);
  319. if (pageIndex < 1) pageIndex = 1;
  320. GenerateMoreChineseKeys(0, 0, pageIndex, new List<string>());
  321. StartCoroutine(RebuildLayout(MorePromptPage));
  322. }
  323. private void GenerateChineseKeys(int keyIndex, RectTransform promptRow, List<string> messages)
  324. {
  325. if (currentChineseWordIndex > maxChineseWordCount - 1)
  326. {
  327. return;
  328. }
  329. if (!promptPagesDic.ContainsKey(0)) promptPagesDic[0] = new Dictionary<int, Dictionary<int, SCKeyboardBaseKey>>();
  330. if (!promptPagesDic[0].ContainsKey(0)) promptPagesDic[0][0] = new Dictionary<int, SCKeyboardBaseKey>();
  331. if (!chinesePagesDic.ContainsKey(0)) chinesePagesDic[0] = new Dictionary<int, Dictionary<int, string>>();
  332. if (!chinesePagesDic[0].ContainsKey(0)) chinesePagesDic[0][0] = new Dictionary<int, string>();
  333. SCKeyboard2DKey promptKey;
  334. string text = Keyboard2DPrompt.GetChinese(currentChineseWordIndex);
  335. if (promptPagesDic[0][0].ContainsKey(keyIndex))
  336. {
  337. promptKey = promptPagesDic[0][0][keyIndex] as SCKeyboard2DKey;
  338. promptKey.Value = text;
  339. promptKey.GetComponentInChildren<ContentSizeFitter>().enabled = true; //改回来
  340. messages.Add(promptKey.Value);
  341. if (!WithinTheLimits(messages, promptRow.GetComponent<HorizontalLayoutGroup>(), promptRow.sizeDelta.x))
  342. {
  343. promptKey.gameObject.SetActive(false);
  344. return;
  345. }
  346. promptKey.gameObject.SetActive(true);
  347. chinesePagesDic[0][0][keyIndex] = text;
  348. }
  349. else
  350. {
  351. promptKey = InstantiateKey(keyPath, promptRow, text);
  352. messages.Add(promptKey.Value);
  353. promptPagesDic[0][0][keyIndex] = promptKey;
  354. if (!WithinTheLimits(messages, promptRow.GetComponent<HorizontalLayoutGroup>(), promptRow.sizeDelta.x))
  355. {
  356. promptKey.gameObject.SetActive(false);
  357. return;
  358. }
  359. promptKey.gameObject.SetActive(true);
  360. chinesePagesDic[0][0][keyIndex] = text;
  361. }
  362. //Debug.Log("promptKey [ " + promptKey.Value + " ] :" + currentChineseWordIndex);
  363. currentChineseWordIndex++;
  364. GenerateChineseKeys(keyIndex + 1, promptRow, messages);
  365. }
  366. private void GenerateURLKeys(int keyIndex, RectTransform promptRow, List<string> messages)
  367. {
  368. if (!promptPagesDic.ContainsKey(0)) promptPagesDic[0] = new Dictionary<int, Dictionary<int, SCKeyboardBaseKey>>();
  369. if (!promptPagesDic[0].ContainsKey(0)) promptPagesDic[0][0] = new Dictionary<int, SCKeyboardBaseKey>();
  370. if (urlPagesDic[0][0].ContainsKey(keyIndex))
  371. {
  372. SCKeyboard2DKey promptKey;
  373. string text = urlPagesDic[0][0][keyIndex];
  374. if (promptPagesDic[0][0].ContainsKey(keyIndex))
  375. {
  376. promptKey = promptPagesDic[0][0][keyIndex] as SCKeyboard2DKey;
  377. }
  378. else
  379. {
  380. promptKey = InstantiateKey(keyPath, promptRow, text);
  381. promptPagesDic[0][0][keyIndex] = promptKey;
  382. }
  383. promptKey.Value = text;
  384. promptKey.GetComponentInChildren<ContentSizeFitter>().enabled = false; //更改promptKey
  385. promptKey.GetComponentInChildren<Text>().GetComponent<RectTransform>().sizeDelta = new Vector2(1000f, 240f); //更改promptKey
  386. messages.Add(promptKey.Value);
  387. if (!WithinTheLimits(messages, promptRow.GetComponent<HorizontalLayoutGroup>(), promptRow.sizeDelta.x))
  388. {
  389. promptKey.gameObject.SetActive(false);
  390. return;
  391. }
  392. promptKey.gameObject.SetActive(true);
  393. //Debug.Log("URLKey [ " + promptKey.Value + " ] :" + keyIndex);
  394. GenerateURLKeys(keyIndex + 1, promptRow, messages);
  395. }
  396. }
  397. private void GenerateMoreChineseKeys(int keyIndex, int rowIndex, int pageIndex, List<string> messages)
  398. {
  399. if (currentChineseWordIndex > maxChineseWordCount - 1)
  400. {
  401. maxPage = currentPage;
  402. return;
  403. }
  404. if (rowIndex > 4)
  405. {
  406. return;
  407. }
  408. SCKeyboard2DKey promptKey;
  409. RectTransform promptRow;
  410. if (promptRowRectTransformsDic.ContainsKey(rowIndex)) promptRow = promptRowRectTransformsDic[rowIndex];
  411. else promptRowRectTransformsDic.Add(rowIndex, promptRow = InstantiateRow(rowPath, MorePromptPage));
  412. string text = Keyboard2DPrompt.GetChinese(currentChineseWordIndex);
  413. if (!promptPagesDic.ContainsKey(1)) promptPagesDic[1] = new Dictionary<int, Dictionary<int, SCKeyboardBaseKey>>();
  414. if (!promptPagesDic[1].ContainsKey(rowIndex)) promptPagesDic[1][rowIndex] = new Dictionary<int, SCKeyboardBaseKey>();
  415. if (!chinesePagesDic.ContainsKey(pageIndex)) chinesePagesDic[pageIndex] = new Dictionary<int, Dictionary<int, string>>();
  416. if (!chinesePagesDic[pageIndex].ContainsKey(rowIndex)) chinesePagesDic[pageIndex][rowIndex] = new Dictionary<int, string>();
  417. if (promptPagesDic[1][rowIndex].ContainsKey(keyIndex))
  418. {
  419. promptKey = promptPagesDic[1][rowIndex][keyIndex] as SCKeyboard2DKey;
  420. promptKey.Value = text;
  421. messages.Add(promptKey.Value);
  422. if (!WithinTheLimits(messages, promptRow.GetComponent<HorizontalLayoutGroup>(), 443f))
  423. {
  424. promptKey.gameObject.SetActive(false);
  425. GenerateMoreChineseKeys(0, rowIndex + 1, pageIndex, new List<string>());
  426. return;
  427. }
  428. promptKey.gameObject.SetActive(true);
  429. chinesePagesDic[pageIndex][rowIndex][keyIndex] = text;
  430. }
  431. else
  432. {
  433. promptKey = InstantiateKey(keyPath, promptRow, text);
  434. messages.Add(promptKey.Value);
  435. promptPagesDic[1][rowIndex].Add(keyIndex, promptKey);
  436. if (!WithinTheLimits(messages, promptRow.GetComponent<HorizontalLayoutGroup>(), 443f))
  437. {
  438. promptKey.gameObject.SetActive(false);
  439. GenerateMoreChineseKeys(0, rowIndex + 1, pageIndex, new List<string>());
  440. return;
  441. }
  442. promptKey.gameObject.SetActive(true);
  443. chinesePagesDic[pageIndex][rowIndex][keyIndex] = text;
  444. }
  445. //Debug.Log("promptKey [ " + promptKey.Value + " ] :" + currentChineseWordIndex);
  446. currentChineseWordIndex++;
  447. GenerateMoreChineseKeys(keyIndex + 1, rowIndex, pageIndex, messages);
  448. }
  449. private void HidePromptPage(int page)
  450. {
  451. if (promptPagesDic.ContainsKey(page))
  452. {
  453. foreach (var rowIndex in promptPagesDic[page].Keys)
  454. {
  455. foreach (var keyIndex in promptPagesDic[page][rowIndex].Keys)
  456. {
  457. promptPagesDic[page][rowIndex][keyIndex].gameObject.SetActive(false);
  458. }
  459. }
  460. }
  461. }
  462. private void HideAllPromptPages()
  463. {
  464. HidePromptPage(0);
  465. HidePromptPage(1);
  466. }
  467. IEnumerator RebuildLayout(RectTransform rect)
  468. {
  469. yield return new WaitForEndOfFrame();
  470. LayoutRebuilder.ForceRebuildLayoutImmediate(rect);
  471. }
  472. public override void PinyinKeyHandler(string preInput)
  473. {
  474. chinesePagesDic = new Dictionary<int, Dictionary<int, Dictionary<int, string>>>();
  475. if (keyboard_morePrompt.activeSelf == false)
  476. {
  477. GenerateChinesePages(0);
  478. }
  479. else
  480. {
  481. GenerateChinesePages(0);
  482. GenerateChinesePages(1);
  483. }
  484. }
  485. private SCKeyboard2DKey InstantiateKey(string path, Transform parent, string value)
  486. {
  487. SCKeyboard2DKey prefab = Resources.Load<SCKeyboard2DKey>(path);
  488. SCKeyboard2DKey promptKey = GameObject.Instantiate(prefab);
  489. promptKey.transform.SetParent(parent);
  490. promptKey.transform.localPosition = Vector3.zero;
  491. promptKey.transform.localRotation = Quaternion.identity;
  492. promptKey.transform.localScale = Vector3.one;
  493. promptKey.Value = value;
  494. return promptKey;
  495. }
  496. private RectTransform InstantiateRow(string path, Transform parent)
  497. {
  498. GameObject prefab = Resources.Load<GameObject>(path);
  499. GameObject promptRow = GameObject.Instantiate(prefab);
  500. promptRow.transform.SetParent(parent);
  501. promptRow.transform.localPosition = Vector3.zero;
  502. promptRow.transform.localRotation = Quaternion.identity;
  503. promptRow.transform.localScale = Vector3.one;
  504. return promptRow.GetComponent<RectTransform>();
  505. }
  506. private bool WithinTheLimits(List<string> messages, HorizontalLayoutGroup group, float LimitWidth)
  507. {
  508. float rectWidth = LimitWidth;
  509. float totalWidth = 0;
  510. float left = group.padding.left;
  511. float right = group.padding.right;
  512. float space = group.spacing;
  513. float width = 0;
  514. int wordCount = messages.Count;
  515. string message = "";
  516. for (int i = 0; i < messages.Count; i++)
  517. {
  518. message += messages[i];
  519. width += 12;
  520. }
  521. width += KeyboardUtils.CaculateTextLength(message, Font) / 10;
  522. totalWidth = (wordCount - 1) * space + left + width;
  523. return totalWidth <= rectWidth;
  524. }
  525. #endregion
  526. #region ActiveKeyboards
  527. protected override void ActiveKeyboard(KeyboardEnum keyboardEnum, KeyboardState keyboardState = KeyboardState.Cn)
  528. {
  529. base.ActiveKeyboard(keyboardEnum, keyboardState);
  530. switch (keyboardEnum)
  531. {
  532. case KeyboardEnum.ABC:
  533. OnActiveABCKeyboard(keyboardState);
  534. switch (presentKeyboardType)
  535. {
  536. case SCKeyboardType.Default:
  537. case SCKeyboardType.ASCIICapable:
  538. case SCKeyboardType.Search:
  539. break;
  540. case SCKeyboardType.URL:
  541. ActiveKeyboard(KeyboardEnum.Prompt);
  542. break;
  543. }
  544. break;
  545. case KeyboardEnum.Symbol:
  546. OnActiveSymbolKeyboard();
  547. break;
  548. case KeyboardEnum.Number:
  549. OnActiveNumberKeyboard();
  550. break;
  551. case KeyboardEnum.Meme:
  552. OnActiveMemeKeyboard();
  553. break;
  554. case KeyboardEnum.Prompt:
  555. OnActivePromptKeyboard();
  556. break;
  557. case KeyboardEnum.MorePrompt:
  558. OnActiveMorePromptKeyboard();
  559. break;
  560. case KeyboardEnum.Language:
  561. OnActiveLanguageKeyboard();
  562. break;
  563. case KeyboardEnum.Delete:
  564. OnActiveDeleteKeyboard();
  565. break;
  566. }
  567. }
  568. protected override void HideKeyboardPrompt(bool inputPreString = false)
  569. {
  570. if (keyboard_prompt.isActiveAndEnabled)
  571. {
  572. switch (presentKeyboardType)
  573. {
  574. case SCKeyboardType.URL:
  575. break;
  576. default:
  577. //if (inputPreString) OnNormalKeyClick(preInputStringBuilder.ToString());
  578. preInputStringBuilder.Clear();
  579. Keyboard2DPrompt.gameObject.SetActive(false);
  580. ChangePromptOpenBtnState(true);
  581. break;
  582. }
  583. }
  584. }
  585. protected void ChangePromptOpenBtnState(bool isOpen)
  586. {
  587. Keyboard2DPrompt.open.gameObject.SetActive(isOpen);
  588. Keyboard2DPrompt.close.gameObject.SetActive(!isOpen);
  589. }
  590. public void OnActiveABCKeyboard(KeyboardState keyboardState)
  591. {
  592. if (presentKeyboard != null)
  593. previousKeyboard = presentKeyboard;
  594. keyboard_abc.SetActive(true);
  595. presentKeyboard = keyboard_abc;
  596. if (previousKeyboard != null && previousKeyboard != presentKeyboard)
  597. previousKeyboard.SetActive(false);
  598. presentKeyboardState = keyboardState;
  599. OnKeyboardStateChange?.Invoke(keyboardState);
  600. }
  601. public void OnActiveSymbolKeyboard()
  602. {
  603. if (presentKeyboard != null)
  604. previousKeyboard = presentKeyboard;
  605. keyboard_symbol.SetActive(true);
  606. HideKeyboardPrompt();
  607. presentKeyboard = keyboard_symbol;
  608. if (previousKeyboard != null && previousKeyboard != presentKeyboard)
  609. previousKeyboard.SetActive(false);
  610. }
  611. public void OnActiveNumberKeyboard()
  612. {
  613. keyboard_num.SetActive(true);
  614. }
  615. public void OnActiveMemeKeyboard()
  616. {
  617. keyboard_meme.SetActive(true);
  618. }
  619. public void OnActivePromptKeyboard()
  620. {
  621. keyboard_prompt.gameObject.SetActive(true);
  622. }
  623. public void OnActiveMorePromptKeyboard()
  624. {
  625. if (presentKeyboard != null)
  626. previousKeyboard = presentKeyboard;
  627. keyboard_morePrompt.gameObject.SetActive(true);
  628. presentKeyboard = keyboard_morePrompt;
  629. if (previousKeyboard != null && previousKeyboard != presentKeyboard)
  630. previousKeyboard.SetActive(false);
  631. }
  632. public void OnActiveLanguageKeyboard()
  633. {
  634. if (presentKeyboard != null)
  635. previousKeyboard = presentKeyboard;
  636. keyboard_language.SetActive(true);
  637. HideKeyboardPrompt();
  638. presentKeyboard = keyboard_language;
  639. if (previousKeyboard != null && previousKeyboard != presentKeyboard)
  640. previousKeyboard.SetActive(false);
  641. }
  642. public void OnActiveDeleteKeyboard()
  643. {
  644. keyboard_delete.SetActive(true);
  645. }
  646. #endregion
  647. #region Methods
  648. private void InitializePromptWords()
  649. {
  650. HideAllPromptPages();
  651. switch (presentKeyboardType)
  652. {
  653. case SCKeyboardType.Default:
  654. case SCKeyboardType.Search:
  655. case SCKeyboardType.ASCIICapable:
  656. preInputStringBuilder.Clear();
  657. Keyboard2DPrompt.SetEnteredText("");
  658. Keyboard2DPrompt.gameObject.SetActive(false);
  659. break;
  660. case SCKeyboardType.URL:
  661. preInputStringBuilder.Clear();
  662. Keyboard2DPrompt.SetEnteredText("");
  663. if (!urlPagesDic.ContainsKey(0)) urlPagesDic[0] = new Dictionary<int, Dictionary<int, string>>();
  664. if (!urlPagesDic[0].ContainsKey(0)) urlPagesDic[0][0] = new Dictionary<int, string>();
  665. for (int i = 0; i < Keyboard2DPrompt.URLWords.Count; i++)
  666. {
  667. urlPagesDic[0][0][i] = Keyboard2DPrompt.URLWords[i];
  668. }
  669. //urlPagesDic[0][0][0] = "http://";
  670. //urlPagesDic[0][0][1] = "www.";
  671. //urlPagesDic[0][0][2] = ".com";
  672. //urlPagesDic[0][0][3] = "@";
  673. GenerateURLPages();
  674. break;
  675. }
  676. if (keyboard_morePrompt.gameObject.activeSelf)
  677. {
  678. keyboard_morePrompt.gameObject.SetActive(false);
  679. Keyboard2DPrompt.isOpen = false;
  680. ActiveKeyboard(KeyboardEnum.ABC, KeyboardState.Cn);
  681. }
  682. }
  683. #endregion
  684. #region Extend Methods
  685. #endregion
  686. }
  687. }