Advertisement
nathmatt

Mouse Map Menu Version: 1.26

May 22nd, 2011
876
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.32 KB | None | 0 0
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
  2. # Mouse Map Menu by Nathmatt
  3. # Version: 1.26
  4. # Type: Menu
  5. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
  6. #  
  7. #  This work is protected by the following license:
  8. # #----------------------------------------------------------------------------
  9. # #  
  10. # #  Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported
  11. # #  ( http://creativecommons.org/licenses/by-nc-sa/3.0/ )
  12. # #  
  13. # #  You are free:
  14. # #  
  15. # #  to Share - to copy, distribute and transmit the work
  16. # #  to Remix - to adapt the work
  17. # #  
  18. # #  Under the following conditions:
  19. # #  
  20. # #  Attribution. You must attribute the work in the manner specified by the
  21. # #  author or licensor (but not in any way that suggests that they endorse you
  22. # #  or your use of the work).
  23. # #  
  24. # #  Noncommercial. You may not use this work for commercial purposes.
  25. # #  
  26. # #  Share alike. If you alter, transform, or build upon this work, you may
  27. # #  distribute the resulting work only under the same or similar license to
  28. # #  this one.
  29. # #  
  30. # #  - For any reuse or distribution, you must make clear to others the license
  31. # #    terms of this work. The best way to do this is with a link to this web
  32. # #    page.
  33. # #  
  34. # #  - Any of the above conditions can be waived if you get permission from the
  35. # #    copyright holder.
  36. # #  
  37. # #  - Nothing in this license impairs or restricts the author's moral rights.
  38. # #  
  39. # #----------------------------------------------------------------------------
  40. #
  41. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
  42. module Mouse_Map_Menu
  43.  
  44.   Version = 1.26
  45.   #============================================================================
  46.   # Mouse_Map_Menu::Config
  47.   #----------------------------------------------------------------------------
  48.   #  This module performs the the configurations.
  49.   #============================================================================
  50.   module Config
  51.     Condition = 0               # 0 for Horizontal 1 for Vertical
  52.     Icons     = ['040-Item09']  # Array of menu icons
  53.     Key       = ['M']           # Array of keys that will call the scene
  54.     Scenes    = [Scene_Menu]    # Array of scenes add Back to to return to map
  55.                                 # when not on map Scene_End if you are
  56.     Mouse     = false           # The mouse graphic while over a command
  57.                                 # or false for none
  58.     Back      = false           # The picture back for each icon or false for none
  59.     Window    = false           # The picture used like a window for the icons
  60.                                 # or false for none
  61.     X         = 0               # The x co-ordanance is by 32
  62.     Y         = 14              # The y co-ordanance is by 32
  63.   end
  64.   #============================================================================
  65.   # Mouse_Map_Menu::Processor
  66.   #----------------------------------------------------------------------------
  67.   #  This class performs the mouse processing.
  68.   #============================================================================
  69.   class Processor
  70.    
  71.     attr_reader   :event_disabled
  72.     attr_accessor :menu_disabled
  73.    
  74.     CON    = Config::Condition
  75.     ICONS  = Config::Icons
  76.     KEY    = Config::Key
  77.     SCENES = Config::Scenes
  78.     MOUSE  = Config::Mouse
  79.     BACK   = Config::Back
  80.     WINDOW = Config::Window
  81.     SIZE   = ICONS.size
  82.     X      = Config::X * 32
  83.     Y      = Config::Y * 32
  84.     W      = (CON == 0 ? SIZE * 32 : 32)
  85.     H      = (CON == 1 ? SIZE * 32 : 32)
  86.    
  87.     def main
  88.       return if @window != nil
  89.       @window,@back,@menu = Sprite.new,Sprite.new,Sprite.new
  90.       @window.z,@back.z,@menu.z = 100,150,200
  91.       @window.x = @back.x = @menu.x = X
  92.       @window.y = @back.y = @menu.y = Y
  93.       @window.bitmap = RPG::Cache.picture(WINDOW) if WINDOW != false
  94.       @back.bitmap = Bitmap.new(W,H)
  95.       @menu.bitmap = Bitmap.new(W,H)
  96.       @disabled = []
  97.       (0...SIZE).each{|i|draw_command(i)}
  98.     end
  99.    
  100.     def draw_command(i)
  101.       x,y = (CON == 0 ? (i * 32) : 0),(CON == 1 ? (i * 32) : 0)
  102.       rect = Rect.new(x,y,32,32)
  103.       @menu.bitmap.fill_rect(rect,Color.new(0,0,0,0))
  104.       if BACK != false
  105.         item = RPG::Cache.picture(BACK)
  106.         @back.bitmap.stretch_blt(rect,item,Rect.new(0,0,item.width,item.height))
  107.       end
  108.       item = RPG::Cache.icon(ICONS[i])
  109.       opacity = (@disabled[i] ? 128 : 255)
  110.       @menu.bitmap.fill_rect(rect,Color.new(0,0,0,0))
  111.       @menu.bitmap.blt(x+4,y+4,item,Rect.new(0,0,24,24),opacity)
  112.     end
  113.    
  114.     def update
  115.       dispose if @menu_disabled
  116.       main    if !@menu_disabled
  117.       return if @menu == nil
  118.       check_mouse
  119.       check_opacity
  120.       i = check_keys
  121.       @event_disabled = (i != false)
  122.       if i != false
  123.         if SCENES[i] == 'Back'
  124.           $scene = ($scene.is_a?(Scene_Map) ? Scene_End.new : Scene_Map.new)
  125.           return
  126.         end
  127.         $scene = SCENES[i].new
  128.       end
  129.     end
  130.      
  131.     def check_mouse
  132.       return if MOUSE == false
  133.       i = over_button?
  134.       if $MCES != nil
  135.         $MCES.mouse_menu = (i != false)
  136.         return
  137.       end
  138.       if i != false
  139.         $mouse.set_cursor(MOUSE)
  140.       else
  141.         $mouse.set_cursor(Mouse::MOUSE_ICON)
  142.       end
  143.     end
  144.    
  145.     def check_keys
  146.       return over_button? if Input.trigger?(Input::Key['Mouse Left'])
  147.       (0...SIZE).each{|i|
  148.       return i if Config::Key[i] != nil &&
  149.         Input.trigger?(Input::Key[Config::Key[i]])}
  150.       return false
  151.     end
  152.    
  153.     def over_button?
  154.       (0...SIZE).each{|i|
  155.       x,y = (CON == 0 ? (X + i * 32) : X),(CON == 1 ? (Y + i * 32) : Y)
  156.       if $mouse.x >= x && $mouse.y >= y && $mouse.x <= x + 32 && $mouse.y <= y + 32
  157.         return i
  158.       end}
  159.       return false
  160.     end
  161.  
  162.     def dispose
  163.       [@window,@back,@menu].each{|s|s.dispose if s != nil && !s.disposed?}
  164.       @window = @back = @menu = nil
  165.     end
  166.     def mouse_in_area?
  167.       return false if @menu == nil || @menu.disposed?
  168.       s = @menu
  169.       b = s.bitmap
  170.       return $game_player.screen_x <= s.x + b.width &&
  171.          $game_player.screen_y <= s.y + b.height &&
  172.          $game_player.screen_x >= s.x && $game_player.screen_y >= s.y
  173.     end
  174.    
  175.    
  176.     def check_opacity
  177.       if mouse_in_area?
  178.         @menu.opacity -= 25 if @menu.opacity > 80
  179.       elsif @menu.opacity <= 255
  180.         @menu.opacity += 25
  181.       end
  182.       [@window,@back,@menu].each{|s|s.opacity = @menu.opacity if !s.disposed?}
  183.     end
  184.    
  185.   end
  186.  
  187. end
  188.  
  189. $mouse_map_menu = Mouse_Map_Menu::Processor.new
  190.  
  191. class Scene_Map
  192.  
  193.   alias mouse_map_menu_main main
  194.   def main
  195.     $mouse_map_menu.main
  196.     mouse_map_menu_main
  197.     $mouse_map_menu.dispose
  198.   end
  199.  
  200.   alias mouse_map_menu_update update
  201.   def update
  202.     $mouse_map_menu.update
  203.     mouse_map_menu_update
  204.   end
  205.  
  206. end
  207.  
  208. class Game_Event < Game_Character
  209.  
  210.   alias start_event_menu start
  211.   def start
  212.     return if $mouse_map_menu.event_disabled
  213.     start_event_menu
  214.   end
  215.  
  216. end
  217.  
  218. if $MCES != nil
  219. class MCES::Processor
  220.  
  221.   attr_accessor :mouse_menu
  222.  
  223.   alias mouse_menu_check_mouse check_mouse
  224.   def check_mouse
  225.     if @mouse_menu
  226.       $mouse.set_cursor(Mouse_Map_Menu::Config::Mouse)
  227.       return
  228.     end
  229.     mouse_menu_check_mouse
  230.   end
  231.  
  232. end
  233. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement