RPGXP 스크립트
2013.09.30 04:26

네코에서 되는 마우스 스크립트

조회 수 1675 추천 수 0 댓글 13
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
#============================================================================== 
# ** Modules.Mouse Input (7.0)              By Near Fantastica & SephirothSpawn
# Modify : 휴리드
# Description : 필요없는 부분 제거 여러 함수 추가
#
#사용 방법
#
#Mouse.pos_x = 마우스의 x좌표를 가져온다
#Mouse.pos_y = 마우스의 y좌표를 가져온다
#클릭( x좌표, y좌표, 가로, 세로) = 마우스가 박스안에서 클릭을 하면 true값을 리턴해준다
#위에( x좌표, y좌표, 가로, 세로) = 마우스가 박스안에 있으면 true값을 리턴해준다
#==============================================================================
module Mouse
  #--------------------------------------------------------------------------
  # * Mouse to Input Triggers
  #
  #   key => Input::KeyCONSTANT (key: 0 - Left, 1 - Middle, 2 - Right)
  #--------------------------------------------------------------------------
  Mouse_to_Input_Triggers = {0 => Input::C, 1 => Input::B, 2 => Input::A}
  #--------------------------------------------------------------------------
  # * API Declaration
  #--------------------------------------------------------------------------
  GAKS          = Win32API.new('user32',    'GetAsyncKeyState', 'i',     'i')
  GSM           = Win32API.new('user32',    'GetSystemMetrics', 'i',     'i')
  Cursor_Pos    = Win32API.new('user32',    'GetCursorPos',     'p',     'i')
  $ShowCursor   = Win32API.new('user32',    'ShowCursor',       'i',     'l')
  Scr2cli       = Win32API.new('user32',    'ScreenToClient',   %w(l p), 'i')
  Client_rect   = Win32API.new('user32',    'GetClientRect',    %w(l p), 'i')
  Findwindow    = Win32API.new('user32',    'FindWindowA',      %w(p p), 'l')
  Readini       = Win32API.new('kernel32',  'GetPrivateProfileStringA', 
                               %w(p p p p l p), 'l')
                               
  # if graphical effects turned on, show fancy cursor
  $ShowCursor.call($game_mouse ? 0 : 1)
  
  @triggers     =   [[0, 1], [0, 2], [0, 4]] 
  @old_pos      =   0
  @pos_i        =   0
    
  #--------------------------------------------------------------------------
  # * Mouse Grid Position
  #--------------------------------------------------------------------------
  def self.grid    
    # Return Nil if Position is Nil
    return nil if @pos.nil?
    
    # Get X & Y Locations  
    x = (@pos[0] + $game_map.display_x / 4) / 32
    y = (@pos[1] + $game_map.display_y / 4) / 32
    
    # Vehicle Stuff
    $mouse_x = x
    $mouse_y = y 
    
    # Return X & Y
    return [x, y]
    
  end
  #--------------------------------------------------------------------------
  # * Mouse Position
  #--------------------------------------------------------------------------
  def self.position
    return @pos == nil ? [0, 0] : @pos
  end
  #--------------------------------------------------------------------------
  # * Mouse Global Position
  #--------------------------------------------------------------------------
  def self.global_pos
    # Packs 0 Position
    pos = [0, 0].pack('ll')
    # Returns Unpacked Cursor Position Call
    return Cursor_Pos.call(pos) == 0 ? nil : pos.unpack('ll')
  end
  
  #--------------------------------------------------------------------------
  # * Screen to Client
  #--------------------------------------------------------------------------
  def self.screen_to_client(x=0, y=0)
    pos = [x, y].pack('ll')
    return Scr2cli.call(self.hwnd, pos) == 0 ? nil : pos.unpack('ll')
  end  
    
  #--------------------------------------------------------------------------
  # * Mouse Position
  #-------------------------------------------------------------------------- 
  def self.pos

    global_pos = [0, 0].pack('ll')    
    gx, gy = Cursor_Pos.call(global_pos) == 0 ? nil : global_pos.unpack('ll')

    local_pos = [gx, gy].pack('ll')
    x, y = Scr2cli.call(self.hwnd, local_pos) == 0 ? nil : local_pos.unpack('ll')
    
    # Begins Test
    begin
      # Return X & Y or Nil Depending on Mouse Position
      if (x >= 0 && y >= 0 && x <= 640 && y <= 480)
        return x, y
      else
        return -20, -20
      end
    rescue
      return 0, 0 #nil
    end
    
  end  
    
  #--------------------------------------------------------------------------
  # * Update Mouse Position
  #--------------------------------------------------------------------------
  def self.update
    
    # Update Position
    old_pos = @pos
    @pos = self.pos
    
    # agf = hide system mouse
#    if !$mouse_sprite.visible && old_pos != @pos
#      $mouse_sprite.visible = true
#    end
    
    # when mouse leaves game window, show system mouse
    if old_pos != [-20, -20] && @pos == [-20, -20]
      $ShowCursor.call(1)
    # when mouse is in game window, show custom mouse if it's turned on
    elsif old_pos == [-20, -20] && @pos != [-20, -20]
      $ShowCursor.call($game_mouse ? 0 : 1)
    end

    # Update Triggers
    for i in @triggers
      # Gets Async State
      n = GAKS.call(i[1])
      # If 0 or 1
      if [0, 1].include?(n)
        i[0] = (i[0] > 0 ? i[0] * -1 : 0)
      else
        i[0] = (i[0] > 0 ? i[0] + 1 : 1)
      end
    end
    
  end
  
  
    #quint
  def self.pos_y
    y = (@pos[1])# + $game_map.display_y / 4)
    return y
  end
  
  def self.pos_x
    x = (@pos[0])# + $game_map.display_x / 4)
    return x
  end
  
  
  #--------------------------------------------------------------------------
  # * Trigger?
  #     id : 0:Left, 1:Right, 2:Center
  #--------------------------------------------------------------------------
  def self.trigger?(id = 0)
    
    #only user trigger if in range of screen
    pos = self.pos
    if pos != [-20,-20]
    
    case id
      when 0  # Left
        return @triggers[id][0] == 1
      when 1  # Right (only when menu enabled)
        
        #quint edit: or else can't close load menu in title screen
        if $ttm_title_screen == true
          if @triggers[1][0] == 1 #&& !$game_system.menu_disabled
            return @triggers[id][0] == 1      
          end
        else
          if @triggers[1][0] == 1 && !$game_system.menu_disabled
            return @triggers[id][0] == 1      
          end
        end
        
      when 2  # Center
        return @triggers[id][0] == 1
    end    
    
    end
    
  end
  #--------------------------------------------------------------------------
  # * Repeat?
  #     id : 0:Left, 1:Right, 2:Center
  #--------------------------------------------------------------------------
  def self.repeat?(id = 0)
    if @triggers[id][0] <= 0
      return false
    else
      return @triggers[id][0] % 5 == 1 && @triggers[id][0] % 5 != 2
    end
  end
  #--------------------------------------------------------------------------
  # * Screen to Client
  #--------------------------------------------------------------------------
  def self.screen_to_client(x=0, y=0)
    # Pack X & Y
    pos = [x, y].pack('ll')
    # Return Unpacked Position or Nil
    return Scr2cli.call(self.hwnd, pos) == 0 ? nil : pos.unpack('ll')
  end
  #--------------------------------------------------------------------------
  # * Hwnd - window handle
  #--------------------------------------------------------------------------
  def self.hwnd
    if @hwnd.nil?
      # Finds Game Name from ini file
      game_name = "" * 256
      Readini.call('Game', 'Title', '', game_name, 255, ".\Game.ini")
      game_name.delete!("")
      # Finds Window
      @hwnd = Findwindow.call('RGSS Player', game_name)
    end
    return @hwnd
  end
  #--------------------------------------------------------------------------
  # * Client Size
  #--------------------------------------------------------------------------
  def self.client_size
    # Packs Empty Rect
    rect = [0, 0, 0, 0].pack('l4')
    # Gets Game Window Rect
    Client_rect.call(self.hwnd, rect)
    # Unpacks Right & Bottom
    right, bottom = rect.unpack('l4')[2..3]
    # Returns Right & Bottom
    return right, bottom
  end
end

#==============================================================================
# ** Input
#==============================================================================

class << Input
  #------------------------------------------------------------------------
  # * Alias Listings
  #------------------------------------------------------------------------
  unless self.method_defined?(:seph_mouse_input_update)
    alias_method :seph_mouse_input_update,   :update
    alias_method :seph_mouse_input_trigger?, :trigger?
    alias_method :seph_mouse_input_repeat?,  :repeat?
  end
  #------------------------------------------------------------------------
  # * Frame Update
  #------------------------------------------------------------------------
  def update
    # Update Mouse
    Mouse.update
    # Original Update
    seph_mouse_input_update
  end
  #--------------------------------------------------------------------------
  # * Trigger? Test
  #--------------------------------------------------------------------------
  def trigger?(constant)
    # Return true if original test is true
    return true if seph_mouse_input_trigger?(constant)
    # If Mouse Position isn't Nil
    unless Mouse.pos.nil?
      # If Mouse Trigger to Input Trigger Has Constant
      if Mouse::Mouse_to_Input_Triggers.has_value?(constant)
        # Return True if Mouse Triggered
        mouse_trigger = Mouse::Mouse_to_Input_Triggers.index(constant)
        return true if Mouse.trigger?(mouse_trigger)      
      end
    end
    # Return False
    return false
  end
  #--------------------------------------------------------------------------
  # * Repeat? Test
  #--------------------------------------------------------------------------
  def repeat?(constant)
    # Return true if original test is true
    return true if seph_mouse_input_repeat?(constant)
    # If Mouse Position isn't Nil
    unless Mouse.pos.nil?
      # If Mouse Trigger to Input Trigger Has Constant
      if Mouse::Mouse_to_Input_Triggers.has_value?(constant)
        # Return True if Mouse Triggered
        mouse_trigger = Mouse::Mouse_to_Input_Triggers.index(constant)     
        return true if Mouse.repeat?(mouse_trigger)
      end
    end
    # Return False
    return false
  end
end
def 위에(x, y, w, h)
  if (Mouse.pos_x > x and Mouse.pos_x < x + w)&& (Mouse.pos_y > y and Mouse.pos_y < y + h)
      return true
  end
end
def 클릭(x, y, w, h)
  if Mouse.trigger?(0)
  if (Mouse.pos_x > x and Mouse.pos_x < x + w)&& (Mouse.pos_y > y and Mouse.pos_y < y + h)
      return true
  end
end
end





?

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수 추천 수
188 RPGXP 스크립트 공포게임에 장비착용메뉴 3  운 2014.08.24 1420 0
187 유니티 스크립트 구간 루프 음악 스크립트 맛난호빵 2015.08.24 232 0
186 RPGXP 스크립트 그레고리우스력 원리. 1 협객 2011.06.22 2506 0
185 RPGXP 스크립트 그레고리우스력 원리. 협객 2011.06.22 2752 0
184 RPGXP 스크립트 그림자문자 사용하기.. 바탕색이 무슨색이건 상관없이 글자가 잘보인다!!! 창조도시 2007.11.06 1475 1
183 RPGXP 스크립트 그림자문자 사용하기.. 바탕색이 무슨색이건 상관없이 글자가 잘보인다!!! 창조도시 2007.11.06 1888 1
182 RPGXP 스크립트 기차 파티 스크립트 2 창조도시 2008.07.24 1465 2
181 RPGXP 스크립트 기차 파티 스크립트 2 창조도시 2008.07.24 1879 2
180 RPGMV 플러그인 날씨효과를 전투중에도 사용하는 플러그인입니다. 3 plam 2015.10.27 839 0
» RPGXP 스크립트 네코에서 되는 마우스 스크립트 13 휴리드 2013.09.30 1675 0
178 RPGXP 스크립트 달리기스크립트 4 천둥번들 2014.02.22 2307 2
177 RPGXP 스크립트 대각선 방향 이동추가로 8방향 이동 만들기. 1 창조도시 2008.08.14 2200 1
176 RPGXP 스크립트 대각선 방향 이동추가로 8방향 이동 만들기. 창조도시 2008.08.14 2043 1
175 RPGXP 스크립트 대기 회복 스크립트 2013.10.01 1076 0
174 RPGXP 스크립트 대화 글씨 폰트를 원하는 폰트로 바꾸기 창조도시 2007.12.01 1391 2
173 RPGXP 스크립트 대화 글씨 폰트를 원하는 폰트로 바꾸기 창조도시 2007.12.01 1811 2
172 RPGXP 스크립트 대화 글씨가 한글자씩 나오는 스크립트 1 청담 2013.09.24 1415 0
171 RPGXP 스크립트 대화에 얼굴이 나오는 스크립트 by: killarot(네이버 dust_mite)(수정버전) 1 부초 2016.02.22 1895 0
170 RPGXP 스크립트 대화창에 얼굴 띄우기& 대화창 명령어 모음. 1 file 창조도시 2008.12.31 2083 1
169 RPGXP 스크립트 대화창에 얼굴 띄우기& 대화창 명령어 모음. 1 file 창조도시 2008.12.31 2820 1
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 15 Next
/ 15






[개인정보취급방침] | [이용약관] | [제휴문의] | [후원창구] | [인디사이드연혁]

Copyright © 1999 - 2016 INdiSide.com/(주)씨엘쓰리디 All Rights Reserved.
인디사이드 운영자 : 천무(이지선) | kernys(김원배) | 사신지(김병국)