)
This commit is contained in:
parent
1a0785862d
commit
eaf0a90173
@ -1,40 +1,13 @@
|
||||
--@include libs/utils.txt
|
||||
--@client
|
||||
|
||||
require("libs/utils.txt")
|
||||
require("/koptilnya/libs/utils.txt")
|
||||
|
||||
EngineSound = class("EngineSound")
|
||||
|
||||
accessorFunc(EngineSound, "_masterVolume", "MasterVolume", 1)
|
||||
accessorFunc(EngineSound, "_parent", "Parent", chip())
|
||||
|
||||
function EngineSound:initialize(soundsMap)
|
||||
self._rpm = 0
|
||||
self._soundsMap = soundsMap
|
||||
self._sources = {}
|
||||
|
||||
for k, v in pairs(soundsMap) do
|
||||
bass.loadURL(v.link, "3d noblock", function(snd, err, errtxt)
|
||||
if snd then
|
||||
snd:setPos(self:getParent():getPos())
|
||||
snd:setLooping(true)
|
||||
snd:setVolume(0)
|
||||
|
||||
v.source = snd
|
||||
table.insert(self._sources, snd)
|
||||
elseif errtext then
|
||||
error(errtxt)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
hook.add("think", "EngineSound_think", function()
|
||||
for _, v in pairs(self._sources) do
|
||||
v:setPos(self:getParent():getPos())
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
local function fadeIn(rpm, range)
|
||||
local fadeIn = 1
|
||||
|
||||
@ -55,19 +28,47 @@ local function fadeOut(rpm, range)
|
||||
return fadeOut
|
||||
end
|
||||
|
||||
function EngineSound:setRPM(rpm)
|
||||
self._rpm = rpm
|
||||
function EngineSound:initialize(soundsMap)
|
||||
self._rpm = 0
|
||||
self._targetRPM = 0
|
||||
self._soundsMap = soundsMap
|
||||
self._sources = {}
|
||||
|
||||
for _, v in pairs(self._soundsMap) do
|
||||
if v.source then
|
||||
local pitch = rpm / v.rootPitch
|
||||
local fadeIn = fadeIn(rpm, v.fadeIn)
|
||||
local fadeOut = fadeOut(rpm, v.fadeOut)
|
||||
|
||||
v.source:setVolume(math.max(self:getMasterVolume() * (fadeIn + fadeOut - 1), 0.01))
|
||||
v.source:setPitch(math.max(pitch, 0.01))
|
||||
end
|
||||
for k, v in pairs(soundsMap) do
|
||||
bass.loadURL(v.link, "3d noblock", function(snd, err, errtxt)
|
||||
if snd then
|
||||
snd:setPos(self:getParent():getPos())
|
||||
snd:setLooping(true)
|
||||
snd:setVolume(0)
|
||||
|
||||
v.source = snd
|
||||
table.insert(self._sources, snd)
|
||||
elseif errtext then
|
||||
error(errtxt)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
hook.add("think", "EngineSound_think", function()
|
||||
self._rpm = math.lerp(0.2, self._rpm, self._targetRPM)
|
||||
|
||||
for _, v in pairs(self._soundsMap) do
|
||||
if v.source then
|
||||
v.source:setPos(self:getParent():getPos())
|
||||
|
||||
local pitch = self._rpm / v.rootPitch
|
||||
local fadeIn = fadeIn(self._rpm, v.fadeIn)
|
||||
local fadeOut = fadeOut(self._rpm, v.fadeOut)
|
||||
|
||||
v.source:setVolume(math.max(self:getMasterVolume() * (fadeIn + fadeOut - 1), 0.01))
|
||||
v.source:setPitch(math.max(pitch, 0.01))
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function EngineSound:setRPM(rpm)
|
||||
self._targetRPM = rpm
|
||||
end
|
||||
|
||||
function EngineSound:getRPM()
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
--@include label.txt
|
||||
--@include radius_mixin.txt
|
||||
--@include ../utils.txt
|
||||
--@include /koptilnya/libs/utils.txt
|
||||
|
||||
require("label.txt")
|
||||
require("../utils.txt")
|
||||
require("/koptilnya/libs/utils.txt")
|
||||
|
||||
EButton = class("EButton", ELabel)
|
||||
EButton:include(require("radius_mixin.txt"))
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
--@include element.txt
|
||||
--@include label.txt
|
||||
--@include ../utils.txt
|
||||
--@include /koptilnya/libs/utils.txt
|
||||
|
||||
require("element.txt")
|
||||
require("label.txt")
|
||||
require("../utils.txt")
|
||||
require("/koptilnya/libs/utils.txt")
|
||||
|
||||
ECheckbox = class("ECheckbox", ELabel)
|
||||
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
--@include ../utils.txt
|
||||
--@include ../skins/default.txt
|
||||
--@include /koptilnya/libs/utils.txt
|
||||
|
||||
require("../utils.txt")
|
||||
local defaultSkin = require("../skins/default.txt")
|
||||
require("/koptilnya/libs/utils.txt")
|
||||
|
||||
Element = class("Element")
|
||||
|
||||
@ -20,7 +18,6 @@ function Element:initialize()
|
||||
self._firstChild = nil
|
||||
self._prevSibling = nil
|
||||
self._nextSibling = nil
|
||||
self._skin = defaultSkin
|
||||
end
|
||||
|
||||
function Element:setWidth(width)
|
||||
@ -128,7 +125,6 @@ function Element:addChild(child)
|
||||
checkVarClass(child, Element)
|
||||
|
||||
child:setParent(self)
|
||||
child:_setSkin(self._skin)
|
||||
|
||||
if not self._firstChild then
|
||||
self._firstChild = child
|
||||
@ -187,10 +183,6 @@ end
|
||||
|
||||
-- PROTECTED
|
||||
|
||||
function Element:_setSkin(skin)
|
||||
self._skin = skin
|
||||
end
|
||||
|
||||
function Element:_postEvent(eventKey, ...)
|
||||
if eventKey == "THINK" then
|
||||
return self:_onThink()
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
--@include element.txt
|
||||
--@include ../utils.txt
|
||||
|
||||
require("element.txt")
|
||||
require("../utils.txt")
|
||||
|
||||
EEmpty = class("EEmpty", Element)
|
||||
@ -1,8 +1,8 @@
|
||||
--@include element.txt
|
||||
--@include ../utils.txt
|
||||
--@include /koptilnya/libs/utils.txt
|
||||
|
||||
require("element.txt")
|
||||
require("../utils.txt")
|
||||
require("/koptilnya/libs/utils.txt")
|
||||
|
||||
ELabel = class("ELabel", Element)
|
||||
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
--@include element.txt
|
||||
--@include label.txt
|
||||
--@include button.txt
|
||||
--@include ../utils.txt
|
||||
--@include /koptilnya/libs/utils.txt
|
||||
|
||||
require("element.txt")
|
||||
require("label.txt")
|
||||
require("button.txt")
|
||||
require("../utils.txt")
|
||||
require("/koptilnya/libs/utils.txt")
|
||||
|
||||
EPanel = class("EPanel", Element)
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
--@include ../utils.txt
|
||||
--@include /koptilnya/libs/utils.txt
|
||||
|
||||
require("../utils.txt")
|
||||
require("/koptilnya/libs/utils.txt")
|
||||
|
||||
local MIXIN = {}
|
||||
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
--@include element.txt
|
||||
--@include ../utils.txt
|
||||
--@include /koptilnya/libs/utils.txt
|
||||
|
||||
require("element.txt")
|
||||
require("../utils.txt")
|
||||
require("/koptilnya/libs/utils.txt")
|
||||
|
||||
EShape = class("EShape", Element)
|
||||
|
||||
|
||||
@ -1,22 +1,17 @@
|
||||
--@include utils.txt
|
||||
--@include render_devices/render_device.txt
|
||||
--@include elements/root.txt
|
||||
--@include skins/default.txt
|
||||
|
||||
require("utils.txt")
|
||||
require("render_devices/render_device.txt")
|
||||
require("elements/root.txt")
|
||||
local defaultSkin = require("skins/default.txt")
|
||||
|
||||
GUI = class("GUI")
|
||||
|
||||
function GUI:initialize(renderDevice, skin)
|
||||
function GUI:initialize(renderDevice)
|
||||
checkVarClass(renderDevice, RenderDevice)
|
||||
|
||||
self.renderDevice = renderDevice
|
||||
self._root = ERoot:new("root")
|
||||
self._root:setSize(renderDevice:getSize())
|
||||
self._root:_setSkin(skin or defaultSkin)
|
||||
|
||||
hook.add("inputPressed", "gui_inputPressed", function(key)
|
||||
local keyName = input.getKeyName(key)
|
||||
@ -69,7 +64,7 @@ function GUI:getRoot()
|
||||
end
|
||||
|
||||
function GUI:add(element)
|
||||
this._root:addChild(element)
|
||||
self._root:addChild(element)
|
||||
end
|
||||
|
||||
function GUI:setVisible(state)
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
--@include ../utils.txt
|
||||
--@include /koptilnya/libs/utils.txt
|
||||
|
||||
require("../utils.txt")
|
||||
require("/koptilnya/libs/utils.txt")
|
||||
|
||||
RenderDevice = class("RenderDevice")
|
||||
|
||||
|
||||
@ -0,0 +1,44 @@
|
||||
--@client
|
||||
|
||||
function render.drawWedge(x, y, w, h, angle, mouthSize, fidelity)
|
||||
if w > 0 and h > 0 and mouthSize <= 360 then
|
||||
local vertices = {}
|
||||
|
||||
vertices[1] = { x = x, y = y, u = 0, v = 0 }
|
||||
|
||||
local _ang = -math.rad(angle)
|
||||
local _c = math.cos(_ang)
|
||||
local _s = math.sin(_ang)
|
||||
|
||||
for ii = 0, fidelity do
|
||||
local _i = ii * (360 - mouthSize) / fidelity
|
||||
local _radd = math.rad(_i)
|
||||
local _x = math.cos(_radd)
|
||||
local _u = 0.5
|
||||
local _y = math.sin(_radd)
|
||||
local _v = 0.5
|
||||
|
||||
local _tempx = _x * w * _c - _y * h * _s + x
|
||||
_y = _x * w * _s + _y * h * _c + y
|
||||
_x = _tempx
|
||||
|
||||
vertices[ii + 2] = { x = _x, y = _y, u = _u, v = _v }
|
||||
end
|
||||
|
||||
render.drawPoly(vertices)
|
||||
end
|
||||
end
|
||||
|
||||
function render.drawArc(x, y, ang, p, rad, color, seg)
|
||||
seg = seg || 80
|
||||
ang = (-ang) + 180
|
||||
local vertices = {}
|
||||
|
||||
table.insert(vertices, {x = x, y = y})
|
||||
for i = 0, seg do
|
||||
local a = math.rad((i / seg) * -p + ang)
|
||||
table.insert(vertices, {x = x + math.sin(a) * rad, y = y + math.cos(a) * rad})
|
||||
end
|
||||
|
||||
render.drawPoly(vertices)
|
||||
end
|
||||
@ -1,6 +1,6 @@
|
||||
local MODEL_PLACEHOLDER = "models/holograms/cube.mdl"
|
||||
local BUNDLE_SIZE = 30
|
||||
local SEND_DELAY = 2
|
||||
local BUNDLE_SIZE = 2
|
||||
local SEND_DELAY = 0.5
|
||||
|
||||
MeshBuilder = class("MeshBuilder")
|
||||
|
||||
@ -19,7 +19,6 @@ function MeshBuilder:initialize()
|
||||
|
||||
net.readEntity(function(ent)
|
||||
if not self._objects[key] then
|
||||
|
||||
local holo = ent:toHologram()
|
||||
|
||||
if self._meshData[key] then
|
||||
@ -47,11 +46,12 @@ function MeshBuilder:initialize()
|
||||
local color = net.readColor()
|
||||
local mat = net.readString()
|
||||
local parent = net.readEntity()
|
||||
local relativeTo = net.readEntity()
|
||||
|
||||
if not self._objects[key] then
|
||||
if isValid(parent) then
|
||||
pos = parent:localToWorld(pos)
|
||||
ang = parent:localToWorldAngles(ang)
|
||||
if isValid(relativeTo) then
|
||||
pos = relativeTo:localToWorld(pos)
|
||||
ang = relativeTo:localToWorldAngles(ang)
|
||||
end
|
||||
|
||||
local holo = holograms.create(pos, ang, MODEL_PLACEHOLDER, scale)
|
||||
@ -71,11 +71,9 @@ function MeshBuilder:initialize()
|
||||
|
||||
net.start("sendHolograms")
|
||||
for k, v in pairs(self._bundle) do
|
||||
if isValid(v) and type(v) == "Hologram" then
|
||||
net.writeBit(1)
|
||||
net.writeString(k)
|
||||
net.writeEntity(v)
|
||||
end
|
||||
net.writeBit(1)
|
||||
net.writeString(k)
|
||||
net.writeEntity(v)
|
||||
end
|
||||
net.writeBit(0)
|
||||
net.send(ply)
|
||||
@ -90,7 +88,7 @@ if CLIENT then
|
||||
self._meshData = meshData
|
||||
end
|
||||
|
||||
function MeshBuilder:setup(key, pos, ang, scale, color, mat, parent)
|
||||
function MeshBuilder:setup(key, pos, ang, scale, color, mat, parent, relativeTo)
|
||||
if not self._objects[key] and not self._bundle[key] and self._meshData[key] then
|
||||
self._bundle[key] = {
|
||||
pos = pos,
|
||||
@ -98,12 +96,13 @@ if CLIENT then
|
||||
scale = scale,
|
||||
color = color,
|
||||
mat = mat,
|
||||
parent = isValid(parent) and parent or chip()
|
||||
parent = isValid(parent) and parent or chip(),
|
||||
relativeTo = isValid(relativeTo) and relativeTo or chip()
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
function MeshBuilder:setupAll(pos, ang, scale, color, mat, parent)
|
||||
function MeshBuilder:setupAll(pos, ang, scale, color, mat, parent, relativeTo)
|
||||
for _, v in pairs(table.getKeys(self._meshData)) do
|
||||
self:setup(v, pos, ang, scale, color, mat, parent)
|
||||
end
|
||||
@ -121,6 +120,7 @@ if CLIENT then
|
||||
net.writeColor(v.color)
|
||||
net.writeString(v.mat)
|
||||
net.writeEntity(v.parent)
|
||||
net.writeEntity(v.relativeTo)
|
||||
end
|
||||
net.writeBit(0)
|
||||
net.send()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user