notemenu.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. class NoteMenu extends UIScriptedMenu
  2. {
  3. protected MultilineEditBoxWidget m_edit;
  4. protected HtmlWidget m_html;
  5. protected ButtonWidget m_confirm_button;
  6. protected ItemBase m_Paper;
  7. protected EntityAI m_Pen;
  8. protected bool m_IsWriting;
  9. //protected int m_Handwriting;
  10. protected int m_SymbolCount;
  11. protected string m_PenColor; //color in hex-code format, transferred as string. Could be transferred as int or array<int, bool>?
  12. void NoteMenu()
  13. {
  14. MissionGameplay mission = MissionGameplay.Cast(GetGame().GetMission());
  15. if (mission)
  16. {
  17. IngameHud hud = IngameHud.Cast(mission.GetHud());
  18. if (hud)
  19. {
  20. hud.ShowHudUI(false);
  21. }
  22. }
  23. }
  24. void ~NoteMenu()
  25. {
  26. MissionGameplay mission = MissionGameplay.Cast(GetGame().GetMission());
  27. if (mission)
  28. {
  29. IngameHud hud = IngameHud.Cast(mission.GetHud());
  30. if (hud)
  31. {
  32. hud.ShowHudUI(true);
  33. }
  34. }
  35. }
  36. override void InitNoteRead(string text = "")
  37. {
  38. m_IsWriting = false;
  39. if (m_edit)
  40. {
  41. m_edit.Show(false);
  42. }
  43. if (m_html)
  44. {
  45. //TODO add text formating here. Just text string for now
  46. if (text)
  47. {
  48. m_html.Show(true);
  49. m_html.SetText(text);
  50. m_SymbolCount = text.Length(); //string.LengthUtf8() ?
  51. //m_html.SetText("<html><body><p>" + text + "</p></body></html>");
  52. }
  53. }
  54. m_confirm_button.Show(false);
  55. }
  56. override void InitNoteWrite(EntityAI paper, EntityAI pen, string text = "")
  57. {
  58. m_IsWriting = true;
  59. if (m_edit)
  60. {
  61. m_Paper = ItemBase.Cast(paper);
  62. m_Pen = pen;
  63. m_PenColor = m_Pen.ConfigGetString("writingColor");
  64. if (m_PenColor == "")
  65. {
  66. m_PenColor = "#000000";
  67. }
  68. //m_Handwriting = handwriting;
  69. m_edit.Show(true);
  70. m_edit.SetText(text);
  71. }
  72. if (m_html)
  73. {
  74. m_html.Show(false);
  75. }
  76. m_confirm_button.Show(true);
  77. }
  78. override Widget Init()
  79. {
  80. layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/day_z_inventory_note.layout");
  81. m_edit = MultilineEditBoxWidget.Cast(layoutRoot.FindAnyWidget("EditWidget"));
  82. m_html = HtmlWidget.Cast(layoutRoot.FindAnyWidget("HtmlWidget"));
  83. m_confirm_button = ButtonWidget.Cast(layoutRoot.FindAnyWidgetById(IDC_OK));
  84. return layoutRoot;
  85. }
  86. override bool OnClick(Widget w, int x, int y, int button)
  87. {
  88. super.OnClick(w, x, y, button);
  89. /* string txt;
  90. m_edit.GetText(txt);
  91. Print(m_edit.GetLinesCount());
  92. Print(txt);
  93. Print(txt.Length());*/
  94. switch (w.GetUserID())
  95. {
  96. case IDC_CANCEL:
  97. Close();
  98. return true;
  99. case IDC_OK:
  100. if (m_Paper && m_Pen && m_IsWriting)
  101. {
  102. string edit_text;
  103. m_edit.GetText(edit_text);
  104. edit_text = MiscGameplayFunctions.SanitizeString(edit_text);
  105. // Print("edit_text: " + edit_text);
  106. Param1<string> text = new Param1<string>(edit_text);
  107. m_Paper.RPCSingleParam(ERPCs.RPC_WRITE_NOTE_CLIENT, text, true);
  108. }
  109. Close();
  110. return true;
  111. }
  112. return false;
  113. }
  114. override void Update(float timeslice)
  115. {
  116. super.Update(timeslice);
  117. if (GetGame() && GetUApi().GetInputByID(UAUIBack).LocalPress())
  118. {
  119. Close();
  120. }
  121. }
  122. }