SHOW:
|
|
- or go back to the newest paste.
| 1 | --Look throughout the code for comments like this. They explain what to do to change things. | |
| 2 | ||
| 3 | --What side the monitor will be on (change this if needed) | |
| 4 | side = "right" | |
| 5 | args = {...}
| |
| 6 | rednet.open("top")
| |
| 7 | message = args[1] | |
| 8 | ||
| 9 | ||
| 10 | m = peripheral.wrap(side) | |
| 11 | ||
| 12 | ||
| 13 | --button on/off color | |
| 14 | bactive = colors.cyan | |
| 15 | binactive=colors.gray | |
| 16 | --text on/off color | |
| 17 | tactive=colors.white | |
| 18 | tinactive=colors.black | |
| 19 | --Background color | |
| 20 | bgcolor = colors.black | |
| 21 | ||
| 22 | ||
| 23 | buttons = {}
| |
| 24 | ||
| 25 | ||
| 26 | ||
| 27 | function newButton(id,xmin,xmax,ymin,ymax,text,func) | |
| 28 | buttons[id] = {}
| |
| 29 | buttons[id]["xmin"] = xmin | |
| 30 | buttons[id]["xmax"] = xmax | |
| 31 | buttons[id]["ymin"] = ymin | |
| 32 | buttons[id]["ymax"] = ymax | |
| 33 | buttons[id]["active"] = false | |
| 34 | buttons[id]["text"] = text | |
| 35 | buttons[id]["func"] = func | |
| 36 | ||
| 37 | end | |
| 38 | --------------------------------------------------------------------------------- | |
| 39 | function printButton(id) | |
| 40 | ymin = buttons[id]["ymin"] | |
| 41 | ymax = buttons[id]["ymax"] | |
| 42 | xmin = buttons[id]["xmin"] | |
| 43 | xmax = buttons[id]["xmax"] | |
| 44 | text = buttons[id]["text"] | |
| 45 | ia = buttons[id]["active"] | |
| 46 | ||
| 47 | ||
| 48 | ||
| 49 | width = xmax - xmin | |
| 50 | height = ymax - ymin | |
| 51 | ||
| 52 | if ia then m.setBackgroundColor(bactive) m.setTextColor(tactive) | |
| 53 | else m.setBackgroundColor(binactive) m.setTextColor(tinactive) end | |
| 54 | ||
| 55 | for j = ymin,ymax do | |
| 56 | m.setCursorPos(xmin,j) | |
| 57 | for i = xmin,xmax do | |
| 58 | ||
| 59 | m.write(" ")
| |
| 60 | ||
| 61 | end | |
| 62 | ||
| 63 | end | |
| 64 | ||
| 65 | ||
| 66 | m.setCursorPos(xmin + width / 2 - #text / 2 + 1,ymin + height / 2) | |
| 67 | ||
| 68 | m.write(text) | |
| 69 | m.setBackgroundColor(bgcolor) | |
| 70 | ||
| 71 | end | |
| 72 | ---------------------------------------------------------------------------------- | |
| 73 | function refreshButtons() | |
| 74 | for i = 1,#buttons do | |
| 75 | printButton(i) | |
| 76 | end | |
| 77 | end | |
| 78 | function checkxy( x,y ) | |
| 79 | for i = 1, #buttons do | |
| 80 | if y >= buttons[i]["ymin"] and y <= buttons[i]["ymax"] then | |
| 81 | if x >= buttons[i]["xmin"] and x <= buttons[i]["xmax"] then | |
| 82 | ||
| 83 | ||
| 84 | buttons[i]["active"] = not buttons[i]["active"] | |
| 85 | clicked = i | |
| 86 | if buttons[i]["func"] ~= nil then | |
| 87 | ||
| 88 | buttons[i]["func"]() | |
| 89 | ||
| 90 | ||
| 91 | end | |
| 92 | end | |
| 93 | end | |
| 94 | end | |
| 95 | end | |
| 96 | ||
| 97 | ||
| 98 | bool1 = false | |
| 99 | bool2 = false | |
| 100 | bool3 = false | |
| 101 | rs.setBundledOutput("back",0)
| |
| 102 | ||
| 103 | ||
| 104 | ||
| 105 | ||
| 106 | --White is pigman, Orange is witch, purple is wither skele (Bundled cable) | |
| 107 | ||
| 108 | ||
| 109 | ||
| 110 | ||
| 111 | ||
| 112 | ||
| 113 | function villager() | |
| 114 | current = rs.getBundledOutput("back")
| |
| 115 | bool1 = not bool1 | |
| 116 | if bool1 then | |
| 117 | rednet.broadcast("lon")
| |
| 118 | else | |
| 119 | rednet.broadcast("loff")
| |
| 120 | end | |
| 121 | end | |
| 122 | ||
| 123 | function znkkiller() | |
| 124 | current = rs.getBundledOutput("back")
| |
| 125 | bool2 = not bool2 | |
| 126 | if bool2 then | |
| 127 | rednet.broadcast("znkkilleron")
| |
| 128 | else | |
| 129 | rednet.broadcast("znkkilleroff")
| |
| 130 | end | |
| 131 | end | |
| 132 | ||
| 133 | function microsoftkiller() | |
| 134 | current = rs.getBundledOutput("back")
| |
| 135 | bool3 = not bool3 | |
| 136 | if bool3 then | |
| 137 | rednet.broadcast("microsoftkilleron")
| |
| 138 | else | |
| 139 | rednet.broadcast("microsoftkilleroff")
| |
| 140 | end | |
| 141 | end | |
| 142 | ||
| 143 | function ancientknight() | |
| 144 | current = rs.getBundledOutput("back")
| |
| 145 | bool3 = not bool3 | |
| 146 | if bool3 then | |
| 147 | - | newButton(1, 2,24,2,11,"Villager",villager) |
| 147 | + | rednet.broadcast("ancienton")
|
| 148 | else | |
| 149 | rednet.broadcast("ancientoff")
| |
| 150 | end | |
| 151 | end | |
| 152 | ||
| 153 | ||
| 154 | --You can add more buttons and also change the size of them. The format is startingx,startingy,endingx,endingy,text,function | |
| 155 | ||
| 156 | --The buttons | |
| 157 | newButton(1, 2,24,2,6,"Villager",villager) | |
| 158 | newButton(2, 26,48,2,6,"ZNK Killer",znkkiller) | |
| 159 | newButton(3, 26,48,7,11,"Microsoft Killer",microsoftkiller) | |
| 160 | newButton(4, 2,24,7,11,"Ancient Knight",ancientknight) | |
| 161 | ------------------------------------------------ | |
| 162 | ||
| 163 | ||
| 164 | ||
| 165 | m.clear() | |
| 166 | refreshButtons() | |
| 167 | ||
| 168 | ||
| 169 | --main loop | |
| 170 | while true do | |
| 171 | e,side,x,y = os.pullEvent("monitor_touch")
| |
| 172 | checkxy(x,y) | |
| 173 | ||
| 174 | refreshButtons() | |
| 175 | end | |
| 176 |