Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # ** Scene_Menu
- #------------------------------------------------------------------------------
- # This class performs the menu screen processing.
- #==============================================================================
- module MENU
- SENSIBILITE_LONG = 7 #Sensibiliter de la souris pour detecter un clic long
- end
- class Game_Actor
- #Ajout de la liste des arme interchangeable
- attr_accessor :weapon_inventaire
- attr_reader :actual_weapon
- alias init_equips_vincent26 init_equips
- def init_equips(equips)
- init_equips_vincent26(equips)
- @weapon_inventaire = [Game_BaseItem.new,Game_BaseItem.new,Game_BaseItem.new,Game_BaseItem.new]
- @weapon_inventaire[0].set_equip(true, @equips[0].object.id) if @equips[0].object != nil
- @actual_weapon = 0
- end
- def actual_weapon=(value)
- @actual_weapon = value
- refresh_weapon
- end
- def refresh_weapon
- change_equip(0, @weapon_inventaire[@actual_weapon].object)
- end
- end
- class Game_Party
- #Ajout du nombre d'arme actuellement equipable
- attr_accessor :nbr_arme
- attr_accessor :nbr_max_item
- alias init_all_items_vincent26 init_all_items
- def init_all_items
- init_all_items_vincent26
- @nbr_max_item = 100
- @nbr_arme = 1
- end
- end
- class Scene_Menu < Scene_Base
- #Démarre la Scène.
- def start
- super
- create_background
- create_picture
- @scroll_difference = 0
- create_info_all
- @timer_souris = 0
- end
- #Creation du fond
- def create_background
- @background_sprite = Sprite.new
- @background_sprite.bitmap = SceneManager.background_bitmap
- @background_sprite.color.set(16, 16, 16, 128)
- @background_sprite.z = -2
- end
- #Creation des images de base
- def create_picture
- @fond = Sprite.new
- @barre_vie = Sprite.new
- @barre_magie = Sprite.new
- @fond.bitmap = Cache.system("Menu")
- @barre_vie.bitmap = Cache.system("Barre_Vie")
- @barre_magie.bitmap = Cache.system("Barre_Magie")
- @x = Graphics.width/2-@fond.bitmap.width/2
- @y = Graphics.height/2-@fond.bitmap.height/2
- @fond.x = @x
- @fond.y = @y
- @fond.z = -1
- @rect_fond = Rect.new(@x,@y,@fond.bitmap.width,@fond.bitmap.height)
- @barre_vie.x = @x + 204
- @barre_vie.y = @y + 44
- @barre_magie.x = @x + 204
- @barre_magie.y = @y + 89
- @cadre = Cache.system("Fond")
- @cache = Cache.system("Cache")
- @icon = Cache.system("Iconset")
- @face = Sprite.new
- @face.bitmap = Bitmap.new(96,96)
- @face.x = @x + 72
- @face.y = @y + 47
- @face.zoom_x = 68.0/96.0
- @face.zoom_y = 68.0/96.0
- @face_rect = Rect.new(@x+72,@y+47,68,68)
- @exp = Sprite.new
- @exp.bitmap = Bitmap.new(56,24)
- @exp.x = @x + 34
- @exp.y = @y + 155
- @lvl = Sprite.new
- @lvl.bitmap = Bitmap.new(57,24)
- @lvl.x = @x + 122
- @lvl.y = @y + 155
- @info = Sprite.new
- @info.bitmap = Bitmap.new(167,117)
- @info.x = @x + 199
- @info.y = @y + 109
- @equipement = []
- @rect_equip = []
- for i in 0..7
- @equipement[i] = Sprite.new
- @equipement[i].bitmap = Bitmap.new(1,1)
- @equipement[i].x = @x + 33 + (i % 4)*88
- @equipement[i].y = @y + 280 + (i/4 )*61
- @rect_equip[i] = Rect.new(@x + 33 + (i % 4)*88,@y + 280 + (i/4 )*61,58,57)
- end
- @view_item = Viewport.new(@x+411,@y+44,250,277)
- @view_item.z = 10
- @item = []
- @scroll = Sprite.new
- @scroll.x = @x + 663
- @scroll.y = @y + 46
- @itemfond = Sprite.new(@view_item)
- @itemfond.z = -1
- @item_nbr = Sprite.new(@view_item)
- @item_nbr.z = 1
- @description = Sprite.new
- @description.bitmap = Bitmap.new(263,67)
- @description.x = @x + 411
- @description.y = @y + 339
- @item_select = Sprite.new
- @item_select.bitmap = Bitmap.new(24,24)
- @item_select.z = 100
- @item_select.zoom_x = 2.0
- @item_select.zoom_y = 2.0
- @item_number_max = Sprite.new
- @item_number_max.bitmap = Bitmap.new(132,18)
- @item_number_max.bitmap.font.size = 18
- @item_number_max.x = @x+542
- @item_number_max.y = @y+26
- end
- #Création des informations du joueur PV|MP|TP|EXP.
- def create_info_all
- #Face
- @face.bitmap.clear
- bitmap = Cache.face($game_party.members[0].face_name)
- rect = Rect.new($game_party.members[0].face_index % 4 * 96, $game_party.members[0].face_index / 4 * 96, 96, 96)
- @face.bitmap.blt(0, 0, bitmap, rect)
- bitmap.dispose
- #EXP
- @exp.bitmap.clear
- s = $game_party.members[0].max_level? ? "---" : $game_party.members[0].next_level_exp - $game_party.members[0].exp
- @exp.bitmap.draw_text(0, 0, @exp.bitmap.width, @exp.bitmap.height, s,1)
- #LVL
- @lvl.bitmap.clear
- @lvl.bitmap.draw_text(0, 0, @exp.bitmap.width, @exp.bitmap.height, $game_party.members[0].level,1)
- #Barre de vie
- @barre_vie.zoom_x = $game_party.members[0].hp_rate
- #Barre de magie
- @barre_magie.zoom_x = $game_party.members[0].mp_rate
- #Or/Temps/Position
- create_info
- #equipement
- create_equipement
- #Item liste
- create_item
- end
- #Creation des info
- def create_info
- @info.bitmap.clear
- @info.bitmap.draw_text(47, 18, 119, 24, $game_party.gold,2)
- a = Graphics.frame_count
- @info.bitmap.draw_text(47, 47, 119, 24, "#{a / 3600}:#{(a/60) % 60}:#{a % 60}",2)
- @info.bitmap.draw_text(47, 81, 119, 24, $game_map.display_name,2)
- end
- #Creation des equipement
- def create_equipement
- for i in 0..7
- @equipement[i].bitmap.clear
- @equipement[i].zoom_x = 1.0
- @equipement[i].zoom_y = 1.0
- @equipement[i].x = @x + 33 + (i % 4)*88
- @equipement[i].y = @y + 280 + (i/4 )*61
- @equipement[i].z = 20
- if i < $game_party.nbr_arme
- unless $game_party.members[0].weapon_inventaire[i].object == nil
- @equipement[i].bitmap = Bitmap.new(24,24)
- @equipement[i].bitmap.blt(0,0,@icon,rect_icon($game_party.members[0].weapon_inventaire[i].object.icon_index))
- @equipement[i].zoom_x = 2.0
- @equipement[i].zoom_y = 2.0
- @equipement[i].x += 4
- @equipement[i].y += 4
- end
- elsif i < 4
- @equipement[i].bitmap = @cache.clone
- elsif i >= 4
- unless $game_party.members[0].equips[1+(i-4)] == nil
- @equipement[i].bitmap = Bitmap.new(24,24)
- @equipement[i].bitmap.blt(0,0,@icon,rect_icon($game_party.members[0].equips[1+(i-4)].icon_index))
- @equipement[i].zoom_x = 2.0
- @equipement[i].zoom_y = 2.0
- @equipement[i].x += 4
- @equipement[i].y += 4
- end
- end
- end
- end
- def create_item
- make_item_list
- @itemfond.bitmap = Bitmap.new(2.75 + 4*59.75,2.75 + ((@data.length-1) / 4 + 1)*(59.75))
- @item_nbr.bitmap = Bitmap.new(2.75 + 4*59.75,2.75 + ((@data.length-1) / 4 + 1)*(59.75))
- @scroll.bitmap = Bitmap.new(7,([272/[(@itemfond.bitmap.height/@view_item.rect.height),1].max,1].max))
- @scroll.bitmap.fill_rect(@scroll.bitmap.rect, Color.new(0,0,0))
- @scroll_rect = Rect.new(@scroll.x,@scroll.y,@scroll.bitmap.width,@scroll.bitmap.height)
- @scroll.y = [[@scroll.y,@y+46].max,((@y+318)-@scroll.bitmap.height)].min
- a = [[(@scroll.y - 46-@y).to_f/(317-@scroll.bitmap.height - 46).to_f,0].max,1].min
- @scroll_difference = (@itemfond.bitmap.height-@view_item.rect.height)*a
- nbr = 0
- for i in 0...@data.length
- @item[i].dispose if @item[i]
- @item[i] = Sprite.new(@view_item)
- @item[i].bitmap = Bitmap.new(24,24)
- @item[i].bitmap.blt(0,0,@icon,rect_icon(@data[i].icon_index))
- @item[i].zoom_x = 2.0
- @item[i].zoom_y = 2.0
- @item[i].x = 6.75 + (i % 4)*(59.75)
- @item[i].y = 6.75 + (i / 4)*(59.75) - @scroll_difference
- @itemfond.y = - @scroll_difference
- @item_nbr.y = - @scroll_difference
- @itemfond.bitmap.blt(2.75 + (i % 4)*(59.75),2.75 + (i / 4)*(59.75),@cadre,@cadre.rect)
- @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)
- nbr += $game_party.item_number(@data[i])
- end
- @item_number_max.bitmap.clear
- @item_number_max.bitmap.draw_text(@item_number_max.bitmap.rect,"#{nbr}/#{$game_party.nbr_max_item}",1)
- for i in @data.length...@item.length
- @item[i].dispose if @item[i]
- end
- end
- #Get rect for icone
- def rect_icon(icon_index)
- return Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
- end
- #creer la liste d'item
- def make_item_list
- @data = []
- @data = $game_party.all_items
- end
- #Affiche l'argent et le temps.
- def argent
- contents.clear
- draw_text(0, 0, contents.width, 70, $game_party.gold.to_i)
- end
- #Mise à jour des composants.
- def update
- super
- action_enter_long if Input.press?(:C)
- end_action_enter_long if !Input.press?(:C)
- action_enter if @end == true
- action_annule if Input.trigger?(:B)
- update_souris_position
- end
- #Gestion de la souris
- def action_enter_long
- @timer_souris += 1
- if @timer_souris == MENU::SENSIBILITE_LONG
- enter_long
- end
- long if @timer_souris > MENU::SENSIBILITE_LONG
- end
- def end_action_enter_long
- end_enter if @timer_souris >= MENU::SENSIBILITE_LONG
- @end = true if @timer_souris < MENU::SENSIBILITE_LONG && @timer_souris != 0
- @timer_souris = 0
- end
- def action_enter
- @end = false
- enter
- end
- def action_annule
- return_scene
- end
- #Action debut long clic
- def enter_long
- x , y = Mouse.pos
- @index_item = -1
- if point_in_rect?(x-@view_item.rect.x,y-@view_item.rect.y,@itemfond.bitmap.rect)
- if @itemfond.bitmap.get_pixel(x-@view_item.rect.x,y-@view_item.rect.y).alpha != 0
- @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
- @item_select.bitmap.clear
- @item_select.bitmap.blt(0,0,@icon,rect_icon(@data[@index_item].icon_index))
- Mouse.set_visible(false)
- end
- end
- if point_in_rect?(x,y,@scroll_rect)
- x , y = Mouse.pos
- y = y-@scroll_rect.y
- @scrolling = y
- end
- end
- #Action long clic
- def long
- x , y = Mouse.pos
- if @taking_number
- if point_in_rect?(x,y,@rectplus)
- @number3 = [@number3+1,$game_party.item_number(@data[@index_item_jeter])].min
- refresh_number
- elsif point_in_rect?(x,y,@rectmoins)
- @number3 = [@number3-1,1].max
- refresh_number
- elsif !point_in_rect?(x,y,@rectnumber)
- @number.dispose
- @number2.dispose
- @taking_number = false
- end
- elsif @attente_confirmation && !point_in_rect?(x,y,@rectconfirmation)
- @confirmation.dispose
- @attente_confirmation = false
- else
- if @scrolling
- @scroll.y = [[y-@scrolling,@y+46].max,((@y+318)-@scroll.bitmap.height)].min
- a = [[(@scroll.y - 46-@y).to_f/(317-@scroll.bitmap.height - 46).to_f,0].max,1].min
- @scroll_difference = (@itemfond.bitmap.height-@view_item.rect.height)*a
- for i in 0...@item.length
- next if @item[i].disposed?
- @item[i].y = 6.75 + (i / 4)*(59.75) - @scroll_difference
- end
- @itemfond.y = -@scroll_difference
- @item_nbr.y = -@scroll_difference
- end
- end
- end
- #Fin d'action longue
- def end_enter
- @scrolling = false
- Mouse.set_visible(true) if @index_item != -1
- @item_select.bitmap.clear
- x , y = Mouse.pos
- for i in 0..7
- if point_in_rect?(x,y,@rect_equip[i]) && @index_item > -1
- item = @data[@index_item]
- if i < 4 && item.is_a?(RPG::Weapon) && $game_party.members[0].equippable?(item)
- $game_party.members[0].weapon_inventaire[i].set_equip(true, item.id)
- play_se_for_equip
- $game_party.members[0].refresh_weapon
- elsif item.is_a?(RPG::Armor) && $game_party.members[0].equippable?(item)
- if item.etype_id == $game_party.members[0].equip_slots[i-3]
- $game_party.members[0].change_equip(i-3, item)
- play_se_for_equip
- end
- end
- end
- create_equipement
- create_item
- end
- if point_in_rect?(x,y,@face_rect)
- item = @data[@index_item]
- if item.is_a?(RPG::Item) && $game_party.members[0].usable?(item)
- use_item(item)
- end
- end
- if !point_in_rect?(x,y,@rect_fond) && @index_item != -1
- item = @data[@index_item]
- @number3 = $game_party.item_number(item)
- take_number if @number3 > 1
- confirmation_jeter(@index_item) if @number3 == 1
- end
- @index_item = -1
- end
- #Action clic court
- def enter
- puts "enter"
- x , y = Mouse.pos
- if @taking_number
- if point_in_rect?(x,y,@rectplus)
- @number3 = [@number3+1,$game_party.item_number(@data[@index_item_jeter])].min
- refresh_number
- elsif point_in_rect?(x,y,@rectmoins)
- @number3 = [@number3-1,1].max
- refresh_number
- elsif point_in_rect?(x,y,@rectok)
- @number.dispose
- @number2.dispose
- @taking_number = false
- confirmation_jeter(@index_item_jeter)
- elsif !point_in_rect?(x,y,@rectnumber)
- @number.dispose
- @number2.dispose
- @taking_number = false
- end
- end
- if @attente_confirmation
- if point_in_rect?(x,y,@rectoui)
- puts "oui"
- @confirmation.dispose
- @attente_confirmation = false
- $game_party.lose_item(@data[@index_item_jeter], @number3)
- create_item
- elsif point_in_rect?(x,y,@rectnon)
- puts "non"
- @confirmation.dispose
- @attente_confirmation = false
- elsif !point_in_rect?(x,y,@rectconfirmation)
- puts "non"
- @confirmation.dispose
- @attente_confirmation = false
- end
- end
- end
- #Creation du choix du nombre
- def take_number
- x , y = Mouse.pos
- @index_item_jeter = @index_item
- @taking_number = true
- @number = Sprite.new
- @number.bitmap = Cache.system("Nombre")
- @number.x = x-@number.bitmap.width/2
- @number.y = y-@number.bitmap.height/2
- @number.z = 200
- @rectplus = Rect.new(@number.x+26,@number.y+28,21,17)
- @rectmoins = Rect.new(@number.x+26,@number.y+47,21,17)
- @rectok = Rect.new(@number.x+122,@number.y+28,22,34)
- @rectnumber = Rect.new(@number.x,@number.y,@number.bitmap.width,@number.bitmap.height)
- @number2 = Sprite.new
- @number2.bitmap = Bitmap.new(66,34)
- @number2.x = x-@number.bitmap.width/2+51
- @number2.y = y-@number.bitmap.height/2+28
- @number2.bitmap.draw_text(0,0,66,34,@number3,2)
- @number2.z = 201
- end
- def refresh_number
- @number2.bitmap.clear
- @number2.bitmap.draw_text(0,0,66,34,@number3,2)
- end
- #creation de la confirmation
- def confirmation_jeter(index)
- @index_item_jeter = index
- x,y = Mouse.pos
- @attente_confirmation = true
- @confirmation = Sprite.new
- @confirmation.bitmap = Cache.system("Confirmation")
- @confirmation.x = x-@confirmation.bitmap.width/2
- @confirmation.y = y-@confirmation.bitmap.height/2
- @confirmation.z = 202
- @rectoui = Rect.new(@confirmation.x+28,@confirmation.y+31,44,32)
- @rectnon = Rect.new(@confirmation.x+72,@confirmation.y+31,44,32)
- @rectconfirmation = Rect.new(@confirmation.x,@confirmation.y,@confirmation.bitmap.width,@confirmation.bitmap.height)
- end
- #Execute l'utilisation d'un item
- def use_item(item)
- play_se_for_item
- user.use_item(item)
- $game_party.members.each do |target|
- item.repeats.times { target.item_apply(user, item) }
- end
- check_common_event
- check_gameover
- end
- #Vieux copier coller des methodes ^^
- def play_se_for_item
- Sound.play_use_item
- end
- def user
- $game_party.movable_members.max_by {|member| member.pha }
- end
- def check_common_event
- SceneManager.goto(Scene_Map) if $game_temp.common_event_reserved?
- end
- #Son pour l'equipement
- def play_se_for_equip
- Sound.play_equip
- end
- #test la présence d'un point dans un rect
- def point_in_rect?(x,y,rect)
- return false unless rect.is_a?(Rect)
- if x > rect.x && x <= rect.x+rect.width
- if y > rect.y && y <= rect.y+rect.height
- return true
- end
- end
- return false
- end
- #Gestion de la souris afin d'afficher un popup.
- def update_souris_position
- @item_select.x , @item_select.y = Mouse.pos
- @item_select.x -= 24
- @item_select.y -= 24
- x , y = Mouse.pos
- if Graphics.frame_count % 2 == 0
- if point_in_rect?(x-@view_item.rect.x,y-@view_item.rect.y,@itemfond.bitmap.rect)
- if @itemfond.bitmap.get_pixel(x-@view_item.rect.x,y-@view_item.rect.y).alpha != 0
- 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
- unless @data[index_item] == nil
- @description.bitmap.clear
- @description.bitmap.draw_text(0,0,@description.bitmap.width,24,@data[index_item].name,2)
- txt = @data[index_item].description
- txt = txt.split("/n")
- for i in 0...txt.length
- @description.bitmap.draw_text(0,24+24*i,@description.bitmap.width,24,txt[i],2)
- end
- end
- else
- @description.bitmap.clear
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement