dsiver144

Dark's Super Simple Menu

May 28th, 2016
551
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.72 KB | None | 0 0
  1. #===============================================================================
  2. # Name: Dark's Super Simple Menu
  3. # Author: Nhat Nguyen (Dark Sky)
  4. # Released on: May 28th 2016
  5. #-------------------------------------------------------------------------------
  6. # Version 1.0: Released!
  7. #-------------------------------------------------------------------------------
  8. # Plug and play!
  9. #===============================================================================
  10. module DarkCreation
  11. module SuperSimpleMenu
  12. WINDOW_X = 140
  13. WINDOW_y = 155
  14. BACKGROUND_OPACITY = 130
  15. HELP_FONT = ["04b_19"]
  16. NON_COMBAT_STYLE = true
  17. COMMANDS = {
  18. :item => [261,"Items","Just for accessing Item Sceneeeeeeeeeeee"],
  19. :skill => [98,"Skills","DO SOME MAGIC!"],
  20. :equip => [170,"Equipment","Change clothes"],
  21. :status => [122,"Status","Check for current status"],
  22. :save => [236,"Save","Save current process"],
  23. :game_end => [121,"End","End this bullsh*t!"],
  24. }
  25. NON_COMBAT_STYLE_LIST = [:skill,:status]
  26. end
  27. end
  28. #==============================================================================
  29. # ** Window_MenuCommand
  30. #------------------------------------------------------------------------------
  31. # This command window appears on the menu screen.
  32. #==============================================================================
  33. include DarkCreation::SuperSimpleMenu
  34. class Window_MenuCommand < Window_Command
  35. attr_accessor :list
  36. attr_accessor :dhelp_window
  37. #--------------------------------------------------------------------------
  38. # * Object Initialization
  39. #--------------------------------------------------------------------------
  40. def initialize
  41. super(WINDOW_X, WINDOW_y)
  42. @dcontents.x = self.x
  43. @dcontents.y = self.y
  44. @dcontents2.x = 150 + (self.x - 100)
  45. @dcontents2.y = 105 + (self.y - 100)
  46. @dcontents.opacity = 0
  47. @dcontents2.opacity = 0
  48. self.opacity = 0
  49. self.back_opacity = 0
  50. select_last
  51. end
  52. #--------------------------------------------------------------------------
  53. # * Get Window Width
  54. #--------------------------------------------------------------------------
  55. def window_width
  56. return 48
  57. end
  58. #--------------------------------------------------------------------------
  59. # * Get Window Width
  60. #--------------------------------------------------------------------------
  61. alias :dark_dispose_window_menu_qwe :dispose
  62. def dispose
  63. dark_dispose_window_menu_qwe
  64. @dcontents.bitmap.dispose
  65. @dcontents.dispose
  66. @dcontents2.bitmap.dispose
  67. @dcontents2.dispose
  68. end
  69.  
  70. #--------------------------------------------------------------------------
  71. # * Draw Character Graphic
  72. #--------------------------------------------------------------------------
  73. def draw_character2(character_name, character_index, x, y)
  74. return unless character_name
  75. bitmap = Cache.character(character_name)
  76. sign = character_name[/^[\!\$]./]
  77. if sign && sign.include?('$')
  78. cw = bitmap.width / 3
  79. ch = bitmap.height / 4
  80. else
  81. cw = bitmap.width / 12
  82. ch = bitmap.height / 8
  83. end
  84. n = character_index
  85. src_rect = Rect.new((n%4*3+1)*cw, (n/4*4)*ch, cw, ch)
  86. @cw = cw
  87. @dcontents2.bitmap.blt(x - cw / 2, y - ch, bitmap, src_rect)
  88. end
  89.  
  90. def draw_actor_graphic2(actor, x, y)
  91. draw_character2(actor.character_name, actor.character_index, x, y)
  92. end
  93.  
  94. #--------------------------------------------------------------------------
  95. # * Draw Face Graphic
  96. # enabled : Enabled flag. When false, draw semi-transparently.
  97. #--------------------------------------------------------------------------
  98. def draw_face2(face_name, face_index, x, y, enabled = true)
  99. bitmap = Cache.face(face_name)
  100. rect = Rect.new(face_index % 4 * 96, face_index / 4 * 96, 96, 96)
  101. @dcontents2.bitmap.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
  102. bitmap.dispose
  103. end
  104. #--------------------------------------------------------------------------
  105. # * Draw Actor Face Graphic
  106. #--------------------------------------------------------------------------
  107. def draw_actor_face2(actor, x, y, enabled = true)
  108. draw_face2(actor.face_name, actor.face_index, x, y, enabled)
  109. end
  110. #--------------------------------------------------------------------------
  111. # * Refresh
  112. #--------------------------------------------------------------------------
  113. def refresh
  114.  
  115. contents.clear
  116. @dcontents ||= Sprite.new
  117. @dcontents.bitmap ||= Bitmap.new(self.width - 5,self.height - 5)
  118. @dcontents.bitmap.clear
  119. @dcontents.bitmap.fill_rect(5,5,self.width,self.height,Color.new(0,0,0,BACKGROUND_OPACITY)) #contents.fill_rect(0,0,contents.width,contents.height,Color.new(0,0,0,170))
  120.  
  121. @dcontents2 ||= Sprite.new
  122. @dcontents2.bitmap ||= Bitmap.new(233,108)#self.width - 5,self.height - 5)
  123. @dcontents2.bitmap.clear
  124. @dcontents2.bitmap.font.name = HELP_FONT
  125. @dcontents2.bitmap.fill_rect(0,0,233,108,Color.new(0,0,0,BACKGROUND_OPACITY))
  126. draw_actor_graphic2($game_party.members[0],20,43)
  127. x = @dcontents2.width - 96
  128. draw_actor_face2($game_party.members[0],x,7)
  129. @actor_info = "#{$game_party.members[0].name}"# | #{$game_party.members[0].class.name}"
  130. @dcontents2.bitmap.font.size -= 6
  131. @dcontents2.bitmap.draw_text(@cw + 10,5,233,24,@actor_info)
  132. @dcontents2.bitmap.font.color = Color.new(253,155,51)
  133. @dcontents2.bitmap.draw_text(@cw + 10,5+24,233,24,"#{$game_party.members[0].class.name}")
  134. @dcontents2.bitmap.font.color = Color.new(255,255,255)
  135. @dcontents2.bitmap.draw_text(5,5+24+24,233,24,"Gold: #{$game_party.gold}G")
  136. @dcontents2.bitmap.draw_text(5,5+24*3,233,24,"Place: #{$game_map.display_name}")
  137. draw_all_items
  138. end
  139. #--------------------------------------------------------------------------
  140. # * Create Command List
  141. #--------------------------------------------------------------------------
  142. def make_command_list
  143. add_main_commands
  144. end
  145. #--------------------------------------------------------------------------
  146. # * Add Main Commands to List
  147. #--------------------------------------------------------------------------
  148. def add_main_commands
  149. COMMANDS.each_key do |key|
  150. next if NON_COMBAT_STYLE_LIST.include?(key) && NON_COMBAT_STYLE
  151. add_command(COMMANDS[key][1], key, main_commands_enabled)
  152. end
  153. end
  154. #--------------------------------------------------------------------------
  155. # * Draw Item
  156. #--------------------------------------------------------------------------
  157. def draw_item(index)
  158. change_color(normal_color, command_enabled?(index))
  159. rect = item_rect_for_text(index)
  160. rect.x = 0
  161. draw_icon(COMMANDS[@list[index][:symbol]][0],rect.x,rect.y)
  162. end
  163. #--------------------------------------------------------------------------
  164. # * Process cursor move
  165. #--------------------------------------------------------------------------
  166. alias dark_menucommand_process_cursor_move_213 process_cursor_move
  167. def process_cursor_move
  168. dark_menucommand_process_cursor_move_213
  169. @dhelp_window.refresh(true)
  170. end
  171. #--------------------------------------------------------------------------
  172. # * Update
  173. #--------------------------------------------------------------------------
  174. alias dark_menucommand_update_213 update
  175. def update
  176. dark_menucommand_update_213
  177. if @dcontents.opacity < 255
  178. @dcontents.opacity += 10
  179. @dcontents2.opacity += 10
  180. end
  181. if @dhelp_window
  182. @dhelp_window.refresh
  183. end
  184. end
  185. end
  186.  
  187. include DarkCreation::SuperSimpleMenu
  188. class Window_HelpScroll < Window_Base
  189. attr_accessor :target
  190. attr_accessor :index
  191. def initialize(x,y,width,height)
  192. super(x,y,width,height)
  193. self.opacity = 0
  194. self.back_opacity = 0
  195. @scroll_pos = 0
  196. @opacity = 0
  197. end
  198. def target=(tar)
  199. if tar.is_a?(Window)
  200. @target = tar
  201. create_assets
  202. refresh
  203. end
  204. end
  205. def dispose
  206. super
  207. @dcontents.bitmap.dispose
  208. @dcontents.dispose
  209. @d_scroll.bitmap.dispose
  210. @d_scroll.dispose
  211. end
  212. def cal_text_width(text)
  213. size = 0
  214. for i in 0...text.size
  215. size += text_size(text[i]).width
  216. end
  217. return size
  218. end
  219. def create_assets
  220. @dcontents = Sprite.new
  221. @dcontents.bitmap = Bitmap.new(self.width - 5,self.height - 5)
  222. @dcontents.bitmap.clear
  223. @dcontents.bitmap.fill_rect(5,5,self.width,self.height,Color.new(0,0,0,BACKGROUND_OPACITY - 20))
  224. @d_scroll = Sprite.new
  225. @d_scroll.bitmap ||= Bitmap.new(544,416)
  226. @dcontents.bitmap.fill_rect(8,@dcontents.bitmap.height - 30,self.width - 16,26,Color.new(0,0,0,BACKGROUND_OPACITY + 30))
  227. @w_width = self.width - 16
  228. @w_height = 26
  229. @w_x = 8
  230. @w_y = @dcontents.bitmap.height - 30
  231. @viewport = Viewport.new(5,5,544,416)
  232. @viewport.z = 990
  233. @dcontents.viewport = @viewport
  234. @d_scroll.bitmap.clear
  235. @dcontents.x = self.x
  236. @dcontents.y = self.y
  237. @viewport1 = Viewport.new(self.x + 14,self.y+32,@w_width-1,@w_height)
  238. @viewport1.z = 999
  239. @dcontents.bitmap.font.name = HELP_FONT
  240. @d_scroll.bitmap.font.name = HELP_FONT
  241. @d_scroll.bitmap.font.size = 15
  242. @d_scroll.viewport = @viewport1
  243. @dcontents.opacity = @d_scroll.opacity = 0
  244. @index = -1
  245. end
  246. def refresh(reset=false)
  247. @d_scroll.bitmap.clear
  248. @dcontents.bitmap.clear
  249. @text = COMMANDS[@target.list[@target.index][:symbol]][2]
  250. if @dcontents.opacity < 255
  251. @dcontents.opacity += 5
  252. @d_scroll.opacity += 5
  253. end
  254. if @index != @target.index
  255. @scroll_pos = -@w_width+1
  256. @d_scroll.ox = @scroll_pos
  257. @index = @target.index
  258. else
  259. @dcontents.bitmap.fill_rect(5,5,self.width,self.height,Color.new(0,0,0,BACKGROUND_OPACITY - 20))
  260. @dcontents.bitmap.fill_rect(8,@dcontents.bitmap.height - 30,self.width - 16,26,Color.new(0,0,0,BACKGROUND_OPACITY + 30))
  261. @dcontents.bitmap.draw_text(8,-1,@dcontents.bitmap.width,24,COMMANDS[@target.list[@target.index][:symbol]][1])
  262. end
  263. @d_scroll.bitmap.draw_text(2,4,cal_text_width(@text),24,@text)
  264. @d_scroll.ox = @scroll_pos
  265. @scroll_pos += 1
  266. if @scroll_pos > cal_text_width(@text) - 10
  267. @scroll_pos = -@w_width+1
  268. end
  269. end
  270. end
  271.  
  272. #==============================================================================
  273. # ** Scene_Menu
  274. #------------------------------------------------------------------------------
  275. # This class performs the menu screen processing.
  276. #==============================================================================
  277.  
  278. class Scene_Menu < Scene_MenuBase
  279. #--------------------------------------------------------------------------
  280. # * Start Processing
  281. #--------------------------------------------------------------------------
  282. def start
  283. super
  284. create_command_window
  285. #create_gold_window
  286. #create_status_window
  287. end
  288. #--------------------------------------------------------------------------
  289. # * Create Command Window
  290. #--------------------------------------------------------------------------
  291. def create_command_window
  292. @command_window = Window_MenuCommand.new
  293. @scroll_help = Window_HelpScroll.new(@command_window.x - 4,@command_window.y,9*32,32*2)
  294. @scroll_help.y = @command_window.y - @scroll_help.height
  295. @scroll_help.target = @command_window
  296. @command_window.dhelp_window = @scroll_help
  297. @command_window.set_handler(:item, method(:command_item))
  298. @command_window.set_handler(:skill, method(:on_personal_ok))
  299. @command_window.set_handler(:equip, method(:on_personal_ok))
  300. @command_window.set_handler(:status, method(:on_personal_ok))
  301. #@command_window.set_handler(:formation, method(:command_formation))
  302. @command_window.set_handler(:save, method(:command_save))
  303. @command_window.set_handler(:game_end, method(:command_game_end))
  304. @command_window.set_handler(:cancel, method(:return_scene))
  305. end
  306. #--------------------------------------------------------------------------
  307. # * Create Gold Window
  308. #--------------------------------------------------------------------------
  309. def create_gold_window
  310. @gold_window = Window_Gold.new
  311. @gold_window.x = 0
  312. @gold_window.y = Graphics.height - @gold_window.height
  313. end
  314. #--------------------------------------------------------------------------
  315. # * Create Status Window
  316. #--------------------------------------------------------------------------
  317. def create_status_window
  318. @status_window = Window_MenuStatus.new(@command_window.width, 0)
  319. end
  320. #--------------------------------------------------------------------------
  321. # * [Item] Command
  322. #--------------------------------------------------------------------------
  323. def command_item
  324. SceneManager.call(Scene_Item)
  325. end
  326. #--------------------------------------------------------------------------
  327. # * [Skill], [Equipment] and [Status] Commands
  328. #--------------------------------------------------------------------------
  329. def command_personal
  330. @status_window.select_last
  331. @status_window.activate
  332. @status_window.set_handler(:ok, method(:on_personal_ok))
  333. @status_window.set_handler(:cancel, method(:on_personal_cancel))
  334. end
  335. #--------------------------------------------------------------------------
  336. # * [Formation] Command
  337. #--------------------------------------------------------------------------
  338. def command_formation
  339. @status_window.select_last
  340. @status_window.activate
  341. @status_window.set_handler(:ok, method(:on_formation_ok))
  342. @status_window.set_handler(:cancel, method(:on_formation_cancel))
  343. end
  344. #--------------------------------------------------------------------------
  345. # * [Save] Command
  346. #--------------------------------------------------------------------------
  347. def command_save
  348. SceneManager.call(Scene_Save)
  349. end
  350. #--------------------------------------------------------------------------
  351. # * [Exit Game] Command
  352. #--------------------------------------------------------------------------
  353. def command_game_end
  354. SceneManager.call(Scene_End)
  355. end
  356. #--------------------------------------------------------------------------
  357. # * [OK] Personal Command
  358. #--------------------------------------------------------------------------
  359. def on_personal_ok
  360. case @command_window.current_symbol
  361. when :skill
  362. SceneManager.call(Scene_Skill)
  363. when :equip
  364. SceneManager.call(Scene_Equip)
  365. when :status
  366. SceneManager.call(Scene_Status)
  367. end
  368. end
  369. #--------------------------------------------------------------------------
  370. # * [Cancel] Personal Command
  371. #--------------------------------------------------------------------------
  372. def on_personal_cancel
  373. @status_window.unselect
  374. @command_window.activate
  375. end
  376. #--------------------------------------------------------------------------
  377. # * Formation [OK]
  378. #--------------------------------------------------------------------------
  379. def on_formation_ok
  380. if @status_window.pending_index >= 0
  381. $game_party.swap_order(@status_window.index,
  382. @status_window.pending_index)
  383. @status_window.pending_index = -1
  384. @status_window.redraw_item(@status_window.index)
  385. else
  386. @status_window.pending_index = @status_window.index
  387. end
  388. @status_window.activate
  389. end
  390. #--------------------------------------------------------------------------
  391. # * Formation [Cancel]
  392. #--------------------------------------------------------------------------
  393. def on_formation_cancel
  394. if @status_window.pending_index >= 0
  395. @status_window.pending_index = -1
  396. @status_window.activate
  397. else
  398. @status_window.unselect
  399. @command_window.activate
  400. end
  401. end
  402. end
Advertisement
Add Comment
Please, Sign In to add comment