Add "bookmarks_gui" mod.
This commit is contained in:
parent
cf84516a55
commit
6b88a29be6
@ -110,6 +110,7 @@ The following mods are also included:
|
||||
* [carts][] ([WTFPL/CC0](mods/transport/carts/README.txt))
|
||||
* [hovercraft][] ([LGPL / CC BY-SA / CC0](mods/transport/hovercraft/LICENSE.txt))
|
||||
* ui/
|
||||
* [bookmarks_gui][] ([BSD 3-Clause](mods/ui/bookmarks_gui/LICENSE))
|
||||
* [hud][] ([LGPL / CC BY-SA / WTFPL](mods/ui/hud/README.txt))
|
||||
* [hudmap][] ([LGPL / WTFPL](mods/ui/hudmap/README.txt))
|
||||
* [vector_extras][] ([WTFPL](mods/vector_extras/LICENSE.txt))
|
||||
@ -136,6 +137,7 @@ The following mods are also included:
|
||||
[away]: https://forum.minetest.net/viewtopic.php?t=1211
|
||||
[bags]: http://cornernote.github.io/minetest-bags/
|
||||
[biome_lib]: https://forum.minetest.net/viewtopic.php?f=11&t=12999
|
||||
[bookmarks_gui]: http://cornernote.github.io/minetest-bookmarks_gui/
|
||||
[campfire]: https://forum.minetest.net/viewtopic.php?t=10569
|
||||
[carts]: https://forum.minetest.net/viewtopic.php?t=2451
|
||||
[character_creator]: https://forum.minetest.net/viewtopic.php?f=9&t=13138
|
||||
|
32
mods/ui/bookmarks_gui/LICENSE
Normal file
32
mods/ui/bookmarks_gui/LICENSE
Normal file
@ -0,0 +1,32 @@
|
||||
Copyright (c) 2013, Brett O'Donnell http://cornernote.github.io
|
||||
All rights reserved.
|
||||
_____ _____ _____ _____ _____ _____
|
||||
| |___| __ | | |___| __ | | |___|_ _|___
|
||||
| --| . | -| | | | -_| -| | | | . | | | | -_|
|
||||
|_____|___|__|__|_|___|___|__|__|_|___|___| |_| |___|
|
||||
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
* Neither the name of the organization nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
43
mods/ui/bookmarks_gui/README.md
Normal file
43
mods/ui/bookmarks_gui/README.md
Normal file
@ -0,0 +1,43 @@
|
||||
# Bookmarks GUI for Minetest
|
||||
|
||||
[](http://cornernote.github.io/minetest-bookmarks_gui/)
|
||||
[](https://github.com/cornernote/minetest-bookmarks_gui/archive/master.zip)
|
||||
[](https://github.com/cornernote/minetest-bookmarks_gui)
|
||||
[](http://forum.minetest.net/viewtopic.php?f=11&t=3219)
|
||||
[](https://minetest-bower.herokuapp.com/mods/bookmarks_gui)
|
||||
|
||||
|
||||
## Description
|
||||
|
||||
Allows players to set bookmark positions and then go to them using the inventory screen.
|
||||
|
||||
|
||||
## Features
|
||||
|
||||
- Allows players to set bookmark positions and then go to them using the inventory screen.
|
||||
- Server priv is required to set bookmarks.
|
||||
|
||||
|
||||
## Project Resources
|
||||
|
||||
* [Home](http://cornernote.github.io/minetest-bookmarks_gui/)
|
||||
* [Download](https://github.com/cornernote/minetest-bookmarks_gui/archive/master.zip)
|
||||
* [Project](https://github.com/cornernote/minetest-bookmarks_gui)
|
||||
* [Forum](http://forum.minetest.net/viewtopic.php?f=11&t=3219)
|
||||
* [Bower](https://minetest-bower.herokuapp.com/mods/bookmarks_gui)
|
||||
|
||||
|
||||
## Support
|
||||
|
||||
- Does this README need improvement? Go ahead and [suggest a change](https://github.com/cornernote/minetest-bookmarks_gui/edit/master/README.md).
|
||||
- Found a bug, or need help using this project? Check the [open issues](https://github.com/cornernote/minetest-bookmarks_gui/issues) or [create an issue](https://github.com/cornernote/minetest-bookmarks_gui/issues/new).
|
||||
|
||||
|
||||
## About
|
||||
|
||||
This module is open source, so it's distributed freely. If you find it useful then I ask not for your wealth, but simply to spare your time to consider the world we share by watching [Earthlings](http://earthlings.com/), a multi-award winning film available to watch online for free. A must-see for anyone who wishes to make the world a better place.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
[BSD-3-Clause](https://raw.github.com/cornernote/minetest-bookmarks_gui/master/LICENSE), Copyright © 2013-2014 [Brett O'Donnell](http://cornernote.github.io/)
|
1
mods/ui/bookmarks_gui/depends.txt
Normal file
1
mods/ui/bookmarks_gui/depends.txt
Normal file
@ -0,0 +1 @@
|
||||
inventory_plus
|
176
mods/ui/bookmarks_gui/init.lua
Normal file
176
mods/ui/bookmarks_gui/init.lua
Normal file
@ -0,0 +1,176 @@
|
||||
--[[
|
||||
|
||||
Bookmarks GUI for Minetest
|
||||
|
||||
Copyright (c) 2012 cornernote, Brett O'Donnell <cornernote@gmail.com>
|
||||
Source Code: https://github.com/cornernote/minetest-bookmarks_gui
|
||||
License: BSD-3-Clause https://raw.github.com/cornernote/minetest-bookmarks_gui/master/LICENSE
|
||||
|
||||
]]--
|
||||
|
||||
-- expose api
|
||||
bookmarks_gui = {}
|
||||
|
||||
-- filename
|
||||
bookmarks_gui.filename = minetest.get_worldpath()..'/bookmarks_gui'
|
||||
|
||||
-- load_bookmarks
|
||||
local bookmarkspos = {}
|
||||
local load_bookmarks = function()
|
||||
local input = io.open(bookmarks_gui.filename..".bookmarks", "r")
|
||||
if input then
|
||||
while true do
|
||||
local x = input:read("*n")
|
||||
if x == nil then
|
||||
break
|
||||
end
|
||||
local y = input:read("*n")
|
||||
local z = input:read("*n")
|
||||
local name = input:read("*l")
|
||||
table.insert(bookmarkspos,{name=name:sub(2),x=x,y=y,z=z})
|
||||
end
|
||||
io.close(input)
|
||||
else
|
||||
bookmarkspos = {}
|
||||
end
|
||||
end
|
||||
load_bookmarks() -- run it now
|
||||
|
||||
-- set
|
||||
bookmarks_gui.set = function(name, pos)
|
||||
name = string.lower(string.gsub(name, "%W", "_"))
|
||||
for i, v in ipairs(bookmarkspos) do
|
||||
if v.name==name then
|
||||
table.remove(bookmarkspos,i)
|
||||
end
|
||||
end
|
||||
table.insert(bookmarkspos,{name=name,x=pos.x,y=pos.y,z=pos.z})
|
||||
-- save the bookmarks data from the table to the file
|
||||
local output = io.open(bookmarks_gui.filename..".bookmarks", "w")
|
||||
for i, v in ipairs(bookmarkspos) do
|
||||
if v ~= nil then
|
||||
output:write(math.floor(v.x).." "..math.floor(v.y).." "..math.floor(v.z).." "..v.name.."\n")
|
||||
end
|
||||
end
|
||||
io.close(output)
|
||||
end
|
||||
|
||||
-- del
|
||||
bookmarks_gui.del = function(name, pos)
|
||||
name = string.lower(string.gsub(name, "%W", "_"))
|
||||
for i, v in ipairs(bookmarkspos) do
|
||||
if v.name==name then
|
||||
table.remove(bookmarkspos,i)
|
||||
end
|
||||
end
|
||||
-- save the bookmarks data from the table to the file
|
||||
local output = io.open(bookmarks_gui.filename..".bookmarks", "w")
|
||||
for i, v in ipairs(bookmarkspos) do
|
||||
if v ~= nil then
|
||||
output:write(math.floor(v.x).." "..math.floor(v.y).." "..math.floor(v.z).." "..v.name.."\n")
|
||||
end
|
||||
end
|
||||
io.close(output)
|
||||
end
|
||||
|
||||
-- go
|
||||
bookmarks_gui.go = function(name, player)
|
||||
name = string.lower(string.gsub(name, "%W", "_"))
|
||||
local pos
|
||||
for i, v in ipairs(bookmarkspos) do
|
||||
if v.name==name then
|
||||
pos = v
|
||||
break
|
||||
end
|
||||
end
|
||||
if pos~=nil then
|
||||
-- move bookmark to the top of the list
|
||||
local bmp = {}
|
||||
for i,v in ipairs(bookmarkspos) do
|
||||
if v.name~=name then
|
||||
table.insert(bmp,v)
|
||||
end
|
||||
end
|
||||
table.insert(bmp,pos)
|
||||
bookmarkspos = bmp
|
||||
-- teleport player
|
||||
player:setpos(pos)
|
||||
end
|
||||
end
|
||||
|
||||
-- formspec
|
||||
bookmarks_gui.formspec = function(player)
|
||||
local formspec = "size[14,10]"
|
||||
.."button[0,9.5;2,0.5;main;Back]"
|
||||
local pages = bookmarks_gui.get_names()
|
||||
local x,y = 0,0
|
||||
local p
|
||||
for i = #pages,1,-1 do
|
||||
p = pages[i]
|
||||
if x == 14 then
|
||||
y = y+1
|
||||
x = 0
|
||||
end
|
||||
formspec = formspec .."button_exit["..(x)..","..(y)..";2,0.5;bookmarks_gui_jump;"..p.."]"
|
||||
x = x+2
|
||||
end
|
||||
if #pages == 0 then
|
||||
formspec = formspec
|
||||
.."label[4,3; --== Bookmarks GUI ==--]"
|
||||
.."label[4,4.5; Create as many bookmarks as you like!]"
|
||||
.."label[4,5.0; Simply enter a name for your bookmark]"
|
||||
.."label[4,5.5; then click Go.]"
|
||||
end
|
||||
formspec = formspec
|
||||
.."field[2.5,9.6;2,1;bookmarks_gui_go_name;;]"
|
||||
.."button_exit[4,9.5;1,0.5;bookmarks_gui_go;Go]"
|
||||
if minetest.check_player_privs(player:get_player_name(), {server=true}) then
|
||||
formspec = formspec
|
||||
.."field[8.5,9.6;2,1;bookmarks_gui_del_name;;]"
|
||||
.."button_exit[10,9.5;1,0.5;bookmarks_gui_del;Del]"
|
||||
.."field[11.5,9.6;2,1;bookmarks_gui_set_name;;]"
|
||||
.."button_exit[13,9.5;1,0.5;bookmarks_gui_set;Set]"
|
||||
end
|
||||
return formspec
|
||||
end
|
||||
|
||||
-- get_names
|
||||
bookmarks_gui.get_names = function()
|
||||
local pages = {}
|
||||
for i,v in ipairs(bookmarkspos) do
|
||||
table.insert(pages,v.name)
|
||||
end
|
||||
return pages
|
||||
end
|
||||
|
||||
-- register_on_joinplayer
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
-- add inventory_plus page
|
||||
inventory_plus.register_button(player,"bookmarks_gui","Bookmarks")
|
||||
end)
|
||||
|
||||
-- register_on_player_receive_fields
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if fields.bookmarks_gui_set and fields.bookmarks_gui_set_name then
|
||||
if minetest.check_player_privs(player:get_player_name(), {server=true}) then
|
||||
bookmarks_gui.set(fields.bookmarks_gui_set_name, player:getpos())
|
||||
end
|
||||
end
|
||||
if fields.bookmarks_gui_del and fields.bookmarks_gui_del_name then
|
||||
if minetest.check_player_privs(player:get_player_name(), {server=true}) then
|
||||
bookmarks_gui.del(fields.bookmarks_gui_del_name, player:getpos())
|
||||
end
|
||||
end
|
||||
if fields.bookmarks_gui_go and fields.bookmarks_gui_go_name then
|
||||
bookmarks_gui.go(fields.bookmarks_gui_go_name, player)
|
||||
end
|
||||
if fields.bookmarks_gui_jump then
|
||||
bookmarks_gui.go(fields.bookmarks_gui_jump, player)
|
||||
end
|
||||
if fields.bookmarks_gui or fields.bookmarks_gui_set or fields.bookmarks_gui_del or fields.bookmarks_gui_go or fields.bookmarks_gui_jump then
|
||||
inventory_plus.set_inventory_formspec(player, bookmarks_gui.formspec(player))
|
||||
end
|
||||
end)
|
||||
|
||||
-- log that we started
|
||||
minetest.log("action", "[MOD]"..minetest.get_current_modname().." -- loaded from "..minetest.get_modpath(minetest.get_current_modname()))
|
BIN
mods/ui/bookmarks_gui/screenshot.png
Normal file
BIN
mods/ui/bookmarks_gui/screenshot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 177 KiB |
Loading…
x
Reference in New Issue
Block a user