home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / demo / client / scripts / mainMenuGui.cs < prev    next >
Encoding:
Text File  |  2005-11-23  |  4.5 KB  |  187 lines

  1. //-----------------------------------------------------------------------------
  2. // Torque Game Engine 
  3. // Copyright (C) GarageGames.com, Inc.
  4. //-----------------------------------------------------------------------------
  5.  
  6. //-----------------------------------------------------------------------------
  7. // MainMenuGui is the main Control through which the game shell is viewed.
  8. //-----------------------------------------------------------------------------
  9.  
  10. function MainMenuGui::onWake(%this)
  11. {
  12.    %this.pushThread(main_menu_thread);
  13.    OverlayBuyNow.setVisible(true);
  14. }
  15.  
  16. //-------------------------------------
  17. function MainMenuGui::getThread(%this)
  18. {
  19.    %top = menu_thread_stack.getCount();
  20.    if (%top > 0)
  21.       return menu_thread_stack.getObject(%top-1);
  22.    else
  23.       return 0;
  24. }
  25.  
  26.  
  27. //-------------------------------------
  28. function MainMenuGui::popCurrent(%this)
  29. {
  30.    if (%thread = %this.getThread())
  31.    {
  32.       Canvas.popDialog(%thread.getObject(%thread.page));
  33.       echo ("POP Current: " @ %thread.getName() @ " page: " @ %thread.page);
  34.    }
  35. }
  36.  
  37.  
  38. //-------------------------------------
  39. function MainMenuGui::pushThread(%this, %thread)
  40. {
  41.    echo ("PushThread: " @ %thread.getname());
  42.  
  43.    %this.popCurrent();
  44.    %thread.page = 0;
  45.    menu_thread_stack.add(%thread);
  46.    %this.update();
  47. }
  48.  
  49.  
  50. //-------------------------------------
  51. function MainMenuGui::popThread(%this)
  52. {
  53.    if (%thread = %this.getThread())
  54.    {
  55.       echo ("PopThread: " @ %thread.getname());
  56.  
  57.       %this.popCurrent();
  58.       menu_thread_stack.remove(%thread);
  59.       %this.update();
  60.    }
  61. }
  62.  
  63.  
  64. //-------------------------------------
  65. function MainMenuGui::isNextPage(%this)
  66. {
  67.    if ( !(%thread = %this.getThread()) )
  68.       return false;
  69.    echo ("isNext: " @ %thread.page @ " - " @ %thread.getCount());
  70.    return %thread.page < (%thread.getCount() - 1);
  71. }
  72.  
  73.  
  74. //-------------------------------------
  75. function MainMenuGui::isPrevPage(%this)
  76. {
  77.    if ( !(%thread = %this.getThread()) )
  78.       return false;
  79.    return %thread.page > 0;
  80. }
  81.  
  82.  
  83. //-------------------------------------
  84. function MainMenuGui::isPrevThread(%this)
  85. {
  86.    return menu_thread_stack.getCount() > 1;
  87. }
  88.  
  89.  
  90. //-------------------------------------
  91. function MainMenuGui::nextPage(%this)
  92. {
  93.    if (%this.isNextPage())
  94.    {
  95.       %this.popCurrent();
  96.       %thread = %this.getThread();
  97.       %thread.page = (%thread.page+1);
  98.       %this.update();
  99.    }
  100.    else
  101.       %this.popThread();
  102. }
  103.  
  104.  
  105. //-------------------------------------
  106. function MainMenuGui::prevPage(%this)
  107. {
  108.    if (%this.isPrevPage())
  109.    {
  110.       %this.popCurrent();
  111.       %thread = %this.getThread();
  112.       %thread.page = (%thread.page-1);
  113.       %this.update();
  114.    }
  115. }
  116.  
  117.  
  118. //-------------------------------------
  119. function MainMenuGui::update(%this)
  120. {
  121.    if (Canvas.getContent().getName() $= "GuiEditorGui")
  122.    {
  123.        %this.popCurrent();
  124.        Canvas.popdialog(OverlayDlg);
  125.        return;
  126.    }
  127.        
  128.    if (%thread = %this.getThread())
  129.    {
  130.       echo ("Update: " @ %thread.getName() @ " page: " @ %thread.page);
  131.       %page = %thread.getObject(%thread.page);
  132.       
  133.       // Setup default overlay buttons
  134.       OverlayTitle.setText("<just:center><shadowcolor:000000><shadow:1:1>" @ %page.title);
  135.       OverlayDesc.setText("");
  136.  
  137. //      OverlayNextPage.setVisible(%this.isNextPage());
  138.       OverlayNextPage.setVisible(%this.isNextPage() || (%this.isPrevPage() && %this.isPrevThread()));
  139.       OverlayNextPage.command = "MainMenuGui.nextPage();";
  140.  
  141.       OverlayPrevPage.setVisible(%this.isPrevPage());
  142.       OverlayPrevPage.command = "MainMenuGui.prevPage();";
  143.  
  144.       OverlayQuitPage.setVisible(false);
  145.       OverlayQuitPage.command = "quit();";
  146.  
  147.       if (!%this.isPrevPage())
  148.       {
  149.          if (%this.isPrevThread())
  150.          {
  151.             OverlayPrevPage.setVisible(true);
  152.             OverlayPrevPage.command = "MainMenuGui.popThread();";
  153.          }
  154.          else
  155.             OverlayQuitPage.setVisible(true);
  156.       }
  157.       
  158.       // Push the current page
  159.       Canvas.pushDialog(%page);
  160.  
  161.       // make sure The Overlay is on top
  162.       Canvas.popdialog(OverlayDlg);
  163.       Canvas.pushdialog(OverlayDlg);
  164.    }
  165. }
  166.  
  167.  
  168. //-------------------------------------
  169. function MainMenuGui::onSleep(%this)
  170. {
  171. }
  172.  
  173. //-------------------------------------
  174. function MainMenuGui::goHome(%this)
  175. {
  176.    disconnect();
  177.    if (Canvas.getContent() != %this.getId())
  178.       Canvas.pushDialog(%this);
  179.    else {
  180.       while (%this.isPrevThread())
  181.          %this.popThread();
  182.    }
  183. }
  184.  
  185.  
  186.  
  187.