local love = assert( love ) local button = require 'ui.button' local savemodal = require 'ui.savemodal' local loadmodal = require 'ui.loadmodal' local Camera = require 'ui.camera' local map = require 'map.map' button.new{ name = "LOAD", x = 250, y = 0, w = 28 * 13, callback = loadmodal.start, icon = love.graphics.newImage( "icons/load.png" )} button.new{ name = "SAVE", x = 250, y = 28, w = 28 * 13, callback = savemodal.start, icon = love.graphics.newImage( "icons/save.png" )} button.new{ name = "UNDO", x = 250, y = 2 * 28, w = 28 * 13, callback = map.undo, icon = love.graphics.newImage( "icons/undo.bmp" ) } local layers = { { name = "AF", layer = "africa" }, { name = "EU", layer = "europe" }, { name = "NA", layer = "northamerica" }, { name = "SA", layer = "southamerica" }, { name = "AS", layer = "southasia" }, { name = "RU", layer = "russia" }, { name = "PATH", layer = "travelnodes" , icon = love.graphics.newImage( "icons/layer-travelnodes.png" )}, { name = "AI", layer = "ainodes" , icon = love.graphics.newImage( "icons/layer-ainodes.png" )}, { name = "CITY", layer = "cities" , icon = love.graphics.newImage( "icons/layer-cities.png" )}, { name = "COAST", layer = "coastlines" , icon = love.graphics.newImage( "icons/layer-coastlines.png" )}, { name = "LOW", layer = "coastlinesLow", icon = love.graphics.newImage( "icons/layer-coastlines-low.png" )}, { name = "INT", layer = "international", icon = love.graphics.newImage( "icons/layer-international.png" )}, { name = "SAIL", layer = "sailable" , icon = love.graphics.newImage( "icons/layer-sailable.png" )}, } local showButtons = {} local visibilityIcon = love.graphics.newImage( "icons/eye.bmp" ) local function updateVisibilityIcons() for i = 1, #showButtons do showButtons[i].icon = map.layers[ showButtons[i].layer ].visible and visibilityIcon end end local function toggleVisibleLayer( self ) if not (self and self.layer) then return end local ml = map.layers[ self.layer ] ml.visible = not( ml.visible ) return updateVisibilityIcons() end local activeLayerButton local function back( self ) self.visible = false map.setEditLayer() activeLayerButton = nil return updateVisibilityIcons() end local backButton = button.new{ name = "UP", visible = false, y = 5 * 28, x = 250, icon = love.graphics.newImage( "icons/up.bmp" ), callback = back, } local function editLayer( self ) map.setEditLayer( self.layer ) activeLayerButton = self backButton.visible = true return updateVisibilityIcons() end local function copy( i, target ) for k, v in pairs( layers[i] ) do target[k] = target[k] or v end return target end local layerButtons = {} local x = 250 local soloButtons = {} local editButtons = {} for i = 1, #layers do editButtons[i] = button.new( copy( i, { y = 3 * 28, x = x + (button.h + 4) * ( i - 1 ), w = 24, callback = editLayer, group = "edit", tooltip = "edit "..layers[i].layer })) layerButtons[ 2 * i - 2 ] = editButtons[i] showButtons[i] = button.new( copy( i, { y = 4 * 28, x = x + (button.h + 4) * ( i - 1 ), w = 24, name = "", callback = toggleVisibleLayer, icon = visibilityIcon, group = "show", tooltip = "show "..layers[i].layer })) layerButtons[ 2 * i - 1 ] = showButtons[i] end local t = {} function t.draw() --Status bar. love.graphics.setScissor( 0, 0, 250, 200 ) local x, y = love.mouse.getPosition() local wx, wy = Camera.GetWorldCoordinate( x, y ) local bx, by = Camera.GetBitmapCoordinate( x, y ) local h = love.graphics.getHeight() - 60 love.graphics.setColor( 0, 0, 0, 1 ) love.graphics.rectangle( "fill", 0, 0, 250, love.graphics.getHeight() ) love.graphics.setColor( 1, 1, 1, 1 ) love.graphics.print(([[ SCREEN %-12d %-12d WORLD %-12.2f%-12.2f BITMAP %-12d %-12d %s %s]]):format( x, y, wx, wy, bx, by, button.selected and button.selected.tooltip or "", map.editLayer and map.editLayer.filename or ""), 0, 0) if map.selected then love.graphics.print( map.selected:formatDisplayInfo(), 0, 80 ) end if map.selectionLocked then end love.graphics.setScissor( 0, 0, love.graphics.getWidth(), 200 ) love.graphics.rectangle( "line", 0, 0 , 250, 200 ) love.graphics.rectangle( "line", 250, 0, love.graphics.getWidth() - 250, 200 ) love.graphics.setColor( 1, 1, 1, 0.8 ) button:draw() love.graphics.setColor( 1, 0, 0, 0.4 ) if activeLayerButton then activeLayerButton:highlight() end end return t