Posted 06 February 2014 - 04:50 PM
Greetings, all :)/>
I've run into a brick wall with my ccDHD program and have exhausted my remaining brain cells trying to work out a solution. The program displays 24 gates/page in 4 columns of 6 gates. This works fine if I 'hard code' for each page. That's clearly no good as even supporting five pages is silly (as show below).
Here is the specific page formatting code:
I'm looking for a way to properly format the pages without having to hardcode a specific set of values for every page. I've managed to get some code working for the first column, but it breaks at page 5. My algorithm-fu is not strong. Any help would be greatly appreciated :)/>
EDIT: I figured out a solution - the code is below:
I've run into a brick wall with my ccDHD program and have exhausted my remaining brain cells trying to work out a solution. The program displays 24 gates/page in 4 columns of 6 gates. This works fine if I 'hard code' for each page. That's clearly no good as even supporting five pages is silly (as show below).
Here is the specific page formatting code:
Spoiler
local function drawDialUI() -- Gate Address Book
local bColor = black
local xPos = 2
local yPos = 4
local j = ((pageNum - 1) * 23) + pageNum
local k = ((pageNum - 1) * 23)
local l = ((pageNum - 1) * 24)
local m = ((pageNum - 1) * 12)
term.setBackgroundColor(bColor)
for i = j,#allGates,1 do -- for i = j,j+23,1 do (fixed to 24 gates per page, but avoids need for 'break')
if (i > 0 and i < 7) or (i > 24 and i < 31) or (i > 48 and i < 55) or (i > 72 and i < 79) or (i > 96 and i < 103) then -- Column 1
xPos = 2
yPos = 4
elseif (i > 6 and i < 13) or (i > 30 and i < 37) or (i > 54 and i < 61) or (i > 78 and i < 85) or (i > 102 and i < 109) then -- Column 2
xPos = 12
yPos = -8
elseif (i > 12 and i < 19) or (i > 36 and i < 43) or (i > 60 and i < 67) or (i > 84 and i < 91) or (i > 108 and i < 115) then -- Column 3
xPos = 22
yPos = -20
elseif (i > 18 and i < 25) or (i > 42 and i < 49) or (i > 66 and i < 73) or (i > 90 and i < 97) or (i > 114 and i < 121) then -- Column 4
xPos = 32
yPos = -32
end
term.setCursorPos(xPos,yPos + ((i - ((pageNum - 1) * 24)) * 2))
term.setTextColor(white)
bColor = assignColor(i)
term.setBackgroundColor(bColor)
if dialAddress == allGates[i].addr then
term.setTextColor(black)
end
if i > (pageNum * 24) or i > #allGates then
break
else
if #allGates[i].addr == 7 then
term.write(" " .. allGates[i].addr .. " ")
elseif #allGates[i].addr == 8 then
term.write(" " .. allGates[i].addr)
elseif #allGates[i].addr == 9 then
term.write(allGates[i].addr)
elseif #allGates[i].addr < 7 then
term.write("*" .. allGates[i].addr .. "*") -- * = address is less than 7 characters
else
term.write("ERROR #10") -- ERROR #10 = address is 10 or more characters
end
end
end
term.setBackgroundColor(black)
end
I'm looking for a way to properly format the pages without having to hardcode a specific set of values for every page. I've managed to get some code working for the first column, but it breaks at page 5. My algorithm-fu is not strong. Any help would be greatly appreciated :)/>
EDIT: I figured out a solution - the code is below:
Spoiler
local function drawDialUI() -- Gate Address Book
local bColor = black
local xPos = 2
local yPos = 4
local j = ((pageNum - 1) * 23) + pageNum
local k = ((pageNum - 1) * 23)
local l = ((pageNum - 1) * 24)
term.setBackgroundColor(bColor)
for i = j,#allGates,1 do -- for i = j,j+23,1 do (fixed to 24 gates per page, but avoids need for 'break')
if i > l and i < l + 7 then -- Column 1
xPos = 2
yPos = 4
elseif i > l + 6 and i < l + 13 then -- Column 2
xPos = 12
yPos = -8
elseif i > l + 12 and i < l + 19 then -- Column 3
xPos = 22
yPos = -20
elseif i > l + 18 and i < l + 25 then -- Column 4
xPos = 32
yPos = -32
end
term.setCursorPos(xPos,yPos + ((i - ((pageNum - 1) * 24)) * 2))
term.setTextColor(white)
bColor = assignColor(i)
term.setBackgroundColor(bColor)
if dialAddress == allGates[i].addr then
term.setTextColor(black)
end
if i > (pageNum * 24) or i > #allGates then
break
else
if #allGates[i].addr == 7 then
term.write(" " .. allGates[i].addr .. " ")
elseif #allGates[i].addr == 8 then
term.write(" " .. allGates[i].addr)
elseif #allGates[i].addr == 9 then
term.write(allGates[i].addr)
elseif #allGates[i].addr < 7 then
term.write("*" .. allGates[i].addr .. "*") -- * = address is less than 7 characters
else
term.write("ERROR #10") -- ERROR #10 = address is 10 or more characters
end
end
end
term.setBackgroundColor(black)
end
[size=4]