Jump to content

how to make custom scrolling?


Derpy

Recommended Posts

Hi! I am interested in making my scoreboard, but there's a problem.

I am worried what to do when there would be too many players, they wouldn't all fit on scoreboard.

But there's scrolling, right?

But how do i make scrolling in dx?

If someone could provide me with an example, that would be great!

something like scrolling on this video:

Link to comment
  • MTA Team

Copied it from my resource. Sorry, but I am too lazy to explain it properly, but the code is already commented.

Source: https://github.com/Necktrox/debugconsole

  
-- Example values 
local index = 0           -- Currently selected line (-index)     
local linecount = 25      -- Number of visible lines 
local playercount = 75    -- Number of all lines (also not visible) 
local windowheight = 300  -- Height of the playerlist-window 
  
-- Calculate how much we show from the actual count 
local visiblefactor = math.min(linecount / playercount, 1.0) 
  
-- Make sure we have a minimum factor 
visiblefactor = math.max(visiblefactor, 0.05) 
  
-- Calculate the bar height 
local barheight = (windowheight - 20) * visiblefactor 
  
-- Calculate the position 
local position = math.min(index / playercount, 1.0 - visiblefactor) * (windowheight - 20) 
  
-- Draw the scrollbar background 
dxDrawRectangle(x, y, 10, windowheight - 20, tocolor(0, 0, 0), true) 
  
-- Draw the scrollbar 
dxDrawRectangle(x, y + position, 10, barheight, tocolor(255, 255, 255), true) 
  

Link to comment

erm i tried doing this thing multiple times, but i always came to an issue, and wasnt really able to make it work

local sw,sh = guiGetScreenSize() 
local width,height = 350/1920*sw,500/1080*sh 
local x,y = sw/2-width/2,sh/2-height/2 
local scaleX,scaleY = 1/1920*sw,1/1080*sh 
local font = "default-bold" 
local maxIndex = 24 
local currentIndex = 0 
  
local tab = { 
[1] = "Text", 
[2] = "Lmao", 
[3] = "Rambo", 
[4] = "Hello World", 
} 
  
function drawRectangle() 
   dxDrawRectangle(x,y,width,height,tocolor(0,0,0,180)) 
   for i = currentIndex,maxIndex+currentIndex do 
      if tab[i] then 
         if i >= currentIndex then 
            dxDrawText(tab[i],x,y+i*20,sw,sh,tocolor(255,255,255),scaleX,scaleY,font) 
         end 
      end 
   end 
end 
setTimer(function() addEventHandler("onClientRender",root,drawRectangle) end,50,1) 
  
function increaseIndex() 
currentIndex = currentIndex + 1 
outputChatBox("Wheel up: Current Index: "..currentIndex) 
end 
bindKey("mouse_wheel_up","down",increaseIndex) 
  
function decreseIndex() 
currentIndex = currentIndex - 1 
outputChatBox("Wheel down: Current Index: "..currentIndex) 
end 
bindKey("mouse_wheel_down","down",decreseIndex) 
  
function addIndex(cmd,tmessage) 
tab[#tab+1] = tmessage 
end 
addCommandHandler("message",addIndex) 
  
function addMultipleRows(cmd,times,text) 
   for i = 1,tonumber(times) do 
      tab[#tab+1] = text 
   end 
end 
addCommandHandler("loop",addMultipleRows) 

if you could help me, i would be really happy, and i checked your resource and at scrolling part it has math.min and math.max functions, but i don't really understand why do you need them

Link to comment
  • 3 weeks later...

What you do is create a render target, and then draw the text on this. That way, any text that goes outside of the render target will be cut off.

Thus, you can just edit the Y position of all the text and whatever you draw inside that target to make it look like you're scrolling.

I'll leave it to you to search the MTA Wiki for the functions you need, see what you can come up with on your own. Then come back here and I'll help further if needed. :D

Link to comment
Good idea Dealman. Taking your example to the extreme - render 200 lines to show show only 15 makes sense.

Why take it to the extreme? I merely suggested what I use for my own needs, there are obviously ways to optimize it. So it doesn't necessarily render what won't be shown on screen.

Did I claim it to be the best way to do it? No, there are many different ways to find a solution to this problem. All in all, it comes down to the way you prefer making things. It suits my needs perfectly, and it's easy to work with. I haven't had and I sincerely doubt I will encounter any performance issues.

How about actually contributing to my suggestion rather than to try to bash it with arrogance? :roll:

Link to comment
  • MTA Team
Good idea Dealman. Taking your example to the extreme - render 200 lines to show show only 15 makes sense.

Why take it to the extreme? I merely suggested what I use for my own needs, there are obviously ways to optimize it. So it doesn't necessarily render what won't be shown on screen.

Did I claim it to be the best way to do it? No, there are many different ways to find a solution to this problem. All in all, it comes down to the way you prefer making things. It suits my needs perfectly, and it's easy to work with. I haven't had and I sincerely doubt I will encounter any performance issues.

How about actually contributing to my suggestion rather than to try to bash it with arrogance? :roll:

Nice wall of text to bash me back. Anyway, you give him an example how to write bad code and it will decrease performance of the client (FPS drop) when the message count increases. You could have told him how to actually show only the neccessary lines, which will be seen on the screen instead of (again) leading him to bad coding (which you should have maybe learned to avoid from your experience).

Link to comment

Nice wall of text to bash me back. Anyway, you give him an example how to write bad code and it will decrease performance of the client (FPS drop) when the message count increases. You could have told him how to actually show only the neccessary lines, which will be seen on the screen instead of (again) leading him to bad coding (which you should have maybe learned to avoid from your experience).

...Excuse me? How is it bad code? I didn't provide him with any code, I merely suggested what functions he could use to achieve the scrolling effect.

And it doesn't affect the performance, at least not to my experience - I'm using this method both for my internet radio and scoreboard.

And if it does indeed start to lag, there are ways to optimize it. The point of the matter is that it does work, I never claimed it to be a better method than yours - I never claimed it to be a reply sent from heaven so back the fuck off dude. I'm trying to help as much as you, really can not be bothered with arrogant people such as yourself.

This is the very reason I took a break from MTA Forums to begin with, full with nothing but arrogant people who see themselves as gods and better than everyone else - or thieves. :roll:

Link to comment
  • MTA Team

You might have a powerful machine like I do, which might not show any huge performance impact when running some code in each render call, but there are other players, which will suffer from "bad code", because the scripter couldn't invest a little bit time to keep that code to a minimum (your code advise). Sorry if I sound arrogant in your eyes, but your care for performance optimization is low.

Link to comment
You might have a powerful machine like I do, which might not show any huge performance impact when running some code in each render call, but there are other players, which will suffer from "bad code", because the scripter couldn't invest a little bit time to keep that code to a minimum (your code advise). Sorry if I sound arrogant in your eyes, but your care for performance optimization is low.

How do you know that my care for performance optimization is low...? I didn't post any code, all I did was mention one way to approach the problem.

Dude, I'm not even gonna bother; I came here to help him, and all you're doing now is trying to act all high and mighty. Mine is just one way to do it out of many.

I never claimed it to be better than yours or anyone else's so stop acting like I did. Golly, you don't "sound" arrogant. You are.

Link to comment
  • Moderators

@Derpy why are you changing your tabs while scrolling? Afaik your scroll is vertical(for the items) and not horizontal(for the tabs).

  
local tabTextSize = 0 
for i=1,#tab do 
                local tabTitle = tab[i] 
                dxDrawText(tabTitle,x,y+tabTextSize-5,sw,sh,tocolor(255,255,255),scaleX,font) -- THERE IS NO ,scaleY !!!!!! 
                tabTextSize = tabTextSize+dxGetTextWidth(tabTitle,scaleX,font)+10 
--tab tab tab tab ... 

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...