first
commit
51a4a3d322
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2021 APercy
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -0,0 +1,225 @@
|
|||
out_here={}
|
||||
out_here.hud_list = {}
|
||||
|
||||
function out_here.animate_gauge(player, ids, prefix, x, y, angle, minor)
|
||||
local minor = minor or 0
|
||||
local angle_in_rad = math.rad(angle + 180)
|
||||
local dim = 5
|
||||
local pos_x = math.sin(angle_in_rad) * dim
|
||||
local pos_y = math.cos(angle_in_rad) * dim
|
||||
player:hud_change(ids[prefix .. "2"], "offset", {x = pos_x + x, y = pos_y + y})
|
||||
dim = 10
|
||||
pos_x = math.sin(angle_in_rad) * dim
|
||||
pos_y = math.cos(angle_in_rad) * dim
|
||||
player:hud_change(ids[prefix .. "3"], "offset", {x = pos_x + x, y = pos_y + y})
|
||||
dim = 15
|
||||
pos_x = math.sin(angle_in_rad) * dim
|
||||
pos_y = math.cos(angle_in_rad) * dim
|
||||
player:hud_change(ids[prefix .. "4"], "offset", {x = pos_x + x, y = pos_y + y})
|
||||
if minor == 0 then
|
||||
dim = 20
|
||||
pos_x = math.sin(angle_in_rad) * dim
|
||||
pos_y = math.cos(angle_in_rad) * dim
|
||||
player:hud_change(ids[prefix .. "5"], "offset", {x = pos_x + x, y = pos_y + y})
|
||||
dim = 25
|
||||
pos_x = math.sin(angle_in_rad) * dim
|
||||
pos_y = math.cos(angle_in_rad) * dim
|
||||
player:hud_change(ids[prefix .. "6"], "offset", {x = pos_x + x, y = pos_y + y})
|
||||
dim = 30
|
||||
pos_x = math.sin(angle_in_rad) * dim
|
||||
pos_y = math.cos(angle_in_rad) * dim
|
||||
player:hud_change(ids[prefix .. "7"], "offset", {x = pos_x + x, y = pos_y + y})
|
||||
end
|
||||
end
|
||||
|
||||
function out_here.update_hud(player)
|
||||
local player_name = player:get_player_name()
|
||||
|
||||
local screen_pos_y = 0
|
||||
local screen_pos_x = 0
|
||||
|
||||
local hour_gauge_x = screen_pos_x - 116
|
||||
local hour_gauge_y = screen_pos_y + 116
|
||||
local minute_gauge_x = screen_pos_x - 116
|
||||
local minute_gauge_y = screen_pos_y + 116
|
||||
|
||||
local ids = out_here.hud_list[player_name]
|
||||
if ids then
|
||||
local time = minetest:get_timeofday() * 24
|
||||
local hour, minutes = math.modf( time )
|
||||
minutes = math.floor(minutes * 100)
|
||||
minutes = (minutes * 60) / 100
|
||||
local minute_angle = (minutes*-360)/60
|
||||
local hour_angle = (hour*-360)/12 + ((minute_angle*30)/360)
|
||||
out_here.animate_gauge(player, ids, "hour_pt_", hour_gauge_x, hour_gauge_y, hour_angle, 1)
|
||||
out_here.animate_gauge(player, ids, "minute_pt_", minute_gauge_x, minute_gauge_y, minute_angle)
|
||||
else
|
||||
ids = {}
|
||||
local pointer_texture = "hud_analog_clock_ind_box.png"
|
||||
ids["bg"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 1, y = 0},
|
||||
offset = {x = screen_pos_x, y = screen_pos_y},
|
||||
text = "hud_analog_clock.png",
|
||||
scale = { x = 0.5, y = 0.5 },
|
||||
alignment = { x = -2.25, y = 2.25 },
|
||||
})
|
||||
|
||||
ids["hour_pt_1"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 1, y = 0},
|
||||
offset = {x = hour_gauge_x, y = hour_gauge_y},
|
||||
text = pointer_texture,
|
||||
scale = { x = 3, y = 3},
|
||||
alignment = { x = -2.25, y = 2.25 },
|
||||
})
|
||||
|
||||
ids["hour_pt_2"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 1, y = 0},
|
||||
offset = {x = hour_gauge_x, y = hour_gauge_y},
|
||||
text = pointer_texture,
|
||||
scale = { x = 3, y = 3},
|
||||
alignment = { x = -2.25, y = 2.25 },
|
||||
})
|
||||
ids["hour_pt_3"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 1, y = 0},
|
||||
offset = {x = hour_gauge_x, y = hour_gauge_y},
|
||||
text = pointer_texture,
|
||||
scale = { x = 3, y = 3},
|
||||
alignment = { x = -2.25, y = 2.25 },
|
||||
})
|
||||
ids["hour_pt_4"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 1, y = 0},
|
||||
offset = {x = hour_gauge_x, y = hour_gauge_y},
|
||||
text = pointer_texture,
|
||||
scale = { x = 3, y = 3},
|
||||
alignment = { x = -2.25, y = 2.25 },
|
||||
})
|
||||
--[[ids["hour_pt_5"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 1, y = 0},
|
||||
offset = {x = hour_gauge_x, y = hour_gauge_y},
|
||||
text = pointer_texture,
|
||||
scale = { x = 3, y = 3},
|
||||
alignment = { x = -2.25, y = 2.25 },
|
||||
})
|
||||
ids["hour_pt_6"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 1, y = 0},
|
||||
offset = {x = hour_gauge_x, y = hour_gauge_y},
|
||||
text = pointer_texture,
|
||||
scale = { x = 3, y = 3},
|
||||
alignment = { x = -2.25, y = 2.25 },
|
||||
})
|
||||
ids["hour_pt_7"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 1, y = 0},
|
||||
offset = {x = hour_gauge_x, y = hour_gauge_y},
|
||||
text = pointer_texture,
|
||||
scale = { x = 3, y = 3},
|
||||
alignment = { x = -2.25, y = 2.25 },
|
||||
})]]--
|
||||
|
||||
ids["minute_pt_1"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 1, y = 0},
|
||||
offset = {x = minute_gauge_x, y = minute_gauge_y},
|
||||
text = pointer_texture,
|
||||
scale = { x = 3, y = 3},
|
||||
alignment = { x = -2.25, y = 2.25 },
|
||||
})
|
||||
ids["minute_pt_2"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 1, y = 0},
|
||||
offset = {x = minute_gauge_x, y = minute_gauge_y},
|
||||
text = pointer_texture,
|
||||
scale = { x = 3, y = 3},
|
||||
alignment = { x = -2.25, y = 2.25 },
|
||||
})
|
||||
ids["minute_pt_3"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 1, y = 0},
|
||||
offset = {x = minute_gauge_x, y = minute_gauge_y},
|
||||
text = pointer_texture,
|
||||
scale = { x = 3, y = 3},
|
||||
alignment = { x = -2.25, y = 2.25 },
|
||||
})
|
||||
ids["minute_pt_4"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 1, y = 0},
|
||||
offset = {x = minute_gauge_x, y = minute_gauge_y},
|
||||
text = pointer_texture,
|
||||
scale = { x = 3, y = 3},
|
||||
alignment = { x = -2.25, y = 2.25 },
|
||||
})
|
||||
ids["minute_pt_5"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 1, y = 0},
|
||||
offset = {x = minute_gauge_x, y = minute_gauge_y},
|
||||
text = pointer_texture,
|
||||
scale = { x = 3, y = 3},
|
||||
alignment = { x = -2.25, y = 2.25 },
|
||||
})
|
||||
ids["minute_pt_6"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 1, y = 0},
|
||||
offset = {x = minute_gauge_x, y = minute_gauge_y},
|
||||
text = pointer_texture,
|
||||
scale = { x = 3, y = 3},
|
||||
alignment = { x = -2.25, y = 2.25 },
|
||||
})
|
||||
ids["minute_pt_7"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 1, y = 0},
|
||||
offset = {x = minute_gauge_x, y = minute_gauge_y},
|
||||
text = pointer_texture,
|
||||
scale = { x = 3, y = 3},
|
||||
alignment = { x = -2.25, y = 2.25 },
|
||||
})
|
||||
|
||||
out_here.hud_list[player_name] = ids
|
||||
end
|
||||
core.after(1, function()
|
||||
out_here.update_hud(player)
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
function out_here.remove_hud(player)
|
||||
if player then
|
||||
local player_name = player:get_player_name()
|
||||
--minetest.chat_send_all(player_name)
|
||||
local ids = out_here.hud_list[player_name]
|
||||
if ids then
|
||||
player:hud_remove(ids["title"])
|
||||
player:hud_remove(ids["bg"])
|
||||
player:hud_remove(ids["hour_pt_7"])
|
||||
player:hud_remove(ids["hour_pt_6"])
|
||||
player:hud_remove(ids["hour_pt_5"])
|
||||
player:hud_remove(ids["hour_pt_4"])
|
||||
player:hud_remove(ids["hour_pt_3"])
|
||||
player:hud_remove(ids["hour_pt_2"])
|
||||
player:hud_remove(ids["hour_pt_1"])
|
||||
player:hud_remove(ids["minute_pt_7"])
|
||||
player:hud_remove(ids["minute_pt_6"])
|
||||
player:hud_remove(ids["minute_pt_5"])
|
||||
player:hud_remove(ids["minute_pt_4"])
|
||||
player:hud_remove(ids["minute_pt_3"])
|
||||
player:hud_remove(ids["minute_pt_2"])
|
||||
player:hud_remove(ids["minute_pt_1"])
|
||||
end
|
||||
out_here.hud_list[player_name] = nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
minetest.register_on_joinplayer(out_here.update_hud)
|
||||
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
out_here.remove_hud(player)
|
||||
end)
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
default
|
|
@ -0,0 +1,3 @@
|
|||
modname = "hud_analog_clock"
|
||||
|
||||
dofile(minetest.get_modpath(modname) .. DIR_DELIM .. "clock_hud.lua")
|
|
@ -0,0 +1,5 @@
|
|||
name = hud_analog_clock
|
||||
depends = default
|
||||
author = APercy
|
||||
description = Adds an analogic clock to hud
|
||||
title = HUD Analogic Clock
|
Binary file not shown.
After Width: | Height: | Size: 25 KiB |
Binary file not shown.
After Width: | Height: | Size: 5.0 KiB |
Loading…
Reference in New Issue