|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
Lynxz Gaming Expert Cheater Reputation: 4
Joined: 01 Jul 2017 Posts: 208 Location: help
|
Posted: Sat May 05, 2018 10:09 am Post subject: convert form design into a lua [help] |
|
|
How to convert form design into a lua script :
example in the form design there is a button
then we will convert it into lua
and it will be
Code: |
btn = createCEButton(formname)
btn.width = 100
btn.height = 100
btn.left = 10
btn.top = 50
|
_________________
my english is bad
discord : rynx#9828 |
|
Back to top |
|
|
Corroder Grandmaster Cheater Supreme Reputation: 75
Joined: 10 Apr 2015 Posts: 1667
|
Posted: Sat May 05, 2018 7:00 pm Post subject: |
|
|
This from old topic. I can't found where is the original post here. But, someone found it, then credit must go to who created this CE lua plug-in. This plug-in call as : "CE Form To LUA script".
A. Script (copy and paste to notepad and then save as 'Form2Lua.lua' file and PUT that lua file to CE Autorun Folder
Code: | function TranslateToFunction(Str, parent)
if (type(Str) ~= 'string') then error('Not valid type'); end;
local action = 'create' .. string.gsub(Str, 'TCE', '') -- Easy solution..
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) -- Not sure that you need this
-- FormToLua[i].Object_font = tostring(Object.Font) -- Or this..
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
for line in string.gfind (GenerateScript,"[^\n]+") do
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
print(line);
end
end
end
function Start()
CEToLua = createForm(false)
CEToLua.height = 25
CEToLua.width = 240
CEToLua.caption = "Convert CE Form to LUA scripts"
CEToLuaButton = createButton(CEToLua)
CEToLuaButton.caption = "Generate"
CEToLuaButton.height = 20
CEToLuaButton.width = 60
CEToLuaButton.top = 2
CEToLuaButton.left = 178
CEToLuaEdit = createEdit(CEToLua)
CEToLuaEdit.width = 174
CEToLuaEdit.left = 2
CEToLuaEdit.top = 2
CEToLuaEdit.Caption = ""
CEToLuaButton.onClick = function ()
a = CEToLuaEdit.Text
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()
end
CEToLua.centerScreen()
end
Start()
function CETrainerToLua()
if CEToLua.getVisible() then
CEToLua.hide()
else
CEToLua.show()
end
end
CEMenu = menu_getItems(form_getMenu(getMainForm()))
CETrainerToLuaScript = createMenuItem(CEMenu)
menuItem_add(CEMenu, CETrainerToLuaScript)
menuItem_setCaption(CETrainerToLuaScript, "CE Form to LUA")
menuItem_onClick(CETrainerToLuaScript, CETrainerToLua) |
B. How to use ?
1. Open CE and a new menu 'CE Form to LUA' will appear. (Capture1). Click on this new menu, it will pop-up a new small window. Just leave it for now.
2. Make your form using CE Form Designer (including all form stuffs like button, panel, label, etc....as you wish)
3. Give name your form (default is UDF1)
4. Back to 'new small window' and type your form name there
5. Click 'Generated' (It will generating lua script as result)
6. Copy lua script result and use it as you wish
EDIT :
C. I can't believe why this script were not added to Lua Plug-in section at that time ?
Description: |
|
Filesize: |
109.29 KB |
Viewed: |
9776 Time(s) |
|
Description: |
|
Filesize: |
91.54 KB |
Viewed: |
9777 Time(s) |
|
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
Back to top |
|
|
Lynxz Gaming Expert Cheater Reputation: 4
Joined: 01 Jul 2017 Posts: 208 Location: help
|
Posted: Sat May 05, 2018 10:56 pm Post subject: |
|
|
Wowww!!! omg this is what im looking forrrr!!!!
THX Corroder!!
_________________
my english is bad
discord : rynx#9828 |
|
Back to top |
|
|
TheyCallMeTim13 Wiki Contributor Reputation: 50
Joined: 24 Feb 2017 Posts: 976 Location: Pluto
|
Posted: Tue May 08, 2018 6:32 pm Post subject: |
|
|
Thought this was neat, so I did some messing with it and here is my modified version. Puts it in the CE "Tools" menu item. There is still a lot on controls it doesn't work with, but still a neat tool.
Code: |
local format = string.format
local strE = string.empty or STRING_EMPTY or ''
local t = translate
local LineEnd = '\r\n'
local CreateMainFormMenuItems = true
local MainMenuItemName = 'ools1' --'miTools' -- 'ools1'
local MainMenuItemCaption = t('Tools')
local ToolMenuItemCaption = t('CE Form to LUA')
local ToolFormCaption = t('Convert CE Form to Lua script')
local StringStartDel = '\''
local StringEndDel = '\''
local PrintScript = true
local function TranslateToFunction(str, parent)
if (type(str) ~= 'string') then
error('Not a valid type')
end
local action = 'create' .. string.gsub(str, 'TCE', strE)
if str == 'createTRadioButton' then
action = 'createRadioGroup'
elseif (str == 'TTabSheet' and parent
and object_getClassName(parent) == 'TCEPageControl') then
action = parent.getName() .. '.addTab()'
end
return action
end
local function GenerateLuaScript(form)
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) or 'false'
FormToLua.MainForm.visible = 'true'
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(t('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 or false
FormToLua[i].Object_visible = Object.Visible or false
FormToLua[i].IsTab = (object_getClassName(Object) == 'TTabSheet')
FormToLua[i].Object_alignment = Object.Alignment or false
FormToLua[i].Object_anchors = Object.Anchors or false
FormToLua[i].Object_bidiMode = Object.BidiMode or false
FormToLua[i].Object_borderStyle = Object.BorderStyle or false
FormToLua[i].Object_charCase = Object.CharCase or false
FormToLua[i].Object_color = Object.Color or false
FormToLua[i].Object_tabOrder = Object.TabOrder or false
FormToLua[i].Object_tabStop = Object.TabStop or false
FormToLua[i].Object_wordWrap = Object.WordWrap or false
end
script = '--' .. LineEnd .. '----' .. LineEnd .. '---- Form' .. LineEnd
.. FormToLua.MainForm.name .. ' = createForm(' .. FormToLua.MainForm.visible .. ')' .. LineEnd
.. FormToLua.MainForm.name .. '.Caption = ' .. StringStartDel .. FormToLua.MainForm.caption .. StringEndDel .. LineEnd
.. FormToLua.MainForm.name .. '.Left = ' .. FormToLua.MainForm.left .. LineEnd
.. FormToLua.MainForm.name .. '.Top = ' .. FormToLua.MainForm.top .. LineEnd
.. FormToLua.MainForm.name .. '.Width = ' .. FormToLua.MainForm.width .. LineEnd
.. FormToLua.MainForm.name .. '.Height = ' .. FormToLua.MainForm.height .. LineEnd
.. FormToLua.MainForm.name .. '.Align = ' .. FormToLua.MainForm.align .. LineEnd
.. FormToLua.MainForm.name .. '.Enabled = ' .. FormToLua.MainForm.enabled .. LineEnd
.. FormToLua.MainForm.name .. '.Visible = ' .. FormToLua.MainForm.visible .. LineEnd
.. '--' .. LineEnd .. '----' .. LineEnd .. '---- Controls' .. LineEnd
for i = 1, CompCount do
i = i - 1
script = script .. '--' .. LineEnd .. '---- ' .. FormToLua[i].Object_name .. LineEnd
.. (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 .. ')') .. LineEnd
.. ((FormToLua[i].Object_caption == false) and strE
or FormToLua[i].Object_name .. '.Caption = ' .. StringStartDel .. FormToLua[i].Object_caption .. StringEndDel) .. LineEnd
.. ((FormToLua[i].Object_left == false) and strE
or FormToLua[i].Object_name .. '.Left = ' .. tostring(FormToLua[i].Object_left)) .. LineEnd
.. ((FormToLua[i].Object_top == false) and strE
or FormToLua[i].Object_name .. '.Top = ' .. tostring(FormToLua[i].Object_top)) .. LineEnd
.. ((FormToLua[i].Object_width == false) and strE
or FormToLua[i].Object_name .. '.Width = ' .. tostring(FormToLua[i].Object_width)) .. LineEnd
.. ((FormToLua[i].Object_height == false) and strE
or FormToLua[i].Object_name .. '.Height = ' .. tostring(FormToLua[i].Object_height)) .. LineEnd
.. ((FormToLua[i].Object_align == false) and strE
or FormToLua[i].Object_name .. '.Align = ' .. tostring(FormToLua[i].Object_align)) .. LineEnd
.. ((FormToLua[i].Object_enabled == false) and strE
or FormToLua[i].Object_name .. '.Enabled = ' .. tostring(FormToLua[i].Object_enabled)) .. LineEnd
.. ((FormToLua[i].Object_visible == false) and strE
or FormToLua[i].Object_name .. '.Visible = ' .. tostring(FormToLua[i].Object_visible)) .. LineEnd
.. ((FormToLua[i].Object_alignment == false) and strE
or FormToLua[i].Object_name .. '.Alignment = ' .. tostring(FormToLua[i].Object_alignment)) .. LineEnd
.. ((FormToLua[i].Object_anchors == false) and strE
or FormToLua[i].Object_name .. '.Anchors = ' .. tostring(FormToLua[i].Object_anchors)):gsub('%[', '{'):gsub('%]', '}') .. LineEnd
.. ((FormToLua[i].Object_bidiMode == false) and strE
or FormToLua[i].Object_name .. '.BidiMode = ' .. tostring(FormToLua[i].Object_bidiMode)) .. LineEnd
.. ((FormToLua[i].Object_borderStyle == false) and strE
or FormToLua[i].Object_name .. '.BorderStyle = ' .. tostring(FormToLua[i].Object_borderStyle)) .. LineEnd
.. ((FormToLua[i].Object_charCase == false) and strE
or FormToLua[i].Object_name .. '.CharCase = ' .. tostring(FormToLua[i].Object_charCase)) .. LineEnd
.. ((FormToLua[i].Object_color == false) and strE
or FormToLua[i].Object_name .. '.Color = ' .. tostring(FormToLua[i].Object_color)) .. LineEnd
.. ((FormToLua[i].Object_tabOrder == false) and strE
or FormToLua[i].Object_name .. '.TabOrder = ' .. tostring(FormToLua[i].Object_tabOrder)) .. LineEnd
.. ((FormToLua[i].Object_tabStop == false) and strE
or FormToLua[i].Object_name .. '.TabStop = ' .. tostring(FormToLua[i].Object_tabStop)) .. LineEnd
.. ((FormToLua[i].Object_wordWrap == false) and strE
or FormToLua[i].Object_name .. '.WordWrap = ' .. tostring(FormToLua[i].Object_wordWrap)) .. LineEnd
end
script = script:gsub('\r\n\r\n', '\r\n')
script = script:gsub('\r\n\r\n', '\r\n')
if PrintScript then
print(script)
end
return script
end
local function Start()
CEToLua = createForm(false)
CEToLua.height = 25
CEToLua.width = 300
CEToLua.caption = ToolFormCaption
CEToLuaButton = createButton(CEToLua)
CEToLuaButton.caption = t('Generate')
CEToLuaButton.height = 20
CEToLuaButton.width = 100
CEToLuaButton.top = 2
CEToLuaButton.left = 198
CEToLuaButton.Default = true
CEToLuaEdit = createEdit(CEToLua)
CEToLuaEdit.width = 194
CEToLuaEdit.left = 2
CEToLuaEdit.top = 2
CEToLuaEdit.Caption = strE
CEToLuaButton.onClick = function( ... )
local text = CEToLuaEdit.Text
if text == nil or text == strE then
local msg = t('The form name can not be empty!')
showMessage(msg)
error(msg)
return
end
loadstring('FormTest = (' .. text .. ' or nil) -- Defines "FormTest" as a CE form')()
if (type(FormTest) ~= 'userdata') then
FormTest = nil
CEToLuaEdit.Caption = strE
local msg = t('Sorry but this is not a valid form!')
showMessage(msg)
error(msg)
return
end
GenerateLuaScript(FormTest)
FormTest = nil
CEToLua.hide()
end
CEToLua.OnClose = function( ... )
CEToLua.hide()
end
CEToLua.centerScreen()
end
Start()
local function CETrainerToLua()
if CEToLua.getVisible() then
CEToLua.hide()
else
CEToLua.show()
CEToLuaEdit.setFocus()
end
end
--
----
---- Setup and load
local function addMenuItem(parent, caption)
if parent == nil then return nil end
local newItem = createMenuItem(parent)
parent.add(newItem)
newItem.Caption = caption
return newItem
end
local function createMainFormMenu()
if MainForm.Menu == nil then return end
local menuItems = MainForm.Menu.Items
local miTools = nil
for i = 0, menuItems.Count - 1 do
if menuItems[i].Name == MainMenuItemName then
miTools = menuItems[i]
miTools.visible = true
-- addMenuItem(miTools, '-')
end
end
if miTools == nil then
miTools = createMenuItem(MainForm)
miTools.Name = MainMenuItemName
miTools.Caption = MainMenuItemCaption
menuItems.insert(menuItems.Count - 2, miTools)
end
return miTools
end
local function loadMenuAddCEForm2Lua()
local function loadloadMenuAddCEForm2LuaTimer_tick(timer)
timer.destroy()
if CreateMainFormMenuItems then
local miTools = createMainFormMenu()
addMenuItem(miTools, t(ToolMenuItemCaption)).setOnClick(CETrainerToLua)
end
end
local intervals = 100
local timer = createTimer(MainForm)
timer.Interval = intervals
timer.OnTimer = loadloadMenuAddCEForm2LuaTimer_tick
end
loadMenuAddCEForm2Lua()
|
_________________
|
|
Back to top |
|
|
Corroder Grandmaster Cheater Supreme Reputation: 75
Joined: 10 Apr 2015 Posts: 1667
|
Posted: Wed May 09, 2018 3:39 am Post subject: |
|
|
Nice work #TheyCallMeTim13, I am also trying to accomplish this function.
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
Back to top |
|
|
TheyCallMeTim13 Wiki Contributor Reputation: 50
Joined: 24 Feb 2017 Posts: 976 Location: Pluto
|
Posted: Wed May 09, 2018 11:29 pm Post subject: |
|
|
So it still needs some testing, and it still needs to be added as a menu item/tool. But here is what I ended up coming up with.
EDIT:
Need to fix "TScrollBox" and "TRadioButton", and figure out how to create then.
Code: |
local format = string.format
local strE = string.empty or STRING_EMPTY or ''
local t = translate
local LineEnd = '\r\n'
local StringDel = { '\'', '\'' }
local controlPropertyList = {
Tag = true,
Left = true,
Height = true,
Hint = true,
Top = true,
Width = true,
HelpType = true,
HelpKeyword = true,
HelpContext = true,
Align = true,
AllowDropFiles = true,
AlphaBlend = true,
AlphaBlendValue = true,
Anchors = true,
AutoScroll = true,
AutoSize = true,
BiDiMode = true,
BorderIcons = true,
BorderStyle = true,
BorderWidth = true,
Caption = true,
ClientHeight = true,
ClientWidth = true,
Color = true,
Constraints = true,
MaxWidth = true,
MinHeight = true,
MinWidth = true,
DefaultMonitor = true,
DockSite = true,
DragKind = true,
DragMode = true,
Font = true,
Name = true,
Orientation = true,
Pitch = true,
Quality = true,
Size = true,
Style = true,
FormStyle = true,
KeyPreview = true,
Menu = true,
ParentBiDiMode = true,
ParentFont = true,
PixelsPerInch = true,
PopupMenu = true,
Position = true,
ShowInTaskBar = true,
Visible = true,
WindowState = true,
DoNotSaveInTable = true,
BidiMode = true,
BorderSpacing = true,
Cancel = true,
Default = true,
Enabled = true,
ModalResult = true,
ParentShowHint = true,
ShowHint = true,
TabOrder = true,
TabStop = true,
Alignment = true,
Layout = true,
ParentBidiMode = true,
ParentColor = true,
ShowAccelChar = true,
Transparent = true,
WordWrap = true,
OptimalFill = true,
AllowGrayed = true,
Checked = true,
DragCursor = true,
State = true,
AutoFill = true,
ColumnLayout = true,
ItemIndex = true,
ClickOnSelChange = true,
ExtendedSelect = true,
IntegralHeight = true,
ItemHeight = true,
MultiSelect = true,
Sorted = true,
TopIndex = true,
ArrowKeysTraverseList = true,
AutoComplete = true,
AutoCompleteText = true,
AutoDropDown = true,
AutoSelect = true,
CharCase = true,
DropDownCount = true,
ItemWidth = true,
MaxLength = true,
ReadOnly = true,
Text = true,
Max = true,
Min = true,
Smooth = true,
Step = true,
BarShowText = true,
Frequency = true,
LineSize = true,
PageSize = true,
Reversed = true,
ScalePos = true,
SelEnd = true,
SelStart = true,
ShowSelRange = true,
TickMarks = true,
TickStyle = true,
AutoExpand = true,
BackgroundColor = true,
DefaultItemHeight = true,
ExpandSignColor = true,
ExpandSignType = true,
HideSelection = true,
HotTrack = true,
Indent = true,
MultiSelectStyle = true,
RightClickSelect = true,
RowSelect = true,
ScrollBars = true,
SelectionColor = true,
SelectionFontColor = true,
SelectionFontColorUsed = true,
SeparatorColor = true,
ShowButtons = true,
ShowLines = true,
ShowRoot = true,
SortType = true,
StateImages = true,
ToolTips = true,
Options = true,
TreeLineColor = true,
TreeLinePenStyle = true,
AllocBy = true,
AutoSort = true,
Checkboxes = true,
ColumnClick = true,
OwnerData = true,
ShowColumnHeaders = true,
SortColumn = true,
SortDirection = true,
ViewStyle = true,
BevelInner = true,
BevelOuter = true,
BevelWidth = true,
FullRepaint = true,
UseDockManager = true,
AutoSnap = true,
Beveled = true,
MinSize = true,
ResizeAnchor = true,
ResizeStyle = true,
Center = true,
Proportional = true,
Stretch = true,
-------------------------
-- AnchorSideLeft = true,
-- AnchorSideTop = true,
-- AnchorSideRight = true,
-- AnchorSideBottom = true,
-- HorzScrollBar = true,
-- VertScrollBar = true,
-- ChildSizing = true,
-- Cursor = true,
-- Icon = true,
-- IconOptions = true,
-- Picture = true,
-- Images = true,
-- Columns = true,
-- Items = true,
}
local controlPropertyStrings = {
Name = true,
Hint = true,
HelpKeyword = true,
Caption = true,
Anchors = true,
BorderIcons = true,
Style = true,
AutoCompleteText = true,
MultiSelectStyle = true,
Options = true,
}
local controlPropertyGroups = {
Font = true,
Constraints = true,
BorderSpacing = true,
-- AnchorSideLeft = true,
-- AnchorSideTop = true,
-- AnchorSideRight = true,
-- AnchorSideBottom = true,
-- Icon = true,
-- IconOptions = true,
-- Picture = true,
-- Columns = true,
-- Items = true,
}
local controlCreators = {
TRadioButton = 'createRadioGroup',
}
local usedKeys = {
AnchorSideLeft = true,
AnchorSideTop = true,
AnchorSideRight = true,
AnchorSideBottom = true,
HorzScrollBar = true,
VertScrollBar = true,
ChildSizing = true,
Cursor = true,
Icon = true,
IconOptions = true,
Picture = true,
Images = true,
Columns = true,
Items = true,
}
local printUnusedKeys = false
local function getCreator(control)
---- Could use 'createClass'
local action = 'create' .. control.ClassName:gsub('TCE', strE)
if controlCreators[control.ClassName] then
action = controlCreators[control.ClassName]
end
local call = '()'
if control.Parent ~= nil then
call = format('(%s)', control.Parent.Name)
end
return action .. call
end
local function getPropertiesScript(control, parentStr)
local script = strE
local pl = getPropertyList(control)
if pl then
for i = 1, pl.Count - 1 do
if controlPropertyGroups[pl[i]] then
script = script .. getPropertiesScript(control[pl[i]], format('%s.%s', parentStr, pl[i]))
elseif controlPropertyList[pl[i]] then
if control[pl[i]] ~= nil then
local v = control[pl[i]]
if controlPropertyStrings[pl[i]] then
v = format('%s%s%s', StringDel[1], v, StringDel[2])
end
script = script .. format('%s.%s = %s', parentStr, pl[i], v) .. LineEnd
end
else
if printUnusedKeys and not usedKeys[pl[i]] then
usedKeys[pl[i]] = true
print(format('---- Key Not Used: "%s"', pl[i]))
end
end
end
end
return script
end
local function getControlComponentScript(control)
local script = strE
if control.ControlCount ~= nil then
for i = 0, control.ComponentCount - 1 do
if control.Component[i].ClassName ~= 'TJvDesignHandle' then
script = script .. '--' .. LineEnd .. '---- ' .. control.Component[i].Name .. LineEnd
script = script .. '--------------------' .. LineEnd
script = script .. format('%s = %s', control.Component[i].Name, getCreator(control.Component[i])) .. LineEnd
script = script .. getPropertiesScript(control.Component[i], control.Component[i].Name)
if control.Component[i].ComponentCount then
script = script .. getControlComponentScript(control.Component[i])
end
script = script .. '--------------------' .. LineEnd
end
end
end
return script
end
local function getControlScript(control)
local parentStr = control.Name
local script = '--' .. LineEnd .. '----' .. LineEnd .. '---- FORM: ' .. control.Name .. LineEnd
script = script .. '------------------------------' .. LineEnd
script = script .. format('%s = %s', parentStr, getCreator(control)) .. LineEnd
script = script .. getPropertiesScript(control, parentStr)
script = script .. '------------------------------' .. LineEnd
script = script .. '---- ' .. control.Name .. ' : Components' .. LineEnd
script = script .. '------------------------------' .. LineEnd
script = script .. getControlComponentScript(control)
script = script .. '------------------------------' .. LineEnd
script = script .. '---- END FORM: ' .. control.Name .. LineEnd .. '---- ' .. LineEnd .. '--' .. LineEnd
return script
end
function CEForm2Lua(form, noPrint)
local vis = form.Visible
form.Visible = true
local s = getControlScript(form)
form.Visible = vis
if not noPrint then
print(s)
end
return s
end
|
_________________
|
|
Back to top |
|
|
Corroder Grandmaster Cheater Supreme Reputation: 75
Joined: 10 Apr 2015 Posts: 1667
|
Posted: Thu May 10, 2018 7:25 am Post subject: |
|
|
Quote: | Need to fix "TScrollBox" |
This function below, usually I use to creating a scroll box via lua :
Code: | function createScrollBox(Parent)
local box = createComponentClass('TScrollBox', Parent)
box.Parent = Parent
return box
end
-- used : createScrollBox(UDF1) -- [form name]
|
But I am not sure where add the function on your script.
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
Back to top |
|
|
TheyCallMeTim13 Wiki Contributor Reputation: 50
Joined: 24 Feb 2017 Posts: 976 Location: Pluto
|
Posted: Thu May 10, 2018 7:19 pm Post subject: |
|
|
Well here is the full script more or less, but scroll box and radio buttons still don't work right.
Code: |
local format = string.format
local strE = string.empty or STRING_EMPTY or ''
local t = translate
local LineEnd = '\r\n'
local CreateMainFormMenuItems = true
local MainMenuItemName = 'ools1' --'miTools' -- 'ools1'
local MainMenuItemCaption = t('Tools')
local ToolMenuItemCaption = t('CE Form to LUA')
local ToolFormCaption = t('Convert CE Form to Lua script')
local StringDel = { '\'', '\'' }
local controlPropertyList = {
Tag = true,
Left = true,
Height = true,
Hint = true,
Top = true,
Width = true,
HelpType = true,
HelpKeyword = true,
HelpContext = true,
Align = true,
AllowDropFiles = true,
AlphaBlend = true,
AlphaBlendValue = true,
Anchors = true,
AutoScroll = true,
AutoSize = true,
BiDiMode = true,
BorderIcons = true,
BorderStyle = true,
BorderWidth = true,
Caption = true,
ClientHeight = true,
ClientWidth = true,
Color = true,
Constraints = true,
MaxWidth = true,
MinHeight = true,
MinWidth = true,
DefaultMonitor = true,
DockSite = true,
DragKind = true,
DragMode = true,
Font = true,
Name = true,
Orientation = true,
Pitch = true,
Quality = true,
Size = true,
Style = true,
FormStyle = true,
KeyPreview = true,
Menu = true,
ParentBiDiMode = true,
ParentFont = true,
PixelsPerInch = true,
PopupMenu = true,
Position = true,
ShowInTaskBar = true,
Visible = true,
WindowState = true,
DoNotSaveInTable = true,
BidiMode = true,
BorderSpacing = true,
Cancel = true,
Default = true,
Enabled = true,
ModalResult = true,
ParentShowHint = true,
ShowHint = true,
TabOrder = true,
TabStop = true,
Alignment = true,
Layout = true,
ParentBidiMode = true,
ParentColor = true,
ShowAccelChar = true,
Transparent = true,
WordWrap = true,
OptimalFill = true,
AllowGrayed = true,
Checked = true,
DragCursor = true,
State = true,
AutoFill = true,
ColumnLayout = true,
ItemIndex = true,
ClickOnSelChange = true,
ExtendedSelect = true,
IntegralHeight = true,
ItemHeight = true,
MultiSelect = true,
Sorted = true,
TopIndex = true,
ArrowKeysTraverseList = true,
AutoComplete = true,
AutoCompleteText = true,
AutoDropDown = true,
AutoSelect = true,
CharCase = true,
DropDownCount = true,
ItemWidth = true,
MaxLength = true,
ReadOnly = true,
Text = true,
Max = true,
Min = true,
Smooth = true,
Step = true,
BarShowText = true,
Frequency = true,
LineSize = true,
PageSize = true,
Reversed = true,
ScalePos = true,
SelEnd = true,
SelStart = true,
ShowSelRange = true,
TickMarks = true,
TickStyle = true,
AutoExpand = true,
BackgroundColor = true,
DefaultItemHeight = true,
ExpandSignColor = true,
ExpandSignType = true,
HideSelection = true,
HotTrack = true,
Indent = true,
MultiSelectStyle = true,
RightClickSelect = true,
RowSelect = true,
ScrollBars = true,
SelectionColor = true,
SelectionFontColor = true,
SelectionFontColorUsed = true,
SeparatorColor = true,
ShowButtons = true,
ShowLines = true,
ShowRoot = true,
SortType = true,
StateImages = true,
ToolTips = true,
Options = true,
TreeLineColor = true,
TreeLinePenStyle = true,
AllocBy = true,
AutoSort = true,
Checkboxes = true,
ColumnClick = true,
OwnerData = true,
ShowColumnHeaders = true,
SortColumn = true,
SortDirection = true,
ViewStyle = true,
BevelInner = true,
BevelOuter = true,
BevelWidth = true,
FullRepaint = true,
UseDockManager = true,
AutoSnap = true,
Beveled = true,
MinSize = true,
ResizeAnchor = true,
ResizeStyle = true,
Center = true,
Proportional = true,
Stretch = true,
-------------------------
AnchorSideLeft = false,
AnchorSideTop = false,
AnchorSideRight = false,
AnchorSideBottom = false,
HorzScrollBar = false,
VertScrollBar = false,
ChildSizing = false,
Cursor = false,
Icon = false,
IconOptions = false,
Picture = false,
Images = false,
Columns = false,
Items = false,
}
local controlPropertyStrings = {
Name = true,
Hint = true,
HelpKeyword = true,
Caption = true,
Anchors = true,
BorderIcons = true,
Style = true,
AutoCompleteText = true,
MultiSelectStyle = true,
Options = true,
}
local controlPropertyGroups = {
Font = true,
Constraints = true,
BorderSpacing = true,
}
local controlConstructors = {
-- TRadioButton = 'createRadioGroup',
TScrollBox = true,
TRadioButton = true,
}
local usedKeys = {}
local printUnusedKeys = false
local function getConstructor(control)
---- Could use 'createComponentClass'
local action = 'create' .. control.ClassName:gsub('TCE', strE)
local callStr = '(%s)'
local parentStr = (control.Parent and control.Parent.Name) or strE
if controlConstructors[control.ClassName] == true then
action = 'createComponentClass'
callStr = '(' .. StringDel[1] .. control.ClassName .. StringDel[2] .. '%s)'
if parentStr ~= strE then
parentStr = ', ' .. parentStr
end
elseif type(controlConstructors[control.ClassName]) == 'string' then
action = controlConstructors[control.ClassName]
end
return action .. format(callStr, parentStr)
end
local function getPropertiesScript(control, parentStr)
local script = strE
local pl = getPropertyList(control)
if pl then
for i = 1, pl.Count - 1 do
if controlPropertyGroups[pl[i]] then
script = script .. getPropertiesScript(control[pl[i]], format('%s.%s', parentStr, pl[i]))
elseif controlPropertyList[pl[i]] then
if control[pl[i]] ~= nil then
local v = control[pl[i]]
if controlPropertyStrings[pl[i]] then
v = format('%s%s%s', StringDel[1], v, StringDel[2])
end
script = script .. format('%s.%s = %s', parentStr, pl[i], v) .. LineEnd
end
else
if printUnusedKeys and not usedKeys[pl[i]]
and controlPropertyList[pl[i]] ~= false then
usedKeys[pl[i]] = true
print(format('---- Key Not Used: "%s"', pl[i]))
end
end
end
end
return script
end
local function getControlComponentScript(control)
local script = strE
if control.ControlCount ~= nil then
for i = 0, control.ComponentCount - 1 do
if control.Component[i].ClassName ~= 'TJvDesignHandle' then
script = script .. '--' .. LineEnd .. '---- ' .. control.Component[i].Name .. LineEnd
script = script .. '--------------------' .. LineEnd
script = script .. format('%s = %s', control.Component[i].Name, getConstructor(control.Component[i])) .. LineEnd
script = script .. getPropertiesScript(control.Component[i], control.Component[i].Name)
if control.Component[i].ComponentCount then
script = script .. getControlComponentScript(control.Component[i])
end
script = script .. '--------------------' .. LineEnd
end
end
end
return script
end
local function getControlScript(control)
local parentStr = control.Name
local script = '--' .. LineEnd .. '----' .. LineEnd .. '---- FORM: ' .. control.Name .. LineEnd
script = script .. '------------------------------' .. LineEnd
script = script .. format('%s = %s', parentStr, getConstructor(control)) .. LineEnd
script = script .. getPropertiesScript(control, parentStr)
script = script .. '------------------------------' .. LineEnd
script = script .. '---- ' .. control.Name .. ' : Components' .. LineEnd
script = script .. '------------------------------' .. LineEnd
script = script .. getControlComponentScript(control)
script = script .. '------------------------------' .. LineEnd
script = script .. '---- END FORM: ' .. control.Name .. LineEnd .. '---- ' .. LineEnd .. '--' .. LineEnd
return script
end
function CEForm2Lua(form, noPrint)
if form == nil then return end
local vis = form.Visible
form.Visible = true
local s = getControlScript(form)
form.Visible = vis
if not noPrint then
print(s)
end
return s
end
--
----
---- GUI
local function showModalForm()
local fW = 400 -- Form width
local lPush = 90 -- Label width
local sX = fW - (lPush + 10) -- Size X
local sY = 23 -- Size Y
local pX = 3 -- Position X
local pY = 3 -- Position Y
local bW = 75 -- Button Width
local bH = 24 -- Button Hight
local padF = 5 -- Form Padding
local pad1 = 3
local pad2 = 1
local row = 0
local frmGenerate = createForm(false)
frmGenerate.centerScreen()
frmGenerate.setSize(fW, fH)
frmGenerate.Name = 'frmGenerate'
frmGenerate.Caption = t(ToolFormCaption)
local lblFormName = createLabel(frmGenerate)
lblFormName.Name = 'lblFormName'
lblFormName.setPosition(pX, pY + sY * row + pad1)
lblFormName.Caption = 'Form Name' .. ':'
local edFormName = createEdit(frmGenerate)
edFormName.Name ='edFormName'
edFormName.setSize(sX, sY)
edFormName.setPosition(pX + lPush, pY + sY * row + pad2)
edFormName.Text = strE
row = row + 1
local btnOk = createButton(frmGenerate)
btnOk.Name = 'btnOk'
btnOk.Caption = 'OK'
btnOk.setSize(bW, bH)
btnOk.setPosition((fW / 3) - (bW / 2), pY + sY * row + pad2)
btnOk.ModalResult = mrOK
btnOk.Default = true
local btnCancel = createButton(frmGenerate)
btnCancel.Name = 'btnCancel'
btnCancel.Caption = 'Cancel'
btnCancel.setSize(bW, bH)
btnCancel.setPosition(((fW / 3) * 2) - (bW / 2), pY + sY * row + pad2)
btnCancel.ModalResult = mrCancel
btnCancel.Cancel = true
row = row + 1
frmGenerate.setSize(fW, pY + sY * row + padF)
local mr = frmGenerate.showModal()
local dt = {
Result = mr,
Name = edFormName.Text,
Form = _G[edFormName.Text],
}
return dt
end
local function form2LuaTool( ... )
local rdt = showModalForm()
if rdt.Result == mrOK then
CEForm2Lua(rdt.Form)
end
end
--
----
---- Setup and load
local function addMenuItem(parent, caption)
if parent == nil then return nil end
local newItem = createMenuItem(parent)
parent.add(newItem)
newItem.Caption = caption
return newItem
end
local function createMainFormMenu()
if MainForm.Menu == nil then return end
local menuItems = MainForm.Menu.Items
local miTools = nil
for i = 0, menuItems.Count - 1 do
if menuItems[i].Name == MainMenuItemName then
miTools = menuItems[i]
miTools.visible = true
-- addMenuItem(miTools, '-')
end
end
if miTools == nil then
miTools = createMenuItem(MainForm)
miTools.Name = MainMenuItemName
miTools.Caption = MainMenuItemCaption
menuItems.insert(menuItems.Count - 2, miTools)
end
return miTools
end
local function loadMenuAddCEForm2Lua()
local function loadloadMenuAddCEForm2LuaTimer_tick(timer)
timer.destroy()
if CreateMainFormMenuItems then
local miTools = createMainFormMenu()
addMenuItem(miTools, t(ToolMenuItemCaption)).setOnClick(form2LuaTool)
end
end
local intervals = 100
local timer = createTimer(MainForm)
timer.Interval = intervals
timer.OnTimer = loadloadMenuAddCEForm2LuaTimer_tick
end
loadMenuAddCEForm2Lua()
|
_________________
|
|
Back to top |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Fri May 11, 2018 3:03 pm Post subject: |
|
|
Much easier method is to convert from "LFM file format" to Lua by hand. I made it many times...
Open your form with FormDesigner, then save it as LFM file. You can open LFM file with any text editor.
A form with button will produce something like this:
Code: | object UDF2: TCEForm
Left = 288
Height = 240
Top = 195
Width = 320
Caption = 'UDF2'
ClientHeight = 240
ClientWidth = 320
object CEButton1: TCEButton
Left = 125
Height = 25
Top = 91
Width = 75
Caption = 'CEButton1'
TabOrder = 0
end
end |
And I convert it by hand (using text editor with MultiCaret feature can help a lot) to something like this:
Code: | UDF2 = createForm()
UDF2.Left = 288
UDF2.Height = 240
UDF2.Top = 195
UDF2.Width = 320
UDF2.Caption = 'UDF2'
UDF2.ClientHeight = 240
UDF2.ClientWidth = 320
CEButton1 = createButton(UDF2)
CEButton1.Left = 125
CEButton1.Height = 25
CEButton1.Top = 91
CEButton1.Width = 75
CEButton1.Caption = 'CEButton1'
CEButton1.TabOrder = 0 |
Of course, there are some limitations. For example, default FORM created with Lua, has few properties set differently than default FORM made with FormDesigner.
So, after "converting from LFM to Lua", I had to always add those lines:
Code: | UDF2.BorderIcons = '[biSystemMenu,biMinimize,biMaximize]'
UDF2.BorderStyle = 'bsSizeable' |
Because Lua created forms have those, BorderIcons set to [biSystemMenu, biMinimize] and BorderStyle set to bsSingle, set as default.
_________________
|
|
Back to top |
|
|
Corroder Grandmaster Cheater Supreme Reputation: 75
Joined: 10 Apr 2015 Posts: 1667
|
Posted: Sun May 13, 2018 6:06 pm Post subject: |
|
|
TheyCallMeTim13
Quote: | but scroll box and radio buttons still don't work right. |
Since didn't find a way to manipulating error when create scrollbox, I tried script like this :
Code: | scrbox_script = [[
function createTScrollBox(Parent)
local box = createComponentClass('TScrollBox', Parent)
box.Parent = Parent
return box
end
]]
..
.. --- other codes and add print function at here on my first script:
..
function Start()
CEToLua = createForm(false)
CEToLua.height = 25
CEToLua.width = 240
CEToLua.caption = "Convert CE Form to LUA scripts"
CEToLuaButton = createButton(CEToLua)
CEToLuaButton.caption = "Generate"
CEToLuaButton.height = 20
CEToLuaButton.width = 60
CEToLuaButton.top = 2
CEToLuaButton.left = 178
CEToLuaEdit = createEdit(CEToLua)
CEToLuaEdit.width = 174
CEToLuaEdit.left = 2
CEToLuaEdit.top = 2
CEToLuaEdit.Caption = ""
CEToLuaButton.onClick = function ()
print(scrbox_script) --------------------------------------------------------------- ADD PRINT HERE
a = CEToLuaEdit.Text
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()
end
CEToLua.centerScreen()
end
Start()
..
..
..
|
I think it can be same way for radio button.
Description: |
|
Filesize: |
94.37 KB |
Viewed: |
9257 Time(s) |
|
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
Back to top |
|
|
TheyCallMeTim13 Wiki Contributor Reputation: 50
Joined: 24 Feb 2017 Posts: 976 Location: Pluto
|
Posted: Sun May 13, 2018 11:14 pm Post subject: |
|
|
So now, I just need to figure out the MainMenu and MenuItems.
The output script runs but not menu is visible on the created form.
Code: |
local format = string.format
local strE = string.empty or STRING_EMPTY or ''
local t = translate
local LineEnd = '\r\n'
local CreateMainFormMenuItems = true
local MainMenuItemName = 'ools1' --'miTools' -- 'ools1'
local MainMenuItemCaption = t('Tools')
local ToolMenuItemCaption = t('CE Form to LUA')
local ToolFormCaption = t('Convert CE Form to Lua script')
local StringDel = { '\'', '\'' }
local controlPropertyList = {
Tag = true,
Left = true,
Height = true,
Hint = true,
Top = true,
Width = true,
HelpType = true,
HelpKeyword = true,
HelpContext = true,
Align = true,
AllowDropFiles = true,
AlphaBlend = true,
AlphaBlendValue = true,
Anchors = true,
AutoScroll = true,
AutoSize = true,
BiDiMode = true,
BorderIcons = true,
BorderStyle = true,
BorderWidth = true,
Caption = true,
ClientHeight = true,
ClientWidth = true,
Color = true,
Constraints = true,
MaxWidth = true,
MinHeight = true,
MinWidth = true,
DefaultMonitor = true,
DockSite = true,
DragKind = true,
DragMode = true,
Font = true,
Name = true,
Orientation = true,
Pitch = true,
Quality = true,
Size = true,
Style = true,
FormStyle = true,
KeyPreview = true,
Menu = true,
ParentBiDiMode = true,
ParentFont = true,
PixelsPerInch = true,
PopupMenu = true,
Position = true,
ShowInTaskBar = true,
Visible = true,
WindowState = true,
DoNotSaveInTable = true,
BidiMode = true,
BorderSpacing = true,
Cancel = true,
Default = true,
Enabled = true,
ModalResult = true,
ParentShowHint = true,
ShowHint = true,
TabOrder = true,
TabStop = true,
Alignment = true,
Layout = true,
ParentBidiMode = true,
ParentColor = true,
ShowAccelChar = true,
Transparent = true,
WordWrap = true,
OptimalFill = true,
AllowGrayed = true,
Checked = true,
DragCursor = true,
State = true,
AutoFill = true,
ColumnLayout = true,
ItemIndex = true,
ClickOnSelChange = true,
ExtendedSelect = true,
IntegralHeight = true,
ItemHeight = true,
MultiSelect = true,
Sorted = true,
TopIndex = true,
ArrowKeysTraverseList = true,
AutoComplete = true,
AutoCompleteText = true,
AutoDropDown = true,
AutoSelect = true,
CharCase = true,
DropDownCount = true,
ItemWidth = true,
MaxLength = true,
ReadOnly = true,
Text = true,
Max = true,
Min = true,
Smooth = true,
Step = true,
BarShowText = true,
Frequency = true,
LineSize = true,
PageSize = true,
Reversed = true,
ScalePos = true,
SelEnd = true,
SelStart = true,
ShowSelRange = true,
TickMarks = true,
TickStyle = true,
AutoExpand = true,
BackgroundColor = true,
DefaultItemHeight = true,
ExpandSignColor = true,
ExpandSignType = true,
HideSelection = true,
HotTrack = true,
Indent = true,
MultiSelectStyle = true,
RightClickSelect = true,
RowSelect = true,
ScrollBars = true,
SelectionColor = true,
SelectionFontColor = true,
SelectionFontColorUsed = true,
SeparatorColor = true,
ShowButtons = true,
ShowLines = true,
ShowRoot = true,
SortType = true,
StateImages = true,
ToolTips = true,
Options = true,
TreeLineColor = true,
TreeLinePenStyle = true,
AllocBy = true,
AutoSort = true,
Checkboxes = true,
ColumnClick = true,
OwnerData = true,
ShowColumnHeaders = true,
SortColumn = true,
SortDirection = true,
ViewStyle = true,
BevelInner = true,
BevelOuter = true,
BevelWidth = true,
FullRepaint = true,
UseDockManager = true,
AutoSnap = true,
Beveled = true,
MinSize = true,
ResizeAnchor = true,
ResizeStyle = true,
Center = true,
Proportional = true,
Stretch = true,
AnchorSideLeft = true,
AnchorSideTop = true,
AnchorSideRight = true,
AnchorSideBottom = true,
Side = true,
Page = true,
Smooth = true,
Position = true,
Range = true,
Tracking = true,
Visible = true,
Center = true,
HorzScrollBar = true,
VertScrollBar = true,
-------------------------
ChildSizing = false,
Cursor = false,
Icon = false,
IconOptions = false,
Picture = false,
Images = false,
Columns = false,
Items = false,
Menu = false,
}
local controlPropertyStrings = {
Name = true,
Hint = true,
HelpKeyword = true,
Caption = true,
Anchors = true,
BorderIcons = true,
Style = true,
AutoCompleteText = true,
MultiSelectStyle = true,
Options = true,
}
local controlPropertyGroups = {
Font = true,
Constraints = true,
BorderSpacing = true,
AnchorSideLeft = true,
AnchorSideTop = true,
AnchorSideRight = true,
AnchorSideBottom = true,
HorzScrollBar = true,
VertScrollBar = true,
}
local controlConstructors = {
TMainMenu = 'createMainMenu',
TMenuItem = 'createMenuItem',
}
local usedKeys = {}
local printUnusedKeys = false
local FormName = nil
function createTScrollBox(Parent)
local control = createComponentClass('TScrollBox', Parent)
control.Parent = Parent
return control
end
function createTRadioButton(Parent)
local control = createComponentClass('TRadioButton', Parent)
control.Parent = Parent
return control
end
local function getConstructor(control)
---- Could use 'createComponentClass'
local action = 'create' .. control.ClassName:gsub('TCE', strE)
local callStr = '(%s)'
local parentStr = (control.Parent and control.Parent.Name) or strE
if type(controlConstructors[control.ClassName]) == 'string' then
action = controlConstructors[control.ClassName]
if action == 'createMainMenu' then
parentStr = FormName
elseif action == 'createMenuItem' then
if parentStr == nil or parentStr == strE then
parentStr = FormName .. '.Menu'
end
end
end
return action .. format(callStr, parentStr)
end
local function getPropertiesScript(control, parentStr)
local script = strE
local pl = getPropertyList(control)
if pl then
for i = 1, pl.Count - 1 do
if controlPropertyGroups[pl[i]] then
script = script .. getPropertiesScript(control[pl[i]], format('%s.%s', parentStr, pl[i]))
elseif controlPropertyList[pl[i]] then
if control[pl[i]] ~= nil then
local v = control[pl[i]]
if controlPropertyStrings[pl[i]] then
v = format('%s%s%s', StringDel[1], v, StringDel[2])
end
script = script .. format('%s.%s = %s', parentStr, pl[i], v) .. LineEnd
end
else
if printUnusedKeys and not usedKeys[pl[i]]
and controlPropertyList[pl[i]] ~= false then
usedKeys[pl[i]] = true
print(format('---- Key Not Used: "%s"', pl[i]))
end
end
end
end
return script
end
local function getControlComponentScript(control)
local script = strE
if control.ControlCount ~= nil then
for i = 0, control.ComponentCount - 1 do
if control.Component[i].ClassName ~= 'TJvDesignHandle' then
script = script .. '--' .. LineEnd .. '---- ' .. control.Component[i].Name .. LineEnd
script = script .. '--------------------' .. LineEnd
script = script .. format('%s = %s', control.Component[i].Name, getConstructor(control.Component[i])) .. LineEnd
script = script .. getPropertiesScript(control.Component[i], control.Component[i].Name)
if control.Component[i].ComponentCount then
script = script .. getControlComponentScript(control.Component[i])
end
script = script .. '--------------------' .. LineEnd
end
end
end
return script
end
local function getControlScript(control)
local parentStr = control.Name
local script = '--' .. LineEnd .. '----' .. LineEnd .. '---- FORM: ' .. control.Name .. LineEnd
script = script .. '------------------------------' .. LineEnd
script = script .. format('%s = %s', parentStr, getConstructor(control)) .. LineEnd
script = script .. getPropertiesScript(control, parentStr)
script = script .. '------------------------------' .. LineEnd
script = script .. '---- ' .. control.Name .. ' : Components' .. LineEnd
script = script .. '------------------------------' .. LineEnd
script = script .. getControlComponentScript(control)
script = script .. '------------------------------' .. LineEnd
script = script .. '---- END FORM: ' .. control.Name .. LineEnd .. '---- ' .. LineEnd .. '--' .. LineEnd
return script
end
function CEForm2Lua(form, noPrint)
if form == nil then return end
if type(form) == 'string' then
form = _G[form]
end
FormName = form.Name
local vis = form.Visible
form.Visible = true
local s = getControlScript(form)
form.Visible = vis
if not noPrint then
print(s)
end
return s
end
--
----
---- GUI
local function showModalForm()
local fW = 400 -- Form width
local lPush = 90 -- Label width
local sX = fW - (lPush + 10) -- Size X
local sY = 23 -- Size Y
local pX = 3 -- Position X
local pY = 3 -- Position Y
local bW = 75 -- Button Width
local bH = 24 -- Button Hight
local padF = 5 -- Form Padding
local pad1 = 3
local pad2 = 1
local row = 0
local frmGenerate = createForm(false)
frmGenerate.centerScreen()
frmGenerate.setSize(fW, fH)
frmGenerate.Name = 'frmGenerate'
frmGenerate.Caption = t(ToolFormCaption)
local lblFormName = createLabel(frmGenerate)
lblFormName.Name = 'lblFormName'
lblFormName.setPosition(pX, pY + sY * row + pad1)
lblFormName.Caption = 'Form Name' .. ':'
local edFormName = createEdit(frmGenerate)
edFormName.Name ='edFormName'
edFormName.setSize(sX, sY)
edFormName.setPosition(pX + lPush, pY + sY * row + pad2)
edFormName.Text = strE
row = row + 1
local btnOk = createButton(frmGenerate)
btnOk.Name = 'btnOk'
btnOk.Caption = 'OK'
btnOk.setSize(bW, bH)
btnOk.setPosition((fW / 3) - (bW / 2), pY + sY * row + pad2)
btnOk.ModalResult = mrOK
btnOk.Default = true
local btnCancel = createButton(frmGenerate)
btnCancel.Name = 'btnCancel'
btnCancel.Caption = 'Cancel'
btnCancel.setSize(bW, bH)
btnCancel.setPosition(((fW / 3) * 2) - (bW / 2), pY + sY * row + pad2)
btnCancel.ModalResult = mrCancel
btnCancel.Cancel = true
row = row + 1
frmGenerate.setSize(fW, pY + sY * row + padF)
local mr = frmGenerate.showModal()
local dt = {
Result = mr,
Name = edFormName.Text,
Form = _G[edFormName.Text],
}
return dt
end
local function form2LuaTool( ... )
local rdt = showModalForm()
if rdt.Result == mrOK then
CEForm2Lua(rdt.Form)
end
end
--
----
---- Setup and load
local function addMenuItem(parent, caption)
if parent == nil then return nil end
local newItem = createMenuItem(parent)
parent.add(newItem)
newItem.Caption = caption
return newItem
end
local function createMainFormMenu()
if MainForm.Menu == nil then return end
local menuItems = MainForm.Menu.Items
local miTools = nil
for i = 0, menuItems.Count - 1 do
if menuItems[i].Name == MainMenuItemName then
miTools = menuItems[i]
miTools.visible = true
-- addMenuItem(miTools, '-')
end
end
if miTools == nil then
miTools = createMenuItem(MainForm)
miTools.Name = MainMenuItemName
miTools.Caption = MainMenuItemCaption
menuItems.insert(menuItems.Count - 2, miTools)
end
return miTools
end
local function loadMenuAddCEForm2Lua()
local function loadloadMenuAddCEForm2LuaTimer_tick(timer)
timer.destroy()
if CreateMainFormMenuItems then
local miTools = createMainFormMenu()
addMenuItem(miTools, t(ToolMenuItemCaption)).setOnClick(form2LuaTool)
end
end
local intervals = 100
local timer = createTimer(MainForm)
timer.Interval = intervals
timer.OnTimer = loadloadMenuAddCEForm2LuaTimer_tick
end
loadMenuAddCEForm2Lua()
|
_________________
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|