#======================================================= # Autor: Raizen # Lune Item Grid Shop # Comunidade : www.centrorpg.com # Adds Grid function on Shops, requires Lune Item Grid #======================================================= $imported ||= {} $imported[:Lune_Item_Grid_Shop] = true module Lune_Item_Grid # Show windows on shop? Show_Windows = false # Shop Image, Image must be in Graphics/Item_Grid Image_Buy = "" # Shop correction position, in case using an image Shop_Position_X = - 6 Shop_Position_Y = - 8 end #============================================================================== # ** Scene_Shop #------------------------------------------------------------------------------ # Esta classe executa o processamento da tela de loja. #============================================================================== class Scene_Shop < Scene_MenuBase alias :lune_item_grid_start :start alias :lune_item_grid_on_sell_ok :on_sell_ok alias :lune_item_grid_on_sell_cancel :on_sell_cancel alias :lune_item_grid_command_sell :command_sell alias :lune_item_grid_update :update alias :lune_item_grid_do_buy :do_buy alias :lune_item_grid_do_sell :do_sell #-------------------------------------------------------------------------- # * Inicialização do processo #-------------------------------------------------------------------------- def start msgbox("Missing Lune Item Grid Script!!!") unless $imported[:Lune_Item_Grid] lune_item_grid_start create_back_sprite @category_window.contents_opacity = 0 @category_window.opacity = 0 unless Lune_Item_Grid::Show_Windows @gold_window.opacity = 0 @command_window.opacity = 0 @dummy_window.opacity = 0 @number_window.opacity = 0 @status_window.opacity = 0 @buy_window.opacity = 0 @help_window.opacity = 0 @dummy_sell_window.opacity = 0 end end #-------------------------------------------------------------------------- # * Criação de Imagens #-------------------------------------------------------------------------- def create_back_sprite @back_sprite_grid = Sprite.new @back_sprite_grid.bitmap = Cache.item_grid(Lune_Item_Grid::Image) @back_sprite_buy = Sprite.new @back_sprite_buy.bitmap = Cache.item_grid(Lune_Item_Grid::Image_Buy) end #-------------------------------------------------------------------------- # * Criação da janela de venda #-------------------------------------------------------------------------- def create_sell_window wy = @category_window.y wh = Graphics.height - wy @dummy_sell_window = Window_Base.new(0, wy, Graphics.width, wh) @dummy_sell_window.hide wy = @category_window.y wh = Graphics.height - wy @sell_window = Window_Grid_ItemList.new(0, wy, Graphics.width, wh + 20) @sell_window.viewport = @viewport @sell_window.help_window = @help_window @sell_window.hide @sell_window.set_handler(:ok, method(:on_sell_ok)) @sell_window.set_handler(:cancel, method(:on_sell_cancel)) @sell_window.x += Lune_Item_Grid::Grid_Position_X @sell_window.y += Lune_Item_Grid::Grid_Position_Y @category_window.item_window = @sell_window @sell_window.opacity = 0 end #-------------------------------------------------------------------------- # * Atualização da tela #-------------------------------------------------------------------------- def update(*args, &block) lune_item_grid_update(*args, &block) if @sell_window.visible && !@dummy_sell_window.visible @dummy_sell_window.show @back_sprite_grid.opacity = 255 @back_sprite_buy.opacity = 0 end if !@sell_window.visible && @dummy_sell_window.visible && !@command_window.active @dummy_sell_window.hide @back_sprite_grid.opacity = 0 @back_sprite_buy.opacity = 255 end end #-------------------------------------------------------------------------- # * Comando [Vender] #-------------------------------------------------------------------------- def command_sell @dummy_window.hide @sell_window.show @sell_window.activate @sell_window.refresh @sell_window.index = 0 end #-------------------------------------------------------------------------- # * Venda [Cancelamento] #-------------------------------------------------------------------------- def on_sell_cancel @sell_window.hide @command_window.activate @status_window.item = nil @help_window.clear end #-------------------------------------------------------------------------- # * Ativação da janela de venda #-------------------------------------------------------------------------- def on_sell_ok unless @sell_window.item Sound.play_buzzer activate_sell_window return end lune_item_grid_on_sell_ok end #-------------------------------------------------------------------------- # * Aquisição do número máximo disponível para compra #-------------------------------------------------------------------------- def max_buy max = 1 buying_price == 0 ? max : [max, money / buying_price].min end #-------------------------------------------------------------------------- # * Aquisição do número máximo disponível para compra #-------------------------------------------------------------------------- def max_buy 1 end #-------------------------------------------------------------------------- # * Execução da compra # number : número de itens #-------------------------------------------------------------------------- def do_buy(number) lune_item_grid_do_buy(number) @sell_window.dispose create_sell_window end #-------------------------------------------------------------------------- # * Execução da compra # number : número de itens #-------------------------------------------------------------------------- def do_sell(number) lune_item_grid_do_sell(number) @sell_window.dispose create_sell_window end end #============================================================================== # ** Window_ShopNumber #------------------------------------------------------------------------------ # Esta janela é para entrada da quantia de itens que será comprada ou # vendida na tela de loja. #============================================================================== class Window_ShopNumber < Window_Selectable #-------------------------------------------------------------------------- # * Variáveis públicas #-------------------------------------------------------------------------- attr_reader :number # Número digitado #-------------------------------------------------------------------------- # * Inicialização do objeto # x : coordenada X # y : coordenada Y # height : altura #-------------------------------------------------------------------------- def initialize(x, y, height) super(x, y, window_width, height) @item = nil @max = 1 @price = 0 @number = 1 @currency_unit = Vocab::currency_unit end #-------------------------------------------------------------------------- # * Aquisição da largura da janela #-------------------------------------------------------------------------- def window_width return 304 end #-------------------------------------------------------------------------- # * Definição de itens, quantia máxima, preço e unidade monetária # item : item # max : quantia máxima # price : preço # currency_unit : unidade mo #-------------------------------------------------------------------------- def set(item, max, price, currency_unit = nil) @item = item @max = max @price = price @currency_unit = currency_unit if currency_unit @number = 1 refresh end #-------------------------------------------------------------------------- # * Renovação #-------------------------------------------------------------------------- def refresh contents.clear draw_item_name(@item, 0, item_y) draw_number draw_total_price end #-------------------------------------------------------------------------- # * Desenho do número de itens #-------------------------------------------------------------------------- def draw_number change_color(normal_color) #draw_text(cursor_x, item_y, cursor_width - 4, line_height, @number, 2) draw_item(cursor_x, item_y, @item) end #-------------------------------------------------------------------------- # * Desenho do preço total #-------------------------------------------------------------------------- def draw_total_price width = contents_width - 8 draw_currency_value(@price * @number, @currency_unit, 4, cursor_height+ price_y - 30, width) end #-------------------------------------------------------------------------- # * Desenho de um item # index : índice do item #-------------------------------------------------------------------------- def draw_item(x, y, item) if item if item.note.include?("" draw_grid_item(item.note[(count + 10)..(count + count2 + 9)], x, y) end end else draw_icon(item.icon_index, x, y, true) end #draw_item_number(rect, item) end end #-------------------------------------------------------------------------- # * Desenho de ícones # icon_index : índice do ícone # x : coordenada X # y : coordenada Y # enabled : habilitar flag, translucido quando false #-------------------------------------------------------------------------- def draw_grid_item(item_name, x, y) bitmap = Cache.item_grid(item_name) rect = Rect.new(0, 0, bitmap.width, bitmap.height) contents.blt(x, y, bitmap, rect, 255) end #-------------------------------------------------------------------------- # * Aquisição da largura do cursor #-------------------------------------------------------------------------- def cursor_width item_size = $game_party.get_item_size(@item) return item_size[0] * Lune_Item_Grid::Item_Size[0] end def cursor_height item_size = $game_party.get_item_size(@item) return item_size[1] * Lune_Item_Grid::Item_Size[1] end #-------------------------------------------------------------------------- # * Desenho do nome de itens # item : objeto # x : coordenada X # y : coordenada Y # enabled : habilitar flag, translucido quando false # width : largura #-------------------------------------------------------------------------- def draw_item_name(item, x, y, enabled = true, width = 172) return unless item change_color(normal_color, enabled) draw_text(x, y, width, line_height, item.name) end #-------------------------------------------------------------------------- # * Coordenada X de exibição do cursor #-------------------------------------------------------------------------- def cursor_x contents_width - cursor_width - 24 end #-------------------------------------------------------------------------- # * Atualização do número de itens #-------------------------------------------------------------------------- def update_number end #-------------------------------------------------------------------------- # * Atualização do cursor #-------------------------------------------------------------------------- def update_cursor cursor_rect.set(cursor_x, item_y, cursor_width, cursor_height) end end