summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcheapie <no-email-for-you@example.com>2020-04-10 06:15:49 -0500
committercheapie <no-email-for-you@example.com>2020-04-10 06:15:49 -0500
commit181f21b70e2cdd7e5e3e63eb9349f820dbeec72e (patch)
tree43331a3e275bae9c6ef0c6ac59815c67ddb10e35
parenta09ca2193c4d68b178522fd15906b1040b777633 (diff)
downloadTSLib-181f21b70e2cdd7e5e3e63eb9349f820dbeec72e.tar
TSLib-181f21b70e2cdd7e5e3e63eb9349f820dbeec72e.tar.gz
TSLib-181f21b70e2cdd7e5e3e63eb9349f820dbeec72e.tar.bz2
TSLib-181f21b70e2cdd7e5e3e63eb9349f820dbeec72e.tar.xz
TSLib-181f21b70e2cdd7e5e3e63eb9349f820dbeec72e.zip
Add textlist supportHEADmaster
-rw-r--r--README8
-rw-r--r--tslib.lua43
2 files changed, 50 insertions, 1 deletions
diff --git a/README b/README
index a51a75a..9fe1660 100644
--- a/README
+++ b/README
@@ -17,6 +17,10 @@ tslib.getColorEscapeSequence(color)
tslib.colorize(color,message)
Returns the message with the text changed to the given color. Behaves similarly to minetest.colorize().
+
+tslib.explode_textlist_event(event)
+ Converts a textlist event into a table containing a "type" field ("INV" for no row selected, "CHG" for single-click, or "DCL" for double-click) and an "index" field with the item number clicked.
+ Behaves similarly to minetest.explode_textlist_event().
screen:getChannel()
Returns the current channel set for the screen object.
@@ -55,6 +59,10 @@ screen:addTextArea(X,Y,width,height,name,label,default)
screen:addDropdown(X,Y,width,height,name,choices[,selected])
Adds a drop-down menu at the given X-Y position, with the given size, name, and list of choices (which should be a table).
An item can optionally be pre-selected by adding a "selected" value. It will default to 1 (the first choice) if not supplied.
+
+screen:addTextlist(X,Y,width,height,name,choices,selected,transparent)
+ Adds a textlist at the given X-Y position, with the given size, name, and list of choices (which should be a table), optionally transparent, but the transparent flag must be given even if false.
+ The item specified by the "selected" value will be pre-selected, or none if this is 0.
screen:draw()
Sends the buffer contents to the screen.
diff --git a/tslib.lua b/tslib.lua
index 14196ad..1613586 100644
--- a/tslib.lua
+++ b/tslib.lua
@@ -14,6 +14,23 @@ local tslib = {
colorize = function(color,message)
return(string.char(0x1b).."(c@"..color..")"..message..string.char(0x1b).."(c@#FFFFFF)")
end,
+ explode_textlist_event = function(event)
+ local ret = {type = "INV"}
+ if string.sub(event,1,3) == "CHG" then
+ local index = tonumber(string.sub(event,5,-1))
+ if index then
+ ret.type = "CHG"
+ ret.index = index
+ end
+ elseif string.sub(event,1,3) == "DCL" then
+ local index = tonumber(string.sub(event,5,-1))
+ if index then
+ ret.type = "DCL"
+ ret.index = index
+ end
+ end
+ return ret
+ end,
_mt = {
setChannel = function(self,channel)
self._channel = channel
@@ -193,6 +210,31 @@ local tslib = {
}
table.insert(self._commands,cmd)
end,
+ addTextlist = function(self,x,y,w,h,name,choices,selected,transparent)
+ assert((type(x))=="number","Invalid X position")
+ assert((type(y))=="number","Invalid Y position")
+ assert((type(w))=="number","Invalid width")
+ assert((type(h))=="number","Invalid height")
+ if not selected then selected = 1 end
+ assert((type(selected))=="number","Invalid selection index")
+ if type(name) ~= "string" then
+ name = tostring(name)
+ end
+ assert((type(transparent)) == "boolean","Invalid transparent flag")
+ assert((type(choices) == "table" and #choices >= 1),"Invalid choices list")
+ local cmd = {
+ command = "addtextlist",
+ X = x,
+ Y = y,
+ W = w,
+ H = h,
+ name = name,
+ listelements = choices,
+ selected_id = selected,
+ transparent = transparent,
+ }
+ table.insert(self._commands,cmd)
+ end,
},
new = function(self,channel)
local ret = {}
@@ -204,4 +246,3 @@ local tslib = {
return ret
end,
}
-