Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- # [Xp/Vx-VxA] DRG - Mouse Gesture
- # Version: 1.50
- # Author : LiTTleDRAgo
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- module LiTTleDRAgo
- module MouseGestures
- VXA = defined?(Window_BattleActor)
- #==============================================================================
- # ** CONFIGURATION
- #==============================================================================
- ALLOWED_SCENE = ['Scene_Map','Scene_Menu','Scene_Item',
- 'Scene_Skill','Scene_Equip','Scene_Status',
- 'Scene_File','Scene_Load']
- # Insert name scene you want to activate mouse gesture
- # Enter all the condition and result you want here
- def result_mouse_gesture(result)
- case result
- when ['down']
- change_scene (Scene_Item)
- when ['right','up','left','down','right']
- change_scene (Scene_Equip)
- when ['left','down','right','down','left']
- change_scene (Scene_Skill)
- when ['left','down','right','down','left','up']
- change_scene (Scene_Status)
- when ['downright','up','downleft']
- unless [Scene_Map,Scene_Title,Scene_Gameover,Scene_Load].include?(scene)
- change_scene (Scene_Map)
- end
- end
- end
- # Enter all condition to disable mouse gesture here
- def forbid_mouse_gestures
- return false if !scene.is_a?(Scene_Map)
- if defined?(Window_ActorCommand) # If VX or VXA
- return true if !$game_player.movable?
- return false
- end # If XP
- return true if $game_system.map_interpreter.running?
- return true if $game_player.move_route_forcing
- return true if $game_temp.message_window_showing
- end
- # Enter all condition to ignore scene changing here
- def ignore_changing_scene
- return true if scene.is_a?(Scene_Battle)
- return true if scene.is_a?(Scene_Load)
- return true if scene.is_a?(Scene_Title)
- return true if scene.is_a?(Scene_Map) && forbid_mouse_gestures
- end
- #==============================================================================
- # ** CONFIG END
- #==============================================================================
- def update_mouse_gestures
- return if forbid_mouse_gestures
- clear_mouse_gesture if @mouse_gesture.nil?
- if Mouse.dragging?
- point = @mouse_gesture[0][@mouse_gesture[4]]
- if point == nil || point.disposed?
- @mouse_gesture[0][@mouse_gesture[4]] = Sprite.new
- end
- @mouse_gesture[0][@mouse_gesture[4]].x = @mouse_gesture[4] == 0 ?
- Mouse.drag_coor[0] : Mouse.x
- @mouse_gesture[0][@mouse_gesture[4]].y = @mouse_gesture[4] == 0 ?
- Mouse.drag_coor[1] : Mouse.y
- recog_mouse_gesture if @mouse_gesture[6] == Mouse.pos
- @mouse_gesture[6] = Mouse.pos if @mouse_gesture[6] != Mouse.pos
- @mouse_gesture[4] += 1
- else
- if !@mouse_gesture[0].empty?
- @mouse_gesture[1].each_with_index { |s,i|
- @mouse_gesture[1][i-1] = nil if i > 0 && s == @mouse_gesture[1][i-1] }
- result_mouse_gesture(@mouse_gesture[1].compact)
- @mouse_gesture[0].each {|i| i.dispose }
- @mouse_gesture[2].each {|i| i.dispose }
- clear_mouse_gesture
- end
- end
- end
- def change_scene(some_scene=nil)
- return if ignore_changing_scene
- VXA ? SceneManager.call(some_scene) : $scene = some_scene.new
- end
- def scene() VXA ? SceneManager.scene : $scene end
- def clear_mouse_gesture() @mouse_gesture = [[],[],[],0,0,0] end
- def draw_mouse_line(start_x,start_y,end_x,end_y,
- start_color,width=1,end_color=start_color)
- point = @mouse_gesture[2][@mouse_gesture[3]]
- if point == nil || point.disposed?
- @mouse_gesture[2][@mouse_gesture[3]] = Sprite.new
- @mouse_gesture[2][@mouse_gesture[3]].bitmap = Bitmap.new(640,480)
- @mouse_gesture[2][@mouse_gesture[3]].z = 9999
- end
- distance = (start_x - end_x).abs + (start_y - end_y).abs
- if end_color == start_color
- (1..distance).each {|i|
- x = (start_x + 1.0 * (end_x - start_x) * i / distance).to_i
- y = (start_y + 1.0 * (end_y - start_y) * i / distance).to_i
- @mouse_gesture[2][@mouse_gesture[3]].bitmap.fill_rect(x, y, width,
- width, start_color)}
- else
- (1..distance).each {|i|
- x = (start_x + 1.0 * (end_x - start_x) * i / distance).to_i
- y = (start_y + 1.0 * (end_y - start_y) * i / distance).to_i
- r = start_color.red*(distance-i)/distance+end_color.red*i/distance
- g = start_color.green*(distance-i)/distance+end_color.green*i/distance
- b = start_color.blue*(distance-i)/distance+end_color.blue*i/distance
- a = start_color.alpha*(distance-i)/distance+end_color.alpha*i/distance
- @mouse_gesture[2][@mouse_gesture[3]].bitmap.fill_rect(x, y, width,
- width, Color.new(r, g, b, a))}
- end
- @mouse_gesture[3] += 1
- end
- def recog_mouse_gesture
- awal = @mouse_gesture[0][@mouse_gesture[5]]
- akhir = @mouse_gesture[0][@mouse_gesture[4]]
- draw_mouse_line(awal.x,awal.y, akhir.x,akhir.y, Color.new(255,0,0),3)
- if awal.x - akhir.x > 50 && (awal.y - akhir.y).abs < 50
- @mouse_gesture[1] << 'left'
- end
- if awal.x - akhir.x < -50 && (awal.y - akhir.y).abs < 50
- @mouse_gesture[1] << 'right'
- end
- if awal.y - akhir.y > 50 && (awal.x - akhir.x).abs < 50
- @mouse_gesture[1] << 'up'
- end
- if awal.y - akhir.y < -50 && (awal.x - akhir.x).abs < 50
- @mouse_gesture[1] << 'down'
- end
- if awal.x - akhir.x > 50 && awal.y - akhir.y > 50
- @mouse_gesture[1] << 'upleft'
- end
- if awal.x - akhir.x < -50 && awal.y - akhir.y > 50
- @mouse_gesture[1] << 'upright'
- end
- if awal.x - akhir.x > 50 && awal.y - akhir.y < -50
- @mouse_gesture[1] << 'downleft'
- end
- if awal.x - akhir.x < -50 && awal.y - akhir.y < -50
- @mouse_gesture[1] << 'downright'
- end
- @mouse_gesture[5] = @mouse_gesture[4]
- end
- end
- end
- #==============================================================================
- # ** Scene_Something
- #------------------------------------------------------------------------------
- # This class is definition from All Class
- #==============================================================================
- LiTTleDRAgo::MouseGestures::ALLOWED_SCENE.each {|kelas| eval "
- class #{kelas}
- include LiTTleDRAgo::MouseGestures
- alias drg_143_upd update unless method_defined?(:drg_143_upd) ||
- !method_defined?(:update)
- def update
- drg_143_upd
- update_mouse_gestures
- end
- end#"}
- #==============================================================================
- # ** Input
- #------------------------------------------------------------------------------
- # This module performs key input processing
- #==============================================================================
- module Input
- class << self
- if !method_defined?(:glitch_input_keys_update)
- raise "This Script needs Glitchfinder's Key Input Module and "+
- "Glitchfinder's Mouse Input Module"
- end
- end
- end
- $drago_mouse_gestures = true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement