Advertisement
Guest User

menu

a guest
Aug 7th, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.26 KB | None | 0 0
  1. #==============================================================================
  2. # ** Scene_Menu
  3. #------------------------------------------------------------------------------
  4. # This class performs the menu screen processing.
  5. #==============================================================================
  6. module MENU
  7.  
  8. SENSIBILITE_LONG = 7 #Sensibiliter de la souris pour detecter un clic long
  9.  
  10. end
  11. class Game_Actor
  12. #Ajout de la liste des arme interchangeable
  13. attr_accessor :weapon_inventaire
  14. attr_reader :actual_weapon
  15. alias init_equips_vincent26 init_equips
  16. def init_equips(equips)
  17. init_equips_vincent26(equips)
  18. @weapon_inventaire = [Game_BaseItem.new,Game_BaseItem.new,Game_BaseItem.new,Game_BaseItem.new]
  19. @weapon_inventaire[0].set_equip(true, @equips[0].object.id) if @equips[0].object != nil
  20. @actual_weapon = 0
  21. end
  22. def actual_weapon=(value)
  23. @actual_weapon = value
  24. refresh_weapon
  25. end
  26. def refresh_weapon
  27. change_equip(0, @weapon_inventaire[@actual_weapon].object)
  28. end
  29. end
  30. class Game_Party
  31. #Ajout du nombre d'arme actuellement equipable
  32. attr_accessor :nbr_arme
  33. attr_accessor :nbr_max_item
  34. alias init_all_items_vincent26 init_all_items
  35. def init_all_items
  36. init_all_items_vincent26
  37. @nbr_max_item = 100
  38. @nbr_arme = 1
  39. end
  40. end
  41. class Scene_Menu < Scene_Base
  42.  
  43. #Démarre la Scène.
  44. def start
  45. super
  46. create_background
  47. create_picture
  48. @scroll_difference = 0
  49. create_info_all
  50. @timer_souris = 0
  51. end
  52.  
  53. #Creation du fond
  54. def create_background
  55. @background_sprite = Sprite.new
  56. @background_sprite.bitmap = SceneManager.background_bitmap
  57. @background_sprite.color.set(16, 16, 16, 128)
  58. @background_sprite.z = -2
  59. end
  60.  
  61. #Creation des images de base
  62. def create_picture
  63. @fond = Sprite.new
  64. @barre_vie = Sprite.new
  65. @barre_magie = Sprite.new
  66. @fond.bitmap = Cache.system("Menu")
  67. @barre_vie.bitmap = Cache.system("Barre_Vie")
  68. @barre_magie.bitmap = Cache.system("Barre_Magie")
  69. @x = Graphics.width/2-@fond.bitmap.width/2
  70. @y = Graphics.height/2-@fond.bitmap.height/2
  71. @fond.x = @x
  72. @fond.y = @y
  73. @fond.z = -1
  74. @rect_fond = Rect.new(@x,@y,@fond.bitmap.width,@fond.bitmap.height)
  75. @barre_vie.x = @x + 204
  76. @barre_vie.y = @y + 44
  77. @barre_magie.x = @x + 204
  78. @barre_magie.y = @y + 89
  79. @cadre = Cache.system("Fond")
  80. @cache = Cache.system("Cache")
  81. @icon = Cache.system("Iconset")
  82. @face = Sprite.new
  83. @face.bitmap = Bitmap.new(96,96)
  84. @face.x = @x + 72
  85. @face.y = @y + 47
  86. @face.zoom_x = 68.0/96.0
  87. @face.zoom_y = 68.0/96.0
  88. @face_rect = Rect.new(@x+72,@y+47,68,68)
  89. @exp = Sprite.new
  90. @exp.bitmap = Bitmap.new(56,24)
  91. @exp.x = @x + 34
  92. @exp.y = @y + 155
  93. @lvl = Sprite.new
  94. @lvl.bitmap = Bitmap.new(57,24)
  95. @lvl.x = @x + 122
  96. @lvl.y = @y + 155
  97. @info = Sprite.new
  98. @info.bitmap = Bitmap.new(167,117)
  99. @info.x = @x + 199
  100. @info.y = @y + 109
  101. @equipement = []
  102. @rect_equip = []
  103. for i in 0..7
  104. @equipement[i] = Sprite.new
  105. @equipement[i].bitmap = Bitmap.new(1,1)
  106. @equipement[i].x = @x + 33 + (i % 4)*88
  107. @equipement[i].y = @y + 280 + (i/4 )*61
  108. @rect_equip[i] = Rect.new(@x + 33 + (i % 4)*88,@y + 280 + (i/4 )*61,58,57)
  109. end
  110. @view_item = Viewport.new(@x+411,@y+44,250,277)
  111. @view_item.z = 10
  112. @item = []
  113. @scroll = Sprite.new
  114. @scroll.x = @x + 663
  115. @scroll.y = @y + 46
  116. @itemfond = Sprite.new(@view_item)
  117. @itemfond.z = -1
  118. @item_nbr = Sprite.new(@view_item)
  119. @item_nbr.z = 1
  120. @description = Sprite.new
  121. @description.bitmap = Bitmap.new(263,67)
  122. @description.x = @x + 411
  123. @description.y = @y + 339
  124. @item_select = Sprite.new
  125. @item_select.bitmap = Bitmap.new(24,24)
  126. @item_select.z = 100
  127. @item_select.zoom_x = 2.0
  128. @item_select.zoom_y = 2.0
  129. @item_number_max = Sprite.new
  130. @item_number_max.bitmap = Bitmap.new(132,18)
  131. @item_number_max.bitmap.font.size = 18
  132. @item_number_max.x = @x+542
  133. @item_number_max.y = @y+26
  134. end
  135.  
  136. #Création des informations du joueur PV|MP|TP|EXP.
  137. def create_info_all
  138. #Face
  139. @face.bitmap.clear
  140. bitmap = Cache.face($game_party.members[0].face_name)
  141. rect = Rect.new($game_party.members[0].face_index % 4 * 96, $game_party.members[0].face_index / 4 * 96, 96, 96)
  142. @face.bitmap.blt(0, 0, bitmap, rect)
  143. bitmap.dispose
  144. #EXP
  145. @exp.bitmap.clear
  146. s = $game_party.members[0].max_level? ? "---" : $game_party.members[0].next_level_exp - $game_party.members[0].exp
  147. @exp.bitmap.draw_text(0, 0, @exp.bitmap.width, @exp.bitmap.height, s,1)
  148. #LVL
  149. @lvl.bitmap.clear
  150. @lvl.bitmap.draw_text(0, 0, @exp.bitmap.width, @exp.bitmap.height, $game_party.members[0].level,1)
  151. #Barre de vie
  152. @barre_vie.zoom_x = $game_party.members[0].hp_rate
  153. #Barre de magie
  154. @barre_magie.zoom_x = $game_party.members[0].mp_rate
  155. #Or/Temps/Position
  156. create_info
  157. #equipement
  158. create_equipement
  159. #Item liste
  160. create_item
  161. end
  162.  
  163. #Creation des info
  164. def create_info
  165. @info.bitmap.clear
  166. @info.bitmap.draw_text(47, 18, 119, 24, $game_party.gold,2)
  167. a = Graphics.frame_count
  168. @info.bitmap.draw_text(47, 47, 119, 24, "#{a / 3600}:#{(a/60) % 60}:#{a % 60}",2)
  169. @info.bitmap.draw_text(47, 81, 119, 24, $game_map.display_name,2)
  170. end
  171.  
  172. #Creation des equipement
  173. def create_equipement
  174. for i in 0..7
  175. @equipement[i].bitmap.clear
  176. @equipement[i].zoom_x = 1.0
  177. @equipement[i].zoom_y = 1.0
  178. @equipement[i].x = @x + 33 + (i % 4)*88
  179. @equipement[i].y = @y + 280 + (i/4 )*61
  180. @equipement[i].z = 20
  181. if i < $game_party.nbr_arme
  182. unless $game_party.members[0].weapon_inventaire[i].object == nil
  183. @equipement[i].bitmap = Bitmap.new(24,24)
  184. @equipement[i].bitmap.blt(0,0,@icon,rect_icon($game_party.members[0].weapon_inventaire[i].object.icon_index))
  185. @equipement[i].zoom_x = 2.0
  186. @equipement[i].zoom_y = 2.0
  187. @equipement[i].x += 4
  188. @equipement[i].y += 4
  189. end
  190. elsif i < 4
  191. @equipement[i].bitmap = @cache.clone
  192. elsif i >= 4
  193. unless $game_party.members[0].equips[1+(i-4)] == nil
  194. @equipement[i].bitmap = Bitmap.new(24,24)
  195. @equipement[i].bitmap.blt(0,0,@icon,rect_icon($game_party.members[0].equips[1+(i-4)].icon_index))
  196. @equipement[i].zoom_x = 2.0
  197. @equipement[i].zoom_y = 2.0
  198. @equipement[i].x += 4
  199. @equipement[i].y += 4
  200. end
  201. end
  202. end
  203. end
  204.  
  205. def create_item
  206. make_item_list
  207. @itemfond.bitmap = Bitmap.new(2.75 + 4*59.75,2.75 + ((@data.length-1) / 4 + 1)*(59.75))
  208. @item_nbr.bitmap = Bitmap.new(2.75 + 4*59.75,2.75 + ((@data.length-1) / 4 + 1)*(59.75))
  209. @scroll.bitmap = Bitmap.new(7,([272/[(@itemfond.bitmap.height/@view_item.rect.height),1].max,1].max))
  210. @scroll.bitmap.fill_rect(@scroll.bitmap.rect, Color.new(0,0,0))
  211. @scroll_rect = Rect.new(@scroll.x,@scroll.y,@scroll.bitmap.width,@scroll.bitmap.height)
  212. @scroll.y = [[@scroll.y,@y+46].max,((@y+318)-@scroll.bitmap.height)].min
  213. a = [[(@scroll.y - 46-@y).to_f/(317-@scroll.bitmap.height - 46).to_f,0].max,1].min
  214. @scroll_difference = (@itemfond.bitmap.height-@view_item.rect.height)*a
  215. nbr = 0
  216. for i in 0...@data.length
  217. @item[i].dispose if @item[i]
  218. @item[i] = Sprite.new(@view_item)
  219. @item[i].bitmap = Bitmap.new(24,24)
  220. @item[i].bitmap.blt(0,0,@icon,rect_icon(@data[i].icon_index))
  221. @item[i].zoom_x = 2.0
  222. @item[i].zoom_y = 2.0
  223. @item[i].x = 6.75 + (i % 4)*(59.75)
  224. @item[i].y = 6.75 + (i / 4)*(59.75) - @scroll_difference
  225. @itemfond.y = - @scroll_difference
  226. @item_nbr.y = - @scroll_difference
  227. @itemfond.bitmap.blt(2.75 + (i % 4)*(59.75),2.75 + (i / 4)*(59.75),@cadre,@cadre.rect)
  228. @item_nbr.bitmap.draw_text(6.75 + (i % 4)*(59.75),31.75 + (i / 4)*(59.75),49,25,$game_party.item_number(@data[i]),1)
  229. nbr += $game_party.item_number(@data[i])
  230. end
  231. @item_number_max.bitmap.clear
  232. @item_number_max.bitmap.draw_text(@item_number_max.bitmap.rect,"#{nbr}/#{$game_party.nbr_max_item}",1)
  233. for i in @data.length...@item.length
  234. @item[i].dispose if @item[i]
  235. end
  236. end
  237.  
  238. #Get rect for icone
  239. def rect_icon(icon_index)
  240. return Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  241. end
  242.  
  243. #creer la liste d'item
  244. def make_item_list
  245. @data = []
  246. @data = $game_party.all_items
  247. end
  248.  
  249.  
  250. #Affiche l'argent et le temps.
  251. def argent
  252. contents.clear
  253. draw_text(0, 0, contents.width, 70, $game_party.gold.to_i)
  254. end
  255.  
  256. #Mise à jour des composants.
  257. def update
  258. super
  259. action_enter_long if Input.press?(:C)
  260. end_action_enter_long if !Input.press?(:C)
  261. action_enter if @end == true
  262. action_annule if Input.trigger?(:B)
  263. update_souris_position
  264. end
  265.  
  266. #Gestion de la souris
  267. def action_enter_long
  268. @timer_souris += 1
  269. if @timer_souris == MENU::SENSIBILITE_LONG
  270. enter_long
  271. end
  272. long if @timer_souris > MENU::SENSIBILITE_LONG
  273. end
  274. def end_action_enter_long
  275. end_enter if @timer_souris >= MENU::SENSIBILITE_LONG
  276. @end = true if @timer_souris < MENU::SENSIBILITE_LONG && @timer_souris != 0
  277. @timer_souris = 0
  278. end
  279. def action_enter
  280. @end = false
  281. enter
  282. end
  283. def action_annule
  284. return_scene
  285. end
  286.  
  287. #Action debut long clic
  288. def enter_long
  289. x , y = Mouse.pos
  290. @index_item = -1
  291. if point_in_rect?(x-@view_item.rect.x,y-@view_item.rect.y,@itemfond.bitmap.rect)
  292. if @itemfond.bitmap.get_pixel(x-@view_item.rect.x,y-@view_item.rect.y).alpha != 0
  293. @index_item = ((x-@view_item.rect.x-2.75)/59.75).to_i + (((y-@view_item.rect.y-2.75-@itemfond.y)/59.75).to_i)*4
  294. @item_select.bitmap.clear
  295. @item_select.bitmap.blt(0,0,@icon,rect_icon(@data[@index_item].icon_index))
  296. Mouse.set_visible(false)
  297. end
  298. end
  299. if point_in_rect?(x,y,@scroll_rect)
  300. x , y = Mouse.pos
  301. y = y-@scroll_rect.y
  302. @scrolling = y
  303. end
  304. end
  305. #Action long clic
  306. def long
  307. x , y = Mouse.pos
  308. if @taking_number
  309. if point_in_rect?(x,y,@rectplus)
  310. @number3 = [@number3+1,$game_party.item_number(@data[@index_item_jeter])].min
  311. refresh_number
  312. elsif point_in_rect?(x,y,@rectmoins)
  313. @number3 = [@number3-1,1].max
  314. refresh_number
  315. elsif !point_in_rect?(x,y,@rectnumber)
  316. @number.dispose
  317. @number2.dispose
  318. @taking_number = false
  319. end
  320. elsif @attente_confirmation && !point_in_rect?(x,y,@rectconfirmation)
  321. @confirmation.dispose
  322. @attente_confirmation = false
  323. else
  324. if @scrolling
  325. @scroll.y = [[y-@scrolling,@y+46].max,((@y+318)-@scroll.bitmap.height)].min
  326. a = [[(@scroll.y - 46-@y).to_f/(317-@scroll.bitmap.height - 46).to_f,0].max,1].min
  327. @scroll_difference = (@itemfond.bitmap.height-@view_item.rect.height)*a
  328. for i in 0...@item.length
  329. next if @item[i].disposed?
  330. @item[i].y = 6.75 + (i / 4)*(59.75) - @scroll_difference
  331. end
  332. @itemfond.y = -@scroll_difference
  333. @item_nbr.y = -@scroll_difference
  334. end
  335. end
  336. end
  337. #Fin d'action longue
  338. def end_enter
  339. @scrolling = false
  340. Mouse.set_visible(true) if @index_item != -1
  341. @item_select.bitmap.clear
  342. x , y = Mouse.pos
  343. for i in 0..7
  344. if point_in_rect?(x,y,@rect_equip[i]) && @index_item > -1
  345. item = @data[@index_item]
  346. if i < 4 && item.is_a?(RPG::Weapon) && $game_party.members[0].equippable?(item)
  347. $game_party.members[0].weapon_inventaire[i].set_equip(true, item.id)
  348. play_se_for_equip
  349. $game_party.members[0].refresh_weapon
  350. elsif item.is_a?(RPG::Armor) && $game_party.members[0].equippable?(item)
  351. if item.etype_id == $game_party.members[0].equip_slots[i-3]
  352. $game_party.members[0].change_equip(i-3, item)
  353. play_se_for_equip
  354. end
  355. end
  356. end
  357. create_equipement
  358. create_item
  359. end
  360. if point_in_rect?(x,y,@face_rect)
  361. item = @data[@index_item]
  362. if item.is_a?(RPG::Item) && $game_party.members[0].usable?(item)
  363. use_item(item)
  364. end
  365. end
  366. if !point_in_rect?(x,y,@rect_fond) && @index_item != -1
  367. item = @data[@index_item]
  368. @number3 = $game_party.item_number(item)
  369. take_number if @number3 > 1
  370. confirmation_jeter(@index_item) if @number3 == 1
  371. end
  372. @index_item = -1
  373. end
  374. #Action clic court
  375. def enter
  376. puts "enter"
  377. x , y = Mouse.pos
  378. if @taking_number
  379. if point_in_rect?(x,y,@rectplus)
  380. @number3 = [@number3+1,$game_party.item_number(@data[@index_item_jeter])].min
  381. refresh_number
  382. elsif point_in_rect?(x,y,@rectmoins)
  383. @number3 = [@number3-1,1].max
  384. refresh_number
  385. elsif point_in_rect?(x,y,@rectok)
  386. @number.dispose
  387. @number2.dispose
  388. @taking_number = false
  389. confirmation_jeter(@index_item_jeter)
  390. elsif !point_in_rect?(x,y,@rectnumber)
  391. @number.dispose
  392. @number2.dispose
  393. @taking_number = false
  394. end
  395. end
  396. if @attente_confirmation
  397. if point_in_rect?(x,y,@rectoui)
  398. puts "oui"
  399. @confirmation.dispose
  400. @attente_confirmation = false
  401. $game_party.lose_item(@data[@index_item_jeter], @number3)
  402. create_item
  403. elsif point_in_rect?(x,y,@rectnon)
  404. puts "non"
  405. @confirmation.dispose
  406. @attente_confirmation = false
  407. elsif !point_in_rect?(x,y,@rectconfirmation)
  408. puts "non"
  409. @confirmation.dispose
  410. @attente_confirmation = false
  411. end
  412. end
  413. end
  414.  
  415. #Creation du choix du nombre
  416. def take_number
  417. x , y = Mouse.pos
  418. @index_item_jeter = @index_item
  419. @taking_number = true
  420. @number = Sprite.new
  421. @number.bitmap = Cache.system("Nombre")
  422. @number.x = x-@number.bitmap.width/2
  423. @number.y = y-@number.bitmap.height/2
  424. @number.z = 200
  425. @rectplus = Rect.new(@number.x+26,@number.y+28,21,17)
  426. @rectmoins = Rect.new(@number.x+26,@number.y+47,21,17)
  427. @rectok = Rect.new(@number.x+122,@number.y+28,22,34)
  428. @rectnumber = Rect.new(@number.x,@number.y,@number.bitmap.width,@number.bitmap.height)
  429. @number2 = Sprite.new
  430. @number2.bitmap = Bitmap.new(66,34)
  431. @number2.x = x-@number.bitmap.width/2+51
  432. @number2.y = y-@number.bitmap.height/2+28
  433. @number2.bitmap.draw_text(0,0,66,34,@number3,2)
  434. @number2.z = 201
  435. end
  436. def refresh_number
  437. @number2.bitmap.clear
  438. @number2.bitmap.draw_text(0,0,66,34,@number3,2)
  439. end
  440.  
  441. #creation de la confirmation
  442. def confirmation_jeter(index)
  443. @index_item_jeter = index
  444. x,y = Mouse.pos
  445. @attente_confirmation = true
  446. @confirmation = Sprite.new
  447. @confirmation.bitmap = Cache.system("Confirmation")
  448. @confirmation.x = x-@confirmation.bitmap.width/2
  449. @confirmation.y = y-@confirmation.bitmap.height/2
  450. @confirmation.z = 202
  451. @rectoui = Rect.new(@confirmation.x+28,@confirmation.y+31,44,32)
  452. @rectnon = Rect.new(@confirmation.x+72,@confirmation.y+31,44,32)
  453. @rectconfirmation = Rect.new(@confirmation.x,@confirmation.y,@confirmation.bitmap.width,@confirmation.bitmap.height)
  454. end
  455.  
  456. #Execute l'utilisation d'un item
  457. def use_item(item)
  458. play_se_for_item
  459. user.use_item(item)
  460. $game_party.members.each do |target|
  461. item.repeats.times { target.item_apply(user, item) }
  462. end
  463. check_common_event
  464. check_gameover
  465. end
  466.  
  467. #Vieux copier coller des methodes ^^
  468. def play_se_for_item
  469. Sound.play_use_item
  470. end
  471. def user
  472. $game_party.movable_members.max_by {|member| member.pha }
  473. end
  474. def check_common_event
  475. SceneManager.goto(Scene_Map) if $game_temp.common_event_reserved?
  476. end
  477.  
  478. #Son pour l'equipement
  479. def play_se_for_equip
  480. Sound.play_equip
  481. end
  482.  
  483. #test la présence d'un point dans un rect
  484. def point_in_rect?(x,y,rect)
  485. return false unless rect.is_a?(Rect)
  486. if x > rect.x && x <= rect.x+rect.width
  487. if y > rect.y && y <= rect.y+rect.height
  488. return true
  489. end
  490. end
  491. return false
  492. end
  493.  
  494. #Gestion de la souris afin d'afficher un popup.
  495. def update_souris_position
  496. @item_select.x , @item_select.y = Mouse.pos
  497. @item_select.x -= 24
  498. @item_select.y -= 24
  499. x , y = Mouse.pos
  500. if Graphics.frame_count % 2 == 0
  501. if point_in_rect?(x-@view_item.rect.x,y-@view_item.rect.y,@itemfond.bitmap.rect)
  502. if @itemfond.bitmap.get_pixel(x-@view_item.rect.x,y-@view_item.rect.y).alpha != 0
  503. index_item = ((x-@view_item.rect.x-2.75)/59.75).to_i + (((y-@view_item.rect.y-2.75-@itemfond.y)/59.75).to_i)*4
  504. unless @data[index_item] == nil
  505. @description.bitmap.clear
  506. @description.bitmap.draw_text(0,0,@description.bitmap.width,24,@data[index_item].name,2)
  507. txt = @data[index_item].description
  508. txt = txt.split("/n")
  509. for i in 0...txt.length
  510. @description.bitmap.draw_text(0,24+24*i,@description.bitmap.width,24,txt[i],2)
  511. end
  512. end
  513. else
  514. @description.bitmap.clear
  515. end
  516. end
  517. end
  518. end
  519.  
  520. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement