View Single Post
01-13-21, 08:01 PM   #9
kurapica.igas
A Chromatic Dragonspawn
Join Date: Aug 2011
Posts: 152
The reactive system is already done, a nameplate mod released at https://www.curseforge.com/wow/addons/aim.

It's a tiny mod, almost all indicators are skin settings defined in the DefaultSkin.lua.

Take the healthbar as an example:

Lua Code:
  1. HealthBar               = {
  2.     -- like class in css, share skin settings with a table for many elements
  3.     SHARE_STATUSBAR_SKIN,  
  4.  
  5.     location = { Anchor("BOTTOMLEFT"), Anchor("BOTTOMRIGHT") },
  6.     height = BAR_HEIGHT,
  7.    
  8.     -- threat, tap, class color
  9.     statusBarColor = Wow.UnitExtendColor(true),
  10.  
  11.     -- The minmax value for the status bar
  12.     minMaxValues = Wow.UnitHealthMax(),
  13.  
  14.     -- Use smooth value instead the value, use NIL to block the default settings
  15.     value = NIL,
  16.  
  17.     -- An extended property works for slider and statusbar for smoothing effect
  18.     -- the unit's health value will be dispatched here
  19.     smoothValue = Wow.UnitHealth(),
  20.  
  21.     -- the back ground settings with a dynamic color for target
  22.     backgroundFrame = {
  23.         -- The border color turn white if the unit is player's target
  24.         backdropBorderColor = Wow.UnitIsTarget():Map(function(val) return val and Color.WHITE or  Color.BLACK end),
  25.     },
  26. },

The APIs like Wow.UnitHealth() will subscribe the UNIT_HEALTH event observable, and match the unit provided by the healthbar's parent(or parent's parent until find a UnitFrame).

The API's definition is simple:

Lua Code:
  1. function Wow.UnitHealth()
  2.     -- Use the Next for a tiny delay after the UnitHealthMax
  3.     return Wow.FromUnitEvent("UNIT_HEALTH", "UNIT_MAXHEALTH"):Next():Map(UnitHealth)
  4. end

The Wow.FromUnitEvent will be used to bind the UNIT event and the unit from the parent. The Next() will delay the data dispatch for one frame and distinct it, so it won't be send twice or more, also make sure the value will be a tiny later than the Wow.UnitHealthMax which will change the status bar's minMax.

Full document will be out in the github when another mod for Raid Panel is released.
  Reply With Quote