Mercurial > wow > reaction
changeset 11:88df7235ad8b
Version 0.33, part 2
author | Flick <flickerstreak@gmail.com> |
---|---|
date | Tue, 20 Mar 2007 21:38:47 +0000 |
parents | f3a7bfebc283 |
children | 2735edcf9ab7 |
files | classes/ReBound.lua classes/ReBound.xml |
diffstat | 2 files changed, 0 insertions(+), 400 deletions(-) [+] |
line wrap: on
line diff
--- a/classes/ReBound.lua Tue Mar 20 21:37:38 2007 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,158 +0,0 @@ --- ReBound.lua --- - - -local AceEvent = AceLibrary("AceEvent-2.0") - -ReBound = { } - --- initial values -ReBound.active = false - -ReBound.targets = { } - -function ReBound:AddKeybindTarget( t ) - if t then - self.targets[t] = CreateFrame("Button", nil, t, "ReBoundClickBindingTemplate") - self.targets[t].keybindTarget = t:GetName() - end -end - -function ReBound:RemoveKeybindTarget( t ) - if t then - self.targets[t] = nil - end -end - -function ReBound:ShowClickBindingButtons() - AceEvent:TriggerEvent("EVENT_REBOUND_KEYBINDING_MODE", true) - for tgt, clickFrame in pairs(self.targets) do - clickFrame:Show() - end -end - -function ReBound:HideClickBindingButtons() - AceEvent:TriggerEvent("EVENT_REBOUND_KEYBINDING_MODE", false) - for tgt, clickFrame in pairs(self.targets) do - clickFrame:Hide() - end -end - -function ReBound:ClearSelectedKey() - self.selectedKey = nil - SetCursor(nil) -- reset cursor to default state -end - -function ReBound:ToggleEnabled() - if self:IsEnabled() then - self:Disable() - else - self:Enable() - end -end - -function ReBound:IsEnabled() - return ReBoundFrame:IsVisible() -end - -function ReBound:Enable() - if InCombatLockdown() then - UIErrorsFrame:AddMessage("Can't set keybindings in combat") - else - ReBoundFrame:Show() - end -end - -function ReBound:Disable() - ReBoundFrame:Hide() -end - - -local mouseButtonConvert = { - LeftButton = "BUTTON1", - RightButton = "BUTTON2", - MiddleButton = "BUTTON3", - Button4 = "BUTTON4", - Button5 = "BUTTON5" -} - -function ReBound:HandleKeyPressed( key ) - if key == nil or key == "UNKNOWN" or key == "SHIFT" or key == "CTRL" or key == "ALT" then - return - end - if IsShiftKeyDown() then - key = "SHIFT-"..key - end - if IsControlKeyDown() then - key = "CTRL-"..key - end - if IsAltKeyDown() then - key = "ALT-"..key - end - if key == "ESCAPE" or GetBindingAction(key) == "ReBound_TOGGLEBINDINGMODE" then - ReBoundFrame:Hide() - return nil, nil - end - key = mouseButtonConvert[key] or key - - self.selectedKey = key - - -- change cursor to glowing hand - SetCursor("CAST_CURSOR") - - local keyTxt = GetBindingText(key, "KEY_") - local cmd = GetBindingAction(key) - local cmdTxt - - if cmd then - cmdTxt = GetBindingText(cmd, "BINDING_NAME_") - end - - -- make click-bindings look prettier - local btnName - if cmdTxt then - btnName = string.match(cmdTxt,"CLICK (.+)\:LeftButton") - btnName = btnName or string.match(cmdTxt,"CLICK (.+)\:RightButton") - end - - return keyTxt, btnName or cmdTxt -end - --- TODO: move to override-binding model and store data in profile -function ReBound:BindSelectedKeyTo( btnName ) - if self.selectedKey and btnName then - self:ClearBinding(btnName) - SetBindingClick(self.selectedKey, btnName, "LeftButton") - SaveBindings(2) -- 2 = character-specific - ReBoundFrame.statusMsg:SetText(GetBindingText(self.selectedKey, "KEY_") .. " is now bound to " .. btnName) - ReBoundFrame.selectedKey:SetText("(none)") - ReBoundFrame.currentAction:SetText("(none)") - self:ClearSelectedKey() - end -end - - -function ReBound:ClearBinding( btnName ) - if btnName then - local current = GetBindingKey("CLICK "..btnName..":LeftButton") - if current then - SetBinding(current, nil) - ReBoundFrame.statusMsg:SetText("|cFFFF3333"..btnName .. " is now unbound|r") - end - end -end - - -function ReBound:UpdateCurrentTarget( btnName ) - local msg = "" - if btnName then - msg = btnName.." is currently " - local current = GetBindingKey("CLICK "..btnName..":LeftButton") - if current then - msg = msg .. "bound to " .. GetBindingText(current, "KEY_") - else - msg = msg .. " not bound" - end - end - ReBoundFrame.statusMsg:SetText(msg) -end
--- a/classes/ReBound.xml Tue Mar 20 21:37:38 2007 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,246 +0,0 @@ -<Ui xmlns="http://www.blizzard.com/wow/ui/" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://www.blizzard.com/wow/ui/..\FrameXML\UI.xsd"> - - - <Button name="ReBoundClickBindingTemplate" virtual="true" hidden="true" toplevel="true" setAllPoints="true"> - <HighlightTexture alphaMode="ADD" file="Interface\Buttons\ButtonHilight-Square"/> - <Layers> - <Layer level="BACKGROUND"> - <Texture> - <Color r="0" g="0" b="0" a="0"/> - </Texture> - </Layer> - </Layers> - <Scripts> - <OnLoad> - this:RegisterForClicks("LeftButtonUp","RightButtonUp") - </OnLoad> - <OnClick> - local mouseBtn = arg1 - if mouseBtn == "LeftButton" then - ReBound:BindSelectedKeyTo(this.keybindTarget) - elseif mouseBtn == "RightButton" then - ReBound:ClearBinding(this.keybindTarget) - end - </OnClick> - <PostClick> - this:SetButtonState("NORMAL") - </PostClick> - <OnEnter> - ReBound:UpdateCurrentTarget(this.keybindTarget) - </OnEnter> - <OnLeave> - ReBound:UpdateCurrentTarget(nil) - </OnLeave> - </Scripts> - </Button> - - - <!-- this frame covers the entire UIParent. It is visible but empty and in the background, so all it does is consume key presses and unhandled mouse clicks --> - <Button name="ReBoundFrame" frameStrata="BACKGROUND" movable="false" enableMouse="true" enableKeyboard="true" parent="UIParent" hidden="true" setAllPoints="true"> - <Frames> - <!-- this is a dialog frame that appears to provide user feedback for the outer frame --> - <Button name="$parentDialog" frameStrata="DIALOG" movable="true" enableMouse="true"> - <Size> - <AbsDimension x="330" y="350"/> - </Size> - <Anchors> - <Anchor point="CENTER"/> - </Anchors> - <TitleRegion> - <Size> - <AbsDimension x="350" y="30"/> - </Size> - <Anchors> - <Anchor point="TOP"> - <Offset> - <AbsDimension x="0" y="-10"/> - </Offset> - </Anchor> - </Anchors> - </TitleRegion> - <Backdrop edgeFile="Interface\Tooltips\UI-Tooltip-Border" tile="true"> - <EdgeSize> - <AbsValue val="16"/> - </EdgeSize> - <TileSize> - <AbsValue val="16"/> - </TileSize> - <BackgroundInsets> - <AbsInset left="4" right="4" top="4" bottom="4"/> - </BackgroundInsets> - </Backdrop> - <Layers> - <Layer level="BACKGROUND"> - <Texture> - <Color r="0" g="0" b="0" a="0.7"/> - </Texture> - </Layer> - <Layer level="ARTWORK"> - <FontString inherits="GameFontNormalLarge" text="Key Binding Setup" justifyH="CENTER"> - <Size> - <AbsDimension x="200" y="30"/> - </Size> - <Anchors> - <Anchor point="TOP"> - <Offset> - <AbsDimension x="0" y="-10"/> - </Offset> - </Anchor> - </Anchors> - </FontString> - <FontString inherits="GameFontNormal" text="Press a key to ready it for assignment, then click a button to assign the key.|nRight-click a button to clear its binding." justifyH="CENTER"> - <Size> - <AbsDimension x="240" y="70"/> - </Size> - <Anchors> - <Anchor point="TOP"> - <Offset> - <AbsDimension x="0" y="-55"/> - </Offset> - </Anchor> - </Anchors> - <Color r="1.0" g="1.0" b="1.0"/> - </FontString> - <FontString inherits="GameFontNormal" text="Selected Key:" justifyH="RIGHT"> - <Size> - <AbsDimension x="175" y="25"/> - </Size> - <Anchors> - <Anchor point="RIGHT" relativePoint="TOP"> - <Offset> - <AbsDimension x="-25" y="-160"/> - </Offset> - </Anchor> - </Anchors> - </FontString> - <FontString inherits="GameFontNormal" text="Current Binding:" justifyH="RIGHT"> - <Size> - <AbsDimension x="175" y="25"/> - </Size> - <Anchors> - <Anchor point="RIGHT" relativePoint="TOP"> - <Offset> - <AbsDimension x="-25" y="-205"/> - </Offset> - </Anchor> - </Anchors> - </FontString> - <FontString name="$parentCurrentActionText" inherits="GameFontNormal" text="(none)" justifyH="CENTER"> - <Size> - <AbsDimension x="140" y="50"/> - </Size> - <Anchors> - <Anchor point="CENTER" relativePoint="TOP"> - <Offset> - <AbsDimension x="75" y="-205"/> - </Offset> - </Anchor> - </Anchors> - <Color r="0" g="1" b="0" a="1"/> - </FontString> - <FontString name="$parentStatusMsg" inherits="GameFontNormal" text="" justifyH="CENTER"> - <Size> - <AbsDimension x="200" y="50"/> - </Size> - <Anchors> - <Anchor point="TOP"> - <Offset> - <AbsDimension x="0" y="-230"/> - </Offset> - </Anchor> - </Anchors> - <Color r="0.1" g="1.0" b="0.1"/> - </FontString> - </Layer> - </Layers> - <Frames> - <Button name="$parentSelectedKey" inherits="UIPanelButtonTemplate2" text="(none)"> - <Size> - <AbsDimension x="140" y="28"/> - </Size> - <Anchors> - <Anchor point="CENTER" relativePoint="TOP"> - <Offset> - <AbsDimension x="75" y="-160"/> - </Offset> - </Anchor> - </Anchors> - </Button> - <Button inherits="GameMenuButtonTemplate" text="Done"> - <Size> - <AbsDimension x="112" y="28"/> - </Size> - <Anchors> - <Anchor point="BOTTOM"> - <Offset> - <AbsDimension x="0" y="10"/> - </Offset> - </Anchor> - </Anchors> - <Scripts> - <OnClick> - this:GetParent():GetParent():Hide() - </OnClick> - </Scripts> - </Button> - </Frames> - <Scripts> - <!-- the dialog frame needs to handle clicks (close button, drag title) so we have to - re-implement the behavior of capturing alternate mouse buttons --> - <OnLoad> - this.selectedKey = getglobal(this:GetName().."SelectedKeyText") - this.currentAction = getglobal(this:GetName().."CurrentActionText") - this:RegisterForClicks("MiddleButtonUp","Button4Up","Button5Up") - </OnLoad> - <OnClick> - local k, a = ReBound:HandleKeyPressed(arg1) - if k then - this.selectedKey:SetText(k) - this.currentAction:SetText(a or "(none)") - end - </OnClick> - </Scripts> - </Button> - </Frames> - <Scripts> - <OnLoad> - this.selectedKey = getglobal(this:GetName().."DialogSelectedKeyText") - this.currentAction = getglobal(this:GetName().."DialogCurrentActionText") - this.statusMsg = getglobal(this:GetName().."DialogStatusMsg") - tinsert(UISpecialFrames,this:GetName()) - this:RegisterForClicks("MiddleButtonUp","Button4Up","Button5Up") - this:RegisterEvent("PLAYER_REGEN_DISABLED") - </OnLoad> - <OnShow> - this.selectedKey:SetText("(none)") - this.currentAction:SetText("(none)") - this.statusMsg:SetText("") - ReBound:ShowClickBindingButtons() - </OnShow> - <OnHide> - ReBound:HideClickBindingButtons() - ReBound:ClearSelectedKey() - </OnHide> - <OnKeyDown> - local k, a = ReBound:HandleKeyPressed(arg1) - if k then - this.selectedKey:SetText(k) - this.currentAction:SetText(a or "(none)") - end - </OnKeyDown> - <OnClick> - local k, a = ReBound:HandleKeyPressed(arg1) - if k then - this.selectedKey:SetText(k) - this.currentAction:SetText(a or "(none)") - end - </OnClick> - <OnEvent> - this:Hide() -- only event is enter-combat - </OnEvent> - </Scripts> - </Button> - -</Ui>