Jump to content

[HELP] Update image when selecting row


Recommended Posts

Posted

Hello guys, I am trying to make a gridlist with items, and when the player clicks a row with lets say "Item1", the image from the left size of the gridlist, is updated with a value from the table:

local items = { 
       {"Infernus", 5, "vehicles/infernus.png"}, 
       {"Bullet", 3, "vehicles/bullet.png"}, 
} 
for i, v in ipairs(items) do 
            local row = guiGridListAddRow(donItemsList) 
            guiGridListSetItemText(donItemsList, row, donItemsName, v[1], false, false) 
            guiGridListSetItemText(donItemsList, row, donItemsPrice, v[2]..".00 €", false, false) 
        end 

I don't know how to update the picture and and to get the picture of the selected item...

Thanks.

76561198066470453.png

SP37Ecj.jpg?2MTA:Rust Pre-Alpha Build v.0.3:SP37Ecj.jpg?2

https://forum.mtasa.com/viewtopic.php?f=114&t=97848

2Pac: ''Only God can judge me!''

Posted

[quote name=..:D&G:..]Hello guys, I am trying to make a gridlist with items, and when the player clicks a row with lets say "Item1", the image from the left size of the gridlist, is updated with a value from the table:

local items = { 
       {"Infernus", 5, "vehicles/infernus.png"}, 
       {"Bullet", 3, "vehicles/bullet.png"}, 
} 
for i, v in ipairs(items) do 
            local row = guiGridListAddRow(donItemsList) 
            guiGridListSetItemText(donItemsList, row, donItemsName, v[1], false, false) 
            guiGridListSetItemText(donItemsList, row, donItemsPrice, v[2]..".00 €", false, false) 
        end 

I don't know how to update the picture and and to get the picture of the selected item...

Thanks.

guiGridListGetSelectedItem 

350x20_FF0090_FFFFFF_0C0A36_FF0090.png
Posted

I tried this but it doesn't destroy the default picture(cover picture) nor create a new one...

for i, v in ipairs(items) do 
            local row = guiGridListAddRow(donItemsList) 
            guiGridListSetItemText(donBunuriList, row, donItemsName, v[1], false, false) 
            guiGridListSetItemText(donBunuriList, row, donItemsPret, v[2]..".00 €", false, false) 
             
            local item = guiGridListGetSelectedItem (donItemsList) 
            local donItem = guiGridListGetItemText(donItemsList, item, 1) 
            destroyElement(donItemsPic) 
            donItemsPic = guiCreateStaticImage(291, 144, 219, 206, "images/"..donBun..".png", false, donItemsMain)  
        end  

76561198066470453.png

SP37Ecj.jpg?2MTA:Rust Pre-Alpha Build v.0.3:SP37Ecj.jpg?2

https://forum.mtasa.com/viewtopic.php?f=114&t=97848

2Pac: ''Only God can judge me!''

Posted

I got to a point where, when I click an item from the gridlist, it gets the 8th item only, and when I click another item, it doesn't change...

addEventHandler ( "onClientGUIClick", getRootElement(), function (button, state) 
            if(button == "left") then 
                if(donBunuriPic) then 
                    destroyElement(donBunuriPic) 
                    donBunuriPic = nil 
                end 
                if(source == donBunuriList) then 
                    if(guiGetVisible(donBunuriMain)) then            
                        local row, column = nil  
                        local row_temp, column_temp = guiGridListGetSelectedItem ( source )  
                        if((row == nil) and (row_temp)) then 
                            row = row_temp 
                            column = column_temp 
                                donBunuriPic = guiCreateStaticImage(291, 144, 219, 206, v[3], false, donBunuriMain)   
                            end 
                        end 
                    end 
                end 
            end 
        end) 

76561198066470453.png

SP37Ecj.jpg?2MTA:Rust Pre-Alpha Build v.0.3:SP37Ecj.jpg?2

https://forum.mtasa.com/viewtopic.php?f=114&t=97848

2Pac: ''Only God can judge me!''

Posted

[quote name=..:D&G:..]Bump

Use this, and make sure that I placed your image path correctly!... :)

function selectedImage (button) 
    if (button == "left" ) then 
        if (source == donBunuriList) then 
            currentImage = guiGridListGetItemText ( donBunuriList, guiGridListGetSelectedItem ( donBunuriList ), 1 ) 
            if ( donBunuriPic ) then 
                if guiStaticImageLoadImage ( donBunuriPic, ..yourPreferredImage.. ) == false then 
                    guiStaticImageLoadImage ( donBunuriPic, ..yourimage.. ) 
                end 
            else 
                currentImage = guiCreateStaticImage(291, 144, 219, 206, v[3], false, donBunuriMain) 
            end 
        end 
    end 
addEventHandler( "onClientGUIClick", donBunuriList, selectedImage ) 
end 

350x20_FF0090_FFFFFF_0C0A36_FF0090.png
Posted
[quote name=..:D&G:..]Bump

Use this, and make sure that I placed your image path correctly!... :)

function selectedImage (button) 
    if (button == "left" ) then 
        if (source == donBunuriList) then 
            currentImage = guiGridListGetItemText ( donBunuriList, guiGridListGetSelectedItem ( donBunuriList ), 1 ) 
            if ( donBunuriPic ) then 
                if guiStaticImageLoadImage ( donBunuriPic, ..yourPreferredImage.. ) == false then 
                    guiStaticImageLoadImage ( donBunuriPic, ..yourimage.. ) 
                end 
            else 
                currentImage = guiCreateStaticImage(291, 144, 219, 206, v[3], false, donBunuriMain) 
            end 
        end 
    end 
addEventHandler( "onClientGUIClick", donBunuriList, selectedImage ) 
end 

How is this even supposed to work? "v[3]" will be nill and the 4th if makes no sense, anyway it doesn't work, but thanks for trying to help me. :)

76561198066470453.png

SP37Ecj.jpg?2MTA:Rust Pre-Alpha Build v.0.3:SP37Ecj.jpg?2

https://forum.mtasa.com/viewtopic.php?f=114&t=97848

2Pac: ''Only God can judge me!''

Posted

thats what i mentioned on my last post, that i dont know your image path nor image list or anything about the images. So you have to edit the code and do it your self if not working.. :!:8)

350x20_FF0090_FFFFFF_0C0A36_FF0090.png
Posted

This is the default picture, which shows when no item is selected:

donBunuriPic = guiCreateStaticImage(291, 144, 219, 206, "images/default.png", false, donBunuriMain) 

And the image that needs to show when an item is selected, is for each item in the table:

local bunuri = { 
--Masini 
    {"Infernus", 5, "images/vehicles/infernus.png"}, 
    {"Bullet", 5, "images/vehicles/bullet.png"}, 
    {"Turismo", 5, "images/vehicles/turismo.png"}, 
    {"Super GT", 4, "images/vehicles/supergt.png"}, 
    {"Banshee", 4, "images/vehicles/banshee.png"}, 
    {"Cheetah", 4, "images/vehicles/cheetah.png"}, 
    {"Hotring Racer", 3, "images/vehicles/hotring.png"}, 
    {"Hotring Racer 2", 3, "images/vehicles/hotrina.png"}, 
    {"Hotring Racer 3", 3, "images/vehicles/hotrinb.png"}, 
} 

76561198066470453.png

SP37Ecj.jpg?2MTA:Rust Pre-Alpha Build v.0.3:SP37Ecj.jpg?2

https://forum.mtasa.com/viewtopic.php?f=114&t=97848

2Pac: ''Only God can judge me!''

Posted
function selectedImage() 
    local row = guiGridListGetSelectedItem(donBunuriList) 
    local currentImage = tostring(guiGridListGetItemText(donBunuriList,row,1)) 
    if(currentImage == "") or (currentImage == " ") then 
        guiStaticImageLoadImage(donItemsPic,"images/default.png") 
    else 
        if(fileExists("images/"..string.lower(currentImage)..".png")) then 
            guiStaticImageLoadImage(donItemsPic,"images/"..string.lower(currentImage)..".png") 
        else 
            guiStaticImageLoadImage(donItemsPic,"images/default.png") 
        end 
    end 
end 
  
-- add your event handler onClientGUIClick 

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted

lol what's your gridList name

i think it's donItemsList right.

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted

[quote name=..:D&G:..]Doesn't work... Maybe the eventHandler is wrong?

addEventHandler ( "onClientGUIClick", donItemsList, selectedImage ) 

that Event Handler is ryt :!:

350x20_FF0090_FFFFFF_0C0A36_FF0090.png
Posted
function selectedImage() 
    local row = guiGridListGetSelectedItem(donItemsList) 
    local currentImage = tostring(guiGridListGetItemText(donItemsList,row,1)) 
    if(currentImage == "") or (currentImage == " ") then 
        guiStaticImageLoadImage(donItemsPic,"images/default.png") 
    else 
        if(fileExists("images/"..string.lower(currentImage)..".png")) then 
            guiStaticImageLoadImage(donItemsPic,"images/"..string.lower(currentImage)..".png") 
        else 
            guiStaticImageLoadImage(donItemsPic,"images/default.png") 
        end 
    end 
end 
  
-- Event handler put it inside the GUI part 
addEventHandler ( "onClientGUIClick", donItemsList, selectedImage,false ) 

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted

[quote name=..:D&G:..]Doesn't work... and there are also no errors..

lol :3 working fine for me , post full code here.

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted
[quote name=..:D&G:..]Doesn't work... and there are also no errors..

lol :3 working fine for me , post full code here.

local bunuri = { 
    {"Infernus", 5, "images/vehicles/infernus.png"}, 
    {"Bullet", 5, "images/vehicles/bullet.png"}, 
    {"Turismo", 5, "images/vehicles/turismo.png"}, 
    {"Super GT", 4, "images/vehicles/supergt.png"}, 
    {"Banshee", 4, "images/vehicles/banshee.png"}, 
    {"Cheetah", 4, "images/vehicles/cheetah.png"}, 
    {"Hotring Racer", 3, "images/vehicles/hotring.png"}, 
    {"Hotring Racer 2", 3, "images/vehicles/hotrina.png"}, 
    {"Hotring Racer 3", 3, "images/vehicles/hotrinb.png"}, 
  
} 
  
function showMainBunuriWindow() 
    if isElement(donBunuriMain) then 
        destroyElement(donBunuriMain) 
        showCursor(false) 
    else 
        local screenWidth, screenHeight = guiGetScreenSize() 
        local windowWidth, windowHeight = 548, 491 
        local left = screenWidth/2 - windowWidth/2 
        local top = screenHeight/2 - windowHeight/2 
        donBunuriMain = guiCreateWindow(left, top, windowWidth, windowHeight, "Informatii Bunuri", false) 
        guiWindowSetSizable(donBunuriMain, false) 
        donBunuriList = guiCreateGridList(24, 98, 257, 351, false, donBunuriMain) 
        donBunuriName = guiGridListAddColumn(donBunuriList, "Nume", 0.6) 
        donBunuriPret = guiGridListAddColumn(donBunuriList, "Preţ(Eur)", 0.3) 
        addEventHandler ( "onClientGUIClick", donBunuriList, selectedImage,false ) 
        for i, v in ipairs(bunuri) do 
            local row = guiGridListAddRow(donBunuriList) 
            guiGridListSetItemText(donBunuriList, row, donBunuriName, v[1], false, false) 
            guiGridListSetItemText(donBunuriList, row, donBunuriPret, v[2]..".00 €", false, false) 
        end  
         
        donInfoTop = guiCreateLabel(60, 39, 440, 18, "Aici puteti vedea bunurile ce le puteti primii pentru suma ce doriti sa o donati!", false, donBunuriMain) 
        guiSetFont(donInfoTop, "default-bold-small") 
        guiLabelSetColor(donInfoTop, 39, 250, 4) 
        donBunuriPic = guiCreateStaticImage(291, 144, 219, 206, "images/default.png", false, donBunuriMain)     
        donInchideButton = guiCreateButton(441, 438, 85, 39, "Închide", false, donBunuriMain) 
        addEventHandler ( "onClientGUIClick", donInchideButton, closeBunuriWindow )  
        showCursor(true) 
    end 
end 
     
function selectedImage() 
    local row = guiGridListGetSelectedItem(donBunuriList) 
    local currentImage = tostring(guiGridListGetItemText(donBunuriList,row,1)) 
    if(currentImage == "") or (currentImage == " ") then 
        guiStaticImageLoadImage(donBunuriPic,"images/default.png") 
    else 
        if(fileExists("images/"..string.lower(currentImage)..".png")) then 
            guiStaticImageLoadImage(donBunuriPic,"images/"..string.lower(currentImage)..".png") 
        else 
            guiStaticImageLoadImage(donBunuriPic,"images/default.png") 
        end 
    end 
end 

76561198066470453.png

SP37Ecj.jpg?2MTA:Rust Pre-Alpha Build v.0.3:SP37Ecj.jpg?2

https://forum.mtasa.com/viewtopic.php?f=114&t=97848

2Pac: ''Only God can judge me!''

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