Merge branch 'MihailRis:main' into main

This commit is contained in:
Xertis
2025-01-18 15:54:34 +03:00
committed by GitHub
78 changed files with 930 additions and 254 deletions
@@ -3,7 +3,9 @@ local body = entity.rigidbody
local rig = entity.skeleton
local itemid = 0
local headIndex = rig:index("head")
local itemIndex = rig:index("item")
local bodyIndex = rig:index("body")
local function refresh_model(id)
itemid = id
@@ -12,7 +14,16 @@ local function refresh_model(id)
end
function on_render()
local invid, slotid = player.get_inventory()
local pid = entity:get_player()
if pid == -1 then
return
end
local rx, ry, rz = player.get_rot(pid, true)
rig:set_matrix(headIndex, mat4.rotate({1, 0, 0}, ry))
rig:set_matrix(bodyIndex, mat4.rotate({0, 1, 0}, rx))
local invid, slotid = player.get_inventory(pid)
local id, _ = inventory.get(invid, slotid)
if id ~= itemid then
refresh_model(id)
+11
View File
@@ -134,6 +134,10 @@ function add_to_history(text)
end
function submit(text)
if #text == 0 then
document.prompt.focused = true
return
end
text = text:trim()
add_to_history(text)
@@ -204,4 +208,11 @@ function on_open(mode)
elseif mode then
modes:set(mode)
end
hud.close("core:ingame_chat")
end
function on_close()
time.post_runnable(function()
hud.open_permanent("core:ingame_chat")
end)
end
+8
View File
@@ -0,0 +1,8 @@
<panel size="300,0" margin="0,0,0,70" max-length='300' min-length='0'
size-func="gui.get_viewport()[1]/2,-1"
padding="0"
min-size="0"
color="0"
interval="0"
gravity="bottom-left" interactive="false">
</panel>
+59
View File
@@ -0,0 +1,59 @@
local lines = {}
local dead_lines = {}
local nextid = 0
local timeout = 7
local fadeout = 1
local initialized = false
local max_lines = 15
local animation_fps = 30
local function remove_line(line)
document[line[1]]:destruct()
time.post_runnable(function() document.root:reposition() end)
end
local function update_line(line, uptime)
local diff = uptime - line[2]
if diff > timeout then
remove_line(line)
table.insert(dead_lines, i)
elseif diff > timeout-fadeout then
local opacity = (timeout - diff) / fadeout
document[line[1]].color = {0, 0, 0, opacity * 80}
document[line[1].."L"].color = {255, 255, 255, opacity * 255}
end
end
events.on("core:chat", function(message)
local current_time = time.uptime()
local id = 'l'..tostring(nextid)
document.root:add(gui.template("chat_line", {id=id}))
document.root:reposition()
document[id.."L"].text = message
nextid = nextid + 1
if #lines == max_lines then
remove_line(lines[1])
table.remove(lines, 1)
end
table.insert(lines, {id, current_time})
end)
function on_open()
if not initialized then
initialized = true
document.root:setInterval(1/animation_fps * 1000, function ()
local uptime = time.uptime()
for _, line in ipairs(lines) do
update_line(line, uptime)
end
if #dead_lines > 0 then
for i = #dead_lines, 1, -1 do
local index = dead_lines[i]
table.remove(lines, i)
end
dead_lines = {}
end
end)
end
end
+2
View File
@@ -37,4 +37,6 @@ end
function on_open()
refresh()
input.add_callback("key:f5", refresh, document.root)
end
+3
View File
@@ -0,0 +1,3 @@
<container id='%{id}' color="#00000050" size="-1,20">
<label pos='5' id='%{id}L' markup='md'/>
</container>
-36
View File
@@ -1,36 +0,0 @@
local gui_util = {}
--- Parse `pagename?arg1=value1&arg2=value2` queries
--- @param query page query string
--- @return page_name, args_table
function gui_util.parse_query(query)
local args = {}
local name
local index = string.find(query, '?')
if index then
local argstr = string.sub(query, index + 1)
name = string.sub(query, 1, index - 1)
for key, value in string.gmatch(argstr, "([^=&]*)=([^&]*)") do
args[key] = value
end
else
name = query
end
return name, args
end
--- @param query page query string
--- @return document_id
function gui_util.load_page(query)
local name, args = gui_util.parse_query(query)
local filename = file.find(string.format("layouts/pages/%s.xml", name))
if filename then
name = file.prefix(filename)..":pages/"..name
gui.load_document(filename, name, args)
return name
end
end
return gui_util
+107
View File
@@ -0,0 +1,107 @@
local gui_util = {
local_dispatchers = {}
}
--- Parse `pagename?arg1=value1&arg2=value2` queries
--- @param query page query string
--- @return page_name, args_table
function gui_util.parse_query(query)
local args = {}
local name
local index = string.find(query, '?')
if index then
local argstr = string.sub(query, index + 1)
name = string.sub(query, 1, index - 1)
for key, value in string.gmatch(argstr, "([^=&]*)=([^&]*)") do
args[key] = value
end
else
name = query
end
return name, args
end
--- @param query page query string
--- @return document_id
function gui_util.load_page(query)
local name, args = gui_util.parse_query(query)
for i = #gui_util.local_dispatchers, 1, -1 do
local newname, newargs = gui_util.local_dispatchers[i](name, args)
name = newname or name
args = newargs or args
end
local filename = file.find(string.format("layouts/pages/%s.xml", name))
if filename then
name = file.prefix(filename)..":pages/"..name
gui.load_document(filename, name, args)
return name
end
end
function gui_util.add_page_dispatcher(dispatcher)
if type(dispatcher) ~= "function" then
error("function expected")
end
table.insert(gui_util.local_dispatchers, dispatcher)
end
function gui_util.reset_local()
gui_util.local_dispatchers = {}
end
-- class designed for simple UI-nodes access via properties syntax
local Element = {}
function Element.new(docname, name)
return setmetatable({docname=docname, name=name}, {
__index=function(self, k)
return gui.getattr(self.docname, self.name, k)
end,
__newindex=function(self, k, v)
gui.setattr(self.docname, self.name, k, v)
end
})
end
-- the engine automatically creates an instance for every ui document (layout)
local Document = {}
function Document.new(docname)
return setmetatable({name=docname}, {
__index=function(self, k)
local elem = Element.new(self.name, k)
rawset(self, k, elem)
return elem
end
})
end
local RadioGroup = {}
function RadioGroup:set(key)
if type(self) ~= 'table' then
error("called as non-OOP via '.', use radiogroup:set")
end
if self.current then
self.elements[self.current].enabled = true
end
self.elements[key].enabled = false
self.current = key
if self.callback then
self.callback(key)
end
end
function RadioGroup:__call(elements, onset, default)
local group = setmetatable({
elements=elements,
callback=onset,
current=nil
}, {__index=self})
group:set(default)
return group
end
setmetatable(RadioGroup, RadioGroup)
gui_util.Document = Document
gui_util.RadioGroup = RadioGroup
return gui_util
+2
View File
@@ -49,6 +49,7 @@ local Skeleton = {__index={
set_visible=function(self, i, b) return __skeleton.set_visible(self.eid, i, b) end,
get_color=function(self) return __skeleton.get_color(self.eid) end,
set_color=function(self, color) return __skeleton.set_color(self.eid, color) end,
set_interpolated=function(self, b) return __skeleton.set_interpolated(self.eid, b) end,
}}
local function new_Skeleton(eid)
@@ -66,6 +67,7 @@ local Entity = {__index={
get_uid=function(self) return self.eid end,
def_index=function(self) return entities.get_def(self.eid) end,
def_name=function(self) return entities.def_name(entities.get_def(self.eid)) end,
get_player=function(self) return entities.get_player(self.eid) end,
}}
local entities = {}
+1 -1
View File
@@ -260,7 +260,7 @@ console.add_command(
"chat text:str",
"Send chat message",
function (args, kwargs)
console.log("[you] "..args[1])
console.chat("[you] "..args[1])
end
)
+24 -53
View File
@@ -146,64 +146,16 @@ function events.emit(event, ...)
return result
end
-- class designed for simple UI-nodes access via properties syntax
local Element = {}
function Element.new(docname, name)
return setmetatable({docname=docname, name=name}, {
__index=function(self, k)
return gui.getattr(self.docname, self.name, k)
end,
__newindex=function(self, k, v)
gui.setattr(self.docname, self.name, k, v)
end
})
end
gui_util = require "core:internal/gui_util"
-- the engine automatically creates an instance for every ui document (layout)
Document = {}
function Document.new(docname)
return setmetatable({name=docname}, {
__index=function(self, k)
local elem = Element.new(self.name, k)
rawset(self, k, elem)
return elem
end
})
end
local _RadioGroup = {}
function _RadioGroup:set(key)
if type(self) ~= 'table' then
error("called as non-OOP via '.', use radiogroup:set")
end
if self.current then
self.elements[self.current].enabled = true
end
self.elements[key].enabled = false
self.current = key
if self.callback then
self.callback(key)
end
end
function _RadioGroup:__call(elements, onset, default)
local group = setmetatable({
elements=elements,
callback=onset,
current=nil
}, {__index=_RadioGroup})
group:set(default)
return group
end
setmetatable(_RadioGroup, _RadioGroup)
RadioGroup = _RadioGroup
Document = gui_util.Document
RadioGroup = gui_util.RadioGroup
__vc_page_loader = gui_util.load_page
_GUI_ROOT = Document.new("core:root")
_MENU = _GUI_ROOT.menu
menu = _MENU
local gui_util = require "core:gui_util"
__vc_page_loader = gui_util.load_page
--- Console library extension ---
console.cheats = {}
@@ -225,6 +177,11 @@ function console.log(...)
log_element:paste(text)
end
function console.chat(...)
console.log(...)
events.emit("core:chat", ...)
end
function gui.template(name, params)
local text = file.read(file.find("layouts/templates/"..name..".xml"))
for k,v in pairs(params) do
@@ -385,6 +342,16 @@ function __vc_on_hud_open()
hud.show_overlay("core:console", false, {"chat"})
end)
end)
input.add_callback("key:escape", function()
if hud.is_paused() then
hud.resume()
elseif hud.is_inventory_open() then
hud.close_inventory()
else
hud.pause()
end
end)
hud.open_permanent("core:ingame_chat")
end
local RULES_FILE = "world:rules.toml"
@@ -408,6 +375,7 @@ end
function __vc_on_world_quit()
_rules.clear()
gui_util:reset_local()
end
local __vc_coroutines = {}
@@ -470,7 +438,10 @@ function __process_post_runnables()
local dead = {}
for name, co in pairs(__vc_named_coroutines) do
coroutine.resume(co)
local success, err = coroutine.resume(co)
if not success then
debug.error(err)
end
if coroutine.status(co) == "dead" then
table.insert(dead, name)
end