Advertisement
deadelf79

alchemy whatsoever

Jul 30th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.71 KB | None | 0 0
  1. module Vocab
  2.   AlchemyCraft = "Создать"
  3.   AlchemyCancel = "Отмена"
  4.   AlchemyNoItem = "Нет предмета"
  5.   AlchemyUnknownCombo = "Комбинация %d: ???"
  6.   Alchemy
  7. end
  8.  
  9. class RPG::Item
  10.   def initialize
  11.     super
  12.     make_combos
  13.   end
  14.  
  15.   def make_combos
  16.     @combos ||= []
  17.     if self.key?
  18.       notes = self.note.split(/\n/)
  19.       notes.each do |line|
  20.         if line=~/<Alchemy Combo/i
  21.           id = line.match(/<Alchemy Combo Item:[\s]*(\d+)*>/i)[1]
  22.           @combos.push {
  23.             :id => id,
  24.             :known => false
  25.           }
  26.         end
  27.       end
  28.     end
  29.   end
  30.  
  31.   def key?
  32.     return true if self.itype_id == 2
  33.     false
  34.   end
  35.  
  36.   def combos
  37.     make_combos if @combos.nil?
  38.     @combos
  39.   end
  40.  
  41.   def combo_known?(index)
  42.     @knowns
  43.   end
  44. end
  45.  
  46. class Window_Regi < Window_Selectable
  47.   def initialize
  48.     x, y, width, height = 0, 0, 272, 216
  49.     super(x, y, width, height)
  50.     @item = nil
  51.     self.index = -1
  52.     redraw
  53.     @max_combos = 0
  54.   end
  55.  
  56.   def redraw
  57.     self.contents.clear
  58.     draw_item_icon
  59.     draw_name
  60.     draw_desc
  61.     draw_combos
  62.   end
  63.  
  64.   def draw_item_icon
  65.     rect = Rect.new(0,0,48,48)
  66.     inner_rect = Rect.new(1,1,46,46)
  67.     contents.fill_rect(rect,Color.new(255,255,255))
  68.     contents.fill_rect(inner_rect,Color.new(255,255,255,0))
  69.     return if @item.nil?
  70.    
  71.     draw_icon $data_items[ @item ].icon_index, 12, 12
  72.   end
  73.  
  74.   def draw_name
  75.     rect = Rect.new( 64,0, self.contents.width-32, self.line_height )
  76.     if @item.nil?
  77.       draw_text(rect, Vocab::AlchemyNoItem)
  78.     else
  79.       draw_text(rect, $data_items[ @item ].name)
  80.     end
  81.   end
  82.  
  83.   def draw_desc
  84.     unless @item.nil?
  85.       draw_text_ex( 0, 48, $data_items[ @item ].description )
  86.     end
  87.   end
  88.  
  89.   def draw_combos
  90.     unless @item.nil?
  91.       if $data_items[ @item ].key?
  92.         @max_combos = $data_items[ @item ].combos.size
  93.         for index in 0...@max_combos
  94.           combo = $data_items[ @item ].combos[ index ]
  95.           rect = Rect.new(
  96.             16,
  97.             96+index*line_height,
  98.             contents.width-16,
  99.             line_height
  100.           )
  101.           rect_rect = Rect.new(
  102.             0,
  103.             96+index*line_height+line_height/2-2,
  104.             4,
  105.             4
  106.           )
  107.           contents.fill_rect( rect_rect, Color.new(255,255,255) )
  108.           draw_text(rect, $data_items[ combo[ :id ].to_i ].name)
  109.         end
  110.       end
  111.     end
  112.   end
  113.  
  114.   def item=(id)
  115.     id = nil if id == 0
  116.     @item = id
  117.     redraw
  118.   end
  119.  
  120.   def update_cursor
  121.     if @index == -1
  122.       cursor_rect.set(0, 0, contents.width, contents.height)
  123.     elsif @index == 0
  124.       cursor_rect.set(0, 0, contents.width, 48)
  125.     else
  126.       if @max_combos > 0
  127.         cursor_rect.set(96+@index*line_height,contents.width,line_height)
  128.       else
  129.         @index = 0
  130.       end
  131.     end
  132.   end
  133. end
  134.  
  135. class Window_Confirm < Window_Command
  136.   def initialize
  137.     x, y, width, height = (Graphics.width-272)/2, Graphics.height - 48, 272, 48
  138.     super(x, y)
  139.     self.width = width
  140.     self.height = height
  141.     self.create_contents
  142.     self.draw_all_items
  143.     self.index = 0
  144.   end
  145.  
  146.   def col_max
  147.     2
  148.   end
  149.  
  150.   def make_command_list
  151.     add_command Vocab::AlchemyCraft, :craft
  152.     add_command Vocab::AlchemyCancel, :cancel
  153.   end
  154.  
  155.   def alignment
  156.     1
  157.   end
  158. end
  159.  
  160. class Window_RegiList < Window_Command
  161.   def initialize
  162.     x, y ,width, height = 0,0, 272, 160
  163.     super(x,y)
  164.     self.width = width
  165.     self.height = height
  166.     self.create_contents
  167.     self.draw_all_items
  168.   end
  169.  
  170.   def make_command_list
  171.    
  172.   end
  173. end
  174.  
  175. class Scene_Alchemy < Scene_MenuBase
  176.   def start
  177.     super
  178.     create_floating_windows
  179.     create_options
  180.     @index = 0
  181.   end
  182.  
  183.   def create_floating_windows
  184.     @floating_windows = []
  185.     @abscissa = [ 0, Graphics.width - 272, 0, Graphics.width - 272 ]
  186.     @ordinate = [ 0,0,216,216 ]
  187.     for index in 0...4
  188.       @floating_windows[ index ] = Window_Regi.new
  189.       @floating_windows[ index ].x = @abscissa[ index ]
  190.       @floating_windows[ index ].y = @ordinate[ index ]
  191.       @floating_windows[ index ].set_handler(:ok, method(:on_input_ok))
  192.     end
  193.     @floating_windows[ 0 ].activate
  194.     @floating_windows[ 0 ].item = 52
  195.   end
  196.  
  197.   def create_options
  198.     @options_window = Window_Confirm.new
  199.     @options_window.deactivate
  200.   end
  201.  
  202.   def update
  203.     super
  204.     case @index
  205.     when 0,1,2,3
  206.       @floating_windows[ @index ].update
  207.     when 4
  208.       @options_window.update
  209.     end
  210.   end
  211.  
  212.   def on_input_ok
  213.     if [0,1,2,3].include? @index
  214.       @floating_windows[ @index ].activate
  215.       @floating_windows[ @index ].index = 0
  216.     else
  217.      
  218.     end
  219.   end
  220. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement