loadfile("luaScripts/common.inc")( ); askText = "Experimental! Keep the top left corner clear!\nCascade stack the windows. Ensure all are the same size OR that the largest windows are at the bottom of the cascade.\nJUST FOR RANNO." myInstructions = {}; myActions = {}; screenChopX = 0; screenChopY = 0; masterTimer = 0; function doit() askForWindow(askText); windowManager("Window Manager", nil, true, true); myActions = {}; addActions(myActions, "Make a Cut Stone"); addInstructions(myInstructions, "Rock Saw", myActions, 5000, 180); myActions = {}; addActions(myActions, "Making"); addInstructions(myInstructions, "Rock Saw", myActions, 99999999999999, 900); myActions = {}; addActions(myActions, "Take"); addActions(myActions, "Everything"); addInstructions(myInstructions, "Rock Saw", myActions, 9999, 300); targetCorners={TOP_RIGHT, BOTTOM_LEFT}; -- REVISION - let's try to cascade instead --~ currentPositions = bubbleSortXY(currentPositions,j); --now cascade them in reverse order -- cascade manually for now --now find the bottom left corners. newPos = {}; srReadScreen(); getCascade("This.png"); --~ error ("Done"); while 1 do masterTimer = 30 - (#currentPositions); --~ currentPositions = bubbleSortXY(currentPositions,j); for i=#newPos,1,-1 do thisPosition = newPos[i]; --Activate Window safeClick(newPos[i][0],newPos[i][3]); lsSleep(click_delay); srReadScreen(); bounds = srGetWindowBorders(sourceX, sourceY); screenChopX=(bounds[2]); screenChopY=(bounds[3]); searchWindow(myInstructions,regionToBox(newPos[i])); clickAllImages("OK-popup.png",10,5); end for i=1,#newPos do safeClick(newPos[i][0],newPos[i][3]); lsSleep(click_delay); end sleepWithStatus(teppyTime(masterTimer),"Waiting for next cycle."); clickAllImages("OK-popup.png",10,5); end end function getCascade(windowText) newPos={}; currentPositions = findAllImages(windowText); for i=#currentPositions,1,-1 do --now get bounds from bottom to top safeClick(currentPositions[i][0],currentPositions[i][1]); lsSleep(click_delay); srReadScreen(); newPos[i]=srGetWindowBorders(currentPositions[i][0]+15,currentPositions[i][1]+5); end for i=1,#newPos do safeClick(newPos[i][0],newPos[i][3]); lsSleep(click_delay); end end function addInstructions(tInstructions, windowName, tActions, cycles, timer) local myTimer = 60 if timer then myTimer = timer; end local tRecord = { ["Window"] = windowName, ["Actions"] = tActions, ["CyclesLeft"] = cycles, ["CyclesDone"] = 0, ["Timer"] = myTimer }; tInstructions[#tInstructions + 1] = tRecord; return; end function addActions(tActions, actionText) tActions[#tActions + 1] = actionText; return; end function actActions(tActions,myBox) myAction = {} for i =1, #tActions do -- find action if i==1 then --first time through the action should be visible myAction = findText(tActions[i],myBox); else --subsequent actions require a menu to pop up, give it time myAction = waitForText(tActions[i],1000,"Looking for: " .. tActions[i]); end if myAction then --found the text somewhere if myAction[0] 0 then --there are still instructions left to execute. do so. if j>1 then if tInstructions[j].Window==tInstructions[j-1].Window then --leave myText as true else myText = waitForText(tInstructions[j].Window,500,#tInstructions .. " instructions\n" .. "Window: " .. tInstructions[j]["Window"] .. "\nj=" .. j); end else myText = waitForText(tInstructions[j].Window,500,#tInstructions .. " instructions\n" .. "Window: " .. tInstructions[j]["Window"] .. "\nj=" .. j); end if myText then -- found the text somewhere --~ if myText[0] array start to end for j = 2, #tTable do flip, flop = tTable[j], tTable[j-1] if iIndex ==1 then -- just sort by table elements if flip[0] < flop[0] then -->switch --~ temp = tTable[j-1] tTable[j-1], tTable[j] = tTable[j], tTable[j-1] --~ tTable[j-1] = tTable[j] --~ tTable[j] = temp end else -- sort by specific index if flip[1] < flop[1] then -->switch --~ temp = tTable[j-1] tTable[j-1], tTable[j] = tTable[j], tTable[j-1] --~ tTable[j-1] = tTable[j] --~ tTable[j] = temp end end end end return tTable end function stashAllWindows2(corner) if not corner then error("Incorrect number of arguments for stashAllWindows()"); end local top = (corner == TOP_LEFT or corner == TOP_RIGHT); local left = (corner == TOP_LEFT or corner == BOTTOM_LEFT); local screen = srGetWindowSize(); local done = false; local stashes = {}; srReadScreen(); local anchors = findAllImages("ThisIs.png"); local a2 = findAllImages("IsMaking.png"); --~ sleepWithStatus(2000, #anchors .. " anchors.\n" .. #a2 .. " secondaries."); for j=0,#a2 do if a2[j] then anchors[#anchors+j]=deepcopy(a2[j]); end end --~ sleepWithStatus(2000, #anchors .. " anchors.\n" .. #a2 .. " secondaries."); while not done do done = true; for i=1,#anchors do if not wasStashed(anchors[i], stashes) then safeClick(anchors[i][0], anchors[i][1]); lsSleep(click_delay); local lastPos = stashWindow(anchors[i][0], anchors[i][1], corner); stashes[#stashes + 1] = lastPos; done = false; end end lsSleep(tick_delay); srReadScreen(); anchors = findAllImages("ThisIs.png"); a2 = findAllImages("IsMaking.png"); for j=0,#a2 do if a2[j] then anchors[#anchors+j]=deepcopy(a2[j]); end end statusScreen("Stashing Windows"); end --~ sleepWithStatus(5000,"Done." .. #anchors .. " windows."); return stashes; end function newCascade(cascade, waterGap, windowPositions) local screen = srGetWindowSize(); local bottomRightX = screen[0] - 20; local bottomRightY = screen[1] - 20; screen[0] = screen[0] - lsGetWindowSize()[0]; local currentX = 0; local currentY = 0; if waterGap then currentX = 10; currentY = 50; end local lastX = 0; local lastY = 0; local xMax = 0; local yMax = 0; srReadScreen(); local wLocs = {}; local window = findImageInWindow("ThisIs.png", bottomRightX, bottomRightY); while window and (window[0] > lastX or window[1] > lastY) do safeClick(window[0], window[1]); lsSleep(click_delay); srReadScreen(); local bounds = srGetWindowBorders(window[0], window[1]); local width = bounds[2] - bounds[0]; local height = bounds[3] - bounds[1]; if cascade then if currentY + height >= screen[1] then currentX = currentX + xMax; currentY = 0; xMax = 0; end if currentX + width >= screen[0] then error("Cannot arrange these windows into a cascade."); end else if currentX + width >= screen[0] then currentX = 0; currentY = currentY + yMax; yMax = 0; end if currentY + height >= screen[1] then error("Cannot arrange these windows into a grid."); end end lastX = window[0] - bounds[0] + currentX; lastY = window[1] - bounds[1] + currentY; safeDrag(window[0], window[1], lastX, lastY); if cascade then currentX = currentX + 8; currentY = currentY + 24; else currentX = currentX + width + 5; end xMax = math.max(xMax, width); yMax = math.max(yMax, height); lsSleep(tick_delay); srReadScreen(); window = findImageInWindow("ThisIs.png", bottomRightX, bottomRightY); statusScreen("Arranging Windows"); end end function findFirstWindow() local windows = {}; local current = srFindFirstTextRegion(); while current do breakupRegion(regionToBox(current), windows); current = srFindNextTextRegion(current[0] + 1, current[1]); end return windows; end -- NORMALLY THIS IS A COMMON FUNCTION function deepcopy(object) local lookup_table = {} local function _copy(object) if type(object) ~= "table" then return object elseif lookup_table[object] then return lookup_table[object] end local new_table = {} lookup_table[object] = new_table for index, value in pairs(object) do new_table[_copy(index)] = _copy(value) end return setmetatable(new_table, getmetatable(object)) end return _copy(object) end function teppyTime(normalTime) if not normalTime then --no value passed, set to 0 return 0; else --return time in milliseconds return (normalTime*1.075*1000); end end