Objekt will nicht aus Liste raus
Übersicht BlitzMax, BlitzMax NG Beginners-Corner
FirstdeathmakerBetreff: Objekt will nicht aus Liste raus |
So, Sep 18, 2005 18:47 Antworten mit Zitat |
|
---|---|---|
Ich hab folgendes Problem: Ich habe ein Objekt (CGText) in einer Liste gespeichert, aber es will da einfach nicht mehr raus, obwohl ich es mit
Code: [AUSKLAPPEN] Method clear() CGGUI.CGGUI_OBJECTS.remove(Self) CGGUI = Null End Method aus der Liste entferne. Andere Sachen die ich genauso behandel, funktionieren problemlos, lassen sich auch einfach wieder aus der Liste entfernen (z.B. CGCursor), aber eben dieses blöde CGText nicht. Das Objekt ist in einer Liste die sich in einem übergeordneten Objekt befindet (CGGUI). Ich weis zwar, dass ein Objekt so lange nicht verschwindet, wie es noch irgentwo gespeichert ist, aber erstens ist das Objekt hier nur in der Liste gespeichert, und zweitens muss so ein Objekt doch spätestens nach dem Befehl remove da rausgelöscht sein, oder? Hier der ganze Codeabschnitt wo das Objekt "CGText" drin vorkommt (Nicht alleine Lauffähig): Code: [AUSKLAPPEN] 'CGGUI, Mini-GUI
Type CGGUI Field CGGUI_OBJECTS:TList Field Aktive:Byte'Ob die GUI überhaupt aktiv ist Field ReturnedCMD:TList Field MOUSE_X:Int Field MOUSE_Y:Int Field MOUSEHIT1:Byte Field MOUSEDOWN1:Byte Field MOUSEOVER:Byte' Wenn die Maus über etwas ist 'Initialisierung Method New() CGGUI_OBJECTS:TList = New TList ReturnedCMD:TList = CreateList() Aktive = 1 End Method 'Hauptprozess Method process() If Aktive ClearList(ReturnedCMD) MOUSE_X = MouseX() MOUSE_Y = MouseY() MOUSEHIT1 = MouseHit(1) MOUSEDOWN1 = MouseDown(1) setownscale() SetRotation 0 Local count:Int For Local OBJEKT:CGGUI_OBJECT = EachIn CGGUI_OBJECTS OBJEKT.process() count:+1 Next DrawText "GUIOBJ: "+count,200,10 EndIf End Method 'Wenn neue Elemente dazu gekommen sind Method Update() SortList(CGGUI_OBJECTS) End Method Method AddButton:CGBUTTON(x:Float,y:Float,.. 'Koordinaten des Buttons text:String,.. 'Schaltertext Image1Path:String,.. 'Image Wenn Schalter Aus Text1Alpha:Float,.. 'Textalpha Wenn Schalter Aus Image2Path:String,.. 'Image Wenn Schalter An Text2Alpha:Float,.. 'Textalpha Wenn Schalter An FONT:Int,.. 'Schriftart für Schalter Command:String,.. 'Schalterkommando (Wird in CGGUI.ReturnedCMD zurückgeliefert wenn aktiviert) Art:Byte=0,.. ' 0 = Normal, 1 = An/Aus wenn geklickt rtext:Byte,gtext:Byte,btext:Byte,.. 'Textfarbe Schalter Aus rtext2:Byte,gtext2:Byte,btext2:Byte,.. 'Textfarbe Schalter An r=255,g=255,b=255) 'Schalterfarbe DebugLog "CreateButton: "+Command Local BB:CGBUTTON = New CGBUTTON BB.x = x*GFX_XSCALE BB.y = y*GFX_YSCALE BB.text = text BB.Image1 = LoadImage(Image1Path) BB.Image2 = LoadImage(Image2Path) BB.Alpha1 = Text1Alpha BB.Alpha2 = Text2Alpha BB.FONT = Font BB.CMD = Command BB.PRIOR = 2 BB.ART = Art BB.r = r BB.g = g BB.b = b BB.rtext = rtext BB.gtext = gtext BB.btext = btext BB.rtext2 = rtext2 BB.gtext2 = gtext2 BB.btext2 = btext2 BB.ImgWidth = ImageWidth(BB.Image2)*GFX_XSCALE BB.ImgHeight = ImageHeight(BB.Image2)*GFX_YSCALE BB.CGGUI = Self CGGUI_OBJECTS.addfirst(BB) Return BB End Method Method KillAllGuiObj(CMD:String) For Local OBJEKT:CGGUI_OBJECT = EachIn CGGUI_OBJECTS If CGBUTTON(OBJEKT) Local B:CGBUTTON = CGBUTTON(OBJEKT) If Instr(B.CMD,CMD) B.clear() ElseIf CGCargoInventar(OBJEKT) Local I:CGCargoInventar = CGCargoInventar(OBJEKT) If Instr(I.Name,CMD) I.clear() ElseIf CGText(OBJEKT) Local CT:CGText = CGText(OBJEKT) If Instr(CT.Name,CMD) CT.clear() EndIf Next End Method Method KillAllButtons(CMD:String) For Local OBJEKT:CGGUI_OBJECT = EachIn CGGUI_OBJECTS If CGBUTTON(OBJEKT) Local B:CGBUTTON = CGBUTTON(OBJEKT) If Instr(B.CMD,CMD) B.clear() EndIf Next End Method Method SetAllButtons(CMD:String,GESPERRT:Byte) For Local OBJEKT:CGGUI_OBJECT = EachIn CGGUI_OBJECTS If CGBUTTON(OBJEKT) Local B:CGBUTTON = CGBUTTON(OBJEKT) If Instr(B.CMD,CMD) B.GESPERRT = GESPERRT EndIf Next End Method Method SetAktiveButtons(CMD:String,AKTIV:Byte) For Local OBJEKT:CGGUI_OBJECT = EachIn CGGUI_OBJECTS If CGBUTTON(OBJEKT) Local B:CGBUTTON = CGBUTTON(OBJEKT) If Instr(B.CMD,CMD) B.AKTIV = AKTIV EndIf Next End Method Method GetAktiveButtons(CMD:String) For Local OBJEKT:CGGUI_OBJECT = EachIn CGGUI_OBJECTS If CGBUTTON(OBJEKT) Local B:CGBUTTON = CGBUTTON(OBJEKT) If Instr(B.CMD,CMD) Return B.AKTIV EndIf Next End Method Method AddCursor(Cursorimagepath:String) Local C:CGCURSOR = New CGCURSOR C.Image = LoadImage(Cursorimagepath) C.PRIOR = 1 CGGUI_OBJECTS.addlast(C) C.CGGUI = Self End Method Method AddCargoInventar:CGCargoInventar(Name:String,x:Int,y:Int,EntryNumber:Int,TCARGO_LIST:TList) Local Inventar:CGCargoInventar = CGCargoInventar.create(Name:String,x:Int,y:Int,EntryNumber:Int,TCARGO_LIST:TList) Inventar.PRIOR = 3 CGGUI_OBJECTS.addlast(Inventar) Inventar.CGGUI = Self Return Inventar:CGCargoInventar End Method Method KillAllInventar(Name:String) For Local OBJEKT:CGGUI_OBJECT = EachIn CGGUI_OBJECTS If CGCargoInventar(OBJEKT) Local I:CGCargoInventar = CGCargoInventar(OBJEKT) If Instr(I.Name,Name) I.clear() EndIf Next End Method Method AddCGText(Name:String,X:Int,Y:Int,Font,Text:String) Local C:CGText = New CGText C.Name = Name C.X = X C.Y = Y C.Font = Font C.Text = Text C.PRIOR = 2 CGGUI_OBJECTS.addlast(C) C.CGGUI = Self End Method Method ShutDown() ClearList(ReturnedCMD) For Local OBJEKT:CGGUI_OBJECT = EachIn CGGUI_OBJECTS OBJEKT.clear() Next End Method End Type Type CGGUI_OBJECT 'Verwaltung Field CGGUI:CGGUI'Zu welcher GUI das Element gehört Field PRIOR'Priorität nach der es sortiert wird Method process() Abstract Method compare(other:Object) If Not CGGUI_OBJECT(other) Then .. Return 0 Local OBJ:CGGUI_OBJECT = CGGUI_OBJECT(other) If OBJ.PRIOR>Self.PRIOR Return 1 ElseIf OBJ.PRIOR<Self.PRIOR Return -1 EndIf Return 0 End Method Method clear() Abstract End Type Type CGBUTTON Extends CGGUI_OBJECT Field x:Float Field y:Float Field text:String Field Image1'Normalzustand Field Image2'Mauszeiger drüber Field Alpha1:Float'Für die Schrift Field Alpha2:Float'Für die Schrift Field FONT Field ART:Byte' 0 = Normal, 1 = An/Aus Field CMD:String Field rtext:Byte,gtext:Byte,btext:Byte Field rtext2:Byte,gtext2:Byte,btext2:Byte Field r:Byte,g:Byte,b:Byte 'Untervariablen Field ImgWidth:Int Field ImgHeight:Int Field AKTIV:Byte Field GESPERRT:Byte Method process() SetBlend(Alphablend) SetAlpha 1 SetColor(r,g,b) If GESPERRT = 0 If CGGUI.MOUSE_X>X And CGGUI.MOUSE_X<X+ImgWidth And CGGUI.MOUSE_Y>Y And CGGUI.MOUSE_Y<Y+ImgHeight CGGUI.MOUSEOVER = 1 Select Art Case 0 If CGGUI.MOUSEHIT1 CGGUI.ReturnedCMD.addlast(CMD) 'Wenn der Mauzeiger gedrückt wurde Case 1 If CGGUI.MOUSEHIT1 AKTIV = 1-AKTIV 'Wenn der Mauzeiger geklickt wurde End Select If Art=0 Or AKTIV DrawImage Image2,x,y SetAlpha Alpha2 SetColor(rtext2,gtext2,btext2) Else DrawImage Image1,x,y SetAlpha Alpha1 SetColor(rtext,gtext,btext) EndIf Else If Art=0 Or AKTIV=0 DrawImage Image1,x,y SetAlpha Alpha1 SetColor(rtext,gtext,btext) Else DrawImage Image2,x,y SetAlpha Alpha2 SetColor(rtext2,gtext2,btext2) EndIf EndIf Else'Wenn der Button gesperrt ist... SetAlpha(0.5) DrawImage Image1,x,y SetAlpha (Alpha1/2) SetColor(rtext,gtext,btext) EndIf SetImageFont FONT DrawText text,x+(ImgWidth/GFX_XSCALE-TextWidth(text))/2,y+(ImgHeight/GFX_YSCALE-TextHeight(text))/2 End Method Method clear() Release Image1 Release Image2 DebugLog "ButtonCleared: "+CMD CGGUI.CGGUI_OBJECTS.remove(Self) CGGUI = Null End Method End Type Type CGCURSOR Extends CGGUI_OBJECT Field Image Method process() SetAlpha 1 SetColor 255,255,255 SetBlend(Alphablend) DrawImage Image,CGGUI.MOUSE_X,CGGUI.MOUSE_Y End Method Method clear() Release Image CGGUI.CGGUI_OBJECTS.remove(Self) CGGUI = Null End Method End Type Type CGCargoInventar Extends CGGUI_OBJECT Field TCARGO_LIST:TList ' Hier werden Pointer auf die Cargoteile hinterlegt. Field Name:String Field x:Int Field y:Int Field InventarImageTop Field InventarImageMid Field InventarImageDown Field EntryImage Field EntryNumber:Int'Wie viele Einträge maximal gleichzeitig sichtbar sind Field EntryPos:Int'Welcher Eintrag gerade oben ist. Field EntryCount:Int'Wie viele Einträge es überhaupt gibt Method process() Local x2:Float Local y2:Float Local TextH:Byte = TextHeight("X") Local TextW:Byte = TextWidth("X") Local i:Int = 0 x2:Float = (x-2)*GFX_XSCALE y2:Float = (y-5)*GFX_YSCALE SetColor 255,255,255 DrawImage InventarImageTop,x2,y2 For i = 0 To EntryNumber x2:Float = (x-2)*GFX_XSCALE y2:Float = (y+i*80)*GFX_YSCALE DrawImage InventarImageMid,x2,y2 Next x2:Float = (x-2)*GFX_XSCALE y2:Float = (y+i*80)*GFX_YSCALE DrawImage InventarImageDown,x2,y2 i = 0 EntryCount = 0 For Local C:TCargo = EachIn TCARGO_LIST EntryCount:+1 If i>=EntryPos And i<=EntryPos+EntryNumber x2:Float = x*GFX_XSCALE y2:Float = (y+(i-Entrypos)*80)*GFX_YSCALE SetColor 255,255,255 DrawImage EntryImage,x2,y2 SetColor 0,0,100 DrawText C.Info.Name,x2+TextW,y2+TextH DrawText "Anzahl: "+C.Number,x2+TextW,y2+TextH*2.5 EndIf i:+1 Next End Method Function create:CGCargoInventar(Name:String,x:Int,y:Int,EntryNumber:Int,TCARGO_LIST:TList Var) Local C:CGCargoInventar = New CGCargoInventar C.Name = Name C.x = x C.y = y C.EntryNumber = EntryNumber C.EntryPos = 0 C.TCARGO_LIST:TList = TCARGO_LIST C.InventarImageTop = LoadImage("Gfx\Menue\InvImageTop.png") C.InventarImageMid = LoadImage("Gfx\Menue\InvImageMid.png") C.InventarImageDown = LoadImage("Gfx\Menue\InvImageTop.png") C.EntryImage = LoadImage("Gfx\Menue\EtryImg.png") Return C End Function Function GetCGCargoInventar:CGCargoInventar(Name:String,GUI:CGGUI) For Local CI:CGCargoInventar = EachIn GUI.CGGUI_OBJECTS If CI.Name = Name Return CI Next End Function Method clear() Release InventarImageTop Release InventarImageMid Release InventarImageDown Release EntryImage CGGUI.CGGUI_OBJECTS.remove(Self) CGGUI = Null End Method 'Steuerung der Liste Method PushEntrys(number:Int) EntryPos:+number If EntryPos<0 EntryPos = 0 If EntryPos>=EntryCount-EntryNumber If EntryCount-Entrynumber>=0 EntryPos = EntryCount-Entrynumber-1 Else EntryPos = 0 EndIf EndIf End Method End Type Type CGText Extends CGGUI_OBJECT Field Name:String Field X:Int Field Y:Int Field Font Field Text:String'Contentfield Method process() 'If CGGUI = Null DebugStop SetAlpha 1 SetColor 255,255,255 SetBlend(Alphablend) SetImageFont(Font) DrawText Text,x*GFX_XSCALE+TextWidth(Text)/2,y*GFX_YSCALE End Method Method GetContent:String() Return Text End Method Function GetCGText:CGText(Name:String,GUI:CGGUI) For Local CT:CGText = EachIn GUI.CGGUI_OBJECTS If CT.Name = Name Return CT Next End Function Rem Method ModCount(Number:Int) If Count+Number<0 Count = 0 Else Count:+Number EndIf End Method Method ModCount2(D:Byte)'Multiplikator mit 10 | -1 = Absteigend, +1 = Aufsteigend If D=1 Count = Count*10 ElseIf D=-1 And Count>0 Count = Count/10 EndIf End Method End Rem Method clear() CGGUI.CGGUI_OBJECTS.remove(Self) CGGUI = Null End Method End Type |
||
www.illusion-games.de
Space War 3 | Space Race | Galaxy on Fire | Razoon Gewinner des BCC #57 User posted image |
rema |
So, Sep 18, 2005 18:52 Antworten mit Zitat |
|
---|---|---|
Probiere mal folgendes:
Code: [AUSKLAPPEN] Method clear() CGGUI_OBJECTS.remove(Self) End Method Vorallem kannst du mit "CGGUI = Null" nicht gleich deinen ganzen Type löschen wollen, oder doch??? |
||
Firstdeathmaker |
So, Sep 18, 2005 19:04 Antworten mit Zitat |
|
---|---|---|
Aber in CGText ist die GUI doch unter CGGUI gespeichert!
Ich rufe in der letzten Methode die Objektliste auf und lösche das Objekt CGText daraus, genauso wie du vorgeschlagen hast. Oder meinst du ich soll das vom GUI-Type aus direkt löschen? Code: [AUSKLAPPEN] Method clear() CGGUI.CGGUI_OBJECTS.remove(Self) CGGUI = Null End Method |
||
www.illusion-games.de
Space War 3 | Space Race | Galaxy on Fire | Razoon Gewinner des BCC #57 User posted image |
Übersicht BlitzMax, BlitzMax NG Beginners-Corner
Powered by phpBB © 2001 - 2006, phpBB Group