Buttonbars selbstgemacht
Plattform: GM7 Pro, mit kleinen Abänderungen auch GM6 registriert
Also, vielleicht kennt ihr die Buttonbar-Extension von der GMC. Wenn nicht schaut dort mal rein und testet sie. Also ich habe mir gedacht, dass man damit nur sehr bedingt arbeiten kann und wollte mir selber so etwas zusammenscripten. Was herausgekommen ist:
Man kann maximal 15 Buttons einfügen, mit individueller Beschriftung und Aktionen. Die Buttonbar lässt sich mit Hilfe von *.png-Bildern "skinnen", also ist es ganz leicht ein eigenes Design zu machen (siehe nächster Absatz). Man kann die Buttonbar auch mit der Maus verschieben. Also legen wir los:
Wir brauchen mindestens diese drei Scripte: bar_init, bar_refesh und bar_draw (für Erleichterung der Arbeit eventuell ein scr_befehle).
Als erstes brauchen wir ein Desing. Dazu verwenden wir ein Programm wie Photoshop, Gimp etc, auf jedenfall eines, das Transparenz unterstützt. Wir zeichnen eine rechte Seite, eine mittlere und eine linke. Wichtig ist, dass alle gleich breit sind. Die mittlere sollte so sein, dass sie gestreckt werden kann. Alle Teile kommen nebeneinander, sodass die Buttonbar schon fertig aussieht im Programm werden sie dann wieder geteilt. Wenn wir mit der Buttonbar fertig sind, kommen die Buttons. dazu müssen drei Buttons nebeneinander gezeichnet werden, in der Reihenfolge: normal, fokus, gedrückt
Die Buttonbar und die Buttons sollten von einer Breite sein, die durch 3 teilbar ist. Danach speichern wir die Buttonbar im Verzeichnis unserer gmk-datei unter einem Unterordner "Skins" und dort in einen Ordner "default" unter dem Namen "bar.png" und die Buttons unter dem Namen "button.png". dann erstellen wir eine Textdatei mit dem Namen "skin_info.txt" in die wir schreiben:
Spoiler anzeigen
col=0
font='Lucida Sans'
size=8
bold=0
italic=0
r_offset=2
l_offset=2
t_offset=(bar_h-but_h)/2
spacing=2
col ist die Textfarbe des Buttons, font die Schriftart, size die Schriftgröße, bold und italic die typen (1 oder 0). r_offset ist der Abstand eines Buttons zur rechten Seite der Buttonbar und l_offset zur linken. t_offset ist der obere Abstand, der hier mit der Funktion "(bar_h-but_h)/2" angegeben wird, was heißt, dass der Button ganau in der Mitte gezeichnet wird. Zu guter Letzt spacing, was der horizontale Abstand zwischen den Buttons ist. So, kommen wir endlich zum GM. Wir erstellen zwei Sprites "spr_bar" und "spr_button" und ein font "fnt_button". Dann kommen wir zum ersten script, bar_init:
Spoiler anzeigen
Alles anzeigen
Den müssen wir einem controller-Objekt inst create event geben, außerdem schreiben wir:
Ihr seht, ein Script mit dem Namen scr_befehle wird ausgeführt. in diesem Script werden Befehle verkürzt, bsp fürs skinwechseln:
In anführunszeichen deshalb, weil wir mit einer execute_string funktion arbeiten.
danach kommt der script "bar_refresh" wo einfach ein paar variablen erneuert werden (zb wenn der skin gewechselt wir, wäre es gut, wenn dieser script ausgeführt wird):
Spoiler anzeigen
Alles anzeigen
Sooo, jetzt kommt das aufwendigste, das Draw-Event (bar_draw):
Spoiler anzeigen
Alles anzeigen
Viel Code, es steckt aber nur das Zeichnen der Buttons und überprüfen der Mauspositon dahinter (man kann das mit einem extra script und argumenten verkürzen). Das kommt jetzt noch ins Draw-Event des Controller Objekts, mit den Argumenten, für die Aktionen. Im Beispiel sieht das so aus:
Zu guter letzt: es ist möglich den Text eines Buttons über die Variable "text[x]" zu ändern oder abzufragen (wobei x eine Zahl von 0 bis 14 ist)
Hinweis: Ich empfehle, den Room-Speed zu erhöhen, damit das mit dem Maus-Verschieben funktioniert.
Als Beispiel habe ich auch eine datei angehängt.
Plattform: GM7 Pro, mit kleinen Abänderungen auch GM6 registriert
Also, vielleicht kennt ihr die Buttonbar-Extension von der GMC. Wenn nicht schaut dort mal rein und testet sie. Also ich habe mir gedacht, dass man damit nur sehr bedingt arbeiten kann und wollte mir selber so etwas zusammenscripten. Was herausgekommen ist:
Man kann maximal 15 Buttons einfügen, mit individueller Beschriftung und Aktionen. Die Buttonbar lässt sich mit Hilfe von *.png-Bildern "skinnen", also ist es ganz leicht ein eigenes Design zu machen (siehe nächster Absatz). Man kann die Buttonbar auch mit der Maus verschieben. Also legen wir los:
Wir brauchen mindestens diese drei Scripte: bar_init, bar_refesh und bar_draw (für Erleichterung der Arbeit eventuell ein scr_befehle).
Als erstes brauchen wir ein Desing. Dazu verwenden wir ein Programm wie Photoshop, Gimp etc, auf jedenfall eines, das Transparenz unterstützt. Wir zeichnen eine rechte Seite, eine mittlere und eine linke. Wichtig ist, dass alle gleich breit sind. Die mittlere sollte so sein, dass sie gestreckt werden kann. Alle Teile kommen nebeneinander, sodass die Buttonbar schon fertig aussieht im Programm werden sie dann wieder geteilt. Wenn wir mit der Buttonbar fertig sind, kommen die Buttons. dazu müssen drei Buttons nebeneinander gezeichnet werden, in der Reihenfolge: normal, fokus, gedrückt
Die Buttonbar und die Buttons sollten von einer Breite sein, die durch 3 teilbar ist. Danach speichern wir die Buttonbar im Verzeichnis unserer gmk-datei unter einem Unterordner "Skins" und dort in einen Ordner "default" unter dem Namen "bar.png" und die Buttons unter dem Namen "button.png". dann erstellen wir eine Textdatei mit dem Namen "skin_info.txt" in die wir schreiben:
col=0
font='Lucida Sans'
size=8
bold=0
italic=0
r_offset=2
l_offset=2
t_offset=(bar_h-but_h)/2
spacing=2
col ist die Textfarbe des Buttons, font die Schriftart, size die Schriftgröße, bold und italic die typen (1 oder 0). r_offset ist der Abstand eines Buttons zur rechten Seite der Buttonbar und l_offset zur linken. t_offset ist der obere Abstand, der hier mit der Funktion "(bar_h-but_h)/2" angegeben wird, was heißt, dass der Button ganau in der Mitte gezeichnet wird. Zu guter Letzt spacing, was der horizontale Abstand zwischen den Buttons ist. So, kommen wir endlich zum GM. Wir erstellen zwei Sprites "spr_bar" und "spr_button" und ein font "fnt_button". Dann kommen wir zum ersten script, bar_init:
GML-Quellcode
- // Voreingestellte Variablen, nicht ändern:
- number=0
- count=0
- // Verzeichnis für Skins:
- dir='skins\default'
- // Die Längen und Höhen der Buttons und der
- // Buttonbar wird hier errechnet:
- but_w=sprite_get_width(spr_button)
- but_h=sprite_get_height(spr_button)
- bar_w=sprite_get_width(spr_bar)
- bar_h=sprite_get_height(spr_bar)
- // x- und y-Position der Buttonbar.
- place_x=310
- place_y=0
- // Texte der Buttons. Leerlassen bedeutet, dass der Button
- // nicht gezeichnet wird:
- text[0]='Skin'
- text[1]='Start'
- text[2]='Beenden'
- text[3]='Hilfe'
- text[4]=''
- text[5]=''
- text[6]=''
- text[7]=''
- text[8]=''
- text[9]=''
- text[10]=''
- text[11]=''
- text[12]=''
- text[13]=''
- text[14]=''
- // Die Skin-Info Datei wird ausgeführt, um wichtige Informationen
- // zum Skin zu erhalten und u.a. die Schriftart zu wechseln:
- if (file_exists(dir+'\skin_info.txt'))
- {
- execute_file(dir+'\skin_info.txt')
- font_replace(fnt_button,font,size,bold,italic,ord('!'),ord('ÿ'))
- }
- // Errechne Anzahl an Buttons. Muss mal maximaler
- // Anzahl an Buttons ausgeführt werden:
- repeat (15)
- {
- if (text[count]!='')
- number+=1
- count+=1
- }
- // Errechne verschiedene Längen um die Arbeit zu erleichtern (length
- // ist für das Streching des Mittelteils der Buttonbar, bar_end ist die
- // Position an der der letzte Teil gezeichnet wird und bstart ist die
- // erste Position eines Buttons):
- length=l_offset+number*but_w+(number-1)*spacing+r_offset
- bar_end=place_x+l_offset+bar_w+but_w*number+spacing*(number-1)+r_offset
- bstart=place_x+l_offset+bar_w
Den müssen wir einem controller-Objekt inst create event geben, außerdem schreiben wir:
GML-Quellcode
- // Laden des Default-Skins.
- sprite_replace_alpha(spr_bar,'skins\default\bar.png',3,0,0,0,0)
- sprite_replace_alpha(spr_button,'skins\default\button.png',3,0,0,0,0)
- // Ausführen der Scripte für die Definition der Befehle, und die
- // Werte für die Buttonbar.
- script_execute(scr_befehle)
- script_execute(bar_init)
Ihr seht, ein Script mit dem Namen scr_befehle wird ausgeführt. in diesem Script werden Befehle verkürzt, bsp fürs skinwechseln:
In anführunszeichen deshalb, weil wir mit einer execute_string funktion arbeiten.
danach kommt der script "bar_refresh" wo einfach ein paar variablen erneuert werden (zb wenn der skin gewechselt wir, wäre es gut, wenn dieser script ausgeführt wird):
GML-Quellcode
- // Script zum refreshen der Buttonbar-Werte, falls etwas verändert wurde.
- // Die Längen und Höhen der Buttons und der
- // Buttonbar wird hier neu errechnet:
- but_w=sprite_get_width(spr_button)
- but_h=sprite_get_height(spr_button)
- bar_w=sprite_get_width(spr_bar)
- bar_h=sprite_get_height(spr_bar)
- // Die Skin-Info Datei wird erneut ausgeführt, um Informationen
- // zum neuen Skin zu erhalten:
- if (file_exists(dir+'\skin_info.txt'))
- {
- execute_file(dir+'\skin_info.txt')
- font_replace(fnt_button,font,size,bold,italic,ord('!'),ord('ÿ'))
- }
- // Errechne Anzahl an Buttons falls einer hinzugefügt wurde.
- // (Nachträgliches Entfernen von vordefinierten Buttons
- // führt zu Fehlern!):
- number=0
- count=0
- repeat (15)
- {
- if (text[count]!='')
- number+=1
- count+=1
- }
- // Errechne verschiedene Längen erneut:
- length=l_offset+number*but_w+(number-1)*spacing+r_offset
- bar_end=place_x+l_offset+bar_w+but_w*number+spacing*(number-1)+r_offset
- bstart=place_x+l_offset+bar_w
Sooo, jetzt kommt das aufwendigste, das Draw-Event (bar_draw):
GML-Quellcode
- // Script, zum Zeichnen Der Buttonbar mitsamt Buttons.
- // Setze Farbe und Schrift, gemäß der Werte aus "skin_info.txt":
- draw_set_color(col)
- draw_set_font(font)
- // Setze zentriertes Textzeichen:
- draw_set_halign(fa_center)
- draw_set_valign(fa_center)
- // Zeichne die Bar, wobei der mittlere Teil gezerrt wird:
- draw_sprite(spr_bar,0,place_x,place_y)
- draw_sprite_stretched(spr_bar,1,place_x+bar_w,place_y,length,bar_h)
- draw_sprite(spr_bar,2,bar_end,place_y)
- // Überprüfe Mausposition für eventuelles Verschieben:
- if (mouse_x>place_x && mouse_x<place_x+bar_w && mouse_y>place_y && mouse_y<place_y+bar_h && mouse_check_button(mb_left))
- {
- // Springe zur Maus:
- place_x=mouse_x-bar_w/2
- place_y=mouse_y-bar_h/2
- // Springe zu Rand
- if (place_x<6)
- place_x=0
- if (place_y<6)
- place_y=0
- // Refresh
- length=l_offset+number*but_w+(number-1)*spacing+r_offset
- bar_end=place_x+l_offset+bar_w+but_w*number+spacing*(number-1)+r_offset
- bstart=place_x+l_offset+bar_w
- }
- // Zeichne Buttons (argument0-argument14 sind die Aktionen,
- // die beim klicken ausgeführt werden.):
- if (text[0]!='')
- {
- // Buttonstatus
- if not (mouse_x>bstart && mouse_x<bstart+but_w && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h)
- draw_sprite(spr_button,0,bstart,place_y+t_offset)
- if (mouse_x>bstart && mouse_x<bstart+but_w && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && not mouse_check_button(mb_left))
- draw_sprite(spr_button,1,bstart,place_y+t_offset)
- if (mouse_x>bstart && mouse_x<bstart+but_w && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && mouse_check_button(mb_left))
- draw_sprite(spr_button,2,bstart,place_y+t_offset)
- if (mouse_x>bstart && mouse_x<bstart+but_w && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && mouse_check_button_released(mb_left))
- execute_string(argument0)
- // Text
- draw_text(bstart+(but_w/2),place_y+t_offset+(but_h/2),text[0])
- }
- if (text[1]!='')
- {
- // Buttonstatus
- if not (mouse_x>bstart+but_w+spacing && mouse_x<bstart+but_w*2+spacing && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h)
- draw_sprite(spr_button,0,bstart+but_w+spacing,place_y+t_offset)
- if (mouse_x>bstart+but_w+spacing && mouse_x<bstart+but_w*2+spacing && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && not mouse_check_button(mb_left))
- draw_sprite(spr_button,1,bstart+but_w+spacing,place_y+t_offset)
- if (mouse_x>bstart+but_w+spacing && mouse_x<bstart+but_w*2+spacing && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && mouse_check_button(mb_left))
- draw_sprite(spr_button,2,bstart+but_w+spacing,place_y+t_offset)
- if (mouse_x>bstart+but_w+spacing && mouse_x<bstart+but_w*2+spacing && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && mouse_check_button_released(mb_left))
- execute_string(argument1)
- // Text
- draw_text(bstart+but_w*1.5+spacing,place_y+t_offset+(but_h/2),text[1])
- }
- if (text[2]!='')
- {
- // Buttonstatus
- if not (mouse_x>bstart+but_w*2+spacing*2 && mouse_x<bstart+but_w*3+spacing*2 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h)
- draw_sprite(spr_button,0,bstart+but_w*2+spacing*2,place_y+t_offset)
- if (mouse_x>bstart+but_w*2+spacing*2 && mouse_x<bstart+but_w*3+spacing*2 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && not mouse_check_button(mb_left))
- draw_sprite(spr_button,1,bstart+but_w*2+spacing*2,place_y+t_offset)
- if (mouse_x>bstart+but_w*2+spacing*2 && mouse_x<bstart+but_w*3+spacing*2 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && mouse_check_button(mb_left))
- draw_sprite(spr_button,2,bstart+but_w*2+spacing*2,place_y+t_offset)
- if (mouse_x>bstart+but_w*2+spacing*2 && mouse_x<bstart+but_w*3+spacing*2 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && mouse_check_button_released(mb_left))
- execute_string(argument2)
- // Text
- draw_text(bstart+but_w*2.5+spacing*2,place_y+t_offset+(but_h/2),text[2])
- }
- if (text[3]!='')
- {
- // Buttonstatus
- if not (mouse_x>bstart+but_w*3+spacing*3 && mouse_x<bstart+but_w*4+spacing*3 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h)
- draw_sprite(spr_button,0,bstart+but_w*3+spacing*3,place_y+t_offset)
- if (mouse_x>bstart+but_w*3+spacing*3 && mouse_x<bstart+but_w*4+spacing*3 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && not mouse_check_button(mb_left))
- draw_sprite(spr_button,1,bstart+but_w*3+spacing*3,place_y+t_offset)
- if (mouse_x>bstart+but_w*3+spacing*3 && mouse_x<bstart+but_w*4+spacing*3 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && mouse_check_button(mb_left))
- draw_sprite(spr_button,2,bstart+but_w*3+spacing*3,place_y+t_offset)
- if (mouse_x>bstart+but_w*3+spacing*3 && mouse_x<bstart+but_w*4+spacing*3 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && mouse_check_button_released(mb_left))
- execute_string(argument3)
- // Text
- draw_text(bstart+but_w*3.5+spacing*3,place_y+t_offset+(but_h/2),text[3])
- }
- if (text[4]!='')
- {
- // Buttonstatus
- if not (mouse_x>bstart+but_w*4+spacing*4 && mouse_x<bstart+but_w*5+spacing*4 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h)
- draw_sprite(spr_button,0,bstart+but_w*4+spacing*4,place_y+t_offset)
- if (mouse_x>bstart+but_w*4+spacing*4 && mouse_x<bstart+but_w*5+spacing*4 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && not mouse_check_button(mb_left))
- draw_sprite(spr_button,1,bstart+but_w*4+spacing*4,place_y+t_offset)
- if (mouse_x>bstart+but_w*4+spacing*4 && mouse_x<bstart+but_w*5+spacing*4 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && mouse_check_button(mb_left))
- draw_sprite(spr_button,2,bstart+but_w*4+spacing*4,place_y+t_offset)
- if (mouse_x>bstart+but_w*4+spacing*4 && mouse_x<bstart+but_w*5+spacing*4 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && mouse_check_button_released(mb_left))
- execute_string(argument4)
- // Text
- draw_text(bstart+but_w*4.5+spacing*4,place_y+t_offset+(but_h/2),text[4])
- }
- if (text[5]!='')
- {
- // Buttonstatus
- if not (mouse_x>bstart+but_w*5+spacing*5 && mouse_x<bstart+but_w*6+spacing*5 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h)
- draw_sprite(spr_button,0,bstart+but_w*5+spacing*5,place_y+t_offset)
- if (mouse_x>bstart+but_w*5+spacing*5 && mouse_x<bstart+but_w*6+spacing*5 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && not mouse_check_button(mb_left))
- draw_sprite(spr_button,1,bstart+but_w*5+spacing*5,place_y+t_offset)
- if (mouse_x>bstart+but_w*5+spacing*5 && mouse_x<bstart+but_w*6+spacing*5 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && mouse_check_button(mb_left))
- draw_sprite(spr_button,2,bstart+but_w*5+spacing*5,place_y+t_offset)
- if (mouse_x>bstart+but_w*5+spacing*5 && mouse_x<bstart+but_w*6+spacing*5 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && mouse_check_button_released(mb_left))
- execute_string(argument5)
- // Text
- draw_text(bstart+but_w*5.5+spacing*5,place_y+t_offset+(but_h/2),text[5])
- }
- if (text[6]!='')
- {
- // Buttonstatus
- if not (mouse_x>bstart+but_w*6+spacing*6 && mouse_x<bstart+but_w*7+spacing*6 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h)
- draw_sprite(spr_button,0,bstart+but_w*6+spacing*6,place_y+t_offset)
- if (mouse_x>bstart+but_w*6+spacing*6 && mouse_x<bstart+but_w*7+spacing*6 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && not mouse_check_button(mb_left))
- draw_sprite(spr_button,1,bstart+but_w*6+spacing*6,place_y+t_offset)
- if (mouse_x>bstart+but_w*6+spacing*6 && mouse_x<bstart+but_w*7+spacing*6 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && mouse_check_button(mb_left))
- draw_sprite(spr_button,2,bstart+but_w*6+spacing*6,place_y+t_offset)
- if (mouse_x>bstart+but_w*6+spacing*6 && mouse_x<bstart+but_w*7+spacing*6 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && mouse_check_button_released(mb_left))
- execute_string(argument6)
- // Text
- draw_text(bstart+but_w*6.5+spacing*6,place_y+t_offset+(but_h/2),text[6])
- }
- if (text[7]!='')
- {
- // Buttonstatus
- if not (mouse_x>bstart+but_w*7+spacing*7 && mouse_x<bstart+but_w*8+spacing*7 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h)
- draw_sprite(spr_button,0,bstart+but_w*7+spacing*7,place_y+t_offset)
- if (mouse_x>bstart+but_w*7+spacing*7 && mouse_x<bstart+but_w*8+spacing*7 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && not mouse_check_button(mb_left))
- draw_sprite(spr_button,1,bstart+but_w*7+spacing*7,place_y+t_offset)
- if (mouse_x>bstart+but_w*7+spacing*7 && mouse_x<bstart+but_w*8+spacing*7 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && mouse_check_button(mb_left))
- draw_sprite(spr_button,2,bstart+but_w*7+spacing*7,place_y+t_offset)
- if (mouse_x>bstart+but_w*7+spacing*7 && mouse_x<bstart+but_w*8+spacing*7 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && mouse_check_button_released(mb_left))
- execute_string(argument7)
- // Text
- draw_text(bstart+but_w*7.5+spacing*7,place_y+t_offset+(but_h/2),text[7])
- }
- if (text[8]!='')
- {
- // Buttonstatus
- if not (mouse_x>bstart+but_w*8+spacing*8 && mouse_x<bstart+but_w*9+spacing*8 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h)
- draw_sprite(spr_button,0,bstart+but_w*8+spacing*8,place_y+t_offset)
- if (mouse_x>bstart+but_w*8+spacing*8 && mouse_x<bstart+but_w*9+spacing*8 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && not mouse_check_button(mb_left))
- draw_sprite(spr_button,1,bstart+but_w*8+spacing*8,place_y+t_offset)
- if (mouse_x>bstart+but_w*8+spacing*8 && mouse_x<bstart+but_w*9+spacing*8 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && mouse_check_button(mb_left))
- draw_sprite(spr_button,2,bstart+but_w*8+spacing*8,place_y+t_offset)
- if (mouse_x>bstart+but_w*8+spacing*8 && mouse_x<bstart+but_w*9+spacing*8 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && mouse_check_button_released(mb_left))
- execute_string(argument8)
- // Text
- draw_text(bstart+but_w*8.5+spacing*8,place_y+t_offset+(but_h/2),text[8])
- }
- if (text[9]!='')
- {
- // Buttonstatus
- if not (mouse_x>bstart+but_w*9+spacing*9 && mouse_x<bstart+but_w*10+spacing*9 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h)
- draw_sprite(spr_button,0,bstart+but_w*9+spacing*9,place_y+t_offset)
- if (mouse_x>bstart+but_w*9+spacing*9 && mouse_x<bstart+but_w*10+spacing*9 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && not mouse_check_button(mb_left))
- draw_sprite(spr_button,1,bstart+but_w*9+spacing*9,place_y+t_offset)
- if (mouse_x>bstart+but_w*9+spacing*9 && mouse_x<+bstart+but_w*10+spacing*9 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && mouse_check_button(mb_left))
- draw_sprite(spr_button,2,bstart+but_w*9+spacing*9,place_y+t_offset)
- if (mouse_x>bstart+but_w*9+spacing*9 && mouse_x<bstart+but_w*10+spacing*9 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && mouse_check_button_released(mb_left))
- execute_string(argument9)
- // Text
- draw_text(bstart+but_w*9.5+spacing*9,place_y+t_offset+(but_h/2),text[9])
- }
- if (text[10]!='')
- {
- // Buttonstatus
- if not (mouse_x>bstart+but_w*10+spacing*10 && mouse_x<bstart+but_w*11+spacing*10 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h)
- draw_sprite(spr_button,0,bstart+but_w*10+spacing*10,place_y+t_offset)
- if (mouse_x>bstart+but_w*10+spacing*10 && mouse_x<bstart+but_w*11+spacing*10 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && not mouse_check_button(mb_left))
- draw_sprite(spr_button,1,bstart+but_w*10+spacing*10,place_y+t_offset)
- if (mouse_x>bstart+but_w*10+spacing*10 && mouse_x<bstart+but_w*11+spacing*10 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && mouse_check_button(mb_left))
- draw_sprite(spr_button,2,bstart+but_w*10+spacing*10,place_y+t_offset)
- if (mouse_x>bstart+but_w*10+spacing*10 && mouse_x<bstart+but_w*11+spacing*10 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && mouse_check_button_released(mb_left))
- execute_string(argument10)
- // Text
- draw_text(bstart+but_w*10.5+spacing*10,place_y+t_offset+(but_h/2),text[10])
- }
- if (text[11]!='')
- {
- // Buttonstatus
- if not (mouse_x>bstart+but_w*11+spacing*11 && mouse_x<bstart+but_w*12+spacing*11 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h)
- draw_sprite(spr_button,0,bstart+but_w*11+spacing*11,place_y+t_offset)
- if (mouse_x>bstart+but_w*11+spacing*11 && mouse_x<bstart+but_w*12+spacing*11 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && not mouse_check_button(mb_left))
- draw_sprite(spr_button,1,bstart+but_w*11+spacing*11,place_y+t_offset)
- if (mouse_x>bstart+but_w*11+spacing*11 && mouse_x<bstart+but_w*12+spacing*11 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && mouse_check_button(mb_left))
- draw_sprite(spr_button,2,bstart+but_w*11+spacing*11,place_y+t_offset)
- if (mouse_x>bstart+but_w*11+spacing*11 && mouse_x<bstart+but_w*12+spacing*11 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && mouse_check_button_released(mb_left))
- execute_string(argument11)
- // Text
- draw_text(bstart+but_w*11.5+spacing*11,place_y+t_offset+(but_h/2),text[11])
- }
- if (text[12]!='')
- {
- // Buttonstatus
- if not (mouse_x>bstart+but_w*12+spacing*12 && mouse_x<bstart+but_w*13+spacing*12 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h)
- draw_sprite(spr_button,0,bstart+but_w*12+spacing*12,place_y+t_offset)
- if (mouse_x>bstart+but_w*12+spacing*12 && mouse_x<bstart+but_w*13+spacing*12 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && not mouse_check_button(mb_left))
- draw_sprite(spr_button,1,bstart+but_w*12+spacing*12,place_y+t_offset)
- if (mouse_x>bstart+but_w*12+spacing*12 && mouse_x<bstart+but_w*13+spacing*12 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && mouse_check_button(mb_left))
- draw_sprite(spr_button,2,bstart+but_w*12+spacing*12,place_y+t_offset)
- if (mouse_x>bstart+but_w*12+spacing*12 && mouse_x<bstart+but_w*13+spacing*12 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && mouse_check_button_released(mb_left))
- execute_string(argument12)
- // Text
- draw_text(bstart+but_w*12.5+spacing*12,place_y+t_offset+(but_h/2),text[12])
- }
- if (text[13]!='')
- {
- // Buttonstatus
- if not (mouse_x>bstart+but_w*13+spacing*13 && mouse_x<bstart+but_w*14+spacing*13 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h)
- draw_sprite(spr_button,0,bstart+but_w*13+spacing*13,place_y+t_offset)
- if (mouse_x>bstart+but_w*13+spacing*13 && mouse_x<bstart+but_w*14+spacing*13 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && not mouse_check_button(mb_left))
- draw_sprite(spr_button,1,bstart+but_w*13+spacing*13,place_y+t_offset)
- if (mouse_x>bstart+but_w*13+spacing*13 && mouse_x<bstart+but_w*14+spacing*13 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && mouse_check_button(mb_left))
- draw_sprite(spr_button,2,bstart+but_w*13+spacing*13,place_y+t_offset)
- if (mouse_x>bstart+but_w*13+spacing*13 && mouse_x<bstart+but_w*14+spacing*13 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && mouse_check_button_released(mb_left))
- execute_string(argument13)
- // Text
- draw_text(bstart+but_w*13.5+spacing*13,place_y+t_offset+(but_h/2),text[13])
- }
- if (text[14]!='')
- {
- // Buttonstatus
- if not (mouse_x>bstart+but_w*14+spacing*14 && mouse_x<bstart+but_w*15+spacing*14 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h)
- draw_sprite(spr_button,0,bstart+but_w*14+spacing*14,place_y+t_offset)
- if (mouse_x>bstart+but_w*14+spacing*14 && mouse_x<bstart+but_w*15+spacing*14 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && not mouse_check_button(mb_left))
- draw_sprite(spr_button,1,bstart+but_w*14+spacing*14,place_y+t_offset)
- if (mouse_x>bstart+but_w*14+spacing*14 && mouse_x<bstart+but_w*15+spacing*14 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && mouse_check_button(mb_left))
- draw_sprite(spr_button,2,bstart+but_w*14+spacing*14,place_y+t_offset)
- if (mouse_x>bstart+but_w*14+spacing*14 && mouse_x<bstart+but_w*15+spacing*14 && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h && mouse_check_button_released(mb_left))
- execute_string(argument14)
- // Text
- draw_text(bstart+but_w*14.5+spacing*14,place_y+t_offset+(but_h/2),text[14])
- }
Viel Code, es steckt aber nur das Zeichnen der Buttons und überprüfen der Mauspositon dahinter (man kann das mit einem extra script und argumenten verkürzen). Das kommt jetzt noch ins Draw-Event des Controller Objekts, mit den Argumenten, für die Aktionen. Im Beispiel sieht das so aus:
Zu guter letzt: es ist möglich den Text eines Buttons über die Variable "text[x]" zu ändern oder abzufragen (wobei x eine Zahl von 0 bis 14 ist)
Hinweis: Ich empfehle, den Room-Speed zu erhöhen, damit das mit dem Maus-Verschieben funktioniert.
Als Beispiel habe ich auch eine datei angehängt.
© 2008 by Teamgrill Productions
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von MasterXY ()