Skip to content

Commit

Permalink
Derma gwen rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown-gd committed Feb 27, 2024
1 parent bc948fa commit 4c198b4
Show file tree
Hide file tree
Showing 2 changed files with 242 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lua/autorun/!!!random-patches.yue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CLIENT = CLIENT
SERVER = SERVER
pairs = pairs

addonName = "Random Patches v5.15.1"
addonName = "Random Patches v5.16.0"

getHookName = ( patchName, hookName ) ->
return addonName .. "::" .. patchName .. ( hookName or "" )
Expand Down
241 changes: 241 additions & 0 deletions lua/derma/derma_gwen.yue
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
:SetDrawColor, :SetMaterial, :DrawTexturedRectUV = surface
PANEL = FindMetaTable( "Panel" )
global GWEN = {}

do

:min, :max, :ceil, :floor = math

GWEN.CreateTextureBorder = ( _xo, _yo, _wo, _ho, l, t, r, b, material_override ) ->
material = SKIN and SKIN.GwenTexture or material_override
if material_override and not material_override\IsError!
material = material_override

texture = material\GetTexture( "$basetexture" )
width, height = texture\Width!, texture\Height!
_x, _y, _w, _h = _xo / width, _yo / height, _wo / width, _ho / height
left, right, top, bottom = 0, 0, 0, 0
_l, _t, _r, _b = 0, 0, 0, 0

return ( x, y, w, h, color ) ->
if color ~= nil
SetDrawColor( color )
else
SetDrawColor( 255, 255, 255, 255 )

SetMaterial( material )

left, right, top, bottom = min( l, ceil( w / 2 ) ), min( r, floor( w / 2 ) ), min( t, ceil( h / 2 ) ), min( b, floor( h / 2 ) )
_l, _t, _r, _b = left / width, top / height, right / width, bottom / height

-- top
DrawTexturedRectUV( x, y, left, top, _x, _y, _x + _l, _y + _t )
DrawTexturedRectUV( x + left, y, w - left - right, top, _x + _l, _y, _x + _w - _r, _y + _t )
DrawTexturedRectUV( x + w - right, y, right, top, _x + _w - _r, _y, _x + _w, _y + _t )

-- middle
DrawTexturedRectUV( x, y + top, left, h - top - bottom, _x, _y + _t, _x + _l, _y + _h - _b )
DrawTexturedRectUV( x + left, y + top, w - left - right, h - top - bottom, _x + _l, _y + _t, _x + _w - _r, _y + _h - _b )
DrawTexturedRectUV( x + w - right, y + top, right, h - top - bottom, _x + _w - _r, _y + _t, _x + _w, _y + _h - _b )

-- bottom
DrawTexturedRectUV( x, y + h - bottom, left, bottom, _x, _y + _h - _b, _x + _l, _y + _h )
DrawTexturedRectUV( x + left, y + h - bottom, w - left - right, bottom, _x + _l, _y + _h - _b, _x + _w - _r, _y + _h )
DrawTexturedRectUV( x + w - right, y + h - bottom, right, bottom, _x + _w - _r, _y + _h - _b, _x + _w, _y + _h )


GWEN.CreateTextureNormal = ( _xo, _yo, _wo, _ho, material_override ) ->
material = SKIN and SKIN.GwenTexture or material_override
if material_override and not material_override\IsError!
material = material_override

texture = material\GetTexture( "$basetexture" )
width, height = texture\Width!, texture\Height!
_x, _y, _w, _h = _xo / width, _yo / height, _wo / width, _ho / height

return ( x, y, w, h, color ) ->
if color ~= nil
SetDrawColor( color )
else
SetDrawColor( 255, 255, 255, 255 )

SetMaterial( material )
DrawTexturedRectUV( x, y, w, h, _x, _y, _x + _w, _y + _h )

GWEN.CreateTextureCentered = ( _xo, _yo, _wo, _ho, material_override ) ->
material = SKIN and SKIN.GwenTexture or material_override
if material_override and not material_override\IsError!
material = material_override

texture = material\GetTexture( "$basetexture" )
width, height = texture\Width!, texture\Height!
_x, _y, _w, _h = _xo / width, _yo / height, _wo / width, _ho / height

return ( x, y, w, h, color ) ->
if color ~= nil
SetDrawColor( color )
else
SetDrawColor( 255, 255, 255, 255 )

SetMaterial( material )

x += ( w - _wo ) * 0.5
y += ( h - _ho ) * 0.5

DrawTexturedRectUV( x, y, _wo, _ho, _x, _y, _x + _w, _y + _h )

do

:GetColor = FindMetaTable( "IMaterial" )

GWEN.TextureColor = ( x, y, material_override ) ->
material = SKIN and SKIN.GwenTexture or material_override
if material_override and not material_override\IsError!
material = material_override

return GetColor( material, x, y )

do

types = {
"Base": "Panel"
"Button": "DButton"
"Label": "DLabel"
"TextBox": "DTextEntry"
"TextBoxMultiline": "DTextEntry"
"ComboBox": "DComboBox"
"HorizontalSlider": "Slider"
"ImagePanel": "DImage"
"CheckBoxWithLabel": "DCheckBoxLabel"
}

:SetMultiline, :Add = PANEL
pairs = pairs

applyGWEN = ( tbl ) =>
if tbl.Type == "TextBoxMultiline"
SetMultiline( @, true )

for key, value in pairs( tbl.Properties )
if @[ "GWEN_Set" .. key ] ~= nil
@[ "GWEN_Set" .. key ]( @, value )

unless tbl.Children
return

for _, value in pairs( tbl.Children )
if types[ value.Type ] ~= nil
applyGWEN( Add( @, types[ value.Type ] ), value )
else
MsgN( "Warning: No GWEN Panel Type ", value.Type )

PANEL.ApplyGWEN = applyGWEN

loadGWENString = ( json ) =>
tbl = util.JSONToTable( json )
if tbl ~= nil and tbl.Controls ~= nil
applyGWEN( @, tbl.Controls )

PANEL.LoadGWENString = loadGWENString

PANEL.LoadGWENFile = ( filePath, gamePath ) =>
json = file.Read( filePath, gamePath or "GAME" )
if json ~= nil
loadGWENString( @, json )

do

:SetPos = PANEL

PANEL.GWEN_SetPosition = ( tbl ) =>
SetPos( @, tbl.x, tbl.y )

do

:SetSize = PANEL

PANEL.GWEN_SetSize = ( tbl ) =>
SetSize( @, tbl.w, tbl.h )

do

:SetText = PANEL

PANEL.GWEN_SetText = ( text ) =>
SetText( @, text )

do

:SetName = PANEL

PANEL.GWEN_SetControlName = ( name ) =>
SetName( @, name )

do

:DockMargin = PANEL

PANEL.GWEN_SetMargin = ( tbl ) =>
DockMargin( @, tbl.left, tbl.top, tbl.right, tbl.bottom )

do

tonumber = tonumber

do

:SetMin = PANEL

PANEL.GWEN_SetMin = ( min ) =>
SetMin( @, tonumber( min ) )

do

:SetMax = PANEL

PANEL.GWEN_SetMax = ( max ) =>
SetMax( @, tonumber( max ) )

do

align = {
"Top-Right": 9
"Top": 8
"Top-Left": 7
"Right": 6
"Center": 5
"Left": 4
"Bottom-Right": 3
"Bottom": 2
"Bottom-Left": 1
"None": 0
}

:SetContentAlignment = PANEL

PANEL.GWEN_SetHorizontalAlign = ( key ) =>
if align[ key ]
SetContentAlignment( @, align[ key ] )

do

dock = {
"Right": RIGHT
"Left": LEFT
"Bottom": BOTTOM
"Top": TOP
"Fill": FILL
}

:Dock = PANEL

PANEL.GWEN_SetDock = ( key ) =>
if dock[ key ]
Dock( @, dock[ key ] )

do

:SetText = PANEL

PANEL.GWEN_SetCheckboxText = ( tbl ) =>
SetText( @, tbl )

0 comments on commit 4c198b4

Please sign in to comment.