(Gelöst) Mini-Gui, Komischer Fehler...
Übersicht BlitzMax, BlitzMax NG Beginners-Corner
FirstdeathmakerBetreff: (Gelöst) Mini-Gui, Komischer Fehler... |
Mi, Sep 07, 2005 19:54 Antworten mit Zitat |
|
---|---|---|
Ich schreibe gerade an einer Mini-GUI die einfache Schaltflächen darstellen soll. Das Problem ist nun dass es nicht so funktioniert wie es sollte. In folgendem Beispiel erstelle ich ein paar Buttons. Wenn man auf den ersten, Shop, klickt, öffnet sich ein Untermenü. Wenn man jetzt aber nochmal auf den Button "Shop" drückt, werden 2 Buttons gelöscht die nicht gelöscht werden sollen, und 2 erstellt wo 2 gelöscht werden sollten. Ich hab mir jetzt mal über debuglog ausgeben lassen, welche Schalter denn gelöscht werden, dort werden allerdings die richtigen angezeigt, obwohl die falschen gelöscht werden. Naja, hier mal der Code, hintendran die benötigten Ressourcen...
Code: [AUSKLAPPEN] 'CGGUI, Mini-GUI
FONT1 = 0'LoadImageFont("Data\Fonts\hoog05_53.ttf",10,SMOOTHFONT) 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 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) For OBJEKT:CGGUI_OBJECT = EachIn CGGUI_OBJECTS OBJEKT.process() Next EndIf End Method 'Wenn neue Elemente dazu gekommen sind Method Update() SortList(CGGUI_OBJECTS) End Method Method AddButton(x:Float,y:Float,text:String,Image1Path:String, Text1Alpha:Float,Image2Path:String,Text2Alpha:Float, FONT:Int,Command:String,Art:Byte=0, rtext:Byte,gtext:Byte,btext:Byte,rtext2:Byte, gtext2:Byte,btext2:Byte,r=255,g=255,b=255) Local BB:CGBUTTON = New CGBUTTON BB.x = x BB.y = y 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) BB.ImgHeight = ImageHeight(BB.Image2) CGGUI_OBJECTS.addlast(BB) BB.CGGUI = Self End Method Method KillAllButtons(CMD:String) For OBJEKT:CGGUI_OBJECT = EachIn CGGUI_OBJECTS If CGBUTTON(OBJEKT) B:CGBUTTON = CGBUTTON(OBJEKT) If Instr(B.CMD,CMD) B.clear() EndIf Next End Method Method AddCursor(Cursorimagepath:String) C:CGCURSOR = New CGCURSOR C.Image = LoadImage(Cursorimagepath) C.PRIOR = 1 CGGUI_OBJECTS.addlast(C) C.CGGUI = Self 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 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 Method process() SetBlend(Alphablend) SetAlpha 1 SetColor(r,g,b) 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 If CGGUI.MOUSEHIT1'Wenn der Mauzeiger geklickt wurde If Art = 0 CGGUI.ReturnedCMD.addlast(CMD) ElseIf Art = 1 AKTIV = 1-AKTIV EndIf EndIf 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 SetImageFont FONT DrawText text,x+(ImgWidth-TextWidth(text))/2,y+(ImgHeight-TextHeight(text))/2 End Method Method clear() 'Release Image1 'Release Image2 DebugLog "ButtonCleared: "+CMD CGGUI.CGGUI_OBJECTS.remove(Self) End Method End Type Type CGCURSOR Extends CGGUI_OBJECT Field Image Method process() SetAlpha 1 SetColor 255,255,255 DrawImage Image,CGGUI.MOUSE_X,CGGUI.MOUSE_Y End Method End Type ' TEST Graphics 800,600,0 OB:CGGUI = New CGGUI OB.AddCursor("cur.bmp") OB.AddButton(10,34*1,"Shop","Image1.png", 0.8,"Image2.png",1.0,FONT1,"OpenShop",0,255,200,200,200,200,255) OB.AddButton(10,34*2,"Bar","Image1.png", 0.8,"Image2.png",1.0,FONT1,"Test1",0,200,200,255,200,200,255) OB.AddButton(10,34*3,"Shiptrader","Image1.png", 0.8,"Image2.png",1.0,FONT1,"Test1",0,200,255,200,200,200,255) OB.AddButton(10,34*4,"Quit","Image1.png", 0.8,"Image2.png",1.0,FONT1,"Close",0,200,255,200,200,200,255) OB.Update() Repeat Cls OB.process() For Local CMD:String = EachIn OB.ReturnedCMD Select CMD Case "OpenShop" OB.KillAllButtons("_Shop") OB.AddButton(120,34*1,"Goods","Image1.png", 0.8,"Image2.png",1.0,FONT1,"_Shop.OpenGoods",0,255,200,200,200,200,255) OB.AddButton(120,34*2,"Weapons","Image1.png", 0.8,"Image2.png",1.0,FONT1,"_Shop.OpenShopWeapons",0,255,200,200,200,200,255) OB.AddButton(120,34*3,"Back","Image1.png", 0.8,"Image2.png",1.0,FONT1,"Return2Start",0,255,200,200,200,200,255) Case "Return2Start" OB.KillAllButtons("") OB.AddButton(10,34*1,"Shop","Image1.png", 0.8,"Image2.png",1.0,FONT1,"OpenShop",0,255,200,200,200,200,255) OB.AddButton(10,34*2,"Bar","Image1.png", 0.8,"Image2.png",1.0,FONT1,"Test1",0,200,200,255,200,200,255) OB.AddButton(10,34*3,"Shiptrader","Image1.png", 0.8,"Image2.png",1.0,FONT1,"Test1",0,200,255,200,200,200,255) OB.AddButton(10,34*4,"Quit","Image1.png", 0.8,"Image2.png",1.0,FONT1,"Close",0,200,255,200,200,200,255) Case "Close" End End Select Next Flip Until KeyHit(KEY_ESCAPE) End Image1.png Image2.png cur.bmp [mod] ~Editiert~ Code editiert da er das Forenlayout sprengte. MfG D2006 [/mod] |
||
www.illusion-games.de
Space War 3 | Space Race | Galaxy on Fire | Razoon Gewinner des BCC #57 User posted image |
- Zuletzt bearbeitet von Firstdeathmaker am Do, Sep 08, 2005 21:09, insgesamt 2-mal bearbeitet
rema |
Mi, Sep 07, 2005 20:40 Antworten mit Zitat |
|
---|---|---|
Kleiner Tip, statt so eine lange unübersichtliche Zeile zu erstellen:
Code: [AUSKLAPPEN] Method AddButton(x:Float,y:Float,text:String, Image1Path:String,Text1Alpha:Float, Image2Path:String,Text2Alpha:Float, FONT:Int,Command:String,Art:Byte=0, rtext:Byte,gtext:Byte,btext:Byte, rtext2:Byte,gtext2:Byte, btext2:Byte,r=255,g=255,b=255)
kannst du folgendes tun: Code: [AUSKLAPPEN] Medthod AddButton( x:Float,y:Float, .. ' meine Koordinaten
text:String, .. Image1Path:String,Text1Alpha:Float, .. ' erstes Image Image2Path:String,Text2Alpha:Float, .. ' zweites Image FONT:Int, .. Command:String, .. ' sonstiger Kommentar Art:Byte=0, .. rtext:Byte,gtext:Byte,btext:Byte, .. rtext2:Byte,gtext2:Byte,btext2:Byte, .. r=255,g=255,b=255) Sieht doch viel übersichtlicher aus! [mod] ~Editiert~ Code editiert da er das Forenlayout sprengte. MfG D2006 [/mod] |
||
Firstdeathmaker |
Mi, Sep 07, 2005 21:14 Antworten mit Zitat |
|
---|---|---|
Hilft aber beim eigentlichen Problem nicht. Ich kannte den Trick schon, benutze ihn aber nicht. | ||
www.illusion-games.de
Space War 3 | Space Race | Galaxy on Fire | Razoon Gewinner des BCC #57 User posted image |
rema |
Mi, Sep 07, 2005 23:24 Antworten mit Zitat |
|
---|---|---|
Meinte ja nur wegen der besseren Lesbarkeit. Den es schreckt ab und ist mühsam sich auch noch horizontal durch zuscrollen...
Was mir auffällt, jedesmal wen du Method New() aufrufst, erstellst du die Globale TListe CGGUI_OBJECTS immer wieder neu. Mache eine Method Init() oder überprüfe ob eine TList CGGUI_OBJECTS schon ersellt wurde. |
||
Firstdeathmaker |
Do, Sep 08, 2005 7:23 Antworten mit Zitat |
|
---|---|---|
Hab mir deine Vorschläge zu Herzen genommen und die Funktionsbedingungen auf mehrere Zeilen verteilt. Die globale Liste CGGUI_OBJECTS ist nun zu einem Field in CGGUI geworden, hatte das vorher nicht bedacht. Aber der Fehler tritt immer noch nicht auf. Das, was ich absolut nicht verstehen kann, passiert in der Method von CGBUTTON:
Code: [AUSKLAPPEN] Method clear()
'Release Image1 'Release Image2 DebugLog "ButtonCleared: "+CMD CGGUI.CGGUI_OBJECTS.remove(Self) End Method Wenn man zum zweiten Mal auf den Button "Shop" klickt, soll er die zwei Buttons "Goods" und "Weapons" löschen. Genau diese werden auch von dem in clear() enthaltenen Debuglog zurück geliefert, aber gelöscht werden die zwei links daneben liegenden. Ich verstehe das einfach nicht, wie kann der die richtigen bei Debuglog zurückliefern, und dann 2 falsche löschen? Der Löschbefehl "remove" kann sich doch nur auf die richtigen beziehen, oder? Code: [AUSKLAPPEN] 'CGGUI, Mini-GUI
FONT1 = 0'LoadImageFont("Data\Fonts\hoog05_53.ttf",10,SMOOTHFONT) 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 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) For OBJEKT:CGGUI_OBJECT = EachIn CGGUI_OBJECTS OBJEKT.process() Next EndIf End Method 'Wenn neue Elemente dazu gekommen sind Method Update() SortList(CGGUI_OBJECTS) End Method Method AddButton(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 BB.y = y 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) BB.ImgHeight = ImageHeight(BB.Image2) BB.CGGUI = Self CGGUI_OBJECTS.addlast(BB) End Method Method KillAllButtons(CMD:String) For OBJEKT:CGGUI_OBJECT = EachIn CGGUI_OBJECTS If CGBUTTON(OBJEKT) B:CGBUTTON = CGBUTTON(OBJEKT) If Instr(B.CMD,CMD) B.clear() EndIf Next End Method Method AddCursor(Cursorimagepath:String) C:CGCURSOR = New CGCURSOR C.Image = LoadImage(Cursorimagepath) C.PRIOR = 1 CGGUI_OBJECTS.addlast(C) C.CGGUI = Self 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 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 Method process() SetBlend(Alphablend) SetAlpha 1 SetColor(r,g,b) 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 If CGGUI.MOUSEHIT1'Wenn der Mauzeiger geklickt wurde If Art = 0 CGGUI.ReturnedCMD.addlast(CMD) ElseIf Art = 1 AKTIV = 1-AKTIV EndIf EndIf 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 SetImageFont FONT DrawText text,x+(ImgWidth-TextWidth(text))/2,y+(ImgHeight-TextHeight(text))/2 End Method Method clear() 'Release Image1 'Release Image2 DebugLog "ButtonCleared: "+CMD CGGUI.CGGUI_OBJECTS.remove(Self) End Method End Type Type CGCURSOR Extends CGGUI_OBJECT Field Image Method process() SetAlpha 1 SetColor 255,255,255 DrawImage Image,CGGUI.MOUSE_X,CGGUI.MOUSE_Y End Method End Type ' TEST Graphics 800,600,0 OB:CGGUI = New CGGUI OB.AddCursor("cur.bmp") OB.AddButton(10,34*1,"Shop","Image1.png",0.8,"Image2.png",1.0,FONT1,"OpenShop",0,100,0,0,200,0,0) OB.AddButton(10,34*2,"Bar","Image1.png",0.8,"Image2.png",1.0,FONT1,"Test1",0,0,0,100,0,0,255) OB.AddButton(10,34*3,"Shiptrader","Image1.png",0.8,"Image2.png",1.0,FONT1,"Test1",0,0,100,0,0,120,0) OB.AddButton(10,34*4,"Quit","Image1.png",0.8,"Image2.png",1.0,FONT1,"Close",0,0,0,0,255,255,0) OB.Update() SetClsColor 255,255,255 Repeat Cls OB.process() For Local CMD:String = EachIn OB.ReturnedCMD Select CMD Case "OpenShop" OB.KillAllButtons("_Shop") OB.KillAllButtons("_Shop") OB.KillAllButtons("Return2Start") OB.AddButton(120,34*1,"Goods","Image1.png",0.8,"Image2.png",1.0,FONT1,"_Shop.OpenGoods",0,50,0,0,255,0,0) OB.AddButton(120,34*2,"Weapons","Image1.png",0.8,"Image2.png",1.0,FONT1,"_Shop.OpenShopWeapons",0,50,0,0,255,0,0) OB.AddButton(120,34*3,"Back","Image1.png",0.8,"Image2.png",1.0,FONT1,"Return2Start",0,50,0,0,255,0,0) Case "Return2Start" OB.KillAllButtons("") OB.AddButton(10,34*1,"Shop","Image1.png",0.8,"Image2.png",1.0,FONT1,"OpenShop",0,100,0,0,200,0,0) OB.AddButton(10,34*2,"Bar","Image1.png",0.8,"Image2.png",1.0,FONT1,"Test1",0,0,0,100,0,0,255) OB.AddButton(10,34*3,"Shiptrader","Image1.png",0.8,"Image2.png",1.0,FONT1,"Test1",0,0,100,0,0,120,0) OB.AddButton(10,34*4,"Quit","Image1.png",0.8,"Image2.png",1.0,FONT1,"Close",0,0,0,0,255,255,0) Case "Close" End End Select Next Flip Until KeyHit(KEY_ESCAPE) End |
||
www.illusion-games.de
Space War 3 | Space Race | Galaxy on Fire | Razoon Gewinner des BCC #57 User posted image |
Firstdeathmaker |
Do, Sep 08, 2005 21:09 Antworten mit Zitat |
|
---|---|---|
Hab den Fehler gefunden, weis aber nicht warum das so ist:
Ich darf beim erstellen eines neuen Buttons nicht "addlast" sondern muss ihn mit "addfirst" an die Schalterliste der GUI anhängen. |
||
www.illusion-games.de
Space War 3 | Space Race | Galaxy on Fire | Razoon Gewinner des BCC #57 User posted image |
rema |
Do, Sep 08, 2005 21:20 Antworten mit Zitat |
|
---|---|---|
Hmm, du hast:
CGGUI_OBJECTS.addlast(BB) geschrieben. Aber: CGGUI_OBJECTS.addlast(self) sollte es wohl heissen! Dann sollte es klappen! Wiso aber dann addfirst klappt ist mir fraglich... |
||
klepto2 |
Do, Sep 08, 2005 21:39 Antworten mit Zitat |
|
---|---|---|
Also Addlast(bb) ist richtig, denn Addlast(self) würde ja bedeuten, das sich das Fenster zu sich selbst zuordnen wollte, aber es soll ja der Button dem Fenster zugeordnet werden.
Es liegt einfach an der Reihenfolge, wie die Button ausgelesen werden. |
||
Matrix Screensaver
Console Modul für BlitzMax KLPacker Modul für BlitzMax HomePage : http://www.brsoftware.de.vu |
Firstdeathmaker |
Do, Sep 08, 2005 23:07 Antworten mit Zitat |
|
---|---|---|
Ja, aber warum löscht der dann zwei Falsche? Ich prüfe ja schließlich ob es die richtigen sind, aber es wurden immer die falschen gelöscht. | ||
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