commit e2f019041b9aaba690bc438d06de53cd1b75123a Author: Robert Zenz Date: Sun Dec 6 17:48:21 2015 +0100 Initial commit. diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..bdf0a87 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "deps/utils"] + path = deps/utils + url = https://github.com/minetest-australopithecus/minetest-australopithecus-utils.git diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1c53c0e --- /dev/null +++ b/LICENSE @@ -0,0 +1,24 @@ +Copyright (c) 2014, Robert 'Bobby' Zenz +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. + +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. + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..121e3ba --- /dev/null +++ b/Makefile @@ -0,0 +1,43 @@ +deps := deps +doc := doc +mod_name := auto_hud_hide +mods := mods +release := release +release_name := auto-hud-hide + +all: doc + +clean: + $(RM) -R $(doc) + +.PHONY: doc +doc: + ldoc --dir=$(doc) mods/$(mod_name) + +.PHONY: release +release: + # Prepare the directory structure. + mkdir -p $(release)/ + mkdir -p $(release)/$(release_name)/ + mkdir -p $(release)/$(release_name)/mods/ + + # Copy the dependencies. + cp -R $(deps)/utils/utils $(release)/$(release_name)/mods/ + + # Copy the mods. + cp -R $(mods)/$(mod_name) $(release)/$(release_name)/mods/ + + # Copy the files. + cp LICENSE $(release)/$(release_name)/ + cp README $(release)/$(release_name)/ + + tar -c --xz -C $(release) -f $(release)/$(release_name).tar.xz $(release_name)/ + tar -c --gz -C $(release) -f $(release)/$(release_name).tar.gz $(release_name)/ + cd $(release); zip -r -9 $(release_name).zip $(release_name); cd - + +.PHONY: update-deps +update-deps: + git submodule foreach git pull origin master + git add $(deps)/ + git commit -m "Updated dependencies." + diff --git a/README b/README new file mode 100644 index 0000000..ff6da58 --- /dev/null +++ b/README @@ -0,0 +1,31 @@ +minetest-australopithecus-auto-hud-hide +======================================= + +A system which automatically hides the HUD if there are no changes. + + +Usage +----- + +The system activates itself, you just need to add the mod to the subgame. + + +Configuration +------------- + +The system can be configured by adding settings to the `minetest.conf`: + + # If the system should be activated, defaults to true. + autohudhide_activate = true + + # The timeout after which the healthbar is hidden, in seconds, defaults + # to 5 seconds. + autohudhide_healthbar_timeout = 5 + + # The timeout after which the hotbar is hidden, in seconds, defaults + # to 3 seconds. + autohudhide_hotbar_timeout = 3 + + # The interval in which the check is run, in seconds, defaults to 0.1. + autohudhide_interval = 0.1 + diff --git a/README.md b/README.md new file mode 120000 index 0000000..100b938 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +README \ No newline at end of file diff --git a/deps/utils b/deps/utils new file mode 160000 index 0000000..517accb --- /dev/null +++ b/deps/utils @@ -0,0 +1 @@ +Subproject commit 517accbba950b2cc0ad55cc297e06743c966e210 diff --git a/mods/auto_hud_hide/autohudhide.lua b/mods/auto_hud_hide/autohudhide.lua new file mode 100644 index 0000000..5e5c7c3 --- /dev/null +++ b/mods/auto_hud_hide/autohudhide.lua @@ -0,0 +1,136 @@ +--[[ +Copyright (c) 2015, Robert 'Bobby' Zenz +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. + +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. +--]] + + + +--- A system which automatically hides hud items if there are no changes. +autohudhide = { + --- The timeout after which the healthbar is hidden. + healthbar_timeout = settings.get_number("autohudhide_healthbar_timeout", 5), + + --- The timeout after which the hotbar is hidden. + hotbar_timeout = settings.get_number("autohudhide_hotbar_timeout", 3), + + --- The infos of players used for determining when to hide elements. + infos = {} +} + + +--- Activates the system, if it has not been deactivated in the configuration +-- by settings autohudhide_activate to false. +function autohudhide.activate() + if settings.get_bool("autohudhide_activate", true) then + minetest.register_on_leaveplayer(autohudhide.remove_info) + scheduler.schedule( + "autohudhide", + settings.get_number("autohudhide_interval", 0.1), + autohudhide.run, + scheduler.OVERSHOOT_POLICY_RUN_ONCE) + end +end + +--- Gets the info for the given player. If there is none, one will be created. +-- +-- @param player_name The player for which to get the info. +-- @return The info object for the given player. +function autohudhide.get_info(player) + local info = autohudhide.infos[player:get_player_name()] + + if info == nil then + info = { + hotbar_visible = true, + last_hotbar_change = os.time() + } + autohudhide.infos[player:get_player_name()] = info + end + + return info +end + +--- Removes the info for the given player. +-- +-- @param player The player for whom to remove the info. +function autohudhide.remove_info(player) + autohudhide.infos[player:get_player_name()] = nil +end + +--- Runs the update on all players. +function autohudhide.run() + for key, player in pairs(minetest.get_connected_players()) do + autohudhide.run_on_player(player) + end +end + +--- Runs the update on the given player. +-- +-- @param player The player on which to run. +function autohudhide.run_on_player(player) + local info = autohudhide.get_info(player) + + autohudhide.update_healthbar(player, info) + autohudhide.update_hotbar(player, info) +end + +--- Updates the status of the healthbar for the given player. +-- +-- @param player The player which to update. +-- @param info The info for the player. +function autohudhide.update_healthbar(player, info) + local current_health = player:get_hp() + + if info.health ~= current_health then + info.health = current_health + info.healthbar_visible = true + info.last_health_change = os.time() + + player:hud_set_flags({ healthbar = true }) + elseif info.healthbar_visible and (os.time() - info.last_health_change) >= autohudhide.healthbar_timeout then + info.healthbar_visible = false + + player:hud_set_flags({ healthbar = false }) + end +end + +--- Updates the status of the hotbar for the given player. +-- +-- @param player The player which to update. +-- @param info The info for the player. +function autohudhide.update_hotbar(player, info) + local current_wield_item = player:get_wielded_item():to_string() + + if info.wield_item ~= current_wield_item then + info.hotbar_visible = true + info.last_wield_item_change = os.time() + info.wield_item = current_wield_item + + player:hud_set_flags({ hotbar = true }) + elseif info.hotbar_visible and (os.time() - info.last_wield_item_change) >= autohudhide.hotbar_timeout then + info.hotbar_visible = false + + player:hud_set_flags({ hotbar = false }) + end +end + diff --git a/mods/auto_hud_hide/depends.txt b/mods/auto_hud_hide/depends.txt new file mode 100644 index 0000000..9487075 --- /dev/null +++ b/mods/auto_hud_hide/depends.txt @@ -0,0 +1 @@ +utils diff --git a/mods/auto_hud_hide/init.lua b/mods/auto_hud_hide/init.lua new file mode 100644 index 0000000..2af766c --- /dev/null +++ b/mods/auto_hud_hide/init.lua @@ -0,0 +1,35 @@ +--[[ +Copyright (c) 2015, Robert 'Bobby' Zenz +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. + +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. +--]] + + +local base_path = minetest.get_modpath(minetest.get_current_modname()) + + +dofile(base_path .. "/autohudhide.lua") + + +autohudhide.activate() + diff --git a/mods/utils b/mods/utils new file mode 120000 index 0000000..e86c13d --- /dev/null +++ b/mods/utils @@ -0,0 +1 @@ +../deps/utils/mods/utils \ No newline at end of file