Jump to content

dxGridList - Cómo crearlo


aka Blue

Recommended Posts

Buenas. Desde hace bastante tiempo me quería ya profundizar en el tema del dxDraw. Me gustaría ya empezar por el dxGridList, crear mis propias listas con mis propias funciones, etc. El tema está en que no sé ni por donde empezar. ¿Alguien que me pueda ayudar?

Gracias!

Link to comment

Creo que este script te puede ayudar, mira a ver: 

--[[

	Author: danibayez
	MTA Forum: https://goo.gl/QX0mcT

]]

local width, height, h_height, r_height, s_width = 500, 520, 70, 40, 15
local renderTarget = dxCreateRenderTarget( width, height, true )
local font = dxCreateFont( "files/font.ttf", 18 )
local posX = ( screenW - width ) / 2
local isScrollActive, scrollCache, scrollColor = _, 0, 0
local players = { }

addEventHandler( "onClientRender", root,
	function( )
		if ( getKeyState( "TAB" ) ) then
		
			local c_height = #players * r_height
			local posY = ( screenH - ( math.min( c_height, height ) + h_height ) ) / 2
			dxDrawRectangle( posX, posY, width, h_height, tocolor( 42, 93, 132, 255 ), true )
			dxDrawImage( posX + 10, posY + ( h_height - 64 ), 64, 64, "files/skins/" .. getElementModel( localPlayer ) .. ".png", 0, 0, 0, tocolor( 255, 255, 255, 255 ), true )
			dxDrawText( #players .. "/100", posX, posY, posX + width - 10, posY + h_height, tocolor( 255, 255, 255, 255 ), 1, font, "right", "center", false, false, true )
			local headerX, headerY = posX + 85, posY + 7
			dxDrawImageSection( headerX, headerY, 16, 16, 16, 0, 16, 16, "files/icons.png", 0, 0, 0, tocolor( 255, 255, 255, 255 ), true )
			dxDrawText( getPlayerName( localPlayer ):gsub( "_", " " ), headerX + 20, headerY, headerX + 20, headerY + 16, tocolor( 255, 255, 255, 255 ), 0.55, font, "left", "center", false, false, true )
			dxDrawImageSection( headerX, headerY + 20, 16, 16, 32, 0, 16, 16, "files/icons.png", 0, 0, 0, tocolor( 255, 255, 255, 255 ), true )
			dxDrawText( convertNumber( getPlayerMoney( ) ) .. "$", headerX + 20, headerY + 20, headerX + 20, headerY + 36, tocolor( 255, 255, 255, 255 ), 0.55, font, "left", "center", false, false, true )
			dxDrawImageSection( headerX, headerY + 40, 16, 16, 0, 0, 16, 16, "files/icons.png", 0, 0, 0, tocolor( 255, 255, 255, 255 ), true )
			dxDrawText( _getZoneName( getElementPosition( localPlayer ) ), headerX + 20, headerY + 40, headerX + 20, headerY + 56, tocolor( 255, 255, 255, 255 ), 0.55, font, "left", "center", false, false, true )
			
			local offsetY = 0
			local _width = c_height > height and width - s_width - 5 or width
			
			dxSetRenderTarget( renderTarget, true )
			
				for i = 1, #players do
				
					local r, g, b = getPlayerNametagColor( players[ i ] )
					local posY = offsetY - scrollCache
					dxDrawRectangle( 0, posY, width, r_height, tocolor( 0, 0, 0, 200 ) )
					dxDrawText( ( getElementData( players[ i ], "playerid" ) or 0 ), 0, posY, 50, posY + r_height, tocolor( r, g, b, 255 ), 0.6, font, "center", "center" )
					dxDrawText( getPlayerName( players[ i ] ):gsub( "_", " " ), 60, posY, 160, posY + r_height, tocolor( r, g, b, 255 ), 0.6, font, "left", "center" )
					dxDrawText( getPlayerPing( players[ i ] ), _width - 70, posY, _width, posY + r_height, tocolor( r, g, b, 255 ), 0.6, font, "center", "center" )
					offsetY = offsetY + r_height
					
				end
				
				if ( width ~= _width ) then
				
					local vRatio = height / c_height
					local s_height = height * vRatio
					local scrollY = ( vRatio * scrollCache ) + 5
					local isHover = isCursorOnElement( posX + _width, posY + scrollY + h_height, s_width, s_height - 10 )
					local r, g, b = interpolateBetween( 42, 93, 132, 22, 73, 112, scrollColor, "Linear" )
					scrollColor = math.min( math.max( isScrollActive and scrollColor + 0.1 or scrollColor - 0.1, 0 ), 1 )
					_dxDrawRectangle( _width, 5, s_width, height - 10, 10, tocolor( 0, 0, 0, 200 ) )
					_dxDrawRectangle( _width, scrollY, s_width, s_height - 10, 10, tocolor( r, g, b, 255 ) )
					
					if ( isHover and getKeyState( "mouse1" ) ) then isScrollActive = not isScrollActive and cursorY( ) - scrollY + 5 or isScrollActive elseif ( not getKeyState( "mouse1" ) ) then isScrollActive = nil end
					
					if ( isScrollActive ) then
						
						scrollCache = math.min( math.max( ( cursorY( ) - isScrollActive ) / vRatio, 0 ), c_height - height )
						
					end
					
				end
				
			dxSetRenderTarget( )
			dxDrawImage( posX, posY + h_height, width, height, renderTarget, 0, 0, 0, tocolor( 255, 255, 255, 255 ), true )
			
		end
		showCursor( getKeyState( "mouse2" ) )
	end
)

addEventHandler( "onClientPlayerJoin", root, function( ) players = getElementsByType( "player" ) end )
addEventHandler( "onClientResourceStart", resourceRoot, function( ) players = getElementsByType( "player" ) end )
addEventHandler( "onClientPlayerQuit", root, function( ) players = getElementsByType( "player" ) scrollCache = math.min( scrollCache, #players * r_height ) end )

addEventHandler( "onClientKey", root,
	function( key )
		local c_height = #players * r_height
		if ( getKeyState( "TAB" ) and ( c_height > height ) ) then
			if ( key == "mouse_wheel_up" ) then
				scrollCache = math.max( scrollCache - r_height, 0 )
			elseif ( key == "mouse_wheel_down" ) then
				scrollCache = math.min( scrollCache + r_height, c_height - height )
			end
		end
	end
)

 

  • Like 1
Link to comment

mm te dejo un ejemplo trate de hacerlo lo mas facil posible para que puedas entenderlo

 

 local scroll = 0
editbox = {
  {"prueba 1"}
  {"prueba 2"}
  {"prueba 3"}
  {"prueba 4"}
  {"prueba 5"}
  {"prueba 6"}
  {"prueba 7"}
  {"prueba 8"}
  {"prueba 9"}
  {"prueba 10"}
   }
   
   
   function dx_editbox()
     ------ scrollbar
	  if #editbox > 5 then
	   local rec = (scroll * 240) / (#editbox - 5)
	   dxDrawRectangle(610, 300, 20, 300, tocolor(0, 0, 0))
	   dxDrawRectangle(610, 300 + rec, 20, 60, tocolor(255, 255, 255))
	  end
	 ------ editbox 
	 local cache = 0
     for i = 1 + scroll, 5 + scroll do
	    if editbox[i] then
		  if isMouseInPosition(400, 300 + cache, 200, 60) or currentedit == i then
		     dxDrawRectangle(400, 300 + cache, 200, 60, tocolor(255, 255, 255))
		     dxDrawText(editbox[i], 400, 300 + cache, 600, 360 + cache, tocolor(0, 0, 0))
		  else
		     dxDrawRectangle(400, 300 + cache, 200, 60, tocolor(0, 0, 0))
		     dxDrawText(editbox[i], 400, 300 + cache, 600, 360 + cache)
		  end
		    cache = cache + 60 
		end
	 end
   end
   addEventHandler("onClientRender", root, dx_editbox)
   
   function on_mouse_scroll()
	 if isMouseInPosition(400, 300, 200, 300)  then
	   if bind == "mouse_wheel_down"  or  bind == "arrow_d" then
         if scroll < #editbox - 5 then
		    scroll + 1
			return
		 end
	   elseif bind == "mouse_wheel_up" or  bind == "arrow_u" then  
		 if scroll > 0 then
		    scroll - 1
			return
		 end
       end
     end
   end
   bindkey("mouse_wheel_down", "down", on_mouse_scroll)
   bindkey("mouse_wheel_up", "down", on_mouse_scroll)
   
   function on_player_click(_, state)
     if state = "down" then
	   for i = 1, 5 do
	     if isMouseInPosition(400, 300 + ((i-1) * 60), 200, 60)  then
		   if editbox[i + scroll] then
		      currentedit = i
			  return
		   end
		 end
	   end
	 end
   end
   addEventHandler("onPlayerClick", root, on_player_click)



 function isMouseInPosition ( x, y, width, height )
   if ( not isCursorShowing( ) ) then
      return false
   end
   local sx, sy = guiGetScreenSize ( )
   local cx, cy = getCursorPosition ( )
   local cx, cy = ( cx * sx ), ( cy * sy )
   if ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) then
     return true
   else
     return false
   end
 end

 

Edited by alex17"
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...