changes
This commit is contained in:
parent
44a539758f
commit
1e9e783ee6
@ -5,7 +5,6 @@ require("/koptilnya/libs/utils.txt")
|
||||
|
||||
EngineSound = class("EngineSound")
|
||||
|
||||
accessorFunc(EngineSound, "_rpm", "RPM", 0)
|
||||
accessorFunc(EngineSound, "_masterVolume", "MasterVolume", 1)
|
||||
accessorFunc(EngineSound, "_parent", "Parent", chip())
|
||||
|
||||
@ -14,6 +13,8 @@ local function fadeIn(rpm, range)
|
||||
|
||||
if range and range[1] != range[2] then
|
||||
fadeIn = math.min(math.max((rpm + (range[2] - range[1] * 2)) / (range[2] - range[1]), 1) - 1, 1)
|
||||
elseif range and range[1] == range[2] then
|
||||
fadeIn = rpm >= range[1] and 1 or 0
|
||||
end
|
||||
|
||||
return fadeIn
|
||||
@ -24,6 +25,8 @@ local function fadeOut(rpm, range)
|
||||
|
||||
if range and range[1] != range[2] then
|
||||
fadeOut = math.min(math.max((rpm + (range[1] - range[2] * 2)) / (range[1] - range[2]), 1) - 1, 1)
|
||||
elseif range and range[1] == range[2] then
|
||||
fadeOut = rpm >= range[1] and 1 or 0
|
||||
end
|
||||
|
||||
return fadeOut
|
||||
@ -33,8 +36,8 @@ function EngineSound:initialize(soundsMap)
|
||||
self.pitchDamping = 0.2
|
||||
self.volumeDamping = 0.3
|
||||
|
||||
self._rpm = 0
|
||||
self._soundsMap = soundsMap
|
||||
self._lastRPM = 0
|
||||
|
||||
for k, v in pairs(soundsMap) do
|
||||
bass.loadURL(v.link, "3d noblock", function(snd, err, errtxt)
|
||||
@ -57,10 +60,10 @@ function EngineSound:initialize(soundsMap)
|
||||
if v.source then
|
||||
v.source:setPos(self:getParent():getPos())
|
||||
|
||||
local fadeIn = fadeIn(self._rpm, v.fadeIn)
|
||||
local fadeOut = fadeOut(self._rpm, v.fadeOut)
|
||||
local fadeIn = fadeIn(self:getRPM(), v.fadeIn)
|
||||
local fadeOut = fadeOut(self:getRPM(), v.fadeOut)
|
||||
local targetVolume = self:getMasterVolume() * (fadeIn + fadeOut - 1)
|
||||
local targetPitch = self._rpm / v.rootPitch
|
||||
local targetPitch = self:getRPM() / v.rootPitch
|
||||
|
||||
local pitch = math.lerp(self.pitchDamping, v.lastPitch, targetPitch)
|
||||
local volume = math.lerp(self.volumeDamping, v.lastVolume, targetVolume)
|
||||
@ -72,7 +75,13 @@ function EngineSound:initialize(soundsMap)
|
||||
v.lastPitch = pitch
|
||||
end
|
||||
end
|
||||
|
||||
_lastRPM = _rpm
|
||||
end)
|
||||
end
|
||||
|
||||
function EngineSound:setRPM(rpm)
|
||||
self._rpm = math.max(rpm, 0)
|
||||
end
|
||||
|
||||
function EngineSound:getRPM()
|
||||
return self._rpm
|
||||
end
|
||||
|
||||
@ -12,7 +12,7 @@ function EButton:initialize()
|
||||
self:setText("Button")
|
||||
self:setSize(100, 32)
|
||||
self:setRoundedCorners(true)
|
||||
self:setRadius(5)
|
||||
self:setRadius(0)
|
||||
self:setColorScheme({
|
||||
bg = {
|
||||
Color(46, 46, 46),
|
||||
|
||||
@ -48,8 +48,7 @@ function ECheckbox:paint(x, y, w, h)
|
||||
render.drawRectFast(x + 4, y + 4, w - 8, h - 8)
|
||||
|
||||
render.setColor(self:getColorFromScheme("border"))
|
||||
render.drawRectOutline(x, y, w, h, 1)
|
||||
render.drawRectOutline(x + 1, y + 1, w - 2, h - 2, 1)
|
||||
render.drawRectOutline(x, y, w, h, 2)
|
||||
end
|
||||
|
||||
-- STUB
|
||||
|
||||
12
koptilnya/gui/elements/icon_button.txt
Normal file
12
koptilnya/gui/elements/icon_button.txt
Normal file
@ -0,0 +1,12 @@
|
||||
--@include button.txt
|
||||
--@include radius_mixin.txt
|
||||
|
||||
require("label.txt")
|
||||
|
||||
EIconButton = class("EIconButton", EButton)
|
||||
|
||||
function EIconButton:initialize()
|
||||
EButton.initialize(self)
|
||||
|
||||
self:setFont(GUI.fonts.icons)
|
||||
end
|
||||
@ -8,6 +8,7 @@ ELabel = class("ELabel", Element)
|
||||
|
||||
function ELabel:initialize()
|
||||
Element.initialize(self)
|
||||
|
||||
self._text = ""
|
||||
self._textWidth = 0
|
||||
self._textHeight = 0
|
||||
|
||||
@ -2,12 +2,15 @@
|
||||
--@include label.txt
|
||||
--@include button.txt
|
||||
--@include /koptilnya/libs/utils.txt
|
||||
--@include /koptilnya/gui/segoe_mdl2_assets_icons.txt
|
||||
|
||||
require("element.txt")
|
||||
require("label.txt")
|
||||
require("button.txt")
|
||||
require("/koptilnya/libs/utils.txt")
|
||||
|
||||
local segoeIcons = require("/koptilnya/gui/segoe_mdl2_assets_icons.txt")
|
||||
|
||||
EPanel = class("EPanel", Element)
|
||||
|
||||
accessorFunc(EPanel, "_parentLock", "ParentLock", false)
|
||||
@ -15,6 +18,8 @@ accessorFunc(EPanel, "_parentLock", "ParentLock", false)
|
||||
function EPanel:initialize()
|
||||
Element.initialize(self)
|
||||
|
||||
self._minimizable = true
|
||||
self._closeable = true
|
||||
self._minimized = false
|
||||
self._lastHeight = 0
|
||||
|
||||
@ -32,7 +37,7 @@ function EPanel:initialize()
|
||||
|
||||
self.minimizeButton = EButton:new()
|
||||
self.minimizeButton:setFont(GUI.fonts["icons"])
|
||||
self.minimizeButton:setText(string.utf8char(0xE73F))
|
||||
self.minimizeButton:setText(segoeIcons.ChromeMinimize)
|
||||
self.minimizeButton:setSize(32, 32)
|
||||
self.minimizeButton:setRadius(0)
|
||||
self.minimizeButton:setColorScheme(colorScheme)
|
||||
@ -43,7 +48,7 @@ function EPanel:initialize()
|
||||
|
||||
self.closeButton = EButton:new()
|
||||
self.closeButton:setFont(GUI.fonts["icons"])
|
||||
self.closeButton:setText(string.utf8char(0xE006))
|
||||
self.closeButton:setText(string.utf8char(0xE8BB))
|
||||
self.closeButton:setSize(32, 32)
|
||||
self.closeButton:setRadius(0)
|
||||
self.closeButton:setColorScheme(colorScheme)
|
||||
@ -74,28 +79,52 @@ function EPanel:getTitle()
|
||||
return self.title:getText()
|
||||
end
|
||||
|
||||
function EPanel:setMinimized(state)
|
||||
self._minimized = state
|
||||
function EPanel:setMinimizable(state)
|
||||
self._minimizable = state
|
||||
|
||||
self.minimizeButton:setEnabled(state)
|
||||
self.minimizeButton:setVisible(state)
|
||||
end
|
||||
|
||||
function EPanel:isMinimizable()
|
||||
return self._minimizable
|
||||
end
|
||||
|
||||
function EPanel:setCloseable(state)
|
||||
self._closeable = state
|
||||
|
||||
self.closeButton:setEnabled(state)
|
||||
self.closeButton:setVisible(state)
|
||||
end
|
||||
|
||||
function EPanel:isMinimized()
|
||||
return self._minimized
|
||||
end
|
||||
|
||||
function EPanel:setMinimized(state)
|
||||
self._minimized = state
|
||||
end
|
||||
|
||||
function EPanel:isCloseable()
|
||||
return self._minimizable
|
||||
end
|
||||
|
||||
function EPanel:close()
|
||||
self:setVisible(false)
|
||||
self:setEnabled(false)
|
||||
self:onClose()
|
||||
end
|
||||
|
||||
function EPanel:open()
|
||||
self:setVisible(true)
|
||||
self:setEnabled(true)
|
||||
self:onOpen()
|
||||
end
|
||||
|
||||
function EPanel:minimize()
|
||||
self._lastHeight = self:getHeight()
|
||||
|
||||
self.minimizeButton:setText(string.utf8char(10063))
|
||||
self.minimizeButton:setText(segoeIcons.ChromeMaximize)
|
||||
self:setMinimized(true)
|
||||
self:setHeight(34)
|
||||
|
||||
@ -110,7 +139,7 @@ function EPanel:minimize()
|
||||
end
|
||||
|
||||
function EPanel:maximize()
|
||||
self.minimizeButton:setText("_")
|
||||
self.minimizeButton:setText(segoeIcons.ChromeMinimize)
|
||||
self:setMinimized(false)
|
||||
self:setHeight(self._lastHeight)
|
||||
|
||||
@ -181,4 +210,12 @@ function EPanel:paint(x, y, w, h)
|
||||
|
||||
render.setColor(self:getColorFromScheme("bg"))
|
||||
render.drawRectFast(x + 1, y + 33, w - 2, h - 34)
|
||||
end
|
||||
|
||||
-- STUB
|
||||
|
||||
function EPanel:onClose()
|
||||
end
|
||||
|
||||
function EPanel:onOpen()
|
||||
end
|
||||
@ -10,6 +10,6 @@ accessorFunc(EShape, "_color", "Color", Color(255, 255, 255))
|
||||
accessorFunc(EShape, "_hoveredColor", "HoveredColor", Color(150, 150, 150))
|
||||
|
||||
function EShape:paint(x, y, w, h)
|
||||
render.setColor(self:isHovered() and self:getHoveredColor() or self:getColor())
|
||||
render.setColor(self:getColor())
|
||||
render.drawRectFast(x, y, w, h)
|
||||
end
|
||||
@ -8,14 +8,14 @@ GUI = class("GUI")
|
||||
|
||||
GUI.static.fonts = {
|
||||
main = render.createFont("Roboto", 16, 700, true),
|
||||
icons = render.createFont("Segoe MDL2 Assets", 32, 400, true)
|
||||
icons = render.createFont("Segoe MDL2 Assets", 16, 400, true, false, false, false, false, true)
|
||||
}
|
||||
|
||||
function GUI:initialize(renderDevice)
|
||||
checkVarClass(renderDevice, RenderDevice)
|
||||
|
||||
self.renderDevice = renderDevice
|
||||
self._root = ERoot:new("root")
|
||||
self._root = ERoot:new()
|
||||
self._root:setSize(renderDevice:getSize())
|
||||
|
||||
hook.add("inputPressed", "gui_inputPressed", function(key)
|
||||
|
||||
@ -5,12 +5,15 @@ require("render_device.txt")
|
||||
RenderDeviceHUD = class("RenderDeviceHUD", RenderDevice)
|
||||
|
||||
function RenderDeviceHUD:initialize()
|
||||
enableHud(player(), true)
|
||||
--if player() == owner() then
|
||||
-- enableHud(player(), true)
|
||||
--end
|
||||
|
||||
self:setSize(render.getResolution())
|
||||
|
||||
hook.add("hudshoulddraw", "gui_hudshoulddraw", function(name)
|
||||
return name == "CHudGMod" or name == "CHudChat"
|
||||
end)
|
||||
--hook.add("hudshoulddraw", "gui_hudshoulddraw", function(name)
|
||||
-- return name == "CHudGMod" or name == "CHudChat"
|
||||
--end)
|
||||
|
||||
hook.add("postdrawhud", "gui_renderer", function()
|
||||
self:render()
|
||||
|
||||
@ -4,6 +4,7 @@ require("/koptilnya/libs/utils.txt")
|
||||
|
||||
RenderDevice = class("RenderDevice")
|
||||
|
||||
accessorFunc(RenderDevice, "_player", "Player", nil)
|
||||
accessorFunc(RenderDevice, "_width", "Width", 0)
|
||||
accessorFunc(RenderDevice, "_height", "Height", 0)
|
||||
|
||||
@ -24,5 +25,7 @@ function RenderDevice:getSize()
|
||||
return self:getWidth(), self:getHeight()
|
||||
end
|
||||
|
||||
-- STUB
|
||||
|
||||
function RenderDevice:render()
|
||||
end
|
||||
1384
koptilnya/gui/segoe_mdl2_assets_icons.txt
Normal file
1384
koptilnya/gui/segoe_mdl2_assets_icons.txt
Normal file
File diff suppressed because it is too large
Load Diff
47
koptilnya/libs/workers.txt
Normal file
47
koptilnya/libs/workers.txt
Normal file
@ -0,0 +1,47 @@
|
||||
WORKERS = {}
|
||||
WORKERS_QUOTA = 0.5
|
||||
|
||||
local function execWorker(worker)
|
||||
local status
|
||||
|
||||
while math.max(quotaAverage(), quotaUsed()) < quotaMax() * WORKERS_QUOTA do
|
||||
status = worker()
|
||||
|
||||
if status == 1 or status == 2 then
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
return status
|
||||
end
|
||||
|
||||
local function procWorkers()
|
||||
local i = 1
|
||||
while i <= #WORKERS do
|
||||
local status = execWorker(WORKERS[i])
|
||||
|
||||
if status == 2 then
|
||||
table.remove(WORKERS, i)
|
||||
elseif status == 1 then
|
||||
i = i + 1
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if #WORKERS == 0 then
|
||||
hook.remove("think", "workers_think")
|
||||
end
|
||||
end
|
||||
|
||||
function addWorker(worker)
|
||||
local status = execWorker(worker)
|
||||
|
||||
if status ~= 2 then
|
||||
if #WORKERS == 0 then
|
||||
hook.add("think", "workers_think", procWorkers)
|
||||
end
|
||||
|
||||
WORKERS[#WORKERS + 1] = worker
|
||||
end
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user