molegato

Event info

Feb 28th, 2012
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.39 KB | None | 0 0
  1. #==============================================================================
  2. # EVENT INFO WINDOW
  3. # Author Molegato
  4. # Version 1.0
  5. #------------------------------------------------------------------------------
  6. # Displays a window with info about an event
  7. #------------------------------------------------------------------------------
  8. # INSTRUCTIONS
  9. # You have to use tags on comments
  10. # You cannot add more than a single tag to each comment, so you'll have to
  11. # use multiple comments with a single line. Sorry about that.
  12. # In the comments, you can use the following tags, all of them are optional
  13. # and you can use some of them for an event, and a different set for another
  14. #
  15. # <event_info>                This event has info, and a window will appear
  16. #                             when the player is near. This tag is neccessary
  17. #                             for the rest of tags to even have a meaning.
  18. # <event_name: name>          This is the name to display.
  19. # <event_name_color: id>      The color id for the name.
  20. #* <event_descript: text>      A line of text for the event info
  21. #* <event_descript_color: id>  The color id for the description.
  22. # <event_icon: index>         The index of the icon to show, if any.
  23. # <event_face: name, index>   The name of the face image, and the index.
  24. #==============================================================================
  25.  
  26. $imported = {} if $imported.nil?
  27. $imported['Molegato-Event_info'] = true
  28.  
  29. #==============================================================================
  30. # CONFIGURATION, YOU CAN TOUCH THIS
  31. #==============================================================================
  32.  
  33. module MOLEGATO_EVENT_INFO
  34.   #Minimum distance in tiles to an event to show its information
  35.   DISTANCE = 4
  36.  
  37.   #Window parameters
  38.   WINDOW = 'Window'
  39.   TONE = [255,255,255,255]
  40.   OPACITY = 255
  41.   X = 0
  42.   Y = Graphics.height-75
  43.   WIDTH = 250
  44.   HEIGHT = 75
  45.  
  46.   #Images
  47.   USE_IMAGE1 = false
  48.   IMAGE1_NAME = ''
  49.   IMAGE1_X = 0
  50.   IMAGE1_Y = 0
  51.   USE_IMAGE2 = false
  52.   IMAGE2_NAME = ''
  53.   IMAGE2_X = 0
  54.   IMAGE2_Y = 0
  55.  
  56.   #Event name
  57.   NAME_FONT_SIZE = Font.default_size
  58.   NAME_X = 50
  59.   NAME_Y = 0
  60.   NAME_WIDTH = 200
  61.   NAME_HEIGHT =32
  62.   NAME_ALIGN=0 #0 for left, 1 for center, 2 for right
  63.  
  64.   #Event Descript
  65.   DES_FONT_SIZE = Font.default_size-6
  66.   DES_X = 50
  67.   DES_Y = 24
  68.   DES_WIDTH = 200
  69.   DES_HEIGHT =32
  70.   DES_ALIGN=0 #0 for left, 1 for center, 2 for right
  71.  
  72.   #Event icon
  73.   ICON_X = 0
  74.   ICON_Y = 0
  75.  
  76.   #Event face
  77.   FACE_X = 0
  78.   FACE_Y = 0
  79.   FACE_SCALE = 0.5
  80.  
  81. end
  82. #==============================================================================
  83. # END OF CONFIGURATION. EVERYTHING UNDER HERE IS A HELLISH MESS OF DEFICIENT
  84. # AMATEUR SCRIPTING. BE AWARE THAT MESSING WITH IT CAN RESULT IN DISASTER
  85. #==============================================================================
  86.  
  87.  
  88.  
  89.  
  90. #==============================================================================
  91. # ■ Game_Event
  92. #==============================================================================
  93.  
  94. class Game_Event < Game_Character
  95.   attr_reader   :x                  # トリガー
  96.   attr_reader   :y                     # 実行内容
  97. end
  98.  
  99. #==============================================================================
  100. # ■ Window_Event_info
  101. #==============================================================================
  102.  
  103. class Window_Event_info < Window_Base
  104.   attr_accessor   :event
  105.  
  106.   def initialize
  107.     super(MOLEGATO_EVENT_INFO::X, MOLEGATO_EVENT_INFO::Y, MOLEGATO_EVENT_INFO::WIDTH, MOLEGATO_EVENT_INFO::HEIGHT)
  108.     self.openness = 0
  109.     refresh
  110.     self.windowskin = Cache.system(MOLEGATO_EVENT_INFO::WINDOW)
  111.     self.opacity=MOLEGATO_EVENT_INFO::OPACITY
  112.   end
  113.  
  114.   def refresh
  115.     contents.clear
  116.     if not @event
  117.       return
  118.     end
  119.    
  120.     #Draw image 1
  121.     if MOLEGATO_EVENT_INFO::USE_IMAGE1
  122.       draw_system(MOLEGATO_EVENT_INFO::IMAGE1_NAME,MOLEGATO_EVENT_INFO::IMAGE1_X,MOLEGATO_EVENT_INFO::IMAGE1_Y)
  123.     end
  124.  
  125.     #Draw face
  126.     if @event.tag_check_multivalues(@event.note,"event_face")
  127.       facename=@event.tag_check_multivalues(@event.note,"event_face")[0]
  128.       faceindex=@event.tag_check_multivalues(@event.note,"event_face")[1].to_i
  129.       if open?
  130.         draw_face_scaled(facename, faceindex, MOLEGATO_EVENT_INFO::FACE_X, MOLEGATO_EVENT_INFO::FACE_Y, MOLEGATO_EVENT_INFO::FACE_SCALE)
  131.       end
  132.     end
  133.  
  134.     #Draw icon
  135.     if @event.tag_check_multivalues(@event.note,"event_icon")
  136.       draw_icon(@event.tag_check_multivalues(@event.note,"event_icon")[0].to_i, MOLEGATO_EVENT_INFO::ICON_X, MOLEGATO_EVENT_INFO::ICON_Y, true)
  137.     end
  138.  
  139.     #Draw image 2
  140.     if MOLEGATO_EVENT_INFO::USE_IMAGE2
  141.       draw_system(MOLEGATO_EVENT_INFO::IMAGE2_NAME,MOLEGATO_EVENT_INFO::IMAGE2_X,MOLEGATO_EVENT_INFO::IMAGE2_Y)    end
  142.    
  143.     #Draw name
  144.     if @event.tag_check_multivalues(@event.note,"event_name")
  145.       if @event.tag_check_multivalues(@event.note,"event_name_color")
  146.         change_color(text_color(event.tag_check_multivalues(event.note,"event_name_color")[0].to_i))
  147.       else
  148.         change_color(normal_color)
  149.       end
  150.       contents.font.size = MOLEGATO_EVENT_INFO::NAME_FONT_SIZE
  151.       draw_text(MOLEGATO_EVENT_INFO::NAME_X,MOLEGATO_EVENT_INFO::NAME_Y,MOLEGATO_EVENT_INFO::NAME_WIDTH,MOLEGATO_EVENT_INFO::NAME_HEIGHT,@event.tag_check_multivalues(event.note,"event_name")[0],MOLEGATO_EVENT_INFO::NAME_ALIGN)
  152.     end
  153.    
  154.     #Draw description
  155.     if @event.tag_check_multivalues(@event.note,"event_descript")
  156.       if @event.tag_check_multivalues(@event.note,"event_descript_color")
  157.         change_color(text_color(event.tag_check_multivalues(event.note,"event_descript_color")[0].to_i))
  158.       else
  159.         change_color(normal_color)
  160.       end
  161.       contents.font.size = MOLEGATO_EVENT_INFO::DES_FONT_SIZE
  162.       draw_text(MOLEGATO_EVENT_INFO::DES_X,MOLEGATO_EVENT_INFO::DES_Y,MOLEGATO_EVENT_INFO::DES_WIDTH,MOLEGATO_EVENT_INFO::DES_HEIGHT,@event.tag_check_multivalues(event.note,"event_descript")[0],MOLEGATO_EVENT_INFO::DES_ALIGN)
  163.     end
  164.  
  165.   end
  166.  
  167.   def update_open
  168.     super
  169.     refresh
  170.   end
  171.  
  172.   def update_close
  173.     super
  174.     refresh
  175.   end
  176.  
  177. end
  178.  
  179. #==============================================================================
  180. # ■ Scene_Map
  181. #==============================================================================
  182.  
  183. class Scene_Map < Scene_Base
  184.   alias event_info_start start
  185.   def start
  186.     event_info_start
  187.     create_event_info_window
  188.   end
  189.  
  190.   def create_event_info_window
  191.     @event_info=Window_Event_info.new
  192.     @event_info.instant_close
  193.   end
  194.  
  195.   alias event_info_update_scene update_scene
  196.   def update_scene
  197.     event_info_update_scene  
  198.     minimum_dis=8
  199.     for i in -1*MOLEGATO_EVENT_INFO::DISTANCE..MOLEGATO_EVENT_INFO::DISTANCE
  200.       for e in -1*MOLEGATO_EVENT_INFO::DISTANCE..MOLEGATO_EVENT_INFO::DISTANCE
  201.         if $game_map.events_xy($game_player.x+i,$game_player.y+e)[0]
  202.           dis = i.abs + e.abs
  203.           current_event=$game_map.events_xy($game_player.x+i,$game_player.y+e)[0]
  204.          
  205.           if dis<minimum_dis and current_event.has_tag?("event_info")
  206.             minimum_dis=dis
  207.             near_event=current_event
  208.           end
  209.         end
  210.       end
  211.     end
  212.  
  213.     if near_event
  214.       if not @event_info.open?
  215.         @event_info.open
  216.         @event_info.event=near_event
  217.         @event_info.refresh
  218.       end
  219.     else
  220.       @event_info.close
  221.     end
  222.    
  223.   end
  224.  
  225.  
  226. end
Advertisement
Add Comment
Please, Sign In to add comment