This is an old script I am used, just a little modified to generated an LFM file.
Code: Select all
--c = getMainForm()
--c.Visible = false
local path = TrainerOrigin or getMainForm()
if moduleForm then moduleForm.Destroy() end
moduleForm = createForm()
moduleForm.setSize(200,50)
moduleForm.borderStyle = 'bsSingle'
moduleForm.Caption = 'LOL'
bgen = createButton(moduleForm)
bgen.setSize(180,30)
bgen.setPosition(10,10)
bgen.Caption = 'Generate Lua Form Script'
function TranslateToFunction(Str, parent)
if (type(Str) ~= 'string') then error('Not valid type'); end;
local action = 'create' .. string.gsub(Str, 'TCE', '')
if ( Str == 'TTabSheet' and parent and object_getClassName(parent) == 'TCEPageControl') then
action = parent.getName() .. '.addTab()';
end
return action
end
function GenerateLuaScript(WantedForm)
Form = WantedForm
FormToLua = {}
FormToLua.MainForm = {}
CompCount = Form.getComponentCount()
FormToLua.MainForm.name = Form.getName()
FormToLua.MainForm.caption = Form.Caption
FormToLua.MainForm.left = Form.Left
FormToLua.MainForm.top = Form.Top
FormToLua.MainForm.width = Form.Width
FormToLua.MainForm.height = Form.Height
FormToLua.MainForm.align = Form.Align
FormToLua.MainForm.enabled = tostring(Form.Enabled)
FormToLua.MainForm.visible = control_getVisible(Form) and 'true' or 'false'
for i=1,CompCount do
i = i-1
FormToLua[i] = {}
Object = UDF1.getComponent(i)
FormToLua[i].Object_parent = Object.Parent.getName()
FormToLua[i].Object_type = TranslateToFunction(object_getClassName(Object), Object.Parent) or error("No object type???");
FormToLua[i].Object_name = Object.getName() or false
FormToLua[i].Object_caption = Object.caption or false
FormToLua[i].Object_left = Object.Left or false
FormToLua[i].Object_top = Object.Top or false
FormToLua[i].Object_width = Object.Width or false
FormToLua[i].Object_height = Object.Height or false
FormToLua[i].Object_align = Object.Align or false
FormToLua[i].Object_enabled = Object.Enabled and 'true' or false
FormToLua[i].Object_visible = control_getVisible(Object) and 'true' or false
FormToLua[i].IsTab = object_getClassName(Object) == 'TTabSheet';
-- FormToLua[i].Object_color = tostring(Object.Color)
-- FormToLua[i].Object_font = tostring(Object.Font)
end
GenerateScript = [[--Creates first the form
]] .. FormToLua.MainForm.name .. [[ = createForm(]] .. FormToLua.MainForm.visible .. [[)
]] .. FormToLua.MainForm.name .. [[.caption = ]] .. "[[" .. FormToLua.MainForm.caption .. "]]" .. [[
]] .. FormToLua.MainForm.name .. [[.left = ]] .. FormToLua.MainForm.left .. [[
]] .. FormToLua.MainForm.name .. [[.top = ]] .. FormToLua.MainForm.top .. [[
]] .. FormToLua.MainForm.name .. [[.width = ]] .. FormToLua.MainForm.width .. [[
]] .. FormToLua.MainForm.name .. [[.height = ]] .. FormToLua.MainForm.height .. [[
]] .. FormToLua.MainForm.name .. [[.align = ]] .. FormToLua.MainForm.align .. [[
]] .. FormToLua.MainForm.name .. [[.enabled = ]] .. FormToLua.MainForm.enabled .. [[
]] .. FormToLua.MainForm.name .. [[.visible = ]] .. FormToLua.MainForm.visible
local f = assert(io.open(path..FormToLua.MainForm.name..'.LFM', "w"))
for line in string.gfind (GenerateScript,"[^\n]+") do
f:write(line, "\n")
print(line)
end
TempText = [[-- Creating the objects]]
for i = 1, CompCount do
i = i-1
TempText = TempText ..[[
]] .. (FormToLua[i].IsTab and FormToLua[i].Object_name .. [[ = ]] .. FormToLua[i].Object_type or FormToLua[i].Object_name .. [[ = ]] .. FormToLua[i].Object_type .. [[(]] .. FormToLua[i].Object_parent .. [[)]]) .. [[
]] .. ((FormToLua[i].Object_caption == false) and '' or FormToLua[i].Object_name .. [[.caption = ]] .. "[[" .. FormToLua[i].Object_caption .. "]]") .. [[
]] .. ((FormToLua[i].Object_left == false) and '' or FormToLua[i].Object_name .. [[.left = ]] .. "[[" .. FormToLua[i].Object_left .. "]]") .. [[
]] .. ((FormToLua[i].Object_top == false) and '' or FormToLua[i].Object_name .. [[.top = ]] .. "[[" .. FormToLua[i].Object_top .. "]]") .. [[
]] .. ((FormToLua[i].Object_width == false) and '' or FormToLua[i].Object_name .. [[.width = ]] .. "[[" .. FormToLua[i].Object_width .. "]]") .. [[
]] .. ((FormToLua[i].Object_height == false) and '' or FormToLua[i].Object_name .. [[.height = ]] .. "[[" .. FormToLua[i].Object_height .. "]]") .. [[
]] .. ((FormToLua[i].Object_align == false) and '' or FormToLua[i].Object_name .. [[.align = ]] .. "[[" .. FormToLua[i].Object_align .. "]]") .. [[
]] .. ((FormToLua[i].Object_enabled == false) and '' or FormToLua[i].Object_name .. [[.enabled = ]] .. "[[" .. FormToLua[i].Object_enabled .. "]]") .. [[
]] .. ((FormToLua[i].Object_visible == false) and '' or FormToLua[i].Object_name .. [[.visible = ]] .. "[[" .. FormToLua[i].Object_visible .. "]]")
end
for line in string.gfind (TempText,"[^\n]+") do
if (line~= '' and #line > 1) then
f:write(line, "\n")
print(line)
end
end
f:write(FormToLua.MainForm.name..'Show()')
f:close()
end
local mess = [[
Enter FORM NAME you has been created
using CE form designer
]]
function Start()
CEToLua = createForm(false)
CEToLua.height = 70
CEToLua.width = 240
CEToLua.caption = "Generator"
CEToLuaButton = createButton(CEToLua)
CEToLuaButton.caption = "Generate"
CEToLuaButton.height = 20
CEToLuaButton.width = 60
CEToLuaButton.top = 2
CEToLuaButton.left = 178
CEToLuaLabel = createLabel(CEToLua)
CEToLuaLabel.setPosition(5,33)
CEToLuaLabel.Caption = mess
CEToLuaEdit = createEdit(CEToLua)
CEToLuaEdit.width = 174
CEToLuaEdit.left = 2
CEToLuaEdit.top = 2
CEToLuaEdit.Caption = ""
CEToLuaButton.onClick = function ()
a = CEToLuaEdit.Text
if a == "" or a == nil then
showMessage("Form name can not be empty")
return a
end
loadstring([[test = (]] .. a .. [[ or nil) -- Defines test as a form]])()
a = nil
if (type(test)~="userdata") then
test = nil
CEToLuaEdit.Caption = ""
showMessage("Sorry but this is not a valid form!")
return
end
GenerateLuaScript(test)
test = nil
CEToLua.hide()
moduleForm.Show()
--crdr.Visible = true
end
CEToLua.centerScreen()
end
Start()
function CETrainerToLua()
moduleForm.Hide()
if CEToLua.getVisible() then
CEToLua.hide()
else
CEToLua.show()
end
end
function canceled()
CEToLua.hide()
moduleForm.Show()
return caFree
end
function loader()
c = getMainForm()
c.Visible = false
end
function clearance()
closeCE()
return caFree
end
--moduleForm.onShow = loader
moduleForm.Show()
moduleForm.onClose = clearance
bgen.onClick = CETrainerToLua
CEToLua.onClose = canceled
How to use:
1. Save the script above as a CT file
2. Open with CE (I am use CE 7.0)
3. A LOL form will appear (just ignore it for now)
4. Create your form using CE Form Designer
5. Once you finish, click 'Generate Form Lua Script' on the LOL form
6. Done
7. Check your LFM file on the folder where you start LOL form
Note:
In case if you add 'CheckListBox' and/or 'ScrollBox' on your form within CE form designer then check your LFM form
and change 'createTCECheckListBox' to 'createListBox' and 'createTCEScrollBox' to 'createScrollBox'.
I think 'createScrollBox' not work since CE 6.4 till the latest CE version. You can add a scrollbox via a Lua function:
Code: Select all
function createScrollBox(Parent)
local box = createComponentClass('TScrollBox', Parent)
box.Parent = Parent
return box
end
-- and use with, example:
myscbox = createScrollBox(form_name)
TODO:
You also able to add a function on the main script which searches inside the generated LFM file for strings 'createTCECheckListBox' then change to 'createListBox' and strings 'createTCEScrollBox' and change to 'createScrollBox'.
Good luck