..:D&G:.. Posted June 27, 2015 Posted June 27, 2015 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.
tuaos Posted June 27, 2015 Posted June 27, 2015 [quote name=..&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
..:D&G:.. Posted June 27, 2015 Author Posted June 27, 2015 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
..:D&G:.. Posted June 27, 2015 Author Posted June 27, 2015 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..
..:D&G:.. Posted June 27, 2015 Author Posted June 27, 2015 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)
tuaos Posted June 29, 2015 Posted June 29, 2015 [quote name=..&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
..:D&G:.. Posted June 29, 2015 Author Posted June 29, 2015 [quote name=..&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.
tuaos Posted June 29, 2015 Posted June 29, 2015 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..
..:D&G:.. Posted June 29, 2015 Author Posted June 29, 2015 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"}, }
Walid Posted June 29, 2015 Posted June 29, 2015 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
..:D&G:.. Posted June 30, 2015 Author Posted June 30, 2015 Doesn't work... Maybe the eventHandler is wrong? addEventHandler ( "onClientGUIClick", donItemsList, selectedImage )
Walid Posted June 30, 2015 Posted June 30, 2015 lol what's your gridList name i think it's donItemsList right.
tuaos Posted June 30, 2015 Posted June 30, 2015 [quote name=..&G:..]Doesn't work... Maybe the eventHandler is wrong? addEventHandler ( "onClientGUIClick", donItemsList, selectedImage ) that Event Handler is ryt
Walid Posted June 30, 2015 Posted June 30, 2015 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 )
..:D&G:.. Posted July 1, 2015 Author Posted July 1, 2015 Doesn't work... and there are also no errors..
Walid Posted July 1, 2015 Posted July 1, 2015 [quote name=..&G:..]Doesn't work... and there are also no errors.. lol :3 working fine for me , post full code here.
..:D&G:.. Posted July 2, 2015 Author Posted July 2, 2015 [quote name=..&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
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