helpText.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 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 LeapToy::createHelpTextScene(%this, %helptext)
  23. {
  24. %this.clearHelpTextScene();
  25. %this.helpTextScene = new Scene(HelpTextScene);
  26. // Create the background
  27. %background = new Sprite();
  28. %background.setSize( 40, 30 );
  29. %background.setImage("ToyAssets:skyBackground");
  30. %background.setSceneLayer(20);
  31. HelpTextScene.add(%background);
  32. // Check if we have text
  33. if (%helptext.getCount() > 0)
  34. {
  35. %startingy = 0 + ((%helptext.getCount()/2) *0.6);
  36. %spacing = 0.75;
  37. %textsize = 0.6;
  38. // Iterate through the text lines
  39. for (%x = 0; %x < %helptext.getCount(); %x++)
  40. {
  41. %object = new ImageFont();
  42. %object.Image = "ToyAssets:Font";
  43. %object.FontSize = %textsize SPC %textsize;
  44. %object.TextAlignment = "Left";
  45. %positiony = %startingy - (%x * %spacing);
  46. %object.Position = "-17" SPC %positiony;
  47. %object.Text = %helptext.getObject(%x).Text;
  48. HelpTextScene.add(%object);
  49. }
  50. // Since we had text let's put up the help prompt.
  51. %helpPrompt = new ImageFont();
  52. %helpPrompt.Image = "ToyAssets:Font";
  53. %helpPrompt.FontSize = "0.7 0.7";
  54. %helpPrompt.TextAlignment = "Center";
  55. %helpPrompt.Position = "0 -12";
  56. %helpPrompt.Text = "Press H for help";
  57. SandboxScene.add(%helpPrompt);
  58. }
  59. }
  60. function LeapToy::toggleHelpTextScene(%this, %val)
  61. {
  62. if (!isObject(HelpTextScene) || !%val)
  63. return;
  64. if (SandboxWindow.getScene() $= %this.helpTextScene)
  65. SandboxWindow.setScene(SandboxScene);
  66. else
  67. SandboxWindow.setScene(HelpTextScene);
  68. }
  69. function LeapToy::clearHelpTextScene(%this)
  70. {
  71. if (!isObject(HelpTextScene))
  72. return;
  73. if (SandboxWindow.getScene() $= %this.helpTextScene)
  74. SandboxWindow.setScene(SandboxScene);
  75. HelpTextScene.clear();
  76. HelpTextScene.delete();
  77. }