Advertisement
offyerrocker

HUDHitConfirm.lua

Aug 9th, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.73 KB | None | 0 0
  1. CloneClass(HUDHitConfirm)
  2.  
  3. --[[function HUDHitConfirm.init(self, hud)
  4.     self.orig.init(self, hud)
  5.     self._hud_panel = hud.panel
  6.     if self._hud_panel:child("hit_confirm") then
  7.         self._hud_panel:remove(self._hud_panel:child("hit_confirm"))
  8.     end
  9.     if self._hud_panel:child("headshot_confirm") then
  10.         self._hud_panel:remove(self._hud_panel:child("headshot_confirm"))
  11.     end
  12.     if self._hud_panel:child("crit_confirm") then
  13.         self._hud_panel:remove(self._hud_panel:child("crit_confirm"))
  14.     end
  15.     self._hit_confirm = self._hud_panel:bitmap({
  16.         valign = "center",
  17.         halign = "center",
  18.         visible = false,
  19.         name = "hit_confirm",
  20.         texture = "guis/textures/pd2/hitconfirm",
  21.         color = Color.white,
  22.         layer = 0,
  23.         blend_mode = "add"
  24.     })
  25.     self._hit_confirm:set_center(self._hud_panel:w() / 2, self._hud_panel:h() / 2)
  26.     self._crit_confirm = self._hud_panel:bitmap({
  27.         valign = "center",
  28.         halign = "center",
  29.         visible = false,
  30.         name = "crit_confirm",
  31.         texture = "guis/textures/pd2/hitconfirm_crit",
  32.         color = Color.white,
  33.         layer = 0,
  34.         blend_mode = "add"
  35.     })
  36.     self._crit_confirm:set_center(self._hud_panel:w() / 2, self._hud_panel:h() / 2)
  37.    
  38.    
  39. end]]--
  40.  
  41. --[[function HUDHitConfirm:on_hit_confirmed()
  42.     self._hit_confirm:stop()
  43.     self._hit_confirm:animate(callback(self, self, "_animate_show"), callback(self, self, "show_done"), 0.25)
  44. end
  45.  
  46. function HUDHitConfirm:on_headshot_confirmed()
  47.     self._hit_confirm:stop()
  48.     self._hit_confirm:animate(callback(self, self, "_animate_show"), callback(self, self, "show_done"), 0.25)
  49. end
  50.  
  51. function HUDHitConfirm:on_crit_confirmed()
  52.     self._crit_confirm:stop()
  53.     self._crit_confirm:animate(callback(self, self, "_animate_show"), callback(self, self, "show_done"), 0.25)
  54. end
  55.  
  56. function HUDHitConfirm:_animate_show(hint_confirm, done_cb, seconds)
  57.     hint_confirm:set_visible(true)
  58.     hint_confirm:set_alpha(1)
  59.     local t = seconds
  60.     while t > 0 do
  61.         local dt = coroutine.yield()
  62.         t = t - dt
  63.         hint_confirm:set_alpha(t / seconds)
  64.     end
  65.     hint_confirm:set_visible(false)
  66.     done_cb()
  67. end]]--
  68.  
  69. function HUDHitConfirm:update_crosshair()
  70.     self._crosshair_main:set_color(Color(CusCrosshair.loaded_options.HUD.RGB_R, CusCrosshair.loaded_options.HUD.RGB_G, CusCrosshair.loaded_options.HUD.RGB_B):with_alpha(CusCrosshair.loaded_options.HUD.RGB_ALPHA))
  71.     self._crosshair_left:set_color(Color(CusCrosshair.loaded_options.HUD.RGB_R, CusCrosshair.loaded_options.HUD.RGB_G, CusCrosshair.loaded_options.HUD.RGB_B):with_alpha(CusCrosshair.loaded_options.HUD.RGB_ALPHA))
  72.     self._crosshair_right:set_color(Color(CusCrosshair.loaded_options.HUD.RGB_R, CusCrosshair.loaded_options.HUD.RGB_G, CusCrosshair.loaded_options.HUD.RGB_B):with_alpha(CusCrosshair.loaded_options.HUD.RGB_ALPHA))
  73.     self._crosshair_above:set_color(Color(CusCrosshair.loaded_options.HUD.RGB_R, CusCrosshair.loaded_options.HUD.RGB_G, CusCrosshair.loaded_options.HUD.RGB_B):with_alpha(CusCrosshair.loaded_options.HUD.RGB_ALPHA))
  74.     self._crosshair_below:set_color(Color(CusCrosshair.loaded_options.HUD.RGB_R, CusCrosshair.loaded_options.HUD.RGB_G, CusCrosshair.loaded_options.HUD.RGB_B):with_alpha(CusCrosshair.loaded_options.HUD.RGB_ALPHA))
  75.  
  76.     self._crosshair_left:set_w(CusCrosshair.loaded_options.HUD.cross_length)
  77.     self._crosshair_left:set_h(CusCrosshair.loaded_options.HUD.cross_width)
  78.     self._crosshair_right:set_w(CusCrosshair.loaded_options.HUD.cross_length)
  79.     self._crosshair_right:set_h(CusCrosshair.loaded_options.HUD.cross_width)
  80.     self._crosshair_above:set_h(CusCrosshair.loaded_options.HUD.cross_length_tb)
  81.     self._crosshair_above:set_w(CusCrosshair.loaded_options.HUD.cross_width_tb)
  82.     self._crosshair_below:set_h(CusCrosshair.loaded_options.HUD.cross_length_tb)
  83.     self._crosshair_below:set_w(CusCrosshair.loaded_options.HUD.cross_width_tb)
  84.     self._crosshair_main:set_w(CusCrosshair.loaded_options.HUD.dot_length)
  85.     self._crosshair_main:set_h(CusCrosshair.loaded_options.HUD.dot_length)
  86.    
  87.     self._crosshair_main:set_center(self._hud_panel:center())
  88.    
  89.     self._crosshair_left:set_center(self._hud_panel:center())
  90.     self._crosshair_left:set_right(self._crosshair_main:left())
  91.    
  92.     self._crosshair_right:set_center(self._hud_panel:center())
  93.     self._crosshair_right:set_left(self._crosshair_main:right())
  94.    
  95.     self._crosshair_above:set_center(self._hud_panel:center())
  96.     self._crosshair_above:set_bottom(self._crosshair_main:top())
  97.    
  98.     self._crosshair_below:set_center(self._hud_panel:center())
  99.     self._crosshair_below:set_top(self._crosshair_main:bottom())
  100.    
  101.     self._crosshair_main:set_visible(CusCrosshair.loaded_options.HUD.Dot)
  102. end
  103.  
  104. function HUDHitConfirm:_animate_show(hint_confirm, done_cb, seconds)
  105.     hint_confirm:set_visible(true)
  106.     hint_confirm:set_alpha(1)
  107.  
  108.     local t = seconds
  109.  
  110.     while t > 0 do
  111.         local dt = coroutine.yield()
  112.         t = t - dt
  113.         local alpha = t/seconds
  114.    
  115.     --offy wuz hear v
  116.         self._crosshair_main:set_visible(false)
  117.         self._crosshair_left:set_visible(false)
  118.         self._crosshair_right:set_visible(false)
  119.         self._crosshair_above:set_visible(false)
  120.         self._crosshair_below:set_visible(false)
  121.     --offy wuz hear ^
  122.        
  123.         hint_confirm:set_alpha(t / seconds)
  124.     end
  125.  
  126.     hint_confirm:set_visible(false)
  127.     done_cb()
  128. end
  129.  
  130. function HUDHitConfirm:tick(t, dt)
  131.     if true then return false end
  132.     --offy wuz hear. i dummied out this function so that it wouldn't keep displaying the crosshair every frame
  133.    
  134.     local player = managers.player:local_player()
  135.     local in_steelsight = alive(player) and player:movement() and player:movement():current_state() and player:movement():current_state():in_steelsight() or false
  136.     if in_steelsight and CusCrosshair.loaded_options.HUD.Hide_on_zoom then
  137.         self._crosshair_main:set_visible(false)
  138.         self._crosshair_left:set_visible(false)
  139.         self._crosshair_right:set_visible(false)
  140.         self._crosshair_above:set_visible(false)
  141.         self._crosshair_below:set_visible(false)
  142.     else
  143.         self._crosshair_main:set_visible(CusCrosshair.loaded_options.HUD.Dot)
  144.         self._crosshair_left:set_visible(true)
  145.         self._crosshair_right:set_visible(true)
  146.         self._crosshair_above:set_visible(true)
  147.         self._crosshair_below:set_visible(true)
  148.     end
  149. end
  150.  
  151. Hooks:PostHook(HUDHitConfirm,"show_done","divebomber_done_anim_hit",function(self)
  152. --when done animating hitmarker...
  153.     local player = managers.player:local_player()
  154.     local in_steelsight = alive(player) and player:movement() and player:movement():current_state() and player:movement():current_state():in_steelsight() or false
  155.     if not (in_steelsight and CusCrosshair.loaded_options.HUD.Hide_on_zoom) then
  156.     --show crosshair if done animating, and not in steelsight
  157.         self._crosshair_main:set_visible(CusCrosshair.loaded_options.HUD.Dot)
  158.         self._crosshair_left:set_visible(true)
  159.         self._crosshair_right:set_visible(true)
  160.         self._crosshair_above:set_visible(true)
  161.         self._crosshair_below:set_visible(true)
  162.     end
  163. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement