Tails Posted October 12, 2014 Share Posted October 12, 2014 Hey it's me again Is there any way I could enable tooltips for my checkboxes or on any other part of my GUI? I tried: guiSetProperty(mycheckbox, "Tooltip", "test") but unfortunately that didn't work. Any ideas? Thanks in advance Link to comment
MTA Team botder Posted October 12, 2014 MTA Team Share Posted October 12, 2014 (edited) You have to make tooltips by yourself with DirectX functions (use the GUI events Focus and Blur to know which gui element is being hovered). Edited October 12, 2014 by Guest Link to comment
Tails Posted October 12, 2014 Author Share Posted October 12, 2014 Guess I'll have to do that then! Thanks! Link to comment
Tails Posted October 12, 2014 Author Share Posted October 12, 2014 I there any way I could use https://wiki.multitheftauto.com/wiki/OnClientMouseEnter instead? I need it to popup on mouse over not on input focus. Link to comment
MTA Team botder Posted October 12, 2014 MTA Team Share Posted October 12, 2014 My mistake. Use that Link to comment
Tails Posted October 12, 2014 Author Share Posted October 12, 2014 No worries. Could you give me an example? I mean how do I use for it only one specific GUI? Not all of them. Link to comment
MTA Team botder Posted October 12, 2014 MTA Team Share Posted October 12, 2014 I made a resource solution, that means a single resource handles the rendering for every gui element, which has a tooltip element data. Example: Result: Code: -- Settings local font_face = "arial" local font_widthscale = 1 local font_heightscale = 1 local font_color = tocolor(255, 255, 255) local background_color = tocolor(0, 0, 0, 200) local hovertime = 500 local cursor_offsetx = 15 local cursor_offsety = -10 local padding_top = 5 local padding_right = 5 local padding_bottom = 5 local padding_left = 5 -- Variables local screenWidth, screenHeight = guiGetScreenSize() local height = dxGetFontHeight(font_heightscale, font_face) local tooltip = false local width = 0 local hoverstart = 0 addEventHandler("onClientRender", root, function () if (tooltip and (isCursorShowing() or isConsoleActive() or isChatBoxInputActive())) then if (hoverstart + hovertime < getTickCount()) then local x, y = getCursorPosition() x, y = screenWidth * x, screenHeight * y x, y = x + cursor_offsetx, y + cursor_offsety dxDrawRectangle(x, y, width + padding_left + padding_right, height + padding_top + padding_bottom, background_color, true) dxDrawText(tooltip, x, y, x + width + padding_left + padding_right, y + height + padding_top + padding_bottom, font_color, font_widthscale, font_heightscale, font_face, "center", "center", false, false, true, true, true) end end end ) addEventHandler("onClientMouseEnter", root, function () local text = getElementData(source, "tooltip") if (type(text) == "string" and #text > 0) then tooltip = text local withoutcolor = text:gsub("#%x%x%x%x%x%x", "") width = dxGetTextWidth(withoutcolor, font_widthscale, font_face) if (#withoutcolor == 0) then tooltip = false return end hoverstart = getTickCount() end end ) addEventHandler("onClientMouseLeave", root, function () tooltip = false end ) Link to comment
DakiLLa Posted October 12, 2014 Share Posted October 12, 2014 You could also use 'tooltips' resource provided with the Map Editor, or this one from the community.multitheftauto.com. Link to comment
Saml1er Posted October 12, 2014 Share Posted October 12, 2014 I made a resource solution, that means a single resource handles the rendering for every gui element, which has a tooltip element data.Example: Result: Code: -- Settings local font_face = "arial" local font_widthscale = 1 local font_heightscale = 1 local font_color = tocolor(255, 255, 255) local background_color = tocolor(0, 0, 0, 200) local hovertime = 500 local cursor_offsetx = 15 local cursor_offsety = -10 local padding_top = 5 local padding_right = 5 local padding_bottom = 5 local padding_left = 5 -- Variables local screenWidth, screenHeight = guiGetScreenSize() local height = dxGetFontHeight(font_heightscale, font_face) local tooltip = false local width = 0 local hoverstart = 0 addEventHandler("onClientRender", root, function () if (tooltip and (isCursorShowing() or isConsoleActive() or isChatBoxInputActive())) then if (hoverstart + hovertime < getTickCount()) then local x, y = getCursorPosition() x, y = screenWidth * x, screenHeight * y x, y = x + cursor_offsetx, y + cursor_offsety dxDrawRectangle(x, y, width + padding_left + padding_right, height + padding_top + padding_bottom, background_color, true) dxDrawText(tooltip, x, y, x + width + padding_left + padding_right, y + height + padding_top + padding_bottom, font_color, font_widthscale, font_heightscale, font_face, "center", "center", false, false, true, true, true) end end end ) addEventHandler("onClientMouseEnter", root, function () local text = getElementData(source, "tooltip") if (type(text) == "string" and #text > 0) then tooltip = text local withoutcolor = text:gsub("#%x%x%x%x%x%x", "") width = dxGetTextWidth(withoutcolor, font_widthscale, font_face) if (#withoutcolor == 0) then tooltip = false return end hoverstart = getTickCount() end end ) addEventHandler("onClientMouseLeave", root, function () tooltip = false end ) Why don't you set the element data sync to false otherwise this element data will be synced with server side which is not needed? setElementData(element,string,value,false) Edit: or the element data doesn't exist server side because the element is client side? Link to comment
MTA Team botder Posted October 12, 2014 MTA Team Share Posted October 12, 2014 That was only an example code And I am not even sure if the server would apply the element data to a GUI element, which is not known serverside. Link to comment
Tails Posted October 12, 2014 Author Share Posted October 12, 2014 Yeah don't worry it's all clientside. Thank you, Necktrox. Link to comment
Tails Posted October 14, 2014 Author Share Posted October 14, 2014 You could also use 'tooltips' resource provided with the Map Editor, or this one from the community.multitheftauto.com. How do you use it? Link to comment
DakiLLa Posted October 14, 2014 Share Posted October 14, 2014 Well, the description of the resource says its all clearly.. Assign any string in "tooltip-text" key as custom data to your GUI element with setElementData() and let the magic do the magic. Simple example: my_btn = guiCreateButton( ... ) setElementData( my_btn, "tooltip-text", "This is my fancy button", false ) Make sure 'tooltips' resource is started. Hover your mouse cursor over the button and you will see a bubble with text on top of it. Link to comment
Tails Posted October 14, 2014 Author Share Posted October 14, 2014 Oh my bad, I meant the tooltip resource from the official map editor. Do you know how to use that one? Link to comment
DNL291 Posted October 14, 2014 Share Posted October 14, 2014 Oh my bad, I meant the tooltip resource from the official map editor. Do you know how to use that one? addEventHandler( "onClientResourceStart", resourceRoot, function() -- Create(x, y, text, foregroundColor, backgroundColor) local BGColor = tocolor(140, 140, 240) local FGColor = tocolor(0, 0, 0) tip = Create(200, 350, "Your tooltip text here", FGColor, BGColor) FadeIn(tip) -- Show the tip end ) Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now