Interpolated HUD and radial menu UI.
This commit is contained in:
parent
5211cc20f2
commit
6439f11c2f
7 changed files with 456 additions and 30 deletions
|
|
@ -3,10 +3,14 @@ local ns = artifact
|
|||
ns.players = {}
|
||||
local db = minetest.get_mod_storage()
|
||||
|
||||
include "radial_menu.lua"
|
||||
|
||||
Player = setmetatable({
|
||||
new = function(p)
|
||||
local m = setmetatable({
|
||||
object = p
|
||||
object = p,
|
||||
pitch = 0,
|
||||
yaw = 0
|
||||
}, {__index = Player})
|
||||
|
||||
m.name = p:get_player_name()
|
||||
|
|
@ -46,6 +50,8 @@ Player = setmetatable({
|
|||
basic_debug = false
|
||||
}
|
||||
|
||||
m.hud = {}
|
||||
m.poi = {}
|
||||
m:create_hud()
|
||||
|
||||
m:set_hotbar_size(8)
|
||||
|
|
@ -58,6 +64,8 @@ Player = setmetatable({
|
|||
local time = minetest.get_us_time()
|
||||
local p = m.object
|
||||
local pos = p:get_pos()
|
||||
local yaw = p:get_look_horizontal()
|
||||
local pitch = p:get_look_vertical()
|
||||
local dir = p:get_look_dir()
|
||||
m.pos = pos
|
||||
m.pos.y = m.pos.y +m.eye_height
|
||||
|
|
@ -149,9 +157,81 @@ Player = setmetatable({
|
|||
m.interacting_with = nil
|
||||
m.interaction_start = nil
|
||||
end
|
||||
|
||||
local wi = p:get_wielded_item()
|
||||
|
||||
m.wielded_item = wi
|
||||
|
||||
if ctl.place and not m.ctl.place and wi:get_name() == "artifact:input" then
|
||||
artifact.show_radial_menu(m, {
|
||||
name = "construct",
|
||||
"test",
|
||||
"test2",
|
||||
"test3",
|
||||
"test4",
|
||||
"test5"
|
||||
})
|
||||
elseif m._menu and not (ctl.place and wi:get_name() == "artifact:input") then
|
||||
artifact.dismiss_radial_menu(m, "construct")
|
||||
elseif m._menu then
|
||||
local dx = m.yaw -yaw
|
||||
local dy = m.pitch -pitch
|
||||
if dx ~= 0 and dy ~= 0 then
|
||||
m._menu.pos.x = m._menu.pos.x +dx *200
|
||||
m._menu.pos.y = m._menu.pos.y -dy *200
|
||||
local r = m._menu.pos:distance(vector.zero())
|
||||
if r > 50 then
|
||||
r = 50
|
||||
m._menu.pos = m._menu.pos:normalize() *50
|
||||
end
|
||||
p:hud_change(m._menu.cursor._id, "offset", m._menu.pos)
|
||||
if r > 20 then
|
||||
local angle = minetest.dir_to_yaw(vector.new(m._menu.pos.x, 0, m._menu.pos.y):normalize())
|
||||
local idx = math.floor((-angle +math.pi +(m._menu.step /2)) %(math.pi *2) /m._menu.step) +1
|
||||
if m._menu.selected and m._menu.selected ~= idx then
|
||||
m._menu[m._menu.selected]:animate{
|
||||
scale = {
|
||||
value = {x=0.7, y=0.7},
|
||||
duration = 0.2
|
||||
},
|
||||
opacity = {
|
||||
value = 128,
|
||||
duration = 0.2
|
||||
}
|
||||
}
|
||||
end
|
||||
if m._menu.selected ~= idx and m._menu[idx] then
|
||||
m._menu.selected = idx
|
||||
m._menu[m._menu.selected]:animate{
|
||||
scale = {
|
||||
value = {x=1, y=1},
|
||||
duration = 0.2
|
||||
},
|
||||
opacity = {
|
||||
value = 256,
|
||||
duration = 0.2
|
||||
}
|
||||
}
|
||||
end
|
||||
elseif m._menu.selected then
|
||||
m._menu[m._menu.selected]:animate{
|
||||
scale = {
|
||||
value = {x=0.7, y=0.7},
|
||||
duration = 0.2
|
||||
},
|
||||
opacity = {
|
||||
value = 128,
|
||||
duration = 0.2
|
||||
}
|
||||
}
|
||||
m._menu.selected = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
m.ctl = ctl
|
||||
|
||||
m.yaw = yaw
|
||||
m.pitch = pitch
|
||||
end,
|
||||
set_character = function(m, to)
|
||||
m.character = to
|
||||
|
|
@ -162,34 +242,34 @@ Player = setmetatable({
|
|||
-- If called post-init, make sure we delete the previous HUD.
|
||||
-- This is useful when we want to recreate the HUD in response
|
||||
-- to an event, like freeing Vix.
|
||||
if m.hud then
|
||||
for _, x in pairs(m.hud) do
|
||||
if type(x) == "table" then
|
||||
for _, y in pairs(x) do
|
||||
m.object:hud_remove(y)
|
||||
end
|
||||
else
|
||||
m.object:hud_remove(x)
|
||||
end
|
||||
end
|
||||
end
|
||||
m.hud = {
|
||||
key_health = m.object:hud_add {
|
||||
type = "statbar",
|
||||
position = {x=0.5,y=1},
|
||||
offset = {x=-27 *5,y=artifact.debug and -96 or -30},
|
||||
scale = {x=4,y=4},
|
||||
alignment = {x=-1, y=-1},
|
||||
size = {x=27,y=27},
|
||||
text = "artifact_heart_vix.png",
|
||||
text2 = "artifact_heart_bg.png",
|
||||
number = 20
|
||||
}
|
||||
}
|
||||
|
||||
if artifact.debug or artifact.story.states[artifact.story.get_state()] >= artifact.story.states.main then
|
||||
|
||||
end
|
||||
-- if m.hud then
|
||||
-- for _, x in pairs(m.hud) do
|
||||
-- if type(x) == "table" then
|
||||
-- for _, y in pairs(x) do
|
||||
-- m.object:hud_remove(y)
|
||||
-- end
|
||||
-- else
|
||||
-- m.object:hud_remove(x)
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
-- m.hud = {
|
||||
-- key_health = m.object:hud_add {
|
||||
-- type = "statbar",
|
||||
-- position = {x=0.5,y=1},
|
||||
-- offset = {x=-27 *5,y=artifact.debug and -96 or -30},
|
||||
-- scale = {x=4,y=4},
|
||||
-- alignment = {x=-1, y=-1},
|
||||
-- size = {x=27,y=27},
|
||||
-- text = "artifact_heart_vix.png",
|
||||
-- text2 = "artifact_heart_bg.png",
|
||||
-- number = 20
|
||||
-- }
|
||||
-- }
|
||||
--
|
||||
-- if artifact.debug or artifact.story.states[artifact.story.get_state()] >= artifact.story.states.main then
|
||||
--
|
||||
-- end
|
||||
end,
|
||||
set_hotbar_size = function(m, slots)
|
||||
local p = m.object
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue