Jump to content

[HELP] Update image when selecting row


..:D&G:..

Recommended Posts

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.

Link to comment

[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 

Link to comment

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  

Link to comment

I tried this:

local item = guiGridListGetSelectedItem (donItemsList) 
             
            guiStaticImageLoadImage(donItemPic, item.v[3]) 

But it doesn't get the "item" and the text, picture and only 1 item is displayed in the gridlist..

Link to comment

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) 

Link to comment

[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 

Link to comment
[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. :)

Link to comment

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"}, 
} 

Link to comment
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 

Link to comment
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 ) 

Link to comment
[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 

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