Chaos Project

RPG Maker => RPG Maker Scripts => Script Requests => Topic started by: darklight on March 02, 2008, 12:24:20 pm

Title: [RESOLVED] Chaos Project shop screen
Post by: darklight on March 02, 2008, 12:24:20 pm
The shop screens from CP are awesome! It's got a better interface than the default shop screens, IMO. Is there a chance this script is public, or is there something like it? I was also wondering if there was a way to show all the different stat increases above PDEF and MDEF.

I believe Juan made a very nice one, but since my game only has 1 heroine (at least for now), I'd be left with a lot of empty space.

Thanks in advance ^_^

ETA: Talk about a very quick turnaround for this request, lol
Title: Re: [Request] Chaos Project-like shop screen
Post by: Blizzard on March 02, 2008, 12:45:27 pm
Actually it IS public. xD It's just not one of my usual scripts. I released it long time ago as part of my Blizzard Script Collection v1.0. Here you go:
#==============================================================================
# Shop layout from Chaos Project (Final Demo Version) by Blizzard
# Version: 2.0
#==============================================================================

#==============================================================================
# Window_ShopBuy
#==============================================================================

class Window_ShopBuy < Window_Selectable

  def initialize(shop_goods)
    super(320, 80, 308, 384)
    @shop_goods = shop_goods
    refresh
    self.index = 0
  end

  def item
    return @data[self.index]
  end

  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    @shop_goods.each {|goods_item|
        item = case goods_item[0]
        when 0 then $data_items[goods_item[1]]
        when 1 then $data_weapons[goods_item[1]]
        when 2 then $data_armors[goods_item[1]]
        end
        @data.push(item) if item != nil}
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      if $fontface != nil
        self.contents.font.name = $fontface
        self.contents.font.size = $fontsize
      elsif $defaultfonttype != nil
        self.contents.font.name = $defaultfonttype
        self.contents.font.size = $defaultfontsize
      end
      (0...@item_max).each {|i| draw_item(i)}
    end
  end

  def draw_item(index)
    item = @data[index]
    number = case item
    when RPG::Item then $game_party.item_number(item.id)
    when RPG::Weapon then $game_party.weapon_number(item.id)
    when RPG::Armor then $game_party.armor_number(item.id)
    end
    x = 4
    y = index * 32
    if item.price <= $game_party.gold && number < 99
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    rect = Rect.new(x, y, self.width - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(item.icon_name)
    opacity = self.contents.font.color == normal_color ? 255 : 128
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    if item.price <= $game_party.gold && number < 99
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
    self.contents.draw_text(x + 176, y, 88, 32, item.price.to_s, 2)
  end
 
  def update_help
    @help_window.set_text(self.item == nil ? "" : self.item.description)
  end
 
end

#==============================================================================
# Window_ShopSell
#==============================================================================

class Window_ShopSell < Window_Selectable

  def initialize
    super(16, 80, 608, 320)
    @column_max = 2
    self.z = 4000
    refresh
    self.index = 0
  end

  def item
    return @data[self.index]
  end

  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    (1...$data_items.size).each {|i|
        @data.push($data_items[i]) if $game_party.item_number(i) > 0}
    (1...$data_weapons.size).each {|i|
        @data.push($data_weapons[i]) if $game_party.weapon_number(i) > 0}
    (1...$data_armors.size).each {|i|
        @data.push($data_armors[i]) if $game_party.armor_number(i) > 0}
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      if $fontface != nil
        self.contents.font.name = $fontface
        self.contents.font.size = $fontsize
      elsif $defaultfonttype != nil
        self.contents.font.name = $defaultfonttype
        self.contents.font.size = $defaultfontsize
      end
      (0...@item_max).each {|i| draw_item(i)}
    end
  end

  def draw_item(index)
    item = @data[index]
    number = case item
    when RPG::Item then $game_party.item_number(item.id)
    when RPG::Weapon then $game_party.weapon_number(item.id)
    when RPG::Armor then $game_party.armor_number(item.id)
    end
    x = 4 + index % 2 * 304
    y = index / 2 * 32
    if item.price > 0
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    rect = Rect.new(x, y, self.width / @column_max - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(item.icon_name)
    opacity = self.contents.font.color == normal_color ? 255 : 128
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    if item.price > 0
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
    self.contents.draw_text(x + 224, y, 16, 32, ":", 1)
    self.contents.draw_text(x + 240, y, 24, 32, number.to_s, 2)
  end

  def update_help
    @help_window.set_text(self.item == nil ? "" : self.item.description)
  end
 
end

#==============================================================================
# Window_ShopNumber
#==============================================================================

class Window_ShopNumber < Window_Base

  def initialize
    super(320, 80, 308, 384)
    self.contents = Bitmap.new(width - 32, height - 32)
    if $fontface != nil
      self.contents.font.name = $fontface
      self.contents.font.size = $fontsize
    elsif $defaultfonttype != nil
      self.contents.font.name = $defaultfonttype
      self.contents.font.size = $defaultfontsize
    end
    @item = nil
    @max = 1
    @price = 0
    @number = 1
    self.z = 5000
  end

  def set(item, max, price)
    @item = item
    @max = max
    @price = price
    @number = 1
    refresh
  end

  def number
    return @number
  end

  def refresh
    self.contents.clear
    self.contents.font.color = system_color
    self.contents.draw_text(4, 0, 276, 32, "How many?")
    draw_item_name(@item, 4, 96)
    self.contents.font.color = normal_color
    self.contents.draw_text(208, 96, 32, 32, "×")
    self.contents.draw_text(244, 96, 24, 32, @number.to_s, 2)
    self.cursor_rect.set(240, 96, 32, 32)
    domination = $data_system.words.gold
    cx = contents.text_size(domination).width
    total_price = @price * @number
    self.contents.font.color = normal_color
    self.contents.draw_text(4, 128, 308-cx, 32, total_price.to_s, 2)
    self.contents.font.color = system_color
    self.contents.draw_text(268-cx, 160, cx, 32, domination, 2)
  end

  def update
    super
    if self.active
      if Input.repeat?(Input::RIGHT) && @number < @max
        $game_system.se_play($data_system.cursor_se)
        @number += 1
        refresh
      elsif Input.repeat?(Input::LEFT) && @number > 1
        $game_system.se_play($data_system.cursor_se)
        @number -= 1
        refresh
      elsif Input.repeat?(Input::UP) && @number < @max
        $game_system.se_play($data_system.cursor_se)
        @number = [@number + 10, @max].min
        refresh
      elsif Input.repeat?(Input::DOWN) && @number > 1
        $game_system.se_play($data_system.cursor_se)
        @number = [@number - 10, 1].max
        refresh
      end
    end
  end
 
end

#==============================================================================
# Window_ShopStatus
#==============================================================================

class Window_ShopStatus < Window_Base

  def initialize
    super(16, 80, 304, 320)
    self.contents = Bitmap.new(width - 32, height - 32)
    if $fontface != nil
      self.contents.font.name = $fontface
      self.contents.font.size = $fontsize
    elsif $defaultfonttype != nil
      self.contents.font.name = $defaultfonttype
      self.contents.font.size = $defaultfontsize
    end
    @item = nil
    self.z = 4000
    refresh
  end

  def refresh
    self.contents.clear
    return if @item == nil
    number = case @item
    when RPG::Item then $game_party.item_number(@item.id)
    when RPG::Weapon then $game_party.weapon_number(@item.id)
    when RPG::Armor then $game_party.armor_number(@item.id)
    end
    self.contents.font.color = system_color
    self.contents.draw_text(44, 0, 200, 32, "possesed")
    self.contents.font.color = normal_color
    self.contents.draw_text(4, 0, 32, 32, number.to_s, 2)
    return if @item.is_a?(RPG::Item)
    (0...$game_party.actors.size).each {|i|
        actor = $game_party.actors[i]
        if actor.equippable?(@item)
          self.contents.font.color = normal_color
        else
          self.contents.font.color = disabled_color
        end
        self.contents.draw_text(4, 32 + 64 * i, 120, 32, actor.name)
        if @item.is_a?(RPG::Weapon)
          item1 = $data_weapons[actor.weapon_id]
        elsif @item.kind == 0
          item1 = $data_armors[actor.armor1_id]
        elsif @item.kind == 1
          item1 = $data_armors[actor.armor2_id]
        elsif @item.kind == 2
          item1 = $data_armors[actor.armor3_id]
        else
          item1 = $data_armors[actor.armor4_id]
        end
        if actor.equippable?(@item)
          if @item.is_a?(RPG::Weapon)
            atk1 = item1 != nil ? item1.atk : 0
            atk2 = @item != nil ? @item.atk : 0
            change1 = atk2 - atk1
          end
          if @item.is_a?(RPG::Armor)
            pdef1 = item1 != nil ? item1.pdef : 0
            mdef1 = item1 != nil ? item1.mdef : 0
            pdef2 = @item != nil ? @item.pdef : 0
            mdef2 = @item != nil ? @item.mdef : 0
            change1 = pdef2 - pdef1
            change2 = mdef2 - mdef1
          end
          if change2 != nil
            if actor.equippable?(@item)
              self.contents.font.color = normal_color
            else
              self.contents.font.color = disabled_color
            end
            self.contents.draw_text(156, 32 + 64 * i, 56, 32,
              sprintf("%+d", change1), 2)
            if actor.equippable?(@item)
              self.contents.font.color = normal_color
            else
              self.contents.font.color = disabled_color
            end
            self.contents.draw_text(212, 32 + 64 * i, 56, 32,
              sprintf("%+d", change2), 2)
          elsif change1 != nil
            if actor.equippable?(@item)
              self.contents.font.color = normal_color
            else
              self.contents.font.color = disabled_color
            end
            self.contents.draw_text(156, 32 + 64 * i, 112, 32,
              sprintf("%+d", change1), 2)
          end
        end
        if item1 != nil
          x = 4
          y = 64 + 64 * i
          bitmap = RPG::Cache.icon(item1.icon_name)
          opacity = self.contents.font.color == normal_color ? 255 : 128
          self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
          if actor.equippable?(@item)
            self.contents.font.color = normal_color
          else
            self.contents.font.color = disabled_color
          end
          self.contents.draw_text(x + 28, y, 212, 32, item1.name)
        end
        if change2 != nil
          self.contents.font.color = normal_color
          self.contents.draw_text(156, 0, 56, 32, "PDef", 2)
          self.contents.draw_text(212, 0, 56, 32, "MDef", 2)
        elsif change1 != nil
          self.contents.font.color = normal_color
          self.contents.draw_text(212, 0, 56, 32, "Atk", 2)
        end}
  end

  def item=(item)
    if @item != item
      @item = item
      refresh
    end
  end
 
end

#==============================================================================
# Scene_Shop
#==============================================================================

class Scene_Shop

  def main
    c = ["Buy", "Sell", "Cancel"]
    @help_window = Window_Help.new
    @command_window = Window_Command.new(192, c)
    @command_window.x = 16
    @command_window.y = 80
    @gold_window = Window_Gold.new
    @gold_window.x = 16
    @gold_window.y = 400
    @buy_window = Window_ShopBuy.new($game_temp.shop_goods)
    @buy_window.help_window = @help_window
    @sell_window = Window_ShopSell.new
    @sell_window.help_window = @help_window
    @number_window = Window_ShopNumber.new
    @status_window = Window_ShopStatus.new
    @buy_window.active = @buy_window.visible = @sell_window.active =
    @sell_window.visible = @number_window.active = @number_window.visible =
    @status_window.visible = false
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      break if $scene != self
    end
    Graphics.freeze
    [@help_window, @command_window, @gold_window, @buy_window, @sell_window,
        @number_window, @status_window].each {|win| win.dispose}
  end

  def update
    [@help_window, @command_window, @gold_window, @buy_window, @sell_window,
        @number_window, @status_window].each {|win| win.update}
    if @command_window.active
      update_command
    elsif @buy_window.active
      update_buy
    elsif @sell_window.active
      update_sell
    elsif @number_window.active
      update_number
    end
  end

  def update_command
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Map.new
    elsif Input.trigger?(Input::C)
      case @command_window.index
      when 0
        $game_system.se_play($data_system.decision_se)
        @command_window.active = false
        @buy_window.refresh
        @buy_window.active = @buy_window.visible = @status_window.visible = true
      when 1
        $game_system.se_play($data_system.decision_se)
        @command_window.active = false
        @sell_window.active = @sell_window.visible = true
        @sell_window.refresh
      when 2
        $game_system.se_play($data_system.decision_se)
        $scene = Scene_Map.new
      end
    end
  end

  def update_buy
    @status_window.item = @buy_window.item
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @command_window.active = true
      @buy_window.active = @buy_window.visible = @status_window.visible = false
      @status_window.item = nil
      @help_window.set_text("")
    elsif Input.trigger?(Input::C)
      @item = @buy_window.item
      if @item == nil or @item.price > $game_party.gold
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      number = case @item
      when RPG::Item then $game_party.item_number(@item.id)
      when RPG::Weapon then $game_party.weapon_number(@item.id)
      when RPG::Armor then $game_party.armor_number(@item.id)
      end
      if number == 99
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      $game_system.se_play($data_system.decision_se)
      max = @item.price == 0 ? 99 : $game_party.gold / @item.price
      max = [max, 99 - number].min
      @buy_window.active = @buy_window.visible = false
      @number_window.set(@item, max, @item.price)
      @number_window.active = @number_window.visible = true
    end
  end

  def update_sell
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @command_window.active = true
      @sell_window.active = @sell_window.visible = false
      @status_window.item = nil
      @help_window.set_text("")
    elsif Input.trigger?(Input::C)
      @item = @sell_window.item
      @status_window.item = @item
      if @item == nil or @item.price == 0
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      $game_system.se_play($data_system.decision_se)
      number = case @item
      when RPG::Item then $game_party.item_number(@item.id)
      when RPG::Weapon then $game_party.weapon_number(@item.id)
      when RPG::Armor then $game_party.armor_number(@item.id)
      end
      max = number
      @sell_window.active = @sell_window.visible = false
      @number_window.set(@item, max, @item.price / 2)
      @number_window.active = @number_window.visible = @status_window.visible = true
    end
  end

  def update_number
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @number_window.active = @number_window.visible = false
      case @command_window.index
      when 0
        @buy_window.active = @buy_window.visible = true
      when 1
        @sell_window.active = @sell_window.visible = true
        @status_window.visible = false
      end
    elsif Input.trigger?(Input::C)
      $game_system.se_play($data_system.shop_se)
      @number_window.active = @number_window.visible = false
      case @command_window.index
      when 0
        $game_party.lose_gold(@number_window.number * @item.price)
        case @item
        when RPG::Item then $game_party.gain_item(@item.id, @number_window.number)
        when RPG::Weapon then $game_party.gain_weapon(@item.id, @number_window.number)
        when RPG::Armor then $game_party.gain_armor(@item.id, @number_window.number)
        end
        [@gold_window, @buy_window, @status_window].each {|win| win.refresh}
        @buy_window.active = @buy_window.visible = true
      when 1
        $game_party.gain_gold(@number_window.number * (@item.price / 2))
        case @item
        when RPG::Item then $game_party.lose_item(@item.id, @number_window.number)
        when RPG::Weapon then $game_party.lose_weapon(@item.id, @number_window.number)
        when RPG::Armor then $game_party.lose_armor(@item.id, @number_window.number)
        end
        [@gold_window, @sell_window, @status_window].each {|win| win.refresh}
        @sell_window.active = @sell_window.visible = true
        @status_window.visible = false
      end
    end
  end
 
end
Title: Re: [Request] Chaos Project-like shop screen
Post by: nerissya on March 02, 2008, 12:48:02 pm
Quote from: Blizzard on March 02, 2008, 12:45:27 pm
Actually it IS public. xD It's just not one of my usual scripts. I released it long time ago as part of my Blizzard Script Collection v1.0. Here you go:
#==============================================================================
# Shop layout from Chaos Project (Final Demo Version) by Blizzard
# Version: 2.0
#==============================================================================

#==============================================================================
# Window_ShopBuy
#==============================================================================

class Window_ShopBuy < Window_Selectable

  def initialize(shop_goods)
    super(320, 80, 308, 384)
    @shop_goods = shop_goods
    refresh
    self.index = 0
  end

  def item
    return @data[self.index]
  end

  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    @shop_goods.each {|goods_item|
        item = case goods_item[0]
        when 0 then $data_items[goods_item[1]]
        when 1 then $data_weapons[goods_item[1]]
        when 2 then $data_armors[goods_item[1]]
        end
        @data.push(item) if item != nil}
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      if $fontface != nil
        self.contents.font.name = $fontface
        self.contents.font.size = $fontsize
      elsif $defaultfonttype != nil
        self.contents.font.name = $defaultfonttype
        self.contents.font.size = $defaultfontsize
      end
      (0...@item_max).each {|i| draw_item(i)}
    end
  end

  def draw_item(index)
    item = @data[index]
    number = case item
    when RPG::Item then $game_party.item_number(item.id)
    when RPG::Weapon then $game_party.weapon_number(item.id)
    when RPG::Armor then $game_party.armor_number(item.id)
    end
    x = 4
    y = index * 32
    if item.price <= $game_party.gold && number < 99
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    rect = Rect.new(x, y, self.width - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(item.icon_name)
    opacity = self.contents.font.color == normal_color ? 255 : 128
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    if item.price <= $game_party.gold && number < 99
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
    self.contents.draw_text(x + 176, y, 88, 32, item.price.to_s, 2)
  end
 
  def update_help
    @help_window.set_text(self.item == nil ? "" : self.item.description)
  end
 
end

#==============================================================================
# Window_ShopSell
#==============================================================================

class Window_ShopSell < Window_Selectable

  def initialize
    super(16, 80, 608, 320)
    @column_max = 2
    self.z = 4000
    refresh
    self.index = 0
  end

  def item
    return @data[self.index]
  end

  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    (1...$data_items.size).each {|i|
        @data.push($data_items[i]) if $game_party.item_number(i) > 0}
    (1...$data_weapons.size).each {|i|
        @data.push($data_weapons[i]) if $game_party.weapon_number(i) > 0}
    (1...$data_armors.size).each {|i|
        @data.push($data_armors[i]) if $game_party.armor_number(i) > 0}
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      if $fontface != nil
        self.contents.font.name = $fontface
        self.contents.font.size = $fontsize
      elsif $defaultfonttype != nil
        self.contents.font.name = $defaultfonttype
        self.contents.font.size = $defaultfontsize
      end
      (0...@item_max).each {|i| draw_item(i)}
    end
  end

  def draw_item(index)
    item = @data[index]
    number = case item
    when RPG::Item then $game_party.item_number(item.id)
    when RPG::Weapon then $game_party.weapon_number(item.id)
    when RPG::Armor then $game_party.armor_number(item.id)
    end
    x = 4 + index % 2 * 304
    y = index / 2 * 32
    if item.price > 0
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    rect = Rect.new(x, y, self.width / @column_max - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(item.icon_name)
    opacity = self.contents.font.color == normal_color ? 255 : 128
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    if item.price > 0
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
    self.contents.draw_text(x + 224, y, 16, 32, ":", 1)
    self.contents.draw_text(x + 240, y, 24, 32, number.to_s, 2)
  end

  def update_help
    @help_window.set_text(self.item == nil ? "" : self.item.description)
  end
 
end

#==============================================================================
# Window_ShopNumber
#==============================================================================

class Window_ShopNumber < Window_Base

  def initialize
    super(320, 80, 308, 384)
    self.contents = Bitmap.new(width - 32, height - 32)
    if $fontface != nil
      self.contents.font.name = $fontface
      self.contents.font.size = $fontsize
    elsif $defaultfonttype != nil
      self.contents.font.name = $defaultfonttype
      self.contents.font.size = $defaultfontsize
    end
    @item = nil
    @max = 1
    @price = 0
    @number = 1
    self.z = 5000
  end

  def set(item, max, price)
    @item = item
    @max = max
    @price = price
    @number = 1
    refresh
  end

  def number
    return @number
  end

  def refresh
    self.contents.clear
    self.contents.font.color = system_color
    self.contents.draw_text(4, 0, 276, 32, "How many?")
    draw_item_name(@item, 4, 96)
    self.contents.font.color = normal_color
    self.contents.draw_text(208, 96, 32, 32, "×")
    self.contents.draw_text(244, 96, 24, 32, @number.to_s, 2)
    self.cursor_rect.set(240, 96, 32, 32)
    domination = $data_system.words.gold
    cx = contents.text_size(domination).width
    total_price = @price * @number
    self.contents.font.color = normal_color
    self.contents.draw_text(4, 128, 308-cx, 32, total_price.to_s, 2)
    self.contents.font.color = system_color
    self.contents.draw_text(268-cx, 160, cx, 32, domination, 2)
  end

  def update
    super
    if self.active
      if Input.repeat?(Input::RIGHT) && @number < @max
        $game_system.se_play($data_system.cursor_se)
        @number += 1
        refresh
      elsif Input.repeat?(Input::LEFT) && @number > 1
        $game_system.se_play($data_system.cursor_se)
        @number -= 1
        refresh
      elsif Input.repeat?(Input::UP) && @number < @max
        $game_system.se_play($data_system.cursor_se)
        @number = [@number + 10, @max].min
        refresh
      elsif Input.repeat?(Input::DOWN) && @number > 1
        $game_system.se_play($data_system.cursor_se)
        @number = [@number - 10, 1].max
        refresh
      end
    end
  end
 
end

#==============================================================================
# Window_ShopStatus
#==============================================================================

class Window_ShopStatus < Window_Base

  def initialize
    super(16, 80, 304, 320)
    self.contents = Bitmap.new(width - 32, height - 32)
    if $fontface != nil
      self.contents.font.name = $fontface
      self.contents.font.size = $fontsize
    elsif $defaultfonttype != nil
      self.contents.font.name = $defaultfonttype
      self.contents.font.size = $defaultfontsize
    end
    @item = nil
    self.z = 4000
    refresh
  end

  def refresh
    self.contents.clear
    return if @item == nil
    number = case @item
    when RPG::Item then $game_party.item_number(@item.id)
    when RPG::Weapon then $game_party.weapon_number(@item.id)
    when RPG::Armor then $game_party.armor_number(@item.id)
    end
    self.contents.font.color = system_color
    self.contents.draw_text(44, 0, 200, 32, "possesed")
    self.contents.font.color = normal_color
    self.contents.draw_text(4, 0, 32, 32, number.to_s, 2)
    return if @item.is_a?(RPG::Item)
    (0...$game_party.actors.size).each {|i|
        actor = $game_party.actors[i]
        if actor.equippable?(@item)
          self.contents.font.color = normal_color
        else
          self.contents.font.color = disabled_color
        end
        self.contents.draw_text(4, 32 + 64 * i, 120, 32, actor.name)
        if @item.is_a?(RPG::Weapon)
          item1 = $data_weapons[actor.weapon_id]
        elsif @item.kind == 0
          item1 = $data_armors[actor.armor1_id]
        elsif @item.kind == 1
          item1 = $data_armors[actor.armor2_id]
        elsif @item.kind == 2
          item1 = $data_armors[actor.armor3_id]
        else
          item1 = $data_armors[actor.armor4_id]
        end
        if actor.equippable?(@item)
          if @item.is_a?(RPG::Weapon)
            atk1 = item1 != nil ? item1.atk : 0
            atk2 = @item != nil ? @item.atk : 0
            change1 = atk2 - atk1
          end
          if @item.is_a?(RPG::Armor)
            pdef1 = item1 != nil ? item1.pdef : 0
            mdef1 = item1 != nil ? item1.mdef : 0
            pdef2 = @item != nil ? @item.pdef : 0
            mdef2 = @item != nil ? @item.mdef : 0
            change1 = pdef2 - pdef1
            change2 = mdef2 - mdef1
          end
          if change2 != nil
            if actor.equippable?(@item)
              self.contents.font.color = normal_color
            else
              self.contents.font.color = disabled_color
            end
            self.contents.draw_text(156, 32 + 64 * i, 56, 32,
              sprintf("%+d", change1), 2)
            if actor.equippable?(@item)
              self.contents.font.color = normal_color
            else
              self.contents.font.color = disabled_color
            end
            self.contents.draw_text(212, 32 + 64 * i, 56, 32,
              sprintf("%+d", change2), 2)
          elsif change1 != nil
            if actor.equippable?(@item)
              self.contents.font.color = normal_color
            else
              self.contents.font.color = disabled_color
            end
            self.contents.draw_text(156, 32 + 64 * i, 112, 32,
              sprintf("%+d", change1), 2)
          end
        end
        if item1 != nil
          x = 4
          y = 64 + 64 * i
          bitmap = RPG::Cache.icon(item1.icon_name)
          opacity = self.contents.font.color == normal_color ? 255 : 128
          self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
          if actor.equippable?(@item)
            self.contents.font.color = normal_color
          else
            self.contents.font.color = disabled_color
          end
          self.contents.draw_text(x + 28, y, 212, 32, item1.name)
        end}
    if change2 != nil
      self.contents.font.color = normal_color
      self.contents.draw_text(156, 0, 56, 32, "PDef", 2)
      self.contents.draw_text(212, 0, 56, 32, "MDef", 2)
    elsif change1 != nil
      self.contents.font.color = normal_color
      self.contents.draw_text(212, 0, 56, 32, "Atk", 2)
    end
  end

  def item=(item)
    if @item != item
      @item = item
      refresh
    end
  end
 
end

#==============================================================================
# Scene_Shop
#==============================================================================

class Scene_Shop

  def main
    c = ["Buy", "Sell", "Cancel"]
    @help_window = Window_Help.new
    @command_window = Window_Command.new(192, c)
    @command_window.x = 16
    @command_window.y = 80
    @gold_window = Window_Gold.new
    @gold_window.x = 16
    @gold_window.y = 400
    @buy_window = Window_ShopBuy.new($game_temp.shop_goods)
    @buy_window.help_window = @help_window
    @sell_window = Window_ShopSell.new
    @sell_window.help_window = @help_window
    @number_window = Window_ShopNumber.new
    @status_window = Window_ShopStatus.new
    @buy_window.active = @buy_window.visible = @sell_window.active =
    @sell_window.visible = @number_window.active = @number_window.visible =
    @status_window.visible = false
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      break if $scene != self
    end
    Graphics.freeze
    [@help_window, @command_window, @gold_window, @buy_window, @sell_window,
        @number_window, @status_window].each {|win| win.dispose}
  end

  def update
    [@help_window, @command_window, @gold_window, @buy_window, @sell_window,
        @number_window, @status_window].each {|win| win.update}
    if @command_window.active
      update_command
    elsif @buy_window.active
      update_buy
    elsif @sell_window.active
      update_sell
    elsif @number_window.active
      update_number
    end
  end

  def update_command
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Map.new
    elsif Input.trigger?(Input::C)
      case @command_window.index
      when 0
        $game_system.se_play($data_system.decision_se)
        @command_window.active = false
        @buy_window.refresh
        @buy_window.active = @buy_window.visible = @status_window.visible = true
      when 1
        $game_system.se_play($data_system.decision_se)
        @command_window.active = false
        @sell_window.active = @sell_window.visible = true
        @sell_window.refresh
      when 2
        $game_system.se_play($data_system.decision_se)
        $scene = Scene_Map.new
      end
    end
  end

  def update_buy
    @status_window.item = @buy_window.item
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @command_window.active = true
      @buy_window.active = @buy_window.visible = @status_window.visible = false
      @status_window.item = nil
      @help_window.set_text("")
    elsif Input.trigger?(Input::C)
      @item = @buy_window.item
      if @item == nil or @item.price > $game_party.gold
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      number = case @item
      when RPG::Item then $game_party.item_number(@item.id)
      when RPG::Weapon then $game_party.weapon_number(@item.id)
      when RPG::Armor then $game_party.armor_number(@item.id)
      end
      if number == 99
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      $game_system.se_play($data_system.decision_se)
      max = @item.price == 0 ? 99 : $game_party.gold / @item.price
      max = [max, 99 - number].min
      @buy_window.active = @buy_window.visible = false
      @number_window.set(@item, max, @item.price)
      @number_window.active = @number_window.visible = true
    end
  end

  def update_sell
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @command_window.active = true
      @sell_window.active = @sell_window.visible = false
      @status_window.item = nil
      @help_window.set_text("")
    elsif Input.trigger?(Input::C)
      @item = @sell_window.item
      @status_window.item = @item
      if @item == nil or @item.price == 0
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      $game_system.se_play($data_system.decision_se)
      number = case @item
      when RPG::Item then $game_party.item_number(@item.id)
      when RPG::Weapon then $game_party.weapon_number(@item.id)
      when RPG::Armor then $game_party.armor_number(@item.id)
      end
      max = number
      @sell_window.active = @sell_window.visible = false
      @number_window.set(@item, max, @item.price / 2)
      @number_window.active = @number_window.visible = @status_window.visible = true
    end
  end

  def update_number
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @number_window.active = @number_window.visible = false
      case @command_window.index
      when 0
        @buy_window.active = @buy_window.visible = true
      when 1
        @sell_window.active = @sell_window.visible = true
        @status_window.visible = false
      end
    elsif Input.trigger?(Input::C)
      $game_system.se_play($data_system.shop_se)
      @number_window.active = @number_window.visible = false
      case @command_window.index
      when 0
        $game_party.lose_gold(@number_window.number * @item.price)
        case @item
        when RPG::Item then $game_party.gain_item(@item.id, @number_window.number)
        when RPG::Weapon then $game_party.gain_weapon(@item.id, @number_window.number)
        when RPG::Armor then $game_party.gain_armor(@item.id, @number_window.number)
        end
        [@gold_window, @buy_window, @status_window].each {|win| win.refresh}
        @buy_window.active = @buy_window.visible = true
      when 1
        $game_party.gain_gold(@number_window.number * (@item.price / 2))
        case @item
        when RPG::Item then $game_party.lose_item(@item.id, @number_window.number)
        when RPG::Weapon then $game_party.lose_weapon(@item.id, @number_window.number)
        when RPG::Armor then $game_party.lose_armor(@item.id, @number_window.number)
        end
        [@gold_window, @sell_window, @status_window].each {|win| win.refresh}
        @sell_window.active = @sell_window.visible = true
        @status_window.visible = false
      end
    end
  end
 
end



Blizzard is just amazing. =)
Title: Re: [Request] Chaos Project-like shop screen
Post by: darklight on March 02, 2008, 12:48:43 pm
Woo! Awesome! Thanks, Blizz. I just started playing CP a few days ago and I loved the shop system.  ;D

ETA: Looks like I spoke too soon. I ran into trouble when I put it in my game project. I get the following error:

Spoiler: ShowHide
(http://i26.tinypic.com/257eq7d.jpg)


I tried shuffling around the order of the scripts but it doesn't work. It crashes when I select the 'Buy' option. I can select 'Sell' but as soon as I try and sell something, it crashes with the same error. It also won't display my game font just for the items listed, but the buy/sell/leave option as well as the item descriptions are fine.
Title: Re: [Bug] Chaos Project shop screen
Post by: Blizzard on March 02, 2008, 03:05:51 pm
Oops! I optimized the script and missed something. I updated the script in the post before, try now.
Title: Re: [Bug] Chaos Project shop screen
Post by: Nortos on March 02, 2008, 04:58:13 pm
Quote from: Blizzard on March 02, 2008, 12:45:27 pm
Blizzard Script Collection v1.0.


Where can I find that Blizz?
Title: Re: [Bug] Chaos Project shop screen
Post by: Sally on March 02, 2008, 06:00:36 pm
how is this a [bug]?
Title: Re: [Bug] Chaos Project shop screen
Post by: Blizzard on March 03, 2008, 02:41:03 am
I think I fixed the bug, try the script again.

@Nortos: It's very old, I think I released my scripts all separately already. Maybe you can find it on rmrk if the post wasn't lost.
Title: Re: [Bug] Chaos Project shop screen
Post by: Nortos on March 03, 2008, 04:56:25 pm
I'll have a look ty
Title: Re: [Bug] Chaos Project shop screen
Post by: Fantasist on March 04, 2008, 06:38:21 am
QuoteBlizzard Script Collection v1.0.

QuoteIt's very old, I think I released my scripts all separately already. Maybe you can find it on rmrk if the post wasn't lost.

I know where you released your scripts, in your scripting tute :)
Title: Re: [Bug] Chaos Project shop screen
Post by: Blizzard on March 04, 2008, 08:51:53 am
Yeah, but the script collection were all scripts in one project. ;)
Title: Re: [Bug] Chaos Project shop screen
Post by: Fantasist on March 04, 2008, 01:34:34 pm
Big difference. You know, many, ahem, 'Testbeds' brag about 'collection of scripts which work together', but your scripts always work together. But you know what? The next time you update the tute package, could you include the script order also? It would be nice :)
Title: Re: [Bug] Chaos Project shop screen
Post by: Blizzard on March 05, 2008, 03:09:27 am
Yeah, but Zeriab would first have to send me that review. xD