1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-25 22:53:22 +00:00

Make Multishell Scrollable (#123)

You can now Scroll through the program list, if the list bigger than your
screen.
This commit is contained in:
Wilma456 (Jakob0815) 2019-02-21 17:00:13 +01:00 committed by SquidDev
parent 6bd11a5e4a
commit 4145914024

View File

@ -8,6 +8,8 @@ local nCurrentProcess = nil
local nRunningProcess = nil
local bShowMenu = false
local bWindowsResized = false
local nScrollPos = 1
local bScrollRight = false
local function selectProcess( n )
if nCurrentProcess ~= n then
@ -86,6 +88,9 @@ local function cullProcess( nProcess )
selectProcess( 1 )
end
end
if nScrollPos ~= 1 then
nScrollPos = nScrollPos - 1
end
return true
end
return false
@ -115,7 +120,15 @@ local function redrawMenu()
parentTerm.setCursorPos( 1, 1 )
parentTerm.setBackgroundColor( menuOtherBgColor )
parentTerm.clearLine()
for n=1,#tProcesses do
local nCharCount = 0
local nSize = parentTerm.getSize()
if nScrollPos ~= 1 then
parentTerm.setTextColor( menuOtherTextColor )
parentTerm.setBackgroundColor( menuOtherBgColor )
parentTerm.write( "<" )
nCharCount = 1
end
for n=nScrollPos,#tProcesses do
if n == nCurrentProcess then
parentTerm.setTextColor( menuMainTextColor )
parentTerm.setBackgroundColor( menuMainBgColor )
@ -124,6 +137,16 @@ local function redrawMenu()
parentTerm.setBackgroundColor( menuOtherBgColor )
end
parentTerm.write( " " .. tProcesses[n].sTitle .. " " )
nCharCount = nCharCount + #tProcesses[n].sTitle + 2
end
if nCharCount > nSize then
parentTerm.setTextColor( menuOtherTextColor )
parentTerm.setBackgroundColor( menuOtherBgColor )
parentTerm.setCursorPos( nSize, 1 )
parentTerm.write( ">" )
bScrollRight = true
else
bScrollRight = false
end
-- Put the cursor back where it should be
@ -262,15 +285,26 @@ while #tProcesses > 0 do
local button, x, y = tEventData[2], tEventData[3], tEventData[4]
if bShowMenu and y == 1 then
-- Switch process
local tabStart = 1
for n=1,#tProcesses do
local tabEnd = tabStart + string.len( tProcesses[n].sTitle ) + 1
if x >= tabStart and x <= tabEnd then
selectProcess( n )
redrawMenu()
break
if x == 1 and nScrollPos ~= 1 then
nScrollPos = nScrollPos - 1
redrawMenu()
elseif bScrollRight and x == term.getSize() then
nScrollPos = nScrollPos + 1
redrawMenu()
else
local tabStart = 1
if nScrollPos ~= 1 then
tabStart = 2
end
for n=nScrollPos,#tProcesses do
local tabEnd = tabStart + string.len( tProcesses[n].sTitle ) + 1
if x >= tabStart and x <= tabEnd then
selectProcess( n )
redrawMenu()
break
end
tabStart = tabEnd + 1
end
tabStart = tabEnd + 1
end
else
-- Passthrough to current process
@ -284,7 +318,15 @@ while #tProcesses > 0 do
elseif sEvent == "mouse_drag" or sEvent == "mouse_up" or sEvent == "mouse_scroll" then
-- Other mouse event
local p1, x, y = tEventData[2], tEventData[3], tEventData[4]
if not (bShowMenu and y == 1) then
if bShowMenu and sEvent == "mouse_scroll" and y == 1 then
if p1 == -1 and nScrollPos ~= 1 then
nScrollPos = nScrollPos - 1
redrawMenu()
elseif bScrollRight and p1 == 1 then
nScrollPos = nScrollPos + 1
redrawMenu()
end
elseif not (bShowMenu and y == 1) then
-- Passthrough to current process
resumeProcess( nCurrentProcess, sEvent, p1, x, (bShowMenu and y-1) or y )
if cullProcess( nCurrentProcess ) then