A4L

Template Button Code for Testing Functions

A4L
Jan 7th, 2022 (edited)
1,832
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.56 KB | None | 0 0
  1. function onload()
  2.     self.setScale({2.30,2.30,2.30})
  3.     setGlobalVariables()
  4.     makeButtons()
  5. end
  6. function setGlobalVariables()
  7.     TopLabel = 'Top Button Name' -- Name of Top Button
  8.     BotLabel = 'Bottom Button Name' -- Name of Top Button
  9.     MinButtonLength = 2500
  10.  
  11. end
  12. --------------------------------------------------------------------------------
  13. -- Place Demo Code in Here -----------------------------------------------------
  14. function Top_Left_Click(obj, color, alt_click)
  15.     print('Top Function : Left Click')
  16. end
  17.  
  18. function Top_Right_Click(obj, color, alt_click)
  19.     print('Top Function : Right Click')
  20. end
  21. --------------------------------------------------------------------------------
  22. -- Place Demo Code in Here -----------------------------------------------------
  23. function Bot_Left_Click(obj, color, alt_click)
  24.     print('Bottom Function : Left Click')
  25. end
  26.  
  27. function Bot_Right_Click(obj, color, alt_click)
  28.     print('Bottom Function : Right Click')
  29. end
  30.  
  31. --******************************************************************************
  32. --*** Ignore Below this line ***************************************************
  33. --******************************************************************************
  34. function f_Top(obj, color, alt_click)
  35.     if not alt_click then
  36.         Top_Left_Click(obj, color, alt_click)
  37.     else
  38.         Top_Right_Click(obj, color, alt_click)
  39.     end
  40. end
  41.  
  42. function f_Bot(obj, color, alt_click)
  43.     if not alt_click then
  44.         Bot_Left_Click(obj, color, alt_click)
  45.     else
  46.         Bot_Right_Click(obj, color, alt_click)
  47.     end
  48. end
  49. --------------------------------------------------------------------------------
  50. --------------------------------------------------------------------------------
  51. function makeButtons()
  52.     local lable = nil
  53.     local ButtonList = {};
  54.             local button = {}
  55.                     button.click_function = 'f_Top'
  56.                     button.function_owner = self
  57.                     button.position = setDynamicButtonSizes_pos(TopLabel) --{0,0.5,1}
  58.                     button.rotation = {0,180,0}
  59.                     button.label =  TopLabel
  60.                     button.width = setDynamicButtonSizes_Width(TopLabel, MinButtonLength)
  61.                     button.height = setDynamicButtonSizes_Hight(TopLabel)
  62.                     button.font_size = 250
  63.             table.insert(ButtonList, button)
  64.             button = {}
  65.                     button.click_function = 'f_Bot'
  66.                     button.function_owner = self
  67.                     button.label = BotLabel
  68.                     button.position = setDynamicButtonSizes_pos(BotLabel) --{0,0.5,-1}
  69.                     button.rotation = {0,180,0}
  70.                     button.width = setDynamicButtonSizes_Width(BotLabel, MinButtonLength)
  71.                     button.height = setDynamicButtonSizes_Hight(BotLabel)
  72.                     button.font_size = 250
  73.             table.insert(ButtonList, button)
  74.  
  75.     for k, b in pairs (ButtonList) do
  76.         self.createButton(b)
  77.     end
  78. end
  79.  
  80. function setDynamicButtonSizes_pos(label)
  81.     local posVec = Vector(0,0.5,1)
  82.     local lines = {}
  83.     for line in label:gmatch("[^\r\n]+") do
  84.         table.insert(lines, line)
  85.     end
  86.  
  87.     adjustZ = 1 + 0.1*#lines
  88.     if label == TopLabel then
  89.         posVec:setAt('z', adjustZ)
  90.     elseif label == BotLabel then
  91.         posVec:setAt('z', -adjustZ)
  92.     end
  93.     --print(logString(lines, 'lines'))
  94.  
  95.     return posVec
  96. end
  97.  
  98. function setDynamicButtonSizes_Hight(lable)
  99.     local minHight = 450
  100.     local lines = {}
  101.     for line in lable:gmatch("[^\r\n]+") do
  102.         table.insert(lines, line)
  103.     end
  104.  
  105.     local count = #lines
  106.     local adjust_hight = 200
  107.     if count > 1 then
  108.         for i=1, count, 1 do
  109.             minHight = minHight + adjust_hight
  110.         end
  111.     end
  112.     return minHight
  113. end
  114.  
  115. function setDynamicButtonSizes_Width(str, minWidth)
  116.     local lable = string.upper(str)--str:gsub("^%l", string.upper)
  117.     local lableSize = #lable
  118.     --print(lable)
  119.     local adjust_Width = 100
  120.     local widthBorder = 600
  121.     local Width = 0
  122.  
  123.     local lines = {}
  124.     for line in lable:gmatch("[^\r\n]+") do
  125.         table.insert(lines, line)
  126.     end
  127.  
  128.     local size = 0
  129.     if lines[2] ~= nil then
  130.         for _, line in pairs(lines) do
  131.             if size < #line then size = #line end
  132.         end
  133.         lableSize = size
  134.     end
  135.  
  136.  
  137.     for i=1, lableSize, 1 do
  138.         Width = Width + adjust_Width
  139.     end
  140.     Width = Width + widthBorder
  141.  
  142.     if Width < minWidth then
  143.         Width = minWidth
  144.     end
  145.     return Width
  146. end
Advertisement
Add Comment
Please, Sign In to add comment