|
| 1 | +<?xml version="1.0" encoding="UTF-8"?> |
| 2 | +<!DOCTYPE MudletPackage> |
| 3 | +<MudletPackage version="1.001"> |
| 4 | + <ScriptPackage> |
| 5 | + <ScriptGroup isActive="yes" isFolder="yes"> |
| 6 | + <name>GUIDrop</name> |
| 7 | + <packageName></packageName> |
| 8 | + <script>--GUIDrop by Edru |
| 9 | +--6 May 2020 |
| 10 | +--v0.0.1</script> |
| 11 | + <eventHandlerList /> |
| 12 | + <Script isActive="yes" isFolder="no"> |
| 13 | + <name>workaround for add</name> |
| 14 | + <packageName></packageName> |
| 15 | + <script>-- Once Geyser.add2 is in this is not needed anymore |
| 16 | +local addwrapper = Adjustable.Container.add |
| 17 | +function Adjustable.Container:add(window, cons) |
| 18 | + addwrapper(self, window, cons) |
| 19 | + if self.hidden then |
| 20 | + tempTimer(0, function() self:hide() end) |
| 21 | + end |
| 22 | + if self.auto_hidden then |
| 23 | + tempTimer(0, function() self:hide(true) end) |
| 24 | + end |
| 25 | +end</script> |
| 26 | + <eventHandlerList /> |
| 27 | + </Script> |
| 28 | + <Script isActive="yes" isFolder="no"> |
| 29 | + <name>createDropManager</name> |
| 30 | + <packageName></packageName> |
| 31 | + <script>GUIDropManager = GUIDropManager or {} |
| 32 | +GUIDropImages = GUIDropImages or {} |
| 33 | +function GUIDropManager.createDropManager() |
| 34 | + GUIDropManager.script = "--GUIDropManager\n" |
| 35 | + |
| 36 | + local labelscript = [[%s = %s or Geyser.Label:new({name = "%s", x="%s", y="%s", width="%s", height="%s"%s}, %s) |
| 37 | + %s:setStyleSheet("border-image: url(%s);") |
| 38 | + %s.imgName = "%s" |
| 39 | + %s:setDropImg() |
| 40 | + |
| 41 | + ]] |
| 42 | + local containerscript = [[%s = %s or Adjustable.Container:new({name = "%s", x = "%s", y = "%s", width = "%s", height = "%s", lockStyle = "full", padding = 0, noLimit = true%s%s}%s) |
| 43 | + |
| 44 | + ]] |
| 45 | + local function createFname(imgName) |
| 46 | + return [["..getMudletHomeDir().."/GUIDropImages/]].. imgName |
| 47 | + end |
| 48 | + for k,v in pairs(GUIDropImages) do |
| 49 | + |
| 50 | + if v.type == "adjustablecontainer" then |
| 51 | + local container = "" |
| 52 | + local containervar = "" |
| 53 | + local locked = "" |
| 54 | + if v.windowname ~= "main" then |
| 55 | + container = v.containervar or getKeyFrom(v.container, ".container") |
| 56 | + if not container then |
| 57 | + container = "Geyser.windowList."..v.windowname.."Container.windowList."..v.windowname |
| 58 | + end |
| 59 | + containervar = [[, containervar = "]]..container..[["]] |
| 60 | + v.containervar = container |
| 61 | + container = ", "..container |
| 62 | + end |
| 63 | + if v.locked then |
| 64 | + locked = ", locked = true" |
| 65 | + end |
| 66 | + GUIDropManager.script = GUIDropManager.script..string.format(containerscript, v.name, v.name, v.name, v.x, v.y, v.width, v.height, locked, containervar, container) |
| 67 | + end |
| 68 | + |
| 69 | + end |
| 70 | + |
| 71 | + |
| 72 | + for k,v in pairs(GUIDropImages) do |
| 73 | + if v.type == "label" then |
| 74 | + v.fname = v.fname or createFname(v.imgName) |
| 75 | + local clickthrough = "" |
| 76 | + if v.clickthrough then |
| 77 | + clickthrough = ", clickthrough = true" |
| 78 | + end |
| 79 | + GUIDropManager.script = GUIDropManager.script..string.format(labelscript, v.name, v.name, v.name, v.x, v.y, v.width, v.height, clickthrough, v.container.container.name, v.name, v.fname, v.name, v.imgName, v.container.container.name) |
| 80 | + end |
| 81 | + end |
| 82 | + |
| 83 | + if not setScript("GUIDropManager", GUIDropManager.script, 2) then |
| 84 | + display(setScript("GUIDropManager", GUIDropManager.script, 2)) |
| 85 | + end |
| 86 | + |
| 87 | +end</script> |
| 88 | + <eventHandlerList /> |
| 89 | + </Script> |
| 90 | + <Script isActive="yes" isFolder="no"> |
| 91 | + <name>Global Variable Functions</name> |
| 92 | + <packageName></packageName> |
| 93 | + <script>function GUIDropManager.getKeyFrom(value, exclude, depth, table, iteration) |
| 94 | + exclude = exclude or false |
| 95 | + depth = depth or 3 |
| 96 | + table = table or _G |
| 97 | + local tempTable = {} |
| 98 | + iteration = iteration or 1 |
| 99 | + if iteration > depth then |
| 100 | + return nil, "key not found" |
| 101 | + end |
| 102 | + for k,v in pairs(table) do |
| 103 | + if type(v) == "table" and k ~= "_G" then |
| 104 | + for k1,v1 in pairs(v) do |
| 105 | + tempTable[k.."."..k1] = v1 |
| 106 | + end |
| 107 | + end |
| 108 | + if v == value and not string.find(k, exclude) then |
| 109 | + return k |
| 110 | + end |
| 111 | + end |
| 112 | + return GUIDropManager.getKeyFrom(value, exclude, depth, tempTable, iteration + 1) |
| 113 | +end</script> |
| 114 | + <eventHandlerList /> |
| 115 | + </Script> |
| 116 | + <Script isActive="yes" isFolder="no"> |
| 117 | + <name>createDropScript</name> |
| 118 | + <packageName></packageName> |
| 119 | + <script>function GUIDropManager.createDropScript() |
| 120 | + if exists("GUIDropManager", "script") == 0 then |
| 121 | + permGroup("GUIDropManager", "script") |
| 122 | + end |
| 123 | + if exists("GUIDropManager", "script") < 2 then |
| 124 | + permScript("GUIDropManager", "GUIDropManager","--GUIDropManager Script") |
| 125 | + enableScript("GUIDropManager") |
| 126 | + echo("DropScript created!") |
| 127 | + end |
| 128 | + GUIDropManager.createDropManager() |
| 129 | +end</script> |
| 130 | + <eventHandlerList /> |
| 131 | + </Script> |
| 132 | + <Script isActive="yes" isFolder="no"> |
| 133 | + <name>ImageDrop</name> |
| 134 | + <packageName></packageName> |
| 135 | + <script>function GUIDropManager.ImageDrop(event, fname, suffix, posx, posy, consoleName) |
| 136 | + Adjustable.Container:saveAll() |
| 137 | + local acceptable_suffix = {"png", "jpg", "bmp", "jpeg"} |
| 138 | + |
| 139 | + if not table.contains(acceptable_suffix, suffix) then |
| 140 | + return |
| 141 | + end |
| 142 | + local main_width, main_height = getMainWindowSize() |
| 143 | + local image_width, image_height = getImageSize(fname) |
| 144 | + |
| 145 | + if not image_width then |
| 146 | + return |
| 147 | + end |
| 148 | + local image_ratio = image_height / image_width |
| 149 | + if image_width > main_width-50 or image_height > main_height-50 then |
| 150 | + image_height = main_height-50 |
| 151 | + image_width = (main_height-50) / image_ratio |
| 152 | + end |
| 153 | + |
| 154 | + posx = math.max(0, posx - (image_width/10)) |
| 155 | + posy = math.max(0, posy - (image_height/10)) |
| 156 | + local imgName = fname:match("([^%/]+)%..+$") |
| 157 | + |
| 158 | + if not (io.exists(getMudletHomeDir() .. "/GUIDropImages/")) then |
| 159 | + lfs.mkdir(getMudletHomeDir() .. "/GUIDropImages/") |
| 160 | + end |
| 161 | + |
| 162 | + --copy file to my profile location |
| 163 | + local imgLocation = getMudletHomeDir() .. "/GUIDropImages/".. imgName.. ".".. suffix |
| 164 | + local infile = io.open(fname, "rb") |
| 165 | + if not (io.exists(imgLocation)) then |
| 166 | + local instr = infile:read("*ab") |
| 167 | + infile:close() |
| 168 | + local outfile = io.open(imgLocation, "wb") |
| 169 | + outfile:write(instr) |
| 170 | + outfile:close() |
| 171 | + end |
| 172 | + |
| 173 | + local acontainer |
| 174 | + if consoleName == "main" then |
| 175 | + acontainer = Geyser |
| 176 | + else |
| 177 | + acontainer = Geyser.windowList[consoleName.."Container"].windowList[consoleName] |
| 178 | + end |
| 179 | + --convert filename to be a feasible variablename |
| 180 | + local containername = string.gsub(imgName,"[^_%w]","") |
| 181 | + --if filename is only composed of number convert it |
| 182 | + if not containername:match("%D+") then |
| 183 | + containername = "defaultName" |
| 184 | + end |
| 185 | + |
| 186 | + --Check if image exists already and create new containername by adding +1 to the name |
| 187 | + if GUIDropImages[containername] or _G[containername] then |
| 188 | + while GUIDropImages[containername] or _G[containername] do |
| 189 | + counter = containername:match("%d+$") |
| 190 | + if counter ~= nil then |
| 191 | + containername = containername:sub(1,-(string.len(counter)+1)) |
| 192 | + end |
| 193 | + counter = counter or 0 |
| 194 | + counter = counter + 1 |
| 195 | + containername = containername..counter |
| 196 | + end |
| 197 | + end |
| 198 | + |
| 199 | + containername = containername |
| 200 | + local labelname = containername.."Label" |
| 201 | + |
| 202 | + GUIDropImages[containername] = Adjustable.Container:new({name="GUIDropImages."..containername, lockStyle = "full", padding = 0, noLimit = true, autoLoad = false, autoSave = false} , acontainer) |
| 203 | + GUIDropImages[containername]:move(posx, posy) |
| 204 | + GUIDropImages[containername]:resize(image_width, image_height) |
| 205 | + GUIDropImages[containername]:setPercent(true, true) |
| 206 | + GUIDropImages[labelname] = Geyser.Label:new({name = "GUIDropImages."..labelname, x=0, y=0, width="100%", height="100%", clickthrough = true}, GUIDropImages[containername]) |
| 207 | + |
| 208 | + GUIDropImages[labelname].fname = [["..getMudletHomeDir().."/GUIDropImages/]].. imgName .. ".".. suffix |
| 209 | + GUIDropImages[labelname].imgName = imgName .. ".".. suffix |
| 210 | + GUIDropManager.createDropScript() |
| 211 | +end |
| 212 | +registerAnonymousEventHandler("sysDropEvent", "GUIDropManager.ImageDrop")</script> |
| 213 | + <eventHandlerList /> |
| 214 | + </Script> |
| 215 | + <Script isActive="yes" isFolder="no"> |
| 216 | + <name>AdjustableContainer Additions</name> |
| 217 | + <packageName></packageName> |
| 218 | + <script>local function deleteImage(s) |
| 219 | + GUIDropImages[string.gsub(s.name,"GUIDropImages%.","")] = nil |
| 220 | + GUIDropImages[string.gsub(s.name.."Label", "GUIDropImages%.","")] = nil |
| 221 | + table.remove(Adjustable.Container.all, table.index_of(Adjustable.Container.all, s)) |
| 222 | + if io.exists(getMudletHomeDir().."/AdjustableContainer/"..s.name..".lua") then |
| 223 | + os.remove(getMudletHomeDir().."/AdjustableContainer/"..s.name..".lua") |
| 224 | + end |
| 225 | + s:hide() |
| 226 | +end |
| 227 | + |
| 228 | +local function convertToLabel(s) |
| 229 | + local labelscript = [[%s = %s or Geyser.Label:new({name = "%s", x="%s", y="%s", width="%s", height="%s"}%s) |
| 230 | + %s:setStyleSheet("border-image: url(%s);") |
| 231 | + ]] |
| 232 | + local container = GUIDropImages[string.gsub(s.name,"GUIDropImages%.","")] |
| 233 | + local labelname = string.gsub(s.name.."Label", "GUIDropImages%.","") |
| 234 | + GUIDropImages[labelname]:changeContainer(container.container) |
| 235 | + GUIDropImages[labelname]:move(container.x, container.y) |
| 236 | + GUIDropImages[labelname]:resize(container.width, container.height) |
| 237 | + |
| 238 | + if exists("GUIDropManager", "script") == 0 then |
| 239 | + permGroup("GUIDropManager", "script") |
| 240 | + end |
| 241 | + |
| 242 | + if exists("GUIDropLabels", "script") == 0 then |
| 243 | + permScript("GUIDropLabels", "GUIDropManager","--GUIDropLabels Script") |
| 244 | + enableScript("GUIDropLabels") |
| 245 | + echo("LabelScript created!") |
| 246 | + end |
| 247 | + |
| 248 | + if container.containervar then |
| 249 | + container.containervar = ","..container.containervar |
| 250 | + else |
| 251 | + container.containervar = "" |
| 252 | + end |
| 253 | + |
| 254 | + local label = GUIDropImages[string.gsub(s.name.."Label", "GUIDropImages%.","")] |
| 255 | + labelname = labelname:sub(1,-6) |
| 256 | + labelscript = string.format(labelscript, labelname, labelname, labelname, label.x, label.y, label.width, label.height, container.containervar, labelname, [["..getMudletHomeDir().."/GUIDropImages/]].. label.imgName) |
| 257 | + |
| 258 | + appendScript("GUIDropLabels", labelscript) |
| 259 | + |
| 260 | + GUIDropImages[string.gsub(s.name,"GUIDropImages%.","")]:hide() |
| 261 | + GUIDropImages[string.gsub(s.name,"GUIDropImages%.","")] = nil |
| 262 | + GUIDropImages[string.gsub(s.name.."Label", "GUIDropImages%.","")] = nil |
| 263 | + table.remove(Adjustable.Container.all, table.index_of(Adjustable.Container.all, s)) |
| 264 | + if io.exists(getMudletHomeDir().."/AdjustableContainer/"..s.name..".lua") then |
| 265 | + os.remove(getMudletHomeDir().."/AdjdustableContainer/"..s.name..".lua") |
| 266 | + end |
| 267 | +end |
| 268 | + |
| 269 | + |
| 270 | +function Adjustable.Container:setDropImg() |
| 271 | + if self.dropImg then |
| 272 | + return |
| 273 | + end |
| 274 | + |
| 275 | + self.dropImg = true |
| 276 | + self.adjLabelstyle =[[ |
| 277 | + QLabel::hover{ background-color: rgba(0,0,0,0%); border: 1px solid grey;} |
| 278 | + QLabel::!hover{ background-color: rgba(0,0,0,0%);}]] |
| 279 | + if not self.locked then |
| 280 | + self.adjLabel:setStyleSheet(self.adjLabelstyle) |
| 281 | + else |
| 282 | + self.adjLabel:setStyleSheet([[border:0;]]) |
| 283 | + end |
| 284 | + self:setTitle(" ") |
| 285 | + self.minimizeLabel:raise() |
| 286 | + self.exitLabel:raise() |
| 287 | + |
| 288 | + self:newCustomItem("setAbsolute", function(s) s:setAbsolute(true, true) self:save() end) |
| 289 | + self:newCustomItem("setPercent", function(s) s:setPercent(true, true) self:save() end) |
| 290 | + self:newCustomItem("deleteImage", function(s) deleteImage(s) GUIDropManager.createDropManager() Adjustable.Container:saveAll() end) |
| 291 | + self:newCustomItem("convertToLabel", function(s) convertToLabel(s) GUIDropManager.createDropManager() Adjustable.Container:saveAll() end) |
| 292 | + self:newCustomItem("saveAll", function(s) Adjustable.Container:saveAll() end) |
| 293 | + self:newCustomItem("loadAll", function(s) Adjustable.Container:saveAll() end) |
| 294 | + self:newCustomItem("updateScript", function(s) Adjustable.Container:saveAll() GUIDropManager.createDropManager() end) |
| 295 | +end</script> |
| 296 | + <eventHandlerList /> |
| 297 | + </Script> |
| 298 | + </ScriptGroup> |
| 299 | + </ScriptPackage> |
| 300 | +</MudletPackage> |
0 commit comments