/tags
--[[ |
This file contains all the GUI instructions. |
I decided on creating the entire gui via lua instead of xml for several reasons. |
There is a "LOT" of optimization still to be done in this file I am more interested |
in generating a base form and set of files to update from. |
]] |
function xcalc_windowframe() |
--Main Window Frame (container) and title bar |
local frame = CreateFrame("Frame","xcalc_window",UIParent) |
frame:SetFrameStrata("HIGH") |
frame:EnableMouse(true) |
frame:EnableKeyboard(true) |
frame:SetMovable(true) |
frame:SetHeight(307) |
frame:SetWidth(240) |
frame:SetScript("OnMouseDown", function() frame:StartMoving() end) |
frame:SetScript("OnMouseUp", function() frame:StopMovingOrSizing() end) |
frame:SetScript("OnShow", function() xcalc_rebind() end) |
frame:SetScript("OnHide", function() xcalc_unbind() end) |
frame:SetBackdrop({bgFile = "Interface/DialogFrame/UI-DialogBox-Background", |
edgeFile = "Interface/DialogFrame/UI-DialogBox-Border", |
tile = true, tileSize = 32, edgeSize = 32, |
insets = { left = 11, right = 12, top = 12, bottom = 11 }}) |
frame:SetPoint("CENTER",0,0) |
local titletexture = frame:CreateTexture("xcalc_window_titletexture") |
titletexture:SetHeight(32) |
titletexture:SetWidth(160) |
titletexture:SetTexture("Interface/DialogFrame/UI-DialogBox-Header") |
titletexture:SetTexCoord(0.2, 0.8, 0, 0.6) |
titletexture:SetPoint("TOP",0,5) |
local titlefont = frame:CreateFontString("xcalc_windowtest_titlefont") |
titlefont:SetHeight(0) |
titlefont:SetWidth(140) |
titlefont:SetFont("Fonts/FRIZQT__.TTF",12) |
titlefont:SetPoint("TOP",0,-4) |
titlefont:SetTextColor(1,0.8196079,0) |
titlefont:SetText("xcalc v" .. XCALC_VERSION) |
--Number Display box |
local numberdisplaybackground = frame:CreateTexture("xcalc_numberdisplaybackground") |
numberdisplaybackground:SetHeight(34) |
numberdisplaybackground:SetWidth(215) |
numberdisplaybackground:SetTexture("interface/chatframe/ui-chatinputborder") |
numberdisplaybackground:SetPoint("TOPLEFT",10,-33) |
local numberdisplay = frame:CreateFontString("xcalc_numberdisplay","GameFontWhite") |
numberdisplay:SetHeight(34) |
numberdisplay:SetWidth(205) |
numberdisplay:SetFont("Fonts/FRIZQT__.TTF",12) |
numberdisplay:SetJustifyH("RIGHT") |
numberdisplay:SetPoint("TOPLEFT",10,-33) |
numberdisplay:SetText(XCALC_NUMBERDISPLAY) |
--Memory Display |
local memorydisplay = frame:CreateFontString("xcalc_memorydisplay","GameFontNormal") |
memorydisplay:SetWidth(29) |
memorydisplay:SetHeight(29) |
memorydisplay:SetFont("Fonts/FRIZQT__.TTF",12) |
memorydisplay:SetPoint("TOPLEFT",15,-73) |
--memorydisplay:SetText("M") |
--ExitButton |
local exitbutton = CreateFrame("Button", "xcalc_exitbutton",frame,"UIPanelCloseButton") |
exitbutton:SetPoint("TOPRIGHT",-4,-4) |
exitbutton:SetScript("OnClick", function() xcalc_windowdisplay() end) |
--Backspace Button |
local backspacebutton = CreateFrame("Button", "backspacebutton",frame,"UIPanelButtonTemplate") |
backspacebutton:SetWidth(75) |
backspacebutton:SetHeight(29) |
backspacebutton:SetPoint("TOPLEFT",50,-73) |
backspacebutton:SetText("Backspace") |
backspacebutton:SetScript("OnClick", function() xcalc_backspace() end) |
--CE button |
local cebutton = CreateFrame("Button", "cebutton",frame,"UIPanelButtonTemplate") |
cebutton:SetWidth(41) |
cebutton:SetHeight(29) |
cebutton:SetPoint("TOPLEFT",131,-73) |
cebutton:SetText("CE") |
cebutton:SetScript("OnClick", function() xcalc_ce() end) |
--Clear Button |
local cbutton = CreateFrame("Button", "cbutton",frame,"UIPanelButtonTemplate") |
cbutton:SetWidth(41) |
cbutton:SetHeight(29) |
cbutton:SetPoint("TOPLEFT",178,-73) |
cbutton:SetText("C") |
cbutton:SetScript("OnClick", function() xcalc_clear() end) |
--Equals Button |
local equalbutton = CreateFrame("Button", "equalbutton",frame,"UIPanelButtonTemplate") |
equalbutton:SetWidth(29) |
equalbutton:SetHeight(70) |
equalbutton:SetPoint("TOPLEFT",190,-183) |
equalbutton:SetText("=") |
equalbutton:SetScript("OnClick", function() xcalc_funckey("=") end) |
--Exp Button |
local expbutton = CreateFrame("Button", "expbutton",frame,"UIPanelButtonTemplate") |
expbutton:SetWidth(29) |
expbutton:SetHeight(32) |
expbutton:SetPoint("TOPLEFT",190,-146) |
expbutton:SetText("^") |
expbutton:SetScript("OnClick", function() xcalc_funckey("^") end) |
--Plus Minus Button |
local pmbutton = CreateFrame("Button", "pmbutton",frame,"UIPanelButtonTemplate") |
pmbutton:SetWidth(29) |
pmbutton:SetHeight(32) |
pmbutton:SetPoint("TOPLEFT",190,-108) |
pmbutton:SetText("+/-") |
pmbutton:SetScript("OnClick", function() xcalc_plusminus() end) |
--Plus Button |
local plusbutton = CreateFrame("Button", "plusbutton",frame,"UIPanelButtonTemplate") |
plusbutton:SetWidth(29) |
plusbutton:SetHeight(32) |
plusbutton:SetPoint("TOPLEFT",155,-221) |
plusbutton:SetText("+") |
plusbutton:SetScript("OnClick", function() xcalc_funckey("+") end) |
--Minus Button |
local minuxbutton = CreateFrame("Button", "minusbutton",frame,"UIPanelButtonTemplate") |
minusbutton:SetWidth(29) |
minusbutton:SetHeight(32) |
minusbutton:SetPoint("TOPLEFT",155,-183) |
minusbutton:SetText("-") |
minusbutton:SetScript("OnClick", function() xcalc_funckey("-") end) |
--Multiply Button |
local multiplybutton = CreateFrame("Button", "multiplybutton",frame,"UIPanelButtonTemplate") |
multiplybutton:SetWidth(29) |
multiplybutton:SetHeight(32) |
multiplybutton:SetPoint("TOPLEFT",155,-146) |
multiplybutton:SetText("*") |
multiplybutton:SetScript("OnClick", function() xcalc_funckey("*") end) |
--Divide Button |
local dividebutton = CreateFrame("Button", "dividebutton",frame,"UIPanelButtonTemplate") |
dividebutton:SetWidth(29) |
dividebutton:SetHeight(32) |
dividebutton:SetPoint("TOPLEFT",155,-108) |
dividebutton:SetText("/") |
dividebutton:SetScript("OnClick", function() xcalc_funckey("/") end) |
--Copper Button |
local copperbutton = CreateFrame("Button", "copperbutton",frame,"UIPanelButtonTemplate") |
copperbutton:SetWidth(29) |
copperbutton:SetHeight(32) |
copperbutton:SetPoint("TOPLEFT",120,-259) |
copperbutton:SetText("c") |
copperbutton:SetScript("OnClick", function() xcalc_statecopper() end) |
--Silver Button |
local silverbutton = CreateFrame("Button", "silverbutton",frame,"UIPanelButtonTemplate") |
silverbutton:SetWidth(29) |
silverbutton:SetHeight(32) |
silverbutton:SetPoint("TOPLEFT",85,-259) |
silverbutton:SetText("s") |
silverbutton:SetScript("OnClick", function() xcalc_statesilver() end) |
--Gold Button |
local goldbutton = CreateFrame("Button", "goldbutton",frame,"UIPanelButtonTemplate") |
goldbutton:SetWidth(29) |
goldbutton:SetHeight(32) |
goldbutton:SetPoint("TOPLEFT",50,-259) |
goldbutton:SetText("g") |
goldbutton:SetScript("OnClick", function() xcalc_stategold() end) |
--Decimal Button |
local decimalbutton = CreateFrame("Button", "decimalbutton",frame,"UIPanelButtonTemplate") |
decimalbutton:SetWidth(29) |
decimalbutton:SetHeight(32) |
decimalbutton:SetPoint("TOPLEFT",120,-221) |
decimalbutton:SetText(".") |
decimalbutton:SetScript("OnClick", function() xcalc_numkey(".") end) |
--0 button |
local zerobutton = CreateFrame("Button", "zerobutton",frame,"UIPanelButtonTemplate") |
zerobutton:SetWidth(64) |
zerobutton:SetHeight(32) |
zerobutton:SetPoint("TOPLEFT",50,-222) |
zerobutton:SetText("0") |
zerobutton:SetScript("OnClick", function() xcalc_numkey("0") end) |
--3 button |
local threebutton = CreateFrame("Button", "threebutton",frame,"UIPanelButtonTemplate") |
threebutton:SetWidth(29) |
threebutton:SetHeight(32) |
threebutton:SetPoint("TOPLEFT",120,-183) |
threebutton:SetText("3") |
threebutton:SetScript("OnClick", function() xcalc_numkey("3") end) |
--2 Button |
local twobutton = CreateFrame("Button", "twobutton",frame,"UIPanelButtonTemplate") |
twobutton:SetWidth(29) |
twobutton:SetHeight(32) |
twobutton:SetPoint("TOPLEFT",85,-183) |
twobutton:SetText("2") |
twobutton:SetScript("OnClick", function() xcalc_numkey("2") end) |
--1 Button |
local onebutton = CreateFrame("Button", "onebutton",frame,"UIPanelButtonTemplate") |
onebutton:SetWidth(29) |
onebutton:SetHeight(32) |
onebutton:SetPoint("TOPLEFT",50,-184) |
onebutton:SetText("1") |
onebutton:SetScript("OnClick", function() xcalc_numkey("1") end) |
--6 Button |
local sixbutton = CreateFrame("Button", "sixbutton",frame,"UIPanelButtonTemplate") |
sixbutton:SetWidth(29) |
sixbutton:SetHeight(32) |
sixbutton:SetPoint("TOPLEFT",120,-146) |
sixbutton:SetText("6") |
sixbutton:SetScript("OnClick", function() xcalc_numkey("6") end) |
--5 Button |
local fivebutton = CreateFrame("Button", "fivebutton",frame,"UIPanelButtonTemplate") |
fivebutton:SetWidth(29) |
fivebutton:SetHeight(32) |
fivebutton:SetPoint("TOPLEFT",85,-146) |
fivebutton:SetText("5") |
fivebutton:SetScript("OnClick", function() xcalc_numkey("5") end) |
--4 Button |
local fourbutton = CreateFrame("Button", "fourbutton",frame,"UIPanelButtonTemplate") |
fourbutton:SetWidth(29) |
fourbutton:SetHeight(32) |
fourbutton:SetPoint("TOPLEFT",50,-146) |
fourbutton:SetText("4") |
fourbutton:SetScript("OnClick", function() xcalc_numkey("4") end) |
--9 Button |
local ninebutton = CreateFrame("Button", "ninebutton",frame,"UIPanelButtonTemplate") |
ninebutton:SetWidth(29) |
ninebutton:SetHeight(32) |
ninebutton:SetPoint("TOPLEFT",120,-108) |
ninebutton:SetText("9") |
ninebutton:SetScript("OnClick", function() xcalc_numkey("9") end) |
--8 Button |
local eightbutton = CreateFrame("Button", "eightbutton",frame,"UIPanelButtonTemplate") |
eightbutton:SetWidth(29) |
eightbutton:SetHeight(32) |
eightbutton:SetPoint("TOPLEFT",85,-108) |
eightbutton:SetText("8") |
eightbutton:SetScript("OnClick", function() xcalc_numkey("8") end) |
--7 Button |
local sevenbutton = CreateFrame("Button", "sevenbutton",frame,"UIPanelButtonTemplate") |
sevenbutton:SetWidth(29) |
sevenbutton:SetHeight(32) |
sevenbutton:SetPoint("TOPLEFT",50,-108) |
sevenbutton:SetText("7") |
sevenbutton:SetScript("OnClick", function() xcalc_numkey("7") end) |
--Memory Add Button |
local mabutton = CreateFrame("Button", "mabutton",frame,"UIPanelButtonTemplate") |
mabutton:SetWidth(29) |
mabutton:SetHeight(32) |
mabutton:SetPoint("TOPLEFT",15,-221) |
mabutton:SetText("MA") |
mabutton:SetScript("OnClick", function() xcalc_ma() end) |
--Memory Store Button |
local msbutton = CreateFrame("Button", "msbutton",frame,"UIPanelButtonTemplate") |
msbutton:SetWidth(29) |
msbutton:SetHeight(32) |
msbutton:SetPoint("TOPLEFT",15,-183) |
msbutton:SetText("MS") |
msbutton:SetScript("OnClick", function() xcalc_ms() end) |
--Memory Recall Button |
local mrbutton = CreateFrame("Button", "mrbutton",frame,"UIPanelButtonTemplate") |
mrbutton:SetWidth(29) |
mrbutton:SetHeight(32) |
mrbutton:SetPoint("TOPLEFT",15,-146) |
mrbutton:SetText("MR") |
mrbutton:SetScript("OnClick", function() xcalc_mr() end) |
--Memory Clear Button |
local mcbutton = CreateFrame("Button", "mcbutton",frame,"UIPanelButtonTemplate") |
mcbutton:SetWidth(29) |
mcbutton:SetHeight(32) |
mcbutton:SetPoint("TOPLEFT",15,-108) |
mcbutton:SetText("MC") |
mcbutton:SetScript("OnClick", function() xcalc_mc() end) |
--Option show button |
local optionbutton = CreateFrame("Button", "xcalc_optionwindow_button",frame,"UIPanelButtonTemplate") |
optionbutton:SetWidth(70) |
optionbutton:SetHeight(25) |
optionbutton:SetPoint("BOTTOMRIGHT",-15,15) |
optionbutton:SetText("Options") |
optionbutton:SetScript("OnClick", function() xcalc_optiondisplay() end) |
xcalc_rebind() |
frame:Show() |
tinsert(UISpecialFrames,"xcalc_window") |
end |
function xcalc_optionframe() |
--Options window Frame |
local frame = CreateFrame("Frame","xcalc_optionwindow",xcalc_window) |
frame:SetFrameStrata("HIGH") |
frame:EnableMouse(true) |
frame:SetWidth(220) |
frame:SetHeight(200) |
frame:SetBackdrop({bgFile = "Interface/DialogFrame/UI-DialogBox-Background", |
edgeFile = "Interface/DialogFrame/UI-DialogBox-Border", |
tile = true, tileSize = 32, edgeSize = 32, |
insets = { left = 11, right = 12, top = 12, bottom = 11 }}) |
frame:SetPoint("CENTER",230,0) |
local titletexture = frame:CreateTexture("xcalc_optionwindow_titletexture") |
titletexture:SetHeight(32) |
titletexture:SetWidth(160) |
titletexture:SetTexture("Interface/DialogFrame/UI-DialogBox-Header") |
titletexture:SetTexCoord(0.2, 0.8, 0, 0.6) |
titletexture:SetPoint("TOP",0,5) |
local titlefont = frame:CreateFontString("xcalc_optionwindow_titlefont") |
titlefont:SetHeight(0) |
titlefont:SetWidth(140) |
titlefont:SetFont("Fonts/FRIZQT__.TTF",12) |
titlefont:SetPoint("TOP",0,-4) |
titlefont:SetTextColor(1,0.8196079,0) |
titlefont:SetText("Xcalc Options") |
--Options Okay Button |
local okaybutton = CreateFrame("Button", "xcalc_optionokaybutton",frame,"UIPanelButtonTemplate") |
okaybutton:SetWidth(70) |
okaybutton:SetHeight(29) |
okaybutton:SetPoint("BOTTOM",0,20) |
okaybutton:SetText("Okay") |
okaybutton:SetScript("OnClick", function() xcalc_optiondisplay() end) |
--Binding Check box |
local bindingcheckbox = CreateFrame("CheckButton","xcalc_options_bindcheckbox",frame,"OptionsCheckButtonTemplate") |
bindingcheckbox:SetPoint("TOPLEFT",15,-40) |
bindingcheckbox:SetChecked(Xcalc_Settings.Binding) |
bindingcheckbox:SetScript("OnClick", function() xcalc_options_binding() end) |
local bindingcheckboxtext = frame:CreateFontString("xcalc_options_bindcheckboxtext") |
bindingcheckboxtext:SetWidth(200) |
bindingcheckboxtext:SetHeight(0) |
bindingcheckboxtext:SetFont("Fonts/FRIZQT__.TTF",10) |
bindingcheckboxtext:SetTextColor(1,0.8196079,0) |
bindingcheckboxtext:SetJustifyH("LEFT") |
bindingcheckboxtext:SetText("Use Automatic Key Bindings") |
bindingcheckboxtext:SetPoint("LEFT","xcalc_options_bindcheckbox",30,0) |
--Display Minimap Check Box |
local minimapcheckbox = CreateFrame("CheckButton","xcalc_options_minimapcheckbox",frame,"OptionsCheckButtonTemplate") |
minimapcheckbox:SetPoint("TOPLEFT",15,-70) |
minimapcheckbox:SetChecked(Xcalc_Settings.Minimapdisplay) |
minimapcheckbox:SetScript("OnClick", function() xcalc_options_minimapdisplay() end) |
local minimapcheckboxtext = minimapcheckbox:CreateFontString("xcalc_options_minimapcheckboxtext") |
minimapcheckboxtext:SetWidth(200) |
minimapcheckboxtext:SetHeight(0) |
minimapcheckboxtext:SetFont("Fonts/FRIZQT__.TTF",10) |
minimapcheckboxtext:SetTextColor(1,0.8196079,0) |
minimapcheckboxtext:SetJustifyH("LEFT") |
minimapcheckboxtext:SetText("Display Minimap Icon") |
minimapcheckboxtext:SetPoint("LEFT","xcalc_options_minimapcheckbox",30,0) |
--Minimap Position Slider |
local minimapslider = CreateFrame("Slider","xcalc_options_minimapslider",frame,"OptionsSliderTemplate") |
minimapslider:SetWidth(180) |
minimapslider:SetHeight(16) |
minimapslider:SetMinMaxValues(0, 360) |
minimapslider:SetValueStep(1) |
minimapslider:SetScript("OnValueChanged", function() xcalc_options_minimapslidercontrol() end) |
xcalc_options_minimapsliderHigh:SetText() |
xcalc_options_minimapsliderLow:SetText() |
xcalc_options_minimapsliderText:SetText("Minimap Button Position") |
minimapslider:SetPoint("TOPLEFT",15,-120) |
minimapslider:SetValue(Xcalc_Settings.Minimappos) |
frame:Show() |
end |
function xcalc_minimap_init() |
if (Xcalc_Settings.Minimapdisplay == 1) then |
local frame = CreateFrame("Button","xcalc_minimap_button",Minimap) |
frame:SetWidth(34) |
frame:SetHeight(34) |
frame:SetFrameStrata("LOW") |
frame:SetToplevel(1) |
frame:SetNormalTexture("Interface\\AddOns\\xcalc\\xcalc_ButtonRoundNormal.tga") |
frame:SetPushedTexture("Interface\\AddOns\\xcalc\\xcalc_ButtonRoundPushed.tga") |
frame:SetHighlightTexture("Interface/Minimap/UI-Minimap-ZoomButton-Highlight") |
frame:SetScript("OnClick", function() xcalc_windowdisplay() end) |
frame:SetScript("OnEnter", function() xcalc_tooltip("minimap") end) |
frame:SetScript("OnLeave", function() xcalc_tooltip("hide") end) |
xcalc_minimapbutton_updateposition() |
frame:Show() |
end |
end |
function xcalc_minimapbutton_updateposition() |
xcalc_minimap_button:SetPoint("TOPLEFT", "Minimap", "TOPLEFT", |
54 - (78 * cos(Xcalc_Settings.Minimappos)), |
(78 * sin(Xcalc_Settings.Minimappos)) - 55) |
end |
BINDING_HEADER_XCALC = "xcalc" |
BINDING_NAME_XC_TOGGLEWINDOW = "Toggle xcalc" |
BINDING_HEADER_XCALC_AUTOMATIC = "xcalc (automatic)" |
BINDING_NAME_XC_NUMLOCK = "Numlock" |
BINDING_NAME_XC_CLEAR = "Clear" |
BINDING_NAME_XC_CLOSE = "Close" |
BINDING_NAME_XC_DIV = "Divide" |
BINDING_NAME_XC_MUL = "Multiply" |
BINDING_NAME_XC_SUB = "Subtract" |
BINDING_NAME_XC_ADD = "Add" |
BINDING_NAME_XC_EQ = "Equals" |
BINDING_NAME_XC_0 = "Digit 0" |
BINDING_NAME_XC_1 = "Digit 1" |
BINDING_NAME_XC_2 = "Digit 2" |
BINDING_NAME_XC_3 = "Digit 3" |
BINDING_NAME_XC_4 = "Digit 4" |
BINDING_NAME_XC_5 = "Digit 5" |
BINDING_NAME_XC_6 = "Digit 6" |
BINDING_NAME_XC_7 = "Digit 7" |
BINDING_NAME_XC_8 = "Digit 8" |
BINDING_NAME_XC_9 = "Digit 9" |
BINDING_NAME_XC_DEC = "Decimal" |
BINDING_NAME_XC_BACKSPACE = "Backspace" |
XCALC_NUMBERDISPLAY = "0" |
XCALC_RUNNINGTOTAL = "" |
XCALC_PREVIOUSKEYTYPE = "none" |
XCALC_PREVIOUSOP = "" |
XCALC_CONSOLE_LAST_ANS = "0" |
XCALC_MEMORYINDICATOR = "" |
XCALC_MEMORYINDICATORON = "M" |
XCALC_MEMORYNUMBER = "0" |
XCALC_MEMORYSET = "0" |
Xcalc_Settings = { } |
<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"> |
<Script file="Localization.lua"/> |
<Script file="xcalc.lua"/> |
<Script file="xcalcgui.lua"/> |
<Frame name="xcalc_core"> |
<Scripts> |
<OnLoad>this:RegisterEvent("VARIABLES_LOADED");</OnLoad> |
<OnEvent>if (event == "VARIABLES_LOADED") then xcalc_initialize(); end</OnEvent> |
</Scripts> |
</Frame> |
</Ui> |
--[[ |
Xcalc see version onload. |
author: moird |
email: peirthies@gmail.com |
Change ideas: |
-Rewrite of the parsing and togsc fromgsc functions |
-Possibly adding a scientific option set to enable the calculator |
window for more functions that can be achieved already through |
the chatline but would give the window a lot better functionality |
-Maybe having a history of the last couple of calculations |
]] |
--Initialization stuff |
function xcalc_initialize() |
-- add our very first chat command! |
SlashCmdList["XCALC"] = xcalc_command |
SLASH_XCALC1 = "/xcalc" |
SLASH_XCALC2 = "/calc" |
SLASH_XCALC3 = "/=" |
xcalc_optionvariables() |
xcalc_minimap_init() |
XCALC_VERSION = GetAddOnMetadata("xcalc", "Version") |
end |
--Fuction for setting up Saved Variables |
function xcalc_optionvariables() |
if (Xcalc_Settings.Binding == nil) then |
Xcalc_Settings.Binding = 1 |
end |
if (Xcalc_Settings.Minimapdisplay == nil) then |
Xcalc_Settings.Minimapdisplay = 1 |
end |
if (Xcalc_Settings.Minimappos == nil) then |
Xcalc_Settings.Minimappos = 295 |
end |
end |
--[[--------------------------------------------------------------------- |
Proccess for setting the display in the main xcalc calculator window |
streamlined the whole process doing it this way so that the function |
can be called instead of calling both the variable, setting the new |
variable then passing the settext string to change the display. |
this also handles the M for memory being displayed on the main window |
---------------------------------------------------------------------]] |
function xcalc_display(displaynumber, memoryset) |
if ( displaynumber == nil or displaynumber == "" ) then |
displaynumber = "0" |
elseif ( memoryset == "1" ) then |
xcalc_memorydisplay:SetText ( XCALC_MEMORYINDICATORON ) |
elseif ( memoryset == "0" ) then |
xcalc_memorydisplay:SetText( XCALC_MEMORYINDICATOR ) |
end |
XCALC_NUMBERDISPLAY = displaynumber |
xcalc_numberdisplay:SetText( displaynumber ) |
end |
--[[-------------------------------------------------------------------- |
Function for adding Debug messages via xcalc_debug("message") call |
Haven't decided on adding a variable to add lots of debugging messages |
if set, will look into that idea as the code evolves a bit. |
--------------------------------------------------------------------]] |
function xcalc_debug(debugmsg) |
ChatFrame1:AddMessage("xcalc_debug: " .. debugmsg) |
end |
--Function for handling the chat slash commands |
function xcalc_command(msg) |
-- this function handles our chat command |
if (msg == nil or msg == "") then |
xcalc_windowdisplay() |
return nil |
end |
local expression = msg |
newexpression = xcalc_parse(expression) |
local result = xcalc_xcalculate(newexpression) |
if ( result == nil ) then |
result = 'nil' |
end |
XCALC_CONSOLE_LAST_ANS = result |
--message(result) |
ChatFrame1:AddMessage("Xcalc Result: " .. expression .. " = " .. result, 1.0, 1.0, 0.5) |
end |
--Display Main calculator Window |
function xcalc_windowdisplay() |
if (xcalc_window == nil) then |
xcalc_windowframe() |
elseif (xcalc_window:IsVisible()) then |
xcalc_window:Hide() |
else |
xcalc_window:Show() |
xcalc_clear() |
end |
end |
--Display options window |
function xcalc_optiondisplay() |
if (xcalc_optionwindow == nil) then |
xcalc_optionframe() |
elseif (xcalc_optionwindow:IsVisible()) then |
xcalc_optionwindow:Hide() |
else |
xcalc_optionwindow:Show() |
end |
end |
--Function for handeling Binding checkbox |
function xcalc_options_binding() |
if (xcalc_options_bindcheckbox:GetChecked() == 1) then |
Xcalc_Settings.Binding = 1 |
else |
xcalc_unbind() |
Xcalc_Settings.Binding = 0 |
end |
end |
-- Function for Handeling Minimap Display checkbox |
function xcalc_options_minimapdisplay() |
if (xcalc_options_minimapcheckbox:GetChecked() == 1) then |
Xcalc_Settings.Minimapdisplay = 1 |
if (xcalc_minimap_button == nil) then |
xcalc_minimap_init() |
else |
xcalc_minimap_button:Show() |
end |
else |
Xcalc_Settings.Minimapdisplay = 0 |
xcalc_minimap_button:Hide() |
end |
end |
-- Function for managing options slider |
function xcalc_options_minimapslidercontrol() |
if (Xcalc_Settings.Minimapdisplay == 1) then |
Xcalc_Settings.Minimappos = xcalc_options_minimapslider:GetValue() |
xcalc_minimapbutton_updateposition() |
else |
xcalc_options_minimapslider:SetValue(Xcalc_Settings.Minimappos) |
return |
end |
end |
--Processes for binding and unbinding numberpad keys to Xcalc |
function xcalc_rebind() |
if (Xcalc_Settings.Binding == 1) then |
--steal numlock away from anything else |
SetBinding("NUMLOCK", "XC_NUMLOCK") |
SetBinding("HOME", "XC_CLEAR") |
SetBinding("END", "XC_CLOSE") |
SetBinding("BACKSPACE", "XC_BACKSPACE") |
--set numlock on keys |
SetBinding("NUMPADDIVIDE", "XC_DIV") |
SetBinding("NUMPADMULTIPLY", "XC_MUL") |
SetBinding("NUMPADMINUS", "XC_SUB") |
SetBinding("NUMPADPLUS", "XC_ADD") |
SetBinding("ENTER", "XC_EQ") |
SetBinding("NUMPAD0", "XC_0") |
SetBinding("NUMPAD1", "XC_1") |
SetBinding("NUMPAD2", "XC_2") |
SetBinding("NUMPAD3", "XC_3") |
SetBinding("NUMPAD4", "XC_4") |
SetBinding("NUMPAD5", "XC_5") |
SetBinding("NUMPAD6", "XC_6") |
SetBinding("NUMPAD7", "XC_7") |
SetBinding("NUMPAD8", "XC_8") |
SetBinding("NUMPAD9", "XC_9") |
SetBinding("NUMPADDECIMAL", "XC_DEC") |
end |
end |
function xcalc_unbind() |
if (Xcalc_Settings.Binding == 1) then |
LoadBindings(GetCurrentBindingSet()) |
end |
end |
--Bound Key management |
function xcalc_onkeydown() |
key = arg1 |
--message(key) |
if ( key == "END" ) then |
elseif ( key == "NUMPAD0" ) then |
xcalc_numkey("0") |
elseif ( key == "NUMPAD1" ) then |
xcalc_numkey("1") |
elseif ( key == "NUMPAD2" ) then |
xcalc_numkey("2") |
elseif ( key == "NUMPAD3" ) then |
xcalc_numkey("3") |
elseif ( key == "NUMPAD4" ) then |
xcalc_numkey("4") |
elseif ( key == "NUMPAD5" ) then |
xcalc_numkey("5") |
elseif ( key == "NUMPAD6" ) then |
xcalc_numkey("6") |
elseif ( key == "NUMPAD7" ) then |
xcalc_numkey("7") |
elseif ( key == "NUMPAD8" ) then |
xcalc_numkey("8") |
elseif ( key == "NUMPAD9" ) then |
xcalc_numkey("9") |
end |
end |
--Button Clear |
function xcalc_clear() |
XCALC_RUNNINGTOTAL = "" |
XCALC_PREVIOUSKEYTYPE = "none" |
XCALC_PREVIOUSOP = "" |
xcalc_display("0") |
end |
--Button CE |
function xcalc_ce() |
xcalc_display("0") |
end |
--Button Backspace |
function xcalc_backspace() |
local currText = XCALC_NUMBERDISPLAY |
if (currText == "0") then |
return |
else |
length = string.len(currText)-1 |
if (length < 0) then |
length = 0 |
end |
currText = string.sub(currText,0,length) |
if (string.len(currText) < 1) then |
xcalc_display("0") |
else |
xcalc_display(currText) |
end |
end |
end |
--Button Plus Minus Key |
function xcalc_plusminus() |
local currText = XCALC_NUMBERDISPLAY |
if (currText ~= "0") then |
if (string.find(currText, "-")) then |
currText = string.sub(currText, 2) |
else |
currText = "-" .. currText |
end |
end |
XCALC_PREVIOUSKEYTYPE = "state" |
xcalc_display(currText) |
end |
--Button Gold (state) |
function xcalc_stategold() |
local currText = XCALC_NUMBERDISPLAY |
if (string.find(currText, "c") == nil) then |
if (string.find(currText, "s") == nil) then |
if (string.find(currText, "g") == nil) then |
currText = currText .. "g" |
end |
end |
end |
XCALC_PREVIOUSKEYTYPE = "state" |
xcalc_display(currText) |
end |
--Button Silver (state) |
function xcalc_statesilver() |
local currText = XCALC_NUMBERDISPLAY |
if (string.find(currText, "c") == nil) then |
if (string.find(currText, "s") == nil) then |
currText = currText .. "s" |
end |
end |
XCALC_PREVIOUSKEYTYPE = "state" |
xcalc_display(currText) |
end |
--Button Copper (state) |
function xcalc_statecopper() |
local currText = XCALC_NUMBERDISPLAY |
if (string.find(currText, "c") == nil) then |
currText = currText .. "c" |
end |
XCALC_PREVIOUSKEYTYPE = "state" |
xcalc_display(currText) |
end |
--Button Memory Clear |
function xcalc_mc() |
XCALC_MEMORYNUMBER = "0" |
xcalc_display(XCALC_NUMBERDISPLAY, "0") |
end |
--Button Memory Add |
function xcalc_ma() |
temp = xcalc_parse(XCALC_MEMORYNUMBER .. "+" .. XCALC_NUMBERDISPLAY) |
XCALC_MEMORYNUMBER = xcalc_xcalculate(temp) |
xcalc_display("0","1") |
xcalc_clear() |
end |
--Button Memory Store |
function xcalc_ms() |
XCALC_MEMORYNUMBER = xcalc_parse(XCALC_NUMBERDISPLAY) |
xcalc_display("0","1") |
xcalc_clear() |
end |
--Button Memory Recall |
function xcalc_mr() |
xcalc_display(XCALC_MEMORYNUMBER) |
end |
--Sets up the function keys ie, + - * / = |
function xcalc_funckey(key) |
local currText = XCALC_NUMBERDISPLAY |
if ( IsShiftKeyDown() and key == "=" ) then |
ChatFrame_OpenChat("") |
return |
end |
if (XCALC_PREVIOUSKEYTYPE=="none" or XCALC_PREVIOUSKEYTYPE=="num" or XCALC_PREVIOUSKEYTYPE=="state") then |
if (key == "/" or key == "*" or key == "-" or key == "-" or key == "+" or key == "^") then |
if (XCALC_PREVIOUSOP~="" and XCALC_PREVIOUSOP ~= "=") then |
temp = xcalc_parse(XCALC_RUNNINGTOTAL .. XCALC_PREVIOUSOP .. currText) |
currText = xcalc_xcalculate(temp) |
end |
XCALC_RUNNINGTOTAL = currText |
XCALC_PREVIOUSOP = key |
elseif (key == "=") then |
if XCALC_PREVIOUSOP ~= "=" and XCALC_PREVIOUSOP ~= "" then |
temp = xcalc_parse(XCALC_RUNNINGTOTAL .. XCALC_PREVIOUSOP .. currText) |
currText = xcalc_xcalculate(temp) |
XCALC_RUNNINGTOTAL = currText |
XCALC_PREVIOUSOP="=" |
end |
end |
else --must be a func key, a second+ time |
if (key == "/" or key == "*" or key == "-" or key == "-" or key == "+" or key == "^") then |
XCALC_PREVIOUSOP=key |
else |
XCALC_PREVIOUSOP="" |
end |
end |
XCALC_PREVIOUSKEYTYPE = "func" |
xcalc_display(currText) |
end |
--Manage Number Inputs |
function xcalc_numkey(key) |
local currText = XCALC_NUMBERDISPLAY |
if (XCALC_PREVIOUSKEYTYPE=="none" or XCALC_PREVIOUSKEYTYPE=="num" or XCALC_PREVIOUSKEYTYPE=="state")then |
if (key == ".") then |
if (string.find(currText, "c") == nil) then |
if (string.find(currText, "s") == nil) then |
if (string.find(currText, "g") == nil) then |
if (string.find(currText, "%.") == nil) then |
currText = currText .. "." |
end |
end |
end |
end |
else |
if (currText == "0") then |
currText = "" |
end |
currText = currText .. key |
end |
else |
if (key == ".") then |
currText = "0." |
else |
currText = key |
end |
end |
XCALC_PREVIOUSKEYTYPE = "num" |
xcalc_display(currText) |
end |
--Send the number display to an open chatbox |
function xcalc_numberdisplay_click(button, ignoreShift) |
if ( button == "LeftButton" ) then |
if ( IsShiftKeyDown() and not ignoreShift ) then |
if ( ChatFrameEditBox:IsVisible() ) then |
ChatFrameEditBox:Insert(XCALC_NUMBERDISPLAY) |
end |
end |
end |
end |
--Tooltip display |
function xcalc_tooltip(mouseover) |
if ( mouseover == "minimap" ) then |
GameTooltip:SetOwner(xcalc_minimap_button , "ANCHOR_BOTTOMLEFT") |
GameTooltip:SetText("Show/Hide xcalc") |
else |
GameTooltip : Hide () |
end |
end |
--[[----------------------------------------------------------------------------------- |
Where the Calculations occur |
On a side note, Simple is easier, getting into complex if/then/elseif/else statements |
to perform math functions may introduce unexpected results... maybe. |
-----------------------------------------------------------------------------------]] |
function xcalc_xcalculate(expression) |
local tempvar = "QCExpVal" |
setglobal(tempvar, nil) |
RunScript(tempvar .. "=(" .. expression .. ")") |
local result = getglobal(tempvar) |
return result |
end |
--This function parses the input for the money functions |
function xcalc_parse(expression) |
local ismoney = false |
newexpression = expression |
local newexpression = string.gsub(newexpression, "ans", XCALC_CONSOLE_LAST_ANS) |
-- g s c |
local newexpression = string.gsub(newexpression, "%d+g%d+s%d+c", function (a) |
ismoney = true |
return FromGSC(a) |
end ) |
-- g s |
local newexpression = string.gsub(newexpression, "%d+g%d+s", function (a) |
ismoney = true |
return FromGSC(a) |
end ) |
-- g c |
local newexpression = string.gsub(newexpression, "%d+g%d+c", function (a) |
ismoney = true |
return FromGSC(a) |
end ) |
-- g allows #.# |
local newexpression = string.gsub(newexpression, "%d+%.?%d*g", function (a) |
ismoney = true |
return FromGSC(a) |
end ) |
-- s c |
local newexpression = string.gsub(newexpression, "%d+s%d+c", function (a) |
ismoney = true |
return FromGSC(a) |
end ) |
-- s allows #.# |
local newexpression = string.gsub(newexpression, "%d+%.?%d*s", function (a) |
ismoney = true |
return FromGSC(a) |
end ) |
-- c |
local newexpression = string.gsub(newexpression, "%d+c", function (a) |
ismoney = true |
return FromGSC(a) |
end ) |
if (ismoney) then |
newexpression = "ToGSC(" .. newexpression .. ")" |
end |
return newexpression |
end |
--The following two functions do the to and from gold calculations |
function ToGSC(decimal, std) |
local gold = 0 |
local silver = 0 |
local copper = 0 |
if (std == "gold") then |
copper = math.fmod(decimal, .01) |
decimal = decimal - copper |
copper = copper * 10000 |
silver = math.fmod(decimal, 1) |
decimal = decimal - silver |
silver = silver * 100 |
gold = decimal |
elseif (std == "silver") then |
copper = math.fmod(decimal, 1) |
decimal = decimal - copper |
copper = copper * 100 |
silver = math.fmod(decimal, 100) |
decimal = decimal - silver |
gold = decimal / 100 |
else |
copper = math.fmod(decimal, 100) |
decimal = decimal - copper |
silver = math.fmod(decimal, 10000) |
decimal = decimal - silver |
silver = silver / 100 |
gold = decimal / 10000 |
end |
local temp = "" |
if (gold > 0) then |
temp = temp .. gold .. "g" |
end |
if (silver > 0 or (gold > 0 and copper > 0)) then |
temp = temp .. silver .. "s" |
end |
if (copper > 0) then |
temp = temp .. copper .. "c" |
end |
return temp |
end |
function FromGSC(gold, silver, copper) |
if (gold == nil) then |
return "" |
end |
local total = 0 |
if (type(gold) == "string" and (not silver or type(silver) == "nil") and (not copper or type(copper) == "nil")) then |
local temp = gold |
golds,golde = string.find(temp, "%d*%.?%d*g") |
if (golds == nil) then |
gold = 0 |
else |
gold = string.sub(temp, golds, golde - 1) |
end |
silvers,silvere = string.find(temp, "%d*%.?%d*s") |
if (silvers == nil) then |
silver = 0 |
else |
silver = string.sub(temp, silvers, silvere - 1) |
end |
coppers,coppere = string.find(temp, "%d*c") |
if (coppers == nil) then |
copper = 0 |
else |
copper = string.sub(temp, coppers, coppere - 1) |
end |
end |
total = total + copper |
total = total + (silver * 100) |
total = total + (gold * 10000) |
return "" .. total |
end |
Xcalc v. 2.05 |
Author: Moird (peirthies@gmail.com) |
Xcalc is a fairly basic calculator that allows mathmatical equations to be entered via the console |
or by using the GUI calculator interface. |
Xcalc is based off of QuickCalc by Mark Ribau. A good portion of the code has been rewritten, and |
the GUI has been completely rewritten. |
Installation |
------------------ |
Extract the zip and put the xcalc folder into |
\World of Warcraft\Interface\AddOns |
**WARNING** |
xcalc 2.0 files have changed and any previous version needs to be deleted before. ie. dont copy |
this over 1.0 installation. |
Usage |
---------------- |
slash commands: |
/xcalc |
/calc |
/= |
there is a = minimap icon that will all open the GUI interface. |
also of importance xcalc will rebind your all your numberpad keys to the gui interface when the Gui |
is open so it is not necessary to bind those keys. the GUI will rebind the numberpad keys back to |
their original bindings when the window closes. With the GUI open use shift+enter to open the chat |
dialog, and you can shift+left click on the number window to output that to the chat dialog if it is |
open. |
Xcalc does support computing of expressions from the command line. This is accessed by using the |
slash commands with the expression after the slash command. |
Math operators: |
+ - * / ^ ( ) |
Special Keyword: |
ans -- Will return the last answer given from using the slash commands |
Math Functions: |
abs() acos() asin() atan() atan2(,) ceil() deg() floor() frexp() ldexp() exp() log() log10() min([,...]) |
max([,...]) mod(,) rad() random([[,] ]) randomseed() sqrt() cos() sin() tan() |
Please see http://www.wowwiki.com/World_of_Warcraft_API#Math_Functions for more information on the math functions. |
Money strings: |
#.#g |
#.#s |
#c |
#g#s#c |
#g#s |
#g#c |
#s#c |
example: |
/calc 2 + 2 |
xcalc Result: 2 + 2 = 4 |
/calc 3.5g |
xcalc Result: 3.5g = 3g50s |
/calc (3.5g + 50s) * 2 |
xcalc Result: (3.5g + 50s) * 2 = 8g |
/calc 4g / 5 |
xcalc Result: 4g / 5 = 80s |
<Bindings> |
<Binding name="XC_TOGGLEWINDOW" description="Toggle Xcalc" header="XCALC"> |
xcalc_windowdisplay(); |
</Binding> |
<Binding name="XC_NUMLOCK" description="Numlock" header="XCALC_AUTOMATIC"> |
</Binding> |
<Binding name="XC_CLEAR" description="Clear"> |
xcalc_statekey("C"); |
</Binding> |
<Binding name="XC_CLOSE" description="Close"> |
xcalc_display(); |
</Binding> |
<Binding name="XC_BACKSPACE" description="Backspace"> |
xcalc_backspace() |
</Binding> |
<Binding name="XC_DIV" description="Divide"> |
xcalc_funckey("/"); |
</Binding> |
<Binding name="XC_MUL" description="Multiply"> |
xcalc_funckey("*"); |
</Binding> |
<Binding name="XC_SUB" description="Subtract"> |
xcalc_funckey("-"); |
</Binding> |
<Binding name="XC_ADD" description="Add"> |
xcalc_funckey("+"); |
</Binding> |
<Binding name="XC_EQ" description="Equals"> |
xcalc_funckey("="); |
</Binding> |
<Binding name="XC_0" description="Digit 0"> |
xcalc_numkey("0"); |
</Binding> |
<Binding name="XC_1" description="Digit 1"> |
xcalc_numkey("1"); |
</Binding> |
<Binding name="XC_2" description="Digit 2"> |
xcalc_numkey("2"); |
</Binding> |
<Binding name="XC_3" description="Digit 3"> |
xcalc_numkey("3"); |
</Binding> |
<Binding name="XC_4" description="Digit 4"> |
xcalc_numkey("4"); |
</Binding> |
<Binding name="XC_5" description="Digit 5"> |
xcalc_numkey("5"); |
</Binding> |
<Binding name="XC_6" description="Digit 6"> |
xcalc_numkey("6"); |
</Binding> |
<Binding name="XC_7" description="Digit 7"> |
xcalc_numkey("7"); |
</Binding> |
<Binding name="XC_8" description="Digit 8"> |
xcalc_numkey("8"); |
</Binding> |
<Binding name="XC_9" description="Digit 9"> |
xcalc_numkey("9"); |
</Binding> |
<Binding name="XC_DEC" description="Decimal"> |
xcalc_numkey("."); |
</Binding> |
</Bindings> |
## Interface: 30000 |
## Title: xcalc |
## Author: Moird |
## Version: 2.1.wowi:revision |
## Notes: Basic Calculator |
## eMail: peirthies@gmail.com |
## DefaultState: Enabled |
## LoadOnDemand: 0 |
## SavedVariablesPerCharacter: Xcalc_Settings |
xcalc.xml |
Bindings.xml |