RMParadise

It seems you either have yet to login or are not a member of RMP. If you are not yet a member, please feel free to sign up so that you can unlock every feature our forums have to offer. If you have yet to login, please do so soon.

A Paradise for RPGMakers.

Welcome everyone to RMP, your very own RPGMaker Paradise.
If you are reading this, that means that you are one of the select few who have been invited to experience our site as a Beta User.
Being a Beta User only requires that you report any bugs and/or problems upon finding them.
You get the chance to have free roam over the boards before they are public and are further up in line for promotions (which will be happening very soon, so stay on your best behavior).
Check out the thread for the RMP Beta Contest. Lets get some new content rolling.
Chat
Back to Top

    Basic Mouse System + Addons

    Share
    avatar
    Vlue
    I'm a new member :)
    I'm a new member :)

    Registered on Registered on : 2012-05-28
    Posts Posts : 30
    Rep. Points Rep. Points : 13

    Basic Mouse System + Addons

    Post by Vlue on Thu May 31, 2012 2:44 pm

    Basic Mouse System + Addons v1.0
    By V.M.


    Introduction
    Adds mouse functionality! Alone it does nothing but I'll be adding more addons over time.
    Current addons:
    Mouse Movement
    Mouse Battle
    Mouse Title/File
    Mouse Menu
    Mouse Shop
    Mouse Name
    Mouse Map
    Mouse Cursor

    How to Use
    Plug and play!
    It's all been moderately tested to moderately work moderately.

    Script
    All the scripts in one big pastebin for those lazy folk out there (me included :D) - RMVXACE MOUSE
    Main Script:
    Code:
    #Basic Mouse System
    #----------#
    #Features: Provides a series of functions to find the current x, y position of
    #          the mouse and whether it is being clicked or not (left or right click)
    #
    #Usage:  Script calls:
    #          Mouse.pos?  - returns the x, y position as an array
    #          Mouse.lclick?(repeat) - returns if left click is achieved
    #                                  repeat = true for repeated checks
    #          Mouse.rclick?(repeat) - same as above for right click
    #          Mouse.within?(rect) - passes a Rect through to check if cursor
    #                                is within it, returns true if so
    #
    #No Customization
    #
    #----------#
    #-- Script by: V.M of D.T
    #--- Free to use in any non-commercial project with credit given

    CPOS = Win32API.new 'user32', 'GetCursorPos', ['p'], 'v'
    WINX = Win32API.new 'user32', 'FindWindowEx', ['l','l','p','p'], 'i'
    ASKS = Win32API.new 'user32', 'GetAsyncKeyState', ['p'], 'i'
    SMET = Win32API.new 'user32', 'GetSystemMetrics', ['i'], 'i'
    WREC = Win32API.new 'user32', 'GetWindowRect', ['l','p'], 'v'

    module Mouse
      def self.setup
        @delay = 0
        bwap = true if SMET.call(23) != 0
        bwap ? @lmb = 0x02 : @lmb = 0x01
        bwap ? @rmb = 0x01 : @rmb = 0x02
      end
      def self.update
        self.setup if @lmb.nil?
        @delay -= 1
        @window_loc = WINX.call(0,0,"RGSS PLAYER",0)
        if ASKS.call(@lmb) == 0 then @l_clicked = false end
        if ASKS.call(@rmb) == 0 then @r_clicked = false end
        rect = '0000000000000000'
        cursor_pos = '00000000'
        WREC.call(@window_loc, rect)
        side, top = rect.unpack("ll")
        CPOS.call(cursor_pos)
        @m_x, @m_y = cursor_pos.unpack("ll")
        w_x = side + SMET.call(5) + SMET.call(45)
        w_y = top + SMET.call(6) + SMET.call(46) + SMET.call(4)
        @m_x -= w_x; @m_y -= w_y
      end
      def self.pos?
        self.update
        return [@m_x, @m_y]
      end
      def self.lclick?(repeat = false)
        self.update
        return false if @l_clicked
        if ASKS.call(@lmb) != 0 then
          @l_clicked = true if !repeat
          return true end
      end
      def self.rclick?(repeat = false)
        self.update
        return false if @r_clicked
        if ASKS.call(@rmb) != 0 then
          @r_clicked = true if !repeat
          return true end
      end
      def self.slowpeat
        self.update
        return false if @delay > 0
        @delay = 120
        return true
      end
      def self.within?(rect)
        self.update
        return false if @m_x < rect.x or @m_y < rect.y
        bound_x = rect.x + rect.width; bound_y = rect.y + rect.height
        return true if @m_x < bound_x and @m_y < bound_y
        return false
      end
    end

    Addons:
    Spoiler:
    Mouse Movement: v1.1
    Code:
    #Mouse Movement - Basic Mouse System Addon
    #----------#
    #Features: Moves the hero in a 4dir pattern based on where the mouse is currently
    #          while it's clicked. No pathfinding, just movement.
    #
    #Usage:  Plug and Play
    #
    #
    #No Customization
    #
    #----------#
    #-- Script by: V.M of D.T
    #--- Same Terms as Basic Mouse System

    class Game_Player < Game_Character
      alias mouse_move_update update
      def update
        mouse_move_update
        mouse_input
      end
      def mouse_input
        return if !movable? || $game_map.interpreter.running?
        if !Mouse.lclick?(true) then return end
        if moving? then return end
        pos = Mouse.pos?
        xx = $game_player.screen_x
        yy = $game_player.screen_y
        cen_pos = [xx,yy]
        x_diff = cen_pos[0] - pos[0]
        y_diff = cen_pos[1] - pos[1]
        if Mouse.within?(Rect.new(xx - 16,yy - 32,32,32)) then return end
        if x_diff > 0 and y_diff > 0
          x_diff >= y_diff ? move_straight(4) : move_straight(8)
          return
        end
        if x_diff < 0 and y_diff > 0
          x_diff *= -1
          x_diff >= y_diff ? move_straight(6) : move_straight(8)
          return
        end
        if x_diff > 0 and y_diff < 0
          y_diff *= -1
          x_diff >= y_diff ? move_straight(4) : move_straight(2)
          return
        end
        if x_diff < 0 and y_diff < 0
          x_diff *= -1
          y_diff *= -1
          x_diff >= y_diff ? move_straight(6) : move_straight(2)
          return
        end
      end
    end
    Mouse Battle: v1.0(Only works with the Default Battle System)
    Code:
    #Mouse Battle - Basic Mouse System Addon
    #----------#
    #Features: Adds basic mouse functionality to the default battle system!
    #          Left click pretty much acts as the accept button
    #          Right click pretty much acts as the cancel button
    #
    #Usage:  Plug and Play
    #
    #No Customization
    #
    #----------#
    #-- Script by: V.M of D.T
    #--- Same Terms as Basic Mouse System

    class Scene_Battle
      WLH = 24
      OFS = 12
      alias mouse_update_basic update_basic
      def update_basic
        mouse_update_basic
        mouse_update
      end
      def mouse_update
        #ACTOR_WINDOW
        if @actor_window.active
          xx = Graphics.width - @enemy_window.width
          yy = Graphics.height - @enemy_window.height
          width = @actor_window.contents.width
          rectcm1 = Rect.new(xx + OFS, yy + OFS, width, WLH)
          rectcm2 = Rect.new(rectcm1.x, rectcm1.y + 24, width, WLH)
          rectcm3 = Rect.new(rectcm1.x, rectcm2.y + 24, width, WLH)
          rectcm4 = Rect.new(rectcm1.x, rectcm3.y + 24, width, WLH)
          rectttl = Rect.new(rectcm1.x, rectcm1.y, width * 2, WLH * 4)
          @actor_window.index = 0 if Mouse.within?(rectcm1)
          @actor_window.index = 1 if Mouse.within?(rectcm2)
          @actor_window.index = 2 if Mouse.within?(rectcm3)
          @actor_window.index = 3 if Mouse.within?(rectcm4)
          @actor_window.process_ok if Mouse.lclick? and Mouse.within?(rectttl)
          @actor_window.process_cancel if Mouse.rclick? and Mouse.within?(rectttl)
        end
        #ITEM_WINDOW
        if @item_window.active
          xx = 0
          yy = @help_window.height
          width = @item_window.contents.width / 2
          hold_rect = []; temp = 2
          smax = [@item_window.item_max, ((@item_window.height - 24) / WLH) * 2].min
          rectttl = Rect.new(xx, yy, @item_window.contents.width, @item_window.contents.height)
          rectcmA = Rect.new(Graphics.width / 2 - 50, @help_window.height - 12, 100, 24)
          rectcmB = Rect.new(Graphics.width / 2 - 50, Graphics.height - @actor_command_window.height - 12, 100, 24)
          for i in Range.new(0,smax - 1)
            tempx = xx + OFS + width * (temp % 2)
            tempy = yy + OFS + 24 * ((temp / 2) - 1)
            hold_rect.push(Rect.new(tempx, tempy, width, WLH))
            temp += 1
          end
          @scroll = @item_window.top_row + (@item_window.top_row * 2 / 2)
          for i in Range.new(0,@item_window.item_max - 1)
            next if hold_rect[i].nil?
            @item_window.index = (i + @scroll) if Mouse.within?(hold_rect[i])
          end
          @item_window.cursor_down if Mouse.within?(rectcmB) and Mouse.slowpeat
          @item_window.cursor_up if Mouse.within?(rectcmA) and Mouse.slowpeat
          @item_window.process_ok if Mouse.lclick? and Mouse.within?(rectttl)
          @item_window.process_cancel if Mouse.rclick? and Mouse.within?(rectttl)
        end
        #SKILL_WINDOW
        if @skill_window.active
          xx = 0
          yy = @help_window.height
          width = @skill_window.contents.width / 2
          hold_rect = []; temp = 2
          rectttl = Rect.new(xx, yy, @skill_window.contents.width, @skill_window.contents.height)
          rectcmA = Rect.new(Graphics.width / 2 - 50, @help_window.height - 12, 100, 24)
          rectcmB = Rect.new(Graphics.width / 2 - 50, Graphics.height - @actor_command_window.height - 12, 100, 24)
          for i in Range.new(0,@skill_window.item_max - 1)
            tempx = xx + OFS + width * (temp % 2)
            tempy = yy + OFS + 24 * ((temp / 2) - 1)
            hold_rect.push(Rect.new(tempx, tempy, width, WLH))
            temp += 1
          end
          @scroll = @skill_window.top_row + (@skill_window.top_row * 2 / 2)
          for i in Range.new(0,@skill_window.item_max - 1)
            next if hold_rect[i].nil?
            @skill_window.index = (i + @scroll) if Mouse.within?(hold_rect[i])
          end
          @skill_window.cursor_down if Mouse.within?(rectcmB) and Mouse.slowpeat
          @skill_window.cursor_up if Mouse.within?(rectcmA) and Mouse.slowpeat
          @skill_window.process_ok if Mouse.lclick? and Mouse.within?(rectttl)
          @skill_window.process_cancel if Mouse.rclick? and Mouse.within?(rectttl)
        end
        #ENEMY_WINDOW
        if @enemy_window.active
          xx = Graphics.width - @enemy_window.width
          yy = Graphics.height - @enemy_window.height
          width = @enemy_window.contents.width / 2
          rectcm1 = Rect.new(xx + OFS, yy + OFS, width, WLH)
          rectcm2 = Rect.new(rectcm1.x + width, rectcm1.y, width, WLH)
          rectcm3 = Rect.new(rectcm1.x, rectcm1.y + 24, width, WLH)
          rectcm4 = Rect.new(rectcm1.x + width, rectcm3.y, width, WLH)
          rectcm5 = Rect.new(rectcm1.x, rectcm3.y + 24, width, WLH)
          rectcm6 = Rect.new(rectcm1.x + width, rectcm5.y, width, WLH)
          rectcm7 = Rect.new(rectcm1.x, rectcm5.y + 24, width, WLH)
          rectcm8 = Rect.new(rectcm1.x + width, rectcm7.y, width, WLH)
          rectttl = Rect.new(rectcm1.x, rectcm1.y, width * 2, WLH * 4)
          @enemy_window.index = 0 if Mouse.within?(rectcm1)
          @enemy_window.index = 1 if Mouse.within?(rectcm2) and !$game_troop.alive_members[1].nil?
          @enemy_window.index = 2 if Mouse.within?(rectcm3) and !$game_troop.alive_members[2].nil?
          @enemy_window.index = 3 if Mouse.within?(rectcm4) and !$game_troop.alive_members[3].nil?
          @enemy_window.index = 4 if Mouse.within?(rectcm5) and !$game_troop.alive_members[4].nil?
          @enemy_window.index = 5 if Mouse.within?(rectcm6) and !$game_troop.alive_members[5].nil?
          @enemy_window.index = 6 if Mouse.within?(rectcm7) and !$game_troop.alive_members[6].nil?
          @enemy_window.index = 7 if Mouse.within?(rectcm8) and !$game_troop.alive_members[7].nil?
          @enemy_window.process_ok if Mouse.lclick? and Mouse.within?(rectttl)
          @enemy_window.process_cancel if Mouse.rclick? and Mouse.within?(rectttl)
        end
        #ACTOR_COMMAND_WINDOW
        if @actor_command_window.active
          xx = Graphics.width - @actor_command_window.width
          yy = Graphics.height - @actor_command_window.height
          width = @actor_command_window.contents.width
          rectcm1 = Rect.new(xx + OFS, yy + OFS, width, WLH)
          rectcmA = Rect.new(rectcm1.x, rectcm1.y - WLH, width, WLH)
          rectcm2 = Rect.new(rectcm1.x, rectcm1.y + WLH, width, WLH)
          rectcm3 = Rect.new(rectcm1.x, rectcm2.y + WLH, width, WLH)
          rectcm4 = Rect.new(rectcm1.x, rectcm3.y + WLH, width, WLH)
          rectcmB = Rect.new(rectcm1.x, rectcm4.y + WLH, width, WLH)
          rectttl = Rect.new(rectcm1.x, rectcm1.y, width, WLH * 4)
          @actor_command_window.cursor_up if Mouse.within?(rectcmA) and @actor_command_window.item_max > 4
          @actor_command_window.cursor_down if Mouse.within?(rectcmB) and @actor_command_window.item_max > 4
          @scroll = @actor_command_window.top_row
          @actor_command_window.index = (0 + @scroll) if Mouse.within?(rectcm1)
          @actor_command_window.index = (1 + @scroll) if Mouse.within?(rectcm2)
          @actor_command_window.index = (2 + @scroll) if Mouse.within?(rectcm3)
          @actor_command_window.index = (3 + @scroll) if Mouse.within?(rectcm4)
          @actor_command_window.process_ok if Mouse.lclick? and Mouse.within?(rectttl)
          @actor_command_window.process_cancel if Mouse.rclick? and Mouse.within?(rectttl)
        end
        #PARTY_COMMAND_WINDOW
        if @party_command_window.openness > 254
          xx = 0
          yy = Graphics.height - @party_command_window.height
          width = @party_command_window.contents.width
          rectcm1 = Rect.new(xx + OFS, yy + OFS, width, WLH)
          rectcm2 = Rect.new(rectcm1.x, rectcm1.y + WLH, width, WLH)
          rectttl = Rect.new(rectcm1.x, rectcm1.y, width, WLH * 2)
          @party_command_window.index = 0 if Mouse.within?(rectcm1)
          @party_command_window.index = 1 if Mouse.within?(rectcm2)
          @party_command_window.process_ok if Mouse.lclick? and Mouse.within?(rectttl)
        #END
      end
      end
    end

    class Window_Message < Window_Base
      def input_pause
        self.pause = true
        wait(10)
        Fiber.yield until Input.trigger?(:B) || Input.trigger?(:C) || (Mouse.lclick? if !SceneManager.scene_is?(Scene_Map))
        Input.update
        self.pause = false
      end
    end
    Mouse Title/File: v1.1
    Code:
    #Mouse Title/File - Basic Mouse System Addon
    #----------#
    #Features: Adds basic mouse functionality to the Title screen and Save screen
    #          and GameOver screen!
    #          Left click pretty much acts as the accept button
    #          Right click pretty much acts as the cancel button
    #
    #Usage:  Plug and Play
    #
    #No Customization
    #
    #----------#
    #-- Script by: V.M of D.T
    #--- Same Terms as Basic Mouse System

    class Scene_Title < Scene_Base
      def update
        super
        mouse_input
      end
      def mouse_input
        new_game_rect = Rect.new(@command_window.x + 12, @command_window.y + 12, @command_window.contents.width, 24)
        cont_rect = Rect.new(new_game_rect.x, new_game_rect.y + 24, new_game_rect.width, 24)
        shutdown_rect = Rect.new(cont_rect.x, cont_rect.y + 24, cont_rect.width, 24)
        rectttl = Rect.new(cont_rect.x, new_game_rect.y, cont_rect.width, 24*3)
        @command_window.index = 0 if Mouse.within?(new_game_rect)
        @command_window.index = 1 if Mouse.within?(cont_rect)
        @command_window.index = 2 if Mouse.within?(shutdown_rect)
        @command_window.process_ok if Mouse.lclick? and Mouse.within?(rectttl)
      end
    end

    class Scene_File < Scene_MenuBase
      alias mouse_update update
      def update
        mouse_update
        mouse_input
      end
      def mouse_input
        xx = 0
        yy = 56
        width = Graphics.width
        rectcm1 = Rect.new(xx, yy, width, savefile_height)
        rectcm2 = Rect.new(xx, yy + rectcm1.height, width, savefile_height)
        rectcm3 = Rect.new(xx, yy + rectcm1.height * 2, width, savefile_height)
        rectcm4 = Rect.new(xx, yy + rectcm1.height * 3, width, savefile_height)
        rectttl = Rect.new(xx, yy, width, rectcm1.height * 4)
        rectcmA = Rect.new(0, yy - 12, Graphics.width, 24)
        rectcmB = Rect.new(0, Graphics.height - 12, Graphics.width, 24)
        @scroll = self.top_index
        last_index = @index
        @index = (0 + @scroll) if Mouse.within?(rectcm1)
        @index = (1 + @scroll) if Mouse.within?(rectcm2)
        @index = (2 + @scroll) if Mouse.within?(rectcm3)
        @index = (3 + @scroll) if Mouse.within?(rectcm4)
        cursor_down(false) if Mouse.within?(rectcmB) and Mouse.slowpeat
        cursor_up(false) if Mouse.within?(rectcmA) and Mouse.slowpeat
        if @index != last_index
          Sound.play_cursor
          @savefile_windows[last_index].selected = false
          @savefile_windows[@index].selected = true
        end
        on_savefile_ok if Mouse.lclick? and Mouse.within?(rectttl)
        on_savefile_cancel if Mouse.rclick? and Mouse.within?(rectttl)
      end
    end

    class Scene_Gameover
      alias mouse_update update
      def update
        mouse_update
        goto_title if Mouse.lclick? or Mouse.rclick?
      end
    end
    Mouse Menu: v1.1
    Code:
    #Mouse Menu - Basic Mouse System Addon
    #----------#
    #Features: Adds basic mouse functionality to the Menu and subjacent options
    #          Left click pretty much acts as the accept button
    #          Right click pretty much acts as the cancel button
    #          Right click on map to pull it up
    #
    #Usage:  Plug and Play
    #
    #No Customization
    #
    #----------#
    #-- Script by: V.M of D.T
    #--- Same Terms as Basic Mouse System

    class Scene_Map < Scene_Base
      alias mouse_update update
      def update
        mouse_update
        mouse_menu_input
      end
      def mouse_menu_input
        call_menu if Mouse.rclick? and !$game_map.interpreter.running?
      end
    end

    class Scene_Menu < Scene_MenuBase
      OFS = 12
      WLH = 24
      alias mouse_update update
      def update
        mouse_update
        mouse_input
      end
      def mouse_input
        if !@status_window.active
          hold_rect = []
          xx = @command_window.x + OFS
          yy = @command_window.y + OFS
          width = @command_window.width
          rectttl = Rect.new(xx, yy, width, WLH * 7)
          for i in Range.new(0, 6)
            hold_rect.push(Rect.new(xx, yy, width, WLH))
            yy += WLH
          end
          for i in Range.new(0, 6)
            @command_window.index = i if Mouse.within?(hold_rect[i])
          end
          @command_window.process_ok if Mouse.lclick? and Mouse.within?(rectttl)
          @command_window.process_cancel if Mouse.rclick?
        else
          hold_rect = []
          xx = @status_window.x + OFS
          yy = @status_window.y + OFS
          width = @status_window.width
          rectttl = Rect.new(xx, yy, width, @status_window.contents.height)
          for i in Range.new(0, $game_party.members.size - 1)
            hold_rect.push(Rect.new(xx, yy, width, @status_window.item_height))
            yy += @status_window.item_height
          end
          for i in Range.new(0, $game_party.members.size - 1)
            @status_window.index = i if Mouse.within?(hold_rect[i])
          end
          @status_window.process_ok if Mouse.lclick? and Mouse.within?(rectttl)
          @status_window.process_cancel if Mouse.rclick? and Mouse.within?(rectttl)
        end
      end
    end
    class Scene_Item
      OFS = 12
      WLH = 24
      alias mouse_update update
      def update
        mouse_update
        mouse_input
      end
      def mouse_input
        if @category_window.active
          hold_rect = []
          xx = @category_window.x + OFS
          yy = @category_window.y + OFS
          width = @category_window.contents.width / 4
          rectttl = Rect.new(xx, yy, width * 4, @category_window.contents.height)
          for i in Range.new(0,3)
            hold_rect.push(Rect.new(xx, yy, width, @category_window.contents.height))
            xx += width
          end
          for i in Range.new(0,3)
            @category_window.index = i if Mouse.within?(hold_rect[i])
          end
          @category_window.process_ok if Mouse.lclick? and Mouse.within?(rectttl)
          @category_window.process_cancel if Mouse.rclick?
        elsif @item_window.active
          xx = @item_window.x + OFS
          yy = @item_window.y + OFS
          width = @item_window.contents.width / 2
          hold_rect = []; temp = 2
          smax = [@item_window.item_max, ((@item_window.height - 24) / WLH) * 2].min
          rectttl = Rect.new(xx, yy, @item_window.contents.width, @item_window.contents.height)
          rectcmA = Rect.new(@item_window.width / 2 - 50, yy - 12, 100, 24)
          rectcmB = Rect.new(@item_window.width / 2 - 50, yy - 12 + @item_window.height, 100, 24)
          for i in Range.new(0,smax - 1)
            tempx = xx + width * (temp % 2)
            tempy = yy + 24 * ((temp / 2) - 1)
            hold_rect.push(Rect.new(tempx, tempy, width, WLH))
            temp += 1
          end
          @scroll = @item_window.top_row + (@item_window.top_row * 2 / 2)
          for i in Range.new(0,@item_window.item_max - 1)
            next if hold_rect[i].nil?
            @item_window.index = (i + @scroll) if Mouse.within?(hold_rect[i])
          end
          @item_window.cursor_down if Mouse.within?(rectcmB) and Mouse.slowpeat
          @item_window.cursor_up if Mouse.within?(rectcmA) and Mouse.slowpeat
          @item_window.process_ok if Mouse.lclick? and Mouse.within?(rectttl)
          @item_window.process_cancel if Mouse.rclick? 
        elsif @actor_window.active
          hold_rect = []
          xx = @actor_window.x + OFS
          yy = @actor_window.y + OFS
          width = @actor_window.width
          rectttl = Rect.new(xx, yy, width, @actor_window.contents.height)
          for i in Range.new(0, $game_party.members.size - 1)
            hold_rect.push(Rect.new(xx, yy, width, @actor_window.item_height))
            yy += @actor_window.item_height
          end
          for i in Range.new(0, $game_party.members.size - 1)
            @actor_window.index = i if Mouse.within?(hold_rect[i])
          end
          @actor_window.process_ok if Mouse.lclick? and Mouse.within?(rectttl)
          @actor_window.process_cancel if Mouse.rclick?
        end
      end
    end
    class Scene_Skill
      OFS = 12
      WLH = 24
      alias mouse_update update
      def update
        mouse_update
        mouse_input
      end
      def mouse_input
        if @command_window.active
          hold_rect = []
          xx = @command_window.x + OFS
          yy = @command_window.y + OFS
          width = @command_window.contents.width
          rectttl = Rect.new(xx, yy, width, @command_window.contents.height)
          for i in Range.new(0,@command_window.item_max-1)
            hold_rect.push(Rect.new(xx, yy, width, WLH))
            yy += WLH
          end
          for i in Range.new(0,@command_window.item_max-1)
            @command_window.index = i if Mouse.within?(hold_rect[i])
          end
          @command_window.process_ok if Mouse.lclick? and Mouse.within?(rectttl)
          @command_window.process_cancel if Mouse.rclick?
        elsif @item_window.active
          xx = @item_window.x + OFS
          yy = @item_window.y + OFS
          width = @item_window.contents.width / 2
          hold_rect = []; temp = 2
          smax = [@item_window.item_max, ((@item_window.height - 24) / WLH) * 2].min
          rectttl = Rect.new(xx, yy, @item_window.contents.width, @item_window.contents.height)
          rectcmA = Rect.new(@item_window.width / 2 - 50, yy - 12, 100, 24)
          rectcmB = Rect.new(@item_window.width / 2 - 50, yy - 12 + @item_window.height, 100, 24)
          for i in Range.new(0,smax - 1)
            tempx = xx + width * (temp % 2)
            tempy = yy + 24 * ((temp / 2) - 1)
            hold_rect.push(Rect.new(tempx, tempy, width, WLH))
            temp += 1
          end
          @scroll = @item_window.top_row + (@item_window.top_row * 2 / 2)
          for i in Range.new(0,@item_window.item_max - 1)
            next if hold_rect[i].nil?
            @item_window.index = (i + @scroll) if Mouse.within?(hold_rect[i])
          end
          @item_window.cursor_down if Mouse.within?(rectcmB) and Mouse.slowpeat
          @item_window.cursor_up if Mouse.within?(rectcmA) and Mouse.slowpeat
          @item_window.process_ok if Mouse.lclick? and Mouse.within?(rectttl)
          @item_window.process_cancel if Mouse.rclick? 
        elsif @actor_window.active
          hold_rect = []
          xx = @actor_window.x + OFS
          yy = @actor_window.y + OFS
          width = @actor_window.width
          rectttl = Rect.new(xx, yy, width, @actor_window.contents.height)
          for i in Range.new(0, $game_party.members.size - 1)
            hold_rect.push(Rect.new(xx, yy, width, @actor_window.item_height))
            yy += @actor_window.item_height
          end
          for i in Range.new(0, $game_party.members.size - 1)
            @actor_window.index = i if Mouse.within?(hold_rect[i])
          end
          @actor_window.process_ok if Mouse.lclick? and Mouse.within?(rectttl)
          @actor_window.process_cancel if Mouse.rclick?
        end
      end
    end
    class Scene_Equip
      OFS = 12
      WLH = 24
      alias mouse_update update
      def update
        mouse_update
        mouse_input
      end
      def mouse_input
        if @command_window.active
          hold_rect = []
          xx = @command_window.x + OFS
          yy = @command_window.y + OFS
          width = @command_window.width / 3
          rectttl = Rect.new(xx, yy, width * 3, @command_window.contents.height)
          for i in Range.new(0, 2)
            hold_rect.push(Rect.new(xx, yy, width, WLH))
            xx += width
          end
          for i in Range.new(0, 2)
            @command_window.index = i if Mouse.within?(hold_rect[i])
          end
          @command_window.process_ok if Mouse.lclick? and Mouse.within?(rectttl)
          @command_window.process_cancel if Mouse.rclick?
        elsif @slot_window.active
          hold_rect = []
          xx = @slot_window.x + OFS
          yy = @slot_window.y + OFS
          width = @slot_window.width
          rectttl = Rect.new(xx, yy, width, @slot_window.contents.height)
          for i in Range.new(0, 4)
            hold_rect.push(Rect.new(xx, yy, width, WLH))
            yy += WLH
          end
          for i in Range.new(0, 4)
            @slot_window.index = i if Mouse.within?(hold_rect[i])
          end
          @slot_window.process_ok if Mouse.lclick? and Mouse.within?(rectttl)
          @slot_window.process_cancel if Mouse.rclick?
        elsif @item_window.active
          xx = @item_window.x + OFS
          yy = @item_window.y + OFS
          width = @item_window.contents.width / 2
          hold_rect = []; temp = 2
          smax = [@item_window.item_max, ((@item_window.height - 24) / WLH) * 2].min
          rectttl = Rect.new(xx, yy, @item_window.contents.width, @item_window.contents.height)
          rectcmA = Rect.new(@item_window.width / 2 - 50, yy - 12, 100, 24)
          rectcmB = Rect.new(@item_window.width / 2 - 50, yy - 12 + @item_window.height, 100, 24)
          for i in Range.new(0,smax - 1)
            tempx = xx + width * (temp % 2)
            tempy = yy + 24 * ((temp / 2) - 1)
            hold_rect.push(Rect.new(tempx, tempy, width, WLH))
            temp += 1
          end
          @scroll = @item_window.top_row + (@item_window.top_row * 2 / 2)
          for i in Range.new(0,@item_window.item_max - 1)
            next if hold_rect[i].nil?
            @item_window.index = (i + @scroll) if Mouse.within?(hold_rect[i])
          end
          @item_window.cursor_down if Mouse.within?(rectcmB) and Mouse.slowpeat
          @item_window.cursor_up if Mouse.within?(rectcmA) and Mouse.slowpeat
          @item_window.process_ok if Mouse.lclick? and Mouse.within?(rectttl)
          @item_window.process_cancel if Mouse.rclick? 
        end
      end
    end
    class Scene_Status
      alias mouse_update update
      def update
        mouse_update
        mouse_input
      end
      def mouse_input
        @status_window.process_pagedown if Mouse.lclick?
        @status_window.process_cancel if Mouse.rclick?
      end
    end
    class Scene_End
      OFS = 12
      WLH = 24
      alias mouse_update update
      def update
        mouse_update
        mouse_input
      end
      def mouse_input
        hold_rect = []
        xx = @command_window.x + OFS
        yy = @command_window.y + OFS
        width = @command_window.width
        rectttl = Rect.new(xx, yy, width, @command_window.contents.height)
        for i in Range.new(0, 2)
          hold_rect.push(Rect.new(xx, yy, width, WLH))
          yy += WLH
        end
        for i in Range.new(0, 2)
          @command_window.index = i if Mouse.within?(hold_rect[i])
        end
        @command_window.process_ok if Mouse.lclick? and Mouse.within?(rectttl)
        @command_window.process_cancel if Mouse.rclick?
      end
    end
    Mouse Shop: v1.0
    Code:
    #Mouse Shop - Basic Mouse System Addon
    #----------#
    #Features: Adds basic mouse functionality to the Shop!
    #          Left click pretty much acts as the accept button
    #          Right click pretty much acts as the cancel button
    #
    #Usage:  Plug and Play
    #
    #No Customization
    #
    #----------#
    #-- Script by: V.M of D.T
    #--- Same Terms as Basic Mouse System

    class Scene_Shop
      OFS = 12
      WLH = 24
      alias mouse_update update
      def update
        mouse_update
        mouse_input
      end
      def mouse_input
        if @command_window.active
          hold_rect = []
          xx = @command_window.x + OFS
          yy = @command_window.y + OFS
          width = @command_window.contents.width / 3
          rectttl = Rect.new(xx, yy, width * 3, WLH)
          for i in Range.new(0, 2)
            hold_rect.push(Rect.new(xx, yy, width, WLH))
            xx += width
          end
          for i in Range.new(0, 2)
            @command_window.index = i if Mouse.within?(hold_rect[i])
          end
          @command_window.process_ok if Mouse.lclick? and Mouse.within?(rectttl)
          @command_window.process_cancel if Mouse.rclick?
        elsif @buy_window.active
          hold_rect = []
          xx = @buy_window.x + OFS
          yy = @buy_window.y + OFS
          width = @buy_window.contents.width
          rectttl = Rect.new(xx, yy, @buy_window.contents.width, @buy_window.contents.height)
          rectcmA = Rect.new(@buy_window.width / 2 - 50, yy - 12, 100, 24)
          rectcmB = Rect.new(@buy_window.width / 2 - 50, yy - 12 + @buy_window.height, 100, 24)
          for i in Range.new(0,@buy_window.item_max - 1)
            hold_rect.push(Rect.new(xx, yy, width, WLH))
            yy += WLH
          end
          @scroll = @buy_window.top_row + (@buy_window.top_row * 2 / 2)
          for i in Range.new(0,@buy_window.item_max - 1)
            next if hold_rect[i].nil?
            @buy_window.index = (i + @scroll) if Mouse.within?(hold_rect[i])
          end
          @buy_window.cursor_down if Mouse.within?(rectcmB) and Mouse.slowpeat
          @buy_window.cursor_up if Mouse.within?(rectcmA) and Mouse.slowpeat
          @buy_window.process_ok if Mouse.lclick? and Mouse.within?(rectttl)
          @buy_window.process_cancel if Mouse.rclick? 
        elsif @number_window.active
          xx = @number_window.x + @number_window.contents.width - 26
          yy = @number_window.y + @number_window.contents.height / 2 - 36
          width = 24
          rectttl = Rect.new(@number_window.x, @number_window.y, @number_window.width, @number_window.height)
          rectcmA = Rect.new(xx, yy - 24, 36, 36)
          rectcmB = Rect.new(xx, yy + 24, 36, 36)
          @number_window.change_number(1) if Mouse.within?(rectcmA) and Mouse.lclick?(true)
          @number_window.change_number(-1) if Mouse.within?(rectcmB) and Mouse.lclick?(true)
          @number_window.process_ok if Mouse.lclick? and Mouse.within?(rectttl) and !Mouse.within?(rectcmA) and !Mouse.within?(rectcmB)
          @number_window.process_cancel if Mouse.rclick?
          @number_window.refresh
        elsif @category_window.active
          hold_rect = []
          xx = @category_window.x + OFS
          yy = @category_window.y + OFS
          width = @category_window.contents.width / 4
          rectttl = Rect.new(xx, yy, width * 4, @category_window.contents.height)
          for i in Range.new(0,3)
            hold_rect.push(Rect.new(xx, yy, width, @category_window.contents.height))
            xx += width
          end
          for i in Range.new(0,3)
            @category_window.index = i if Mouse.within?(hold_rect[i])
          end
          @category_window.process_ok if Mouse.lclick? and Mouse.within?(rectttl)
          @category_window.process_cancel if Mouse.rclick?
        elsif @sell_window.active
          xx = @sell_window.x + OFS
          yy = @sell_window.y + OFS
          width = @sell_window.contents.width / 2
          hold_rect = []; temp = 2
          smax = [@sell_window.item_max, ((@sell_window.height - 24) / WLH) * 2].min
          rectttl = Rect.new(xx, yy, @sell_window.contents.width, @sell_window.contents.height)
          rectcmA = Rect.new(@sell_window.width / 2 - 50, yy - 12, 100, 24)
          rectcmB = Rect.new(@sell_window.width / 2 - 50, yy - 12 + @sell_window.height, 100, 24)
          for i in Range.new(0,smax - 1)
            tempx = xx + width * (temp % 2)
            tempy = yy + 24 * ((temp / 2) - 1)
            hold_rect.push(Rect.new(tempx, tempy, width, WLH))
            temp += 1
          end
          @scroll = @sell_window.top_row + (@sell_window.top_row * 2 / 2)
          for i in Range.new(0,@sell_window.item_max - 1)
            next if hold_rect[i].nil?
            @sell_window.index = (i + @scroll) if Mouse.within?(hold_rect[i])
          end
          @sell_window.cursor_down if Mouse.within?(rectcmB) and Mouse.slowpeat
          @sell_window.cursor_up if Mouse.within?(rectcmA) and Mouse.slowpeat
          @sell_window.process_ok if Mouse.lclick? and Mouse.within?(rectttl)
          @sell_window.process_cancel if Mouse.rclick? 
        end
      end
    end
    class Window_ShopNumber
      alias mouse_refresh refresh
      def refresh
        mouse_refresh
        xx = self.contents.width - 30
        yy = self.contents.height / 2 - 36
        self.contents.draw_text(xx, yy - 24, 24, 24, "+", 1)
        self.contents.draw_text(xx, yy + 24, 24, 24, "-", 1)
      end
    end
    Mouse Name v1.0:
    Code:
    #Mouse Name - Basic Mouse System Addon
    #----------#
    #Features: Adds basic mouse functionality to the Name Input screen!
    #          Left click pretty much acts as the accept button
    #          Right click pretty much acts as the cancel button
    #
    #Usage:  Plug and Play
    #
    #No Customization
    #
    #----------#
    #-- Script by: V.M of D.T
    #--- Same Terms as Basic Mouse System

    class Scene_Name
      OFS = 12
      WLH = 24
      alias mouse_update update
      def update
        mouse_update
        mouse_input
      end
      def mouse_input
        hold_rect = []
        xx = @input_window.x + OFS
        yy = @input_window.y + OFS
        width = (@input_window.contents.width - 12 ) / 10
        rectttl = Rect.new(xx, yy, @input_window.contents.width, @input_window.contents.height)
        for i in Range.new(0, 89)
          hold_rect.push(Rect.new(xx, yy, width, WLH))
          xx += width
          xx += 12 if (i + 1) % 5 == 0
          if (i + 1) % 10 == 0
            xx = @input_window.x + OFS
            yy += WLH
          end
        end
        for i in Range.new(0, 89)
          @input_window.index = i if Mouse.within?(hold_rect[i])
        end
        @input_window.process_ok if Mouse.lclick? and Mouse.within?(rectttl)
        @input_window.process_back if Mouse.rclick?
      end
    end
    Mouse Map v1.0:
    Code:


    #Mouse Map - Basic Mouse System Addon
    #----------#
    #Features: Adds basic mouse functionality to the map events!
    #          Right clicking on a adjacent event activates them!
    #
    #Usage:  Plug and Play
    #
    #No Customization
    #
    #----------#
    #-- Script by: V.M of D.T
    #--- Same Terms as Basic Mouse System

    class Scene_Map
      alias mouse_update update
      def update
        mouse_update
        mouse_input_events
      end
      def mouse_input_events
        xx = $game_player.screen_x
        yy = $game_player.screen_y
        xx -= 16;
        recttop = Rect.new(xx - 6, yy - 80, 44, 48)
        rectrit = Rect.new(xx + 32, yy - 36, 48, 44)
        rectbot = Rect.new(xx - 6, yy, 44, 48)
        rectleft = Rect.new(xx - 48, yy - 38, 48, 44)
        mouse_action(8) if Mouse.within?(recttop)
        mouse_action(6) if Mouse.within?(rectrit)
        mouse_action(2) if Mouse.within?(rectbot)
        mouse_action(4) if Mouse.within?(rectleft)
        call_menu if Mouse.rclick? and !$game_map.interpreter.running?
      end
      def mouse_action(d)
        return if !Mouse.rclick?
        $game_player.set_direction(d)
        $game_player.check_action_event
      end
    end

    class Window_Message < Window_Base
      def input_pause
        self.pause = true
        wait(10)
        Fiber.yield until Input.trigger?(:B) || Input.trigger?(:C) || Mouse.lclick?
        Input.update
        self.pause = false
      end
    end

    class Window_Command
      OFS = 12
      WLH = 24
      alias mouse_update update
      def update
        mouse_update
        mouse_input if SceneManager.scene_is?(Scene_Map) and self.active
      end
      def mouse_input
        hold_rect = []
        xx = self.x + OFS
        yy = self.y + OFS
        width = self.contents.width
        rectttl = Rect.new(xx, yy, width, WLH * 4)
        for i in Range.new(0, self.item_max - 1)
          hold_rect.push(Rect.new(xx, yy, width, WLH))
          yy += WLH
        end
        for i in Range.new(0, self.item_max - 1)
          self.index = i if Mouse.within?(hold_rect[i])
        end
        self.process_ok if Mouse.lclick? and Mouse.within?(rectttl)
        self.process_cancel if Mouse.rclick?
      end
    end

    class Window_NumberInput
      OFS = 12
      WLH = 24
      alias mouse_update update
      def update
        mouse_update
        mouse_input if SceneManager.scene_is?(Scene_Map) and self.active
      end
      def mouse_input
        hold_rect = []
        xx = self.x + OFS
        yy = self.y + OFS
        width = 20
        rectttl = Rect.new(xx, yy, self.contents.width, WLH)
        for i in Range.new(0, @digits_max - 1)
          hold_rect.push(Rect.new(xx, yy, width, WLH))
          xx += width
        end
        for i in Range.new(0, @digits_max - 1)
          @index = i if Mouse.within?(hold_rect[i])
        end
        rectok = Rect.new(xx, yy, 34, 24)
        rectnum = Rect.new(self.x + OFS, yy, @digits_max * 20, WLH)
        self.process_ok if Mouse.within?(rectok) and Mouse.lclick?
        process_mouse_change if Mouse.within?(rectnum)
      end
      def refresh
        contents.clear
        change_color(normal_color)
        s = sprintf("%0*d", @digits_max, @number)
        @digits_max.times do |i|
          rect = item_rect(i)
          rect.x += 1
          draw_text(rect, s[i,1], 1)
        end
        draw_text(self.contents.width - 24, 0, 34, WLH, "OK")
      end
      def update_placement
        self.width = @digits_max * 20 + padding * 2 + 34
        self.height = fitting_height(1)
        self.x = (Graphics.width - width) / 2
        if @message_window.y >= Graphics.height / 2
          self.y = @message_window.y - height - 8
        else
          self.y = @message_window.y + @message_window.height + 8
        end
      end
      def process_mouse_change
        return unless active
        Sound.play_cursor
        place = 10 ** (@digits_max - 1 - @index)
        n = @number / place % 10
        @number -= n * place
        n = (n + 1) % 10 if Mouse.lclick?
        n = (n + 9) % 10 if Mouse.rclick?
        @number += n * place
        refresh
      end
    end
    Mouse Cursor v1.0:
    Code:


    #Mouse Cursor - Basic Mouse System Addon
    #----------#
    #Features: Adds a customizable mouse cursor! Bonus!
    #
    #Usage:  Plug and Play
    #
    #Customization: MOUSE_ICON, the index of the icon for the cursor
    #
    #----------#
    #-- Script by: V.M of D.T
    #--- Same Terms as Basic Mouse System

    #MOUSE_ICON, set to the index of the icon to use as a cursor
    MOUSE_ICON = 147

    SHOWMOUS = Win32API.new 'user32', 'ShowCursor', 'i', 'i'
    SHOWMOUS.call(0)

    module DataManager
      class << self
        alias mouse_init init
      end
      def self.init
        mouse_init
        $cursor = Mouse_Cursor.new
      end
    end

    class Scene_Base
      alias cursor_update update_basic
      def update_basic
        cursor_update
        mouse_cursor
      end
      def mouse_cursor
        pos = Mouse.pos?
        $cursor.x = pos[0]
        $cursor.y = pos[1]
      end
    end

    class Mouse_Cursor < Sprite_Base
      def initialize
        super
        draw_cursor
        self.z = 255
      end
      def draw_cursor
        self.bitmap = nil
        self.bitmap = Cache.system("Iconset")
        rect = Rect.new(MOUSE_ICON % 16 * 24, MOUSE_ICON / 16 * 24, 24, 24)
        self.bitmap.blt(0, 0, self.bitmap, rect)
        self.src_rect.set(0, 0, 24, 24) 
      end
    end

    FAQ
    Q. Can I throw money at you?
    A. Yes, yes you may.

    Credit and Thanks
    - By V.M. of D.T
    - Free to use in any non-commercial game with credit given
    - Thanks to the well documented MSDN for the Win32API calls x.x

    Author's Notes
    Huff.. de luff...
    I like this one

    History
    Cursor v1.0 - Addon added
    Title/File v 1.1 - Added mouse click to gameover screen
    Menu Screen v1.1 - Edited to work with Mouse Map Addon
    Map v1.0 - Addon added
    Name v1.0 - Addon added
    Shop v1.0 - Addon added
    Menu Screen v1.0 - Addon added
    Title/File v1.0 - Addon added
    Movement v1.1 - Fixed bug allowing movement at odd times
    avatar
    Hyde
    Administrator
    Administrator

    Registered on Registered on : 2012-05-18
    Posts Posts : 101
    Rep. Points Rep. Points : 6

    Re: Basic Mouse System + Addons

    Post by Hyde on Thu May 31, 2012 7:12 pm

    Ooooohh... Very nice. I personally love the fact that a mouse can be used with Ace. It just feels awkward to me having a computer game without any use of the mouse, and you fixed that for us. I will have to use this sometime.


    _________________


      Current date/time is Wed Aug 15, 2018 10:25 am