Jump to content

Array in a class


AggrorJorn
 Share

Recommended Posts

The titel is perhaps a little overdue to the actual problem. Here is the situation. I am working on my Gui and it is time for me to create a dropdown button. (you might have notice the status update ;))

 

I want to create this Gui so that it is really easy accesible and easy to understand for everyone. Basicly said: a Dropdown button actually exists out of multiple normal buttons (with normal, hover and mousedown mode). What I hope to achieve is something like the code beneath.

 

dropdown1 = LuaGui.CreateDropDown(2) -- number of rows is filled in as a parameter
dropdown1:SetImages("abstract::normal.dds","abstract::hover.dds")
dropdown1.row1:SetImages("abstract::normal.dds","abstract::hover.dds")
dropdown1.row2:SetImages("abstract::normal.dds","abstract::hover.dds")

 

As you can see, row1 and row2 members of the dropdown button that is created.

 

In the Gui code itself I have this:

       function LuaGui.CreateDropDown(rows)
       local o = {}
       setmetatable(o, LuaGui)

  	--rows
o.row = {}	
for n=1,rows do
	o.row[n] = LuaGui.CreateButton()--Create a basic button for every row.
       end
       return o

 

Any suggestions?

Link to comment
Share on other sites

I guess I forgot to mention the most important part to make this topic in the first place: it doesn't work.... ;)

 

But you helped me out again. It has to be dropdown1.row[1] instead if dropdown1.row1. I figured that the Gui code would place the number just behind the row. Which, after reading this line, doesn't make much sense.

 

The actual problem is solved but suggestions, comments, constructive critism are all welcome. It might put me to some ideas.

 

Thanks for the help Rick +1

Link to comment
Share on other sites

It's not a bad design, but I don't think it's flexible enough. If someone wants to add rows on the fly this doesn't seem to account for that.

 

I would drop the parameter which you seem to be using to tell how many are in the table. Use something like the below if you need to loop through the table:

 

for index,value in ipairs(t) do

print(index,value)

end

 

Then maybe make an AddButton() method that will add a button to the next index in the array (you can keep this count in a variable to the class if you like, although I would make they keys in the table a name of the button so people could retrieve the button from the table by name later if they so wish. So AddButton() would take a parameter which would be the string name to call the button in the table).

Link to comment
Share on other sites

Just to frustrate you a little bit further Aggror: :)

To have a really nice dropdown, it also needs a container with a background image and a slider (another image) so you can scroll through items.

post-79-039534400 1280130248_thumb.jpg

desktop: Quad core Q6600 + 4GB + ATI HD4890 + XP

laptop: Dual core T6400 + 4 GB + NVidia 9600M GT + Vista 32

Link to comment
Share on other sites

ey guys!

 

Yes there are many flaws to the gui design. Not just this dropdown button but the Gui in general. But I am just seeing how far I can get with squirming around and trying stuff out. I have the principle of OOP in my head with this Gui, but it isn't really used yet.

 

As for the:

 

for index,value in ipairs(t) do

print(index,value)

end

I'll give it a go! :)

 

@ cocopino. You are right, that should be added as well. But then I should let people have the ability to create panels as well. I am afraid it would take me little to much time to find this out. I want to focus merely on the things that I can do (and understand). Still, thanks for the reminder.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...