urgh...
Ok if i have more then one input box, only the first works...
dofile("Buttons.lua")
IInputs = { }
InputID = 0
KeyDown = 0
shiftstate = 0
function new_input(text,x,y,w,h,formid)
InputID = InputID + 1
IInputs[InputID] = {text = "", x = 0, y = 0, w = 0, h = 0, formid = 0, active = 0}
IInputs[InputID].text = text
IInputs[InputID].x = x
IInputs[InputID].y = y
IInputs[InputID].w = w
IInputs[InputID].h = h
IInputs[InputID].formid = formid
echo("New Input, ID = " .. InputID)
end
function checkactive(ID)
if(IInputs[ID].active == 1) then return 1 end
echo("Inputbox: " .. i .. ".active = " .. IInputs[i].active)
end
local function ___mouse_down(button,x,y)
for i=1,#IInputs do
IInputs[i].active = hit_test(IInputs[i].x+FForms[IInputs[i].formid].x,IInputs[i].y+FForms[IInputs[i].formid].y+30,IInputs[i].w,IInputs[i].h)
end
end
local function DrawInputs()
for i=1,#IInputs do
if(FForms[IInputs[i].formid].show == 1) then
set_color(FForms[IInputs[i].formid].r,FForms[IInputs[i].formid].g,FForms[IInputs[i].formid].b,0.3)
draw_quad(FForms[IInputs[i].formid].x + IInputs[i].x, FForms[IInputs[i].formid].y + IInputs[i].y+30, IInputs[i].w, IInputs[i].h)
set_color(1,1,1,0.3)
draw_quad(IInputs[i].x+FForms[IInputs[i].formid].x+IInputs[i].w-2,FForms[IInputs[i].formid].y+IInputs[i].y+30, 2, IInputs[i].h)
draw_quad(IInputs[i].x+FForms[IInputs[i].formid].x,FForms[IInputs[i].formid].y+IInputs[i].y+28+IInputs[i].h, IInputs[i].w-2, 2)
set_color(0,0,0,0.3)
draw_quad(IInputs[i].x+FForms[IInputs[i].formid].x,FForms[IInputs[i].formid].y+IInputs[i].y+30, 2, IInputs[i].h)
draw_quad(IInputs[i].x+FForms[IInputs[i].formid].x+2,FForms[IInputs[i].formid].y+IInputs[i].y+30, IInputs[i].w-2, 2)
set_color(0,0,0,IInputs[i].active+0.3)
draw_boxed_text(IInputs[i].text, IInputs[i].x+FForms[IInputs[i].formid].x+3, FForms[IInputs[i].formid].y + IInputs[i].y+30, IInputs[i].w, IInputs[i].h, 15, 1)
end
end
end
function inputboxinput(key,i)
echo(i)
if key == 8 then
if #IInputs[i].text <= 1 then IInputs[i].text = "" end
if #IInputs[i].text > 1 then IInputs[i].text = string.sub(IInputs[i].text,1,#IInputs[i].text - 1) end
else
if shiftstate == 0 then IInputs[i].text = IInputs[i].text .. string.char(key)
else IInputs[i].text = IInputs[i].text .. string.upper(string.char(key))
end
end
--echo(IInputs[i].text)
end
local function _KeyDown(key)
if key == 303 or key == 304 then shiftstate = 1; return 1 end
for i=1,#IInputs do
echo(IInputs[i].active)
if(checkactive(i) and key ~= 13 and key ~= 27) then
--echo("Inputting: " .. string.char(key))
inputboxinput(key,i)
--echo("Input: " .. string.char(key))
return 1
end
end
end
local function _KeyUp(key)
if key == 303 or key == 304 then shiftstate = 0; return 1 end
return 1
end
add_hook("draw2d","InputBoxes",DrawInputs)
add_hook("key_down","InputBoxes",_KeyDown)
add_hook("key_up","InputBoxes",_KeyUp)
add_hook("mouse_button_down","InputBoxes",___mouse_down)
Any reason why?
Last edited by Blam; Mar 29, 2008 at 11:26 AM.