Buttonbars selbst gemacht

    Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

    • Buttonbars selbst gemacht

      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

      GML-Quellcode

      1. // Voreingestellte Variablen, nicht ändern:
      2. number=0
      3. count=0
      4. // Verzeichnis für Skins:
      5. dir='skins\default'
      6. // Die Längen und Höhen der Buttons und der
      7. // Buttonbar wird hier errechnet:
      8. but_w=sprite_get_width(spr_button)
      9. but_h=sprite_get_height(spr_button)
      10. bar_w=sprite_get_width(spr_bar)
      11. bar_h=sprite_get_height(spr_bar)
      12. // x- und y-Position der Buttonbar.
      13. place_x=310
      14. place_y=0
      15. // Texte der Buttons. Leerlassen bedeutet, dass der Button
      16. // nicht gezeichnet wird:
      17. text[0]='Skin'
      18. text[1]='Start'
      19. text[2]='Beenden'
      20. text[3]='Hilfe'
      21. text[4]=''
      22. text[5]=''
      23. text[6]=''
      24. text[7]=''
      25. text[8]=''
      26. text[9]=''
      27. text[10]=''
      28. text[11]=''
      29. text[12]=''
      30. text[13]=''
      31. text[14]=''
      32. // Die Skin-Info Datei wird ausgeführt, um wichtige Informationen
      33. // zum Skin zu erhalten und u.a. die Schriftart zu wechseln:
      34. if (file_exists(dir+'\skin_info.txt'))
      35. {
      36. execute_file(dir+'\skin_info.txt')
      37. font_replace(fnt_button,font,size,bold,italic,ord('!'),ord('ÿ'))
      38. }
      39. // Errechne Anzahl an Buttons. Muss mal maximaler
      40. // Anzahl an Buttons ausgeführt werden:
      41. repeat (15)
      42. {
      43. if (text[count]!='')
      44. number+=1
      45. count+=1
      46. }
      47. // Errechne verschiedene Längen um die Arbeit zu erleichtern (length
      48. // ist für das Streching des Mittelteils der Buttonbar, bar_end ist die
      49. // Position an der der letzte Teil gezeichnet wird und bstart ist die
      50. // erste Position eines Buttons):
      51. length=l_offset+number*but_w+(number-1)*spacing+r_offset
      52. bar_end=place_x+l_offset+bar_w+but_w*number+spacing*(number-1)+r_offset
      53. bstart=place_x+l_offset+bar_w
      Alles anzeigen



      Den müssen wir einem controller-Objekt inst create event geben, außerdem schreiben wir:

      GML-Quellcode

      1. // Laden des Default-Skins.
      2. sprite_replace_alpha(spr_bar,'skins\default\bar.png',3,0,0,0,0)
      3. sprite_replace_alpha(spr_button,'skins\default\button.png',3,0,0,0,0)
      4. // Ausführen der Scripte für die Definition der Befehle, und die
      5. // Werte für die Buttonbar.
      6. script_execute(scr_befehle)
      7. 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:

      GML-Quellcode

      1. skin="{dir=get_directory_alt('Skinordner wählen',working_directory+'\skins');
      2. if (dir!=''){sprite_replace_alpha(spr_bar,dir+'\bar.png',3,0,0,0,0);
      3. sprite_replace_alpha(spr_button,dir+'\button.png',3,0,0,0,0)
      4. script_execute(bar_refresh)}}"


      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

      GML-Quellcode

      1. // Script zum refreshen der Buttonbar-Werte, falls etwas verändert wurde.
      2. // Die Längen und Höhen der Buttons und der
      3. // Buttonbar wird hier neu errechnet:
      4. but_w=sprite_get_width(spr_button)
      5. but_h=sprite_get_height(spr_button)
      6. bar_w=sprite_get_width(spr_bar)
      7. bar_h=sprite_get_height(spr_bar)
      8. // Die Skin-Info Datei wird erneut ausgeführt, um Informationen
      9. // zum neuen Skin zu erhalten:
      10. if (file_exists(dir+'\skin_info.txt'))
      11. {
      12. execute_file(dir+'\skin_info.txt')
      13. font_replace(fnt_button,font,size,bold,italic,ord('!'),ord('ÿ'))
      14. }
      15. // Errechne Anzahl an Buttons falls einer hinzugefügt wurde.
      16. // (Nachträgliches Entfernen von vordefinierten Buttons
      17. // führt zu Fehlern!):
      18. number=0
      19. count=0
      20. repeat (15)
      21. {
      22. if (text[count]!='')
      23. number+=1
      24. count+=1
      25. }
      26. // Errechne verschiedene Längen erneut:
      27. length=l_offset+number*but_w+(number-1)*spacing+r_offset
      28. bar_end=place_x+l_offset+bar_w+but_w*number+spacing*(number-1)+r_offset
      29. bstart=place_x+l_offset+bar_w
      Alles anzeigen



      Sooo, jetzt kommt das aufwendigste, das Draw-Event (bar_draw):
      Spoiler anzeigen

      GML-Quellcode

      1. // Script, zum Zeichnen Der Buttonbar mitsamt Buttons.
      2. // Setze Farbe und Schrift, gemäß der Werte aus "skin_info.txt":
      3. draw_set_color(col)
      4. draw_set_font(font)
      5. // Setze zentriertes Textzeichen:
      6. draw_set_halign(fa_center)
      7. draw_set_valign(fa_center)
      8. // Zeichne die Bar, wobei der mittlere Teil gezerrt wird:
      9. draw_sprite(spr_bar,0,place_x,place_y)
      10. draw_sprite_stretched(spr_bar,1,place_x+bar_w,place_y,length,bar_h)
      11. draw_sprite(spr_bar,2,bar_end,place_y)
      12. // Überprüfe Mausposition für eventuelles Verschieben:
      13. 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))
      14. {
      15. // Springe zur Maus:
      16. place_x=mouse_x-bar_w/2
      17. place_y=mouse_y-bar_h/2
      18. // Springe zu Rand
      19. if (place_x<6)
      20. place_x=0
      21. if (place_y<6)
      22. place_y=0
      23. // Refresh
      24. length=l_offset+number*but_w+(number-1)*spacing+r_offset
      25. bar_end=place_x+l_offset+bar_w+but_w*number+spacing*(number-1)+r_offset
      26. bstart=place_x+l_offset+bar_w
      27. }
      28. // Zeichne Buttons (argument0-argument14 sind die Aktionen,
      29. // die beim klicken ausgeführt werden.):
      30. if (text[0]!='')
      31. {
      32. // Buttonstatus
      33. if not (mouse_x>bstart && mouse_x<bstart+but_w && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h)
      34. draw_sprite(spr_button,0,bstart,place_y+t_offset)
      35. 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))
      36. draw_sprite(spr_button,1,bstart,place_y+t_offset)
      37. 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))
      38. draw_sprite(spr_button,2,bstart,place_y+t_offset)
      39. 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))
      40. execute_string(argument0)
      41. // Text
      42. draw_text(bstart+(but_w/2),place_y+t_offset+(but_h/2),text[0])
      43. }
      44. if (text[1]!='')
      45. {
      46. // Buttonstatus
      47. 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)
      48. draw_sprite(spr_button,0,bstart+but_w+spacing,place_y+t_offset)
      49. 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))
      50. draw_sprite(spr_button,1,bstart+but_w+spacing,place_y+t_offset)
      51. 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))
      52. draw_sprite(spr_button,2,bstart+but_w+spacing,place_y+t_offset)
      53. 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))
      54. execute_string(argument1)
      55. // Text
      56. draw_text(bstart+but_w*1.5+spacing,place_y+t_offset+(but_h/2),text[1])
      57. }
      58. if (text[2]!='')
      59. {
      60. // Buttonstatus
      61. 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)
      62. draw_sprite(spr_button,0,bstart+but_w*2+spacing*2,place_y+t_offset)
      63. 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))
      64. draw_sprite(spr_button,1,bstart+but_w*2+spacing*2,place_y+t_offset)
      65. 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))
      66. draw_sprite(spr_button,2,bstart+but_w*2+spacing*2,place_y+t_offset)
      67. 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))
      68. execute_string(argument2)
      69. // Text
      70. draw_text(bstart+but_w*2.5+spacing*2,place_y+t_offset+(but_h/2),text[2])
      71. }
      72. if (text[3]!='')
      73. {
      74. // Buttonstatus
      75. 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)
      76. draw_sprite(spr_button,0,bstart+but_w*3+spacing*3,place_y+t_offset)
      77. 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))
      78. draw_sprite(spr_button,1,bstart+but_w*3+spacing*3,place_y+t_offset)
      79. 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))
      80. draw_sprite(spr_button,2,bstart+but_w*3+spacing*3,place_y+t_offset)
      81. 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))
      82. execute_string(argument3)
      83. // Text
      84. draw_text(bstart+but_w*3.5+spacing*3,place_y+t_offset+(but_h/2),text[3])
      85. }
      86. if (text[4]!='')
      87. {
      88. // Buttonstatus
      89. 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)
      90. draw_sprite(spr_button,0,bstart+but_w*4+spacing*4,place_y+t_offset)
      91. 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))
      92. draw_sprite(spr_button,1,bstart+but_w*4+spacing*4,place_y+t_offset)
      93. 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))
      94. draw_sprite(spr_button,2,bstart+but_w*4+spacing*4,place_y+t_offset)
      95. 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))
      96. execute_string(argument4)
      97. // Text
      98. draw_text(bstart+but_w*4.5+spacing*4,place_y+t_offset+(but_h/2),text[4])
      99. }
      100. if (text[5]!='')
      101. {
      102. // Buttonstatus
      103. 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)
      104. draw_sprite(spr_button,0,bstart+but_w*5+spacing*5,place_y+t_offset)
      105. 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))
      106. draw_sprite(spr_button,1,bstart+but_w*5+spacing*5,place_y+t_offset)
      107. 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))
      108. draw_sprite(spr_button,2,bstart+but_w*5+spacing*5,place_y+t_offset)
      109. 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))
      110. execute_string(argument5)
      111. // Text
      112. draw_text(bstart+but_w*5.5+spacing*5,place_y+t_offset+(but_h/2),text[5])
      113. }
      114. if (text[6]!='')
      115. {
      116. // Buttonstatus
      117. 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)
      118. draw_sprite(spr_button,0,bstart+but_w*6+spacing*6,place_y+t_offset)
      119. 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))
      120. draw_sprite(spr_button,1,bstart+but_w*6+spacing*6,place_y+t_offset)
      121. 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))
      122. draw_sprite(spr_button,2,bstart+but_w*6+spacing*6,place_y+t_offset)
      123. 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))
      124. execute_string(argument6)
      125. // Text
      126. draw_text(bstart+but_w*6.5+spacing*6,place_y+t_offset+(but_h/2),text[6])
      127. }
      128. if (text[7]!='')
      129. {
      130. // Buttonstatus
      131. 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)
      132. draw_sprite(spr_button,0,bstart+but_w*7+spacing*7,place_y+t_offset)
      133. 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))
      134. draw_sprite(spr_button,1,bstart+but_w*7+spacing*7,place_y+t_offset)
      135. 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))
      136. draw_sprite(spr_button,2,bstart+but_w*7+spacing*7,place_y+t_offset)
      137. 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))
      138. execute_string(argument7)
      139. // Text
      140. draw_text(bstart+but_w*7.5+spacing*7,place_y+t_offset+(but_h/2),text[7])
      141. }
      142. if (text[8]!='')
      143. {
      144. // Buttonstatus
      145. 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)
      146. draw_sprite(spr_button,0,bstart+but_w*8+spacing*8,place_y+t_offset)
      147. 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))
      148. draw_sprite(spr_button,1,bstart+but_w*8+spacing*8,place_y+t_offset)
      149. 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))
      150. draw_sprite(spr_button,2,bstart+but_w*8+spacing*8,place_y+t_offset)
      151. 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))
      152. execute_string(argument8)
      153. // Text
      154. draw_text(bstart+but_w*8.5+spacing*8,place_y+t_offset+(but_h/2),text[8])
      155. }
      156. if (text[9]!='')
      157. {
      158. // Buttonstatus
      159. 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)
      160. draw_sprite(spr_button,0,bstart+but_w*9+spacing*9,place_y+t_offset)
      161. 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))
      162. draw_sprite(spr_button,1,bstart+but_w*9+spacing*9,place_y+t_offset)
      163. 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))
      164. draw_sprite(spr_button,2,bstart+but_w*9+spacing*9,place_y+t_offset)
      165. 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))
      166. execute_string(argument9)
      167. // Text
      168. draw_text(bstart+but_w*9.5+spacing*9,place_y+t_offset+(but_h/2),text[9])
      169. }
      170. if (text[10]!='')
      171. {
      172. // Buttonstatus
      173. 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)
      174. draw_sprite(spr_button,0,bstart+but_w*10+spacing*10,place_y+t_offset)
      175. 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))
      176. draw_sprite(spr_button,1,bstart+but_w*10+spacing*10,place_y+t_offset)
      177. 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))
      178. draw_sprite(spr_button,2,bstart+but_w*10+spacing*10,place_y+t_offset)
      179. 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))
      180. execute_string(argument10)
      181. // Text
      182. draw_text(bstart+but_w*10.5+spacing*10,place_y+t_offset+(but_h/2),text[10])
      183. }
      184. if (text[11]!='')
      185. {
      186. // Buttonstatus
      187. 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)
      188. draw_sprite(spr_button,0,bstart+but_w*11+spacing*11,place_y+t_offset)
      189. 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))
      190. draw_sprite(spr_button,1,bstart+but_w*11+spacing*11,place_y+t_offset)
      191. 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))
      192. draw_sprite(spr_button,2,bstart+but_w*11+spacing*11,place_y+t_offset)
      193. 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))
      194. execute_string(argument11)
      195. // Text
      196. draw_text(bstart+but_w*11.5+spacing*11,place_y+t_offset+(but_h/2),text[11])
      197. }
      198. if (text[12]!='')
      199. {
      200. // Buttonstatus
      201. 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)
      202. draw_sprite(spr_button,0,bstart+but_w*12+spacing*12,place_y+t_offset)
      203. 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))
      204. draw_sprite(spr_button,1,bstart+but_w*12+spacing*12,place_y+t_offset)
      205. 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))
      206. draw_sprite(spr_button,2,bstart+but_w*12+spacing*12,place_y+t_offset)
      207. 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))
      208. execute_string(argument12)
      209. // Text
      210. draw_text(bstart+but_w*12.5+spacing*12,place_y+t_offset+(but_h/2),text[12])
      211. }
      212. if (text[13]!='')
      213. {
      214. // Buttonstatus
      215. 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)
      216. draw_sprite(spr_button,0,bstart+but_w*13+spacing*13,place_y+t_offset)
      217. 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))
      218. draw_sprite(spr_button,1,bstart+but_w*13+spacing*13,place_y+t_offset)
      219. 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))
      220. draw_sprite(spr_button,2,bstart+but_w*13+spacing*13,place_y+t_offset)
      221. 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))
      222. execute_string(argument13)
      223. // Text
      224. draw_text(bstart+but_w*13.5+spacing*13,place_y+t_offset+(but_h/2),text[13])
      225. }
      226. if (text[14]!='')
      227. {
      228. // Buttonstatus
      229. 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)
      230. draw_sprite(spr_button,0,bstart+but_w*14+spacing*14,place_y+t_offset)
      231. 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))
      232. draw_sprite(spr_button,1,bstart+but_w*14+spacing*14,place_y+t_offset)
      233. 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))
      234. draw_sprite(spr_button,2,bstart+but_w*14+spacing*14,place_y+t_offset)
      235. 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))
      236. execute_string(argument14)
      237. // Text
      238. draw_text(bstart+but_w*14.5+spacing*14,place_y+t_offset+(but_h/2),text[14])
      239. }
      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:

      GML-Quellcode

      1. // skin, play, ende und hilfe sind definierte Variablen aus "scr_befehle"
      2. // und ersetzten argument0-argument3 in "bar_draw".
      3. script_execute(bar_draw,skin,play,ende,hilfe)


      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.
      Dateien

      © 2008 by Teamgrill Productions

      Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von MasterXY ()

    • Was ich noch vergessen habe: Der script "scr_refesh" sollte mit diesem gefüllt sein
      Spoiler anzeigen

      GML-Quellcode

      1. // Script zum refreshen der Buttonbar-Werte, falls etwas verändert wurde.
      2. // Die Längen und Höhen der Buttons und der
      3. // Buttonbar wird hier neu errechnet:
      4. but_w=sprite_get_width(spr_button)
      5. but_h=sprite_get_height(spr_button)
      6. bar_w=sprite_get_width(spr_bar)
      7. bar_h=sprite_get_height(spr_bar)
      8. // Die Skin-Info Datei wird erneut ausgeführt, um Informationen
      9. // zum neuen Skin zu erhalten:
      10. if (file_exists(dir+'\skin_info.txt'))
      11. {
      12. execute_file(dir+'\skin_info.txt')
      13. font_replace(fnt_button,font,size,bold,italic,ord('!'),ord('ÿ'))
      14. }
      15. // Errechne Anzahl an Buttons falls einer hinzugefügt wurde.
      16. // (Nachträgliches Entfernen von vordefinierten Buttons
      17. // führt zu Fehlern!):
      18. number=0
      19. count=0
      20. repeat (15)
      21. {
      22. if (text[count]!='')
      23. number+=1
      24. count+=1
      25. }
      26. // Errechne verschiedene Längen erneut:
      27. length=l_offset+number*but_w+(number-1)*spacing+r_offset
      28. bar_end=place_x+l_offset+bar_w+but_w*number+spacing*(number-1)+r_offset
      29. bstart=place_x+l_offset+bar_w
      Alles anzeigen


      und möglichst bei jedem Skinwechsel ausgeführt werden. Wenn noch was fehlt, bitte mir sagen oder in der Beispieldatei nachschauen, da ist alles drin.

      © 2008 by Teamgrill Productions

      Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von MasterXY ()

    • Warum hast du 15 mal hintereinander fast den gleichen Code geschrieben? Ich geb dir nen Tipp: Du kannst statt argument0, argument1... argument[0..15] verwenden und den Code in eine Schleife packen.

      Achja, du solltest die Anzahl an möglichen Buttons unbegrenzt machen. Glaub zwar kaum, dass jemand mehr brauch, find ich aber irgendwie besser. ;)

      Ansonsten gute Arbeit!

      Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von Bl@ckSp@rk ()

    • Original von Bl@ckSp@rk
      Achja, du solltest die Anzahl an möglichen Buttons unbegrenzt machen. Glaub zwar kaum, dass jemand mehr brauch, find ich aber irgendwie besser. ;)


      Tja, wie gesagt, außer du hast einen 100 Zoll Bildschirm :D

      Aber wie meinst du das mit der Schleife?

      © 2008 by Teamgrill Productions
    • Die Schleife müsste so aussehen. Probiers mal aus.

      GML-Quellcode

      1. // Zeichne Buttons (argument0-argument14 sind die Aktionen,
      2. // die beim klicken ausgeführt werden.):
      3. for (i = 0; i < 15; i += 1)
      4. {
      5. if (text[i]!='')
      6. {
      7. // Buttonstatus
      8. if (mouse_x>bstart+i*but_w && mouse_x<bstart+(i+1)*but_w+i*spacing && mouse_y>place_y+t_offset && mouse_y<place_y+t_offset+but_h)
      9. {
      10. if (mouse_check_button(mb_left))
      11. draw_sprite(spr_button,2,bstart,place_y+t_offset)
      12. else if (mouse_check_button_released(mb_left))
      13. execute_string(argument[i])
      14. else
      15. draw_sprite(spr_button,1,bstart,place_y+t_offset)
      16. }
      17. else
      18. draw_sprite(spr_button,0,bstart,place_y+t_offset)
      19. // Text
      20. draw_text(bstart+(i+0.5)*but_w,place_y+t_offset+(but_h/2),text[i])
      21. }
      22. }
      Alles anzeigen
    • So, nach längerem Überlegen habe ich mir meine Buttonbar nochmal angeschaut und sie nun noch ein bisschen kompakter gescripted. Zum einen habe ich, wie Bl@ckSp@rk gesagt hat den Code in eine Schleife gepackt (seine Variante hat zwar nicht funktioniert, aber ich habe es mir angetan, es selbst zu machen :D). Zum Anderen hbae ich das Mausverschieben flüssiger gemacht, sodass man auch noch bei hoher Geschwindigkeit die Buttonbar anständig bewegen kann. Ich werde die Scriptänderungen jetzt nicht hier reinstellen, aber natürlich die neue *.gmk Datei.
      Dateien
      • buttonbar.zip

        (155,36 kB, 249 mal heruntergeladen, zuletzt: )

      © 2008 by Teamgrill Productions
    • Benutzer online 1

      1 Besucher