Mercurial > wow > reaction
comparison Editor.lua @ 237:704f4a05a1d7
Demodulificate all bar options (except state options)
author | Flick |
---|---|
date | Thu, 24 Mar 2011 13:11:30 -0700 |
parents | a5d91d7fd485 |
children | f255cd69e890 |
comparison
equal
deleted
inserted
replaced
236:dcdc0235d489 | 237:704f4a05a1d7 |
---|---|
18 TOPRIGHT = L["Top Right"], | 18 TOPRIGHT = L["Top Right"], |
19 BOTTOMLEFT = L["Bottom Left"], | 19 BOTTOMLEFT = L["Bottom Left"], |
20 BOTTOMRIGHT = L["Bottom Right"], | 20 BOTTOMRIGHT = L["Bottom Right"], |
21 } | 21 } |
22 | 22 |
23 local Editor = { } | 23 local Editor = { |
24 buttonHandlers = { } | |
25 } | |
24 | 26 |
25 function Editor:New() | 27 function Editor:New() |
26 -- create new self | 28 -- create new self |
27 self = setmetatable( { }, { __index = self } ) | 29 self = setmetatable( { }, { __index = self } ) |
28 | 30 |
321 bigStep = 0.05, | 323 bigStep = 0.05, |
322 order = 4, | 324 order = 4, |
323 }, | 325 }, |
324 }, | 326 }, |
325 }, | 327 }, |
328 buttonOpts = self:CreateButtonOptions(bar) | |
326 }, | 329 }, |
327 plugins = { } | 330 plugins = { } |
328 } | 331 } |
329 end | 332 end |
330 | 333 |
345 end | 348 end |
346 end | 349 end |
347 end | 350 end |
348 end | 351 end |
349 | 352 |
353 function Editor:CreateButtonOptions(bar) | |
354 local buttonClass = bar:GetButtonClass() | |
355 local classID = buttonClass:GetButtonTypeID() | |
356 local handler = self.buttonHandlers[classID] | |
357 | |
358 if handler then | |
359 local h = handler:New(bar) | |
360 return h:GetOptions() | |
361 end | |
362 end | |
363 | |
350 function Editor:RefreshBarOptions() | 364 function Editor:RefreshBarOptions() |
351 for name, key in pairs(self.barOptMap) do | 365 for name, key in pairs(self.barOptMap) do |
352 if not ReAction:GetBar(name) then | 366 if not ReAction:GetBar(name) then |
353 self.barOptMap[name] = nil | 367 self.barOptMap[name] = nil |
354 self.options.args[key] = nil | 368 self.options.args[key] = nil |
394 local bar = ReAction:CreateBar(self.tmp.barName, self.tmp.barType or ReAction:GetDefaultBarType(), self.tmp.barRows, self.tmp.barCols, self.tmp.barSize, self.tmp.barSpacing) | 408 local bar = ReAction:CreateBar(self.tmp.barName, self.tmp.barType or ReAction:GetDefaultBarType(), self.tmp.barRows, self.tmp.barCols, self.tmp.barSize, self.tmp.barSpacing) |
395 if bar then | 409 if bar then |
396 AceConfigDialog:SelectGroup(self.configID, self.barOptMap[self.tmp.barName]) | 410 AceConfigDialog:SelectGroup(self.configID, self.barOptMap[self.tmp.barName]) |
397 self.tmp.barName = nil | 411 self.tmp.barName = nil |
398 end | 412 end |
413 end | |
414 end | |
415 | |
416 ------------------------------- | |
417 ---- Action button handler ---- | |
418 ------------------------------- | |
419 | |
420 do | |
421 local ActionHandler = { | |
422 buttonClass = ReAction.Button.Action, | |
423 options = { | |
424 hideEmpty = { | |
425 name = L["Hide Empty Buttons"], | |
426 order = 1, | |
427 type = "toggle", | |
428 width = "double", | |
429 get = "GetHideEmpty", | |
430 set = "SetHideEmpty", | |
431 }, | |
432 lockButtons = { | |
433 name = L["Lock Buttons"], | |
434 desc = L["Prevents picking up/dragging actions (use SHIFT to override this behavior)"], | |
435 order = 2, | |
436 type = "toggle", | |
437 get = "GetLockButtons", | |
438 set = "SetLockButtons", | |
439 }, | |
440 lockOnlyCombat = { | |
441 name = L["Only in Combat"], | |
442 desc = L["Only lock the buttons when in combat"], | |
443 order = 3, | |
444 type = "toggle", | |
445 disabled = "LockButtonsCombatDisabled", | |
446 get = "GetLockButtonsCombat", | |
447 set = "SetLockButtonsCombat", | |
448 }, | |
449 pages = { | |
450 name = L["# Pages"], | |
451 desc = L["Use the Dynamic State tab to specify page transitions"], | |
452 order = 4, | |
453 type = "range", | |
454 min = 1, | |
455 max = 10, | |
456 step = 1, | |
457 get = "GetNumPages", | |
458 set = "SetNumPages", | |
459 }, | |
460 mindcontrol = { | |
461 name = L["Mind Control Support"], | |
462 desc = L["When possessing a target (e.g. via Mind Control), map the first 12 buttons of this bar to the possessed target's actions."], | |
463 order = 5, | |
464 type = "toggle", | |
465 width = "double", | |
466 set = "SetMindControl", | |
467 get = "GetMindControl", | |
468 }, | |
469 vehicle = { | |
470 name = L["Vehicle Support"], | |
471 desc = L["When on a vehicle, map the first 6 buttons of this bar to the vehicle actions. The vehicle-exit button is mapped to the 7th button. Pitch controls are not supported."], | |
472 order = 6, | |
473 type = "toggle", | |
474 width = "double", | |
475 get = "GetVehicle", | |
476 set = "SetVehicle", | |
477 }, | |
478 actions = { | |
479 name = L["Edit Action IDs"], | |
480 order = 7, | |
481 type = "group", | |
482 inline = true, | |
483 args = { | |
484 method = { | |
485 name = L["Assign"], | |
486 order = 1, | |
487 type = "select", | |
488 width = "double", | |
489 values = { [0] = L["Choose Method..."], | |
490 [1] = L["Individually"], | |
491 [2] = L["All at Once"], }, | |
492 get = "GetActionEditMethod", | |
493 set = "SetActionEditMethod", | |
494 }, | |
495 rowSelect = { | |
496 name = L["Row"], | |
497 desc = L["Rows are numbered top to bottom"], | |
498 order = 2, | |
499 type = "select", | |
500 width = "half", | |
501 hidden = "IsButtonSelectHidden", | |
502 values = "GetRowList", | |
503 get = "GetSelectedRow", | |
504 set = "SetSelectedRow", | |
505 }, | |
506 colSelect = { | |
507 name = L["Col"], | |
508 desc = L["Columns are numbered left to right"], | |
509 order = 3, | |
510 type = "select", | |
511 width = "half", | |
512 hidden = "IsButtonSelectHidden", | |
513 values = "GetColumnList", | |
514 get = "GetSelectedColumn", | |
515 set = "SetSelectedColumn", | |
516 }, | |
517 pageSelect = { | |
518 name = L["Page"], | |
519 order = 4, | |
520 type = "select", | |
521 width = "half", | |
522 hidden = "IsPageSelectHidden", | |
523 values = "GetPageList", | |
524 get = "GetSelectedPage", | |
525 set = "SetSelectedPage", | |
526 }, | |
527 single = { | |
528 name = L["Action ID"], | |
529 usage = L["Specify ID 1-120"], | |
530 order = 5, | |
531 type = "input", | |
532 width = "half", | |
533 hidden = "IsButtonSelectHidden", | |
534 get = "GetActionID", | |
535 set = "SetActionID", | |
536 validate = "ValidateActionID", | |
537 }, | |
538 multi = { | |
539 name = L["ID List"], | |
540 usage = L["Specify a comma-separated list of IDs for each button in the bar (in order). Separate multiple pages with semicolons (;)"], | |
541 order = 6, | |
542 type = "input", | |
543 multiline = true, | |
544 width = "double", | |
545 hidden = "IsMultiIDHidden", | |
546 get = "GetMultiID", | |
547 set = "SetMultiID", | |
548 validate = "ValidateMultiID", | |
549 }, | |
550 }, | |
551 }, | |
552 } | |
553 } | |
554 | |
555 Editor.buttonHandlers[ActionHandler.buttonClass:GetButtonTypeID()] = ActionHandler | |
556 | |
557 local meta = { __index = ActionHandler } | |
558 | |
559 function ActionHandler:New( bar ) | |
560 return setmetatable( | |
561 { | |
562 bar = bar, | |
563 config = bar:GetConfig(), | |
564 }, | |
565 meta) | |
566 end | |
567 | |
568 function ActionHandler:Refresh() | |
569 self.buttonClass:SetupBar(self.bar) | |
570 end | |
571 | |
572 function ActionHandler:UpdateButtonLock() | |
573 self.buttonClass:SetButtonLock(self.bar, self.config.lockButtons, self.config.lockButtonsCombat) | |
574 end | |
575 | |
576 function ActionHandler:GetLastButton() | |
577 return self.bar:GetButton(self.bar:GetNumButtons()) | |
578 end | |
579 | |
580 -- options handlers | |
581 function ActionHandler:GetOptions() | |
582 return { | |
583 type = "group", | |
584 name = L["Action Buttons"], | |
585 handler = self, | |
586 order = 2, | |
587 args = self.options | |
588 } | |
589 end | |
590 | |
591 function ActionHandler:SetHideEmpty(info, value) | |
592 if value ~= self.config.hideEmpty then | |
593 self.config.hideEmpty = value | |
594 for _, b in self.bar:IterateButtons() do | |
595 b:ShowGrid(not value) | |
596 end | |
597 end | |
598 end | |
599 | |
600 function ActionHandler:GetHideEmpty() | |
601 return self.config.hideEmpty | |
602 end | |
603 | |
604 function ActionHandler:GetLockButtons() | |
605 return self.config.lockButtons | |
606 end | |
607 | |
608 function ActionHandler:SetLockButtons(info, value) | |
609 self.config.lockButtons = value | |
610 self:UpdateButtonLock() | |
611 end | |
612 | |
613 function ActionHandler:GetLockButtonsCombat() | |
614 return self.config.lockButtonsCombat | |
615 end | |
616 | |
617 function ActionHandler:SetLockButtonsCombat(info, value) | |
618 self.config.lockButtonsCombat = value | |
619 self:UpdateButtonLock() | |
620 end | |
621 | |
622 function ActionHandler:LockButtonsCombatDisabled() | |
623 return not self.config.lockButtons | |
624 end | |
625 | |
626 function ActionHandler:GetNumPages() | |
627 return self.config.nPages | |
628 end | |
629 | |
630 function ActionHandler:SetNumPages(info, value) | |
631 self.config.nPages = value | |
632 self:Refresh() | |
633 end | |
634 | |
635 function ActionHandler:GetMindControl() | |
636 return self.config.mindcontrol | |
637 end | |
638 | |
639 function ActionHandler:SetMindControl(info, value) | |
640 self.config.mindcontrol = value | |
641 self:Refresh() | |
642 end | |
643 | |
644 function ActionHandler:GetVehicle() | |
645 return self.config.vehicle | |
646 end | |
647 | |
648 function ActionHandler:SetVehicle(info, value) | |
649 self.config.vehicle = value | |
650 self:Refresh() | |
651 end | |
652 | |
653 function ActionHandler:GetActionEditMethod() | |
654 return self.editMethod or 0 | |
655 end | |
656 | |
657 function ActionHandler:SetActionEditMethod(info, value) | |
658 self.editMethod = value | |
659 end | |
660 | |
661 function ActionHandler:IsButtonSelectHidden() | |
662 return self.editMethod ~= 1 | |
663 end | |
664 | |
665 function ActionHandler:GetRowList() | |
666 local r,c = self.bar:GetButtonGrid() | |
667 if self.rowList == nil or #self.rowList ~= r then | |
668 local list = { } | |
669 for i = 1, r do | |
670 table.insert(list,i) | |
671 end | |
672 self.rowList = list | |
673 end | |
674 return self.rowList | |
675 end | |
676 | |
677 function ActionHandler:GetSelectedRow() | |
678 local r, c = self.bar:GetButtonGrid() | |
679 local row = self.selectedRow or 1 | |
680 if row > r then | |
681 row = 1 | |
682 end | |
683 self.selectedRow = row | |
684 return row | |
685 end | |
686 | |
687 function ActionHandler:SetSelectedRow(info, value) | |
688 self.selectedRow = value | |
689 end | |
690 | |
691 function ActionHandler:GetColumnList() | |
692 local r,c = self.bar:GetButtonGrid() | |
693 if self.columnList == nil or #self.columnList ~= c then | |
694 local list = { } | |
695 for i = 1, c do | |
696 table.insert(list,i) | |
697 end | |
698 self.columnList = list | |
699 end | |
700 return self.columnList | |
701 end | |
702 | |
703 function ActionHandler:GetSelectedColumn() | |
704 local r, c = self.bar:GetButtonGrid() | |
705 local col = self.selectedColumn or 1 | |
706 if col > c then | |
707 col = 1 | |
708 end | |
709 self.selectedColumn = col | |
710 return col | |
711 end | |
712 | |
713 function ActionHandler:SetSelectedColumn(info, value) | |
714 self.selectedColumn = value | |
715 end | |
716 | |
717 function ActionHandler:IsPageSelectHidden() | |
718 return self.editMethod ~= 1 or (self.config.nPages or 1) < 2 | |
719 end | |
720 | |
721 function ActionHandler:GetPageList() | |
722 local n = self.config.nPages or 1 | |
723 if self.pageList == nil or #self.pageList ~= n then | |
724 local p = { } | |
725 for i = 1, n do | |
726 table.insert(p,i) | |
727 end | |
728 self.pageList = p | |
729 end | |
730 return self.pageList | |
731 end | |
732 | |
733 function ActionHandler:GetSelectedPage() | |
734 local p = self.selectedPage or 1 | |
735 if p > (self.config.nPages or 1) then | |
736 p = 1 | |
737 end | |
738 self.selectedPage = p | |
739 return p | |
740 end | |
741 | |
742 function ActionHandler:SetSelectedPage(info, value) | |
743 self.selectedPage = value | |
744 end | |
745 | |
746 function ActionHandler:GetActionID() | |
747 local row = self.selectedRow or 1 | |
748 local col = self.selectedColumn or 1 | |
749 local r, c = self.bar:GetButtonGrid() | |
750 local n = (row-1) * c + col | |
751 local btn = self.bar:GetButton(n) | |
752 if btn then | |
753 return tostring(btn:GetActionID(self.selectedPage or 1)) | |
754 end | |
755 end | |
756 | |
757 function ActionHandler:SetActionID(info, value) | |
758 local row = self.selectedRow or 1 | |
759 local col = self.selectedColumn or 1 | |
760 local r, c = self.bar:GetButtonGrid() | |
761 local n = (row-1) * c + col | |
762 local btn = self.bar:GetButton(n) | |
763 if btn then | |
764 btn:SetActionID(tonumber(value), self.selectedPage or 1) | |
765 end | |
766 end | |
767 | |
768 function ActionHandler:ValidateActionID(info, value) | |
769 value = tonumber(value) | |
770 if value == nil or value < 1 or value > 120 then | |
771 return L["Specify ID 1-120"] | |
772 end | |
773 return true | |
774 end | |
775 | |
776 function ActionHandler:IsMultiIDHidden() | |
777 return self.editMethod ~= 2 | |
778 end | |
779 | |
780 function ActionHandler:GetMultiID() | |
781 local p = { } | |
782 for i = 1, self.config.nPages or 1 do | |
783 local b = { } | |
784 for _, btn in self.bar:IterateButtons() do | |
785 table.insert(b, btn:GetActionID(i)) | |
786 end | |
787 table.insert(p, table.concat(b,",")) | |
788 end | |
789 return table.concat(p,";\n") | |
790 end | |
791 | |
792 | |
793 local function ParseMultiID(nBtns, nPages, s) | |
794 if s:match("[^%d%s,;]") then | |
795 return nil | |
796 end | |
797 local p = { } | |
798 for list in s:gmatch("[^;]+") do | |
799 local pattern = ("^%s?$"):format(("%s*(%d+)%s*,"):rep(nBtns)) | |
800 local ids = { list:match(pattern) } | |
801 if #ids ~= nBtns then | |
802 return nil | |
803 end | |
804 table.insert(p,ids) | |
805 end | |
806 if #p ~= nPages then | |
807 return nil | |
808 end | |
809 return p | |
810 end | |
811 | |
812 function ActionHandler:SetMultiID(info, value) | |
813 local p = ParseMultiID(self.bar:GetNumButtons(), self.config.nPages or 1, value) | |
814 for page, b in ipairs(p) do | |
815 for button, id in ipairs(b) do | |
816 self.bar:GetButton(button):SetActionID(id, page) | |
817 end | |
818 end | |
819 end | |
820 | |
821 function ActionHandler:ValidateMultiID(info, value) | |
822 local bad = L["Invalid action ID list string"] | |
823 if value == nil or ParseMultiID(self.bar:GetNumButtons(), self.config.nPages or 1, value) == nil then | |
824 return bad | |
825 end | |
826 return true | |
827 end | |
828 end | |
829 | |
830 | |
831 ---------------------------------- | |
832 ---- PetAction button handler ---- | |
833 ---------------------------------- | |
834 | |
835 do | |
836 local PetHandler = { | |
837 buttonClass = ReAction.Button.PetAction, | |
838 } | |
839 | |
840 Editor.buttonHandlers[PetHandler.buttonClass:GetButtonTypeID()] = PetHandler | |
841 | |
842 local meta = { __index = PetHandler } | |
843 | |
844 function PetHandler:New(bar) | |
845 return setmetatable( | |
846 { | |
847 bar = bar, | |
848 config = bar.config | |
849 }, meta) | |
850 end | |
851 | |
852 function PetHandler:GetLockButtons() | |
853 return self.config.lockButtons | |
854 end | |
855 | |
856 function PetHandler:SetLockButtons(info, value) | |
857 self.config.lockButtons = value | |
858 self.buttonClass:UpdateButtonLock(self.bar) | |
859 end | |
860 | |
861 function PetHandler:GetLockButtonsCombat() | |
862 return self.config.lockButtonsCombat | |
863 end | |
864 | |
865 function PetHandler:SetLockButtonsCombat(info, value) | |
866 self.config.lockButtonsCombat = value | |
867 self.buttonClass:UpdateButtonLock(self.bar) | |
868 end | |
869 | |
870 function PetHandler:LockButtonsCombatDisabled() | |
871 return not self.config.lockButtons | |
872 end | |
873 | |
874 function PetHandler:GetOptions() | |
875 return { | |
876 type = "group", | |
877 name = L["Pet Buttons"], | |
878 handler = self, | |
879 order = 2, | |
880 args = { | |
881 lockButtons = { | |
882 name = L["Lock Buttons"], | |
883 desc = L["Prevents picking up/dragging actions (use SHIFT to override this behavior)"], | |
884 order = 2, | |
885 type = "toggle", | |
886 get = "GetLockButtons", | |
887 set = "SetLockButtons", | |
888 }, | |
889 lockOnlyCombat = { | |
890 name = L["Only in Combat"], | |
891 desc = L["Only lock the buttons when in combat"], | |
892 order = 3, | |
893 type = "toggle", | |
894 disabled = "LockButtonsCombatDisabled", | |
895 get = "GetLockButtonsCombat", | |
896 set = "SetLockButtonsCombat", | |
897 }, | |
898 } | |
899 } | |
900 end | |
901 end | |
902 | |
903 | |
904 ------------------------------------- | |
905 ---- Vehicle Exit button handler ---- | |
906 ------------------------------------- | |
907 | |
908 do | |
909 local VExitHandler = { | |
910 buttonClass = ReAction.Button.VehicleExit, | |
911 } | |
912 | |
913 Editor.buttonHandlers[VExitHandler.buttonClass:GetButtonTypeID()] = VExitHandler | |
914 | |
915 local meta = { __index = VExitHandler } | |
916 | |
917 function VExitHandler:New(bar) | |
918 return setmetatable( | |
919 { | |
920 bar = bar, | |
921 }, meta) | |
922 end | |
923 | |
924 function VExitHandler:GetConfig() | |
925 return self.bar:GetConfig() | |
926 end | |
927 | |
928 function VExitHandler:GetPassengerOnly() | |
929 return not self:GetConfig().withControls | |
930 end | |
931 | |
932 function VExitHandler:SetPassengerOnly(info, value) | |
933 self:GetConfig().withControls = not value | |
934 self.buttonClass:UpdateRegistration(self.bar) | |
935 end | |
936 | |
937 | |
938 function VExitHandler:GetOptions() | |
939 return { | |
940 type = "group", | |
941 name = L["Exit Vehicle"], | |
942 handler = self, | |
943 args = { | |
944 passengerOnly = { | |
945 name = L["Show only when passenger"], | |
946 desc = L["Only show the button when riding as a passenger in a vehicle (no vehicle controls)"], | |
947 order = 2, | |
948 width = "double", | |
949 type = "toggle", | |
950 get = "GetPassengerOnly", | |
951 set = "SetPassengerOnly", | |
952 }, | |
953 } | |
954 } | |
399 end | 955 end |
400 end | 956 end |
401 | 957 |
402 | 958 |
403 | 959 |