Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- # [Xp/Vx-VXA] Event Interaction
- # Version: 2.40
- # Author : LiTTleDRAgo
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- module LiTTleDRAgo
- module Event_Interaction
- BUTTON_ACTION_PREV = Input::L
- BUTTON_ACTION_NEXT = Input::R
- BUTTON_ACTION_CONFIRM = Input::C
- EVENT_INTERACT_SWITCH = false
- VX = defined?(Window_ActorCommand)
- VXA = defined?(Window_BattleActor)
- end
- end
- EVENT_INTERACTION =<<_SCRIPT_
- #==============================================================================
- # ** Scene_Map
- #------------------------------------------------------------------------------
- # This class performs map screen processing.
- #==============================================================================
- class Scene_Map
- alias_method :drg136_main, :main unless method_defined?(:drg136_main)
- alias_method :drg136_upd, :update unless method_defined?(:drg136_upd)
- attr_accessor :event_interaction
- def main
- @event_interaction = [Window_EventInteraction.new]
- @event_interaction[6] = LiTTleDRAgo::Event_Interaction::VX
- drg136_main
- @event_interaction[0].dispose
- end
- def update
- drg136_upd
- event_interaction_update
- end
- def event_interaction_update
- cond = @event_interaction[6] ? !$game_player.movable? :
- ($game_system.map_interpreter.running? or
- $game_player.move_route_forcing or
- $game_temp.message_window_showing)
- @event_interaction[0].update_position
- unless cond
- @event_interaction[0].update
- event = facing_object([0,1,2],0) || facing_object([0,1,2],1)
- event_interaction_refresh(event)
- end
- end
- def event_interaction_refresh(e)
- @event_interaction[5] = $game_player.direction
- set_command_object(e,[],'',0)
- event = e ? e.list.select {|list| [108,408].include?(list.code)} : []
- notes = event.collect {|list| list.parameters[0]}.join
- var_eventint_process(notes)
- return
- event.list.each {|list| next unless [108,408].include?(list.code)
- var_eventint_process(list.parameters[0])} if event
- end
- def var_eventint_process(note)
- return if (note || '') == ''
- @event_interaction[2] = $1.split(/,/).uniq if note =~ /<Action = (.+?)>/i
- @event_interaction[3] = $1.to_s if note =~ /<Object = (.+?)>/i
- end
- def set_command_object(event=nil,command=[],object='',post=0)
- @event_interaction[1] = event
- @event_interaction[2] = command
- @event_interaction[3] = object
- @event_interaction[4] = post
- end
- def facing_object(triggers,type)
- coor,dir = [$game_player.x,$game_player.y],$game_player.direction
- new_x = coor[0] + (dir == 6 ? 1 : dir == 4 ? -1 : 0)
- new_y = coor[1] + (dir == 2 ? 1 : dir == 8 ? -1 : 0)
- type = type+2 if @event_interaction[6]
- case type
- when 0
- $game_map.events.values.each {|event|
- if [event.x.round,event.y.round] == [new_x.round,new_y.round] &&
- triggers.include?(event.trigger) &&
- !event.jumping? && !event.over_trigger?
- return event
- end }
- when 1
- $game_map.events.values.each {|event|
- if event.x == coor[0] && event.y == coor[1] &&
- triggers.include?(event.trigger) &&
- !event.jumping? && event.over_trigger?
- return event
- end }
- when 2
- front_x = $game_map.x_with_direction(coor[0], dir)
- front_y = $game_map.y_with_direction(coor[1], dir)
- $game_map.events_xy(front_x, front_y).each {|event|
- if triggers.include?(event.trigger) && event.priority_type == 1
- return event
- end}
- if $game_map.counter?(front_x, front_y)
- front_x = $game_map.x_with_direction(front_x, dir)
- front_y = $game_map.y_with_direction(front_y, dir)
- $game_map.events_xy(front_x, front_y).each {|event|
- if triggers.include?(event.trigger) && event.priority_type == 1
- return event
- end}
- end
- when 3
- $game_map.events_xy(coor[0], coor[1]).each {|event|
- if [1,2].include?(event.trigger) and event.priority_type == 1
- return event
- end }
- end
- return nil
- end
- end
- #==============================================================================
- # ** Window_EventInteraction
- #------------------------------------------------------------------------------
- # This window is used to select the choice when interacting with event
- #==============================================================================
- class Window_EventInteraction < Window_Base
- MODULE = LiTTleDRAgo::Event_Interaction
- BUTTON_ACTION_PREV = MODULE::BUTTON_ACTION_PREV
- BUTTON_ACTION_NEXT = MODULE::BUTTON_ACTION_NEXT
- BUTTON_ACTION_CONFIRM = MODULE::BUTTON_ACTION_CONFIRM
- ENABLE_SWITCH = MODULE::EVENT_INTERACT_SWITCH
- def initialize
- super( (640 - init_width) / 2, 0, init_width, init_height)
- self.contents = Bitmap.new(width - 32, height - 32)
- self.visible = false
- self.opacity = 128
- @index = 0
- end
- def init_width() 240 end
- def init_height() 64 end
- def event() scene.event_interaction[1] || 0 end
- def command_text(index=0) object(@command[index]) end
- def enabled?
- return true if !ENABLE_SWITCH
- return $game_switches[ENABLE_SWITCH]
- end
- def object(obj=scene.event_interaction[3])
- text = obj.to_s
- text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
- text.gsub!(/\\[Nn]\[([0-9]+)\]/) {
- $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : '' }
- text = convert_escape_characters(text.dup) if MODULE::VXA
- return text
- end
- def scene
- MODULE::VXA ? SceneManager.scene : $scene
- end
- def update
- return unless scene.is_a?(Scene_Map)
- @command = scene.event_interaction[2]
- interpreter = MODULE::VX ? $game_map.interpreter.running? :
- $game_system.map_interpreter.running?
- return self.visible = false if interpreter || (@command || []).empty? ||
- @index == nil || event == 0 || object == ''
- self.visible = enabled?
- @index = @command[@index].nil? ? 0 : @index
- if self.visible
- update_position
- if Input.repeat?(BUTTON_ACTION_PREV)
- sound_play('cursor')
- @index = (@index - 1) % @command.size
- elsif Input.repeat?(BUTTON_ACTION_NEXT)
- sound_play('cursor')
- @index = (@index + 1) % @command.size
- elsif Input.repeat?(BUTTON_ACTION_CONFIRM)
- refresh
- if self.contents.font.color == normal_color
- sound_play('decision')
- $interaction = @command[@index].downcase
- $object_event = object.downcase
- self.visible = false
- event.start if event != 0
- scene.event_interaction[2] = []
- else
- $interaction = nil
- sound_play('buzzer')
- end
- return
- end
- refresh
- end
- end
- def update_position
- return unless self.visible
- return self.visible = false if event == 0
- if scene.event_interaction[4] == 0
- self.x = [[event.screen_x - self.width/2, 0].max, 640 - self.width].min
- self.y = [[event.screen_y-32-self.height, 0].max, 480 - self.height].min
- else
- x = scene.event_interaction[4][0].to_f.round
- y = scene.event_interaction[4][1].to_f.round
- screen_x=(x * 128 - $game_map.display_x + 3) / 4 + 16
- screen_y=(y * 128 - $game_map.display_y + 3) / 4 + 32
- self.x = [[screen_x - self.width/2, 0].max, 640 - self.width].min
- self.y = [[screen_y-32-self.height, 0].max, 480 - self.height].min
- end
- end
- def sound_play(se)
- case se
- when 'cursor'
- MODULE::VX ? Sound.play_cursor :
- $game_system.se_play($data_system.cursor_se)
- when 'decision'
- MODULE::VX ? MODULE::VXA ? Sound.play_ok :
- Sound.play_decision : $game_system.se_play($data_system.decision_se)
- when 'buzzer'
- MODULE::VX ? Sound.play_buzzer :
- $game_system.se_play($data_system.buzzer_se)
- end
- end
- def refresh
- return if @index.nil? || @command.nil? || !scene.is_a?(Scene_Map)
- return self.visible = false if event == 0
- text = command_text(@index)+' '+object
- if text.length >= 20 && !@changed
- self.contents.dispose
- self.contents = Bitmap.new(width+100 - 32, height - 32)
- self.width += 100
- @changed = true
- elsif text.length < 20 && @changed
- self.contents.dispose
- self.contents = Bitmap.new(width-100 - 32, height - 32)
- self.width -= 100
- @changed = false
- end
- cw,ch = self.width - 32, self.height - 32
- rect = Rect.new(0, 0, cw, ch)
- font = self.contents.font.size
- self.contents.font.size = font
- self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
- self.contents.font.color = object == '' ? disabled_color : normal_color
- self.contents.draw_text(0, 0, cw, 32, text,1)
- self.contents.font.size -= 6
- self.contents.draw_text(4, 0, cw, 32, '<Q', 0) if BUTTON_ACTION_PREV
- self.contents.draw_text(-3, 0, cw, 32, 'W>', 2) if BUTTON_ACTION_NEXT
- self.contents.font.size = font
- end
- end
- #==============================================================================
- # ** Game_Player
- #------------------------------------------------------------------------------
- # This class handles maps. It includes event starting determinants and map
- # scrolling functions. The instance of this class is referenced by $game_map.
- #==============================================================================
- class Game_Player
- MODULE = LiTTleDRAgo::Event_Interaction
- if MODULE::VX
- alias drg_136_chk check_action_event unless method_defined?(:drg_136_chk)
- def check_action_event
- scene = MODULE::VXA ? SceneManager.scene : $scene
- return if scene.is_a?(Scene_Map) && !scene.event_interaction[2].empty?
- drg_136_chk
- end
- end
- end
- #==============================================================================
- # ** Game_Interpreter
- #------------------------------------------------------------------------------
- # An interpreter for executing event commands. This class is used within the
- # Game_Map, Game_Troop, and Game_Event classes.
- #==============================================================================
- Klass = LiTTleDRAgo::Event_Interaction::VX ? Game_Interpreter : Interpreter
- class Klass
- VXA = LiTTleDRAgo::Event_Interaction::VXA
- alias drg138_com_end command_end unless VXA || method_defined?(:drg138_com_end)
- def command_end
- drg138_com_end
- s = VXA ? SceneManager.scene : $scene
- event = s.event_interaction[1]
- $interaction, $object_event = nil, '' if event && event.id == @event_id
- end
- end
- _SCRIPT_
- eval(EVENT_INTERACTION)
- $drago_event_interaction = true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement