SHARE
TWEET

Untitled

a guest Jan 12th, 2017 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local BoardData = require("level.modules.board_data")
  2.  
  3. local ANIMATION_TIME = 1
  4. local ANIMATION_DISSAPEAR_TIME = 0.5
  5. local SHADE_ALPHA = 0.8
  6. local POINTER_DEALY = 1
  7. local POINTER_MOVE_TIME = 1
  8. local INITIAL_TIMEOUT_BEFORE_APPEAR = 1
  9.  
  10.  
  11. function init(self)
  12.     gui.set_render_order(90)
  13.     self.info_stripe_node = gui.get_node("info_stripe")
  14.     self.left_part_node = gui.get_node("left_part")
  15.     self.right_part_node = gui.get_node("right_part")
  16.     self.shade_node = gui.get_node("shade")
  17.     self.pointer_node = gui.get_node("pointer")
  18.     self.pointer_sprite = gui.get_node("pointer_sprite")
  19.     self.pointer_start_position = gui.get_position(gui.get_node("pointer_from"))
  20.     self.pointer_end_position = gui.get_position(gui.get_node("pointer_to"))
  21.     set_node_status(self, false)
  22.     self.config = json.decode(gui.get_text(gui.get_node("config")))
  23.     self.show_pointer = false
  24.     self.pointer_counter = 0
  25.     self.data_appeared = false
  26. end
  27.  
  28. function set_node_status(self, status)
  29.     gui.set_enabled(self.shade_node, status)
  30.     gui.set_enabled(self.pointer_node, status)
  31.     gui.set_enabled(self.left_part_node, status)
  32.     gui.set_enabled(self.right_part_node, status)
  33.     gui.set_enabled(self.info_stripe_node, status)
  34. end
  35.  
  36. function update(self, dt)
  37.     if self.data_appeared == false and BoardData.turn_number == self.config.turn_number then
  38.       self.initial_timer = (self.initial_timer or 0) + dt
  39.       if self.initial_timer > INITIAL_TIMEOUT_BEFORE_APPEAR then
  40.         self.data_appeared = true
  41.         move_captions(self)
  42.       end
  43.     end
  44.  
  45.     if self.show_pointer then
  46.       if BoardData.selected_cell then
  47.         self.pointer_counter = 0
  48.       else
  49.         self.pointer_counter = self.pointer_counter + dt
  50.       end
  51.  
  52.       if self.pointer_counter > (POINTER_DEALY + POINTER_MOVE_TIME) then
  53.         move_pointer_and_hide(self)
  54.         self.pointer_counter = 0
  55.       end
  56.     end
  57.  
  58.     if self.data_appeared and BoardData.target_cell and not self.destroy_in_progress then
  59.       print("im here", self.config.turn_number)
  60.       self_destroy(self)
  61.     end
  62. end
  63.  
  64. function self_destroy(self)
  65.   self.destroy_in_progress = true
  66.   self.show_pointer = false
  67.    
  68.   animate_disappear(self, self.stripe_data)
  69.   animate_disappear(self, self.left_data)
  70.   animate_disappear(self, self.right_data)
  71.  
  72.   local disable = function()
  73.     msg.post(msg.url(), "disable")
  74.   end
  75.   gui.animate(self.shade_node, "color", self.start_shade_color, gui.EASING_LINEAR, ANIMATION_DISSAPEAR_TIME, 0, disable)
  76. end
  77.  
  78.  
  79. function get_node_data(self, node)
  80.   local result = {}
  81.   result.node = node
  82.   result.original_position =  gui.get_position(node)
  83.   result.start_position = vmath.vector3(result.original_position)
  84.   result.size = gui.get_size(node)
  85.   return result
  86. end
  87.  
  88. function animate_appear(self, data, on_done)
  89.   gui.set_position(data.node, data.start_position)
  90.   gui.animate(data.node, "position", data.original_position, gui.EASING_OUTBACK, ANIMATION_TIME, 0, on_done)
  91. end
  92.  
  93. function animate_disappear(self, data, on_done)
  94.   gui.animate(data.node, "position", data.start_position, gui.EASING_INBACK, ANIMATION_DISSAPEAR_TIME, 0, on_done)
  95. end
  96.  
  97. function  move_captions(self)
  98.     set_node_status(self, true)
  99.     gui.set_enabled(self.pointer_node, false)
  100.  
  101.     self.stripe_data = get_node_data(self, self.info_stripe_node)
  102.     self.stripe_data.start_position.y = -self.stripe_data.size.y / 2
  103.     animate_appear(self, self.stripe_data)
  104.  
  105.     self.left_data = get_node_data(self, self.left_part_node)
  106.     self.left_data.start_position.x = -self.left_data.size.x / 2
  107.     animate_appear(self, self.left_data)
  108.  
  109.     self.right_data = get_node_data(self, self.right_part_node)
  110.     self.right_data.start_position.x = gui.get_width() + self.right_data.size.x / 2
  111.     animate_appear(self, self.right_data)
  112.  
  113.     show_shade(self)
  114. end
  115.  
  116. function show_shade(self)
  117.   self.original_shade_color = gui.get_color(self.shade_node)
  118.   self.start_shade_color = vmath.vector4(self.original_shade_color)
  119.   self.start_shade_color.w = 0
  120.   gui.set_color(self.shade_node, self.start_shade_color)
  121.   gui.animate(self.shade_node, "color", self.original_shade_color, gui.EASING_LINEAR, ANIMATION_TIME / 2, ANIMATION_TIME / 2, function() self.show_pointer = true end )
  122. end
  123.  
  124.  
  125. function move_pointer_and_hide(self)
  126.   gui.set_enabled(self.pointer_node, true)
  127.   gui.set_position(self.pointer_node, self.pointer_start_position)
  128.   gui.set_color(self.pointer_sprite, vmath.vector4(1,1,1,0))
  129.   gui.animate(self.pointer_node, "position", self.pointer_end_position, gui.EASING_LINEAR, POINTER_MOVE_TIME, 0, show_pointer_with_delay)
  130.   gui.animate(self.pointer_sprite, "color", vmath.vector4(1), gui.EASING_INOUTCUBIC, POINTER_MOVE_TIME, 0, nil, gui.PLAYBACK_ONCE_PINGPONG )
  131. end
RAW Paste Data
Top