Last active
August 29, 2015 14:20
-
-
Save Starfox64/cfb4ffd77ccb6df52633 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hook.Add("PostDrawOpaqueRenderables", "CAH_PostDrawOpaqueRenderables", function() | |
for k, cahGame in pairs(CAH:GetGames()) do | |
local cahTable = cahGame:GetTable() | |
if (IsValid(cahTable) and cahTable:GetPos():DistToSqr(LocalPlayer():GetPos()) < 62500) then | |
local angles = cahTable:GetAngles() | |
angles:RotateAroundAxis(angles:Up(), 90) | |
cam.Start3D2D(cahTable:LocalToWorld(cahTable.origin), angles, SCALE) | |
local cursor = CAH:GetCursor(cahTable, angles) | |
--draw.RoundedBox(0, 0, 0, TABLE_WIDTH, TABLE_HEIGHT, Color(255, 255, 255, 50)) | |
for seatID, client in pairs(cahGame:GetPlayers()) do | |
for cardKey, cardID in pairs(client:GetCards()) do | |
local x, y = CARDS_ORIGIN[seatID].x + cardKey * 200, CARDS_ORIGIN[seatID].y | |
local flipped = false | |
if (client != LocalPlayer()) then | |
flipped = true | |
end | |
CAH:DrawCard(cardID, x, y, flipped) | |
end | |
end | |
CAH:DrawCard(471, 1600, 670, false, 0) | |
CAH:DrawCard(186, 1800, 670, false, 180) | |
if (cursor) then | |
surface.SetMaterial(Material("cah/hand64.png")) | |
surface.SetDrawColor(Color(220, 220, 220, 255)) | |
surface.DrawTexturedRectRotated(cursor.x, cursor.y, 64, 64, cursor.r) | |
end | |
--LocalPlayer():ChatPrint("X = "..cursor.x..", Y = "..cursor.y) | |
cam.End3D2D() | |
end | |
end | |
end) | |
-- CAH Cursor Position Generator -- | |
function CAH:GetCursor( cahTable, angles ) | |
if (LocalPlayer():InVehicle() and LocalPlayer():GetVehicle():GetNWInt("CAH_ChairID")) then | |
local hitPos = util.IntersectRayWithPlane(LocalPlayer():EyePos(), gui.ScreenToVector(ScrW()/2, ScrH()/2), cahTable:LocalToWorld(cahTable.origin), angles:Up()) | |
if (hitPos) then | |
local offset = hitPos - cahTable:LocalToWorld(cahTable.origin) | |
offset:Rotate(Angle(0, -angles.y, 0)) | |
offset:Rotate(Angle(-angles.p, 0, 0)) | |
offset:Rotate(Angle(0, 0, -angles.r)) | |
local x, y = offset.x * (1 / SCALE), -(offset.y * (1 / SCALE)) | |
local rotate = 0 | |
local chairID = LocalPlayer():GetVehicle():GetNWInt("CAH_ChairID") | |
if (chairID == 2 or chairID == 4) then | |
rotate = 180 | |
end | |
if (x <= TABLE_WIDTH and x >= 0 and y <= TABLE_HEIGHT and y >= 0) then | |
return {x = x, y = y, r = rotate} | |
end | |
end | |
end | |
end | |
-- CAH Cards Drawer -- | |
function CAH:DrawCard( cardID, x, y, flipped, ang ) | |
local textColor = "0,0,0" | |
local cardColor = Color(255, 255, 255) | |
if (CAH:GetCard(cardID):IsQuestion()) then | |
textColor = "255,255,255" | |
cardColor = Color(0, 0, 0) | |
end | |
local markupDraw = markup.Parse("<color="..textColor.."><font=CAH_CardFont>"..CAH:GetCard(cardID):GetText().."</font></color>", 180) | |
function markupDraw:Draw( xOffset, yOffset, halign, valign, alphaoverride, ang ) | |
for i,blk in pairs(self.blocks) do | |
local y = yOffset + (blk.height - blk.thisY) + blk.offset.y | |
local x = xOffset | |
if (halign == TEXT_ALIGN_CENTER) then x = x - (self.totalWidth / 2) | |
elseif (halign == TEXT_ALIGN_RIGHT) then x = x - (self.totalWidth) | |
end | |
x = x + blk.offset.x | |
if (valign == TEXT_ALIGN_CENTER) then y = y - (self.totalHeight / 2) | |
elseif (valign == TEXT_ALIGN_BOTTOM) then y = y - (self.totalHeight) | |
end | |
local alpha = blk.colour.a | |
if (alphaoverride) then alpha = alphaoverride end | |
CAH:DrawRotatedText(blk.text, x, y, Color(blk.colour.r, blk.colour.g, blk.colour.b, alpha), blk.font, ang) | |
end | |
end | |
draw.RoundedBox(8, x, y, 185, 256, cardColor) | |
markupDraw:Draw(x + 10, y + 10, TEXT_ALIGN_LEFT, TEXT_ALIGN_BOTTOM , 255, ang) | |
end | |
function CAH:DrawRotatedText( text, x, y, color, font, ang ) | |
local mat = Matrix() | |
local matAng = Angle(0, 0, 0) | |
local matTrans = Vector(0, 0, 0) | |
local matScale = Vector(0, 0, 0) | |
matAng.y = ang | |
mat:SetAngles(matAng) | |
matTrans.x = x | |
matTrans.y = y | |
mat:SetTranslation(matTrans) | |
matScale.x = 1 | |
matScale.y = 1 | |
mat:Scale(matScale) | |
surface.SetTextPos(0, 0) | |
cam.PushModelMatrix(mat) | |
surface.DrawText(text) | |
cam.PopModelMatrix() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment