標題: [教學主題] MUSHclient 裝備視窗
bugs99
名望的騎士
Rank: 4



UID 88
精華 0
積分 397
帖子 14
銅幣 1188 枚
銀幣 18 枚
金幣 0 枚
閱讀權限 25
註冊 2008-12-26
用戶註冊天數 5603
用戶失蹤天數 1
狀態 離線
68.150.22.188
分享 
發表於 2024-3-29 17:29  資料 文集 私人訊息 
MUSHclient 裝備視窗
這是試驗後可以用的


local equipment = {}
local max_width = WindowTextWidth (win, font, "你正在使用的裝備有:")
-- loop until end of equipment
while true do
  local line, wildcards, styles = wait.match ("*")
-- see if end of equipment
  if not string.match (line, "^\<") then
   break
  end -- if
-- save equipment line
  table.insert (equipment, styles)
-- work out max width
  max_width = math.max (max_width, WindowTextWidth (win, font, line))
end -- while loop
local font_height = WindowFontInfo (win, font, 1)
local window_width = max_width + 10
local window_height = font_height * (#equipment + 2) + 10
-- make window correct size
WindowCreate (win, 0, 0, window_width, window_height, 8, 0, ColourNameToRGB "#373737")
WindowRectOp (win, 5, 0, 0, 0, 0, 5, 15 + 0x1000)
-- heading line
WindowText (win, font, "你正在使用的裝備有:", 5, 5, 0, 0, ColourNameToRGB "yellow")
-- draw each equipment line
local y = font_height * 2 + 5
for i, styles in pairs (equipment) do
  local x = 5
  for _, style in ipairs (styles) do
   x = x + WindowText (win, font, style.text, x, y, 0, 0, style.textcolour)
  end -- for
  y = y + font_height
end -- for each equipment item
WindowShow (win, true)
end)  -- end of coroutine
頂部