Guest User

Untitled

a guest
Oct 20th, 2024
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. number sfx1 sfx2 sfx3 sfx4
  2. mml_load sfx1 "sfx/b1.mml"
  3. mml_load sfx2 "sfx/b2.mml"
  4. mml_load sfx3 "sfx/b3.mml"
  5. mml_load sfx4 "sfx/b4.mml"
  6.  
  7. map c b1 b2 b3 b4
  8. map_set c "draw" draw_window
  9. map_set c "event" null_event
  10. call_result b1 mkbutton "Elixir" sfx1
  11. call_result b2 mkbutton "Holy Water" sfx2
  12. call_result b3 mkbutton "Potion" sfx3
  13. call_result b4 mkbutton "Potion Omega" sfx4
  14.  
  15. number font
  16. font_load font "vga.ttf" 12 1
  17.  
  18. number container w1 w2 w3 w4
  19.  
  20. widget_create container 200 200 c
  21. widget_set_accepts_focus container FALSE
  22. widget_create w1 0.5 0.5 b1
  23. widget_set_parent w1 container
  24. widget_create w2 0.5 0.5 b2
  25. widget_set_parent w2 container
  26. widget_create w3 0.5 0.5 b3
  27. widget_set_break_line w3 TRUE
  28. widget_set_parent w3 container
  29. widget_create w4 0.5 0.5 b4
  30. widget_set_parent w4 container
  31.  
  32. widget_set_padding w1 5
  33. widget_set_padding w2 5
  34. widget_set_padding w3 5
  35. widget_set_padding w4 5
  36.  
  37. gui_start container
  38.  
  39. gui_set_focus w1
  40.  
  41. function draw_window x y w h focussed data
  42. {
  43.     filled_rectangle 0 0 255 255 0 0 255 255 0 0 255 255 0 0 255 255 x y w h
  44. }
  45.  
  46. function draw_button x y w h focussed data
  47. {
  48.     number r g b
  49.     if (== focussed TRUE) yellow white
  50.         = r 255
  51.         = g 255
  52.         = b 0
  53.     :yellow
  54.         = r 255
  55.         = g 255
  56.         = b 255
  57.     :white
  58.     number tw th
  59.     font_width font tw [data "text"]
  60.     font_height font th
  61.  
  62.     number xx yy
  63.     = xx (+ x (/ w 2))
  64.     - xx (/ tw 2)
  65.     = yy (+ y (/ h 2))
  66.     - yy (/ th 2)
  67.  
  68.     filled_rectangle 0 0 255 255 0 0 255 255 0 255 255 255 0 255 255 255 x y w h
  69.     rectangle r g b 255 x y w h 2
  70.     font_draw font r g b 255 [data "text"] xx yy
  71. }
  72.  
  73. function null_event type a b c d x y w h focussed data
  74. {
  75. }
  76.  
  77. function button_event type a b c d x y w h focussed data
  78. {
  79.     if (&& (== type EVENT_MOUSE_DOWN) (== a 1)) play
  80.         number on_button
  81.         call_result on_button owned x y w h c d
  82.         if (== on_button TRUE) really_play
  83.             mml_play [data "sfx"] 1 0
  84.         :really_play
  85.     :play
  86.  
  87.     if (&& (== TRUE focussed) (|| (&& (== type EVENT_KEY_DOWN) (== KEY_RETURN a)) (&& (== type EVENT_JOY_DOWN) (== a JOY_A)))) play_it
  88.         mml_play [data "sfx"] 1 0
  89.     :play_it
  90. }
  91.  
  92. function mkbutton text sfx
  93. {
  94.     map m
  95.     map_set m "text" text
  96.     map_set m "sfx" sfx
  97.     map_set m "draw" draw_button
  98.     map_set m "event" button_event
  99.     return m
  100. }
  101.  
  102. function owned wx wy ww wh x y
  103. {
  104.     if (|| (< x wx) (< y wy) (>= x (+ wx ww)) (>= y (+ wy wh))) nope
  105.         return FALSE
  106.     :nope
  107.     return TRUE
  108. }
  109.  
  110. function gui_event id type a b c d x y w h focussed data
  111. {
  112.     call [data "event"] type a b c d x y w h focussed data
  113. }
  114.  
  115. function gui_draw id x y w h focussed data
  116. {
  117.     call [data "draw"] x y w h focussed data
  118. }
Advertisement
Add Comment
Please, Sign In to add comment