Guest User

Hirion Engine - Main Menu

a guest
Mar 18th, 2015
217
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #==============================================================================
  2. # Hirion Engine - Main Menu
  3. # Author: Nicke
  4. # Created: 22/10/2013
  5. # Edited: 10/11/2013
  6. # Version: 1.0b
  7. #==============================================================================
  8. # Instructions
  9. # -----------------------------------------------------------------------------
  10. # To install this script, open up your script editor and copy/paste this script
  11. # to an open slot below ▼ Materials but above ▼ Main. Remember to save.
  12. #==============================================================================
  13. # Required scripts (Added above this script):
  14. # Hirion Engine - Core
  15. # Hirion Engine - Settings
  16. #==============================================================================
  17. #
  18. # This script changes the visual of menu scene as well as adding new features
  19. # to it. Don't use this script with any XS - Menu versions.
  20. #
  21. # To setup use the instructions module which needs to be located above this
  22. # script. Make sure you read through everything to understand each section.
  23. #
  24. # *** Only for RPG Maker VX Ace. ***
  25. #==============================================================================
  26. ($imported ||= {})["HIRION-ENGINE-MAIN-MENU"] = true
  27. # // Check if required scripts are imported properly.
  28. ERROR.imported?("HIRION-ENGINE-CORE", "Hirion Engine - Main Menu")
  29. # *** Don't edit below unless you know what you are doing. ***
  30. #==============================================================================#
  31. # ** Game_System
  32. #==============================================================================#
  33. class Game_System
  34.  
  35. attr_accessor :menu_list
  36.  
  37. alias hirion_main_menu_gm_sys_initialize initialize
  38. def initialize(*args, &block)
  39. # // Method to initialize game system.
  40. hirion_main_menu_gm_sys_initialize(*args, &block)
  41. @menu_list = {}
  42. end
  43.  
  44. def get_menu
  45. # // Method to get the menu list.
  46. HIRION::SETTINGS::MENU_CUSTOM ? @menu_list : HIRION::SETTINGS::MENU_LIST
  47. end
  48.  
  49. end
  50. #==============================================================================#
  51. # ** Game_Interpreter
  52. #==============================================================================#
  53. class Game_Interpreter
  54.  
  55. def menu_custom?
  56. # // Check if menu custom is enabled or else raise error.
  57. raise ("Menu custom is disabled! Don't use any menu scene methods.") unless HIRION::SETTINGS::MENU_CUSTOM
  58. end
  59.  
  60. def menu_scene(key, type = :add)
  61. # // Method to add/remove a menu item to the list.
  62. menu_custom?
  63. list = HIRION::SETTINGS::MENU_LIST
  64. valid = "The key: \"#{key}\" doesn't exists in the menu list! Please use a valid one.\nValid keys: #{list.keys}"
  65. included = "The key: \"#{key}\" already exists in the menu list!\nPlease add another one."
  66. case type
  67. when :add
  68. return raise(valid) if list[key].nil?
  69. return raise(included) if $game_system.menu_list.has_key?(key)
  70. $game_system.menu_list[key] = list[key]
  71. when :del
  72. raise(valid) if list[key].nil?
  73. $game_system.menu_list.delete(key)
  74. end
  75. end
  76.  
  77. def menu_active(key, enabled)
  78. # // Method to enable id.
  79. menu_custom?
  80. $game_system.menu_list[key][3] = enabled
  81. end
  82.  
  83. def menu_active?(key)
  84. # // Method to check if menu key is enabled.
  85. menu_custom?
  86. return $game_system.menu_list[key][3] rescue false
  87. end
  88.  
  89. def menu_add_all
  90. # // Method to add all available menu items.
  91. HIRION::SETTINGS::MENU_LIST.each_key {|key| menu_scene(key) }
  92. end
  93.  
  94. def menu_del_all
  95. # // Method to remove all available menu items.
  96. HIRION::SETTINGS::MENU_LIST.each_key {|key| menu_scene(key, :del) }
  97. end
  98.  
  99. end
  100. #==============================================================================
  101. # ** Window_MenuCommand
  102. #==============================================================================
  103. class Window_MenuCommand < Window_Command
  104.  
  105. def window_width
  106. # // Method to determine the width of the window.
  107. return 200
  108. end
  109.  
  110. def window_height
  111. # // Method to determine the height of the window.
  112. return @list.size * item_height + standard_padding * 2
  113. end
  114.  
  115. def item_height
  116. # // Method to set item height.
  117. return 32
  118. end
  119.  
  120. def draw_item(index)
  121. # // Method to draw item.
  122. font = HIRION::SETTINGS::MENU_FONT
  123. rect = item_rect(index)
  124. item = HIRION::SETTINGS::MENU_LIST[@list[index][:symbol]]
  125. enabled = command_enabled?(index)
  126. color = font[2]
  127. color.alpha = enabled ? 255 : 128
  128. # // Draw text.
  129. draw_str(command_name(index).upcase, rect.x + 26, rect.y + 6, rect.width, 0, font[0], font[1], color, font[3], font[4], font[5], font[6])
  130. # // Draw icons.
  131. draw_icon(item[2], rect.x + 2, rect.y + 4, true)
  132. end
  133.  
  134. def make_command_list
  135. # // Method to add the commands.
  136. $game_system.get_menu.each {|key, value|
  137. name = value[0] == "" ? key.id2name.capitalize : value[0]
  138. HIRION::SETTINGS::MENU_LIST[:save][3] = save_enabled if HIRION::SETTINGS::MENU_SAVE
  139. add_command(name, key, value[3], value[5].nil? ? nil : value[5])
  140. }
  141. end
  142.  
  143. end
  144. #==============================================================================
  145. # ** Window_Menu_Details
  146. #==============================================================================
  147. class Window_Menu_Details < Window_Base
  148.  
  149. def initialize(x, y)
  150. # // Method to initialize.
  151. super(x, y, Graphics.width, fitting_height(1))
  152. @playtime = $game_system.playtime_s
  153. refresh
  154. end
  155.  
  156. def refresh
  157. # // Method to refresh the window.
  158. contents.clear
  159. # // Draw map.
  160. font = HIRION::SETTINGS::MENU_FONT_DETAILS
  161. icon = HIRION::SETTINGS::MENU_DETAIL_ICONS
  162. draw_icon(icon[0], 0, 0)
  163. draw_str($data_mapinfos[$game_map.map_id].name, 26, 2, contents_width, 0, font[0], font[1], font[2], font[3], font[4], font[5], font[6])
  164. # // Draw gold.
  165. gold = "#{sprintf("%07d", $game_party.gold)}#{Vocab::currency_unit}"
  166. draw_icon(icon[1], (contents_width / 2) + 36, 0)
  167. draw_str(gold, -148, 2, contents_width, 2, font[0], font[1], font[2], font[3], font[4], font[5], font[6])
  168. # // Draw playtime.
  169. draw_icon(icon[2], contents_width - 90, 0)
  170. draw_str(@playtime, 0, 2, contents_width, 2, font[0], font[1], font[2], font[3], font[4], font[5], font[6])
  171. end
  172.  
  173. def update
  174. # // Method to update the window.
  175. super
  176. @playtime = $game_system.playtime_s
  177. refresh
  178. end
  179.  
  180. end
  181. #==============================================================================
  182. # ** Window_MenuStatus
  183. #==============================================================================
  184. class Window_MenuStatus < Window_Selectable
  185.  
  186. def initialize(x, y)
  187. # // Method to initialize the window.
  188. super(x, y, window_width, window_height)
  189. self.arrows_visible = false
  190. @pending_index = -1
  191. refresh
  192. end
  193.  
  194. def window_width
  195. # // Method to determine window width.
  196. return (Graphics.width == 640 ? col_max : col_max) * item_width + standard_padding * 2
  197. end
  198.  
  199. def window_height
  200. # // Method to determine window height.
  201. return 244
  202. end
  203.  
  204. def col_max
  205. # // Method to determine col max.
  206. col = HIRION::SETTINGS::MENU_ACTORS
  207. return Graphics.width == 640 ? col[0] : col[1]
  208. end
  209.  
  210. def spacing
  211. # // Method to determine spacing.
  212. return 0
  213. end
  214.  
  215. def item_width
  216. # // Method to determine item width.
  217. return 80
  218. end
  219.  
  220. def item_height
  221. # // Method to determine item height. <EDITING>
  222. return 200
  223. end
  224.  
  225. def draw_item(index)
  226. # // Method to draw item.
  227. actor = $game_party.members[index]
  228. rect = item_rect(index)
  229. actor_font_name = HIRION::SETTINGS::MENU_ACTOR_NAME
  230. actor_font_lvl = HIRION::SETTINGS::MENU_ACTOR_LVL
  231. actor_font_stats = HIRION::SETTINGS::MENU_ACTOR_STATS
  232. # // Draw rect.
  233. draw_rect(rect.x, rect.y, rect.width, 39, Color.new(0,0,0,64), Color.new(0,0,0,64))
  234. # // Draw side lines.
  235. draw_shadow_line(rect.x - 11, rect.y, Color.new(255,255,255), Color.new(0,0,0,64), 1, contents_height, :v)
  236. draw_shadow_line(contents_width - 12, 0, Color.new(255,255,255), Color.new(0,0,0,64), 1, contents_height, :v)
  237. # // Draw top line.
  238. draw_shadow_line(rect.x, rect.y - 11, Color.new(255,255,255), Color.new(0,0,0,64), contents_width, 1)
  239. # // Draw name.
  240. draw_str(actor.name, rect.x, rect.y, rect.width, 1, actor_font_name[0], actor_font_name[1], actor_font_name[2], actor_font_name[3], actor_font_name[4], actor_font_name[5], actor_font_name[6])
  241. # // Draw class.
  242. # draw_str(actor.class.name, rect.x + 8, rect.y + 18, rect.width, 0, actor_font_name[0], actor_font_name[1], actor_font_name[2], actor_font_name[3], actor_font_name[4], actor_font_name[5], actor_font_name[6])
  243. # // Draw face.
  244. draw_actor_face(actor, rect.x + 2, rect.y + (rect.height - 98))
  245. # // Draw level.
  246. lvl = "#{Vocab::level_a} #{actor.level}"
  247. draw_str(lvl, rect.x + 4, rect.y + (rect.height - 22), rect.width, 0, actor_font_lvl[0], actor_font_lvl[1], actor_font_lvl[2], actor_font_lvl[3], actor_font_lvl[4], actor_font_lvl[5], actor_font_lvl[6])
  248. # // Draw bottom line.
  249. draw_shadow_line(rect.x, rect.y + (rect.height - 13), Color.new(255,255,255), Color.new(0,0,0,64), contents_width, 1)
  250. # // Draw stats.
  251. Vocab.create(:exp_a, "EXP")
  252. stats_height = 30
  253. draw_actor_stats(actor, :hp, rect.x + 2, rect.y + stats_height, 0, 18, HIRION::SETTINGS::MENU_BAR_HP[0], HIRION::SETTINGS::MENU_BAR_HP[1], rect.width - 3, stats_height, Vocab.hp_a, 6, rect.y + 6, actor_font_stats)
  254. draw_actor_stats(actor, :mp, rect.x + 2, rect.y + stats_height * 2, 0, 18, HIRION::SETTINGS::MENU_BAR_MP[0], HIRION::SETTINGS::MENU_BAR_MP[1], rect.width - 3, stats_height, Vocab.mp_a, 6, rect.y + 6, actor_font_stats)
  255. # draw_actor_stats(actor, :exp, rect.x + 2, rect.y + stats_height * 3, 0, 18, HIRION::SETTINGS::MENU_BAR_EXP[0], HIRION::SETTINGS::MENU_BAR_EXP[1], rect.width - 3, stats_height, Vocab.exp_a, 6, rect.y + 6, actor_font_stats)
  256. end
  257.  
  258. end
  259. #==============================================================================#
  260. # ** Window_Menu_Help
  261. #==============================================================================#
  262. class Window_Menu_Help < Window_Help
  263.  
  264. def refresh
  265. # // Refresh help contents.
  266. contents.clear
  267. font = HIRION::SETTINGS::MENU_HELP_FONT
  268. draw_str(@text, 0, 0, contents_width, 0, font[0], font[1], font[2], font[3], font[4], font[5], font[6])
  269. end
  270.  
  271. end
  272. #==============================================================================#
  273. # ** Window_Menu_Character_Options
  274. #==============================================================================#
  275. class Window_Menu_Character_Options < Window_HorzCommand
  276.  
  277. def initialize(x, y, width)
  278. # // Method to initialize the window.
  279. @window_width = width
  280. super(x, y)
  281. end
  282.  
  283. def window_width
  284. # // Method to determine the width of the window.
  285. return @window_width
  286. end
  287.  
  288. def update_open
  289. # // Method override to update window opening.
  290. self.openness += 15
  291. self.opacity = self.openness unless self.opacity == 0
  292. self.back_opacity = self.openness unless self.opacity == 0
  293. @opening = false if open?
  294. end
  295.  
  296. def update_close
  297. # // Method override to update window closing.
  298. self.openness -= 15
  299. self.opacity = self.openness unless self.opacity == 0
  300. self.back_opacity = self.openness unless self.opacity == 0
  301. @closing = false if close?
  302. end
  303.  
  304. def col_max
  305. # // Method to determine col max.
  306. return 3
  307. end
  308.  
  309. def alignment
  310. # // Method to return the alignment.
  311. return 1
  312. end
  313.  
  314. def draw_item(index)
  315. # // Method to draw item.
  316. font = HIRION::SETTINGS::MENU_FONT_CHAR_OPTIONS
  317. rect = item_rect(index)
  318. enabled = command_enabled?(index)
  319. color = font[2]
  320. color.alpha = enabled ? 255 : 128
  321. draw_str(command_name(index), rect.x, rect.y, rect.width, 1, font[0], font[1], color, font[3], font[4], font[5], font[6])
  322. end
  323.  
  324. def make_command_list
  325. # // Method to add the commands.
  326. add_command("Check Status", :status)
  327. add_command("Manage Skills", :skill)
  328. add_command("Change Equipment", :equip)
  329. end
  330.  
  331. end
  332. #==============================================================================#
  333. # ** Scene_MenuBase
  334. #==============================================================================#
  335. class Scene_MenuBase < Scene_Base
  336.  
  337. @@last_scene = nil
  338.  
  339. def start
  340. # // Method to start the scene.
  341. super
  342. @actor = $game_party.menu_actor
  343. # // Check if current scene is Scene_Menu and create backgrounds.
  344. if SceneManager.scene_is?(Scene_Menu)
  345. @backgrounds = []
  346. create_menu_backgrounds
  347. end
  348. # // Store last played music bgm & bgs.
  349. @bgm = HIRION::SETTINGS::MENU_MUSIC_BGM
  350. @bgs = HIRION::SETTINGS::MENU_MUSIC_BGS
  351. @last_bgm = RPG::BGM.last if @last_bgm.nil?
  352. @last_bgs = RPG::BGS.last if @last_bgs.nil?
  353. # // Play music if enabled.
  354. play_menu_music
  355. end
  356.  
  357. def create_background
  358. # // Mehod to create background.
  359. @background_sprite = Sprite.new
  360. @background_sprite.bitmap = SceneManager.background_bitmap
  361. @background_sprite.color.set(0, 0, 0, 192)
  362. end
  363.  
  364. def create_menu_backgrounds
  365. # // Method to create custom background(s).
  366. HIRION::SETTINGS::MENU_BACKGROUND.each {|key, value| @backgrounds << [Sprite.new, key] }
  367. @backgrounds.each {|i|
  368. i[0].bitmap = Cache.system(i[1])
  369. i[0].x = HIRION::SETTINGS::MENU_BACKGROUND[i[1]][0]
  370. i[0].y = HIRION::SETTINGS::MENU_BACKGROUND[i[1]][1]
  371. i[0].z = HIRION::SETTINGS::MENU_BACKGROUND[i[1]][2]
  372. i[0].opacity = HIRION::SETTINGS::MENU_BACKGROUND[i[1]][3]
  373. }
  374. end
  375.  
  376. def play_menu_music
  377. # // Method to play menu music.
  378. if @bgm != RPG::BGM.last.name
  379. Sound.play(@bgm[0], @bgm[1], @bgm[2], :bgm) unless @bgm.nil?
  380. Sound.play(@bgs[0], @bgs[1], @bgs[2], :bgs) unless @bgs.nil?
  381. end
  382. end
  383.  
  384. alias hirion_menubase_transition perform_transition
  385. def perform_transition(*args, &block)
  386. # // Method to create the transition.
  387. return if $game_system.get_menu.empty?
  388. if HIRION::SETTINGS::MENU_TRANSITION.nil?
  389. hirion_menubase_transition(*args, &block)
  390. else
  391. Graphics.transition(HIRION::SETTINGS::MENU_TRANSITION[0],HIRION::SETTINGS::MENU_TRANSITION[1],HIRION::SETTINGS::MENU_TRANSITION[2])
  392. end
  393. end
  394.  
  395. def dispose_sprites
  396. # // Method to dispose sprites.
  397. @backgrounds.each {|i| i[0].dispose unless i[0].nil? ; i[0] = nil } rescue nil
  398. end
  399.  
  400. def pre_terminate
  401. # // Method to pre terminate scene menu.
  402. # // Play last bgm and bgs if menu music is enabled.
  403. if SceneManager.scene_is?(Scene_Map)
  404. @last_bgm.replay rescue nil
  405. @last_bgs.replay rescue nil
  406. end
  407. end
  408.  
  409. def terminate
  410. # // Method to terminate.
  411. super
  412. dispose_sprites unless SceneManager.scene_is?(Scene_Menu)
  413. end
  414.  
  415. def return_scene
  416. # // Method to return scene.
  417. @@last_scene = SceneManager.scene.class
  418. super
  419. end
  420.  
  421. end
  422. #==============================================================================#
  423. # ** Scene_Menu
  424. #==============================================================================#
  425. class Scene_Menu < Scene_MenuBase
  426.  
  427. def start
  428. # // Method to start the scene.
  429. # // Raise error if menu list is empty.
  430. super
  431. if $game_system.get_menu.empty? and HIRION::SETTINGS::MENU_CUSTOM
  432. raise("Menu custom is set to true and the system couldn't find any commands added to the menu scene!\nPlease add one or use the menu_add_all code before calling the scene.")
  433. exit
  434. end
  435. # // Setup particles.
  436. @particles = []
  437. @particles_timer = 0
  438. @particles_x = 0.1 + rand(1.0)
  439. @particles_y = 0.5 + rand(1.0)
  440. @particles_ox = 0.1 + rand(1.0)
  441. @particles_oy = 0.5 + rand(1.0)
  442. # // Create windows.
  443. create_menu_command_window
  444. create_menu_details_window
  445. create_menu_actor_window
  446. create_menu_help_window
  447. create_menu_particles
  448. # // Remember the last scene called when using the character window.
  449. # // Needed for reactivating the status window when returning to the scene.
  450. scenes = [Scene_Status, Scene_Skill, Scene_Equip]
  451. if @@last_scene && scenes.include?(@@last_scene)
  452. @@last_scene = nil
  453. @command_window.deactivate
  454. command_personal
  455. end
  456. end
  457.  
  458. def create_menu_particles
  459. # // Method to create the command window.
  460. HIRION::SETTINGS::MENU_PARTICLES.each {|k, v|
  461. x = v[0] == :random ? HIRION::SETTINGS.random_particle_movement(:width) : v[0]
  462. y = v[1] == :random ? HIRION::SETTINGS.random_particle_movement(:height) : v[1]
  463. @particles << Sprite_Particle.new(k, x, y, v[2], v[3], v[4], v[5])
  464. }
  465. end
  466.  
  467. def create_menu_command_window
  468. # // Method to create the command window.
  469. @command_window = Window_MenuCommand.new
  470. @command_window.opacity = 0
  471. @command_window.center(:y)
  472. $game_system.get_menu.each {|key, value|
  473. unless value[5].nil?
  474. @command_window.set_handler(key, method(:command_custom))
  475. else
  476. personal = value[4] == true ? :command_personal : "command_#{key}".to_sym
  477. @command_window.set_handler(key, method(personal))
  478. end
  479. }
  480. @command_window.set_handler(:cancel, method(:return_scene))
  481. end
  482.  
  483. def create_menu_details_window
  484. # // Method to create the details window.
  485. @details_window = Window_Menu_Details.new(0, 0)
  486. @details_window.x = 0
  487. @details_window.y = (Graphics.height - @details_window.height) + 8
  488. @details_window.opacity = 0
  489. end
  490.  
  491. def create_menu_actor_window
  492. # // Method to create the actor window.
  493. @status_window = Window_MenuStatus.new(0, 0)
  494. @status_window.x = (Graphics.width - @status_window.width) / 1.1
  495. @status_window.center(:y)
  496. @status_window.back_opacity = 200
  497. end
  498.  
  499. def create_menu_help_window
  500. # // Method to create help window.
  501. @help_window = Window_Menu_Help.new(1)
  502. @help_window.viewport = @viewport
  503. @help_window.opacity = 0
  504. @help_window.set_text(create_menu_help_text)
  505. end
  506.  
  507. def create_menu_help_text
  508. # // Method to create help inn text.
  509. str = HIRION::SETTINGS::MENU_LIST[@command_window.current_symbol]
  510. name = str[0] == "" ? @command_window.current_symbol.id2name.capitalize : str[0]
  511. return "#{name} - #{str[1]}"
  512. end
  513.  
  514. def create_menu_character_window
  515. # // Method to create character window.
  516. width = Graphics.width == 640 ? @status_window.width : @status_window.width + 66
  517. x = @status_window.x - (Graphics.width == 640 ? 0 : 66 * 0.75)
  518. @character_window = Window_Menu_Character_Options.new(0, 0, width)
  519. @character_window.x = x
  520. @character_window.y = @status_window.height + @status_window.y
  521. @character_window.z = 200
  522. @character_window.back_opacity = 255
  523. @character_window.openness = 0
  524. @character_window.open
  525. @character_window.set_handler(:ok, method(:on_character_ok))
  526. @character_window.set_handler(:cancel, method(:on_character_cancel))
  527. end
  528.  
  529. def update
  530. # // Method for updating the scene.
  531. super
  532. # // Remeber last symbol and renew it if changed.
  533. if @last_symbol != @command_window.current_symbol
  534. # // Update help window.
  535. @help_window.set_text(create_menu_help_text)
  536. @last_symbol = @command_window.current_symbol
  537. end
  538. # // Create and animate the particles:
  539. unless HIRION::SETTINGS::MENU_PARTICLES_DELAY.nil?
  540. @particles_timer += 1
  541. if @particles_timer >= HIRION::SETTINGS::MENU_PARTICLES_DELAY
  542. create_menu_particles
  543. @particles_timer = 0
  544. end
  545. else
  546. create_menu_particles
  547. end
  548. @particles.each { |i|
  549. i.update
  550. unless i.done
  551. i.x += @particles_x
  552. i.y -= @particles_y
  553. i.ox += @particles_ox
  554. i.oy += @particles_oy
  555. else
  556. @particles.delete(i)
  557. end
  558. }
  559. if @status_window.active
  560. @status_window.arrows_visible = $game_party.all_members.size >= 5
  561. else
  562. @status_window.arrows_visible = false
  563. end
  564. end
  565.  
  566. def call_scene(window)
  567. # // Method to call scene.
  568. scene = "Scene_#{window.current_symbol.to_s.capitalize}".to_class
  569. SceneManager.call(scene)
  570. end
  571.  
  572. def on_character_ok
  573. # // Method when selecting ok on character window.
  574. call_scene(@character_window)
  575. end
  576.  
  577. def on_character_cancel
  578. # // Method when selecting cancel on character window.
  579. @character_window.close
  580. command_personal
  581. end
  582.  
  583. def on_personal_ok
  584. # // Method override on personal ok.
  585. return command_character if @command_window.current_symbol == :character
  586. call_scene(@command_window)
  587. end
  588.  
  589. def command_character
  590. # // Method to call character window.
  591. create_menu_character_window
  592. end
  593.  
  594. def command_custom
  595. # // Method to call a custom command. (Don't remove)
  596. if @command_window.current_ext.is_a?(Integer)
  597. $game_temp.reserve_common_event(@command_window.current_ext)
  598. return SceneManager.call(Scene_Map)
  599. end
  600. SceneManager.call(@command_window.current_ext)
  601. end
  602.  
  603. def terminate
  604. # // Method to terminate the scene.
  605. SceneManager.snapshot_for_background
  606. super
  607. @character_window.dispose unless @character_window.nil?
  608. @character_window = nil
  609. @particles.each { |i| i.dispose unless i.nil? ; i = nil }
  610. @particles.clear
  611. @particles = nil
  612. end
  613.  
  614. end
RAW Paste Data