Code: Select all
function DungeonEditor:update()
if not renderer:isReadyToRender() or (config.sleepWhenNoFocus and not mainFrame:hasFocus()) then
sys.sleep(100)
return
end
if self.pendingLoadDungeon then
self:loadDungeon(self.pendingLoadDungeon)
self.pendingLoadDungeon = nil
end
updateTime()
updateFileChangeRequests()
--sys.sleep(50)
-- update input state
local windowSizeChanged = false
do
local state = imgui.state
state.doubleClick = detectDoubleClick()
-- clear unprocessed keys
state.keyInput = {}
state.mouseWheel = 0
-- poll events
while true do
local event = mainFrame:pollEvents()
if not event then break end
if event.type == "key" and event.down then
--print(event.key, event.char)
state.keyInput[#state.keyInput+1] = event
-- global keys
local action = config:convertEditorKeyToAction(event.keyCode, event.modifiers)
if event.key == "O" and event.modifiers == 2 then self:onOpenProject() end
if event.key == "S" and event.modifiers == 2 then self:onSaveProject() end
if event.key == "R" and event.modifiers == 2 then self:onReloadProject() end
if event.key == "T" and event.modifiers == 2 then self:onBackToGame() end
if event.key == "Y" and event.modifiers == 2 then sys.restart{ "launchEditor" } end
if action == "start_preview" then self:playPreview() end
if action == "stop_preview" then self:stopPreview() end
elseif event.type == "mouse_wheel" then
state.mouseWheel = state.mouseWheel + event.delta
elseif event.type == "menu" then
self:onMenuEvent(event.id)
elseif event.type == "resize" then
self.windowWidth = event.width -- 0 when window is minimized
self.windowHeight = event.height
windowSizeChanged = true
elseif event.type == "close" then
self:confirmClose(function() sys.exit() end)
end
end
end
-- early out if window is minimized
if self.windowWidth == 0 or self.windowHeight == 0 then return end
-- recreate render window if window was resized
if windowSizeChanged then
renderer:resizeRenderBuffers(self.windowWidth, self.windowHeight)
end
-- update steam
steamContext:update()
renderer:setViewport(0, 0, self.windowWidth, self.windowHeight)
renderer:beginRender()
ImmediateMode.beginDraw()
imgui.prepare(mainFrame)
local screenWidth = self.windowWidth
local screenHeight = self.windowHeight
if self.previewMode and self.fullscreen then
-- fullscreen preview mode
self:preview(0, 0, screenWidth, screenHeight)
else
ImmediateMode.fillRect(0, 0, screenWidth, screenHeight, {41,41,41,255})
self:toolBar(20, 10, 200, 30)
self:brushInfo(self.splitter1 + 2, 10, (screenWidth - self.splitter1) - self.splitter2 - 4, 30)
-- screen height without status bar
local screenHeight2 = screenHeight - 20
-- project/asset browser splitter
do
local x = 0
local y = 44
local width = self.splitter1 - 2
local height = screenHeight2 - y
-- asset browser
do
local y = self.splitter4+2
local height = screenHeight2 - y
self:assetBrowser(x, y, width, height)
end
-- project explorer
do
local height = self.splitter4 - y - 2
self:projectExplorer(x, y, width, height)
end
-- splitter 4
self.splitter4 = imgui.vsplitter("splitter4", x, self.splitter4, width)
self.splitter4 = math.clamp(self.splitter4, y + 50, screenHeight2 - 22)
end
-- map view
do
local x = self.splitter1 + 4
local y = 44
local width = (screenWidth - self.splitter2) - self.splitter1 - 8
local height = screenHeight2 - y
self:mapView(x, y, width, height)
end
-- preview/inspector splitter
do
local x = (screenWidth - self.splitter2) + 2
local y = 44
local width = screenWidth - x
local height = screenHeight2 - y
-- inspectors
do
local y = self.splitter3+2
local height = screenHeight2 - y
local sel = iff(#self.selection == 1, self.selection[1], nil)
self.inspector:inspect(sel, x, y, width, height, 0)
end
-- preview
do
local height = self.splitter3 - y - 2
self:previewButtons(x, 10)
if self.previewMode and self.fullscreen then
self:preview(0, 0, screenWidth, screenHeight)
else
self:preview(x, y, width, height)
end
end
-- splitter 3
self.splitter3 = imgui.vsplitter("splitter3", x, self.splitter3, width)
self.splitter3 = math.clamp(self.splitter3, y + 50, screenHeight2 - 22)
end
-- status bar
do
local h = 17
local x = 0
local y = screenHeight - h
ImmediateMode.fillRect(x, y, screenWidth, h, {56,56,56,255})
if self.status then ImmediateMode.drawText(self.status, x+4, y+2, imgui.state.font, {200,200,200,255}) end
-- draw coordinates
if self.mouseCellX and self.mouseCellY then
local text = string.format("%d,%d", self.mouseCellX, self.mouseCellY)
local textWidth = imgui.state.font:getTextWidth(text)
local x = x + screenWidth - textWidth - 4
ImmediateMode.fillRect(x-4, y, textWidth+8, h, {56,56,56,255})
ImmediateMode.drawText(text, x, y + 2, imgui.state.font, {200,200,200,255})
end
end
-- splitter 1 (measured from left screen edge)
self.splitter1 = imgui.hsplitter("splitter1", self.splitter1, 0, screenHeight)
self.splitter1 = math.clamp(self.splitter1, 10, (screenWidth - self.splitter2)-10)
-- splitter 2 (measured from right screen edge)
self.splitter2 = screenWidth - imgui.hsplitter("splitter2", screenWidth - self.splitter2, 0, screenHeight)
self.splitter2 = math.clamp(self.splitter2, 10, (screenWidth - self.splitter1)-10)
self:updateContextMenu()
end
if self.dialog then
self.dialog:update()
if self.dialog.close then self.dialog = nil end
end
imgui.finish()
ImmediateMode.endDraw()
renderer:endRender()
tvec.free()
tmat.free()
end