Advertisement
gerkrt

RPGXP - ENG - Warning message

Sep 14th, 2011
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.25 KB | None | 0 0
  1. #==============================================================================
  2. # Warning message
  3. # By gerkrt/gerrtunk
  4. # Version: 1
  5. # License: GPL, credits
  6. #==============================================================================
  7. =begin
  8.  
  9. Features:
  10.  
  11. I created this script long ago for one of my menus and any other project. Its very flexible
  12. and can be used for a lot of things. It uses a modified window+sprite combination
  13. because i think that it looks better, anyway you can modify it or do what you want.
  14.  
  15. -The window size and position is based on the text size.
  16. -All other sizes or positions are set automatically.
  17. -It have methods for automatically visible/invisible, dipose,etc, all sprites
  18. and windows.
  19. -You can add a question to it. With this a modified version of a window command
  20. is actived.
  21. -You can changue the text, ask option, x and y in every call.
  22.  
  23. I use it with a variable in the Scene called "Warning_message_type" that defines
  24. the behavior of it.
  25.  
  26. =end
  27.  
  28. class Warning_Message
  29.   def initialize
  30.     # Default values when refreshing it
  31.     @default_x = 200
  32.     @default_y = 200
  33.     # Back text window
  34.     @text_window = Window_Base.new(120, 136, 400, 64)
  35.     @text_window.z = 252
  36.     @text_window.visible = false
  37.     # Text sprite
  38.     @text_sprite = Sprite.new
  39.     @text_sprite.z = 254
  40.     @text_sprite.x = 120
  41.     @text_sprite.y = 136
  42.     @text_sprite.bitmap = Bitmap.new(400,64)
  43.     # Testing bitmap for size test
  44.     @testing_bitmap =  Bitmap.new(1,1)
  45.     # Question window
  46.     @question_window = Window_Selection.new(80, ["Yes", "No"])
  47.     @question_window.x = 280
  48.     @question_window.y = 200
  49.     @question_window.z = 253
  50.     @question_window.back_opacity = 0
  51.     @question_window.opacity = 0
  52.     @question_window.active = false
  53.     @question_window.visible = false
  54.     # Back question window
  55.     @back_question_window = Window_Base.new(120, 136, 64, 64)
  56.     @back_question_window.x = 280
  57.     @back_question_window.y = 200
  58.     @back_question_window.z = 254
  59.     @back_question_window.visible = false
  60.  
  61.   end
  62.  
  63.   # Make all the sprites/windows visibles
  64.   def visible
  65.     @text_window.visible = true
  66.     @text_sprite.visible = true
  67.     # Question ones only if active
  68.     if @back_question_window.active
  69.       @question_window.visible = true
  70.       @back_question_window.visible = true
  71.     end
  72.   end
  73.  
  74.   # Make all the sprites/windows invisibles
  75.   def no_visible
  76.     @text_window.visible = false
  77.     @text_sprite.visible = false
  78.     @question_window.visible = false
  79.     @back_question_window.visible = false
  80.   end
  81.  
  82.   # Is question window active?
  83.   def active
  84.     return @question_window.active
  85.   end
  86.  
  87.   # Set question window active
  88.   def active=(value)
  89.     @question_window.active = value
  90.   end
  91.  
  92.   # Update all the sprites/windows visibles
  93.   def update
  94.     @text_window.update
  95.     @text_sprite.update
  96.     @back_question_window.update
  97.     @question_window.update
  98.   end
  99.  
  100.   # Draw the warning message
  101.   # question: called to add a yes/no window.
  102.   def refresh(message, question=true, x=@default_x, y=@default_y)
  103.     # Basic position settings
  104.     @text_window.y = y
  105.     @text_window.x = x
  106.     @text_sprite.x = x
  107.     @text_sprite.y = y
  108.     rect = @testing_bitmap.text_size(message)
  109.     # With question window or not. All the positions auto-setting are done here.
  110.     if question
  111.       @text_window.width = rect.width+26+40
  112.       @question_window.visible = true
  113.       @question_window.active = true
  114.       @back_question_window.visible = true
  115.       @question_window.x = @text_window.x+rect.width+4+6
  116.       @question_window.y = @text_window.y - 16
  117.       @back_question_window.x = @text_window.x+rect.width+4+16
  118.       @back_question_window.y = @text_window.y
  119.     else
  120.       @text_window.width = rect.width+26
  121.     end
  122.     # First update the back window
  123.     @text_window.update
  124.     @text_sprite.bitmap.clear
  125.     # Draw text
  126.     @text_sprite.bitmap.draw_text(0+10,0,400,64,message, 0)
  127.     @text_sprite.update
  128.   end
  129.  
  130.   # Dispose all the sprites/windows visibles
  131.   def dispose
  132.     @text_window.dispose
  133.     @text_sprite.dispose
  134.     @question_window.dispose
  135.     @back_question_window.dispose
  136.   end
  137. end
  138.  
  139.  
  140. class Window_Selection < Window_Command
  141.    #--------------------------------------------------------------------------
  142.   # * Update Cursor Rectangle
  143.   #--------------------------------------------------------------------------
  144.   def update_cursor_rect
  145.     # If cursor position is less than 0
  146.     if @index < 0
  147.       self.cursor_rect.empty
  148.       return
  149.     end
  150.     # Get current row
  151.     row = @index / @column_max
  152.     # If current row is before top row
  153.     if row < self.top_row
  154.       # Scroll so that current row becomes top row
  155.       self.top_row = row
  156.     end
  157.     # If current row is more to back than back row
  158.     if row > self.top_row + (self.page_row_max - 1)
  159.       # Scroll so that current row becomes back row
  160.       self.top_row = row - (self.page_row_max - 1)
  161.     end
  162.     # Calculate cursor width
  163.     cursor_width = (self.width / @column_max - 32)+11
  164.     # Calculate cursor coordinates
  165.     x = @index % @column_max * (cursor_width + 32)
  166.     y = @index / @column_max * 32 - self.oy
  167.     # Update cursor rectangle
  168.     self.cursor_rect.set(x-4, y, cursor_width, 32)
  169.   end
  170.  
  171. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement