2024-04-29 02:44:18 +00:00
|
|
|
|
|
|
|
local love = assert( love )
|
|
|
|
local button = require 'button'
|
|
|
|
local savemodal = require 'savemodal'
|
|
|
|
local map = require 'map'
|
|
|
|
|
|
|
|
button.new{ name = "SAVE", y = 222, callback = savemodal.start, icon = love.graphics.newImage( "icons/save.png" )}
|
|
|
|
button.new{ name = "UNDO", y = 250, callback = map.undo, icon = love.graphics.newImage( "icons/undo.bmp" ) }
|
|
|
|
|
|
|
|
local tools
|
|
|
|
local layerButtons = {}
|
|
|
|
local function back( self )
|
|
|
|
for k, button in pairs( tools ) do button.visible = false end
|
|
|
|
for k, button in pairs( layerButtons ) do button.visible = true end
|
|
|
|
self.visible = false
|
|
|
|
map.editLayer = false
|
|
|
|
end
|
|
|
|
|
2024-05-02 00:32:07 +00:00
|
|
|
local backButton = button.new{
|
2024-04-29 02:44:18 +00:00
|
|
|
name = "UP",
|
|
|
|
visible = false,
|
|
|
|
y = 250 + button.h + 4,
|
|
|
|
icon = love.graphics.newImage( "icons/up.bmp" ),
|
|
|
|
callback = back,
|
|
|
|
}
|
|
|
|
|
|
|
|
local function toolCallback( self )
|
|
|
|
local f = (map.layers[self.layer])[self.name]
|
|
|
|
if f then return f(self) end
|
|
|
|
end
|
|
|
|
|
|
|
|
tools = {
|
|
|
|
button.new{ name = "SELECT"},
|
|
|
|
button.new{ name = "ERASE",},
|
|
|
|
button.new{ name = "MOVE", },
|
|
|
|
button.new{ name = "ADD", },
|
|
|
|
button.new{ name = "EDIT", },
|
|
|
|
button.new{ name = "DRAW", },
|
|
|
|
}
|
|
|
|
for i, v in ipairs( tools ) do
|
|
|
|
v.callback = toolCallback
|
|
|
|
v.y = 250 + (v.h + 4) * ( i + 1 )
|
|
|
|
v.visible = false
|
|
|
|
end
|
|
|
|
|
|
|
|
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" },
|
|
|
|
{ name = "AI", layer = "ainodes" },
|
|
|
|
{ name = "CITY", layer = "cities" },
|
|
|
|
{ name = "COAST", layer = "coastlines" },
|
|
|
|
{ name = "LOW", layer = "coastlinesLow"},
|
|
|
|
{ name = "INT", layer = "international"},
|
|
|
|
{ name = "SAIL", layer = "sailable" },
|
|
|
|
}
|
|
|
|
|
|
|
|
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 soloIcon = false--love.graphics.newImage( "icons/eye.bmp" )
|
|
|
|
local function soloVisibleLayer( self )
|
|
|
|
for k, layer in pairs( map.layers ) do
|
|
|
|
print( "invisible layer, map:", k, layer)
|
|
|
|
layer.visible = false
|
|
|
|
end
|
|
|
|
map.layers[ self.layer ].visible = true
|
|
|
|
return updateVisibilityIcons()
|
|
|
|
end
|
|
|
|
|
|
|
|
local function editLayer( self )
|
|
|
|
map.editLayer = map.layers[ self.layer ]
|
|
|
|
map.editLayer.visible = true
|
|
|
|
for k, button in pairs( layerButtons ) do button.visible = false end
|
|
|
|
for k, button in pairs( tools ) do
|
|
|
|
button.visible = true
|
|
|
|
button.layer = self.layer
|
|
|
|
end
|
|
|
|
backButton.visible = true
|
|
|
|
print( "EDITING LAYER", self.layer )
|
|
|
|
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 y = 250
|
|
|
|
local soloButtons = {}
|
|
|
|
local editButtons = {}
|
|
|
|
for i = 1, #layers do
|
|
|
|
editButtons[i] = button.new( copy( i, {
|
|
|
|
x = 8,
|
|
|
|
y = y + (button.h + 4) * i,
|
|
|
|
w = 112,
|
|
|
|
callback = editLayer,
|
|
|
|
group = "edit",
|
|
|
|
}))
|
|
|
|
layerButtons[ 3 * i - 2 ] = editButtons[i]
|
|
|
|
|
|
|
|
showButtons[i] = button.new( copy( i, {
|
|
|
|
x = 128,
|
|
|
|
y = y + (button.h + 4) * i,
|
|
|
|
w = 24,
|
|
|
|
name = "",
|
|
|
|
callback = toggleVisibleLayer,
|
|
|
|
icon = visibilityIcon,
|
|
|
|
group = "show",
|
|
|
|
}))
|
|
|
|
layerButtons[ 3 * i - 1 ] = showButtons[i]
|
|
|
|
|
|
|
|
soloButtons[i] = button.new( copy( i, {
|
|
|
|
x = 160,
|
|
|
|
y = y + (button.h + 4) * i,
|
|
|
|
w = 24,
|
|
|
|
name = "S",
|
|
|
|
callback = soloVisibleLayer,
|
|
|
|
icon = soloIcon,
|
|
|
|
group = "solo",
|
|
|
|
}))
|
|
|
|
layerButtons[ 3 * i ] = soloButtons[i]
|
|
|
|
end
|