changeset 118:5c189f44e776

Fixed rule-select so that you can select rules for classes you're not currently playing. Added "in a vehicle" rule
author Flick <flickerstreak@gmail.com>
date Fri, 06 Feb 2009 21:32:32 +0000
parents e2257bf1d717
children 79a44f66683f
files locale/enUS.lua modules/State.lua modules/modules.xml
diffstat 3 files changed, 71 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/locale/enUS.lua	Fri Feb 06 20:49:37 2009 +0000
+++ b/locale/enUS.lua	Fri Feb 06 21:32:32 2009 +0000
@@ -64,6 +64,7 @@
 "Friendly Focus",
 "No Focus",
 "Mind Control",
+"In a Vehicle",
 "Raid",
 "Party",
 "Solo",
--- a/modules/State.lua	Fri Feb 06 20:49:37 2009 +0000
+++ b/modules/State.lua	Fri Feb 06 21:32:32 2009 +0000
@@ -322,26 +322,47 @@
     end
   end
 
+  local playerClass = select(2, UnitClass("player"))
+  local function ClassFilter(...)
+    for i = 1, select('#',...) do
+      if playerClass == select(i,...) then
+        return false
+      end
+    end
+    return true
+  end
+
   -- As far as I can tell the macro clauses are NOT locale-specific.
+  -- 'filter' specifies whether rules should be omitted from execution.
+  -- 'true' indicates they should be filtered out.
   local ruleformats = { 
-    stealth       = "stealth",
-    nostealth     = "nostealth",
-    shadowform    = "form:1",
-    noshadowform  = "noform",
-    pet           = "pet",
-    nopet         = "nopet",
-    harm          = "target=target,harm",
-    help          = "target=target,help",
-    notarget      = "target=target,noexists",
-    focusharm     = "target=focus,harm",
-    focushelp     = "target=focus,help",
-    nofocus       = "target=focus,noexists",
-    raid          = "group:raid",
-    party         = "group:party",
-    solo          = "nogroup",
-    combat        = "combat",
-    nocombat      = "nocombat",
-    possess       = "bonusbar:5",
+    stealth       = { format = "stealth",        filter = ClassFilter("ROGUE","DRUID") },
+    nostealth     = { format = "nostealth",      filter = ClassFilter("ROGUE","DRUID") },
+    shadowform    = { format = "form:1",         filter = ClassFilter("PRIEST") },
+    noshadowform  = { format = "noform",         filter = ClassFilter("PRIEST") },
+    battle        = { format = "stance:1",       filter = ClassFilter("WARRIOR") },
+    defensive     = { format = "stance:2",       filter = ClassFilter("WARRIOR") },
+    berserker     = { format = "stance:3",       filter = ClassFilter("WARRIOR") },
+    caster        = { format = "form:0/2/4/5/6", filter = ClassFilter("DRUID") },
+    bear          = { format = "form:1",         filter = ClassFilter("DRUID") },
+    cat           = { format = "form:1",         filter = ClassFilter("DRUID") },
+    tree          = { format = "form:5",         filter = ClassFilter("DRUID") },
+    moonkin       = { format = "form:5",         filter = ClassFilter("DRUID") },
+    pet           = { format = "pet" },
+    nopet         = { format = "nopet" },
+    harm          = { format = "target=target,harm" },
+    help          = { format = "target=target,help" },
+    notarget      = { format = "target=target,noexists" },
+    focusharm     = { format = "target=focus,harm" },
+    focushelp     = { format = "target=focus,help" },
+    nofocus       = { format = "target=focus,noexists" },
+    raid          = { format = "group:raid" },
+    party         = { format = "group:party" },
+    solo          = { format = "nogroup" },
+    combat        = { format = "combat" },
+    nocombat      = { format = "nocombat" },
+    possess       = { format = "bonusbar:5" },
+    vehicle       = { format = "target=vehicle,exists" },
   }
 
   -- Have to do these shenanigans instead of hardcoding the stances/forms because the 
@@ -374,14 +395,13 @@
     local moonkin   = forms["Interface\\Icons\\Spell_Nature_ForceOfNature"] or 9
     local flight    = forms["Interface\\Icons\\Ability_Druid_FlightForm"] or 9 -- flight and swift flight share the same icon
 
-    ruleformats.battle    = "stance:1"
-    ruleformats.defensive = format("stance:%d",defensive)
-    ruleformats.berserker = format("stance:%d",berserker)
-    ruleformats.caster    = format("form:0/%d/%d/%d",aquatic, travel, flight)
-    ruleformats.bear      = format("form:%d",bear)
-    ruleformats.cat       = format("form:%d",cat)
-    ruleformats.tree      = format("form:%d",tree)
-    ruleformats.moonkin   = format("form:%d",moonkin)
+    ruleformats.defensive.format = format("stance:%d",defensive)
+    ruleformats.berserker.format = format("stance:%d",berserker)
+    ruleformats.caster.format    = format("form:0/%d/%d/%d", aquatic, travel, flight)
+    ruleformats.bear.format      = format("form:%d",bear)
+    ruleformats.cat.format       = format("form:%d",cat)
+    ruleformats.tree.format      = format("form:%d",tree)
+    ruleformats.moonkin.format   = format("form:%d",moonkin)
   end
 
   local function BuildRule(states)
@@ -402,7 +422,9 @@
         if c.values then
           local clauses = { }
           for key, value in pairs(c.values) do
-            table.insert(clauses, ruleformats[key])
+            if ruleformats[key] and not ruleformats[key].filter then
+              table.insert(clauses, ruleformats[key].format)
+            end
           end
           if #clauses > 0 then
             local sep = (type == "any") and "][" or ","
@@ -568,29 +590,20 @@
 
 local CreateBarOptions, RegisterPropertyOptions
 do
-  local playerClass = select(2, UnitClass("player"))
-  local function ClassCheck(...)
-    for i = 1, select('#',...) do
-      if playerClass == select(i,...) then
-        return false
-      end
-    end
-    return true
-  end
-
   -- pre-sorted by the order they should appear in
   local rules = {
-    --  rule          hidden                          fields
-    { "stance",  ClassCheck("WARRIOR"),          { {battle = L["Battle Stance"]}, {defensive = L["Defensive Stance"]}, {berserker = L["Berserker Stance"]} } },
-    { "form",    ClassCheck("DRUID"),            { {caster = L["Caster Form"]}, {bear = L["Bear Form"]}, {cat = L["Cat Form"]}, {tree = L["Tree of Life"]}, {moonkin = L["Moonkin Form"]} } },
-    { "stealth", ClassCheck("ROGUE","DRUID"),    { {stealth = L["Stealth"]}, {nostealth = L["No Stealth"]} } },
-    { "shadow",  ClassCheck("PRIEST"),           { {shadowform = L["Shadowform"]}, {noshadowform = L["No Shadowform"]} } },
-    { "pet",     ClassCheck("HUNTER","WARLOCK"), { {pet = L["With Pet"]}, {nopet = L["Without Pet"]} } },
-    { "target",  false,                          { {harm = L["Hostile Target"]}, {help = L["Friendly Target"]}, {notarget = L["No Target"]} } },
-    { "focus",   false,                          { {focusharm = L["Hostile Focus"]}, {focushelp = L["Friendly Focus"]}, {nofocus = L["No Focus"]} } },
-    { "possess", false,                          { {possess = L["Mind Control"]} } },
-    { "group",   false,                          { {raid = L["Raid"]}, {party = L["Party"]}, {solo = L["Solo"]} } },
-    { "combat",  false,                          { {combat = L["In Combat"]}, {nocombat = L["Out of Combat"]} } },
+    --  rule       fields
+    { "stance",  { {battle = L["Battle Stance"]}, {defensive = L["Defensive Stance"]}, {berserker = L["Berserker Stance"]} } },
+    { "form",    { {caster = L["Caster Form"]}, {bear = L["Bear Form"]}, {cat = L["Cat Form"]}, {tree = L["Tree of Life"]}, {moonkin = L["Moonkin Form"]} } },
+    { "stealth", { {stealth = L["Stealth"]}, {nostealth = L["No Stealth"]} } },
+    { "shadow",  { {shadowform = L["Shadowform"]}, {noshadowform = L["No Shadowform"]} } },
+    { "pet",     { {pet = L["With Pet"]}, {nopet = L["Without Pet"]} } },
+    { "target",  { {harm = L["Hostile Target"]}, {help = L["Friendly Target"]}, {notarget = L["No Target"]} } },
+    { "focus",   { {focusharm = L["Hostile Focus"]}, {focushelp = L["Friendly Focus"]}, {nofocus = L["No Focus"]} } },
+    { "possess", { {possess = L["Mind Control"]} } },
+    { "vehicle", { {vehicle = L["In a Vehicle"]} } },
+    { "group",   { {raid = L["Raid"]}, {party = L["Party"]}, {solo = L["Solo"]} } },
+    { "combat",  { {combat = L["In Combat"]}, {nocombat = L["Out of Combat"]} } },
   }
 
   local ruleSelect = { }
@@ -612,13 +625,11 @@
 
   -- unpack rules table into ruleSelect and ruleMap
   for _, c in ipairs(rules) do
-    local rule, hidden, fields = unpack(c)
-    if not hidden then
-      for _, field in ipairs(fields) do
-        local key, label = next(field)
-        table.insert(ruleSelect, label)
-        table.insert(ruleMap, key)
-      end
+    local rule, fields = unpack(c)
+    for _, field in ipairs(fields) do
+      local key, label = next(field)
+      table.insert(ruleSelect, label)
+      table.insert(ruleMap, key)
     end
   end
 
@@ -981,7 +992,7 @@
     local notified = false
     if self:GetRuleField("type") == "all" then
       for _, c in ipairs(rules) do
-        local rule, hidden, fields = unpack(c)
+        local rule, fields = unpack(c)
         local once = false
         if setkey then
           for idx, field in ipairs(fields) do
--- a/modules/modules.xml	Fri Feb 06 20:49:37 2009 +0000
+++ b/modules/modules.xml	Fri Feb 06 21:32:32 2009 +0000
@@ -13,4 +13,7 @@
 <Script file="Action.lua"/>
 <Script file="PetAction.lua"/>
 
+<!-- testing -->
+<Script file="Button.lua"/>
+
 </Ui>
\ No newline at end of file