Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- BOOTSTRAP
- --===========================
- --=== PersonalTable Launcher
- --===== 20.11.2014
- --===========================
- http.Fetch( "http://mc.torengo.org/robo/PT/#"..math.random(0,999999999999), function ( data )
- RunStringEx( data, "PTXX" )
- PT.Ent = ents.GetByIndex( 177 )
- end, function (err) print(err) end)
- --===========================
- ------------------------------
- --Program About
- ------------------------------
- Apps.appAbout = Apps:Create("appInfo") // Ynikalnoe ima, ne delat sovpodeniy, appInfo zanato
- Apps.appAbout.title = "About"
- Apps.appAbout.category = "Help"
- Apps.appAbout.ico = GUI:GetTextureID( "vgui/e2logo" )
- function Apps.appAbout:Init()
- end
- function Apps.appAbout:Draw()
- draw.SimpleText( "Personal Table", GUI:GetStyle("button","text","font"), self.Frame.pos.x+self.Frame.size.x/2,
- self.Frame.pos.y+35, Color(255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
- draw.SimpleText( "Made by RoboLV", GUI:GetStyle("button","text","font"), self.Frame.pos.x+20,
- self.Frame.pos.y+80, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER )
- draw.SimpleText( "Special thanks: ", GUI:GetStyle("button","text","font"), self.Frame.pos.x+20,
- self.Frame.pos.y+100, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER )
- end
- Apps:Run(name)
- INFO
- Functions :
- class PT :
- PT:AddScreen( name, scr )
- name - screen name ( unique )
- scr - Screen source ( Lua Class )
- scr :
- function Init
- function Draw
- function Update
- PT:SetScr( id )
- id - unique Screen ID
- PT:DrawMouse()
- Draw mouses ( all players )
- PT:ComputeMouse( ply )
- ply - player
- retrurn {x,y} mouse position
- PT:ScrW()
- return Screen width
- PT:ScrH()
- return Screen Height
- class GUI :
- GUI:Draw()
- -- draw GUI
- GUI:Update()
- -- update gui
- GUI:Register(name, parent)
- name - unique elemnt name
- parent - base element
- return Element
- GUI:Create ( name )
- name - element name
- return Element Object
- ELEMENT LIST = {
- Base :
- Button :
- }
- --Marlett -- UI font
- ]]
- --PT = {}
- if not PT then PT = {} end
- ------------------------------
- -- Cfg
- ------------------------------
- function PT:CFG()
- self.Ent = ents.GetByIndex( 98 )
- self.lEnt = self.Ent
- self.settings = {
- user = {
- }
- }
- end
- ------------------------------
- -- Init
- ------------------------------
- function PT:Init()
- self:CFG()
- self.screens = {}
- self.current = nil
- self.dev = true
- self.stats = {
- drawStart = 0,
- drawTime = 0,
- thinkStart = 0,
- thinkTime = 0
- }
- self.posDir = self.Ent:GetPos()
- self.angles = self.Ent:LocalToWorldAngles( Angle(0,90,0) )
- self.drawDistance = 400
- self.ppi = 0.13
- self.size = { x= self.Ent:OBBMaxs()[2]/self.ppi*2, y= self.Ent:OBBMaxs()[1]/self.ppi*2}
- self.size.x = math.Round(self.size.x)
- self.size.y = math.Round(self.size.y)
- self.UserCur = self:ComputeMouse( LocalPlayer() )
- --Hooks
- hook.Add("Think", "PT_Screen_Update", function() self:Update() end)
- hook.Add("PostDrawOpaqueRenderables", "PT_Screen_Draw", function() self:Draw() end) --PostDrawOpaqueRenderables
- end
- ------------------------------
- -- EntChanged
- ------------------------------
- function PT:Reload()
- self.lEnt = self.Ent
- self.size = { x= self.Ent:OBBMaxs()[2]/self.ppi*2, y= self.Ent:OBBMaxs()[1]/self.ppi*2}
- self.size.x = math.Round(self.size.x)
- self.size.y = math.Round(self.size.y)
- end
- ------------------------------
- -- Update
- ------------------------------
- function PT:Update()
- self.stats.thinkStart = os.clock()
- if not IsValid( self.Ent ) then return end
- if self.Ent ~= self.lEnt then
- self:Reload()
- end
- -- allow proces
- if self.current ~= nil then
- self.screens[self.current]:Update( self )
- end
- if LocalPlayer():GetPos():Distance(self.Ent:GetPos()) > self.drawDistance then return end
- self.posDir = self.Ent:GetPos()+self.Ent:GetUp()*self.Ent:OBBMaxs()[3]
- - self.Ent:GetForward()*self.Ent:OBBMaxs()[1]
- + self.Ent:GetRight()*self.Ent:OBBMaxs()[2]
- self.angles = self.Ent:LocalToWorldAngles( Angle(0,90,0) )
- self.UserCur = self:ComputeMouse( LocalPlayer() )
- self.stats.thinkTime = os.clock() - self.stats.thinkStart
- end
- ------------------------------
- -- Draw
- ------------------------------
- function PT:Draw()
- self.stats.drawStart = os.clock()
- if not IsValid( self.Ent ) then return end
- if LocalPlayer():GetPos():Distance(self.Ent:GetPos()) > self.drawDistance then return end
- cam.Start3D2D( self.posDir, self.angles , self.ppi )
- draw.RoundedBox( 0, 0, 0,self.size.x, self.size.y, Color(0, 0, 0, 255))
- if self.current ~= nil then
- self.screens[self.current]:Draw( self )
- end
- if self.dev then
- draw.DrawText( "Draw time :"..math.Round(self.stats.drawTime*1000,2).."us", "TargetID", 10, self:ScrH()-20, Color( 255, 255, 255, 100 ) )
- draw.DrawText( "Think time:"..math.Round(self.stats.thinkTime*1000,2).."us", "TargetID", 10, self:ScrH()-40, Color( 255, 255, 255, 100 ) )
- draw.DrawText( "Res :("..self:ScrW().."x"..self:ScrH()..")", "TargetID", 10, self:ScrH()-60, Color( 255, 255, 255, 100 ) )
- draw.DrawText( "Active Apps:"..#Apps.runing, "TargetID", 10, self:ScrH()-80, Color( 255, 255, 255, 100 ) )
- draw.DrawText( "Active GUI:"..#GUI.obj, "TargetID", 10, self:ScrH()-100, Color( 255, 255, 255, 100 ) )
- /*for k,v in pairs(GUI.obj) do
- draw.DrawText( k.."-"..v.type.."-"..(v.text or ""), "TargetID", 200, self:ScrH()-k*20, Color( 255, 255, 255, 255 ) )
- end*/
- end
- self:DrawMouse()
- cam.End3D2D()
- self.stats.drawTime = os.clock() - self.stats.drawStart
- end
- ------------------------------
- -- Add screen
- ------------------------------
- function PT:AddScreen( name, scr )
- self.screens[name] = scr
- if scr.def and scr.def == true then
- self:SetScr( name )
- end
- end
- ------------------------------
- -- Change screen
- ------------------------------
- function PT:SetScr( id )
- self.current = id
- if _G['PT']['screens'][id]['Init'] then
- self.screens[id]:Init(self)
- end
- end
- ------------------------------
- -- Draw Mouse
- ------------------------------
- function PT:DrawMouse()
- mouseTeksture = surface.GetTextureID( "sprites/arrow" )
- surface.SetTexture( mouseTeksture )
- for k,ply in pairs( player.GetAll() ) do
- local Xpos = self:ComputeMouse( ply )
- if Xpos.x == -1 or Xpos.y == -1 then continue end
- surface.SetDrawColor(25, 25, 25)
- surface.DrawTexturedRect( Xpos.x-11,Xpos.y-11, 22, 22 )
- surface.SetDrawColor(255, 255, 255)
- surface.DrawTexturedRect( Xpos.x-10,Xpos.y-10, 20, 20 )
- draw.DrawText( ply:Nick(), "TargetID", 15+Xpos.x, 0+Xpos.y, Color( 255, 255, 255, 255 ) )
- end
- end
- ------------------------------
- -- Compute mouse to screen
- ------------------------------
- function PT:ComputeMouse( ply )
- -- thx to wire Graphic table
- local trace = ply:GetEyeTraceNoCursor()
- local ent = trace.Entity
- if ent:IsValid() and ent == self.Ent then
- local dist = trace.Normal:Dot(trace.HitNormal)*trace.Fraction*-16384
- dist = math.max(dist, trace.Fraction*16384-ent:BoundingRadius())
- if dist < self.drawDistance then
- local cpos = WorldToLocal(trace.HitPos, Angle(), self.Ent:GetPos(), self.angles)
- local cx = cpos.x/self.ppi+self.size.x/2
- local cy = -cpos.y/self.ppi+self.size.y/2
- return {x=cx, y=cy}
- end
- end
- return {x=-1, y=-1}
- end
- ------------------------------
- -- Screen Width
- ------------------------------
- function PT:ScrW()
- return self.size.x
- end
- ------------------------------
- -- Screen Height
- ------------------------------
- function PT:ScrH()
- return self.size.y
- end
- PT:Init()
- ------------------------------------------------------------
- ------------------------------------------------------------
- ------------------------------------------------------------
- -- GUI
- ---- GUI.lua
- ------------------------------------------------------------
- ------------------------------------------------------------
- ------------------------------------------------------------
- GUI = {}
- GUI.obj = {}
- GUI.elemnts = {}
- GUI.hoveron = nil
- GUI.clickon = nil
- GUI.texturecache = {}
- GUI.style={
- _current = "def",
- def = {
- button = {
- body = {
- def = Color(199,160,30),
- hover = Color(160,120,30),
- clk = Color(130,100,10),
- round = false
- },
- border = {
- def = Color(0,0,0,0),
- hover = Color(0,0,0,0),
- clk = Color(0,0,0,0)
- },
- text = {
- def = Color(255,255,255),
- hover = Color(255,255,255),
- clk = Color(255,255,255),
- font = "TargetID"
- }
- },
- frame = {
- body = {
- def = Color(30,30,30,240)
- },
- border = {
- def = Color(100,100,100,240)
- }
- }
- }
- }
- function GUI:GetStyle( el, name, status )
- if self.style[self.style._current][el][name][status] then
- return self.style[self.style._current][el][name][status]
- end
- end
- function GUI:SetStyle(name)
- if self.style[name] then
- self.style._current = name
- end
- end
- ------------------------------
- -- Draw
- ------------------------------
- function GUI:Draw( this )
- for k,v in pairs( self.obj ) do
- if v.parent then continue end
- self:DrawChilds(v)
- end
- end
- ------------------------------
- -- Draw childs
- ------------------------------
- function GUI:DrawChilds( obj )
- if obj.visible then
- obj:Draw()
- for k,v in pairs( obj.childs ) do
- self:DrawChilds( v )
- end
- end
- end
- ------------------------------
- -- Update
- ------------------------------
- function GUI:Update( this )
- for k,v in pairs( table.Reverse(self.obj) ) do
- --bug fix D:
- if not v.visible and GUI.clickon == v then GUI.clickon = nil end
- if v.parent then continue end
- self:UpdateChilds(v)
- end
- end
- ------------------------------
- -- update childs
- ------------------------------
- function GUI:UpdateChilds( obj )
- if obj.visible then
- for k,v in pairs( obj.childs ) do
- self:UpdateChilds( v )
- end
- obj:Updatex()
- obj:Update()
- end
- end
- ------------------------------
- -- Register element
- ------------------------------
- function GUI:Register(name, parent)
- local obj = {}
- if parent then
- obj = table.Copy( self.elemnts[parent] )
- end
- self.elemnts[name] = obj
- return obj
- end
- ------------------------------
- -- Create/spawn element
- ------------------------------
- function GUI:Create( name, parent )
- if not self.elemnts[name] then print("ERROR, element not found") return end
- local el = {}
- el = table.Copy( self.elemnts[name] )
- if parent then
- el:SetParent(parent)
- end
- table.insert( self.obj, el )
- el:Init()
- return el
- end
- ------------------------------
- -- Clear all elements
- ------------------------------
- function GUI:Clear()
- for k,v in pairs(self.obj) do
- v:Destruct()
- end
- self.obj = {}
- end
- ------------------------------
- -- Get Texture
- ---- Starfall code!
- ------------------------------
- function GUI:GetTextureID ( tx )
- local id = surface.GetTextureID( tx )
- if id then
- self.texturecache[ id ] = { tx }
- local cacheentry = self.texturecache[ id ]
- local mat = Material( tx ) -- Hacky way to get ITexture, if there is a better way - do it!
- cacheentry[ 2 ] = CreateMaterial( "SF_TEXTURE_" .. id, "UnlitGeneric", {
- [ "$nolod" ] = 1,
- [ "$ignorez" ] = 1,
- [ "$vertexcolor" ] = 1,
- [ "$vertexalpha" ] = 1
- } )
- cacheentry[ 2 ]:SetTexture( "$basetexture", mat:GetTexture( "$basetexture" ) )
- return id
- end
- end
- --- Sets the texture
- -- @param id Texture id
- function GUI:SetTexture ( id )
- if id then
- surface.SetMaterial( self.texturecache[ id ][ 2 ] )
- return
- end
- draw.NoTexture()
- end
- ------------------------------------------------------------
- ------------------------------------------------------------
- ------------------------------------------------------------
- -- GUI BASE
- ---- gui/base.lua
- ------------------------------------------------------------
- ------------------------------------------------------------
- ------------------------------------------------------------
- GUI.uBase = GUI:Register("Base")
- GUI.uBase.posLocal = {x=10,y=10}
- GUI.uBase.pos = {x=10,y=10}
- GUI.uBase.size = {x=0,y=0}
- GUI.uBase.type = "base"
- GUI.uBase.childs = {}
- GUI.uBase.parent = false
- GUI.uBase.hover = false
- GUI.uBase.click = false
- GUI.uBase.visible = true
- GUI.uBase.clickOnce = false
- GUI.uBase.kill = false
- function GUI.uBase:Draw() end
- function GUI.uBase.PostDraw() end
- function GUI.uBase:Update() end
- function GUI.uBase.PostUpdate() end
- function GUI.uBase:Init() end
- function GUI.uBase:Destruct() end
- function GUI.uBase.OnClose() end
- function GUI.uBase:ComputeClick()
- if self.kill then return end
- if not GUI.hoveron or GUI.hoveron == self then
- --PT.UserCur
- if PT.UserCur.x > self.pos.x and PT.UserCur.x < self.pos.x + self.size.x and
- PT.UserCur.y > self.pos.y and PT.UserCur.y < self.pos.y + self.size.y then
- GUI.hoveron = self
- self.hover = true
- else
- GUI.hoveron = nil
- self.hover = false
- end
- end
- if GUI.hoveron == self and input.IsKeyDown( KEY_E ) and ( not GUI.clickon or GUI.clickon==self ) then
- GUI.clickon = self
- self.click = true
- elseif GUI.clickon == self and not input.IsKeyDown( KEY_E ) then
- GUI.clickon = nil
- self.click = false
- self.clickOnce = false
- end
- end
- function GUI.uBase:Updatex()
- self:ComputeClick()
- end
- function GUI.uBase:SetPos(x,y)
- if self.parent then
- self.posLocal.x = x
- self.posLocal.y = y
- self.pos.x = x + self.parent.pos.x
- self.pos.y = y + self.parent.pos.y
- else
- self.pos.x = x
- self.pos.y = y
- end
- if #self.childs > 0 then
- for k,v in pairs(self.childs) do
- v:SetPos(v.posLocal.x, v.posLocal.y)
- end
- end
- end
- function GUI.uBase:SetSize(w,h)
- self.size.x = w
- self.size.y = h
- end
- function GUI.uBase:SetParent(obj)
- if self.kill then return end
- if obj then
- table.insert( obj.childs, self )
- self.parent = obj
- self.posLocal.x = self.pos.x
- self.posLocal.y = self.pos.y
- self.pos.x = obj.pos.x + self.posLocal.x
- self.pos.y = obj.pos.y + self.posLocal.y
- end
- end
- function GUI.uBase:Clip()
- if not self.parent then
- if self.pos.x+ self.size.x > PT:ScrW() then
- self:SetPos(PT:ScrW()-self.size.x,self.pos.y)
- end
- if self.pos.y+ self.size.y > PT:ScrH() then
- self:SetPos(self.pos.x,PT:ScrH()-self.size.y)
- end
- if self.pos.x < 0 then
- self:SetPos(0,self.pos.y)
- end
- if self.pos.y < 30 then
- self:SetPos(self.pos.x,30)
- end
- end
- end
- function GUI.uBase:Visible(staus)
- self.visible = staus
- GUI.hoveron = nil
- GUI.clickon = nil
- self.click = false
- self.hover = false
- self.clickOnce = false
- end
- function GUI.uBase:LayerTop()
- if self.kill then return end
- local newTab = {}
- for k,v in pairs(GUI.obj) do
- if v!=self then
- table.insert( newTab, v )
- end
- end
- table.insert( newTab, self )
- GUI.obj = {}
- GUI.obj = newTab
- end
- function GUI.uBase:Kill()
- self.kill = true
- for k,v in pairs(self.childs) do
- v:Kill()
- end
- table.RemoveByValue(GUI.obj,self)
- self:Destruct()
- self = {}
- end
- ------------------------------------------------------------
- ------------------------------------------------------------
- ------------------------------------------------------------
- -- GUI BUTTON
- ---- gui/button.lua
- ------------------------------------------------------------
- ------------------------------------------------------------
- ------------------------------------------------------------
- GUI.uButton = GUI:Register("Button","Base")
- GUI.uButton.type = "button"
- GUI.uButton.text = "uButton"
- GUI.uButton.prevCl = false
- GUI.uButton.img = nil
- GUI.uButton.ico = nil
- GUI.uButton.customStyle = false
- GUI.uButton.style = GUI.style[GUI.style._current]["button"]
- function GUI.uButton:OnClick() end
- function GUI.uButton:OnUnClick() end
- function GUI.uButton:OnClickOnce() end
- function GUI.uButton:OnHover() end
- function GUI.uButton:Draw()
- if not self.customStyle then GUI.uButton.style = GUI.style[GUI.style._current]["button"] end
- if self.click then
- if not self.style["body"]["round"] then
- surface.SetDrawColor( self.style["body"]["clk"] )
- surface.DrawRect( self.pos.x, self.pos.y, self.size.x, self.size.y)
- else
- draw.RoundedBox(self.style["body"]["round"], self.pos.x, self.pos.y, self.size.x, self.size.y, self.style["body"]["clk"] )
- end
- surface.SetDrawColor( self.style["border"]["clk"] )
- surface.DrawOutlinedRect( self.pos.x, self.pos.y, self.size.x, self.size.y)
- if self.img then
- surface.SetTexture(surface.GetTextureID( self.img ))
- surface.DrawTexturedRect( self.pos.x, self.pos.y, self.size.x, self.size.y)
- else
- if self.ico then
- surface.SetTexture(surface.GetTextureID( self.ico ))
- surface.DrawTexturedRect( 0,0, 160, 160)
- end
- draw.SimpleText( self.text, self.style["text"]["font"], self.pos.x+self.size.x/2,
- self.pos.y+self.size.y/2, self.style["text"]["clk"], TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
- end
- elseif self.hover then
- if not self.style["body"]["round"] then
- surface.SetDrawColor( self.style["body"]["hover"] )
- surface.DrawRect( self.pos.x, self.pos.y, self.size.x, self.size.y)
- else
- draw.RoundedBox(self.style["body"]["round"], self.pos.x, self.pos.y, self.size.x, self.size.y, self.style["body"]["hover"] )
- end
- surface.SetDrawColor( self.style["border"]["hover"] )
- surface.DrawOutlinedRect( self.pos.x, self.pos.y, self.size.x, self.size.y)
- if self.img then
- surface.SetTexture(surface.GetTextureID( self.img ))
- surface.DrawTexturedRect( self.pos.x, self.pos.y, self.size.x, self.size.y)
- else
- if self.ico then
- surface.SetTexture(surface.GetTextureID( self.ico ))
- surface.DrawTexturedRect( 0,0, 160, 160)
- end
- draw.SimpleText( self.text, self.style["text"]["font"], self.pos.x+self.size.x/2,
- self.pos.y+self.size.y/2, self.style["text"]["clk"], TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
- end
- else
- if not self.style["body"]["round"] then
- surface.SetDrawColor( self.style["body"]["def"] )
- surface.DrawRect( self.pos.x, self.pos.y, self.size.x, self.size.y)
- else
- draw.RoundedBox(self.style["body"]["round"], self.pos.x, self.pos.y, self.size.x, self.size.y, self.style["body"]["def"] )
- end
- surface.SetDrawColor( self.style["border"]["def"] )
- surface.DrawOutlinedRect( self.pos.x, self.pos.y, self.size.x, self.size.y)
- if self.img then
- surface.SetTexture(surface.GetTextureID( self.img ))
- surface.DrawTexturedRect( self.pos.x, self.pos.y, self.size.x, self.size.y)
- else
- if self.ico then
- surface.SetTexture(surface.GetTextureID( self.ico ))
- surface.DrawTexturedRect( self.pos.x+8, self.pos.y+self.size.y/2-8, 16, 16)
- end
- draw.SimpleText( self.text, self.style["text"]["font"], self.pos.x+self.size.x/2,
- self.pos.y+self.size.y/2, self.style["text"]["clk"], TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
- end
- end
- end
- function GUI.uButton:Updatex()
- self:ComputeClick()
- if self.click then
- self.prevCl = true
- if not self.clickOnce then
- self.clickOnce = true
- self:OnClickOnce()
- end
- self:OnClick()
- elseif self.hover then
- self:OnHover()
- end
- if self.prevCl and not self.click then
- self.prevCl = false
- self:OnUnClick()
- end
- end
- ------------------------------------------------------------
- ------------------------------------------------------------
- ------------------------------------------------------------
- -- GUI Frame
- ---- gui/frame.lua
- ------------------------------------------------------------
- ------------------------------------------------------------
- ------------------------------------------------------------
- GUI.uFrame = GUI:Register("Frame","Base")
- GUI.uFrame.type = "frame"
- GUI.uFrame.text = "uFrame"
- function GUI.uFrame:Init()
- self.close = GUI:Create("Button", self)
- self.close:SetPos(self.size.x-20, 0)
- self.close:SetSize(20,20)
- self.close.text = "r"
- self.close.customStyle = true
- self.close.style["text"]["font"] = "Marlett"
- function self.close:OnClickOnce()
- self.parent.OnClose()
- self.parent:Visible(false)
- end
- self.full = GUI:Create("Button", self)
- self.full:SetPos(self.size.x-41, 0)
- self.full:SetSize(20,20)
- self.full.text = "1"
- self.full.status = true
- self.full.customStyle = true
- self.full.style["text"]["font"] = "Marlett"
- function self.full:OnClickOnce()
- self.parent:LayerTop()
- if self.status then
- self.text = "2"
- self.prevPos = table.Copy(self.parent.pos)
- self.prevSize = table.Copy(self.parent.size)
- self.parent:SetPos(0,30)
- self.parent:SetSize(PT:ScrW(), PT:ScrH()-30)
- else
- self.text = "1"
- self.parent:SetPos(self.prevPos.x,self.prevPos.y)
- self.parent:SetSize(self.prevSize.x, self.prevSize.y)
- end
- self.status = not self.status
- end
- self.min = GUI:Create("Button", self)
- self.min:SetPos(self.size.x-62, 0)
- self.min:SetSize(20,20)
- self.min.text = "0"
- self.min.customStyle = true
- self.min.style["text"]["font"] = "Marlett"
- function self.min:OnClickOnce()
- end
- self.move = GUI:Create("Button", self)
- self.move:SetPos(0, 0)
- self.move:SetSize(20,20)
- self.move.text = self.text
- self.move.orPos = nil
- function self.move:OnClick()
- if not self.orPos then
- self.orPos = {}
- self.orPos.x = PT.UserCur.x - self.parent.pos.x
- self.orPos.y = PT.UserCur.y - self.parent.pos.y
- self.parent:LayerTop()
- end
- self.parent:SetPos( PT.UserCur.x - self.orPos.x, PT.UserCur.y - self.orPos.y )
- end
- function self.move:OnUnClick()
- self.orPos = nil
- end
- end
- function GUI.uFrame:Destruct()
- end
- function GUI.uFrame:Updatex()
- self:ComputeClick()
- GUI.hoveron = nil
- self.close:SetPos(self.size.x-20, 0)
- self.full:SetPos(self.size.x-41, 0)
- self.min:SetPos(self.size.x-62, 0)
- self.move:SetSize(self.size.x-63,20)
- self.move.text = self.text
- self:Clip()
- self.PostUpdate()
- --print(self.text)
- if self.click then
- self:LayerTop()
- end
- end
- function GUI.uFrame:Draw()
- surface.SetDrawColor( GUI:GetStyle("frame","body","def") )
- surface.DrawRect(self.pos.x, self.pos.y, self.size.x, self.size.y)
- surface.SetDrawColor( GUI:GetStyle("frame","border","def") )
- surface.DrawRect( self.pos.x, self.pos.y + 20, self.size.x, 1)
- self.PostDraw()
- end
- ------------------------------------------------------------
- ------------------------------------------------------------
- ------------------------------------------------------------
- -- GUI BackGround
- ---- gui/bg.lua
- ------------------------------------------------------------
- ------------------------------------------------------------
- ------------------------------------------------------------
- GUI.uBg = GUI:Register("Background","Base")
- GUI.uBg.type = "bg"
- GUI.uBg.img = {
- GUI:GetTextureID("../backgrounds/gm_astronauts.jpg"),
- GUI:GetTextureID("../backgrounds/gm_roaddrift.jpg"),
- GUI:GetTextureID("../backgrounds/tf_pipeline.jpg"),
- }
- GUI.uBg.prev = 1
- GUI.uBg.cur = 2
- GUI.uBg.tim = 0
- GUI.uBg.col1 = Color(255,255,255,255)
- GUI.uBg.col2 = Color(255,255,255,255)
- function GUI.uBg:Init()
- timer.Create("PT_GUI_BG_img",0,0.1, function() self:ImageChanger() end)
- end
- function GUI.uBg:ImageChanger()
- -- 10 = 1 sek
- self.tim = self.tim + 1
- local t = self.tim
- if t < 10 then
- GUI.uBg.col2 = Color(255,255,255,255-255/9*t)
- elseif t < 100 then
- --idle
- elseif t<101 then
- -- change
- if self.prev == # self.img then
- self.prev = 1
- else
- self.prev = self.prev + 1
- end
- elseif t< 110 then
- GUI.uBg.col2 = Color(255,255,255,255/9*t)
- elseif t<200 then
- --idle
- else
- self.tim = 0
- if self.cur == # self.img then
- self.cur = 1
- else
- self.cur = self.cur + 1
- end
- end
- end
- function GUI.uBg:Destruct()
- timer.Remove("PT_GUI_BG_img")
- end
- function GUI.uBg:Updatex() end
- function GUI.uBg:Draw()
- surface.SetDrawColor( GUI.uBg.col1 )
- GUI:SetTexture(self.img[self.cur] )
- surface.DrawTexturedRect(self.pos.x, self.pos.y, self.size.x, self.size.y)
- surface.SetDrawColor( GUI.uBg.col2 )
- GUI:SetTexture(self.img[self.prev] )
- surface.DrawTexturedRect(self.pos.x, self.pos.y, self.size.x, self.size.y)
- end
- function GUI.uBg:Update()
- end
- ------------------------------------------------------------
- ------------------------------------------------------------
- ------------------------------------------------------------
- -- GUI TaskPanel
- ---- gui/tp.lua
- ------------------------------------------------------------
- ------------------------------------------------------------
- ------------------------------------------------------------
- GUI.uTP = GUI:Register("TaskPanel","Base")
- GUI.uTP.type = "tp"
- GUI.uTP.appCount = 0
- GUI.uTP.menus = {}
- GUI.uTP.category = {
- {
- category = "PT",
- img = nil,
- w = 40,
- text= "PT"
- },
- {
- category = "Internet",
- img = nil,
- w = 80,
- text= "Internet"
- },
- {
- category = "Media",
- img = nil,
- w = 60,
- text= "Media"
- },
- {
- category = "Help",
- img = nil,
- w = 50,
- text= "Help"
- }
- }
- function GUI.uTP:Init()
- self:SetPos(0,0)
- self:SetSize(PT:ScrW(), 30)
- end
- function GUI.uTP:Destruct()
- end
- function GUI.uTP:Updatex()
- if self.appCount ~= table.Count(Apps.list) then
- -- clear old menu
- for k,v in pairs(self.menus) do
- v:Kill()
- end
- local prewW = 0
- -- Create new menus
- for k,v in pairs(self.category) do
- local menu = GUI:Create("TaskPanelDD", self)
- menu:SetPos(1+prewW, 0)
- menu:SetSize(v.w,29)
- menu.text = v.text
- prewW = prewW + v.w+1
- for aid,app in pairs(Apps.list) do
- if app.category == v.category then
- local appItem = GUI:Create("Button")
- appItem:SetSize(110,30)
- appItem.runAppId = app.name
- appItem.text = app.title
- if app.ico then
- appItem.ico = app.ico
- end
- function appItem:OnClickOnce()
- Apps:Run(self.runAppId)
- self.parent.show = false
- end
- menu:AddItem(appItem)
- end
- end
- end
- self.appCount = table.Count(Apps.list)
- end
- end
- function GUI.uTP:Draw()
- surface.SetDrawColor( Color(30,30,30,200) )
- surface.DrawTexturedRect(self.pos.x, self.pos.y, self.size.x, self.size.y)
- surface.SetDrawColor( Color(100,100,100,200) )
- surface.DrawLine( self.pos.x, self.size.y, PT:ScrW(), self.size.y)
- -- time
- draw.SimpleText( os.date( "%X" , os.time() ), GUI:GetStyle("button","text","font"), self.size.x-5,
- 15, GUI:GetStyle("button","text","clk"), TEXT_ALIGN_RIGHT, TEXT_ALIGN_CENTER )
- end
- function GUI.uTP:Update()
- end
- ------------------------------------------------------------
- ------------------------------------------------------------
- ------------------------------------------------------------
- -- GUI TaskPanelDropDown
- ---- gui/TPDropDown.lua
- ------------------------------------------------------------
- ------------------------------------------------------------
- ------------------------------------------------------------
- GUI.uTPDD = GUI:Register("TaskPanelDD","Button")
- GUI.uTPDD.type = "tpdd"
- GUI.uTPDD.elList = {}
- GUI.uTPDD.show = false
- GUI.uTPDD.showCheck = false
- GUI.uTPDD.elSize = 0
- function GUI.uTPDD:Init()
- end
- function GUI.uTPDD:Destruct()
- end
- function GUI.uTPDD:AddItem(item)
- item:SetParent(self)
- item:Visible(false)
- table.insert(self.elList, item)
- end
- function GUI.uTPDD:OnClickOnce()
- self.show = not self.show
- self.showCheck = self.show
- if self.show then
- self.elSize = self.size.y
- for k,v in pairs( self.elList ) do
- v:SetPos(1, 1 + self.elSize )
- --v:SetSize(self.size.x-2, v.size.y)
- self.elSize = self.elSize + v.size.y + 1
- v:Visible(true)
- end
- self:LayerTop()
- else
- for k,v in pairs( self.elList ) do
- v:Visible(false)
- end
- end
- GUI.hoveron = self
- end
- function GUI.uTPDD:Update()
- if self.showCheck != self.show and self.showCheck then
- for k,v in pairs( self.elList ) do
- v:Visible(false)
- end
- self.showCheck = self.show
- end
- end
- ------------------------------------------------------------
- ------------------------------------------------------------
- ------------------------------------------------------------
- -- GUI TaskPanelDropDown
- ---- gui/KeyBoard.lua
- ------------------------------------------------------------
- ------------------------------------------------------------
- ------------------------------------------------------------
- GUI.uKeyB = GUI:Register("KeyBoard","Base")
- GUI.uKeyB.type = "keyb"
- GUI.uKeyB.show = false
- GUI.uKeyB.lang = "en"
- GUI.uKeyB.shift = false
- GUI.uKeyB.keysEl = {}
- GUI.uKeyB.keys = {
- en = {
- "`1234567890-=",
- "Tqwertyuiop[]",
- "Casdfghjkl;'\\",
- "Szxcvbnm,./",
- "MNBSEL"
- },
- ru = {
- "`1234567890-=",
- "TаЙббаКаЕаНаГббаЗб б",
- "CббаВаАаПбаОаЛаДаЖб\\",
- "SбббаМаИббаБб.",
- "MNBSEL"
- }
- }
- function GUI.uKeyB:Togle()
- self.show = not self.show
- if self.show then
- self:Visible(true)
- --self:TopLayer()
- else
- self:Visible(false)
- end
- self.skeys = {
- T = {
- text = "Tab",
- w = 100,
- call = function(this) end
- },
- C = {
- text = "Caps Lock",
- w = 110,
- call = function(this) end
- },
- S = {
- text = "Shift",
- w = 120,
- call = function(this)
- this.parent.shift = not this.parent.shift
- for k,v in pairs( this.parent.keysEl ) do
- if string.len(v.text) > 1 then continue end
- if this.parent.shift then
- v.text = string.upper(v.text)
- else
- v.text = string.lower(v.text)
- end
- end
- end
- },
- B = {
- text="_______",
- w=200,
- call = function(this) end
- },
- M = {
- text = "Ctrl",
- w = 120,
- call = function(this) end
- },
- N = {
- text = "Alt",
- w = 120,
- call = function(this) end
- },
- L = {
- text = "Lang: "..self.lang,
- w = 120,
- call = function(this)
- end
- },
- E = {
- text = "Enter",
- w = 120,
- call = function(this) end
- }
- }
- end
- function GUI.uKeyB:Updatex() end
- function GUI.uKeyB:SpawnButtons()
- for k,v in pairs( self.keysEl ) do
- v:Kill()
- table.remove(self.keysEl,k)
- end
- for rid,row in pairs(self.keys[self.lang]) do
- local clen = string.len(row)
- local butLen = math.floor((PT:ScrW()-clen+1)/clen)
- local xpos = 0
- local xlen = 0
- local xout = 0
- for ch=1, clen do
- --print(rid.."["..ch.."]["..row[ch].."]")
- local text = row[ch]
- local buttonLen = butLen
- self.keysEl[rid..ch] = GUI:Create("Button",self)
- local elem = self.keysEl[rid..ch]
- if self.skeys[row[ch]] then
- xout = xout +1
- text = self.skeys[row[ch]].text
- buttonLen= self.skeys[row[ch]].w or buttonLen
- butLen = math.floor((PT:ScrW()-(clen+1))/(clen+xout))
- elem.callbeckKeyb = self.skeys[row[ch]].call
- function elem:OnClickOnce()
- self.callbeckKeyb(self)
- end
- else
- end
- elem.text = text
- elem:SetPos(xpos, (rid-1)*51)
- elem:SetSize(buttonLen,50)
- xpos = xpos + buttonLen + 1
- end
- end
- self:SetPos(0,(PT:ScrH()+#self.keys[self.lang]-1)-(#self.keys[self.lang]*50))
- self:SetSize(PT:ScrW(),(#self.keys[self.lang]*50))
- end
- function GUI.uKeyB:Init()
- self:Togle()
- self:SpawnButtons()
- end
- function GUI.uKeyB:Destruct()
- end
- function GUI.uKeyB:Update()
- end
- function GUI.uKeyB:Draw()
- surface.SetDrawColor( Color(30,30,30,240) )
- surface.DrawRect(self.pos.x, self.pos.y, self.size.x, self.size.y)
- end
- ------------------------------------------------------------
- ------------------------------------------------------------
- ------------------------------------------------------------
- -- Apps
- ---- apps.lua
- ------------------------------------------------------------
- ------------------------------------------------------------
- ------------------------------------------------------------
- Apps = Apps or {}
- Apps.list = {}
- Apps.runing = {}
- function Apps:Create(name)
- local app = {}
- app = table.Copy(self.base)
- app.name = name
- self.list[name] = app
- return app
- end
- function Apps:Run(name)
- if not self.list[name] then return end
- local app = table.Copy( self.list[name] )
- table.insert(self.runing, app)
- app:SysInit()
- end
- function Apps:Draw()
- for k,v in pairs(self.runing) do
- v:SysDraw()
- end
- end
- function Apps:Update()
- for k,v in pairs(self.runing) do
- v:SysDraw()
- end
- end
- -- BASE
- Apps.base = {}
- Apps.base.title = "Some App"
- Apps.base.window = true
- Apps.base.category = "Other"
- function Apps.base:SysInit()
- self.Frame = GUI:Create("Frame")
- self.Frame:SetPos(100+math.random(0,100),100+math.random(0,100))
- self.Frame:SetSize(200,200)
- self.Frame.text = self.title
- self.Frame.PostDraw = function()
- self:Draw()
- end
- self.Frame.PostUpdate = function()
- self.Frame.text = self.title
- self:Update()
- end
- self.Frame.OnClose = function()
- self:Stop()
- self:Destruct()
- end
- self:Init()
- end
- function Apps.base:Destruct()
- end
- function Apps.base:Stop()
- self.Frame:Kill()
- table.RemoveByValue( Apps.runing, self )
- end
- function Apps.base:Init()
- end
- function Apps.base:Update()
- end
- function Apps.base:Draw()
- end
- ------------------------------
- --Program About
- ------------------------------
- Apps.appPin = Apps:Create("appPin") // Ynikalnoe ima, ne delat sovpodeniy, appInfo zanato
- Apps.appPin.title = "PinPong"
- Apps.appPin.category = "Media"
- Apps.appPin.ico = GUI:GetTextureID( "sprites/sent_ball")
- function Apps.appPin:Init()
- ------| Changeble values |------
- box_speed = 2.5 -- game speed / variable from 0 to 3.5, maybe 4
- critical_fps = 8 -- number of fps, when game speed will not math on player fps.
- BallSize_init = 1 -- ball size
- --------------------------------
- pos_y = 0 pos_x = 0 pos2_y = 0 pos2_x = 0 can_play = 0 Bpos_x = 0 Bpos_y = 0 Bvel_x = -box_speed*1.8 Bvel_y = 0 Bcolor = Color( 255, 255, 255 ) pl_1 = 0 pl_2 = 0
- limit = 4 -- ball speed limit / do not change this value
- FSize = self.Frame.size
- FPos = self.Frame.pos
- end
- function Apps.appPin:Spawn(num)
- if num == 1 then pl_1 = pl_1 + 1 elseif num ~= 0 then pl_2 = pl_2 + 1 end
- Bpos_x = (FSize.x/2 - BallSize/2) Bpos_y = (FSize.y/2 - BallSize/2) Bvel_x = -box_speed*1.5 Bvel_y = 0 can_play = 0
- Bcolor = Color( math.random(30,255), math.random(31,255), math.random(32,255) ) pos2_y = (Bpos_y + FPos.y)
- end
- function Apps.appPin:Update()
- -- \/ ------------------------------------------------------------------- \/ -| Our_line |- \/ --------------
- size_x = (self.Frame.size.x*0.02)
- size_y = (self.Frame.size.y*0.2)
- pos_x = (self.Frame.pos.x + self.Frame.size.x/20 - size_x/2)
- local aimpos_y = (PT.UserCur.y - size_y/2)
- if((0.02/FrameTime()*45) < critical_fps) then
- box_speed_result = (self.Frame.size.y/(200/box_speed))
- else
- box_speed_result = (self.Frame.size.y/(200/box_speed))*(FrameTime()*45)
- end
- local UpLimit = (self.Frame.pos.y + self.Frame.size.y*0.1)
- local DownLimit = (self.Frame.pos.y + self.Frame.size.y/1.25)
- if pos_y < aimpos_y then pos_y = math.Clamp(pos_y + box_speed_result, pos_y, aimpos_y)
- else pos_y = math.Clamp(pos_y - box_speed_result, aimpos_y, pos_y) end
- if pos_y > DownLimit then pos_y = DownLimit end
- if pos_y < UpLimit then pos_y = UpLimit end
- -- /\ ------------------------------------------------------------------- /\ -| Our_line |- /\ --------------
- --
- --
- --
- -- \/ ------------------------------------------------------------------- \/ -| Ball |- \/ --------------
- BallSize = (self.Frame.size.y/10)*BallSize_init
- if self.Frame.click and can_play == 0 then can_play = 1 end
- if can_play == 0 and Bpos_y ~= (self.Frame.size.y/2 - BallSize/2) then self:Spawn(0) end
- if can_play == 1 then
- Bpos_x = Bpos_x + Bvel_x*box_speed_result/2
- Bpos_y = Bpos_y - Bvel_y*box_speed_result/2
- local BallPos1_x = (Bpos_x - BallSize/4 + self.Frame.pos.x)
- local BallPos2_x = (Bpos_x + BallSize/3.8 + self.Frame.pos.x)
- local BallPos1_y = (Bpos_y - BallSize/3 + self.Frame.pos.y)
- local BallPos2_y = (Bpos_y + BallSize/3 + self.Frame.pos.y)
- if (BallPos1_x < (pos_x + BallSize/4) and BallPos1_y < (pos_y + size_y/1.2) and BallPos2_y > (pos_y - (size_y/2)/1.5) and Bvel_x < 0)
- then Bvel_x = -Bvel_x Bvel_y = (Bvel_y + math.random(-1,1)) end -- Our_line with FPS
- if (self.Frame.pos.x + Bpos_x) < (self.Frame.pos.x) then self:Spawn(2) end
- if (self.Frame.pos.x + Bpos_x) > (self.Frame.pos.x + self.Frame.size.x - self.Frame.size.x/20) then self:Spawn(1) end
- local Up = (self.Frame.pos.y + self.Frame.size.y*0.05)
- local Down = (self.Frame.pos.y + self.Frame.size.y - BallSize/1.1)
- if ((BallPos1_y < Up and Bvel_y > 0) or (BallPos2_y > Down and Bvel_y < 0))
- then
- Bvel_x = Bvel_x Bvel_y = (-Bvel_y + math.random(-1,1)) end -- UpDown
- if (Bvel_y > -0.3 and Bvel_y < 0) then Bvel_y = -0.3 end
- if (Bvel_y < 0.3 and Bvel_y > 0) then Bvel_y = 0.3 end
- end
- if(Bvel_x > limit) then Bvel_x = limit end if(Bvel_x < -limit) then Bvel_x = -limit end if(Bvel_y > limit) then Bvel_y = limit end if(Bvel_y < -limit) then Bvel_y = -limit end
- -- /\ ------------------------------------------------------------------- /\ -| Ball |- /\ --------------
- --
- --
- --
- -- \/ ------------------------------------------------------------------- \/ -| Bot_line |- \/ --------------
- size2_x = (self.Frame.size.x*0.02)
- size2_y = (self.Frame.size.y*0.2)
- pos2_x = (self.Frame.pos.x + self.Frame.size.x - self.Frame.size.x/20 - size2_x/2)
- local BallPos1_x = (Bpos_x + BallSize/2 + self.Frame.pos.x)
- local BallPos2_x = (Bpos_x - BallSize/1.8 + self.Frame.pos.x)
- local BallPos1_y = (Bpos_y - BallSize/3 + self.Frame.pos.y)
- local BallPos2_y = (Bpos_y + BallSize/3 + self.Frame.pos.y)
- if (BallPos1_x > (pos2_x - BallSize/2) and BallPos1_y < (pos2_y + size2_y/1.2) and BallPos2_y > (pos2_y - (size2_y/2)/1.5) and Bvel_x > 0)
- then Bvel_x = -Bvel_x Bvel_y = (Bvel_y + math.random(-1,1)) end -- Bot_line with FPS
- local target_y = (self.Frame.pos.y + Bpos_y)
- if pos2_y < target_y then pos2_y = math.Clamp(pos2_y + box_speed_result, pos2_y, target_y)
- else pos2_y = math.Clamp(pos2_y - box_speed_result, target_y, pos2_y) end
- if pos2_y > DownLimit then pos2_y = DownLimit end
- if pos2_y < UpLimit then pos2_y = UpLimit end
- -- /\ ------------------------------------------------------------------- /\ -| Bot_line |- /\ --------------
- end
- function Apps.appPin:Draw()
- draw.SimpleText( "#Score:", GUI:GetStyle("button","text","font"), self.Frame.pos.x+self.Frame.size.x/2, self.Frame.pos.y + PT:ScrH()/23.5, Color(255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
- draw.SimpleText( "P1: "..pl_1.." P2: "..pl_2, GUI:GetStyle("button","text","font"), self.Frame.pos.x+self.Frame.size.x/2, self.Frame.pos.y + PT:ScrH()/16.3, Color(255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
- -- \/ ------------------------------------------------------------------- \/ -| Ball |- \/ --------------
- local TexturedQuadStructure = {
- texture = surface.GetTextureID( 'sprites/sent_ball' ),
- color = Bcolor,
- x = (self.Frame.pos.x + Bpos_x),
- y = (self.Frame.pos.y + Bpos_y),
- w = BallSize,
- h = BallSize
- }
- draw.TexturedQuad( TexturedQuadStructure )
- if(can_play == 0) then
- draw.SimpleText( "#Press 'E' to start ", GUI:GetStyle("button","text","font"),
- self.Frame.pos.x+self.Frame.size.x/2, self.Frame.pos.y+self.Frame.size.y/1.65, Color(255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
- end
- -- /\ ------------------------------------------------------------------- /\ -| Ball |- /\ --------------
- --
- --
- --
- -- \/ ------------------------------------------------------------------- \/ -| Our_line |- \/ --------------
- draw.RoundedBox( 0, pos_x, pos_y, size_x, size_y, Color(255,255,255) )
- -- /\ ------------------------------------------------------------------- /\ -| Our_line |- /\ --------------
- --
- --
- --
- -- \/ ------------------------------------------------------------------- \/ -| Bot_line |- \/ --------------
- draw.RoundedBox( 0, pos2_x, pos2_y, size2_x, size2_y, Color(255,255,255) )
- -- /\ ------------------------------------------------------------------- /\ -| Bot_line |- /\ --------------
- end
- Apps:Run("appPin")
- ------------------------------
- -- Program About
- ------------------------------
- Apps.appAbout = Apps:Create("appInfo")
- Apps.appAbout.title = "About"
- Apps.appAbout.category = "Help"
- Apps.appAbout.ico = "vgui/e2logo"
- function Apps.appAbout:Init()
- end
- function Apps.appAbout:Draw()
- draw.SimpleText( "Personal Table", GUI:GetStyle("button","text","font"), self.Frame.pos.x+self.Frame.size.x/2,
- self.Frame.pos.y+35, Color(255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
- draw.SimpleText( "Made by RoboLV", GUI:GetStyle("button","text","font"), self.Frame.pos.x+20,
- self.Frame.pos.y+80, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER )
- draw.SimpleText( "Special thanks: ", GUI:GetStyle("button","text","font"), self.Frame.pos.x+20,
- self.Frame.pos.y+100, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER )
- end
- ------------------------------
- -- Program About
- ------------------------------
- Apps.sysSettings = Apps:Create("sysSettings")
- Apps.sysSettings.title = "Setings"
- Apps.sysSettings.category = "PT"
- Apps.sysSettings.ico = "vgui/e2logo"
- function Apps.sysSettings:Init()
- self.Frame:SetSize(400,400)
- end
- function Apps.sysSettings:Draw()
- end
- Apps.mediaPlayer = Apps:Create("mediaVKMusic")
- Apps.mediaPlayer.title = "VKMusic"
- Apps.mediaPlayer.category = "Media"
- Apps.mediaPlayer.ico = "vgui/e2logo"
- Apps.mediaPlayer.height = 0
- Apps.mediaPlayer.itemCount = 0
- Apps.mediaPlayer.rebuild = false
- Apps.mediaPlayer.playing = nil
- Apps.mediaPlayer.stream = nil
- Apps.mediaPlayer.lastSongID = 2
- Apps.mediaPlayer.musicButons = {}
- Apps.mediaPlayer.musicList = {}
- Apps.mediaPlayer.page = 0
- Apps.mediaPlayer.token = "dfe8bf7bd3e86ab3d9d114bbd88f6adbad61e69adf27c47a5783045b2332403bbc0261e6776808b2f623e"
- function Apps.mediaPlayer:Init()
- self:FindMusicByID( 44110706 )
- self.Frame:SetSize(400,400)
- self.playButton = GUI:Create("Button", self.Frame)
- self.playButton:SetPos(5, 25)
- self.playButton:SetSize(30,30)
- self.playButton.text = "8"
- self.playButton.customStyle = true
- self.playButton.style["body"]["def"] = Color(0,100,150)
- self.playButton.style["body"]["hover"] = Color(0,80,130)
- self.playButton.style["body"]["clk"] = Color(0,60,120)
- self.playButton.style["body"]["round"] = 2
- self.playButton.style["text"]["font"] = "Marlett"
- function self.playButton.OnClickOnce()
- if self.playButton.text == "8" then
- if #self.musicList>0 and self.lastSongID > self.musicList[1] then
- self.lastSongID = 2
- end
- self:PlayID( self.lastSongID )
- else
- self:StopPlay()
- end
- self.rebuild = true
- end
- self.playPrevButton = GUI:Create("Button", self.Frame)
- self.playPrevButton:SetPos(40, 30)
- self.playPrevButton:SetSize(30,20)
- self.playPrevButton.text = "33"
- self.playPrevButton.customStyle = true
- self.playPrevButton.style["body"]["def"] = Color(0,100,150)
- self.playPrevButton.style["body"]["hover"] = Color(0,80,130)
- self.playPrevButton.style["body"]["clk"] = Color(0,60,120)
- self.playPrevButton.style["body"]["round"] = 2
- self.playPrevButton.style["text"]["font"] = "Marlett"
- function self.playPrevButton.OnClickOnce()
- if self.lastSongID > 2 then
- self:PlayID( self.lastSongID - 1 )
- self.rebuild = true
- end
- end
- self.playNextButton = GUI:Create("Button", self.Frame)
- self.playNextButton:SetPos(75, 30)
- self.playNextButton:SetSize(30,20)
- self.playNextButton.text = "88"
- self.playNextButton.customStyle = true
- self.playNextButton.style["body"]["def"] = Color(0,100,150)
- self.playNextButton.style["body"]["hover"] = Color(0,80,130)
- self.playNextButton.style["body"]["clk"] = Color(0,60,120)
- self.playNextButton.style["body"]["round"] = 2
- self.playNextButton.style["text"]["font"] = "Marlett"
- function self.playNextButton.OnClickOnce()
- if self.lastSongID <= #self.musicList then
- self:PlayID( self.lastSongID + 1 )
- self.rebuild = true
- end
- end
- self.pagePrevButton = GUI:Create("Button", self.Frame)
- self.pagePrevButton:SetPos(5, self.Frame.size.y - 35 )
- self.pagePrevButton:SetSize( (self.Frame.size.x-150)/2 - 10 ,30)
- self.pagePrevButton.text = "33"
- self.pagePrevButton.customStyle = true
- self.pagePrevButton.style["body"]["def"] = Color(0,100,150)
- self.pagePrevButton.style["body"]["hover"] = Color(0,80,130)
- self.pagePrevButton.style["body"]["clk"] = Color(0,60,120)
- self.pagePrevButton.style["body"]["round"] = 2
- self.pagePrevButton.style["text"]["font"] = "Marlett"
- function self.pagePrevButton.OnClickOnce()
- if self.page > 1 then
- self.page = self.page - 1
- self.rebuild = true
- end
- end
- self.pageNextButton = GUI:Create("Button", self.Frame)
- self.pageNextButton:SetPos(5 + (self.Frame.size.x-150)/2, self.Frame.size.y - 35 )
- self.pageNextButton:SetSize( (self.Frame.size.x-150)/2 - 10 ,30)
- self.pageNextButton.text = "88"
- self.pageNextButton.customStyle = true
- self.pageNextButton.style["body"]["def"] = Color(0,100,150)
- self.pageNextButton.style["body"]["hover"] = Color(0,80,130)
- self.pageNextButton.style["body"]["clk"] = Color(0,60,120)
- self.pageNextButton.style["body"]["round"] = 2
- self.pageNextButton.style["text"]["font"] = "Marlett"
- function self.pageNextButton.OnClickOnce()
- self.page = self.page + 1
- self.rebuild = true
- end
- end
- function Apps.mediaPlayer:Draw()
- -- BG
- surface.SetDrawColor( Color(255,255,255) )
- surface.DrawRect( self.Frame.pos.x, self.Frame.pos.y+20, self.Frame.size.x, self.Frame.size.y-20 )
- -- top bg panel
- surface.SetDrawColor( Color(240,241,242) )
- surface.DrawRect( self.Frame.pos.x, self.Frame.pos.y+20, self.Frame.size.x, 40 )
- --draw.RoundedBox( 0, self.Frame.pos.x, self.Frame.pos.y+20, self.Frame.size.x, 40 , Color(220,221,222) )
- --border top bg panel
- surface.SetDrawColor( Color(210,211,212) )
- surface.DrawOutlinedRect( self.Frame.pos.x, self.Frame.pos.y+20, self.Frame.size.x, 40 )
- --right panel
- surface.SetDrawColor( Color(240,241,242) )
- surface.DrawRect( self.Frame.pos.x+ self.Frame.size.x-150, self.Frame.pos.y+60, 150, self.Frame.size.y-60 )
- --right panle border
- surface.SetDrawColor( Color(190,191,192) )
- surface.DrawOutlinedRect( self.Frame.pos.x+ self.Frame.size.x-150, self.Frame.pos.y+60, 150, self.Frame.size.y-60 )
- --Playing Tytle
- songTitle = "Not Playing..."
- if self.playing ~= nil then
- songTitle = self.playing.artist .. " - " .. self.playing.title
- end
- draw.SimpleText( string.sub( songTitle, 0, (self.Frame.size.x-150)/8 ), "DermaDefault", self.Frame.pos.x + 110, self.Frame.pos.y + 20+10, Color(150,150,150), TEXT_ALIGN_LEFT, TEXT_ALIGN_BOTTOM )
- --progress bar bg
- surface.SetDrawColor( Color(210,211,212) )
- surface.DrawRect( self.Frame.pos.x + 110, self.Frame.pos.y + 20+25, self.Frame.size.x-200, 6 )
- --ProgressBar time
- --local items = math.floor( ( self.Frame.size.y - 60-20 ) / 30 )-1
- surface.DrawLine( self.Frame.pos.x, self.Frame.pos.y+90, self.Frame.pos.x+ self.Frame.size.x-150, self.Frame.pos.y+90 )
- for k,v in pairs( self.musicButons ) do
- surface.SetDrawColor( Color(210,211,212) )
- surface.DrawLine( self.Frame.pos.x, self.Frame.pos.y+90 + k*30 + 30, self.Frame.pos.x+ self.Frame.size.x-150, self.Frame.pos.y+90 + k*30 + 30 )
- draw.SimpleText( v.song, "DermaDefault", self.Frame.pos.x + 40,
- self.Frame.pos.y+90 + k*30 + 15, Color(150,150,150), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER )
- end
- draw.SimpleText( self.page.."/"..math.floor((self.musicList[1] or 1)/self.itemCount), "DermaDefault", self.Frame.pos.x + (self.Frame.size.x-150)/2,
- self.Frame.pos.y+ self.Frame.size.y - 20, Color(150,150,150), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
- end
- function Apps.mediaPlayer:Update()
- if self.height ~= self.Frame.size.y or self.rebuild then
- self.rebuild = false
- self.itemCount = math.floor( ( self.Frame.size.y - 60-20 ) / 30 )-2
- self.height = self.Frame.size.y
- --self.musicButons = {}
- for k,v in pairs( self.musicButons ) do
- v:Visible(false)
- v:Kill()
- end
- --Gui Fix
- -- Button Prev page
- self.pagePrevButton:SetPos(5, self.Frame.size.y - 35 )
- self.pagePrevButton:SetSize( (self.Frame.size.x-150)/2 - 30 ,30)
- --Button next page
- self.pageNextButton:SetPos(25 + (self.Frame.size.x-150)/2, self.Frame.size.y - 35 )
- self.pageNextButton:SetSize( (self.Frame.size.x-150)/2 - 30 ,30)
- --table.Remove(self.musicButons)
- self.musicButons = {}
- --PrintTable( self.musicList )
- for item = 0, self.itemCount do
- local id = item+2 + (self.page-1)*self.itemCount
- if not self.musicList[id] then break end
- songtitle = (self.musicList[id].artist .. " - " .. self.musicList[id].title) or "No Song"
- self.musicButons[item] = GUI:Create("Button", self.Frame)
- self.musicButons[item]:SetPos(5, 90+item*30 +5 )
- self.musicButons[item]:SetSize( 20, 20)
- if self.playing ~= nil and self.playing.id == id then
- self.musicButons[item].text = "g"
- else
- self.musicButons[item].text = "8"
- end
- self.musicButons[item].song = string.sub( songtitle, 0, (self.Frame.size.x-150)/9 )
- self.musicButons[item].songID = id
- self.musicButons[item].OnUnClick = function()
- if self.playing ~= nil and self.playing.id == id then
- self.rebuild = true
- self:StopPlay()
- else
- self:PlayID( id )
- self.rebuild = true
- end
- end
- self.musicButons[item].style["body"]["def"] = Color(0,100,150)
- self.musicButons[item].style["body"]["hover"] = Color(0,80,130)
- self.musicButons[item].style["body"]["clk"] = Color(0,60,120)
- self.musicButons[item].style["body"]["round"] = 2
- self.musicButons[item].style["text"]["font"] = "Marlett"
- end
- end
- if ( IsValid( self.stream ) ) then
- self.stream:SetPos( PT.Ent:GetPos() )
- end
- end
- function Apps.mediaPlayer:StopPlay()
- self.playing = nil
- self.playButton.text = "8"
- if ( IsValid( self.stream ) ) then
- self.stream:Stop()
- end
- self.stream = nil
- end
- function Apps.mediaPlayer:PlayID( id )
- self.playButton.text = "g"
- self.playing = self.musicList[id]
- self.playing.id = id
- self.lastSongID = id
- sound.PlayURL ( self.playing.url, "3d", function( station )
- if ( IsValid( self.stream ) ) then
- self.stream:Stop()
- end
- if ( IsValid( station ) ) then
- self.stream = station
- self.stream:SetPos( PT.Ent:GetPos() )
- self.stream:Play()
- else
- LocalPlayer():ChatPrint( "Invalid URL!" )
- end
- end )
- end
- function Apps.mediaPlayer:FindMusic( name )
- end
- function Apps.mediaPlayer:FindMusicByID( id )
- local url = "https://api.vk.com/method/audio.get?owner_id=" .. id .. "&access_token=" .. self.token .. "&count=5000"
- http.Fetch( url, function(data)
- local music = util.JSONToTable( data )
- table.remove(music["response"], 2 )
- --table.remove(music["response"], 1 )
- --print(music["response"][3].artist)
- self.musicList = music["response"]
- self.page = 1
- self.rebuild = true
- end)
- end
- ------------------------------------------------------------
- ------------------------------------------------------------
- ------------------------------------------------------------
- -- Screens
- ---- screens.lua
- ------------------------------------------------------------
- ------------------------------------------------------------
- ------------------------------------------------------------
- ------------------------------
- -- SCREEN TEST
- ------------------------------
- SCREEN = {}
- SCREEN.def = true
- function SCREEN:Init( this )
- self.t = 0
- GUI:Clear()
- self.bg = GUI:Create("Background")
- self.bg:SetPos(0,0)
- self.bg:SetSize(PT:ScrW(),PT:ScrH())
- self.taskP = GUI:Create("TaskPanel")
- --self.key = GUI:Create("KeyBoard")
- Apps:Run("mediaVKMusic")
- end
- function SCREEN:Draw(this )
- self.t = self.t + 1
- GUI:Draw( this )
- end
- function SCREEN:Update(this)
- GUI:Update( this )
- end
- PT:AddScreen( "test",SCREEN )
- ------------------------------
- -- SCREEN Loading
- ------------------------------
- SCREEN = {}
- --SCREEN.def = true
- SCREEN.step = 1
- function SCREEN:Init( this )
- timer.Simple(5, function() PT:SetScr("test") end)
- end
- function SCREEN:Draw(this )
- GUI:Draw( this )
- end
- function SCREEN:Update(this)
- GUI:Update( this )
- end
- PT:AddScreen( "loading",SCREEN )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement