--*********************************************************** --** THE INDIE STONE ** --** Author: turbotutone ** --*********************************************************** require "ISUI/ISCollapsableWindow" IsoRegionDebug = ISCollapsableWindow:derive("IsoRegionDebug"); IsoRegionDebug.instance = nil; IsoRegionDebug.shiftDown = 0; --[[ local enabled = true; --getDebug(); function IsoRegionDebug.OnKeepKeyDown(key) --backspace 13, shift 42, 54 --print("KeyKeepDown = "..tostring(key)); if key==42 or key==54 then IsoRegionDebug.shiftDown = 4; end end function IsoRegionDebug.OnKeyDown(key) --backspace 14, shift 42, 54 --print("KeyDown = "..tostring(key)); if IsoRegionDebug.shiftDown>0 and key ==11 then IsoRegionDebug.OnOpenPanel(); end end --]] function IsoRegionDebug.OnOpenPanel() if IsoRegionDebug.instance==nil then IsoRegionDebug.instance = IsoRegionDebug:new (100, 100, 1000, 1000, getPlayer()); IsoRegionDebug.instance:initialise(); IsoRegionDebug.instance:instantiate(); end IsoRegionDebug.instance:addToUIManager(); IsoRegionDebug.instance:setVisible(true); return IsoRegionDebug.instance; end function IsoRegionDebug:initialise() ISCollapsableWindow.initialise(self); end function IsoRegionDebug:createChildren() ISCollapsableWindow.createChildren(self); local y = self:titleBarHeight(); self.canvasY = y; --y = y+10; --self:setHeight(y); local camW = 60*10; local camH = 60*10; self.cam = { x = 0, y = 0, width = camW, height = camH, centerX = camW/2, centerY = camH/2, chunkWidth = 10, chunkHeight = 10, chunkPixDim = 60, }; y = y + self.cam.height; self.palpha = 1.0; self.palphaUp = false; self.regionMode = 0; self.showGrid = true; self.showInvalidRegions = true; local x = 0; self.buttonToggleRegions = ISButton:new(x+5, y+2, self.cam.width-10,18,"showing: Master regions",self, IsoRegionDebug.onButton); self.buttonToggleRegions:initialise(); self.buttonToggleRegions.backgroundColor = {r=0, g=0.0, b=0, a=1.0}; self.buttonToggleRegions.backgroundColorMouseOver = {r=1.0, g=1.0, b=1.0, a=0.1}; self.buttonToggleRegions.borderColor = {r=1.0, g=1.0, b=1.0, a=0.3}; self.buttonToggleRegions.btnStringID = "ToggleRegions"; self.buttonToggleRegions.btnCode = self.regionMode; self:addChild(self.buttonToggleRegions); --self:onButton(self.buttonToggleRegions); y = self.buttonToggleRegions:getY() + self.buttonToggleRegions:getHeight(); self.buttonToggleGrid = ISButton:new(x+5, y+2, self.cam.width-10,18,"showing grid = TRUE",self, IsoRegionDebug.onButton); self.buttonToggleGrid:initialise(); self.buttonToggleGrid.backgroundColor = {r=0, g=0.8, b=0, a=1.0}; self.buttonToggleGrid.backgroundColorMouseOver = {r=1.0, g=1.0, b=1.0, a=0.1}; self.buttonToggleGrid.borderColor = {r=1.0, g=1.0, b=1.0, a=0.3}; self.buttonToggleGrid.btnStringID = "ToggleGrid"; self.buttonToggleGrid.btnCode = self.showGrid; self:addChild(self.buttonToggleGrid); y = self.buttonToggleGrid:getY() + self.buttonToggleGrid:getHeight(); self.buttonToggleInvalidRegions = ISButton:new(x+5, y+2, self.cam.width-10,18,"showing invalid regions = TRUE",self, IsoRegionDebug.onButton); self.buttonToggleInvalidRegions:initialise(); self.buttonToggleInvalidRegions.backgroundColor = {r=0, g=0.8, b=0, a=1.0}; self.buttonToggleInvalidRegions.backgroundColorMouseOver = {r=1.0, g=1.0, b=1.0, a=0.1}; self.buttonToggleInvalidRegions.borderColor = {r=1.0, g=1.0, b=1.0, a=0.3}; self.buttonToggleInvalidRegions.btnStringID = "ToggleInvalidRegions"; self.buttonToggleInvalidRegions.btnCode = self.showInvalidRegions; self:addChild(self.buttonToggleInvalidRegions); y = self.buttonToggleInvalidRegions:getY() + self.buttonToggleInvalidRegions:getHeight(); local booltxt = IsoRegions.isDebugLoadAllChunks() and "TRUE" or "FALSE"; self.buttonToggleLoadAllChunks = ISButton:new(x+5, y+2, self.cam.width-10,18,"load all chunks around plr = "..booltxt,self, IsoRegionDebug.onButton); self.buttonToggleLoadAllChunks:initialise(); if IsoRegions.isDebugLoadAllChunks() then self.buttonToggleLoadAllChunks.backgroundColor = {r=0.0, g=0.8, b=0, a=1.0}; else self.buttonToggleLoadAllChunks.backgroundColor = {r=0.8, g=0.0, b=0, a=1.0}; end self.buttonToggleLoadAllChunks.backgroundColorMouseOver = {r=1.0, g=1.0, b=1.0, a=0.1}; self.buttonToggleLoadAllChunks.borderColor = {r=1.0, g=1.0, b=1.0, a=0.3}; self.buttonToggleLoadAllChunks.btnStringID = "ToggleLoadAllChunks"; self.buttonToggleLoadAllChunks.btnCode = self.showGrid; self:addChild(self.buttonToggleLoadAllChunks); y = self.buttonToggleLoadAllChunks:getY() + self.buttonToggleLoadAllChunks:getHeight(); self.buttonReset = ISButton:new(x+5, y+2, self.cam.width-10,18,"DESTROY CURRENT DATASET",self, IsoRegionDebug.onButton); self.buttonReset:initialise(); self.buttonReset.backgroundColor = {r=0, g=0.0, b=0, a=1.0}; self.buttonReset.backgroundColorMouseOver = {r=1.0, g=1.0, b=1.0, a=0.1}; self.buttonReset.borderColor = {r=1.0, g=1.0, b=1.0, a=0.3}; self.buttonReset.btnStringID = "ResetData"; self.buttonReset.btnCode = self.showGrid; self:addChild(self.buttonReset); y = self.buttonReset:getY() + self.buttonReset:getHeight(); self:setWidth(self.cam.width); self:setHeight(y+self:resizeWidgetHeight()); end function IsoRegionDebug:onButton(_btn) if _btn.btnStringID=="ToggleRegions" then self.buttonToggleRegions.btnCode = self.buttonToggleRegions.btnCode + 1; if self.buttonToggleRegions.btnCode >= 3 then self.buttonToggleRegions.btnCode = 0; end if self.buttonToggleRegions.btnCode == 0 then self.buttonToggleRegions.title = "showing: Master regions"; self.regionMode = 0; elseif self.buttonToggleRegions.btnCode == 1 then self.buttonToggleRegions.title = "showing: Chunk regions"; self.regionMode = 1; elseif self.buttonToggleRegions.btnCode == 2 then self.buttonToggleRegions.title = "showing: Blueprint"; self.regionMode = 2; end end if _btn.btnStringID == "ToggleGrid" then self.showGrid = not self.showGrid; if self.showGrid then self.buttonToggleGrid.title = "showing grid = TRUE"; self.buttonToggleGrid.backgroundColor = {r=0, g=0.8, b=0, a=1.0}; else self.buttonToggleGrid.title = "showing grid = FALSE"; self.buttonToggleGrid.backgroundColor = {r=0.8, g=0.0, b=0, a=1.0}; end end if _btn.btnStringID == "ToggleInvalidRegions" then self.showInvalidRegions = not self.showInvalidRegions; if self.showInvalidRegions then self.buttonToggleInvalidRegions.title = "showing invalid regions = TRUE"; self.buttonToggleInvalidRegions.backgroundColor = {r=0, g=0.8, b=0, a=1.0}; else self.buttonToggleInvalidRegions.title = "showing invalid regions = FALSE"; self.buttonToggleInvalidRegions.backgroundColor = {r=0.8, g=0.0, b=0, a=1.0}; end end if _btn.btnStringID == "ToggleLoadAllChunks" then IsoRegions.setDebugLoadAllChunks(not IsoRegions.isDebugLoadAllChunks()); if IsoRegions.isDebugLoadAllChunks() then self.buttonToggleLoadAllChunks.title = "load all chunks around plr = TRUE"; self.buttonToggleLoadAllChunks.backgroundColor = {r=0, g=0.8, b=0, a=1.0}; else self.buttonToggleLoadAllChunks.title = "load all chunks around plr = FALSE"; self.buttonToggleLoadAllChunks.backgroundColor = {r=0.8, g=0.0, b=0, a=1.0}; end end if _btn.btnStringID == "ResetData" then IsoRegions.ResetAllDataDebug(); end end function IsoRegionDebug:convertCoords(_x, _y) local x,y=1000-(_y/18.7),_x/18.7; return x,y; end function IsoRegionDebug:onResize() ISUIElement.onResize(self); local th = self:titleBarHeight(); end function IsoRegionDebug:update() ISCollapsableWindow.update(self); if IsoRegionDebug.shiftDown>0 then IsoRegionDebug.shiftDown = IsoRegionDebug.shiftDown-1; end end function IsoRegionDebug:prerender() self:stayOnSplitScreen(); ISCollapsableWindow.prerender(self); end function IsoRegionDebug:stayOnSplitScreen() ISUIElement.stayOnSplitScreen(self, self.playerNum) end function IsoRegionDebug:onMouseDown(x, y) --print("Mouse over x="..tostring(x)..", y="..tostring(y)); local sx,sy = 60, self.canvasY+60; local ex,ey = sx+((self.cam.chunkWidth-2)*60),sy+((self.cam.chunkHeight-2)*60); if x>=sx and x=sy and y