add some UI
This commit is contained in:
parent
a2eeafcdb3
commit
8b766723f1
9
bmp.lua
9
bmp.lua
|
@ -15,8 +15,15 @@ function t.load( filename )
|
||||||
return img, imgd
|
return img, imgd
|
||||||
end
|
end
|
||||||
|
|
||||||
function t.save( data, filename )
|
function t.save( data, filename, format )
|
||||||
local w, h = data:getDimensions()
|
local w, h = data:getDimensions()
|
||||||
|
local str = ""
|
||||||
|
for x = 0, w - 1 do
|
||||||
|
for y = 0, h - 1 do
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return str
|
||||||
end
|
end
|
||||||
|
|
||||||
return t
|
return t
|
85
button.lua
85
button.lua
|
@ -1,32 +1,79 @@
|
||||||
local t = {}
|
local lg = love.graphics
|
||||||
|
|
||||||
function t.onHover( button )
|
local t = {
|
||||||
|
name = "",
|
||||||
|
tooltip = "button",
|
||||||
|
icon = lg.newImage( "icons/eye.bmp" ),
|
||||||
|
x = 8,
|
||||||
|
y = 250,
|
||||||
|
w = 176,
|
||||||
|
h = 24,
|
||||||
|
visible = true,
|
||||||
|
callback = function( self ) return print( "clicked button: ", self.name, self.x, self.y, self.w, self.h, self.visible ) end
|
||||||
|
}
|
||||||
|
t.selected, t.next, t.prev = t, t, t
|
||||||
|
|
||||||
|
function t.contains( button, x, y )
|
||||||
|
return x < button.x + button.w and x > button.x
|
||||||
|
and y < button.y + button.h and y > button.y
|
||||||
end
|
end
|
||||||
|
|
||||||
function t.onClick( button )
|
function t.new( b )
|
||||||
|
b = setmetatable( b or {}, t )
|
||||||
|
b.next = t
|
||||||
|
t.prev.next = b
|
||||||
|
b.prev = t.prev
|
||||||
|
t.prev = b
|
||||||
|
return b
|
||||||
end
|
end
|
||||||
|
|
||||||
function t.newButton( name, tooltip, icon, x, y, w, h, callback )
|
local drawPassOngoing = false
|
||||||
return setmetatable( {
|
function t.draw( b )
|
||||||
name = name,
|
if b == t then
|
||||||
tooltip = tooltip,
|
drawPassOngoing = not( drawPassOngoing )
|
||||||
icon = icon,
|
if not drawPassOngoing then return end
|
||||||
x = x,
|
elseif b.visible then
|
||||||
y = y,
|
lg.rectangle( "line", b.x, b.y, b.w, b.h, 6 )
|
||||||
w = w,
|
lg.printf( b.name,
|
||||||
h = h,
|
b.x,
|
||||||
callback = callback },
|
b.y + 0.5 * ( b.h- lg.getFont():getHeight() ),
|
||||||
t )
|
b.w - 5,
|
||||||
|
"right" )
|
||||||
|
if b.icon then lg.draw( b.icon,
|
||||||
|
b.x, b.y + 0.5 * (b.h - b.icon:getHeight()),
|
||||||
|
0,
|
||||||
|
0.5, 0.5 )
|
||||||
|
end
|
||||||
|
if t.selected == b then
|
||||||
|
lg.rectangle( "fill", b.x, b.y, b.w, b.h, 6 )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return t.draw( b.next )
|
||||||
end
|
end
|
||||||
|
|
||||||
function t.draw( button )
|
function t.select( b )
|
||||||
|
t.selected = b
|
||||||
end
|
end
|
||||||
|
|
||||||
t.__index = t
|
function t.selectNext()
|
||||||
t.__call = t.newButton
|
repeat t.selected = t.selected.next until t.selected.visible
|
||||||
|
end
|
||||||
|
|
||||||
|
function t.selectPrev()
|
||||||
|
repeat t.selected = t.selected.prev until t.selected.visible
|
||||||
|
end
|
||||||
|
|
||||||
|
function t.selectIn( x, y )
|
||||||
|
t.selected = t
|
||||||
|
repeat t.selected = t.selected.next until (t.selected == t) or (t.selected.visible and t.selected:contains( x, y ))
|
||||||
|
end
|
||||||
|
|
||||||
|
function t.deselect( b )
|
||||||
|
t.selected = t
|
||||||
|
end
|
||||||
|
|
||||||
setmetatable( t, t )
|
setmetatable( t, t )
|
||||||
|
t.__index = t
|
||||||
|
t.__call = t.new
|
||||||
|
|
||||||
return t
|
return t
|
|
@ -47,8 +47,8 @@ function Camera.Set( x, y, w, h )
|
||||||
tfTerritory:translate( -x * 512 / 360, y * 512 / 360 )
|
tfTerritory:translate( -x * 512 / 360, y * 512 / 360 )
|
||||||
|
|
||||||
tfNodes:reset()
|
tfNodes:reset()
|
||||||
tfNodes:scale( w / 360, h / 200 )
|
tfNodes:scale( w / 360, -h / 200 )
|
||||||
tfNodes:translate( 180 - x , y + 100 )
|
tfNodes:translate( 180 - x , -y - 100 )
|
||||||
--tfNodes:translate( -x * 800 / 360, y * 400 / 200 )
|
--tfNodes:translate( -x * 800 / 360, y * 400 / 200 )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
2745
data/cities.dat
2745
data/cities.dat
File diff suppressed because it is too large
Load Diff
Binary file not shown.
After Width: | Height: | Size: 144 KiB |
48
lines.lua
48
lines.lua
|
@ -3,6 +3,18 @@ local t = {}
|
||||||
local lfs = love.filesystem
|
local lfs = love.filesystem
|
||||||
local lg = love.graphics
|
local lg = love.graphics
|
||||||
|
|
||||||
|
local polygon = { x = 180, X = -180, y = 100, Y = -100 } --default empty bounding box
|
||||||
|
local polymt = { __index = polygon }
|
||||||
|
|
||||||
|
function polygon:formatDisplayInfo()
|
||||||
|
return ([[
|
||||||
|
x: %f
|
||||||
|
y: %f
|
||||||
|
X: %f
|
||||||
|
Y: %f
|
||||||
|
N: %d]]):format( self.x, self.y, self.X, self.Y, #self )
|
||||||
|
end
|
||||||
|
|
||||||
function t.load( filename )
|
function t.load( filename )
|
||||||
local polys = { visible = true }
|
local polys = { visible = true }
|
||||||
local poly = {}
|
local poly = {}
|
||||||
|
@ -12,7 +24,7 @@ function t.load( filename )
|
||||||
if line:find "b" then
|
if line:find "b" then
|
||||||
k = 1
|
k = 1
|
||||||
if #poly > 2 then n = n + 1 end
|
if #poly > 2 then n = n + 1 end
|
||||||
poly = {}
|
poly = setmetatable({}, polymt) --axis-aligned bounding box
|
||||||
polys[n] = poly
|
polys[n] = poly
|
||||||
else
|
else
|
||||||
local _, _, x, y = line:find( "(%g+)%s+(%g+)" )
|
local _, _, x, y = line:find( "(%g+)%s+(%g+)" )
|
||||||
|
@ -20,6 +32,10 @@ function t.load( filename )
|
||||||
if x and y then
|
if x and y then
|
||||||
poly[k], poly[ k + 1 ] = x, y
|
poly[k], poly[ k + 1 ] = x, y
|
||||||
k = k + 2
|
k = k + 2
|
||||||
|
if x < poly.x then poly.x = x end
|
||||||
|
if x > poly.X then poly.X = x end
|
||||||
|
if y < poly.y then poly.y = y end
|
||||||
|
if y > poly.Y then poly.Y = y end
|
||||||
else
|
else
|
||||||
print( "LINES: malformed line:", filename, line )
|
print( "LINES: malformed line:", filename, line )
|
||||||
end
|
end
|
||||||
|
@ -35,9 +51,35 @@ function t.load( filename )
|
||||||
return setmetatable( polys, {__index = t } )
|
return setmetatable( polys, {__index = t } )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function t.selectNearest( lines, wx, wy )
|
||||||
|
local d = math.huge
|
||||||
|
local nearest
|
||||||
|
for i, poly in ipairs( lines ) do
|
||||||
|
if poly.x - 5 < wx and
|
||||||
|
poly.X + 5 > wx and
|
||||||
|
poly.y - 5 < wy and
|
||||||
|
poly.Y + 5 > wy then
|
||||||
|
for k = 1, #poly, 2 do
|
||||||
|
local x, y = poly[k], poly[k + 1]
|
||||||
|
local r = ( x - wx ) * ( x - wx ) + ( y - wy ) * ( y - wy )
|
||||||
|
if r < d then
|
||||||
|
d = r
|
||||||
|
nearest = poly
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nearest
|
||||||
|
end
|
||||||
|
|
||||||
function t.save( lines, filename )
|
function t.save( lines, filename )
|
||||||
|
print( "=== SAVING LINES ===" )
|
||||||
|
local str = {}
|
||||||
|
for i, poly in ipairs( lines ) do
|
||||||
|
str[i] = table.concat( poly, " " )
|
||||||
|
end
|
||||||
|
str = table.concat( str, "\nb\n" ):gsub("(%S+) (%S+) ", "%1 %2\n")
|
||||||
|
return str
|
||||||
end
|
end
|
||||||
|
|
||||||
function t.newPolygon( x, y )
|
function t.newPolygon( x, y )
|
||||||
|
|
264
main.lua
264
main.lua
|
@ -14,11 +14,14 @@ function love.load()
|
||||||
assert( lfs.createDirectory( SAVEDIRECTORY.."data/graphics" ))
|
assert( lfs.createDirectory( SAVEDIRECTORY.."data/graphics" ))
|
||||||
|
|
||||||
|
|
||||||
love.graphics.setNewFont( 12, "mono" )
|
love.graphics.setNewFont( 14 )--, "mono" )
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.directorydropped( path )
|
function love.directorydropped( path )
|
||||||
if map.path then assert( love.filesystem.unmount( map.path ) ) end
|
if map.path then
|
||||||
|
assert( love.filesystem.unmount( map.path ) )
|
||||||
|
map.loaded = false
|
||||||
|
end
|
||||||
love.filesystem.mount( path, "" )
|
love.filesystem.mount( path, "" )
|
||||||
return map.load( path )
|
return map.load( path )
|
||||||
end
|
end
|
||||||
|
@ -37,72 +40,34 @@ function love.update( dt )
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local toolButtons = {
|
|
||||||
"Brush",
|
|
||||||
"Move Nodes",
|
|
||||||
"Add Nodes",
|
|
||||||
"Edit Node",
|
|
||||||
"Draw Polygon",
|
|
||||||
"Erase Polygon"
|
|
||||||
}
|
|
||||||
|
|
||||||
local layerButtons = {
|
|
||||||
"Africa",
|
|
||||||
"Europe",
|
|
||||||
"North America",
|
|
||||||
"South America",
|
|
||||||
"Asia",
|
|
||||||
"Russia",
|
|
||||||
"Travel Nodes",
|
|
||||||
"AI Markers",
|
|
||||||
"Cities",
|
|
||||||
"Coastlines",
|
|
||||||
"Coastlines Low",
|
|
||||||
"Sailable"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
if not map.loaded then
|
if not map.loaded then
|
||||||
return love.graphics.print( "Drag and drop folder to begin.")
|
local w, h = love.graphics.getDimensions()
|
||||||
|
return love.graphics.printf( "Drag and drop folder to begin.", w / 2 - 200, h / 2 - 128, 200, "center")
|
||||||
end
|
end
|
||||||
|
|
||||||
love.graphics.push( "all" )
|
love.graphics.push( "all" )
|
||||||
map.draw()
|
map.draw()
|
||||||
love.graphics.pop()
|
love.graphics.pop()
|
||||||
|
|
||||||
--Layer buttons.
|
|
||||||
do
|
|
||||||
love.graphics.setColor( 1, 1, 1, 1 )
|
|
||||||
local h = love.graphics.getHeight() - 60
|
|
||||||
for x = 0, 300, 30 do
|
|
||||||
love.graphics.rectangle( "line", x, h, 30, 30 )
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
--Status bar.
|
--Status bar.
|
||||||
local x, y = love.mouse.getPosition()
|
local x, y = love.mouse.getPosition()
|
||||||
local wx, wy = Camera.GetWorldCoordinate( x, y )
|
local wx, wy = Camera.GetWorldCoordinate( x, y )
|
||||||
local bx, by = Camera.GetBitmapCoordinate( x, y )
|
local bx, by = Camera.GetBitmapCoordinate( x, y )
|
||||||
local h = love.graphics.getHeight() - 30
|
local h = love.graphics.getHeight() - 60
|
||||||
love.graphics.setColor( 0.2, 0.1, 0.1, 1.0 )
|
love.graphics.setColor( 0.1, 0.1, 0.5, 0.8 )
|
||||||
love.graphics.rectangle( "fill", 0, h, love.graphics.getWidth() / 2, 30 )
|
love.graphics.rectangle( "fill", 0, 0, 250, love.graphics.getHeight() )
|
||||||
love.graphics.setColor( 1, 1, 1, 1 )
|
love.graphics.setColor( 1, 1, 1, 1 )
|
||||||
love.graphics.rectangle( "line", 0, h, love.graphics.getWidth() / 2, 30 )
|
love.graphics.print(([[
|
||||||
love.graphics.print(("SCREEN\t%d\t%d\nWORLD \t%5.2f\t%5.2f"):format(x, y, wx, wy), 0, h)
|
SCREEN%8d%8d
|
||||||
love.graphics.print(("BITMAP\t%5.2f\t%5.2f"):format(bx, by), 200, h )
|
WORLD %8.2f%8.2f
|
||||||
|
BITMAP%8.2f%8.2f]]):format(x, y, wx, wy, bx, by), 0, 0)
|
||||||
|
|
||||||
--Edit box.
|
if map.selected then love.graphics.print( map.selected:formatDisplayInfo(), 0, 80 ) end
|
||||||
love.graphics.rectangle( "line", love.graphics.getWidth() / 2, h, love.graphics.getWidth() / 2, 30 )
|
if map.selectionLocked then end
|
||||||
if map.selected then
|
|
||||||
love.graphics.setColor( 0.2, 0.1, 0.1, 1.0 )
|
love.graphics.setColor( 1, 1, 1, 0.8 )
|
||||||
love.graphics.rectangle( "fill", 0, 0, 150 ,100 )
|
button:draw()
|
||||||
love.graphics.setColor( 1, 1, 1, 1 )
|
|
||||||
love.graphics.rectangle( "line", 0, 0, 150 ,100 )
|
|
||||||
love.graphics.setColor( 1.2, 1.1, 1.1, 1.5 )
|
|
||||||
love.graphics.print( map.selected:formatDisplayInfo(), 0, 0 )
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.resize(w, h)
|
function love.resize(w, h)
|
||||||
|
@ -113,59 +78,166 @@ function love.wheelmoved(x, y)
|
||||||
Camera.Zoom( (y > 0) and 0.5 or -0.5 )
|
Camera.Zoom( (y > 0) and 0.5 or -0.5 )
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.mousepressed( x, y, button, istouch, presses )
|
function love.mousepressed( x, y, mouseButton, istouch, presses )
|
||||||
local wx, wy = Camera.GetWorldCoordinate( x, y )
|
local wx, wy = Camera.GetWorldCoordinate( x, y )
|
||||||
if map.loaded then
|
|
||||||
if button == 1 then
|
|
||||||
map.cities.lockSelection()
|
|
||||||
else
|
|
||||||
map.cities.unlockSelection()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
print( ("MOUSE\tx %f\ty %f\twx %f\twy %f"):format(x, y, wx, wy) )
|
print( ("MOUSE\tx %f\ty %f\twx %f\twy %f"):format(x, y, wx, wy) )
|
||||||
|
if button.selected and button.selected:contains( x, y ) then button.selected:callback() end
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.mousemoved( x, y, dx, dy, istouch )
|
function love.mousemoved( x, y, dx, dy, istouch )
|
||||||
local wx, wy = Camera.GetWorldCoordinate( x, y )
|
if not map.loaded then return end
|
||||||
if map.loaded then
|
--mouse over menu
|
||||||
if map.cities.visible then map.selected = map.cities:selectNearest( wx, wy )
|
button.selectIn( x, y )
|
||||||
elseif map.travelnodes.visible then map.selected = map.travelnodes:selectNearest( wx, wy )
|
|
||||||
elseif map.ainodes.visible then map.selected = map.ainodes:selectNearest( wx, wy )
|
--mouse on map
|
||||||
end
|
if map.selectionLocked then return end
|
||||||
|
if map.editLayer and map.editLayer.selectNearest then
|
||||||
|
map.selected = map.editLayer:selectNearest( Camera.GetWorldCoordinate( x, y ) )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function ToggleVisibility( layer )
|
function love.keypressed(key, code, isRepeat)
|
||||||
if not layer then return end
|
|
||||||
local ml
|
|
||||||
if map[layer] then ml = map[layer] end
|
|
||||||
if map.territory[layer] then ml = map.territory[layer] end
|
|
||||||
assert( ml )
|
|
||||||
ml.visible = not( ml.visible )
|
|
||||||
print( layer, ml.visible )
|
|
||||||
end
|
|
||||||
|
|
||||||
local layerVisibilityKeybinds = {
|
|
||||||
["1"] = "africa",
|
|
||||||
["2"] = "europe",
|
|
||||||
["3"] = "northamerica",
|
|
||||||
["4"] = "southamerica",
|
|
||||||
["5"] = "southasia",
|
|
||||||
["6"] = "russia",
|
|
||||||
["7"] = "sailable",
|
|
||||||
["8"] = "coastlines",
|
|
||||||
["9"] = "coastlinesLow",
|
|
||||||
["0"] = "international",
|
|
||||||
["-"] = "cities",
|
|
||||||
["="] = "travelnodes",
|
|
||||||
["backspace"] = "ainodes",
|
|
||||||
}
|
|
||||||
|
|
||||||
function love.keypressed(key)
|
|
||||||
ToggleVisibility( layerVisibilityKeybinds[key] )
|
|
||||||
wasKeyPressed = true
|
wasKeyPressed = true
|
||||||
|
|
||||||
|
if code == "down" then return button.selectNext() end
|
||||||
|
if code == "up" then return button.selectPrev() end
|
||||||
|
if code == "return" then return button.selected:callback() end
|
||||||
|
|
||||||
if key == "l" then
|
if key == "l" then
|
||||||
return map.save()
|
return map.save()
|
||||||
end
|
end
|
||||||
|
if key == "c" then
|
||||||
|
map.selectionLocked = not( map.selectionLocked )
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
do
|
||||||
|
|
||||||
|
button.new{ name = "UNDO", y = 250, callback = map.undo }
|
||||||
|
|
||||||
|
local function toolCallback( self )
|
||||||
|
local f = (map.layers[self.layer])[self.name]
|
||||||
|
if f then return f(self) end
|
||||||
|
end
|
||||||
|
|
||||||
|
local 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 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
|
||||||
|
|
||||||
|
local backButton = button.new{
|
||||||
|
name = "BACK",
|
||||||
|
visible = false,
|
||||||
|
y = 250 + button.h + 4,
|
||||||
|
callback = back,
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = "SAIL", layer = "sailable" },
|
||||||
|
}
|
||||||
|
|
||||||
|
local visibilityIcon = love.graphics.newImage( "icons/eye.bmp" )
|
||||||
|
local function toggleVisibleLayer( self )
|
||||||
|
if not (self and self.layer) then return end
|
||||||
|
local ml = map.layers[ self.layer ]
|
||||||
|
ml.visible = not( ml.visible )
|
||||||
|
self.icon = ml.visible and visibilityIcon
|
||||||
|
end
|
||||||
|
|
||||||
|
local soloIcon = love.graphics.newImage( "icons/eye.bmp" )
|
||||||
|
local function soloVisibleLayer( self )
|
||||||
|
--hide icons for disabled invisible layers
|
||||||
|
print( "===SOLO LAYER===", self.layer )
|
||||||
|
for i, button in ipairs( layerButtons ) do
|
||||||
|
if button.layer ~= self.layer then
|
||||||
|
button.icon = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for k, layer in pairs( map.layers ) do
|
||||||
|
print( "invisible layer, map:", k, layer)
|
||||||
|
layer.visible = false
|
||||||
|
end
|
||||||
|
map.layers[ self.layer ].visible = true
|
||||||
|
end
|
||||||
|
|
||||||
|
local function editLayer( self )
|
||||||
|
map.editLayer = map.layers[ self.layer ]
|
||||||
|
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
|
||||||
|
return soloVisibleLayer( self )
|
||||||
|
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
|
||||||
|
for i = 1, #layers do
|
||||||
|
|
||||||
|
layerButtons[ 3 * i - 2 ] = button.new( copy( i, {
|
||||||
|
x = 8,
|
||||||
|
y = y + (button.h + 4) * i,
|
||||||
|
w = 112,
|
||||||
|
callback = editLayer
|
||||||
|
}))
|
||||||
|
|
||||||
|
layerButtons[ 3 * i - 1 ] = button.new( copy( i, {
|
||||||
|
x = 128,
|
||||||
|
y = y + (button.h + 4) * i,
|
||||||
|
w = 24,
|
||||||
|
name = "V",
|
||||||
|
callback = toggleVisibleLayer,
|
||||||
|
icon = visibilityIcon,
|
||||||
|
}))
|
||||||
|
|
||||||
|
layerButtons[ 3 * i ] = button.new( copy( i, {
|
||||||
|
x = 160,
|
||||||
|
y = y + (button.h + 4) * i,
|
||||||
|
w = 24,
|
||||||
|
name = "S",
|
||||||
|
callback = soloVisibleLayer,
|
||||||
|
icon = soloIcon
|
||||||
|
}))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
73
map.lua
73
map.lua
|
@ -6,11 +6,31 @@ local Nodes = require 'travelNodes'
|
||||||
local Camera = require 'camera'
|
local Camera = require 'camera'
|
||||||
local Territory = require 'territory'
|
local Territory = require 'territory'
|
||||||
|
|
||||||
local map = {
|
--flat list of editable layers for convenience
|
||||||
loaded = false,
|
local layers = {
|
||||||
coastlines = false,
|
coastlines = false,
|
||||||
coastlinesLow = false,
|
coastlinesLow = false,
|
||||||
international = false,
|
international = false,
|
||||||
|
africa = false,
|
||||||
|
europe = false,
|
||||||
|
northamerica = false,
|
||||||
|
russia = false,
|
||||||
|
southamerica = false,
|
||||||
|
southasia = false,
|
||||||
|
travelnodes = false,
|
||||||
|
sailable = false,
|
||||||
|
ainodes = false,
|
||||||
|
cities = false,
|
||||||
|
}
|
||||||
|
|
||||||
|
local map = {
|
||||||
|
layers = layers,
|
||||||
|
path = false,
|
||||||
|
loaded = false,
|
||||||
|
selected = false,
|
||||||
|
selectionLocked = false,
|
||||||
|
editLayer = false,
|
||||||
|
|
||||||
territory = {
|
territory = {
|
||||||
africa = false,
|
africa = false,
|
||||||
europe = false,
|
europe = false,
|
||||||
|
@ -19,6 +39,11 @@ local map = {
|
||||||
southamerica = false,
|
southamerica = false,
|
||||||
southasia = false
|
southasia = false
|
||||||
},
|
},
|
||||||
|
|
||||||
|
background = false,
|
||||||
|
coastlines = false,
|
||||||
|
coastlinesLow = false,
|
||||||
|
international = false,
|
||||||
travelnodes = false,
|
travelnodes = false,
|
||||||
sailable = false,
|
sailable = false,
|
||||||
ainodes = false,
|
ainodes = false,
|
||||||
|
@ -26,6 +51,7 @@ local map = {
|
||||||
}
|
}
|
||||||
|
|
||||||
function map.load( path )
|
function map.load( path )
|
||||||
|
map.background = lg.newImage( "data/graphics/blur.bmp" )
|
||||||
map.cities = Cities.load( "data/earth/cities.dat" )
|
map.cities = Cities.load( "data/earth/cities.dat" )
|
||||||
map.coastlines = Lines.load( "data/earth/coastlines.dat" )
|
map.coastlines = Lines.load( "data/earth/coastlines.dat" )
|
||||||
map.coastlinesLow = Lines.load( "data/earth/coastlines-low.dat" )
|
map.coastlinesLow = Lines.load( "data/earth/coastlines-low.dat" )
|
||||||
|
@ -38,6 +64,11 @@ function map.load( path )
|
||||||
end
|
end
|
||||||
map.loaded = true
|
map.loaded = true
|
||||||
map.path = path
|
map.path = path
|
||||||
|
|
||||||
|
--update references
|
||||||
|
for k, v in pairs( layers ) do
|
||||||
|
layers[k] = map[k] or map.territory[k]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function map.draw()
|
function map.draw()
|
||||||
|
@ -45,10 +76,13 @@ function map.draw()
|
||||||
if not map.loaded then return end
|
if not map.loaded then return end
|
||||||
|
|
||||||
do --territory
|
do --territory
|
||||||
lg.setColor( 1,1,1,1)
|
|
||||||
lg.setLineJoin( "none" )
|
lg.setLineJoin( "none" )
|
||||||
lg.replaceTransform( Camera.tfTerritory )
|
lg.replaceTransform( Camera.tfTerritory )
|
||||||
lg.setBlendMode( "add" )
|
lg.setBlendMode( "add" )
|
||||||
|
|
||||||
|
lg.setColor( 1, 1, 1, 0.2 )
|
||||||
|
lg.draw( map.background )
|
||||||
|
lg.setColor( 1, 1, 1, 0.5 )
|
||||||
for k, v in pairs(map.territory) do
|
for k, v in pairs(map.territory) do
|
||||||
if v.visible then
|
if v.visible then
|
||||||
v:draw()
|
v:draw()
|
||||||
|
@ -80,11 +114,20 @@ function map.draw()
|
||||||
lg.replaceTransform( Camera.tf )
|
lg.replaceTransform( Camera.tf )
|
||||||
|
|
||||||
if map.selected then
|
if map.selected then
|
||||||
|
if map.selected[1] then --lines
|
||||||
|
local p = map.selected
|
||||||
|
lg.setColor( 0.4, 0.5, 0.8, 0.5 )
|
||||||
|
lg.setLineWidth( 0.2 / Camera.zoom )
|
||||||
|
lg.rectangle( "fill", p.x, p.y, p.X - p.x, p.Y - p.y )
|
||||||
|
lg.setColor( 1.0, 0, 0, 1 )
|
||||||
|
lg.line( p )
|
||||||
|
else --points
|
||||||
lg.setColor( 1.0, 0.5, 0.5, 0.9 )
|
lg.setColor( 1.0, 0.5, 0.5, 0.9 )
|
||||||
lg.setLineJoin( "miter" )
|
lg.setLineJoin( "miter" )
|
||||||
lg.setLineWidth( 1.0 / Camera.zoom )
|
lg.setLineWidth( 1.0 / Camera.zoom )
|
||||||
lg.circle( "line", map.selected.x, map.selected.y, 0.2 + 1.0 / Camera.zoom )
|
lg.circle( "line", map.selected.x, map.selected.y, 0.2 + 1.0 / Camera.zoom )
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if map.cities.visible then --points
|
if map.cities.visible then --points
|
||||||
|
|
||||||
|
@ -134,23 +177,27 @@ function map.draw()
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function write( filename, string )
|
--[[local function write( filename, string )
|
||||||
os.rename( filename, filename..".bak" ) --just in case :^)
|
os.rename( filename, filename..".bak" ) --just in case :^)
|
||||||
local file = assert( io.open( filename, "w+" ) )
|
local file = assert( io.open( filename, "w+" ) )
|
||||||
assert( file:write( string ) )
|
assert( file:write( string ) )
|
||||||
file:close()
|
file:close()
|
||||||
|
end]]
|
||||||
|
|
||||||
|
local function write( filename, string )
|
||||||
|
print( "Pretending to write", string:len(), "bytes to", filename )
|
||||||
end
|
end
|
||||||
|
|
||||||
function map.save()
|
function map.save()
|
||||||
write( map.path.."/data/earth/cities.dat", map.cities:save())
|
write( map.path.."/data/earth/cities.dat", map.cities:save())
|
||||||
map.coastlines.save()
|
write( map.path.."/data/earth/coastlines.dat", map.coastlines:save())
|
||||||
map.coastlinesLow.save()
|
write( map.path.."/data/earth/coastlines-low.dat", map.coastlinesLow:save())
|
||||||
map.international.save()
|
write( map.path.."/data/earth/international.dat", map.international:save())
|
||||||
map.sailable.save()
|
map.sailable:save()
|
||||||
map.travelnodes.save()
|
map.travelnodes:save()
|
||||||
map.ainodes.save()
|
map.ainodes:save()
|
||||||
for k, v in pairs(map.territory) do
|
for k, v in pairs(map.territory) do
|
||||||
map.territory[k].save()
|
map.territory[k]:save()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -158,4 +205,8 @@ function map.hover(x, y)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function map.undo()
|
||||||
|
print( "=== UNDO ===" )
|
||||||
|
end
|
||||||
|
|
||||||
return map
|
return map
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
local jit = require 'jit'
|
|
||||||
for k, v in pairs( jit.opt ) do print(k , v ) end
|
|
|
@ -144,11 +144,7 @@ function t.computeBorder( territory, threshold, key )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function t.drawConnections( nodes )
|
function t.save( territory )
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
function t.save( nodes, filename )
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -41,21 +41,26 @@ function travelNode:formatDisplayInfo()
|
||||||
LATITUDE: %3.2f]]):format( self.idx, self.x, self.y )
|
LATITUDE: %3.2f]]):format( self.idx, self.x, self.y )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function worldToBitmap( x, y )
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
local function bitmapToWorld( x, y )
|
||||||
|
return 360 * ( x - 800 ) / 800 - 360 / 2 + 360,
|
||||||
|
360 * ( 600 / 800 ) * ( y - 600 ) / 600 + 180
|
||||||
|
end
|
||||||
|
|
||||||
function t.load( filename, sailable )
|
function t.load( filename, sailable )
|
||||||
|
|
||||||
isSailable = sailable
|
isSailable = sailable
|
||||||
local img, imgd = bmp.load( filename )
|
local img, imgd = bmp.load( filename )
|
||||||
local nodes = { visible = true, nodes = {}, points = {}, connections = {}, img = img }
|
local nodes = { visible = true, nodes = {}, points = {}, connections = {}, img = img }
|
||||||
|
|
||||||
print( "=== Loading Nodes: ===" )
|
|
||||||
local n = 1
|
local n = 1
|
||||||
for x = 0, 799 do
|
for x = 0, 799 do
|
||||||
for y = 0, 399 do
|
for y = 0, 399 do
|
||||||
if imgd:getPixel( x, 399 - y ) > 0 then
|
if imgd:getPixel( x, 399 - y ) > 0 then
|
||||||
local long = 360 * ( x - 800 ) / 800 - 360 / 2 + 360
|
local long, lat = bitmapToWorld( x, y )
|
||||||
local lat = 360 * ( 600 / 800 ) * ( 600 - y ) / 600 - 180
|
nodes.nodes[n] = setmetatable({x = long, y = lat, idx = n}, mtTravelNode )
|
||||||
nodes.nodes[n] = setmetatable({x = long, y = -lat, idx = n}, mtTravelNode )
|
|
||||||
print( nodes.nodes[n]:formatDisplayInfo() )
|
|
||||||
nodes.points[ 2 * n - 1 ] = long
|
nodes.points[ 2 * n - 1 ] = long
|
||||||
nodes.points[ 2 * n ] = lat
|
nodes.points[ 2 * n ] = lat
|
||||||
n = n + 1
|
n = n + 1
|
||||||
|
@ -73,7 +78,6 @@ function t.load( filename, sailable )
|
||||||
nodes.connections[i] = adjacent
|
nodes.connections[i] = adjacent
|
||||||
end
|
end
|
||||||
|
|
||||||
print( "=== Nodes Loaded ===" )
|
|
||||||
nodes.nodes = locationQuery.New( nodes.nodes )
|
nodes.nodes = locationQuery.New( nodes.nodes )
|
||||||
setmetatable( nodes, {__index = t} )
|
setmetatable( nodes, {__index = t} )
|
||||||
return nodes
|
return nodes
|
||||||
|
@ -96,7 +100,7 @@ function t.drawConnections( nodes )
|
||||||
for i, connection in pairs( nodes.connections ) do
|
for i, connection in pairs( nodes.connections ) do
|
||||||
for j in pairs( connection ) do
|
for j in pairs( connection ) do
|
||||||
local ix, iy, fx, fy = nodes.nodes[i].x, nodes.nodes[i].y, nodes.nodes[j].x, nodes.nodes[j].y
|
local ix, iy, fx, fy = nodes.nodes[i].x, nodes.nodes[i].y, nodes.nodes[j].x, nodes.nodes[j].y
|
||||||
lg.line( ix, -iy, fx, -fy )
|
lg.line( ix, iy, fx, fy )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue