ui.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. #include "eruta.h"
  2. #include "image.h"
  3. #include "store.h"
  4. #include "zori.h"
  5. #include "zori_screen.h"
  6. #include "zori_console.h"
  7. #include "zori_button.h"
  8. #include "zori_page.h"
  9. #include "zori_menu.h"
  10. #include "monolog.h"
  11. #include "ui.h"
  12. /* This file contains the concrete implementation of the Eruta GUI
  13. * and it's various GUI screens and pages. */
  14. static struct ui_state the_ui_state;
  15. char POEM_TEXT[] = "After mankind's summer, winter suddenly came"
  16. "Most reached for the stars, but some remained"
  17. "The earth scarred by the Ancients unhostpitable"
  18. "The hopes low, and so much wisdom forgotten"
  19. "Yet when it seemed the last hour struck"
  20. "Our hope returned, a savior arose"
  21. "Lord Kei, who by Creator's grace"
  22. "Restored the Trees that guard us all from harm"
  23. "Thus ushered in a new millennial spring"
  24. "Lord Kei, watch over us and protect us"
  25. "Until the Travellers return with bounty of the stars";
  26. char INTRO_TEXT[] = "Millennia have passed since mankind first traveled to the moon. "
  27. "Civilizations rose as never before, yet to fall again. "
  28. "When all hope seemed lost, the 21 trees sprouted from the earth. "
  29. "They brought mysterious powers that protected and strengthened mankind. "
  30. "Hi!\n\n"
  31. "Hello µ world, this is me, 無 life should be\nfun for everyone!";
  32. char INTRO_TEXT2[] = "Something happened, and I was changed!";
  33. zori_id ui_state_make_sub_menu(zori_id parent, int x, int y, int w, int bh);
  34. /* Set up Zori GUI. */
  35. void ui_state_init(struct ui_state * ui,
  36. zori_display * display,
  37. zori_font * font
  38. ) {
  39. struct zori_style style;
  40. Rebox box;
  41. memset(&style, 0, sizeof(style));
  42. style.text.font = font;
  43. style.text.color = color_rgb(255,255,255);
  44. style.back.color = color_rgba(64,0,0, 191);
  45. if ( !ZORI_ID_OK_P(zori_start(&style)) ) {
  46. LOG_ERROR( "Out of memory when allocating GUI.");
  47. return;
  48. }
  49. if (zori_start(&style) != ZORI_ID_OK) {
  50. LOG_ERROR( "Cannot set up ZORI UI screen.");
  51. return;
  52. }
  53. ui->screen = zori_new_screen(-1, display);
  54. if (!ZORI_ID_OK_P(ui->screen)) {
  55. LOG_ERROR( "Cannot set up main screen.");
  56. return;
  57. }
  58. ui->main.page = zori_new_page(-1, ui->screen);
  59. LOG_NOTE("Main page: %d\n", ui->main.page);
  60. box = rebox_make(280, 80, 140, 240);
  61. ui->main.menu = zori_new_menu(-1, ui->main.page, &box);
  62. LOG_NOTE("Main menu: %d\n", ui->main.menu);
  63. {
  64. Rebox box = rebox_make(300, 100, 100, 60);
  65. ui->main.button.resume = zori_new_button(-1, ui->main.menu, &box, "Continue");
  66. LOG_NOTE("Button: %d\n", ui->main.button.resume);
  67. }
  68. {
  69. Rebox box = rebox_make(300, 200, 100, 60);
  70. ui->main.button.new = zori_new_button(-1, ui->main.menu, &box, "New");
  71. LOG_NOTE("Button: %d\n", ui->main.button.new);
  72. }
  73. }
  74. void ui_handle_main_menu(struct ui_state * ui, int selected) {
  75. LOG_NOTE("Main menu selected: %d\n", selected);
  76. }
  77. void ui_state_update(struct ui_state * ui,
  78. zori_display * display, zori_font * font) {
  79. int value = 0;
  80. if ((value = zori_result(ui->main.menu))) {
  81. ui_handle_main_menu(ui, value);
  82. }
  83. }
  84. #ifdef COMMENT_
  85. /* Direct mode operation? */
  86. INTRO_TEXT2 =
  87. def make_sub_menu(parent, x, y, w, h, bh)
  88. sub_menu = parent.make_menu(x, y, w, h, nil)
  89. sub_menu.make_button(x, y + 20, w - 20, bh, "Sub choice 1") do
  90. puts "choice 1"
  91. end
  92. sub_menu.make_button(x, y + 30 + bh, w - 20, bh, "Sub choice 2") do
  93. puts "choice 2"
  94. end
  95. sub_menu.make_button(x, y + 40 + 2* bh, w - 20, bh, "Sub choice 3") do
  96. puts "choice 3"
  97. end
  98. sub_menu.fit_children
  99. sub_menu.hide
  100. return sub_menu
  101. end
  102. def do_main_menu
  103. main_music = Music.load(:main, '/music/nethis-the_writer.ogg')
  104. $lote = nil
  105. $lobe = nil
  106. if PLAY_MUSIC
  107. res = main_music.play!
  108. end
  109. # res = nil
  110. # $main_menu = MainMenu.new
  111. # $main_menu.active = true
  112. Zori.make_page(:default) do |m|
  113. State.talk_box = m.make_longtext(10, 310, 620, 160, "Testing 1 2 3")
  114. State.talk_box.graph.each { |g| g.font = Eruta::Zori.font.id }
  115. State.talk_box.delay = 0.1
  116. State.talk_box.page_lines = 5
  117. State.talk_box.page = 0
  118. State.talk_box.hide
  119. end
  120. Zori.make_page(:main_menu) do |m|
  121. if MAIN_BACKGROUND
  122. main_back = Bitmap.load(:main_back,
  123. '/image/background/eruta_mainmenu.png')
  124. p main_back, main_back.width, main_back.height, main_back.name, main_back.id
  125. main_back = Bitmap.load(:main_back,
  126. '/image/background/eruta_mainmenu.png')
  127. p main_back, main_back.width, main_back.height, main_back.name, main_back.id
  128. p Bitmap[:main_back]
  129. p Store[:bitmap_main_back]
  130. m.graph_image(0, 0, main_back.id)
  131. end
  132. main_menu = m.make_menu(250, 190, 120, 440, nil)
  133. ma = main_menu
  134. main_button_1 = ma.make_button(260, 200, 100, 30, "Continue")
  135. sub_menu = make_sub_menu(main_button_1, 50, 190, 120, 440, 30)
  136. sub_menu.hide
  137. main_button_2 = ma.make_button(260, 240, 100, 30, "New") do
  138. do_start_test_map
  139. Zori.go(:default)
  140. end
  141. main_button_3 = ma.make_button(260, 280, 100, 30, "Settings") do
  142. Zori.go(:settings)
  143. end
  144. main_button_4 = ma.make_button(260, 320, 100, 30, "Instructions")
  145. main_button_5 = ma.make_button(260, 360, 100, 30, "µ£éè")
  146. main_button_5 << sub_menu
  147. main_button_5= ma.make_button(260, 400, 100, 30, "Quit") do
  148. Eruta.quit
  149. end
  150. main_menu.fit_children
  151. end
  152. Zori.make_page(:settings) do |se|
  153. lote2 = se.make_longtext(100, 10, 160, 100, INTRO_TEXT)
  154. lote2.delay = 1
  155. lote2.page = 0
  156. lote2.page_lines = 3
  157. # $lote2.line_stop = 999990
  158. settings_menu = se.make_menu(480, 380, 120, 440, nil)
  159. sm = settings_menu
  160. settings_ok_button = sm.make_button(500, 300, 100, 30, "Font 1") do
  161. if lote2
  162. lote2.graph.each { |g| g.font = 0 }
  163. end
  164. end
  165. settings_ok_button = sm.make_button(500, 350, 100, 30, "Font 2") do
  166. if lote2
  167. lote2.graph.each { |g| g.font = Eruta::Zori.font.id }
  168. end
  169. lote2.text = INTRO_TEXT2
  170. end
  171. settings_ok_button = sm.make_button(500, 400, 100, 30, "OK") do
  172. Zori.go(:main_menu)
  173. if lote
  174. lote.close
  175. lote = nil
  176. end
  177. end
  178. sm.fit_children
  179. end
  180. Zori[:main_menu].hide
  181. Zori[:settings].hide
  182. Zori.go(:main_menu)
  183. end
  184. #endif