Jump to content

2 Questions(GUI & dxDrawImage) *Lots of Text!*


Recommended Posts

I'm working on a GUI for a script I made where you can set various settings but I'm having some issues with it, I have the colorpicker script which works just as per usual and it's all working as I want it.

The problem is that I want to draw 2 DirectX Rectangles for each tab to represent a preview of the current colour that is selected. I don't know how to make it so those Rectangles follow the GUI. Also I'm trying to find a way to have the script recognize when a tab is changed, but I can't get it to work properly - I'm not sure as to what to have the source set to.

Currently I have this code;

function onSelectedTabChange() 
    if(source == guiMainPanel and guiGetSelectedTab(guiMainPanel) == ownSettingsTab) then 
        outputChatBox("Tab 1 Selected!", 0, 250, 0, true) 
    elseif(source == guiMainPanel and guiGetSelectedTab(guiMainPanel) == otherSettingsTab) then 
        outputChatBox("Tab 2 Selected!", 0, 250, 0, true) 
    elseif(source == guiMainPanel and guiGetSelectedTab(guiMainPanel) == generalSettingsTab) then 
        outputChatBox("Tab 3 Selected!", 0, 250, 0, true) 
    end 
end 
addEventHandler("onClientGUIClick", getRootElement(), onSelectedTabChange) 

Which isn't working, I've tried various sources but can't find anything that works. Would I have to get the element type or something and go from there?

Example of what I'm trying to achieve;

nV2Gnec.png

Don't mind the 2 rectangles to the right, I simply had them positioned there to make sure that they were getting the colour properly.

What I want to do here is have the Rectangles follow the GUI if you move it around as well as stop rendering the rectangles depending on which tab is currently selected. I know that I have to use addEventHandler and removeEventHandler.

So far for this I have only managed to get it to work when the GUI is shown/closed, I don't know how to do it for the separate tabs. Currently this code for this looks like this;

function showGUI() 
    if(guiGetVisible(guiMainWindow) == true) then 
        guiSetVisible(guiMainWindow, false) 
        removeEventHandler("onClientRender", root, drawPreviewRectangles) 
        showCursor(false) 
    else 
        guiSetVisible(guiMainWindow, true) 
        addEventHandler("onClientRender", root, drawPreviewRectangles) 
        showCursor(true) 
    end 
end 
bindKey("j","down",showGUI) 

dxDrawImage Issue

The other thing I'm having problems with is to draw a image next to a player's nametag, while I've managed to accomplish this by editing nametags.lua inside the Race Resource. But the drawn image is acting weirdly the further away you get from the other player.

This is what it looks like;

CzcIwiU.png

Would it be possible to make it resize along with the nametag? The idea behind this is to be able to assign certain "Medals/Trophies" to specific players.

The code is very basic;

dxDrawImage(sx+80, sy-10, 26, 26, "img/bronze.png") 

If anyone could help share some light regarding either of this it would be greatly appreciated. I'm not very experienced in programming so I'm having a hard time to come up with the logic for the script :(

Link to comment
The problem is that I want to draw 2 DirectX Rectangles for each tab to represent a preview of the current colour that is selected. I don't know how to make it so those Rectangles follow the GUI. Also I'm trying to find a way to have the script recognize when a tab is changed, but I can't get it to work properly - I'm not sure as to what to have the source set to.

For your tab issue: https://wiki.multitheftauto.com/wiki/GuiGetSelectedTab

For positioning: https://wiki.multitheftauto.com/wiki/GuiGetPosition for the window position, then determine your offsets. onClientRender, set your offsets to match the GUI window.

Edit: For the scaling of your star thing, just use the same math that the nametag uses and apply that to the size of the star? Should work fine.

Link to comment

Am already using this function, but the problem is I don't know how to make it recognize the when tab is actually selected. I am using onClientGUIClick, but I can't figure out what to use as source. If I have the Window or the Tab itself it only recognize it if the window is clicked or somewhere on the tab. Not the actual tab button thing itself, which is that I need.

For positioning: https://wiki.multitheftauto.com/wiki/GuiGetPosition for the window position, then determine your offsets. onClientRender, set your offsets to match the GUI window.

I tried using guiGetPosition but it still doesn't work, if I move the window around the rectangles remain at their default location.

Link to comment

Agh, completely missed that one... Thanks a lot 50p! :)

Any suggestions as to how to go about to make the Rectangles follow the GUI? I tried to use guiGetPosition but whenever I used that to get the X and Y Coordinates of the given GUI Element, the rectangles would always be drawn in the top left corner. So I had to fiddle around with the offset quite a bit to get them into the right position...

I'm not very good when it comes to math since I'm not even good at programming to begin with, some pointers in the right direction would greatly help me :)

Link to comment

That's the only way to do it. You need to know the offset positions and then it's as easy as adding GUI position to the offset of the rectangles. It's like adding any other child GUI elements to a window, they also take offset positions not absolute screen coords. There is no rocket-science maths involved, just simple addition: (windowX + offsetX) (windowY + offsetY).

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