diff --git a/ROADMAP b/ROADMAP index c3e0efe..569963e 100644 --- a/ROADMAP +++ b/ROADMAP @@ -254,6 +254,7 @@ It's really fast. May be used on a website, to show the actual map. Maybe used with https://github.com/octacian/spawnpoint **** TODO [feature_FactionUI] Try to add a factions UI :LOGBOOK: + CLOCK: [2019-12-03 mar. 12:04]--[2019-12-03 mar. 12:42] => 0:38 CLOCK: [2019-11-19 mar. 09:06]--[2019-11-19 mar. 09:51] => 0:45 CLOCK: [2019-11-09 sam. 06:47]--[2019-11-09 sam. 07:05] => 0:18 CLOCK: [2019-10-31 jeu. 05:31]--[2019-10-31 jeu. 05:42] => 0:11 @@ -288,7 +289,10 @@ It's really fast. May be used on a website, to show the actual map. ...etest/games/minetest-pvp/mods/redtrees/sakuragi/init.lua - [X] Just add a create button with a name textedit xpro/sfinv.lua calls a register_page function -- [ ] Handle new faction button event +- [-] Handle new faction button event + - [X] Must get the faction name from lineedit + - [ ] Finally create the faction +- [ ] Must correctly place 'Créer' button **** DONE Trying to install mintest on the raspberry CLOCK: [2019-06-25 mar. 23:07]--[2019-06-25 mar. 23:53] => 0:46 CLOCK: [2019-06-25 mar. 04:10]--[2019-06-25 mar. 06:15] => 2:05 diff --git a/TODO b/TODO index 7f89925..ceae566 100644 --- a/TODO +++ b/TODO @@ -11,7 +11,8 @@ minetest-solebull - LGPL-2.1 - A PVP/faction game for minetest based on Cobalt. * v0.0.2-7 (10 Aug. 2019 - ???) CLOC ???,??? -- (4) Add new faction elements to factions_ui +- (5) Got faction name in button event +- Add new faction elements to factions_ui - Should fix the faction players number - Manually set faction leader name to fix for factions_ui - Add invite-only value to factions UI diff --git a/mods/factions_ui/init.lua b/mods/factions_ui/init.lua index e343dd5..5a6c1e8 100644 --- a/mods/factions_ui/init.lua +++ b/mods/factions_ui/init.lua @@ -51,11 +51,32 @@ get_factions_ui = function(faction_id) label[0,1;Invite-only :] label[2,1;]]..iotext..[[] textlist[0,2;7,4;faclist;]]..facnames..[[] field[5,1;2,1;name;Nouvelle faction :;newFaction] - button[5,3;2,1;name;Créer] + button[5,3;2,1;create;Créer] ]] return formspec end +create_faction_from_UI = function(name) + if faction then + send_error(player, "You are already in a faction.") + return false + end + if factions.can_create_faction(factionname) then + new_faction = factions.new_faction(factionname, nil) + new_faction:add_player(player, new_faction.default_leader_rank) + + -- Manual fix ? + new_faction.leader = player + new_faction.players[player] = player + factions.save() + + return true + else + send_error(player, "Faction cannot be created.") + return false + end +end + sfinv.register_page("sfinv:factions_ui", { title = "Factions", on_enter = function(self, player, context) @@ -76,8 +97,24 @@ sfinv.register_page("sfinv:factions_ui", { sfinv.set_player_inventory_formspec(player, context) elseif event.type == "INV" then -- We clicked the Create button - print("Creating new faction") + local factionName = fields.name + print("Creating new faction " .. factionName) + end end }) + +-- Used to dump a lua table +function dump(o) + if type(o) == 'table' then + local s = '{ ' + for k,v in pairs(o) do + if type(k) ~= 'number' then k = '"'..k..'"' end + s = s .. '['..k..'] = ' .. dump(v) .. ',' + end + return s .. '} ' + else + return tostring(o) + end +end