initial commit

This commit is contained in:
Markus Ast
2018-12-06 22:54:26 +01:00
commit 2619cfc2aa
3 changed files with 414 additions and 0 deletions

View File

@@ -0,0 +1,193 @@
function scratchpad_load()
package.path = package.path..";.\\LuaSocket\\?.lua;"..'.\\Scripts\\?.lua;'.. '.\\Scripts\\UI\\?.lua;'
package.cpath = package.cpath..";.\\LuaSocket\\?.dll;"
local JSON = loadfile("Scripts\\JSON.lua")()
local lfs = require('lfs')
local U = require('me_utilities')
local Skin = require('Skin')
local DialogLoader = require('DialogLoader')
local Tools = require('tools')
local Input = require('Input')
local isHidden = true
local keyboardLocked = false
local window = nil
local windowDefaultSkin = nil
local windowSkinHidden = Skin.windowSkinChatMin()
local panel = nil
local textarea = nil
local scratchpad = {
logFile = io.open(lfs.writedir()..[[Logs\Scratchpad.log]], "w")
}
function scratchpad.loadConfiguration()
scratchpad.log("Loading config file...")
local tbl = Tools.safeDoFile(lfs.writedir() .. 'Config/ScratchpadConfig.lua', false)
if (tbl and tbl.config) then
scratchpad.log("Configuration exists...")
scratchpad.config = tbl.config
else
scratchpad.log("Configuration not found, creating defaults...")
scratchpad.config = {
hotkey = "Ctrl+Shift+x",
windowPosition = { x = 200, y = 200 },
windowSize = { w = 350, h = 150 },
content = "Start writing here ...",
}
scratchpad.saveConfiguration()
end
end
function scratchpad.saveConfiguration()
U.saveInFile(scratchpad.config, 'config', lfs.writedir() .. 'Config/ScratchpadConfig.lua')
end
function scratchpad.log(str)
if not str then
return
end
if scratchpad.logFile then
scratchpad.logFile:write("["..os.date("%H:%M:%S").."] "..str.."\r\n")
scratchpad.logFile:flush()
end
end
local function unlockKeyboardInput(releaseKeyboardKeys)
if keyboardLocked then
DCS.unlockKeyboardInput(releaseKeyboardKeys)
keyboardLocked = false
end
end
local function lockKeyboardInput()
if keyboardLocked then
return
end
local keyboardEvents = Input.getDeviceKeys(Input.getKeyboardDeviceName())
DCS.lockKeyboardInput(keyboardEvents)
keyboardLocked = true
end
function scratchpad.createWindow()
window = DialogLoader.spawnDialogFromFile(lfs.writedir() .. 'Scripts\\Scratchpad\\ScratchpadWindow.dlg', cdata)
windowDefaultSkin = window:getSkin()
panel = window.Box
textarea = panel.ScratchpadEditBox
-- setup textarea
textarea:setText(scratchpad.config.content)
textarea:addChangeCallback(function(self)
scratchpad.config.content = self:getText()
scratchpad.saveConfiguration()
end)
textarea:addFocusCallback(function(self)
if self:getFocused() then
lockKeyboardInput()
else
unlockKeyboardInput(true)
end
end)
textarea:addKeyDownCallback(function(self, keyName, unicode)
if keyName == 'escape' then
self:setFocused(false)
unlockKeyboardInput(true)
end
end)
-- setup window
window:setBounds(
scratchpad.config.windowPosition.x,
scratchpad.config.windowPosition.y,
scratchpad.config.windowSize.w,
scratchpad.config.windowSize.h
)
scratchpad.handleResize(window)
window:addHotKeyCallback(scratchpad.config.hotkey, function()
if isHidden == true then
scratchpad.show()
else
scratchpad.hide()
end
end)
window:addSizeCallback(scratchpad.handleResize)
window:addPositionCallback(scratchpad.handleMove)
window:setVisible(true)
scratchpad.hide()
scratchpad.log("Scratchpad Window created")
end
function scratchpad.setVisible(b)
window:setVisible(b)
end
function scratchpad.handleResize(self)
local w, h = self:getSize()
panel:setBounds(0, 0, w, h - 20)
textarea:setBounds(0, 0, w, h - 20)
scratchpad.config.windowSize = { w = w, h = h }
scratchpad.saveConfiguration()
end
function scratchpad.handleMove(self)
local x, y = self:getPosition()
scratchpad.config.windowPosition = { x = x, y = y }
scratchpad.saveConfiguration()
end
function scratchpad.show()
if window == nil then
local status, err = pcall(scratchpad.createWindow)
if not status then
net.log("[Scratchpad] Error creating window: " .. tostring(err))
end
end
window:setVisible(true)
window:setSkin(windowDefaultSkin)
panel:setVisible(true)
window:setHasCursor(true)
isHidden = false
end
function scratchpad.hide()
window:setSkin(windowSkinHidden)
panel:setVisible(false)
textarea:setFocused(false)
window:setHasCursor(false)
-- window.setVisible(false) -- if you make the window invisible, its destroyed
unlockKeyboardInput(true)
isHidden = true
end
function scratchpad.onSimulationFrame()
if scratchpad.config == nil then
scratchpad.loadConfiguration()
end
if not window then
scratchpad.log("Creating Scratchpad window hidden...")
scratchpad.createWindow()
end
end
DCS.setUserCallbacks(scratchpad)
net.log("[Scratchpad] Loaded ...")
end
local status, err = pcall(scratchpad_load)
if not status then
net.log("[Scratchpad] Load Error: " .. tostring(err))
end

View File

@@ -0,0 +1,209 @@
dialog = {
["type"] = "Window",
["params"] = {
["bounds"] = {
[1] = {
["h"] = 200,
["w"] = 350,
["x"] = 0,
["y"] = 0,
},
},
["draggable"] = true,
["enabled"] = true,
["hasCursor"] = true,
["lockFlow"] = false,
["modal"] = false,
["offscreen"] = false,
["resizable"] = true,
["zOrder"] = 111,
["text"] = "Scratchpad",
},
["skin"] = {
["params"] = {
["name"] = "windowSkin",
},
["skins"] = {
["header"] = {
["skinData"] = {
["params"] = {
["hasCloseButton"] = false,
["insets"] = {
["bottom"] = 2,
["left"] = 2,
["right"] = 2,
["top"] = 2,
},
},
["states"] = {
["released"] = {
[1] = {
["bkg"] = {
["center_center"] = "0x00000066",
},
["text"] = {
["color"] = "0xffffffaa",
},
},
[2] = {
["bkg"] = {
["center_center"] = "0x00000066",
},
["text"] = {
["color"] = "0xffffffaa",
},
},
},
},
},
},
},
["states"] = {
["released"] = {
[1] = {
["bkg"] = {
["center_center"] = "0x00000000",
},
},
},
},
},
["children"] = {
["Box"] = {
["children"] = {
["ScratchpadEditBox"] = {
["params"] = {
["acceptDecimalPoint"] = false,
["bounds"] = {
["h"] = 100,
["w"] = 250,
["x"] = 0,
["y"] = 0,
},
["enabled"] = true,
["multiline"] = true,
["numeric"] = false,
["password"] = false,
["readOnly"] = false,
["tabOrder"] = 80,
["text"] = "...",
["textWrapping"] = true,
["tooltip"] = "",
["visible"] = true,
["zindex"] = 0,
},
["skin"] = {
["params"] = {
["name"] = "editBoxNew",
},
["states"] = {
["released"] = {
[1] = {
["bkg"] = {
["center_center"] = "0x00000080",
},
},
},
},
},
["type"] = "EditBox",
},
},
["params"] = {
["bounds"] = {
[1] = {
["h"] = 467,
["w"] = 360,
["x"] = 0,
["y"] = 55,
},
},
["enabled"] = true,
["text"] = "",
["tooltip"] = "",
["visible"] = true,
["zindex"] = 0,
},
["skin"] = {
["params"] = {
["name"] = "panelSkin",
},
},
["type"] = "Panel",
},
["pNoVisible"] = {
["children"] = {
["windowModeMin"] = {
["params"] = {
["bounds"] = {
["h"] = 36,
["w"] = 40,
["x"] = 13,
["y"] = 203,
},
["enabled"] = true,
["text"] = "Panel1",
["tooltip"] = "",
["visible"] = true,
["zindex"] = 0,
},
["skin"] = {
["params"] = {
["name"] = "panelSkin",
},
},
["type"] = "Panel",
},
["windowModeFull"] = {
["params"] = {
["bounds"] = {
["h"] = 36,
["w"] = 40,
["x"] = 13,
["y"] = 203,
},
["enabled"] = true,
["text"] = "panel0",
["tooltip"] = "",
["visible"] = true,
["zindex"] = 0,
},
["skin"] = {
["params"] = {
["name"] = "panelSkin",
},
["states"] = {
["released"] = {
[1] = {
["bkg"] = {
["center_center"] = "0x00000064",
},
},
},
},
},
["type"] = "Panel",
},
},
["params"] = {
["bounds"] = {
["h"] = 435,
["w"] = 228,
["x"] = 442,
["y"] = 31,
},
["enabled"] = true,
["text"] = "panel0",
["tooltip"] = "",
["visible"] = false,
["zindex"] = 0,
},
["skin"] = {
["params"] = {
["name"] = "panelSkin",
},
},
["type"] = "Panel",
},
},
}