GUI:SetRelativeMode(true)
InputEditText = GUI:AddEditText(0, 0.1, ScreenSizeX, 0.1, "")
InputEditText:SetEnabled(false)
InputEditText:SetNumericOnly(true)
Digits = {}
Digit = {}
rr = 0 bb = 255
for i = 1,ScreenSizeY do
rr = rr + (255/ScreenSizeY)
bb = bb - (255/ScreenSizeY)
Screen:DrawRect(0,i,ScreenSizeY,1,Color:rgb(rr,250,bb))
end
Digits[0] = GUI:AddButton(0, 0.2, 0.25, 0.20, "0")
Digits[1] = GUI:AddButton(0, 0.4, 0.25, 0.20, "1")
Digits[2] = GUI:AddButton(0.25, 0.4, 0.25, 0.20, "2")
Digits[3] = GUI:AddButton(0.50, 0.4, 0.25, 0.20, "3")
Digits[4] = GUI:AddButton(0, 0.6, 0.25, 0.20, "4")
Digits[5] = GUI:AddButton(0.25, 0.6, 0.25, 0.20, "5")
Digits[6] = GUI:AddButton(0.50, 0.6, 0.25, 0.20, "6")
Digits[7] = GUI:AddButton(0, 0.8, 0.25, 0.20, "7")
Digits[8] = GUI:AddButton(0.25, 0.8, 0.25, 0.20, "8")
Digits[9] = GUI:AddButton(0.50, 0.8, 0.25, 0.20, "9")
ClearButton = GUI:AddButton(0.25, 0.2, 0.25, 0.20, "CE")
EqualButton = GUI:AddButton(0.50, 0.2, 0.25, 0.20, "=")
CountButton = GUI:AddButton(0.9,0,0.1,0.07,"")
SumButton = GUI:AddButton(0.75, 0.2, 0.25, 0.20, "+")
SubButton = GUI:AddButton(0.75, 0.4, 0.25, 0.20, "-")
MulButton = GUI:AddButton(0.75, 0.6, 0.25, 0.20, "*")
DivButton = GUI:AddButton(0.75, 0.8, 0.25, 0.20, "/")
TempValue = "0"
NewValue = "0"
FinalValue = "0"
Mode = ""
function ClearAllDigits()
InputEditText:SetText("")
CountButton:SetText("")
TempValue = "0"
NewValue = "0"
FinalValue = "0"
Mode = ""
end
function CountFunc(v)
if InputEditText:GetText():len() > 0 then
if Mode:len() == 0 then
Mode = ""..v..""
CountButton:SetText(""..v.."")
TempValue = InputEditText:GetText()
InputEditText:SetText("")
NewValue = "0"
else
Equal()
end
end
end
function SumFunc()
CountFunc("+")
end
function SubFunc()
CountFunc("-")
end
function MulFunc()
CountFunc("*")
end
function DivFunc()
CountFunc("/")
end
function Equal()
if Mode:len() ~= 0 then
if Mode == "+" then
NewValue = tonumber(InputEditText:GetText())
FinalValue = tonumber(TempValue) + tonumber(NewValue)
InputEditText:SetText(""..FinalValue.."")
TempValue = "0"
NewValue = "0"
FinalValue = "0"
Mode = ""
elseif Mode == "-" then
NewValue = tonumber(InputEditText:GetText())
FinalValue = tonumber(TempValue) - tonumber(NewValue)
InputEditText:SetText(""..FinalValue.."")
TempValue = "0"
NewValue = "0"
FinalValue = "0"
Mode = ""
elseif Mode == "*" then
NewValue = tonumber(InputEditText:GetText())
FinalValue = tonumber(TempValue) * tonumber(NewValue)
InputEditText:SetText(""..FinalValue.."")
TempValue = "0"
NewValue = "0"
FinalValue = "0"
Mode = ""
elseif Mode == "/" then
NewValue = tonumber(InputEditText:GetText())
FinalValue = tonumber(TempValue) / tonumber(NewValue)
InputEditText:SetText(""..FinalValue.."")
TempValue = "0"
NewValue = "0"
FinalValue = "0"
Mode = ""
end
else
Mode = ""
CountButton:SetText("")
end
end
function AddDigit(v)
lastvalue = ""..tostring(InputEditText:GetText())..""
InputEditText:SetText(lastvalue..""..v)
end
for i = 0, 9 do
Digit[i] = function()
AddDigit(i)
end
end
for i = 0, 9 do
Digits[i]:AddEventHandler("OnTouchDown", Digit[i])
end
EqualButton:AddEventHandler("OnTouchDown", Equal)
SumButton:AddEventHandler("OnTouchDown", SumFunc)
SubButton:AddEventHandler("OnTouchDown", SubFunc)
MulButton:AddEventHandler("OnTouchDown", MulFunc)
DivButton:AddEventHandler("OnTouchDown", DivFunc)
ClearButton:AddEventHandler("OnTouchDown", ClearAllDigits)
CountButton:SetEnabled(false)