mirror of
https://github.com/asherao/dcs-scratchpad.git
synced 2025-10-29 16:56:22 +00:00
parent
569109ba62
commit
9018f04209
@ -16,6 +16,113 @@ function scratchpad_load()
|
|||||||
local panel = nil
|
local panel = nil
|
||||||
local textarea = nil
|
local textarea = nil
|
||||||
|
|
||||||
|
local getCoordsLua =
|
||||||
|
[[
|
||||||
|
-- thanks MIST! https://github.com/mrSkortch/MissionScriptingTools/blob/master/mist.lua
|
||||||
|
|
||||||
|
local round = function (num, idp)
|
||||||
|
local mult = 10^(idp or 0)
|
||||||
|
return math.floor(num * mult + 0.5) / mult
|
||||||
|
end
|
||||||
|
|
||||||
|
local tostringLL = function (lat, lon, acc, DMS)
|
||||||
|
local latHemi, lonHemi
|
||||||
|
if lat > 0 then
|
||||||
|
latHemi = 'N'
|
||||||
|
else
|
||||||
|
latHemi = 'S'
|
||||||
|
end
|
||||||
|
|
||||||
|
if lon > 0 then
|
||||||
|
lonHemi = 'E'
|
||||||
|
else
|
||||||
|
lonHemi = 'W'
|
||||||
|
end
|
||||||
|
|
||||||
|
lat = math.abs(lat)
|
||||||
|
lon = math.abs(lon)
|
||||||
|
|
||||||
|
local latDeg = math.floor(lat)
|
||||||
|
local latMin = (lat - latDeg)*60
|
||||||
|
|
||||||
|
local lonDeg = math.floor(lon)
|
||||||
|
local lonMin = (lon - lonDeg)*60
|
||||||
|
|
||||||
|
if DMS then -- degrees, minutes, and seconds.
|
||||||
|
local oldLatMin = latMin
|
||||||
|
latMin = math.floor(latMin)
|
||||||
|
local latSec = round((oldLatMin - latMin)*60, acc)
|
||||||
|
|
||||||
|
local oldLonMin = lonMin
|
||||||
|
lonMin = math.floor(lonMin)
|
||||||
|
local lonSec = round((oldLonMin - lonMin)*60, acc)
|
||||||
|
|
||||||
|
if latSec == 60 then
|
||||||
|
latSec = 0
|
||||||
|
latMin = latMin + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
if lonSec == 60 then
|
||||||
|
lonSec = 0
|
||||||
|
lonMin = lonMin + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
local secFrmtStr -- create the formatting string for the seconds place
|
||||||
|
if acc <= 0 then -- no decimal place.
|
||||||
|
secFrmtStr = '%02d'
|
||||||
|
else
|
||||||
|
local width = 3 + acc -- 01.310 - that's a width of 6, for example.
|
||||||
|
secFrmtStr = '%0' .. width .. '.' .. acc .. 'f'
|
||||||
|
end
|
||||||
|
|
||||||
|
return string.format('%02d', latDeg) .. ' ' .. string.format('%02d', latMin) .. '\' ' .. string.format(secFrmtStr, latSec) .. '"' .. latHemi .. ' '
|
||||||
|
.. string.format('%02d', lonDeg) .. ' ' .. string.format('%02d', lonMin) .. '\' ' .. string.format(secFrmtStr, lonSec) .. '"' .. lonHemi
|
||||||
|
|
||||||
|
else -- degrees, decimal minutes.
|
||||||
|
latMin = round(latMin, acc)
|
||||||
|
lonMin = round(lonMin, acc)
|
||||||
|
|
||||||
|
if latMin == 60 then
|
||||||
|
latMin = 0
|
||||||
|
latDeg = latDeg + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
if lonMin == 60 then
|
||||||
|
lonMin = 0
|
||||||
|
lonDeg = lonDeg + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
local minFrmtStr -- create the formatting string for the minutes place
|
||||||
|
if acc <= 0 then -- no decimal place.
|
||||||
|
minFrmtStr = '%02d'
|
||||||
|
else
|
||||||
|
local width = 3 + acc -- 01.310 - that's a width of 6, for example.
|
||||||
|
minFrmtStr = '%0' .. width .. '.' .. acc .. 'f'
|
||||||
|
end
|
||||||
|
|
||||||
|
return string.format('%02d', latDeg) .. ' ' .. string.format(minFrmtStr, latMin) .. '\'' .. latHemi .. ' '
|
||||||
|
.. string.format('%02d', lonDeg) .. ' ' .. string.format(minFrmtStr, lonMin) .. '\'' .. lonHemi
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local marks = world.getMarkPanels()
|
||||||
|
local result = ""
|
||||||
|
for _, mark in pairs(marks) do
|
||||||
|
local lat, lon = coord.LOtoLL({
|
||||||
|
x = mark.pos.z,
|
||||||
|
y = 0,
|
||||||
|
z = mark.pos.x
|
||||||
|
})
|
||||||
|
local alt = round(land.getHeight({
|
||||||
|
x = mark.pos.z,
|
||||||
|
y = mark.pos.x
|
||||||
|
}), 0)
|
||||||
|
result = result .. "\n" .. tostringLL(lat, lon, 2, true) .. "\n" .. tostring(alt) .. "m, " .. mark.text .. "\n"
|
||||||
|
end
|
||||||
|
return result
|
||||||
|
]]
|
||||||
|
|
||||||
local scratchpad = {
|
local scratchpad = {
|
||||||
logFile = io.open(lfs.writedir() .. [[Logs\Scratchpad.log]], "w")
|
logFile = io.open(lfs.writedir() .. [[Logs\Scratchpad.log]], "w")
|
||||||
}
|
}
|
||||||
@ -115,11 +222,29 @@ function scratchpad_load()
|
|||||||
keyboardLocked = true
|
keyboardLocked = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function insertCoordinates()
|
||||||
|
local coords = net.dostring_in("server", getCoordsLua)
|
||||||
|
local lineCountBefore = textarea:getLineCount()
|
||||||
|
|
||||||
|
if coords == "" then
|
||||||
|
textarea:setText(textarea:getText() .. "\nNo marks found\n")
|
||||||
|
else
|
||||||
|
textarea:setText(textarea:getText() .. coords .. "\n")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- scroll to the bottom of the textarea
|
||||||
|
local lastLine = textarea:getLineCount() - 1
|
||||||
|
local lastLineChar = textarea:getLineTextLength(lastLine)
|
||||||
|
textarea:setSelectionNew(lastLine, 0, lastLine, lastLineLen)
|
||||||
|
scratchpad.saveContent("0000", textarea:getText(), true)
|
||||||
|
end
|
||||||
|
|
||||||
function scratchpad.createWindow()
|
function scratchpad.createWindow()
|
||||||
window = DialogLoader.spawnDialogFromFile(lfs.writedir() .. "Scripts\\Scratchpad\\ScratchpadWindow.dlg", cdata)
|
window = DialogLoader.spawnDialogFromFile(lfs.writedir() .. "Scripts\\Scratchpad\\ScratchpadWindow.dlg", cdata)
|
||||||
windowDefaultSkin = window:getSkin()
|
windowDefaultSkin = window:getSkin()
|
||||||
panel = window.Box
|
panel = window.Box
|
||||||
textarea = panel.ScratchpadEditBox
|
textarea = panel.ScratchpadEditBox
|
||||||
|
insertCoordsBtn = panel.ScratchpadInsertCoordsButton
|
||||||
|
|
||||||
-- setup textarea
|
-- setup textarea
|
||||||
local skin = textarea:getSkin()
|
local skin = textarea:getSkin()
|
||||||
@ -150,6 +275,13 @@ function scratchpad_load()
|
|||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
|
-- setup insert coords button
|
||||||
|
insertCoordsBtn:addMouseDownCallback(
|
||||||
|
function(self)
|
||||||
|
insertCoordinates()
|
||||||
|
end
|
||||||
|
)
|
||||||
|
|
||||||
-- setup window
|
-- setup window
|
||||||
window:setBounds(
|
window:setBounds(
|
||||||
scratchpad.config.windowPosition.x,
|
scratchpad.config.windowPosition.x,
|
||||||
@ -185,7 +317,8 @@ function scratchpad_load()
|
|||||||
local w, h = self:getSize()
|
local w, h = self:getSize()
|
||||||
|
|
||||||
panel:setBounds(0, 0, w, h - 20)
|
panel:setBounds(0, 0, w, h - 20)
|
||||||
textarea:setBounds(0, 0, w, h - 20)
|
textarea:setBounds(0, 0, w, h - 20 - 20)
|
||||||
|
insertCoordsBtn:setBounds(0, h - 40, 50, 20)
|
||||||
|
|
||||||
scratchpad.config.windowSize = {w = w, h = h}
|
scratchpad.config.windowSize = {w = w, h = h}
|
||||||
scratchpad.saveConfiguration()
|
scratchpad.saveConfiguration()
|
||||||
|
|||||||
@ -6,8 +6,8 @@ dialog = {
|
|||||||
["h"] = 200,
|
["h"] = 200,
|
||||||
["w"] = 350,
|
["w"] = 350,
|
||||||
["x"] = 0,
|
["x"] = 0,
|
||||||
["y"] = 0,
|
["y"] = 0
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
["draggable"] = true,
|
["draggable"] = true,
|
||||||
["enabled"] = true,
|
["enabled"] = true,
|
||||||
@ -17,11 +17,11 @@ dialog = {
|
|||||||
["offscreen"] = false,
|
["offscreen"] = false,
|
||||||
["resizable"] = true,
|
["resizable"] = true,
|
||||||
["zOrder"] = 111,
|
["zOrder"] = 111,
|
||||||
["text"] = "Scratchpad",
|
["text"] = "Scratchpad"
|
||||||
},
|
},
|
||||||
["skin"] = {
|
["skin"] = {
|
||||||
["params"] = {
|
["params"] = {
|
||||||
["name"] = "windowSkin",
|
["name"] = "windowSkin"
|
||||||
},
|
},
|
||||||
["skins"] = {
|
["skins"] = {
|
||||||
["header"] = {
|
["header"] = {
|
||||||
@ -32,53 +32,75 @@ dialog = {
|
|||||||
["bottom"] = 2,
|
["bottom"] = 2,
|
||||||
["left"] = 2,
|
["left"] = 2,
|
||||||
["right"] = 2,
|
["right"] = 2,
|
||||||
["top"] = 2,
|
["top"] = 2
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
["states"] = {
|
["states"] = {
|
||||||
["released"] = {
|
["released"] = {
|
||||||
[1] = {
|
[1] = {
|
||||||
["bkg"] = {
|
["bkg"] = {
|
||||||
["center_center"] = "0x00000066",
|
["center_center"] = "0x00000066"
|
||||||
},
|
},
|
||||||
["text"] = {
|
["text"] = {
|
||||||
["color"] = "0xffffffaa",
|
["color"] = "0xffffffaa"
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
[2] = {
|
[2] = {
|
||||||
["bkg"] = {
|
["bkg"] = {
|
||||||
["center_center"] = "0x00000066",
|
["center_center"] = "0x00000066"
|
||||||
},
|
},
|
||||||
["text"] = {
|
["text"] = {
|
||||||
["color"] = "0xffffffaa",
|
["color"] = "0xffffffaa"
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
["states"] = {
|
["states"] = {
|
||||||
["released"] = {
|
["released"] = {
|
||||||
[1] = {
|
[1] = {
|
||||||
["bkg"] = {
|
["bkg"] = {
|
||||||
["center_center"] = "0x00000000",
|
["center_center"] = "0x00000000"
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
["children"] = {
|
["children"] = {
|
||||||
["Box"] = {
|
["Box"] = {
|
||||||
["children"] = {
|
["children"] = {
|
||||||
|
["ScratchpadInsertCoordsButton"] = {
|
||||||
|
["params"] = {
|
||||||
|
["bounds"] = {
|
||||||
|
["h"] = 20,
|
||||||
|
["w"] = 30,
|
||||||
|
["x"] = 0,
|
||||||
|
["y"] = 180
|
||||||
|
},
|
||||||
|
["enabled"] = true,
|
||||||
|
["tabOrder"] = 0,
|
||||||
|
["text"] = "+L/L",
|
||||||
|
["tooltip"] = "Insert Coords",
|
||||||
|
["visible"] = true,
|
||||||
|
["zindex"] = 1
|
||||||
|
},
|
||||||
|
["skin"] = {
|
||||||
|
["params"] = {
|
||||||
|
["name"] = "buttonSkinAwacs"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
["type"] = "Button"
|
||||||
|
},
|
||||||
["ScratchpadEditBox"] = {
|
["ScratchpadEditBox"] = {
|
||||||
["params"] = {
|
["params"] = {
|
||||||
["acceptDecimalPoint"] = false,
|
["acceptDecimalPoint"] = false,
|
||||||
["bounds"] = {
|
["bounds"] = {
|
||||||
["h"] = 100,
|
["h"] = 180,
|
||||||
["w"] = 250,
|
["w"] = 350,
|
||||||
["x"] = 0,
|
["x"] = 0,
|
||||||
["y"] = 0,
|
["y"] = 20
|
||||||
},
|
},
|
||||||
["enabled"] = true,
|
["enabled"] = true,
|
||||||
["multiline"] = true,
|
["multiline"] = true,
|
||||||
@ -90,46 +112,46 @@ dialog = {
|
|||||||
["textWrapping"] = true,
|
["textWrapping"] = true,
|
||||||
["tooltip"] = "",
|
["tooltip"] = "",
|
||||||
["visible"] = true,
|
["visible"] = true,
|
||||||
["zindex"] = 0,
|
["zindex"] = 0
|
||||||
},
|
},
|
||||||
["skin"] = {
|
["skin"] = {
|
||||||
["params"] = {
|
["params"] = {
|
||||||
["name"] = "editBoxNew",
|
["name"] = "editBoxNew"
|
||||||
},
|
},
|
||||||
["states"] = {
|
["states"] = {
|
||||||
["released"] = {
|
["released"] = {
|
||||||
[1] = {
|
[1] = {
|
||||||
["bkg"] = {
|
["bkg"] = {
|
||||||
["center_center"] = "0x00000080",
|
["center_center"] = "0x00000080"
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
["type"] = "EditBox",
|
["type"] = "EditBox"
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
["params"] = {
|
["params"] = {
|
||||||
["bounds"] = {
|
["bounds"] = {
|
||||||
[1] = {
|
[1] = {
|
||||||
["h"] = 467,
|
["h"] = 200,
|
||||||
["w"] = 360,
|
["w"] = 350,
|
||||||
["x"] = 0,
|
["x"] = 0,
|
||||||
["y"] = 55,
|
["y"] = 0
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
["enabled"] = true,
|
["enabled"] = true,
|
||||||
["text"] = "",
|
["text"] = "",
|
||||||
["tooltip"] = "",
|
["tooltip"] = "",
|
||||||
["visible"] = true,
|
["visible"] = true,
|
||||||
["zindex"] = 0,
|
["zindex"] = 0
|
||||||
},
|
},
|
||||||
["skin"] = {
|
["skin"] = {
|
||||||
["params"] = {
|
["params"] = {
|
||||||
["name"] = "panelSkin",
|
["name"] = "panelSkin"
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
["type"] = "Panel",
|
["type"] = "Panel"
|
||||||
},
|
},
|
||||||
["pNoVisible"] = {
|
["pNoVisible"] = {
|
||||||
["children"] = {
|
["children"] = {
|
||||||
@ -139,20 +161,20 @@ dialog = {
|
|||||||
["h"] = 36,
|
["h"] = 36,
|
||||||
["w"] = 40,
|
["w"] = 40,
|
||||||
["x"] = 13,
|
["x"] = 13,
|
||||||
["y"] = 203,
|
["y"] = 203
|
||||||
},
|
},
|
||||||
["enabled"] = true,
|
["enabled"] = true,
|
||||||
["text"] = "Panel1",
|
["text"] = "Panel1",
|
||||||
["tooltip"] = "",
|
["tooltip"] = "",
|
||||||
["visible"] = true,
|
["visible"] = true,
|
||||||
["zindex"] = 0,
|
["zindex"] = 0
|
||||||
},
|
},
|
||||||
["skin"] = {
|
["skin"] = {
|
||||||
["params"] = {
|
["params"] = {
|
||||||
["name"] = "panelSkin",
|
["name"] = "panelSkin"
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
["type"] = "Panel",
|
["type"] = "Panel"
|
||||||
},
|
},
|
||||||
["windowModeFull"] = {
|
["windowModeFull"] = {
|
||||||
["params"] = {
|
["params"] = {
|
||||||
@ -160,50 +182,50 @@ dialog = {
|
|||||||
["h"] = 36,
|
["h"] = 36,
|
||||||
["w"] = 40,
|
["w"] = 40,
|
||||||
["x"] = 13,
|
["x"] = 13,
|
||||||
["y"] = 203,
|
["y"] = 203
|
||||||
},
|
},
|
||||||
["enabled"] = true,
|
["enabled"] = true,
|
||||||
["text"] = "panel0",
|
["text"] = "panel0",
|
||||||
["tooltip"] = "",
|
["tooltip"] = "",
|
||||||
["visible"] = true,
|
["visible"] = true,
|
||||||
["zindex"] = 0,
|
["zindex"] = 0
|
||||||
},
|
},
|
||||||
["skin"] = {
|
["skin"] = {
|
||||||
["params"] = {
|
["params"] = {
|
||||||
["name"] = "panelSkin",
|
["name"] = "panelSkin"
|
||||||
},
|
},
|
||||||
["states"] = {
|
["states"] = {
|
||||||
["released"] = {
|
["released"] = {
|
||||||
[1] = {
|
[1] = {
|
||||||
["bkg"] = {
|
["bkg"] = {
|
||||||
["center_center"] = "0x00000064",
|
["center_center"] = "0x00000064"
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
["type"] = "Panel",
|
["type"] = "Panel"
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
["params"] = {
|
["params"] = {
|
||||||
["bounds"] = {
|
["bounds"] = {
|
||||||
["h"] = 435,
|
["h"] = 435,
|
||||||
["w"] = 228,
|
["w"] = 228,
|
||||||
["x"] = 442,
|
["x"] = 442,
|
||||||
["y"] = 31,
|
["y"] = 31
|
||||||
},
|
},
|
||||||
["enabled"] = true,
|
["enabled"] = true,
|
||||||
["text"] = "panel0",
|
["text"] = "panel0",
|
||||||
["tooltip"] = "",
|
["tooltip"] = "",
|
||||||
["visible"] = false,
|
["visible"] = false,
|
||||||
["zindex"] = 0,
|
["zindex"] = 0
|
||||||
},
|
},
|
||||||
["skin"] = {
|
["skin"] = {
|
||||||
["params"] = {
|
["params"] = {
|
||||||
["name"] = "panelSkin",
|
["name"] = "panelSkin"
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
["type"] = "Panel",
|
["type"] = "Panel"
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user