Hi - I'm trying to create a UI system that will allow me to create screens and buttons etc. I'm doing this the following way using my new OOP knowledge!
You see in the UICreateScreen function that it creates a list of buttons.
What I'd like to do is have the functionality to add buttons to the list I have created (within TScreen), and then use a for eachin loop to cycle through the buttons in the list and any that exist will be drawn.
Problem is I've tried putting an addButton method function into the TScreen type, but I'm confused as to how to access the list I have already created in the UICreateScreen function . And I also dont know how to access the buttons to draw them ;-(
Can anyone help?
thanks
Type TScreen Field sName:String Field background:TImage ' Create a list of buttons belonging to the screen Field buttonList: TList 'Creates a list of screens Global ScreenList: TList Function UICreateScreen:TScreen(name:String, image:String, totalButtons:Int) Local NewScreen: TScreen NewScreen = New TScreen NewScreen.sName = name$ NewScreen.background = LoadImage(image$) ' Verfiy files exist and are of correct size Assert NewScreen.background Else "Cannot find file '"+image$+ "'." Assert NewScreen.background.width=iScreenWidth Else "Background: "+image$+" size does Not match screen width." Assert NewScreen.background.height=iScreenHeight Else "Background: "+image$+" size does Not match screen height." If Not screenlist Then ScreenList:Tlist = CreateList() ' Once all checks are done add screen to list ScreenList.addlast ( NewScreen) 'Create a list of buttons which will be a part of this screen If Not NewScreen.buttonList Then NewScreen.buttonList:Tlist= CreateList() For Local temp=1 To totalButtons NewScreen.buttonList.addlast( New TButton) Next 'This should return the object just created so we can access it at a later date Return NewScreen EndFunction Method AddButton(screen:TScreen, name:String, x:Int,y:Int, image:String, buttonType:Int) Local NewButton:TButton NewButton= New Tbutton NewButton.sName$=name$ NewButton.x=x NewButton.y=y SetMaskColor (0,0,0) If buttonType=STATIC NewButton.normal = LoadImage(image$) Else NewButton.normal = LoadAnimImage(image$,NewButton.iCellWidth,NewButton.iCellHeight,0,NewButton.iTotalFrames+1,DYNAMICIMAGE|MASKEDIMAGE) EndIf Assert NewButton.normal Else "Cannot find file '"+image$+ "'." screen.buttonList.addlast ( NewButton ) End Method Method DrawButtoScreen() DrawImage background,0,0 EndMethod EndType
You see in the UICreateScreen function that it creates a list of buttons.
Type TButton Field sName:String Field x:Int Field y:Int Field normal:TImage 'This will be a anim image. If we only want it to be a static image only have one frame Field link:Int Field iCellWidth:Int=169 Field iCellHeight:Int=75 Field iTotalFrames:Int=0 endtype
What I'd like to do is have the functionality to add buttons to the list I have created (within TScreen), and then use a for eachin loop to cycle through the buttons in the list and any that exist will be drawn.
Problem is I've tried putting an addButton method function into the TScreen type, but I'm confused as to how to access the list I have already created in the UICreateScreen function . And I also dont know how to access the buttons to draw them ;-(
Can anyone help?
thanks