help.tscript 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. function HelpDlg::onWake(%this)
  23. {
  24. HelpFileList.entryCount = 0;
  25. HelpFileList.clear();
  26. for(%file = findFirstFile("*.hfl"); %file !$= ""; %file = findNextFile("*.hfl"))
  27. {
  28. HelpFileList.fileName[HelpFileList.entryCount] = %file;
  29. HelpFileList.addRow(HelpFileList.entryCount, fileBase(%file));
  30. HelpFileList.entryCount++;
  31. }
  32. HelpFileList.sortNumerical(0);
  33. for(%i = 0; %i < HelpFileList.entryCount; %i++)
  34. {
  35. %rowId = HelpFileList.getRowId(%i);
  36. %text = HelpFileList.getRowTextById(%rowId);
  37. %text = %i + 1 @ ". " @ restWords(%text);
  38. HelpFileList.setRowById(%rowId, %text);
  39. }
  40. HelpFileList.setSelectedRow(0);
  41. }
  42. function HelpFileList::onSelect(%this, %row)
  43. {
  44. %fo = new FileObject();
  45. %fo.openForRead(%this.fileName[%row]);
  46. %text = "";
  47. while(!%fo.isEOF())
  48. %text = %text @ %fo.readLine() @ "\n";
  49. %fo.delete();
  50. HelpText.setText(%text);
  51. }
  52. function getHelp(%helpName)
  53. {
  54. Canvas.pushDialog(HelpDlg);
  55. if(%helpName !$= "")
  56. {
  57. %index = HelpFileList.findTextIndex(%helpName);
  58. HelpFileList.setSelectedRow(%index);
  59. }
  60. }
  61. function contextHelp()
  62. {
  63. for(%i = 0; %i < Canvas.getCount(); %i++)
  64. {
  65. if(Canvas.getObject(%i).getName() $= HelpDlg)
  66. {
  67. Canvas.popDialog(HelpDlg);
  68. return;
  69. }
  70. }
  71. %content = Canvas.getContent();
  72. %helpPage = %content.getHelpPage();
  73. getHelp(%helpPage);
  74. }
  75. function GuiControl::getHelpPage(%this)
  76. {
  77. return %this.helpPage;
  78. }
  79. function GuiMLTextCtrl::onURL(%this, %url)
  80. {
  81. gotoWebPage( %url );
  82. }