Skip to content

Commit

Permalink
Monitor control moved to bottom line
Browse files Browse the repository at this point in the history
As discussed in sandalle#34, clicking the lowest monitor line now switches
device class, and going past the last device of its class via arrow
click now also switches device class.

Also:
* Untangled a few things in printCentered(). It was overwriting and then
reprinting the monitor names, and the math was subtly off.
* added formatReadableSIUnit(number), to shorten the buffer numbers on
status screen, which were too big for display along the navigation
arrows.
  • Loading branch information
thetaphi committed Apr 8, 2015
1 parent 669e079 commit f9ae96c
Showing 1 changed file with 83 additions and 37 deletions.
120 changes: 83 additions & 37 deletions lolmer_bigreactor_monitor_prog.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ TODO:


-- Some global variables
local progVer = "0.3.17-ta"
local progVer = "0.3.17"
local progName = "EZ-NUKE"
local sideClick, xClick, yClick = nil, 0, 0
local loopTime = 2
Expand Down Expand Up @@ -222,6 +222,22 @@ function stringTrim(s)
return(string.gsub(s, "^%s*(.-)%s*$", "%1"))
end

-- Format number with [k,M,G,T,P,E] postfix or exponent, depending on how large it is
local function formatReadableSIUnit(num)
printLog("formatReadableSIUnit("..num..")", DEBUG)
num = tonumber(num)
if(num < 1000) then return tostring(num) end
local sizes = {"", "k", "M", "G", "T", "P", "E"}
local exponent = math.floor(math.log10(num))
local group = math.floor(exponent / 3)
if group > #sizes then
return string.format("%e", num)
else
local divisor = math.pow(10, (group - 1) * 3)
return string.format("%i%s", num / divisor, sizes[group])
end
end -- local function formatReadableSIUnit(num)

-- pretty printLog() a table
local function tprint (tbl, loglevel, indent)
if not loglevel then loglevel = DEBUG end
Expand Down Expand Up @@ -393,20 +409,16 @@ local function printCentered(printString, yPos, monitorIndex)
if yPos == 1 then
-- Add monitor name to first line
monitorNameLength = monitorNames[monitorIndex]:len()
width = width - monitorNameLength -- add a space

-- Leave room for "offline" and "online" on the right except for overall status display
if monitorAssignments[monitorNames[monitorIndex]].type ~= "Status" then
width = width - 7
end
end

monitor.setCursorPos(math.floor(width/2) - math.ceil(printString:len()/2) + monitorNameLength/2, yPos)
monitor.clearLine()
monitor.setCursorPos(monitorNameLength + math.ceil((1 + width - printString:len())/2), yPos)
monitor.write(printString)

monitor.setTextColor(colors.blue)
print{monitorNames[monitorIndex], 1, 1, monitorIndex}
monitor.setTextColor(colors.white)
end -- function printCentered(printString, yPos, monitorIndex)


Expand Down Expand Up @@ -608,28 +620,36 @@ UI.handlePossibleClick = function(self)
return
end

-- All the second line are belong to us
if (yClick == 2) then
self.monitorIndex = monitorData.index
local width, height = monitorList[self.monitorIndex].getSize()
self.monitorIndex = monitorData.index
local width, height = monitorList[self.monitorIndex].getSize()
-- All the last line are belong to us
if (yClick == height) then
if (monitorData.type == "Reactor") then
if (xClick == 1) then
self:selectPrevReactor()
elseif (xClick == width) then
self:selectNextReactor()
elseif (2 <= xClick and xClick <= width - 2) then
elseif (3 <= xClick and xClick <= width - 2) then
self:selectTurbine()
end
elseif (monitorData.type == "Turbine") then
if (xClick == 1) then
self:selectPrevTurbine()
elseif (xClick == width) then
self:selectNextTurbine()
elseif (2 <= xClick and xClick <= width - 2) then
elseif (3 <= xClick and xClick <= width - 2) then
self:selectStatus()
end
elseif (monitorData.type == "Status") then
self:selectReactor()
if (xClick == 1) then
self.turbineIndex = #turbineList
self:selectTurbine()
elseif (xClick == width) then
self.reactorIndex = 1
self:selectReactor()
elseif (3 <= xClick and xClick <= width - 2) then
self:selectReactor()
end
else
self:selectStatus()
end
Expand Down Expand Up @@ -671,19 +691,24 @@ UI.selectReactor = function(self)
end -- UI.selectReactor()

UI.selectPrevReactor = function(self)
self.reactorIndex = self.reactorIndex - 1
if self.reactorIndex < 1 then
if self.reactorIndex <= 1 then
self.reactorIndex = #reactorList
self:selectStatus()
else
self.reactorIndex = self.reactorIndex - 1
self:selectReactor()
end
self:selectReactor()
end -- UI.selectPrevReactor()

UI.selectNextReactor = function(self)
self.reactorIndex = self.reactorIndex + 1
if self.reactorIndex > #reactorList then
if self.reactorIndex >= #reactorList then
self.reactorIndex = 1
self.turbineIndex = 1
self:selectTurbine()
else
self.reactorIndex = self.reactorIndex + 1
self:selectReactor()
end
self:selectReactor()
end -- UI.selectNextReactor()


Expand All @@ -695,19 +720,24 @@ UI.selectTurbine = function(self)
end -- UI.selectTurbine()

UI.selectPrevTurbine = function(self)
self.turbineIndex = self.turbineIndex - 1
if self.turbineIndex < 1 then
if self.turbineIndex <= 1 then
self.turbineIndex = #turbineList
self.reactorIndex = #reactorList
self:selectReactor()
else
self.turbineIndex = self.turbineIndex - 1
self:selectTurbine()
end
self:selectTurbine()
end -- UI.selectPrevTurbine()

UI.selectNextTurbine = function(self)
self.turbineIndex = self.turbineIndex + 1
if self.turbineIndex > #turbineList then
if self.turbineIndex >= #turbineList then
self.turbineIndex = 1
self:selectStatus()
else
self.turbineIndex = self.turbineIndex + 1
self:selectTurbine()
end
self:selectTurbine()
end -- UI.selectNextTurbine()


Expand All @@ -721,6 +751,7 @@ end -- UI.selectStatus()
UI.selectDebug = function(self)
monitorAssignments[monitorNames[self.monitorIndex]] = {type="Debug", index=self.monitorIndex}
saveMonitorAssignments()
monitorList[self.monitorIndex].clear()
local messageText = "Selected debug output for display on "..monitorNames[self.monitorIndex]
self:logChange(messageText)
end -- UI.selectDebug()
Expand Down Expand Up @@ -1674,9 +1705,9 @@ local function displayReactorBars(barParams)
end

drawLine(6, monitorIndex)
monitor.setCursorPos(1, 2)
monitor.setCursorPos(1, height)
monitor.write("< ")
monitor.setCursorPos(width-1, 2)
monitor.setCursorPos(width-1, height)
monitor.write(" >")

-- Draw some text
Expand Down Expand Up @@ -1768,6 +1799,13 @@ local function displayReactorBars(barParams)
monitor.setTextColor(colors.blue)
printCentered(_G[reactorNames[reactorIndex]]["ReactorOptions"]["reactorName"],12,monitorIndex)
monitor.setTextColor(colors.white)

-- monitor switch controls
monitor.setCursorPos(1, height)
monitor.write("<")
monitor.setCursorPos(width, height)
monitor.write(">")

end -- function displayReactorBars(barParams)


Expand Down Expand Up @@ -1931,7 +1969,15 @@ local function displayAllStatus(monitorIndex)
end -- if #turbineList then

printCentered("Fuel: "..round(totalReactorFuelConsumed,3).." mB/t", 11, monitorIndex)
print{"Buffer: "..math.ceil(totalEnergy,3).."/"..totalMaxEnergyStored.." RF", 2, 12, monitorIndex}
printCentered("Buffer: "..formatReadableSIUnit(math.ceil(totalEnergy)).."/"..formatReadableSIUnit(totalMaxEnergyStored).." RF", 12, monitorIndex)

-- monitor switch controls
local width, height = monitor.getSize()
monitor.setCursorPos(1, height)
monitor.write("<")
monitor.setCursorPos(width, height)
monitor.write(">")

end -- function displayAllStatus()


Expand Down Expand Up @@ -1975,9 +2021,9 @@ local function displayTurbineBars(turbineIndex, monitorIndex)
end

drawLine(7,monitorIndex)
monitor.setCursorPos(1, 2)
monitor.setCursorPos(1, height)
monitor.write("< ")
monitor.setCursorPos(width-1, 2)
monitor.setCursorPos(width-1, height)
monitor.write(" >")

local turbineFlowRate = tonumber(_G[turbineNames[turbineIndex]]["TurbineOptions"]["LastFlow"])
Expand Down Expand Up @@ -2057,6 +2103,12 @@ local function displayTurbineBars(turbineIndex, monitorIndex)
printCentered(_G[turbineNames[turbineIndex]]["TurbineOptions"]["turbineName"],12,monitorIndex)
monitor.setTextColor(colors.white)

-- monitor switch controls
monitor.setCursorPos(1, height)
monitor.write("<")
monitor.setCursorPos(width, height)
monitor.write(">")

-- Need equation to figure out rotor efficiency and display
end -- function displayTurbineBars(statusParams)

Expand Down Expand Up @@ -2261,8 +2313,6 @@ local function helpText()
-- these keys are actually defined in eventHandler(), check there
return [[Keyboard commands:
m Select next monitor
c Make selected monitor display next reactor
t Make selected monitor display next turbine
s Make selected monitor display global status
x Make selected monitor display debug information
Expand Down Expand Up @@ -2496,10 +2546,6 @@ eventHandler = function(event, arg1, arg2, arg3)
write("debugMode "..modeText.."\n")
elseif ch == "m" then
UI:selectNextMonitor()
elseif ch == "c" then
UI:selectNextReactor()
elseif ch == "t" then
UI:selectNextTurbine()
elseif ch == "s" then
UI:selectStatus()
elseif ch == "x" then
Expand Down

0 comments on commit f9ae96c

Please sign in to comment.