Advertisement
astral17

AGUI-dev.lua

Jul 25th, 2018
55
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local gpu = require("component").gpu
  2. local event = require("event")
  3. local unicode = require("unicode")
  4.  
  5. local IsInited = false
  6. local gui = {}
  7. local elements -- = {}
  8. local timers -- = {}
  9.  
  10. gui.Version = "0.4"
  11.  
  12. -- function gui.getVersion(requestVersion)
  13.   -- if type(goodVersion) ~= "table" then
  14.     -- return false
  15.   -- end
  16.   -- if V
  17. -- end
  18.  
  19. --gui.Elements = elements
  20.  
  21. function gui.NewIsClicked(x1, y1, x2, y2)
  22.   return function(x, y) return x1 <= x and x <= x2 and y1 <= y and y <= y2;end
  23. end
  24.  
  25. function gui:IsClicked(x, y)
  26.   return self.X <= x and x <= self.X + self.Width - 1 and self.Y <= y and y <= self.Y + self.Height - 1
  27. end
  28.  
  29. function gui.gc()
  30.   for index, element in pairs(elements) do
  31.     if type(element) == "table" and element.Garbage then
  32.       elements[index] = nil
  33.     end
  34.   end
  35. end
  36.  
  37. function gui.OnClick(_, _, x, y, _, name)
  38.   gui.gc()
  39.   for index, element in pairs(elements) do
  40.     if type(element) == "table" and element.Enabled and type(element.OnClick) == "function" then
  41.       -- element:OnClick(x, y)
  42.       pcall(element.OnClick, element, x, y)
  43.     end
  44.   end
  45.  
  46.   for index, element in pairs(elements) do
  47.     if type(element) == "table" and element.Enabled and type(element.IsClicked) == "function" and type(element.OnElementClick) == "function" and element:IsClicked(x, y) then
  48.       -- element:OnElementClick(x - element.X + 1, y - element.Y + 1)
  49.       pcall(element.OnElementClick, element, x - element.X + 1, y - element.Y + 1)
  50.       break
  51.     end
  52.   end
  53. end
  54.  
  55. function gui.OnKeyDown(_, _, key1, key2, name)
  56.   gui.gc()
  57.   for index, element in pairs(elements) do
  58.     if type(element) == "table" and element.Enabled and element.Focused and type(element.OnKeyDown) == "function" then
  59.       -- element:OnKeyDown(key1, key2, name)
  60.       pcall(element.OnKeyDown, element, key1, key2, name)
  61.     end
  62.   end
  63. end
  64.  
  65. function gui.Init()
  66.   if IsInited then
  67.     return false
  68.   end
  69.   IsInited = true
  70.   elements = {}
  71.   timers = {}
  72.   event.listen("touch", gui.OnClick)
  73.   event.listen("key_down", gui.OnKeyDown)
  74. end
  75.  
  76. function gui.Destroy()
  77.   event.ignore("touch", gui.OnClick)
  78.   event.ignore("key_down", gui.OnKeyDown)
  79.   IsInited = false
  80.   for index, timer in pairs(timers) do
  81.     event.cancel(timer)
  82.   end
  83.   timers = nil
  84.   for index, element in pairs(elements) do
  85.     if type(element) == "table" and type(element.Destroy) == "function" then
  86.       element:Destroy()
  87.     end
  88.   end
  89.   elements = nil
  90.   -- WorkingSpaceStack = nil
  91.   -- _G.guiDestroy = nil
  92. end
  93.  
  94. -- function gui.CreateWorkingSpace()
  95.   -- local LocalGUI = {elements = nil}
  96.   -- return
  97. -- end
  98.  
  99. -- function _G.guiDestroy()
  100.   -- gui.Destroy()
  101. -- end
  102.  
  103. function gui.Create(element)
  104.   if type(element) ~= "table" then
  105.     return {}
  106.   end
  107.   if type(element.Destroy) ~= "function" then
  108.     element.Destroy = function(self) self.Garbage = true end
  109.   end
  110.   if type(element.Enabled) ~= "boolean" then
  111.     element.Enabled = false
  112.   end
  113.  
  114.   if type(element.Enable) ~= "function" then
  115.     element.Enable = function(self) self.Enabled = true; return self end
  116.   end
  117.  
  118.   if type(element.Disable) ~= "function" then
  119.     element.Disable = function(self) self.Enabled = false; return self end
  120.   end
  121.  
  122.   if type(element.Init) ~= "function" then
  123.     element.Init = function(self) return self end
  124.   end
  125.  
  126.   if type(element.Paint) ~= "function" then
  127.     element.Paint = function(self) return self end
  128.   end
  129.  
  130.   if type(element.Modify) ~= "function" then
  131.     element.Modify = function(self, tbl)
  132.       for index, element in pairs(tbl) do
  133.         self[index] = element
  134.       end
  135.       return self
  136.     end
  137.   end
  138.  
  139.   if type(element.X) ~= "number" then
  140.     element.X = 1
  141.   end
  142.  
  143.   if type(element.Y) ~= "number" then
  144.     element.Y = 1
  145.   end
  146.  
  147.   if type(element.Width) ~= "number" then
  148.     element.Width = 1
  149.   end
  150.  
  151.   if type(element.Height) ~= "number" then
  152.     element.Height = 1
  153.   end
  154.  
  155.   if type(element.Focused) ~= "boolean" then
  156.     element.Focused = false
  157.   end
  158.  
  159.   table.insert(elements, element)
  160.   return element
  161. end
  162.  
  163. -- Group --
  164.  
  165. function gui.GroupCreate(group, elements)
  166.   if type(group) ~= "table" then
  167.     group = {}
  168.   end
  169.  
  170.   group.X = 1
  171.   group.Y = 1
  172.   group.Width = 1
  173.   group.Height = 1
  174.  
  175.   if type(group.Init) ~= "function" then
  176.     group.Init = function(self)
  177.       for index, element in pairs(self.Elements) do
  178.         if type(element) == "table" and type(element.Init) == "function" then
  179.           element:Init()
  180.         end
  181.       end
  182.       return self
  183.     end
  184.   end
  185.  
  186.   if type(group.Enabled) ~= "boolean" then
  187.     group.Enabled = false
  188.   end
  189.  
  190.   if type(group.Paint) ~= "function" then
  191.     group.Paint = function(self)
  192.       for index, element in pairs(self.Elements) do
  193.         if type(element) == "table" and type(element.Paint) == "function" then
  194.           element:Paint()
  195.         end
  196.       end
  197.       return self
  198.     end
  199.   end
  200.  
  201.   if type(group.Enable) ~= "function" then
  202.     group.Enable = function(self)
  203.       for index, element in pairs(self.Elements) do
  204.         if type(element) == "table" and type(element.Enable) == "function" then
  205.           element:Enable()
  206.         end
  207.       end
  208.       self.Enabled = true
  209.       return self
  210.     end
  211.   end
  212.  
  213.   if type(group.Disable) ~= "function" then
  214.     group.Disable = function(self)
  215.       for index, element in pairs(self.Elements) do
  216.         if type(element) == "table" and type(element.Disable) == "function" then
  217.           element:Disable()
  218.         end
  219.       end
  220.       self.Enabled = false
  221.       return self
  222.     end
  223.   end
  224.  
  225.   if type(group.Destroy) ~= "function" then
  226.     group.Destroy = function(self)
  227.       for index, element in pairs(self.Elements) do
  228.         if type(element) == "table" and type(element.Destroy) == "function" then
  229.           element:Destroy()
  230.         end
  231.       end
  232.       self = nil
  233.     end
  234.   end
  235.  
  236.   group.Elements = elements
  237.   if type(group.Elements) ~= "table" then
  238.     group.Elements = {}
  239.   end
  240.   return group
  241. end
  242.  
  243. --~Group~--
  244.  
  245. gui.backend = {}
  246. -- Text --
  247. gui.backend.Text = {}
  248. local text = gui.backend.Text
  249.  
  250. function text:Paint()
  251.   gpu.setBackground(self.BackColor)
  252.   gpu.setForeground(self.TextColor)
  253.   if self.Width > 0 then
  254.     -- gpu.set(self.X + math.floor(self.Width / 2) - math.ceil(unicode.len(self.Text) / 2), self.Y, self.Text)
  255.     gpu.set(self.X + math.floor((self.Width - unicode.len(self.Text)) / 2), self.Y, self.Text)
  256.   else
  257.     gpu.set(self.X, self.Y, self.Text)
  258.   end
  259.   gpu.setBackground(0x000000)
  260.   gpu.setForeground(0xffffff)
  261.   return self
  262. end
  263.  
  264. function text:Create(x, y, width, text)
  265.   return gui.Create{
  266.     X = x,
  267.     Y = y,
  268.     Width = width or 0,
  269.     Paint = self.Paint,
  270.     Text = text,
  271.     BackColor = 0x000000,
  272.     TextColor = 0xffffff,
  273.   }
  274. end
  275.  
  276. -- Button --
  277. gui.backend.Button = {}
  278. local button = gui.backend.Button
  279.  
  280. function button:Paint(pressed)
  281.   gpu.setBackground(self.BackColor)
  282.   gpu.setForeground(self.TextColor)
  283.   gpu.fill(self.X, self.Y, self.Width, self.Height, " ")
  284.   gpu.set(self.X + math.floor(self.Width / 2) - math.ceil(unicode.len(self.Text) / 2), self.Y + math.floor(self.Height / 2), self.Text)
  285.   gpu.setBackground(0x000000)
  286.   gpu.setForeground(0xffffff)
  287.   return self
  288. end
  289.  
  290. function button:Create(x, y, width, height, text, onclick)
  291.   return gui.Create{
  292.     OnElementClick = onclick,
  293.     Paint = self.Paint,
  294.     IsClicked = gui.IsClicked,
  295.     Text = text,
  296.     X = x,
  297.     Y = y,
  298.     Width = width,
  299.     Height = height,
  300.     BackColor = 0x666666,
  301.     TextColor = 0xffffff,
  302.   }
  303. end
  304.  
  305. -- TextBox --
  306. gui.backend.TextBox = {}
  307. local textbox = gui.backend.TextBox
  308.  
  309. function textbox:Init()
  310.   self.Timer = event.timer(0.5, function()
  311.     if self.Enable and self.Focused then
  312.       self.Blink = not self.Blink
  313.       self:Paint()
  314.     end
  315.   end, math.huge)
  316.   table.insert(timers, self.Timer)
  317. end
  318.  
  319. function textbox:Destroy()
  320.   event.cancel(self.Timer)
  321. end
  322.  
  323. function textbox:OnClick(x, y)
  324.   self.Focused = false
  325.   self.Blink = false
  326.   self:Paint()
  327. end
  328.  
  329. function textbox:OnElementClick(x, y)
  330.   self.Focused = true
  331.   if self.Focused then
  332.     self.CursorPosition = math.min(math.max(1, x), unicode.len(self.Text) + 1)
  333.     self:Paint()
  334.   end
  335.   return self
  336. end
  337.  
  338. function textbox:OnKeyDown(key1, key2)
  339.   if key1 == 8 then -- BackSpace
  340.     if self.CursorPosition > 1 then
  341.       self.Text = unicode.sub(self.Text, 1, self.CursorPosition - 2) .. unicode.sub(self.Text, self.CursorPosition, unicode.len(self.Text))
  342.       self.CursorPosition = self.CursorPosition - 1
  343.     end
  344.   elseif key2 == 211 then -- Delete
  345.     if self.CursorPosition <= unicode.len(self.Text) then
  346.       self.Text = unicode.sub(self.Text, 1, self.CursorPosition - 1) .. unicode.sub(self.Text, self.CursorPosition + 1, unicode.len(self.Text))
  347.     end
  348.   elseif key2 == 199 then -- Home
  349.     self.CursorPosition = 1
  350.   elseif key2 == 207 then -- End
  351.     self.CursorPosition = unicode.len(self.Text) + 1
  352.   elseif key2 == 203 then -- Left
  353.     self.CursorPosition = math.max(self.CursorPosition - 1, 1)
  354.   elseif key2 == 205 then -- Right
  355.     self.CursorPosition = math.min(self.CursorPosition + 1, unicode.len(self.Text) + 1)
  356.   elseif key1 ~= 0 and (not self.AvailableChars or self.AvailableChars:find(unicode.char(key1))) then
  357.     self.Text = unicode.sub(self.Text, 1, self.CursorPosition - 1) .. unicode.char(key1) .. unicode.sub(self.Text, self.CursorPosition, unicode.len(self.Text))
  358.     self.CursorPosition = self.CursorPosition + 1
  359.   end
  360.   self:Paint()
  361. end
  362.  
  363. function textbox:Paint()
  364.   gpu.setBackground(self.BackColor)
  365.   gpu.setForeground(self.TextColor)
  366.   gpu.set(self.X, self.Y, string.rep(" ", self.Width))
  367.   gpu.set(self.X, self.Y, self.Text)
  368.   if self.Blink then
  369.     gpu.setBackground(self.TextColor)
  370.     gpu.setForeground(self.BackColor)
  371.     gpu.set(self.X + self.CursorPosition - 1, self.Y, self.CursorPosition <= #self.Text and unicode.sub(self.Text, self.CursorPosition, self.CursorPosition) or " ")
  372.   end
  373.  
  374.   gpu.setBackground(0x000000)
  375.   gpu.setForeground(0xffffff)
  376.   return self
  377. end
  378.  
  379. function textbox:Create(x, y, width, text, availableChars)
  380.  
  381.   return gui.Create{
  382.     Init = self.Init,
  383.     Destroy = self.Destroy,
  384.     OnClick = self.OnClick,
  385.     OnElementClick = self.OnElementClick,
  386.     OnKeyDown = self.OnKeyDown,
  387.     Paint = self.Paint,
  388.     IsClicked = gui.IsClicked,
  389.     Text = text,
  390.     AvailableChars = availableChars,
  391.     CursorPosition = 0,
  392.     BackColor = 0x333333,
  393.     TextColor  = 0xffffff,
  394.     X = x,
  395.     Y = y,
  396.     Width = width,
  397.     Height = 1,
  398.   }
  399. end
  400.  
  401. -- CheckBox --
  402.  
  403. gui.backend.CheckBox = {}
  404. local checkbox = gui.backend.CheckBox
  405.  
  406. function checkbox:Paint()
  407.   gpu.setBackground(self.BackColor)
  408.   gpu.setForeground(self.TextColor)
  409.  
  410.   local box = "[ ] "
  411.   if self.Checked then
  412.     box = "[X] "
  413.   end
  414.   gpu.set(self.X, self.Y, unicode.sub(box .. self.Text, 1, self.Width) .. string.rep(" ", self.Width - box:len() - self.Text:len()))
  415.  
  416.   gpu.setBackground(0x000000)
  417.   gpu.setForeground(0xffffff)
  418.   return self
  419. end
  420.  
  421. function checkbox:OnElementClick(x, y)
  422.   self.Checked = not self.Checked
  423.   self:Paint()
  424. end
  425.  
  426. function checkbox:Create(x, y, width, text, checked)
  427.   return gui.Create{
  428.     IsClicked = gui.IsClicked,
  429.     OnElementClick = self.OnElementClick,
  430.     Paint = self.Paint,
  431.     X = x,
  432.     Y = y,
  433.     Width = width,
  434.     Text = text,
  435.     BackColor = 0x333333,
  436.     TextColor  = 0xffffff,
  437.     Checked = checked or false,
  438.   }
  439. end
  440.  
  441. -- RadioButton --
  442.  
  443. gui.backend.RadioButton = {}
  444. local radiobutton = gui.backend.RadioButton
  445.  
  446. function radiobutton:Paint()
  447.   gpu.setBackground(self.BackColor)
  448.   gpu.setForeground(self.TextColor)
  449.  
  450.   local box = "( ) "
  451.   if self.Checked then
  452.     box = "(X) "
  453.   end
  454.   gpu.set(self.X, self.Y, unicode.sub(box .. self.Text, 1, self.Width) .. string.rep(" ", self.Width - box:len() - self.Text:len()))
  455.  
  456.   gpu.setBackground(0x000000)
  457.   gpu.setForeground(0xffffff)
  458.   return self
  459. end
  460.  
  461. function radiobutton:OnAnotherChecked()
  462.   self.Checked = false
  463. end
  464.  
  465. function radiobutton:OnElementClick(x, y)
  466.   self.Checked = true
  467.   if type(self.Parent) == "table" then
  468.     self.Parent:OnChecked(self.Name)
  469.   else
  470.     self:Paint()
  471.   end
  472. end
  473.  
  474. function radiobutton:Create(x, y, width, text)
  475.   return gui.Create{
  476.     IsClicked = gui.IsClicked,
  477.     OnElementClick = self.OnElementClick,
  478.     OnAnotherChecked = self.OnAnotherChecked,
  479.     Paint = self.Paint,
  480.     X = x,
  481.     Y = y,
  482.     Width = width,
  483.     Text = text,
  484.     BackColor = 0x333333,
  485.     TextColor  = 0xffffff,
  486.     Checked = true,
  487.   }
  488. end
  489.  
  490. -- RadioGroup --
  491.  
  492. gui.backend.RadioGroup = {}
  493. local radiogroup = gui.backend.RadioGroup
  494.  
  495. function radiogroup:Init()
  496.   if self.Checked == nil then
  497.     self.Checked = next(self.Elements)
  498.   end
  499.   for index, element in pairs(self.Elements) do
  500.     element.Parent = self
  501.     element.Name = index
  502.     if self.Checked ~= index then
  503.       element.Checked = false
  504.     end
  505.     element:Init()
  506.   end
  507.   return self
  508. end
  509.  
  510. function radiogroup:OnChecked(name)
  511.   self.Checked = name
  512.   for index, element in pairs(self.Elements) do
  513.     if type(element) == "table" then
  514.       if index ~= name then
  515.         element:OnAnotherChecked()
  516.       end
  517.       element:Paint()
  518.     end
  519.   end
  520. end
  521.  
  522. function radiogroup:Create(elements, checked)
  523.   return gui.GroupCreate({
  524.     Init = self.Init,
  525.     OnChecked = self.OnChecked,
  526.     Checked = checked,
  527.   }, elements)
  528. end
  529.  
  530. -- MessageBox --
  531. --[[
  532.  
  533. function centerText(x, y, w, text)
  534.   gpu.set(x+math.floor(w/2-string.len(text)/2),y,text)
  535. end
  536.  
  537. function messageBox(title,text,color)
  538.   local x,y=(cfg.MapWidth-6)/((cfg.SuperQuality and 2)or 1),(math.floor(cfg.MapHeight/2)-3)/((cfg.SuperQuality and 2)or 1)
  539.   local len1,len2=string.len(title),string.len(text)
  540.   local len3=math.max(len1,len2)+2
  541.   gpu.setBackground(0xffffff)
  542.   gpu.fill(x,y,len3,2+3," ")
  543.   gpu.setForeground(color or 0xFF0000)
  544.   centerText(x,y+1,len3,title)
  545.   gpu.setForeground(0x000000)
  546.   centerText(x,y+3,len3,text)
  547.   gpu.setBackground(color or 0xFF0000)
  548.   gpu.setForeground(0xffffff)
  549.   gpu.fill(x,y+5,len3,3," ")
  550.   centerText(x,y+6,len3,"OK")
  551. end
  552.  
  553. --]]
  554.  
  555.  
  556. gui.backend.MessageBox = {}
  557. local msgbox = gui.backend.MessageBox
  558.  
  559. function msgbox:Init()
  560.   local widthScreen, heightScreen = gpu.getResolution()
  561.   self.Width = math.max(self.Width, unicode.len(self.Title) + 2, unicode.len(self.Text) + 2)
  562.   self.X = math.floor((widthScreen - self.Width) / 2) + 1
  563.   self.Y = math.floor((heightScreen - self.Height) / 2) + 1
  564.   self.Elements = gui.GroupCreate(nil,
  565.   {
  566.     Title = gui.backend.Text:Create(self.X, self.Y + 1, self.Width, self.Title):Modify{TextColor = self.TitleColor, BackColor = self.BackColor},
  567.     Text = gui.backend.Text:Create(self.X, self.Y + 3, self.Width, self.Text):Modify{TextColor = self.TextColor, BackColor = self.BackColor},
  568.     Button = gui.backend.Button:Create(self.X, self.Y + 5, self.Width, 3, "OK", function()
  569.       if type(self.ButtonHandle) == "function" then
  570.         self:ButtonHandle()
  571.       end
  572.       self:Destroy()
  573.     end):Modify{BackColor = self.ButtonColor},
  574.   }):Init():Enable()
  575.   return self
  576. end
  577.  
  578. function msgbox:Destroy()
  579.   self.Elements:Destroy()
  580.   self.Garbage = true
  581. end
  582.  
  583. function msgbox:Paint()
  584.   -- local x,y=(cfg.MapWidth-6)/((cfg.SuperQuality and 2)or 1),(math.floor(cfg.MapHeight/2)-3)/((cfg.SuperQuality and 2)or 1)
  585.   gpu.setBackground(self.BackColor)
  586.   gpu.fill(self.X, self.Y, self.Width, 5, " ")
  587.   self.Elements:Paint()
  588.   return self
  589.   -- local x, y = self.X or 0, self.Y or 0
  590.   -- if x == 0 or y == 0 then
  591.     -- if x == 0 then
  592.       -- x = math.floor((widthScreen - self.Width) / 2)
  593.     -- end
  594.     -- if y == 0 then
  595.       -- y = math.floor((heightScreen - self.Height) / 2)
  596.     -- end
  597.   -- end
  598.   -- local len1,len2=string.len(title),string.len(text)
  599.   -- local len3=math.max(len1,len2)+2
  600.   -- gpu.setBackground(0xffffff)
  601.   -- gpu.fill(x,y,len3,2+3," ")
  602.   -- gpu.setForeground(color or 0xFF0000)
  603.   -- centerText(x,y+1,len3,title)
  604.   -- gpu.setForeground(0x000000)
  605.   -- centerText(x,y+3,len3,text)
  606.   -- gpu.setBackground(color or 0xFF0000)
  607.   -- gpu.setForeground(0xffffff)
  608.   -- gpu.fill(x,y+5,len3,3," ")
  609.   -- centerText(x,y+6,len3,"OK")
  610.   -- return self
  611. end
  612.  
  613. function msgbox:Create(title, text, buttonText)
  614.   -- error("MSGBOX NOT READY!")
  615.   return gui.Create{
  616.     Init = self.Init,
  617.     Destroy = self.Destroy,
  618.     Paint = self.Paint,
  619.     X = 0,
  620.     Y = 0,
  621.     Width = 10,
  622.     Height = 8,
  623.     Title = title or "Error",
  624.     Text = text or "oops...",
  625.     ButtonText = buttonText or "OK",
  626.     TitleColor = 0xff0000,
  627.     TextColor = 0x000000,
  628.     BackColor = 0xffffff,
  629.     ButtonColor = 0xff0000,
  630.     -- ButtonHandle
  631.   }
  632. end
  633.  
  634. function gui.Error(text)
  635.   return gui.backend.MessageBox:Create(nil, text):Init():Paint()
  636. end
  637.  
  638. -- Form --
  639. gui.backend.Form = {}
  640. local form = gui.backend.Form
  641.  
  642. function form:Init()
  643.   for _, element in pairs(self.Elements) do
  644.     element.X = element.X + self.X - 1
  645.     element.Y = element.Y + self.Y - 1
  646.     element:Init()
  647.   end
  648.   return self
  649. end
  650.  
  651. function form:Paint(NoClear)
  652.   if not NoClear then
  653.     gpu.setBackground(0x000000)
  654.     gpu.setForeground(0xffffff)
  655.     width, height = gpu.getResolution()
  656.     gpu.fill(1, 1, width, height, " ")
  657.     pcall(gpu.setResolution, self.Width, self.Height)
  658.   end
  659.   for index, element in pairs(self.Elements) do
  660.     element:Paint()
  661.   end
  662.   return self
  663. end
  664.  
  665. function form:Show()
  666.   for index, element in pairs(self.Elements) do
  667.     element:Enable()
  668.   end
  669.   self.Enabled = true
  670.   return self
  671. end
  672.  
  673. function form:Hide(NoClear)
  674.   for _, element in pairs(self.Elements) do
  675.     element:Disable()
  676.   end
  677.   if not NoClear then
  678.     gpu.setResolution(gpu.maxResolution())
  679.     gpu.setBackground(0x000000)
  680.     gpu.setForeground(0xffffff)
  681.     width, height = gpu.getResolution()
  682.     gpu.fill(1, 1, width, height, " ")
  683.   end
  684.   self.Enabled = false
  685.   return self
  686. end
  687.  
  688. function form:Destroy()
  689.   self:Disable()
  690.   for _, element in pairs(self.Elements) do
  691.     if type(element) == "table" and type(element.Destroy) == "function" then
  692.       element:Destroy()
  693.     end
  694.   end
  695.   self.Garbage = true
  696. end
  697.  
  698. function form:Create(width, height, elements)
  699.   return gui.Create{
  700.     Enable = self.Show,
  701.     Disable = self.Hide,
  702.     Destroy = self.Destroy,
  703.     Paint = self.Paint,
  704.     Init = self.Init,
  705.     Width = width,
  706.     Height = height,
  707.     Elements = elements,
  708.   }
  709. end
  710.  
  711. --return gui --[[
  712. ---------------------------------------------------------
  713. gui.Init()
  714.  
  715. -- ScoresForm = gui.backend.Form:Create(20, 20,
  716.   -- {
  717.     -- gui.backend.TextBox:Create(1, 1, 10, "YourфText"),
  718.    
  719.     -- gui.backend.CheckBox:Create(1, 3, 20, "всё ок?"),
  720.    
  721.     -- TMP = gui.backend.RadioGroup:Create
  722.     -- {
  723.       -- qm = gui.backend.RadioButton:Create(1, 5, 20, "QWERTYмэн"),
  724.       -- q2 = gui.backend.RadioButton:Create(2, 6, 10, "Qмэн"),
  725.     -- },
  726.    
  727.     -- gui.backend.Button:Create(1, 18, 20, 3, "Back", function()
  728.       -- print(ScoresForm.Elements["TMP"].Checked) os.sleep(1)
  729.       -- ScoresForm:Disable(true)
  730.       -- MainForm:Enable():Paint()
  731.     -- end),
  732.   -- }
  733. -- ):Init()
  734.  
  735. -- SettingsForm = gui.backend.Form:Create(20, 17,
  736.   -- {
  737.     -- gui.backend.Text:Create(1, 1, 20, "Settings"),
  738.    
  739.     -- gui.backend.Text:Create(1, 3, nil, "Width"),
  740.     -- Width  = gui.backend.TextBox:Create(1, 4, 20, "0", "0123456789"),
  741.    
  742.     -- gui.backend.Text:Create(1, 6, nil, "Height"),
  743.     -- Height = gui.backend.TextBox:Create(1, 7, 20, "0", "0123456789"),
  744.    
  745.     -- SQ     = gui.backend.CheckBox:Create(1, 9, 20, "Super Quality"),
  746.    
  747.     -- gui.backend.Text:Create(1, 11, nil, "Map Generation Mode"),
  748.     -- Mode = gui.backend.RadioGroup:Create
  749.     -- {
  750.       -- gui.backend.RadioButton:Create(1, 12, 20, "Recursive"),
  751.       -- gui.backend.RadioButton:Create(1, 13, 20, "Hunt&Kill"),
  752.     -- },
  753.    
  754.     -- gui.backend.Button:Create(1, 15, 20, 3, "Back", function()
  755.       -- print(SettingsForm.Elements["Mode"].Checked) os.sleep(1)
  756.       -- print(SettingsForm.Elements["SQ"].Checked) os.sleep(1)
  757.       -- print(SettingsForm.Elements["Width"].Text) os.sleep(1)
  758.       -- SettingsForm:Disable(true)
  759.       -- MainForm:Enable():Paint()
  760.     -- end),
  761.   -- }
  762. -- ):Init()
  763.  
  764. -- MainForm = gui.backend.Form:Create(20, 15,
  765.   -- {
  766.     -- gui.backend.Button:Create(1, 1, 20, 3, "New Game", function() MainForm:Disable(true) quit = true end),
  767.     -- gui.backend.Button:Create(1, 5, 20, 3, "High Scores", function()
  768.       -- MainForm:Disable(true) --error("!")
  769.       -- ScoresForm:Enable():Paint()
  770.     -- end),
  771.     -- gui.backend.Button:Create(1, 9, 20, 3, "Settings", function()
  772.       -- MainForm:Disable(true)
  773.       -- SettingsForm:Enable():Paint()
  774.     -- end),
  775.     -- gui.backend.Button:Create(1, 13, 20, 3, "Exit", function() quit = true end),
  776.   -- }
  777. -- )
  778.  
  779. -- MainForm:Init():Enable():Paint()
  780. -- Err = gui.backend.MessageBox:Create():Init():Paint()
  781. -- gui.Error("GG!")
  782. gui.backend.MessageBox:Create("congratulation","You Win!"):Modify{ButtonHandle = function() print("HANDLED")  end}:Init():Paint()
  783.  
  784. eoe = event.onError
  785. event.onError = function(...)
  786.   quit = true
  787.   print("event error") os.sleep(1)
  788.   return eoe(...)
  789. end
  790.  
  791. quit = false
  792. pcall(function()
  793.   while not quit do
  794.     event.pull()
  795.   end
  796. end)
  797.  
  798. event.onError = eoe
  799. -- print(SettingsForm.Elements["Width"].Text, SettingsForm.Elements["Height"].Text) os.sleep(1)
  800.  
  801. gui.Destroy()
  802. --]]
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement