settings screen, hud color, alternate compass images

master
Kilarin 2014-06-01 19:12:06 -05:00
parent ea8e16007c
commit eb85596a47
26 changed files with 175 additions and 72 deletions

24
README
View File

@ -25,7 +25,7 @@ The hud updates constantly as long as the compass is in one of your active inven
There is a GUI that pops up whenever you wield the compass and left click. I never played with a GUI in minetest before, so this was a new experience for me, I learned a lot and made quite a few changes:
[img]http://i59.tinypic.com/210bxvt.png[/img]
[IMG]http://i61.tinypic.com/29zzgy1.png[/IMG]
The bookmark list has been expanded from a dropdown into a textlist to improve visibility. Select any bookmark in the list by clicking on it, and then click "Find Selected Bookmark" to make the compass (and hud) point at that location. "default" is always at the top of the list and will point to (0,0,0) or your bed from PilzAdams bed-mod, or home location as defined in the sethome-mod. (Setting default to your bed or sethome is old code, I modified it to make it work with my new version, but I cant take credit for the idea or basic structure.) The rest of the list are bookmarked locations that you have set and named
@ -33,12 +33,19 @@ Just click in the "Sort by" box to change whether the bookmarks are sorted by na
Click in the "Dist" box to change whether the distance is calculated in 3d (including your distance in the vertical direction) or in 2d (x and z coords only, ignore vertical distance)
I figured the position of the hud text was likely to be something that people would want to customize, so right there in the gui are the x and y coords for the hud text. Just enter the new coords where you want the hud text to appear and click "Change Hud Pos"
The cords must be between 0 and 1 and represent a percentage of the screen, so x=0 would put the text at the far left of the screen, and y=0.98 would put the text almost at the bottom of the screen. The default is x=0.4 and y=0.01, and that is displayed right over the input boxes so the user can easily set them back to the default if they are having trouble placing the hud. If you change either the x or y coord to a number that is out of range (less than 0 or greater than 1) then the hud will not be displayed. That makes it easy to turn the hud off if you wish.
Down at the lower right of the screen, I'm certain you noticed the "Teleport to bookmark" button. That button appears if, and ONLY IF the player has teleport privileges. If they do, then they can select any bookmark out of the list, click on teleport, and be instantly transported to the location of that bookmark. Since the user already had teleport privileges, this just saved them some typing, it's not adding any new abilities.
The bookmark list is saved any time a user changes it. All of your other settings, the currently selected bookmark, sort order, distance function, and hud position, are saved whenever a user leaves the game, and on game shutdown. so if you move the hud down to the lower right hand corner of the screen, and then quit, the hud will still be in the place you put it when you restart the game later.
If you click the "Settings" button in the upper right hand corner it brings up a screen where you can customize the appearance of your compass gps:
[IMG]http://i59.tinypic.com/aahqa8.png[/IMG]
I figured the position of the hud text was likely to be something that people would want to customize, so here in the settings gui are the x and y coords for the hud text. Just enter the new coords where you want the hud text to appear and click "Change Hud"
The cords must be between 0 and 1 and represent a percentage of the screen, so x=0 would put the text at the far left of the screen, and y=0.98 would put the text almost at the bottom of the screen. The default is x=0.4 and y=0.01, and that is displayed right over the input boxes so the user can easily set them back to the default if they are having trouble placing the hud. If you change either the x or y coord to a number that is out of range (less than 0 or greater than 1) then the hud will not be displayed. That makes it easy to turn the hud off if you wish.
You can also change the color of the hud text by changing the value in the "Color" field here. Again, click "Change Hud" to make the update appear.
AND, there are three buttons here that allow you to select from 3 different styles of compass images. The basic compass image by Echo. A nice wooden compass image by Bas080. And a high resolution compass image by spootonium.
The bookmark list is saved any time a user changes it. All of your other settings, the currently selected bookmark, sort order, distance function, and hud position and color, and compass type, are saved whenever a user leaves the game, and on game shutdown. so if you move the hud down to the lower right hand corner of the screen, and then quit, the hud will still be in the place you put it when you restart the game later.
I also fixed a few bugs while I was working on this. There was a problem in the mod that caused compass to jump around in inventory if there were empty slots above it, that is fixed now. And there was also a problem with the bookmark list not being saved after you removed a bookmark if you didn't add a new bookmark afterwards. Now the bookmark list is saved whenever you change it, either adding or removing.
@ -47,11 +54,14 @@ I tried to follow Echo and TeTpaAka's examples of how to properly code for multi
The code is kinda a mess, because I was learning a lot of new things while working on it. I hope to do a clean up on it sometime in the near future, but I wanted to release it now so some people could start testing it. Please do not hesitate to offer critiques, criticism, or coding advice. I'm new to lua and minetest and could use the help.
[b]Credits:[/b]
Original mod is by Echo and TeTpaAka, and probably PilzAdam. Cactuz_pl clockmod showed me how to write the hud to the screen. My son offered a lot of advice and suggested several changes. I got an example of how to sort lists in lua from Michal Kottman on StackOverflow
Original mod is by Echo and TeTpaAka, and probably PilzAdam. Cactuz_pl clockmod showed me how to write the hud to the screen. My son offered a lot of advice and suggested several changes. I got an example of how to sort lists in lua from Michal Kottman on StackOverflow. Big thanks to Bas080 and spootonium for providing some very nice alternate images for the compass gps mod!
[b]License:[/b]
Original code by Echo, PilzAdam, and TeTpaAka is WTFPL. My changes are CC0 (No rights reserved)
textures: CC BY-SA by Echo
textures: original compass textures: CC BY-SA by Echo
compass b textures: ? by Bas080 (slight modifications by Kilarin)
compass c textures: CC BY-SA by Andre Goble mailto:spootonium@gmail.com
(slight modifications by Kilarin)
[b]Dependencies:[/b]
default is the only requirement.

223
init.lua
View File

@ -7,6 +7,13 @@
--added hud showing current pos -> target pos : distance
local hud_default_x=0.4
local hud_default_y=0.01
local hud_default_color="FFFF00"
local compass_default_type="a"
local compass_valid_types={"a","b","c"}
local compassgps = { }
local activewidth=8 --until I can find some way to get it from minetest
@ -28,6 +35,10 @@ local point_name = {}
local sort_function = {}
local distance_function ={}
local hud_pos = {}
local hud_color = {}
local compass_type = {}
--local remove
--the sort functions and distance functions have to be defined ABOVE the
@ -104,12 +115,17 @@ for name,stng in pairs(settings) do
if settings[name].hud_pos then
hud_pos[name]=settings[name].hud_pos
end
if settings[name].hud_color then
hud_color[name]=settings[name].hud_color
end
if settings[name].compass_type then
compass_type[name]=settings[name].compass_type
end
end --for
local textlist_clicked = {}
local hud_default_x=0.4
local hud_default_y=0.01
function compassgps.bookmark_from_idx(name,idx)
@ -137,16 +153,17 @@ end --bookmark_from_idx
--function compassgps.get_confirm_formspec(name,bkmrk)
-- print("get_confirm_formspec")
-- return "compassgps:confirm", "size[8,8;]"..
-- --"field[0,0.2;5,1;confirm_bookmarkname;Remove "..bkmark.."?;]"..
-- "field[0,0.2;7,1;confirm_bookmarkname;Remove selected bookmark?;]"..
-- "button[0,0.7;4,1;confirm_yes;Yes]"..
-- "button[4,0.7;4,1;confirm_no;No]"
--end
--[
function compassgps.get_confirm_formspec(name,bkmrk)
print("get_confirm_remove_formspec")
return "compassgps:confirm_remove", "size[8,4;]"..
--"field[0,0.2;5,1;confirm_bookmarkname;Remove "..bkmark.."?;]"..
--"field[0,0.2;7,1;confirm_bookmarkname;Remove selected bookmark?;]"..
"label[0,0.2;Remove bookmark: "..bkmark.." ?]"..
"button[0,0.7;4,1;confirm_yes;Yes]"..
"button[4,0.7;4,1;confirm_no;No]"
end
--]
minetest.register_on_player_receive_fields(function(player,formname,fields)
@ -167,7 +184,7 @@ minetest.register_on_player_receive_fields(function(player,formname,fields)
or ( (fields["bookmark"]) and (fields["bookmark"]~="") --bookmark field not blank
and (not fields["remove_bookmark"]) and (not fields["find_bookmark"])
and (not fields["bookmark_list"]) and (not fields["sort_type"])
and (not fields["distance_type"]) and (not fields["hud_pos"])
and (not fields["distance_type"]) and (not fields["settings"]) --and (not fields["hud_pos"])
and (not fields["teleport"]) )
then
compassgps.set_bookmark(name, fields["bookmark"])
@ -179,7 +196,8 @@ minetest.register_on_player_receive_fields(function(player,formname,fields)
-- "button[4,0.7;4,1;remove_no;No]")
--minetest.show_formspec(name,compassgps.get_confirm_formspec(name,textlist_clicked[name]))
--seems you can reshow THIS formspec, but not pop up another
compassgps.remove_bookmark(name, textlist_clicked[name])
--minetest.show_formspec(name, compassgps.get_confirm_formspec(name,"test"))
compassgps.remove_bookmark(name, textlist_clicked[name])
minetest.show_formspec(name, compassgps.get_compassgps_formspec(name))
elseif fields["find_bookmark"] and textlist_clicked[name] then
--if fields["bookmark_list"] then
@ -214,7 +232,12 @@ minetest.register_on_player_receive_fields(function(player,formname,fields)
elseif fields["teleport"] then
-- Teleport player.
compassgps.teleport_bookmark(name, textlist_clicked[name])
elseif fields["hud_pos"] and fields["hudx"] and fields["hudy"] then
elseif fields["settings"] then
--bring up settings screen
minetest.show_formspec(name, compassgps.get_settings_formspec(name))
end --compassgps formspec
elseif (name ~= "" and formname == "compassgps:settings") then
if fields["hud_pos"] then --and fields["hudx"] and fields["hudy"] then
--minetest.chat_send_all("hud_pos triggered")
if tonumber(fields["hudx"]) and tonumber(fields["hudy"]) then
hud_pos[name].x=fields["hudx"]
@ -226,8 +249,20 @@ minetest.register_on_player_receive_fields(function(player,formname,fields)
end
else --not numbers
minetest.chat_send_player(name,"compassgps: hud coords are not numeric. Change to between 0 and 1")
end --if numbers
end
end --if x,y valid
if tonumber(fields["hudcolor"],16) then
hud_color[name]=fields["hudcolor"]
else
mintest.chat_send_player(name,"compassgps: hud color not valid hex number")
end --if color valid
elseif fields["compass_type_a"] then
compass_type[name]="a"
elseif fields["compass_type_b"] then
compass_type[name]="b"
print("compass_type b triggered compass_type[name]="..compass_type[name])
elseif fields["compass_type_c"] then
compass_type[name]="c"
end --
end
end)
@ -264,7 +299,9 @@ function compassgps.write_settings()
point_name=point_name[name],
hud_pos=hud_pos[name],
sort_function=sort_short,
distance_function=dist_short}
distance_function=dist_short,
hud_color=hud_color[name],
compass_type=compass_type[name]}
end
--now write to file
local file = io.open(minetest.get_worldpath().."/compassgps_settings", "w")
@ -542,6 +579,22 @@ function read_spawns()
end
function compassgps.compass_type_name(playername,imagenum,ctypein)
local ctype="a"
if ctypein then
ctype=ctypein
end
if playername~="" and compass_type[playername] then
ctype=compass_type[playername]
end
if ctype=="a" then
ctype=""
end
--print("compass type name return "..ctype..imagenum)
return ctype..imagenum
end
function compassgps.get_default_pos_and_name(name)
-- try to get position from PilzAdams bed-mod spawn
local pos = pilzadams_spawns[name]
@ -589,8 +642,6 @@ minetest.register_globalstep(function(dtime)
--problem being that arrays are not sorted in lua
for i,stack in ipairs(player:get_inventory():get_list("main")) do
if i<=activewidth and string.sub(stack:get_name(), 0, 11) == "compassgps:" then
--player:get_inventory():remove_item("main", stack:get_name())
--player:get_inventory():add_item("main", "compassgps:"..compass_image)
activeinv=stack --store the stack so we can update it later with new image
stackidx=i --store the index so we can add image at correct location
gotacompass=true
@ -619,10 +670,13 @@ minetest.register_globalstep(function(dtime)
--update compass image to point at target
if wielded then
player:set_wielded_item("compassgps:"..compass_image)
elseif activeinv then
--player:set_wielded_item("compassgps:"..compass_image)
player:set_wielded_item("compassgps:"..
compassgps.compass_type_name(name,compass_image))
elseif activeinv then
player:get_inventory():remove_item("main", activeinv:get_name())
player:get_inventory():set_stack("main",stackidx,"compassgps:"..compass_image)
player:get_inventory():set_stack("main",stackidx,"compassgps:"..
compassgps.compass_type_name(name,compass_image))
end --if wielded elsif activin
@ -638,9 +692,24 @@ minetest.register_globalstep(function(dtime)
hudx=tonumber(hud_pos[name].x)
hudy=tonumber(hud_pos[name].y)
else
hud_pos[name]={x=hud_default_x, y=hud_default_y}
hud_pos[name]={x=hud_default_x, y=hud_default_y}
end
local hudcolor=tonumber(hud_default_color, 16)
if hud_color[name] then
hudcolor=tonumber(hud_color[name], 16)
else
hud_color[name]=hud_default_color
end
local compasstype=compass_default_type
if compass_type[name] and
(compass_type[name]=="a" or compass_type[name]=="b" or compass_type[name]=="c") then
compasstype=compass_type[name]
else
compass_type[name]=compass_default_type
end
local h=nil
if hudx>=0 and hudx<=1 and hudy>=0 and hudy<=1 then
h = player:hud_add({
@ -651,7 +720,8 @@ minetest.register_globalstep(function(dtime)
text = compassgps.pos_to_string(pos).." -> "..point_name[name]..
" "..compassgps.pos_to_string(spawn).." : "..
compassgps.round_digits(distance_function[name](pos,spawn),2);
number = 0xFFFF00;
--number = 0xFFFF00;
number = hudcolor;
scale = 20;
});
end --if x and y in range
@ -671,20 +741,6 @@ end) -- register_globalstep
local images = {
"compass_0.png",
"compass_1.png",
"compass_2.png",
"compass_3.png",
"compass_4.png",
"compass_5.png",
"compass_6.png",
"compass_7.png",
"compass_8.png",
"compass_9.png",
"compass_10.png",
"compass_11.png",
}
@ -767,7 +823,6 @@ function compassgps.get_compassgps_formspec(name)
distance_function[name]=compassgps.distance3d
end
--textlist triggers register_on_recieve_fields whenever you click on an item in
--the list, but returns nil if you check it after a button is clicked.
--so we use textlist_clicked[name] to store the currently selected item in the
@ -790,7 +845,6 @@ function compassgps.get_compassgps_formspec(name)
end
end
--check to see if the player has teleport privliges
local player_privs
if core then player_privs = core.get_player_privs(name)
@ -801,19 +855,15 @@ function compassgps.get_compassgps_formspec(name)
telepriv=true
end
return "compassgps:bookmarks", "size[9,10;]"..
"field[0,0.2;5,1;bookmark;bookmark:;]"..
"button[5.5,0;2.25,0.8;settings;Settings]"..
"button[0,0.7;4,1;new_bookmark;create bookmark]"..
"button[4,0.7;4,1;remove_bookmark;remove bookmark]"..
"label[0,1.75;Sort by:]"..
"textlist[1,1.75;1.2,1;sort_type;name,distance;"..sortdropdown.."]"..
"label[2.4,1.75;Dist:]"..
"textlist[3,1.75;.5,1;distance_type;3d,2d;"..distdropdown.."]"..
"button[4,1.9;2.25,1;hud_pos;Change hud Pos:]"..
"field[6.6,2.2;1.2,1;hudx;X:("..hud_default_x..");"..hud_pos[name].x.."]"..
"field[7.8,2.2;1.2,1;hudy;Y:("..hud_default_y..");"..hud_pos[name].y.."]"..
"textlist[0,3.0;9,6;bookmark_list;"..list..";"..bkmrkidx.."]"..
"button[0,9.3;3,1;find_bookmark;find selected bookmark]"..
"button[4,9.3;3,1;teleport;teleport to bookmark]"
@ -822,27 +872,70 @@ function compassgps.get_compassgps_formspec(name)
--{"textlist", x=<X>, y=<Y>, w=<Width>, h=<Height>, name="<name>", list=<array of string/number/boolean>}
--"textlist[0.1,1.2;5.7,3.6;travelpoint;" .. tp_string .. ";" .. tp_index .. "]"
end
end --get_compassgps_formspec
function compassgps.get_settings_formspec(name)
local player = minetest.get_player_by_name(name)
return "compassgps:settings", "size[8,4;]"..
"button[1,0.2;2.25,1;hud_pos;Change hud:]"..
"field[3.6,0.5;1.2,1;hudx;X:("..hud_default_x..");"..hud_pos[name].x.."]"..
"field[4.8,0.5;1.2,1;hudy;Y:("..hud_default_y..");"..hud_pos[name].y.."]"..
"field[6.0,0.5;2,1;hudcolor;Color:("..hud_default_color..");"..hud_color[name].."]"..
"label[1,1.5;Compass Type:]"..
"image_button[3,1.5;1,1;compass_0.png;compass_type_a;]"..
"image_button[4,1.5;1,1;compass_b0.png;compass_type_b;]"..
"image_button[5,1.5;1,1;compass_c0.png;compass_type_c;]"
end --get_compassgps_formspec
--[
local images = {
"compass_0.png",
"compass_1.png",
"compass_2.png",
"compass_3.png",
"compass_4.png",
"compass_5.png",
"compass_6.png",
"compass_7.png",
"compass_8.png",
"compass_9.png",
"compass_10.png",
"compass_11.png",
}
--]
local i
for i,img in ipairs(images) do
local inv = 1
if i == 1 then
inv = 0
end
minetest.register_tool("compassgps:"..(i-1), {
description = "compassgps",
inventory_image = img,
wield_image = img, --.."^[transformR90" didn't work
on_use = function (itemstack, user, pointed_thing)
local name = user:get_player_name()
if (name ~= "") then
minetest.show_formspec(name, compassgps.get_compassgps_formspec(name))
end
end,
groups = {not_in_creative_inventory=inv}
})
end
--for i,img in ipairs(images) do
for i=1,12 do
for c,ctype in pairs(compass_valid_types) do
local inv = 1
if i == 1 and ctype=="a" then
inv = 0
end
ctypename=compassgps.compass_type_name("",(i-1),ctype)
img="compass_"..ctypename..".png"
--print("registering compassgps:"..ctypename.." img="..img)
minetest.register_tool("compassgps:"..ctypename, {
description = "compassgps",
inventory_image = img,
wield_image = img, --.."^[transformR90" didn't work
on_use = function (itemstack, user, pointed_thing)
local name = user:get_player_name()
if (name ~= "") then
minetest.show_formspec(name, compassgps.get_compassgps_formspec(name))
end
end,
groups = {not_in_creative_inventory=inv}
})
end --for ctype
end --for i,img
minetest.register_craft({
output = 'compassgps:1',

BIN
textures/compass_b0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 584 B

BIN
textures/compass_b1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 587 B

BIN
textures/compass_b10.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 539 B

BIN
textures/compass_b11.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 526 B

BIN
textures/compass_b2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 571 B

BIN
textures/compass_b3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 575 B

BIN
textures/compass_b4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 541 B

BIN
textures/compass_b5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 525 B

BIN
textures/compass_b6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 537 B

BIN
textures/compass_b7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 527 B

BIN
textures/compass_b8.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 522 B

BIN
textures/compass_b9.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 552 B

BIN
textures/compass_c0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
textures/compass_c1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
textures/compass_c10.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
textures/compass_c11.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
textures/compass_c2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
textures/compass_c3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
textures/compass_c4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
textures/compass_c5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
textures/compass_c6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
textures/compass_c7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
textures/compass_c8.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
textures/compass_c9.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB