mirror of
https://github.com/Mjokfox/color_picker.git
synced 2024-12-04 16:04:02 -05:00
Compare commits
2 commits
eea1cbd569
...
5b9370a0de
Author | SHA1 | Date | |
---|---|---|---|
|
5b9370a0de | ||
|
610bff1362 |
2 changed files with 47 additions and 4 deletions
50
init.lua
50
init.lua
|
@ -4,6 +4,8 @@ local mapping_type_index = "2"
|
|||
local dropdown_index = "3"
|
||||
local bars = {"0","100","50"}
|
||||
local fs = {}
|
||||
local LastUpdate = os.time()
|
||||
local job_active = false
|
||||
|
||||
local modpath = minetest.get_modpath(minetest.get_current_modname())
|
||||
dofile(modpath.."/converters.lua")
|
||||
|
@ -15,6 +17,13 @@ if (width == nil) then
|
|||
minetest.settings:set("map_size",64)
|
||||
end
|
||||
|
||||
local mapUpdateTimeout = tonumber(minetest.settings:get("mapUpdateTimeout"))
|
||||
|
||||
if (mapUpdateTimeout == nil) then
|
||||
mapUpdateTimeout = 1
|
||||
minetest.settings:set("mapUpdateTimeout",1)
|
||||
end
|
||||
|
||||
local height = width
|
||||
|
||||
-- helper function
|
||||
|
@ -73,8 +82,14 @@ local function assemble_sliders(x,y,w,h)
|
|||
|
||||
-- slider exact value showing
|
||||
buf[#buf + 1] = "scroll_container[".. x + w + 0.3 ..",".. y + i*h + h*0.2 ..";1,0.6;bar" .. i .. ";vertical;1]"
|
||||
for n = 0, maxs[i] do
|
||||
buf[#buf + 1] = ("label[0,%s;%s".. units[i] .."]"):format(n + h*0.3, n)
|
||||
if (dropdown_index == "1") then
|
||||
for n = 0, maxs[i] do
|
||||
buf[#buf + 1] = ("label[0,%s;%s".. units[i] .."]"):format(n + h*0.3, toHex(n))
|
||||
end
|
||||
else
|
||||
for n = 0, maxs[i] do
|
||||
buf[#buf + 1] = ("label[0,%s;%s".. units[i] .."]"):format(n + h*0.3, n)
|
||||
end
|
||||
end
|
||||
buf[#buf + 1] = "scroll_container_end[]"
|
||||
end
|
||||
|
@ -195,8 +210,35 @@ end
|
|||
|
||||
-- helper function
|
||||
function color_picker.show_formspec(user)
|
||||
assemble_colorspace();
|
||||
minetest.show_formspec(user:get_player_name(), "color_picker:picker", table.concat(fs))
|
||||
if (mapping_type_index == "1") then
|
||||
local now = os.time()
|
||||
local difftime = os.difftime(now,LastUpdate)
|
||||
if (not job_active) then
|
||||
if (difftime > mapUpdateTimeout) then
|
||||
job_active = true
|
||||
|
||||
assemble_colorspace();
|
||||
minetest.show_formspec(user:get_player_name(), "color_picker:picker", table.concat(fs))
|
||||
LastUpdate = now
|
||||
minetest.after(mapUpdateTimeout - difftime, function () job_active = false end)
|
||||
else
|
||||
job_active = true
|
||||
minetest.after(mapUpdateTimeout - difftime,
|
||||
function()
|
||||
assemble_colorspace()
|
||||
minetest.show_formspec(user:get_player_name(), "color_picker:picker", table.concat(fs))
|
||||
LastUpdate = os.time()
|
||||
job_active = false
|
||||
end
|
||||
)
|
||||
end
|
||||
end
|
||||
else
|
||||
-- not map active
|
||||
assemble_colorspace();
|
||||
minetest.show_formspec(user:get_player_name(), "color_picker:picker", table.concat(fs))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- register item
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
# I recommend not going higher than 128, even 64 is quite heavy.
|
||||
map_size (the color maps square dimensions) int 64
|
||||
mapUpdateTimeout (the minimum time between the color map update) int 1
|
Loading…
Reference in a new issue