Add sfinv, add tabs

This commit is contained in:
rubenwardy 2016-02-15 01:27:20 +00:00
parent f4e70557d3
commit 97091c6037
7 changed files with 261 additions and 77 deletions

View file

@ -1 +1,2 @@
ctf
sfinv

View file

@ -1,46 +1,40 @@
ctf.register_on_init(function()
ctf._set("inventory", false)
end)
local fs = "size[8,8.5]" ..
"bgcolor[#080808BB;true]" ..
"background[5,5;1,1;gui_formbg.png;true]" ..
"listcolors[#00000069;#5A5A5A;#141318;#30434C;#FFF]" ..
"list[current_player;main;0,4.25;8,1;]" ..
"list[current_player;main;0,5.5;8,3;8]" ..
"textlist[0,0;7.85,4;help;"
local fs = [[
size[8,8.6]
bgcolor[#080808BB;true]
background[5,5;1,1;gui_formbg.png;true]
{{ nav }}
textlist[0,0;7.85,8.5;help;
]]
local items = {
"Welcome to Capture the Flag!",
"* There is no crafting, look for stuff in chests.",
"* Your team color is displayed in the top left.",
"Tips",
"",
"* Capture an enemy's flag by walking up to it, punching it,",
" then running and punching your team's flag.",
"* Look for guns, grenades and other resources in chests.",
"* Guns can destroy blocks.",
"* See the league table by typing /rankings",
" See your position in it by typing /rankings me",
" Get to the top by capturing lots of flags, and having a high K/D ratio.",
"* Your team has a chest near your flag.",
" Be warned that other teams can steal from it.",
"* Your team name is displayed in the top left.",
" to talk with only your team, type: /t message",
"* If the match is getting boring, type /vote_next",
"* rubenwardy is the only admin or mod on this server.",
" Message him using /mail rubenwardy your message"
"* If the match is getting boring, type /vote, then /yes to vote yes.",
"* Report people who sabotage using /report."
}
for i = 1, #items do
if i > 1 then
fs = fs .. ","
end
fs = fs .. minetest.formspec_escape(items[i])
items[i] = minetest.formspec_escape(items[i])
end
fs = fs .. table.concat(items, ",") .. "]"
sfinv.register_page("ctf_inventory:help", {
title = "Help",
get = function(player, context)
return fs
end
})
--"list[current_player;craft;1.75,0.5;3,3;]" ..
--"list[current_player;craftpreview;5.75,1.5;1,1;]" ..
--"image[4.75,1.5;1,1;gui_furnace_arrow_bg.png^[transformR270]" ..
--"listring[current_player;main]" ..
--"listring[current_player;craft]" ..
fs = fs ..
"]" ..
"image[0,4.25;1,1;gui_hb_bg.png]" ..
"image[1,4.25;1,1;gui_hb_bg.png]" ..
"image[2,4.25;1,1;gui_hb_bg.png]" ..
"image[3,4.25;1,1;gui_hb_bg.png]" ..
"image[4,4.25;1,1;gui_hb_bg.png]" ..
"image[5,4.25;1,1;gui_hb_bg.png]" ..
"image[6,4.25;1,1;gui_hb_bg.png]" ..
"image[7,4.25;1,1;gui_hb_bg.png]"
minetest.register_on_joinplayer(function(player)
if ctf.setting("inventory") then

View file

@ -46,21 +46,12 @@ function random_messages.check_params(name,func,params)
end
function random_messages.read_messages()
local line_number = 1
local input = io.open(minetest.get_worldpath().."/random_messages","r")
if not input then
local output = io.open(minetest.get_worldpath().."/random_messages","w")
output:write("To talk to only your team, start your messages with /t. For example, /t Hello team!\n")
output:write("If the map is ruined, use /vote to start a new vote to skip the current match.\n")
output:write("Eat apples to restore health quickly.\n")
io.close(output)
input = io.open(minetest.get_worldpath().."/random_messages","r")
end
for line in input:lines() do
random_messages.messages[line_number] = line
line_number = line_number + 1
end
io.close(input)
random_messages.messages = {
"To talk to only your team, start your messages with /t. For example, /t Hello team!",
"If the map is ruined, use /vote to start a new vote to skip the current match.",
"Eat apples to restore health quickly.",
"You can steal items from the other team's chest."
}
end
function random_messages.display_message(message_number)

1
mods/rules/depends.txt Normal file
View file

@ -0,0 +1 @@
sfinv?

View file

@ -1,35 +1,49 @@
-- License: WTFPL
rules = {}
function rules.show(player)
local msgs = {
"Welcome to Capture the Flag!",
"Developed and hosted by rubenwardy.",
"Moderators: Kpenguin, Thomas-S, Dragonop,",
" stormchaser3000, Calinou.",
" tip: use /vote to skip to the next round",
",By playing on this server you agree to these rules:",
"1. Be nice. eg: No (excessive or bad) swearing",
"2. No dating.",
"3. Don't be a cheater. No hacked clients.",
"4. Don't be a traitor. Don't:",
" a. Dig blocks in your base to make it less secure or",
" to trap team mates on purpose.",
" b. Help the other team.",
"5. Don't impersonate other community members",
"Failure to follow these rules may result in a kick or ban",
" (temp or permanent) depending on severity."}
local fs = ""
for _, line in pairs(msgs) do
if fs ~= "" then
fs = fs .. ","
local items = {
"Welcome to Capture the Flag!",
"",
"Developed and hosted by rubenwardy.",
"Moderators: Kpenguin, Thomas-S, Dragonop,",
" stormchaser3000, Calinou, sparky/ircSparky.",
"By playing on this server you agree to these rules:",
"1. Be nice. eg: No (excessive or bad) swearing",
"2. No dating.",
"3. Don't be a cheater. No hacked clients.",
"4. Don't be a traitor. Don't:",
" a. Dig blocks in your base to make it less secure or",
" to trap team mates on purpose.",
" b. Help the other team win.",
"5. Don't impersonate other community members",
"Failure to follow these rules may result in a kick or ban",
" (temp or permanent) depending on severity.",
"Use /report to send a message to a moderator.",
"For example, /report bobgreen is destroying our base"}
for i = 1, #items do
items[i] = minetest.formspec_escape(items[i])
end
rules.txt = table.concat(items, ",")
if minetest.global_exists("sfinv") then
sfinv.register_page("rules:rules", {
title = "Rules",
get = function(player, context)
return ([[
size[8,8.6]
bgcolor[#080808BB;true]
background[5,5;1,1;gui_formbg.png;true]
{{ nav }}
textlist[0,0;7.85,8.5;help;]] .. rules.txt .. "]")
end
fs = fs .. minetest.formspec_escape(line)
end
})
end
fs = "size[8,8]textlist[0.1,0.1;7.8,6;msg;" .. fs .. "]"
function rules.show(player)
local fs = "size[8,8]textlist[0.1,0.1;7.8,6;msg;" .. rules.txt .. "]"
if minetest.check_player_privs(player:get_player_name(), { interact = true }) then
fs = fs .. "button_exit[0.5,6;7,2;yes;Okay]"
else

153
mods/sfinv/api.lua Normal file
View file

@ -0,0 +1,153 @@
local theme = [[size[8,8.6]
bgcolor[#080808BB;true]
background[5,5;1,1;gui_formbg.png;true]
{{ nav }}
listcolors[#00000069;#5A5A5A;#141318;#30434C;#FFF]
list[current_player;main;0,4.25;8,1;]
list[current_player;main;0,5.5;8,3;8] ]]
sfinv = {
pages = {},
pages_unordered = {},
homepage_name = "sfinv:crafting",
contexts = {}
}
function sfinv.register_page(name, def)
if not name or not def or not def.get then
error("Invalid sfinv page. Requires a name & def, and a get function in def")
end
sfinv.pages[name] = def
def.name = name
table.insert(sfinv.pages_unordered, def)
end
function sfinv.parse_variables(fs, vars)
local ret = fs
for key, value in pairs(vars) do
print("Running " .. key .. "=" .. value .. " on string")
ret = string.gsub(ret, "{{([ ]+)" .. key .. "([ ]+)}}", value)
end
return ret
end
function sfinv.get(player, context)
local page = sfinv.pages[context.page]
if not page then
page = sfinv.pages["404"]
end
print(dump(page))
local fs = page:get(player, context)
local nav = {}
local nav_ids = {}
local current_idx = 1
for i, pdef in pairs(sfinv.pages_unordered) do
if not pdef.is_in_nav or pdef.is_in_nav(player, context) then
nav[#nav + 1] = pdef.title
nav_ids[#nav_ids + 1] = pdef.name
if pdef.name == context.page then
current_idx = i
end
end
end
context.nav = nav_ids
print(dump(context))
print(current_idx)
local vars = {
layout = theme,
name = player:get_player_name(),
nav = "tabheader[0,0;tabs;" .. table.concat(nav, ",") .. ";" .. current_idx .."]"
}
fs = sfinv.parse_variables(fs, vars)
fs = sfinv.parse_variables(fs, vars)
return fs
end
function sfinv.set(player, context)
if not context then
local name = player:get_player_name()
context = sfinv.contexts[name]
if not context then
context = {
page = sfinv.homepage_name
}
sfinv.contexts[name] = context
end
end
print("Setting " .. context.page)
local fs = sfinv.get(player, context)
print(fs)
player:set_inventory_formspec(fs)
--[[local tmp = [ [
size[8,8.6]
image[4.06,3.4;0.8,0.8;creative_trash_icon.png]
list[current_player;main;0,4.7;8,1;]
list[current_player;main;0,5.85;8,3;8]
list[detached:creative_trash;main;4,3.3;1,1;]
tablecolumns[color;text;color;text]
tableoptions[background=#00000000;highlight=#00000000;border=false]
button[5.4,3.2;0.8,0.9;creative_prev;<]
button[7.25,3.2;0.8,0.9;creative_next;>]
button[2.1,3.4;0.8,0.5;search;?]
button[2.75,3.4;0.8,0.5;clear;X]
tooltip[search;Search]
tooltip[clear;Reset]
listring[current_player;main]
] ] ..
"field[0.3,3.5;2.2,1;filter;;".. filter .."]"..
"listring[detached:creative_".. player_name ..";main]"..
"tabheader[0,0;tabs;Crafting,All,Nodes,Tools,Items;".. tostring(tab_id) ..";true;false]"..
"list[detached:creative_".. player_name ..";main;0,0;8,3;".. tostring(start_i) .."]"..
"table[6.05,3.35;1.15,0.5;pagenum;#FFFF00,".. tostring(pagenum) ..",#FFFFFF,/ ".. tostring(pagemax) .."]"..
default.get_hotbar_bg(0,4.7)..
default.gui_bg .. default.gui_bg_img .. default.gui_slots
]]--
end
minetest.register_on_joinplayer(function(player)
minetest.after(0.5, function()
minetest.chat_send_player(player:get_player_name(), "Hello!")
sfinv.set(player)
end)
end)
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= "" then
return false
end
print("Received fields! " .. dump(fields))
-- Get Context
local name = player:get_player_name()
local context = sfinv.contexts[name]
if not context then
sfinv.set(player)
return false
end
-- Handle Events
if fields.tabs and context.nav then
local tid = tonumber(fields.tabs)
if tid and tid > 0 then
local id = context.nav[tid]
if id and sfinv.pages[id] then
print(name .. " views sfinv/" .. id)
-- TODO: on_leave
context.page = id
sfinv.set(player, context)
end
end
return
end
-- Pass to page
local page = sfinv.pages[context.page]
if page and page.on_player_receive_fields then
return page.on_player_receive_fields(player, context, fields)
end
end)

30
mods/sfinv/init.lua Normal file
View file

@ -0,0 +1,30 @@
dofile(minetest.get_modpath("sfinv") .. "/api.lua")
sfinv.register_page("sfinv:crafting", {
title = "Crafting",
is_in_nav = function(player, context)
return true
end,
get = function(player, context)
return [[ {{ layout }}
list[current_player;craft;1.75,0.5;3,3;]
list[current_player;craftpreview;5.75,1.5;1,1;]
image[4.75,1.5;1,1;gui_furnace_arrow_bg.png^[transformR270]
listring[current_player;main]
listring[current_player;craft]
image[0,4.25;1,1;gui_hb_bg.png]
image[1,4.25;1,1;gui_hb_bg.png]
image[2,4.25;1,1;gui_hb_bg.png]
image[3,4.25;1,1;gui_hb_bg.png]
image[4,4.25;1,1;gui_hb_bg.png]
image[5,4.25;1,1;gui_hb_bg.png]
image[6,4.25;1,1;gui_hb_bg.png]
image[7,4.25;1,1;gui_hb_bg.png] ]]
end,
on_player_receive_fields = function(player, context, fields)
print("Received!")
end,
on_leave = function(player, context)
print("Left page!")
end
})