Skip to content

Commit

Permalink
Merge branch 'MT-CTF:master' into spike
Browse files Browse the repository at this point in the history
  • Loading branch information
farooqkz authored Feb 11, 2024
2 parents d2a3c42 + e2d5deb commit 89ad15a
Show file tree
Hide file tree
Showing 173 changed files with 3,000 additions and 975 deletions.
3 changes: 3 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@


- [ ] This PR has been tested locally
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ debug.txt
/mods/ctf/ctf_map/textures/*Back.*
/mods/ctf/ctf_map/textures/*Left.*
/mods/ctf/ctf_map/textures/*Right.*
/mods/ctf/ctf_map/textures/*_screenshot.png
/mods/ctf/ctf_map/textures/*_screenshot.png

*.blend1
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,14 @@ Created by [rubenwardy](https://rubenwardy.com/).
Developed by [LandarVargan](https://github.com/LoneWolfHT).
Previous Developers: [savilli](https://github.com/savilli).

Licenses where not specified:
Code: LGPLv2.1+
Textures: CC-BY-SA 3.0

### Textures
Check out [mods/](mods/) to see all the installed mods and their respective licenses.

* [Header](menu/header.png): CC BY-SA 4.0 by xenonca
* [Background Image](menu/background.png): CC0 (where applicable) by Apelta (Uses [Minetest Game](https://github.com/minetest/minetest_game) textures, the majority of which are licensed CC-BY-SA 3.0). The player skin used is licensed CC-BY-SA 3.0
Licenses where not specified:\
Code: [GNU LGPLv2.1+](https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html)\
Media: [CC BY-SA 3.0 Unported](https://creativecommons.org/licenses/by-sa/3.0/)

### Mods
### Textures

Check out [mods/](mods/) to see all the installed mods and their respective licenses.
* [Header](menu/header.png): [CC BY 3.0 Unported](https://creativecommons.org/licenses/by/3.0/) by [SuddenSFD](https://github.com/SuddenSFD)
* [Background Image](menu/background.png): [CC BY-SA 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/) (where applicable) by [GreenBlob](https://github.com/a-blob) (Uses [Minetest Game](https://github.com/minetest/minetest_game) textures, the majority of which are licensed [CC BY-SA 3.0 Unported](https://creativecommons.org/licenses/by-sa/3.0/)). The player skins used are licensed under [CC BY-SA 3.0 Unported](https://creativecommons.org/licenses/by-sa/3.0/)
* [Icon](menu/icon.png): [CC BY 3.0](https://creativecommons.org/licenses/by/3.0/) by [SuddenSFD](https://github.com/SuddenSFD)
17 changes: 10 additions & 7 deletions docs/accurate_statbar.patch
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ index 46c947b6..f4372843 100644
local hud_ids = {}

local function scaleToDefault(player, field)
+ return player["get_" .. field](player)
- -- Scale "hp" or "breath" to the default dimensions
- local current = player["get_" .. field](player)
- local nominal = core["PLAYER_MAX_".. field:upper() .. "_DEFAULT"]
- local max_display = math.max(nominal,
- math.max(player:get_properties()[field .. "_max"], current))
- return current / max_display * nominal
+ if field == "health" then
+ return player["get_" .. field](player)
+ else
-- Scale "hp" or "breath" to the default dimensions
local current = player["get_" .. field](player)
local nominal = core["PLAYER_MAX_".. field:upper() .. "_DEFAULT"]
local max_display = math.max(nominal,
math.max(player:get_properties()[field .. "_max"], current))
return current / max_display * nominal
+ end
end

local function update_builtin_statbars(player)
Binary file modified menu/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified menu/header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified menu/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 26 additions & 9 deletions mods/apis/ctf_gui/dev.lua
Original file line number Diff line number Diff line change
@@ -1,31 +1,48 @@
local unset_function = "[f]\nreturn "

function ctf_gui.show_formspec_dev(player, formname, formspec, formcontext)
local filepath = minetest.get_worldpath().."/ctf_gui/"
local filename = filepath.."file_edit.txt"
local slower_loop = false

minetest.chat_send_all("Started formspec editing file at "..filename)

minetest.mkdir(filepath)

local file = assert(io.open(filename, "w"))

file:write(formspec)

if type(formspec) ~= "function" then
file:write(formspec)
else
file:write(unset_function)
end
file:close()

local function interval()
if formspec:sub(1, 3) == "[f]" then
local result, form = pcall(loadstring(formspec:sub(4)), formcontext)
ctf_gui.show_formspec(player, formname, result and form or "")
if type(formspec) == "function" then
ctf_gui.show_formspec(player, formname, formspec(formcontext))
elseif formspec:sub(1, 3) == "[f]" then
local result, form = pcall((loadstring(formspec:sub(4)) or function() return function() end end)(), formcontext)

ctf_gui.show_formspec(player, formname,
result and form or "size[10,10]hypertext[0,0;10,10;err;"..minetest.formspec_escape(form or "").."]"
)

slower_loop = not result
else
ctf_gui.show_formspec(player, formname, formspec)
end

minetest.after(1, function()
minetest.after(slower_loop and 3 or 1, function()
local f = assert(io.open(filename, "r"))
local new_form = f:read("*a")

formspec = f:read("*a")
if new_form ~= unset_function then
formspec = new_form
end

f:close()

if formspec:match("^exit") then
if type(formspec) == "function" or not formspec:match("^exit") then
interval()
else
minetest.request_shutdown("Formspec dev requested shutdown", true)
Expand Down
4 changes: 4 additions & 0 deletions mods/apis/ctf_gui/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function ctf_gui.init()
local action = ctx._on_formspec_input(pname, ctx, fields, ...)

if action == "refresh" then
minetest.log("action", "Refreshing formspec "..dump(ctx._formname).." to "..dump(pname))
minetest.show_formspec(pname, ctx._formname, ctx._formspec(ctx))
end
end
Expand Down Expand Up @@ -115,6 +116,7 @@ function ctf_gui.show_formspec(player, formname, formspec, formcontext)
context[player]._formname = formname
context[player]._formspec = formspec

minetest.log("action", "Showing new_formspec "..dump(formname).." to "..dump(player))
if type(formspec) == "function" then
minetest.show_formspec(player, formname, formspec(formcontext))
else
Expand Down Expand Up @@ -144,6 +146,7 @@ do
end
end

-- minetest.log("action", "[ctf_gui] unpacking: "..dump(l))
return format(base, unpck(l))
end

Expand Down Expand Up @@ -457,6 +460,7 @@ function ctf_gui.old_show_formspec(player, formname, formdef)
formdef._info = formdef
context[player] = formdef

minetest.log("action", "Showing formspec "..dump(formname).." to "..dump(player))
minetest.show_formspec(player, formname, formspec)
end,
formdef, ctf_gui.ELEM_SIZE, ctf_gui.SCROLLBAR_WIDTH)
Expand Down
73 changes: 58 additions & 15 deletions mods/apis/ctf_settings/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ctf_settings = {
settings_list = {},
}

local FORMSIZE = {x = 8, y = 5}
local FORMSIZE = {x = 8, y = 9.4}
local SCROLLBAR_W = 0.4

minetest.after(0, function()
Expand All @@ -29,10 +29,12 @@ function ctf_settings.register(name, def)
table.insert(ctf_settings.settings_list, name)
end

---@param player ObjectRef
function ctf_settings.set(player, setting, value)
player:get_meta():set_string("ctf_settings:"..setting, value)
end

---@param player ObjectRef
---@return string Returns the player's chosen setting value, the default given at registration, or if both are unset: ""
function ctf_settings.get(player, setting)
local value = player:get_meta():get_string("ctf_settings:"..setting)
Expand All @@ -41,37 +43,72 @@ function ctf_settings.get(player, setting)
return value == "" and info.default or value
end

-- This Function MIT by Rubenwardy
--- Creates a scrollbaroptions for a scroll_container
--
-- @param visible_l the length of the scroll_container and scrollbar
-- @param total_l length of the scrollable area
-- @param scroll_factor as passed to scroll_container
local function make_scrollbaroptions_for_scroll_container(visible_l, total_l, scroll_factor)

assert(total_l >= visible_l)

local thumb_size = (visible_l / total_l) * (total_l - visible_l)

local max = total_l - visible_l

return ("scrollbaroptions[min=0;max=%f;thumbsize=%f]"):format(max / scroll_factor, thumb_size / scroll_factor)
end

minetest.register_on_mods_loaded(function()
sfinv.register_page("ctf_settings:settings", {
title = "Settings",
get = function(self, player, context)
local setting_list = {}
local lastypos = -0.5

if not context then
context = {}
end

if not context.setting then
context.setting = {}
end

for k, setting in ipairs(ctf_settings.settings_list) do
local settingdef = ctf_settings.settings[setting]

if not context.setting[setting] then
context.setting[setting] = ctf_settings.get(player, setting)
end

if settingdef.type == "bool" then
setting_list[k] = {
"checkbox[0,%f;%s;%s;%s]tooltip[%s;%s]",
lastypos,
setting,
settingdef.label or setting,
ctf_settings.get(player, setting),
context.setting[setting],
setting,
settingdef.description or HumanReadable(setting)
}

lastypos = lastypos + 0.5
elseif settingdef.type == "list" then
local max_len = 0

for _, val in pairs(settingdef.list) do
max_len = math.max(val:len(), max_len)
end

lastypos = lastypos + 0.3
setting_list[k] = {
"dropdown[0,%f;%f;%s;%s;%d]tooltip[0,%f;%f,0.6;%s]",
lastypos,
FORMSIZE.x/1.7,
math.max(FORMSIZE.x / 2, math.min(FORMSIZE.x - SCROLLBAR_W + 2, 0.5 + (max_len * 0.23))),
setting,
settingdef.list,
ctf_settings.get(player, setting),
context.setting[setting],
--label
lastypos,
(FORMSIZE.x/1.7) - 0.3,
Expand All @@ -84,21 +121,21 @@ minetest.register_on_mods_loaded(function()
local form = {
{"box[-0.1,-0.1;%f,%f;#00000055]", FORMSIZE.x - SCROLLBAR_W, FORMSIZE.y},
{"scroll_container[-0.1,0.3;%f,%f;settings_scrollbar;vertical;0.1]",
FORMSIZE.x - SCROLLBAR_W,
FORMSIZE.x - SCROLLBAR_W + 2,
FORMSIZE.y + 0.7
},
ctf_gui.list_to_formspec_str(setting_list),
"scroll_container_end[]",
{"scrollbaroptions[max=%d]", math.ceil((lastypos - 3.833) * 11.538)},
make_scrollbaroptions_for_scroll_container(FORMSIZE.y + 0.7, math.max(lastypos+1, FORMSIZE.y + 0.7), 0.1),
{"scrollbar[%f,-0.1;%f,%f;vertical;settings_scrollbar;%f]",
FORMSIZE.x - SCROLLBAR_W,
SCROLLBAR_W,
FORMSIZE.y,
context and context.settings_scrollbar or 0
context.settings_scrollbar or 0
},
}

return sfinv.make_formspec(player, context, ctf_gui.list_to_formspec_str(form), true)
return sfinv.make_formspec(player, context, ctf_gui.list_to_formspec_str(form), false)
end,
on_player_receive_fields = function(self, player, context, fields)
local refresh = false
Expand All @@ -110,24 +147,30 @@ minetest.register_on_mods_loaded(function()
if setting.type == "bool" then
local newvalue = value == "true" and "true" or "false"

ctf_settings.set(player, field, newvalue)
if context.setting[field] ~= newvalue then
context.setting[field] = newvalue
ctf_settings.set(player, field, newvalue)

if setting.on_change then
setting.on_change(player, newvalue)
if setting.on_change then
setting.on_change(player, newvalue)
end

refresh = true
end
elseif setting.type == "list" then
local idx = table.indexof(setting.list, value)

if idx ~= -1 then
if idx ~= -1 and context.setting[field] ~= tostring(idx) then
context.setting[field] = tostring(idx)
ctf_settings.set(player, field, tostring(idx))

if setting.on_change then
setting.on_change(player, idx)
setting.on_change(player, tostring(idx))
end

refresh = true
end
end

refresh = true
end
end

Expand Down
32 changes: 20 additions & 12 deletions mods/apis/hud_events/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local hud = mhud.init()

local HUD_SHOW_TIME = 3
local HUD_SHOW_QUICK_TIME = 2
local HUD_SHOW_NEXT_TIME = 1
local HUD_SHOW_NEXT_TIME = 0.6

local HUD_COLORS = {
primary = 0x0D6EFD,
Expand Down Expand Up @@ -51,7 +51,7 @@ local function show_quick_hud_event(player, huddef)
end

if quick_event_timer[pname] then
quick_event_timer[pname].cancel()
quick_event_timer[pname]:cancel()
end
quick_event_timer[pname] = minetest.after(HUD_SHOW_QUICK_TIME, function()
if not player:is_player() then return end
Expand Down Expand Up @@ -82,16 +82,24 @@ local function handle_hud_events(player)
end

hud_queues[pname].t = minetest.after(HUD_SHOW_TIME, function()
hud:change(player, "hud_event", {text = ""})

hud_queues[pname].t = minetest.after(HUD_SHOW_NEXT_TIME, function()
if #hud_queues[pname].e >= 1 then
handle_hud_events(player)
else
hud:remove(player, "hud_event")
hud_queues[pname] = nil
end
end)
player = minetest.get_player_by_name(pname)

if player then
hud:change(player, "hud_event", {text = ""})

hud_queues[pname].t = minetest.after(HUD_SHOW_NEXT_TIME, function()
player = minetest.get_player_by_name(pname)

if player then
if #hud_queues[pname].e >= 1 then
handle_hud_events(player)
else
hud:remove(player, "hud_event")
hud_queues[pname] = nil
end
end
end)
end
end)
end

Expand Down
7 changes: 5 additions & 2 deletions mods/ctf/ctf_combat/ctf_combat_mode/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ local function update(player)
return
end

local hud_message = "You are in combat [%ds left]"
hud_message = hud_message:format(combat.time)
local hud_message = "You are in combat [%ds left] \n%s"
hud_message = hud_message:format(combat.time, combat.suffocation_message)

if hud:exists(player, "combat_indicator") then
hud:change(player, "combat_indicator", {
Expand All @@ -36,8 +36,10 @@ local function update(player)

if node.groups.real_suffocation then -- From real_suffocation mod
combat.time = combat.time + 0.5
combat.suffocation_message = "You are inside blocks. Move out to stop your combat timer from increasing."
else
combat.time = combat.time - 1
combat.suffocation_message = ""
end

combat.timer = minetest.after(1, update, player)
Expand All @@ -56,6 +58,7 @@ function ctf_combat_mode.add_hitter(player, hitter, weapon_image, time)
combat.time = time
combat.last_hitter = hitter
combat.weapon_image = weapon_image
combat.suffocation_message = ""

if not combat.timer then
update(player)
Expand Down
Loading

0 comments on commit 89ad15a

Please sign in to comment.