1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-06-23 00:44:09 +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 nRunningProcess = nil
local bShowMenu = false local bShowMenu = false
local bWindowsResized = false local bWindowsResized = false
local nScrollPos = 1
local bScrollRight = false
local function selectProcess( n ) local function selectProcess( n )
if nCurrentProcess ~= n then if nCurrentProcess ~= n then
@ -86,6 +88,9 @@ local function cullProcess( nProcess )
selectProcess( 1 ) selectProcess( 1 )
end end
end end
if nScrollPos ~= 1 then
nScrollPos = nScrollPos - 1
end
return true return true
end end
return false return false
@ -115,7 +120,15 @@ local function redrawMenu()
parentTerm.setCursorPos( 1, 1 ) parentTerm.setCursorPos( 1, 1 )
parentTerm.setBackgroundColor( menuOtherBgColor ) parentTerm.setBackgroundColor( menuOtherBgColor )
parentTerm.clearLine() 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 if n == nCurrentProcess then
parentTerm.setTextColor( menuMainTextColor ) parentTerm.setTextColor( menuMainTextColor )
parentTerm.setBackgroundColor( menuMainBgColor ) parentTerm.setBackgroundColor( menuMainBgColor )
@ -124,6 +137,16 @@ local function redrawMenu()
parentTerm.setBackgroundColor( menuOtherBgColor ) parentTerm.setBackgroundColor( menuOtherBgColor )
end end
parentTerm.write( " " .. tProcesses[n].sTitle .. " " ) 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 end
-- Put the cursor back where it should be -- 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] local button, x, y = tEventData[2], tEventData[3], tEventData[4]
if bShowMenu and y == 1 then if bShowMenu and y == 1 then
-- Switch process -- Switch process
local tabStart = 1 if x == 1 and nScrollPos ~= 1 then
for n=1,#tProcesses do nScrollPos = nScrollPos - 1
local tabEnd = tabStart + string.len( tProcesses[n].sTitle ) + 1 redrawMenu()
if x >= tabStart and x <= tabEnd then elseif bScrollRight and x == term.getSize() then
selectProcess( n ) nScrollPos = nScrollPos + 1
redrawMenu() redrawMenu()
break 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 end
tabStart = tabEnd + 1
end end
else else
-- Passthrough to current process -- 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 elseif sEvent == "mouse_drag" or sEvent == "mouse_up" or sEvent == "mouse_scroll" then
-- Other mouse event -- Other mouse event
local p1, x, y = tEventData[2], tEventData[3], tEventData[4] 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 -- Passthrough to current process
resumeProcess( nCurrentProcess, sEvent, p1, x, (bShowMenu and y-1) or y ) resumeProcess( nCurrentProcess, sEvent, p1, x, (bShowMenu and y-1) or y )
if cullProcess( nCurrentProcess ) then if cullProcess( nCurrentProcess ) then