SHOW:
|
|
- or go back to the newest paste.
| 1 | - | --Desktop |
| 1 | + | function test() |
| 2 | - | slc = 0 |
| 2 | + | --Main |
| 3 | - | tBarC = 8 |
| 3 | + | --====================== |
| 4 | - | tBartC = 1 |
| 4 | + | menu1 = Menu("menu1")
|
| 5 | - | backColor = 1 |
| 5 | + | |
| 6 | - | term.setBackgroundColor(backColor) |
| 6 | + | --print(menu1.getDeltaX()) --> 1 |
| 7 | - | term.clear() |
| 7 | + | --print(type(menu1.deltaX)) --> nil |
| 8 | menu1.addItem("A")
| |
| 9 | menu1.addItem("B")
| |
| 10 | - | function titlebar() |
| 10 | + | print(menu1.getItem(0).test()) |
| 11 | - | term.setCursorPos(1,1) |
| 11 | + | print(menu1.getItem(0).getTitle()) |
| 12 | - | term.setBackgroundColor(tBarC) |
| 12 | + | |
| 13 | - | term.setTextColor(tBartC) |
| 13 | + | --print(menu1.getItem(1).getName()) |
| 14 | - | term.clearLine() |
| 14 | + | menu1.printItems() |
| 15 | - | term.setCursorPos(3, 1) |
| 15 | + | menu1.addItem("C")
|
| 16 | - | print("[Begin]")
|
| 16 | + | menu1.printItems() |
| 17 | print(menu1.getSize()) | |
| 18 | menu1.removeItem(1) | |
| 19 | - | function drawDesktop() |
| 19 | + | menu1.printItems() |
| 20 | - | --bground = paintutils.loadImage(".background")
|
| 20 | + | print(menu1.getSize()) |
| 21 | - | --paintutils.drawImage(bground, 1, 1) |
| 21 | + | |
| 22 | - | titlebar() |
| 22 | + | menu1.getItem(1).setGo("print(\"this actually ran\")")
|
| 23 | menu1.getItem(1).go() | |
| 24 | print(menu1.getItem(0).getTitle()) | |
| 25 | - | drawDesktop() |
| 25 | + | |
| 26 | ||
| 27 | - | while true do |
| 27 | + | function Menu(name) |
| 28 | - | local event, X, Y = os.pullEventRaw() |
| 28 | + | |
| 29 | - | if slc == 0 then |
| 29 | + | --Class Variables |
| 30 | - | if event == "mouse_click" then |
| 30 | + | --====================== |
| 31 | - | if X >= 2 and X <= 8 and Y == 1 and button == 1 then |
| 31 | + | local deltaX = 1 |
| 32 | - | term.clear() |
| 32 | + | local self = {}
|
| 33 | - | else |
| 33 | + | local items = {}
|
| 34 | - | drawDesktop() |
| 34 | + | local size = 0 |
| 35 | - | end |
| 35 | + | local name = name |
| 36 | - | end |
| 36 | + | |
| 37 | - | end |
| 37 | + | for i=0, 1 do |
| 38 | - | end |
| 38 | + | items[i] = 0 |
| 39 | end | |
| 40 | ||
| 41 | -- Class Functions | |
| 42 | --====================== | |
| 43 | --getName | |
| 44 | self.getName = function() | |
| 45 | return name | |
| 46 | end | |
| 47 | ||
| 48 | --getDeltaX | |
| 49 | self.getDeltaX = function() | |
| 50 | return deltaX | |
| 51 | end | |
| 52 | ||
| 53 | --getSize | |
| 54 | self.getSize = function() | |
| 55 | return size | |
| 56 | end | |
| 57 | ||
| 58 | --addItem | |
| 59 | self.addItem = function(title) | |
| 60 | menuItem = MenuItem(title) | |
| 61 | items[size] = menuItem | |
| 62 | size = size+1 | |
| 63 | end | |
| 64 | ||
| 65 | --removeItem(idx) | |
| 66 | self.removeItem = function(idx) | |
| 67 | item = items[idx] | |
| 68 | table.remove(items,idx) | |
| 69 | size= size-1 | |
| 70 | return item | |
| 71 | end | |
| 72 | ||
| 73 | --getItem(idx) | |
| 74 | self.getItem = function(idx) | |
| 75 | return items[idx] | |
| 76 | end | |
| 77 | ||
| 78 | --printItems | |
| 79 | self.printItems = function() | |
| 80 | for i=0, size-1 do | |
| 81 | -- print("in printing loop")
| |
| 82 | print(items[i].getTitle()) | |
| 83 | end | |
| 84 | end | |
| 85 | ||
| 86 | --Inner class MenuItem | |
| 87 | --====================== | |
| 88 | function MenuItem(title) | |
| 89 | local str = nil | |
| 90 | local title = title | |
| 91 | local child = {}
| |
| 92 | ||
| 93 | --go | |
| 94 | child.go = function() | |
| 95 | if str == nil then | |
| 96 | print("No go-function assigned to MenuItem")
| |
| 97 | else | |
| 98 | assert(loadstring("return "..str.."(...)"))
| |
| 99 | end | |
| 100 | end | |
| 101 | ||
| 102 | --setGo | |
| 103 | child.setGo = function(inn) | |
| 104 | str = inn | |
| 105 | end | |
| 106 | ||
| 107 | --getName | |
| 108 | child.getTitle = function() | |
| 109 | return title | |
| 110 | end | |
| 111 | ||
| 112 | child.test = function() | |
| 113 | return title | |
| 114 | end | |
| 115 | ||
| 116 | return child | |
| 117 | end | |
| 118 | ||
| 119 | ||
| 120 | return self | |
| 121 | end | |
| 122 | ||
| 123 | test() |