Advertisement
Guest User

EmuButton with frame delay

a guest
Jul 21st, 2021
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Emu (c) 2020 @dragonitespam
  2. // See the Github wiki for documentation: https://github.com/DragoniteSpam/Emu/wiki
  3. function EmuButton(x, y, w, h, delay, text, callback) : EmuCallback(x, y, w, h, 0, callback) constructor {
  4.     self.text = text;
  5.     self.alignment = fa_center;
  6.     self.valignment = fa_middle;
  7.    
  8.     self.color_hover = EMU_COLOR_HOVER;
  9.     self.color_back = EMU_COLOR_BACK;
  10.     self.color_disabled = EMU_COLOR_DISABLED;
  11.    
  12.     self.frame_delay = max(1, delay);
  13.    
  14.     Render = function(base_x, base_y) {
  15.         processAdvancement();
  16.        
  17.         var x1 = x + base_x;
  18.         var y1 = y + base_y;
  19.         var x2 = x1 + width;
  20.         var y2 = y1 + height;
  21.        
  22.         if (frame_delay <= 0) {
  23.             if (getMouseHover(x1, y1, x2, y2)) {
  24.                 ShowTooltip();
  25.             }
  26.        
  27.             if (getMouseReleased(x1, y1, x2, y2)) {
  28.                 Activate();
  29.                 callback();
  30.             }
  31.         }
  32.        
  33.         var back_color = getMouseHover(x1, y1, x2, y2) ? color_hover : ((GetInteractive() and frame_delay <= 0) ? color_back : color_disabled);
  34.         drawNineslice(1, x1, y1, x2, y2, back_color, 1);
  35.         drawNineslice(0, x1, y1, x2, y2, color, 1);
  36.        
  37.         scribble_set_box_align(alignment, valignment);
  38.         scribble_set_wrap(width, height);
  39.         scribble_draw(floor(mean(x1, x2)), floor(mean(y1, y2)), text);
  40.        
  41.         if (frame_delay > 0) frame_delay --;
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement