Jacob Lenn Posted July 27, 2013 Share Posted July 27, 2013 <towary> <item name="Item 1" cash="100" score="0" /> <item name="Item 2" cash="100" score="0" /> </towary> That's my XML file and how i can download all of these items and put them in girdlist? I know about triggering but i don't really know how XML function works. If someone be nice and can tell me how it works i will be happy. Link to comment
Vector Posted July 27, 2013 Share Posted July 27, 2013 set file as a client-side file. suppose your file is towary.xml in the meta file, put this. > src="towary.xml" />> an put a client-side script to load your items into a grid-list > ="client.lua" type="client" /> src="towary.xml" />> this is the client-side script. (client.lua) -- this is your grid list. local gridList = guiCreateGridList (0.4, 0.4, 0.35, 0.3, true); -- I´ll add a column for the cash, another for the name and the score. local nameColumn = guiGridListAddColumn (gridList, "name", .333); -- name column local cashColumn = guiGridListAddColumn (gridList, "cash", .333); -- cash column local scoreColumn = guiGridListAddColumn (gridList, "score", .333); -- score column -- this will load the items. addEventHandler ("onClientResourceStart", getResourceRootElement (getThisResource ()), function () local file = xmlLoadFile ("towary.xml"); -- open file. assert (file, "Fail to load towary.xml"); -- error if file could not be opened. local children = xmlNodeGetChildren (file); -- get children nodes. for _,child in ipairs (children) do -- for each node... if string.lower (xmlNodeGetName (child)) == "item" then -- be sure it´s a item -- get item data. local attrs = xmlNodeGetAttributes (child); local name,cash,score = attrs.name, attrs.cash, attrs.score; -- check if all attributes are set. -- output an error if some attribute is not set. if not name then outputDebugString ("name attribute not set for item", 2); end; if not cash then outputDebugString ("cash attribute not set for item", 2); end; if not score then outputDebugString ("score attribute not set for item", 2); end; if cash and score and name then -- is a valid item ? -- add new item to gridlist. local itemRow = guiGridListAddRow (gridList); guiGridListSetItemText (gridList, itemRow, nameColumn, name, false, false); guiGridListSetItemText (gridList, itemRow, cashColumn, cash, false, true); guiGridListSetItemText (gridList, itemRow, scoreColumn, score, false, true); end; end; end; xmlUnloadFile (file); -- close file end); Link to comment
Jacob Lenn Posted July 27, 2013 Author Share Posted July 27, 2013 K thanks. And now how can i do gridlist without moving this bar below? Image: http://snag.gy/MP6fq.jpg Link to comment
Vector Posted July 27, 2013 Share Posted July 27, 2013 you need to reduce the relative size of the columns. ... instead of local nameColumn = guiGridListAddColumn (gridList, "name", .333); -- name column local cashColumn = guiGridListAddColumn (gridList, "cash", .333); -- cash column local scoreColumn = guiGridListAddColumn (gridList, "score", .333); -- score column try this... local nameColumn = guiGridListAddColumn (gridList, "name", .233); -- name column local cashColumn = guiGridListAddColumn (gridList, "cash", .233); -- cash column local scoreColumn = guiGridListAddColumn (gridList, "score", .233); -- score column Link to comment
Jacob Lenn Posted July 27, 2013 Author Share Posted July 27, 2013 What about center row's text? Link to comment
Vector Posted July 27, 2013 Share Posted July 27, 2013 you can´t do that directly, but you can use a little trick, leaving spaces at left and right side. I guess. use this function, instead of guiGridListSetItemText function guiGridListSetItemTextAligned(gridList, rowIndex, colIndex, text, section, number, colSize) local gridListWidth = guiGetSize (gridList, false); local gridListColumnWidth = colSize * gridListWidth; local textWidth = dxGetTextWidth (text); -- font must be default. local spaceWidth = dxGetTextWidth (" "); local numSpaces = math.floor ((gridListColumnWidth-textWidth)/2)/spaceWidth); local spaces = string.rep (" ", numSpaces); local alignedText = spaces .. text .. spaces; guiGridListSetItemText (gridList, rowIndex, colIndex, alignedText, section, number); end; -- i have not test it. instead of... guiGridListSetItemText (gridList, itemRow, nameColumn, name, false, false); guiGridListSetItemText (gridList, itemRow, cashColumn, cash, false, true); guiGridListSetItemText (gridList, itemRow, scoreColumn, score, false, true); do this... guiGridListSetItemTextAligned (gridList,itemRow,nameColumn,name,false,false, .233); guiGridListSetItemTextAligned (gridList,itemRow,cashColumn,cash,false,true,.233); guiGridListSetItemTextAligned (gridList,itemRow,scoreColumn,score,false,true,.233); Link to comment
Jacob Lenn Posted July 27, 2013 Author Share Posted July 27, 2013 Wow ur da best. U only missed 1 thing. Here local numSpaces = math.floor ((gridListColumnWidth-textWidth)/2)/spaceWidth); Correct local numSpaces = math.floor (((gridListColumnWidth-textWidth)/2)/spaceWidth); Link to comment
Vector Posted July 27, 2013 Share Posted July 27, 2013 aa ok. . carefull with that function, only work if the GUI font of the gridlist is the default one. if any question: [email protected] 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