北大侠客行MUD论坛

 找回密码
 注册
搜索
热搜: 新手 wiki 升级
查看: 2468|回复: 2

Mudlet无插件看图功能

[复制链接]
发表于 2021-6-13 16:01:22 | 显示全部楼层 |阅读模式
Mudlet 4.10.1 (Deepin 20.1 Linux),没有可用插件,只能自己解决,还好很容易实现,困扰好几个月的切换浏览器打开看图的问题,终于解决。

下面贴出代码。
  1. function hidepiclabel(current_pic_labelName, evt)
  2.   if evt == nil or evt.button == "RightButton" then
  3.     local ln = current_pic_labelName and current_pic_labelName or getProfileName()
  4.     hideWindow(ln)
  5.   end
  6. end

  7. function showpic(_, filename)
  8.   
  9.   if string.ends(filename, ".html") then
  10.     -- read the contents of the webpage in
  11.     local f, s, webpage = io.open(filename)
  12.     if f then webpage = f:read("*a"); io.close(f) end
  13.     -- delete the file on disk, don't clutter
  14.     os.remove(filename)
  15.    
  16.     -- parse our downloaded file for the player count
  17.     -- src="./b2evo_captcha_tmp/b2evo_captcha_CBC7910861405F533B8858798683C6B2.jpg"
  18.     local imgUrl = "http://fullme.pkuxkx.net/".. webpage:match([[src="([^"]+)"]])
  19.     current_pic_filepath = getMudletHomeDir().."/codepic/"..current_html_labelName..".jpg"
  20.     downloadFile(current_pic_filepath, imgUrl)
  21.    
  22.   else
  23.     createLabel(current_html_labelName, codepic[current_html_labelName].x, codepic[current_html_labelName].y, codepic[current_html_labelName].w, codepic[current_html_labelName].h, 1)
  24.     showWindow(current_html_labelName)
  25.    
  26.     setBackgroundImage(current_html_labelName, current_pic_filepath)
  27.    
  28.     setLabelDoubleClickCallback(current_html_labelName, "downloadpic", codepic[current_html_labelName].html, current_html_labelName)
  29.    
  30.     setLabelClickCallback(current_html_labelName, "hidepiclabel", current_html_labelName)
  31.         
  32.     cecho("\n双击刷新图片,右键单击隐藏图片!!!")
  33.   end
  34.   
  35. end

  36. -- 调用入口
  37. function downloadpic(htmlUrl, labelName)
  38.   if not io.exists(getMudletHomeDir().."/codepic/") then
  39.     os.execute("mkdir -p "..getMudletHomeDir().."/codepic/")
  40.   end
  41.   local ln = labelName or getProfileName()
  42.   --debugc("当前labelname.."..ln)
  43.   codepic[ln].html = htmlUrl
  44.   current_html_url = htmlUrl
  45.   current_html_labelName = ln
  46.   current_html_filepath = getMudletHomeDir().."/codepic/"..ln..".html"
  47.   --debugc("图片下载路径1"..current_html_filepath)
  48.   downloadFile(current_html_filepath, htmlUrl)
  49. end


  50. function showpicfail(evt, errorFound)
  51.   cecho("\n下载图片失败,尝试用浏览器打开!")
  52.   openUrl(current_html_url)
  53. end


  54. registerAnonymousEventHandler("sysDownloadDone", "showpic")
  55. --registerAnonymousEventHandler("sysDownloadError", "showpicfail")
复制代码


预定义的变量:
  1. codepic = {
  2.   fullme_xkx = {x = 1000, y = 500, w = 900, h = 110, html = ""},
  3.   xkx = {x = 400, y = 350, w = 1500, h = 110, html = ""}
  4. }
复制代码
北大侠客行Mud(pkuxkx.net),最好的中文Mud游戏!
 楼主| 发表于 2021-6-13 16:13:27 | 显示全部楼层
论坛搞截图好麻烦,附件是演示截图。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
北大侠客行Mud(pkuxkx.net),最好的中文Mud游戏!
 楼主| 发表于 2021-6-13 16:17:49 | 显示全部楼层
上一个是fullme图片,这个是其他图片码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
北大侠客行Mud(pkuxkx.net),最好的中文Mud游戏!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|北大侠客行MUD ( 京ICP备16065414号-1 )

GMT+8, 2024-4-24 03:23 PM , Processed in 0.012829 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表