Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TURTLE = 96;
- Data = {
- {
- name = "Plant",
- slot = 2,
- color = colors.cyan,
- },
- {
- name = "Factory",
- slot = 3,
- color = colors.lightGray,
- },
- {
- name = "MtFluff",
- slot = 4,
- color = colors.lightBlue,
- },
- {
- name = "Tree",
- slot = 5,
- color = colors.green,
- },
- };
- rednet.open("top");
- monitor = peripheral.wrap("back");
- monitor.clear();
- SelectedIndex = 0;
- function write(text, x, y, fc, bc)
- fc = fc or colors.white;
- bc = bc or colors.black;
- x = x or 1;
- y = y or 1;
- monitor.setCursorPos(x, y);
- monitor.setBackgroundColor(bc);
- monitor.setTextColor(fc);
- monitor.write(text);
- end
- function getCenteredOffset(text)
- local width = monitor.getSize();
- return math.floor((width - #text) / 2) + 1;
- end
- function getButtonOffset()
- local width, height = monitor.getSize();
- return (height - ((#Data * 4) - 1)) / 2;
- end
- function getHitButton(yPos)
- local yOffset = getButtonOffset();
- return math.max(1, math.floor((yPos - yOffset - 1) / 4) + 1);
- end
- function drawScreen()
- monitor.setBackgroundColor(colors.black);
- monitor.clear();
- local width, height = monitor.getSize();
- local yOffset = getButtonOffset();
- for i = 1, #Data do
- local button = Data[i];
- local y = ((i - 1) * 4) + 1 + yOffset;
- write(button.name, getCenteredOffset(button.name), y);
- -- draw button borders
- for j = 1, 2 do
- write(" ", 1, y + j, nil, colors.white);
- write(" ", width, y + j, nil, colors.white);
- -- highlight button
- if (i == SelectedIndex) then
- write(string.rep(" ", width - 2), 2, y + j, nil, button.color)
- end
- end
- end
- end
- while true do
- drawScreen();
- local event, side, x, y = os.pullEvent("monitor_touch");
- print(x, y);
- SelectedIndex = getHitButton(y);
- rednet.send(TURTLE, Data[SelectedIndex].slot);
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement