Advertisement
Guest User

BASS click handler + double clicks

a guest
Jun 25th, 2015
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.88 KB | None | 0 0
  1. //----------------------------------------------------------------------------------------------------
  2. // game_start()
  3. //----------------------------------------------------------------------------------------------------
  4. function game_start()
  5. {
  6.     lblActionText.Text = "";   
  7. }
  8.  
  9. //----------------------------------------------------------------------------------------------------
  10. // double clicks
  11. //--------------------
  12.  
  13. #define DCDELAY 7
  14. int lastclick, mx, my;
  15.  
  16. function left_click(bool single) {
  17.   if (single) {
  18.     // single-click code
  19.     ProcessClick(mx, my, eModeInteract );
  20.   }
  21.   else {    
  22.     // double-click code
  23.     ProcessClick(mx, my, eModeChRoom);
  24.   }
  25. }
  26.  
  27.  
  28. //----------------------------------------------------------------------------------------------------
  29. // on_mouse_click()
  30. //----------------------------------------------------------------------------------------------------
  31. function on_mouse_click(MouseButton button)
  32. {
  33.     // when mouse is clicked, text label is cleared
  34.     lblActionText.Text = "";
  35.    
  36.     // when game is paused, clicks aren't processed
  37.     if (IsGamePaused())
  38.     {
  39.         return;
  40.     }
  41.    
  42.     // Left Mouse Button on Object/Character/Hotspot/Location
  43.     // when no inventory is selected:
  44.     // - INTERACT with target
  45.     // - walk to location
  46.     // else
  47.     // - USE inventory on target
  48.     else if (button == eMouseLeft)
  49.     {
  50.         if (GetLocationType(mouse.x, mouse.y) != eLocationNothing)
  51.         {
  52.             if (player.ActiveInventory == null)
  53.             {
  54.         if (lastclick && mouse.x==mx && mouse.y==my) {
  55.           lastclick=0;
  56.           left_click(false);  
  57.         }
  58.         else {
  59.           lastclick=1;
  60.           mx=mouse.x;
  61.           my=mouse.y;
  62.         }
  63.             }
  64.             else
  65.             {
  66.                 ProcessClick(mouse.x, mouse.y, eModeUseinv);
  67.             }          
  68.            
  69.         }
  70.         else
  71.         {
  72.             if (player.ActiveInventory == null)
  73.             {
  74.                 ProcessClick(mouse.x, mouse.y, eModeWalkto);
  75.             }
  76.             else
  77.             {
  78.                 player.ActiveInventory = null;
  79.             }
  80.         }          
  81.     }
  82.  
  83.     // Right Mouse Button on Object/Character/Hotspot/Location
  84.     // when no inventory is selected:
  85.     // - EXAMINE target
  86.     // else
  87.     // - DESELECT inventory
  88.     else if (button == eMouseRight)
  89.     {
  90.         if (player.ActiveInventory != null)
  91.         {
  92.             player.ActiveInventory = null;
  93.         }
  94.        
  95.         else if (GetLocationType(mouse.x, mouse.y) != eLocationNothing)
  96.         {
  97.             ProcessClick(mouse.x, mouse.y, eModeLookat);
  98.         }
  99.     }
  100.    
  101.     // Left Mouse Button on Inventory Item
  102.     // when no inventory is selected:
  103.     // - INTERACT with target
  104.     // - SELECT target
  105.     // else
  106.     // - USE inventory on target
  107.     else if (button == eMouseLeftInv)
  108.     {
  109.         InventoryItem *i = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
  110.         if (i != null)
  111.         {
  112.             if (i.GetProperty("propInstantUse") == true)
  113.             {
  114.                 if (player.ActiveInventory == null)
  115.                 {
  116.                     i.RunInteraction(eModeInteract);
  117.                 }
  118.                 else
  119.                 {
  120.                     i.RunInteraction(eModeUseinv);
  121.                 }
  122.             }
  123.             else
  124.             {
  125.                 if (player.ActiveInventory == null)
  126.                 {
  127.                     player.ActiveInventory = i;
  128.                 }
  129.                 else
  130.                 {
  131.                     if (i.ID != player.ActiveInventory.ID)
  132.                     {
  133.                         i.RunInteraction(eModeUseinv);
  134.                     }
  135.                 }
  136.             }
  137.         }
  138.     }
  139.    
  140.     // Right Mouse Button on Inventory Item
  141.     // when no inventory is selected:
  142.     // - EXAMINE target
  143.     // else
  144.     // - DESELECT INVENTORY
  145.     else if (button == eMouseRightInv)
  146.     {
  147.         if (player.ActiveInventory != null)
  148.         {
  149.             player.ActiveInventory = null;
  150.             return;
  151.         }
  152.        
  153.         InventoryItem *i = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
  154.         if (i != null)
  155.         {
  156.             i.RunInteraction(eModeLookat);
  157.         }
  158.     }
  159.    
  160. }
  161.  
  162. //----------------------------------------------------------------------------------------------------
  163. // repeatedly_execute()
  164. //----------------------------------------------------------------------------------------------------
  165. function repeatedly_execute()
  166. {
  167.   // double clicks
  168.   if (lastclick>0 && lastclick<=DCDELAY) lastclick++;
  169.   else if (lastclick>DCDELAY) {
  170.     lastclick=0;
  171.     left_click(true);
  172.   }  
  173.  
  174.     // Inventory GUI:
  175.     // - make visible if mouse "touches" trigger zone
  176.     // - make invisible if mouse leaves inventory GUI
  177.     if (!gInventoryBar.Visible && mouse.y <= INVENTORY_POPUP_POSITION)
  178.     {
  179.         gInventoryBar.Visible = true;
  180.     }
  181.    
  182.     if (gInventoryBar.Visible && mouse.y > gInventoryBar.Height)
  183.     {
  184.         gInventoryBar.Visible = false;
  185.     }
  186.    
  187.     // Action Text
  188.     // We always display the name of what is under the mouse, with one exception:
  189.     // IF the player has an inventory item selected and hovers over the same inventory item,
  190.     // we display nothing to indicate that an item can not be used on itself
  191.     if (player.ActiveInventory == null)
  192.     {
  193.         lblActionText.Text = Game.GetLocationName(mouse.x, mouse.y);
  194.     }
  195.     else
  196.     {
  197.         InventoryItem *i = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
  198.         if (i != null && (i.ID == player.ActiveInventory.ID))
  199.         {
  200.             lblActionText.Text = "";
  201.         }
  202.         else
  203.         {
  204.             lblActionText.Text = Game.GetLocationName(mouse.x, mouse.y);
  205.         }
  206.     }
  207.  
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement