Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # ** DRG - Scene Menu
- # Version : 1.20
- # Author : LiTTleDRAgo
- #==============================================================================
- module LiTTleDRAgo
- VX = defined?(Window_ActorCommand)
- SCENE_MENU = { # VX Version
- # index => [Menu Name, Menu Scene, Scene Args, Condition],
- 0 => ['Inventory' , Scene_Item , false, '$game_actors[1].hp >= 0'],
- 1 => ['Skill' , Scene_Skill, :actor],
- 2 => ['Equip' , Scene_Equip, :actor],
- 3 => ['Status' , Scene_Status, :actor],
- 4 => ['Save' , Scene_File, [true,false,false], '!$game_system.save_disabled'],
- 5 => ['End' , Scene_End ],
- }
- SCENE_MENU = { # XP Version
- # index => [Menu Name, Menu Scene, Scene Args, Condition],
- 0 => ['Inventory' , Scene_Item , false, '$game_actors[1].hp >= 0'],
- 1 => ['Skill' , Scene_Skill, :actor],
- 2 => ['Equip' , Scene_Equip, :actor],
- 3 => ['Status' , Scene_Status, :actor],
- 4 => ['Save' , Scene_Save, false, '!$game_system.save_disabled'],
- 5 => ['End' , Scene_End ],
- } if !VX
- # Menu Name = Name of the menu
- # Menu Scene = Scene of the menu
- # Scene Args = Args required in the menu
- # false/nil = no args
- # :actor = select actor
- # [] (Array)= use all in the inside of the array as args
- # Condition = menu can be used as long as the condition is fulfilled
- # Image related (in folder Graphics/Windowskins)
- LAYOUT_IMAGES = 'Menu Layout'
- HEADER_FOOTER = 'Menu Header Footer'
- SIDE_IMAGES = 'Menu Chains'
- BACK_IMAGES = 'Mn_Back'
- BAR_IMAGES = 'HP Bar'
- HP_METER_IMAGE = 'HP Meter'
- SP_METER_IMAGE = 'SP Meter'
- NUMBER_IMAGE = 'Menu Number'
- # Transition (in folder Graphics/Transition)
- TRANSITION = '015-Diamond01'
- end
- #==============================================================================
- # ** Scene_Menu
- #------------------------------------------------------------------------------
- # This class performs menu screen processing.
- #==============================================================================
- class Scene_Menu
- #--------------------------------------------------------------------------
- # * Constants
- #--------------------------------------------------------------------------
- VX = LiTTleDRAgo::VX
- #--------------------------------------------------------------------------
- # * main
- #--------------------------------------------------------------------------
- def main
- create_arrow
- create_layout
- create_menu
- create_player
- create_spriteset
- create_transition
- update_premenu
- update while $scene == self
- dispose_premenu
- dispose_freeze
- dispose
- end
- #--------------------------------------------------------------------------
- # * create_transition
- #--------------------------------------------------------------------------
- def create_transition
- file = "Graphics/Transitions/#{LiTTleDRAgo::TRANSITION}"
- if FileTest.exist?("#{file}.png") || FileTest.exist?("#{file}.jpg")
- Graphics.transition(20,"#{file}")
- else
- Graphics.transition(20)
- end
- end
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- update_grafis
- update_index
- update_arrow
- update_player
- end
- #--------------------------------------------------------------------------
- # * update_grafis
- #--------------------------------------------------------------------------
- def update_grafis() [Graphics,Input].each {|s| s.update} end
- #--------------------------------------------------------------------------
- # * Cache
- #--------------------------------------------------------------------------
- def cache() VX ? Cache : RPG::Cache end
- def windowskin(f) cache.load_bitmap('Graphics/Windowskins/', f) end
- def actors() VX ? $game_party.members : $game_party.actors end
- #--------------------------------------------------------------------------
- # * Create Layout
- #--------------------------------------------------------------------------
- def create_layout
- @sprite_layout = []
- if $image_drg_menu.nil?
- $image_drg_menu = [lay = windowskin(LiTTleDRAgo::SIDE_IMAGES),
- fog = windowskin(LiTTleDRAgo::BACK_IMAGES),
- bef = windowskin(LiTTleDRAgo::LAYOUT_IMAGES),
- cla = windowskin(LiTTleDRAgo::HEADER_FOOTER),
- ri = cla.clone, copy = lay.clone]
- (0...lay.height).each {|i| (0...lay.width).each {|j|
- lay.set_pixel(lay.width-j-1,lay.height-i-1,copy.get_pixel(j,i))} }
- (0...cla.height).each {|i| (0...cla.width).each {|j|
- cla.set_pixel(cla.width-j-1,cla.height-i-1,ri.get_pixel(j,i))} }
- end
- map = load_data("Data/MapInfos.rxdata")[$game_map.map_id].name if !VX
- map = load_data("Data/MapInfos.rvdata")[$game_map.map_id].name if VX
- @sprite_layout[0] = Plane.new
- @sprite_layout[1] = Plane.new
- @sprite_layout[2] = Plane.new
- @sprite_layout[3] = Plane.new
- @sprite_layout[4] = Sprite.new
- @sprite_layout[5] = Sprite.new
- @sprite_layout[0].bitmap = Bitmap.new(*@resolution)
- @sprite_layout[1].bitmap = Bitmap.new(*@resolution)
- @sprite_layout[3].bitmap = Bitmap.new(*@resolution)
- @sprite_layout[4].bitmap = Bitmap.new(*@resolution)
- @sprite_layout[5].bitmap = Bitmap.new(*@resolution)
- r = [@sprite_layout[0].bitmap.rect,$image_drg_menu[5].dup.rect]
- @sprite_layout[0].bitmap.stretch_blt(r[0],$image_drg_menu[5].dup,r[1])
- @sprite_layout[1].bitmap.stretch_blt(r[0],$image_drg_menu[0].dup,r[1])
- @sprite_layout[2].bitmap = $image_drg_menu[1].dup
- @sprite_layout[3].bitmap.stretch_blt(r[0],$image_drg_menu[2].dup,r[1])
- @sprite_layout[4].bitmap.stretch_blt(r[0],$image_drg_menu[3].dup,r[1])
- @sprite_layout[5].bitmap.stretch_blt(r[0],$image_drg_menu[4].dup,r[1])
- @sprite_layout[2].opacity = 70
- @sprite_layout[3].opacity = 250
- @sprite_layout[4].y -= 50
- @sprite_layout[5].y += 50
- s = @sprite_layout[4].bitmap
- s.font.italic = true
- s.font.bold = true
- s.font.size = 22-4
- draw_hemming_text(s,377-(45),0,254,36,'Location :') if VX
- draw_hemming_text(s,377-(0),0,254,36,'Location :') if !VX
- s.font.size = 20-4
- s.draw_text((377+92)-(38),2,254,36,"#{map}") if VX
- s.draw_text((377+92)-(0),2,254,36,"#{map}") if !VX
- s = @sprite_layout[5].bitmap
- s.font.italic = true
- s.font.bold = true
- s.font.size = 22-4
- draw_hemming_text(s,9,@resolution[1]-30,254,36,'Gold :')
- s.font.size = 20-4
- s.draw_text(9+60,@resolution[1]-29,204,36,"#{$game_party.gold}")
- @sprite_layout.each_with_index {|s,i| s.z = 5-i}
- @sprite_layout[3].z = 4
- @sprite_layout[4].z = 10
- @sprite_layout[5].z = 10
- end
- #--------------------------------------------------------------------------
- # ● update_sprite_layout
- #--------------------------------------------------------------------------
- def update_sprite_layout
- update_layout_position
- end
- #--------------------------------------------------------------------------
- # * Create Arrow
- #--------------------------------------------------------------------------
- def create_arrow
- @resolution = VX ? [Graphics.width,Graphics.height] : [640,480]
- @sprite_arrow = Sprite.new
- if $arrow_drg_menu.nil?
- bit = $game_system.windowskin_name if !VX
- bit = [windowskin(bit),Rect.new(160,96,32,32)] if !VX
- bit = [Cache.system("Window"),Rect.new(96,80,16,16)] if VX
- @sprite_arrow.bitmap = Bitmap.new(32, 32)
- @sprite_arrow.bitmap.stretch_blt(@sprite_arrow.bitmap.rect,bit[0],bit[1])
- bit = @sprite_arrow.bitmap
- copy = bit.clone
- (0...bit.height).each{|i|(0...bit.width).each{|j|
- bit.set_pixel(bit.width-i-1,j,copy.get_pixel(j,i))}}
- $arrow_drg_menu = bit.dup
- else
- @sprite_arrow.bitmap = $arrow_drg_menu.dup
- end
- @sprite_arrow.mirror = true if VX
- @sprite_arrow.x -= 100
- @sprite_arrow.z = 7
- end
- #--------------------------------------------------------------------------
- # * Create Spriteset
- #--------------------------------------------------------------------------
- def create_spriteset
- @spriteset = Spriteset_Map.new if !VX
- end
- #--------------------------------------------------------------------------
- # * Create Menu
- #--------------------------------------------------------------------------
- def create_menu
- @sprite_menu = []
- @index = 0
- @menu = LiTTleDRAgo::SCENE_MENU
- @menu.each {|a| b = @menu[@index]
- @sprite_menu[@index] = Window_Base.new(-200-50*@index,(48*@index)+5,160,48)
- @sprite_menu[@index].contents = Bitmap.new(160-32,16)
- @sprite_menu[@index].back_opacity = 180
- @sprite_menu[@index].contents.font.size = 18
- @sprite_menu[@index].contents.font.bold = true
- @sprite_menu[@index].contents.font.color =
- @sprite_menu[@index].disabled_color if (b[3] && !condition_eval(b[3]))||
- (b[2] && actors.size == 0)
- @sprite_menu[@index].contents.draw_text(0,0,160-32,16,b[0],1)
- @sprite_menu[@index].z = 6
- @index += 1}
- @index = 0
- @column_max = 1
- @item_max = @sprite_menu.size
- end
- #--------------------------------------------------------------------------
- # * Create Player
- #--------------------------------------------------------------------------
- def create_player
- @sprite_player = []
- actors.each_with_index {|a,i|
- @sprite_player[i] = Window_Base.new(400+240+(30*i),(80*i)+80,240,80)if !VX
- @sprite_player[i] = Window_Base.new(280+240+(30*i),(80*i)+80,240,80)if VX
- @sprite_player[i].contents = Bitmap.new(240-32,80-32)
- @sprite_player[i].back_opacity = 180
- @sprite_player[i].z = 6
- face = windowskin("Hud_Face#{a.id}") rescue '3x234572se3'
- if face == '3x234572se3'
- @sprite_player[i].instance_variable_set(:@placeholderface,true)
- face = sprite_character(a)
- end
- x = 60
- @sprite_player[i].instance_variable_set(:@placeholderx, x)
- @sprite_player[i].contents.font.size = 18
- @sprite_player[i].contents.font.bold = true
- @sprite_player[i].contents.draw_text(x,0-10+16*0,100,32,a.name)
- bitmaphp = create_hp_bar(a,0)
- bitmapsp = create_hp_bar(a,1)
- numberhp = create_hp_number(a,0)
- numbersp = create_hp_number(a,1)
- @sprite_player[i].contents.blt(5,2,face,face.rect)
- @sprite_player[i].contents.blt(x,2+16*1,bitmaphp,bitmaphp.rect)
- @sprite_player[i].contents.blt(x,11,numberhp,numberhp.rect)
- @sprite_player[i].contents.blt(x,2+16*2,bitmapsp,bitmapsp.rect)
- @sprite_player[i].contents.blt(x,27,numbersp,numbersp.rect) }
- @index_player = 0
- end
- #--------------------------------------------------------------------------
- # * Update Player
- #--------------------------------------------------------------------------
- def update_player
- @sprite_player.each_with_index {|s,i| a = actors[i]
- bitmaphp = create_hp_bar(a,0)
- bitmapsp = create_hp_bar(a,1)
- numberhp = create_hp_number(a,0)
- numbersp = create_hp_number(a,1)
- x = s.instance_variable_get(:@placeholderx) || 0
- s.contents.blt(x,2+16*1,bitmaphp,bitmaphp.rect)
- s.contents.blt(x,11,numberhp,numberhp.rect)
- s.contents.blt(x,2+16*2,bitmapsp,bitmapsp.rect)
- s.contents.blt(x,27,numbersp,numbersp.rect)
- if s.instance_variable_get(:@placeholderface) #&& !VX
- face = sprite_character(a)
- s.contents.blt(5,2,face,face.rect)
- end }
- @timer = (@timer||0) + 1
- if !@timer || @timer % 8 == 0
- @pattern = (@pattern||0) + 1
- @pattern = 0 if @pattern >= 4
- end
- end
- #--------------------------------------------------------------------------
- # * Create HP Bar
- #--------------------------------------------------------------------------
- def create_hp_bar(a,type=0)
- @flow = (@flow||0) + 1
- hpbar = windowskin(LiTTleDRAgo::BAR_IMAGES)
- hpmet = type == 0 ? windowskin(LiTTleDRAgo::HP_METER_IMAGE) :
- windowskin(LiTTleDRAgo::SP_METER_IMAGE)
- sp = VX ? a.mp/a.maxmp : a.sp/a.maxsp
- hprect = type == 0 ? Rect.new(@flow,0,hpbar.width*a.hp/a.maxhp,hpbar.height) :
- Rect.new(@flow,0,hpbar.width*sp,hpbar.height)
- @flow = 0 if @flow >= hprect.width*1.65
- bit = Bitmap.new(hpbar.width, hpbar.height)
- bit.blt(0,0,hpbar,hpbar.rect)
- bit.blt(3,2,hpmet,hprect)
- bitmaphp = Bitmap.new(100, hpbar.height)
- bitmaphp.stretch_blt(bitmaphp.rect, bit, bit.rect)
- return bitmaphp
- end
- #--------------------------------------------------------------------------
- # * Create HP Number
- #--------------------------------------------------------------------------
- def create_hp_number(actor,type=0)
- number_image = windowskin(LiTTleDRAgo::NUMBER_IMAGE)
- hp_number = Bitmap.new(number_image.width,number_image.height)
- im_cw = hp_number.width / 10
- im_ch = hp_number.height / 2
- hp_src_rect = Rect.new(im_cw,0, im_cw, im_ch)
- sp = VX ? [actor.mp,actor.maxmp] : [actor.sp,actor.maxsp]
- hp_number_text = type == 0 ? actor.hp.abs.to_s.split(//) :
- sp[0].abs.to_s.split(//)
- lowhp2 = type == 0 ? actor.maxhp * 30 / 100 : sp[1] * 30 / 100
- hp_health = hp_number_text.join.to_i < lowhp2 ? im_ch : 0
- (0..hp_number_text.size-1).each {|r|
- hp_src_rect = Rect.new(im_cw*hp_number_text[r].to_i,hp_health,im_cw,im_ch)
- hp_number.blt(20 +((im_cw-7)*r), 0, number_image, hp_src_rect) }
- return hp_number
- end
- #--------------------------------------------------------------------------
- # ● sprite_character
- #--------------------------------------------------------------------------
- def sprite_character(actor)
- if VX
- bit = cache.character(actor.character_name)
- sign = actor.character_name[/^[\!\$]./]
- if sign != nil and sign.include?('$')
- cw = [bit.width / 3,bit.height / 4]
- else
- cw = [bit.width / 12,bit.height / 8]
- end
- index = actor.character_index
- pattern = (@pattern||0) < 3 ? (@pattern||0) : 1
- sx = [(index % 4 * 3 + pattern) * cw[0],
- (index / 4 * 4 + (2 - 2) / 2) * cw[1]]
- rect = Rect.new(sx[0], sx[1], cw[0], cw[1])
- bitmap = Bitmap.new(*cw)
- bitmap.blt(0,0,bit,rect)
- return bitmap
- end
- bit = cache.character(actor.character_name,0) if !VX
- cw = [bit.width / 4, bit.height / 4]
- sx = [(@pattern||0) * cw[0], (2 - 2) / 2 * cw[1]]
- rect = Rect.new(sx[0], sx[1], cw[0], cw[1])
- bitmap = Bitmap.new(*cw)
- bitmap.blt(0,0,bit,rect)
- return bitmap
- end
- #--------------------------------------------------------------------------
- # ● Draw Hemming Text
- #--------------------------------------------------------------------------
- def draw_hemming_text(obj, x, y, w, h, text, align = 0)
- original_color = obj.font.color.dup
- obj.font.color = Color.new(0,0,0,255)
- obj.draw_text(x , y , w, h, text.to_s, align)
- obj.draw_text(x , y+2, w, h, text.to_s, align)
- obj.draw_text(x+2, y+2, w, h, text.to_s, align)
- obj.draw_text(x+2, y , w, h, text.to_s, align)
- obj.font.color = original_color
- obj.draw_text(x+1, y+1, w, h, text.to_s, align)
- end
- #--------------------------------------------------------------------------
- # ● update_premenu
- #--------------------------------------------------------------------------
- def update_premenu
- while @sprite_menu[-1].x < 50 && @sprite_arrow.x < 5
- @sprite_menu.each {|s| s.x = [s.x+40,50].min }
- @sprite_player.each {|s| s.x = [s.x-30,400].max } if !VX
- @sprite_player.each {|s| s.x = [s.x-30,280].max } if VX
- @sprite_arrow.x = [@sprite_arrow.x+3,5].min
- @sprite_arrow.y = 16
- update_layout_position
- update_grafis
- end
- update_arrow
- while @sprite_layout[4].y != 0
- update_layout_position
- update_grafis
- @sprite_layout[4].y = [@sprite_layout[4].y+1,0].min
- @sprite_layout[5].y = [@sprite_layout[5].y-1,0].max
- end
- end
- #--------------------------------------------------------------------------
- # ● dispose_premenu
- #--------------------------------------------------------------------------
- def dispose_premenu
- while @sprite_menu[-1].x > -200
- @sprite_menu.each_with_index {|s,i| s.x = s.x-(40+i*10) }
- @sprite_player.each {|s| s.x = s.x+40 }
- @sprite_layout[4].y -= 5
- @sprite_layout[5].y += 5
- @sprite_arrow.x -= 15
- update_layout_position
- update_grafis
- end
- end
- #--------------------------------------------------------------------------
- # ● dispose_freeze
- #--------------------------------------------------------------------------
- def dispose_freeze
- Graphics.freeze
- end
- #--------------------------------------------------------------------------
- # ● Frame Dispose
- #--------------------------------------------------------------------------
- def dispose
- @all_sprite = [@sprite_arrow,@sprite_menu,@sprite_player,@spriteset,@sprite_layout]
- @all_sprite.flatten.compact.each {|s|s.dispose}
- end
- #--------------------------------------------------------------------------
- # ● update_arrow
- #--------------------------------------------------------------------------
- def update_arrow
- if !@status_active
- @sprite_arrow.x = [@sprite_arrow.x-10, 5].max
- @sprite_arrow.y = @sprite_menu[@index].y + 10
- @sprite_menu.each {|s| s.y -= 10} if @sprite_arrow.y > @resolution[1]-(40+34)
- @sprite_menu.each {|s| s.y += 10} if @sprite_arrow.y < 0+10
- else
- @sprite_arrow.x = [@sprite_arrow.x+10,@sprite_player[@index_player].x-40].min
- @sprite_arrow.y = @sprite_player[@index_player].y + 15
- @sprite_player.each {|s| s.y -= 10} if @sprite_arrow.y > @resolution[1]-60
- @sprite_player.each {|s| s.y += 10} if @sprite_arrow.y < 0+(10+34)
- end
- update_sprite_layout
- end
- #--------------------------------------------------------------------------
- # ● update_layout_position
- #--------------------------------------------------------------------------
- def update_layout_position
- @sprite_layout[0].oy += 1
- @sprite_layout[1].oy -= 1
- @sprite_layout[2].ox += 1
- @sprite_layout[2].oy += 1
- end
- #--------------------------------------------------------------------------
- # ● condition_eval
- #--------------------------------------------------------------------------
- def condition_eval(ev='')
- return true if ev.nil?
- return ev if !ev.is_a?(String)
- return eval (ev)
- end
- #--------------------------------------------------------------------------
- # ● se_play
- #--------------------------------------------------------------------------
- def se_play(type)
- a = [$game_system,$data_system]
- case type
- when :cursor : VX ? Sound.play_cursor : a[0].se_play(a[1].cursor_se)
- when :decision : VX ? Sound.play_decision : a[0].se_play(a[1].decision_se)
- when :cancel : VX ? Sound.play_cancel : a[0].se_play(a[1].cancel_se)
- when :buzzer : VX ? Sound.play_buzzer : a[0].se_play(a[1].buzzer_se)
- end
- end
- #--------------------------------------------------------------------------
- # ● update_index
- #--------------------------------------------------------------------------
- def update_index
- if Input.repeat?(Input::DOWN)
- if (@column_max == 1 && Input.trigger?(Input::DOWN)) ||
- @index < @item_max - @column_max
- se_play(:cursor)
- !@status_active ? @index = (@index + @column_max) % @item_max :
- @index_player = (@index_player + @column_max) % @item_max
- end
- return
- end
- if Input.repeat?(Input::UP)
- if (@column_max == 1 && Input.trigger?(Input::UP)) ||
- @index >= @column_max
- se_play(:cursor)
- !@status_active ? @index = (@index - @column_max) % @item_max :
- @index_player = (@index_player - @column_max) % @item_max
- end
- return
- end
- if Input.trigger?(Input::B)
- se_play(:cancel)
- if !@status_active
- $scene = Scene_Map.new
- else
- @status_active = false
- @item_max = @sprite_menu.size
- end
- end
- if Input.trigger?(Input::C)
- if !condition_eval(@menu[@index][3]) ||
- (@menu[@index][2] && @sprite_player.size == 0)
- return se_play(:buzzer)
- end
- if !@status_active
- if !@menu[@index][2] || @sprite_player.size == 1
- se_play(:decision)
- $scene = @menu[@index][1].new
- elsif @menu[@index][2] == :actor
- se_play(:decision)
- @status_active = true
- @item_max = @sprite_player.size
- elsif @menu[@index][2].is_a?(Array)
- se_play(:decision)
- $scene = @menu[@index][1].new(*@menu[@index][2])
- end
- else
- se_play(:decision)
- @status_active = false
- @sprite_arrow.opacity = 0
- $scene = @menu[@index][1].new(@index_player)
- end
- end
- end
- end
- $drago_simple_cms = true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement