Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[Resolved] Little Help - Image Sorting

Status
Not open for further replies.

Mac

Member

I'm having a few troubles with my images for my shop buy menu, the image appears up the call of the shop, but i onlt want it to appear when i select the buy option. Does anybody know how to sort this little problem.

Code:
#==============================================================================
# ** Window_Tactics_ShopBuy
#------------------------------------------------------------------------------
#  This window displays buyable goods on the shop screen.
#==============================================================================

class Window_Tactics_ShopBuy < Window_Selectable
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     shop_goods : goods
  #--------------------------------------------------------------------------
  def initialize(shop_goods)
    super(20, 20, 600, 228)
    self.contents = Bitmap.new(width - 32, row_max * 32)
    @SHOPBACK_graphic = Sprite.new
    @SHOPBACK_graphic.x = self.x + 1
    @SHOPBACK_graphic.y = self.y + 1
    @SHOPBACK_graphic.z = self.z + 1
    self.opacity = 0
    @shop_goods = shop_goods
    refresh
    self.index = 0
  end
  #--------------------------------------------------------------------------
  # * Item Acquisition
  #--------------------------------------------------------------------------
  def item
    return @data[self.index]
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    for goods_item in @shop_goods
      case goods_item[0]
      when 0
        item = $data_items[goods_item[1]]
      when 1
        item = $data_weapons[goods_item[1]]
      when 2
        item = $data_armors[goods_item[1]]
      end
      if item != nil
        @data.push(item)
      end
    end
    # If item count is not 0, make a bit map and draw all items
    @item_max = @data.size
    if @item_max > 0
    self.contents = Bitmap.new(width - 32, row_max * 32)
    for i in 0...@item_max
      draw_item(i)
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #--------------------------------------------------------------------------
def draw_item(index)
    item = @data[index]
    # Get items in possession
    case item
    when RPG::Item
      number = $game_party.item_number(item.id)
      equipped_number = 0
    when RPG::Weapon
      number = $game_party.weapon_number(item.id)
      equipped_number = $game_party.equipped_weapon_number(item.id)
    when RPG::Armor
      number = $game_party.armor_number(item.id)
      equipped_number = $game_party.equipped_armor_number(item.id)
    end
    # If price is less than money in possession, and amount in possession is
    # not 99, then set to normal text color. Otherwise set to disabled color
    if item.price <= $game_party.gold and number < 99
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    x = 4
    y = index * 32
    rect = Rect.new(x, y, self.width - 32, 32)
    bitmap = RPG::Cache.icon(item.icon_name)
    opacity = self.contents.font.color == normal_color ? 255 : 128
    @SHOPBACK_graphic.bitmap = RPG::Cache.picture('Shop Window')
    @SHOPBACK_graphic.visible = true
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
    self.contents.draw_text(x + 370, y, 88, 32, (number + equipped_number).to_s, 2)
    self.contents.draw_text(x + 290, y, 88, 32, equipped_number.to_s, 2)
    self.contents.draw_text(x + 460, y, 88, 32, item.price.to_s, 2)
  end
  def dispose
        @SHOPBACK_graphic.dispose
        end
  #--------------------------------------------------------------------------
  # * Help Text Update
  #--------------------------------------------------------------------------
  def update_help
    @help_window.set_text(self.item == nil ? "" : self.item.description)
  end
end
 
There's a few things I think you can do easier here.

1)
Code:
module FFT_ShopSystem
  class Window_ShopBy < ::Window_ShopBuy

  end
end

As I have told you before, you can basically make this a sub-class of the default Window_ShopBuy. All the methods can basically be omiited except for the changes you make. I will make these for you. Feel free to change them.

Code:
module FFT_ShopSystem
  class Window_ShopBy < ::Window_ShopBuy
    def initialize(shop_goods)
      super(shop_goods)
      self.x = 20
      self.y = 20
      self.width = 600
      self.height = 228
      self.opacity = 0
      @showback_graphic = Sprite.new
      @showback_graphic.bitmap = RPG::Cache.picture('Shop Window')
      @showback_graphic.x = self.x + 1
      @showback_graphic.y = self.y + 1
      @showback_graphic.z = self.z - 1
      @showback_graphic.visible = self.visible
  end
  def draw_item(index)
    item = @data[index]
    # Get items in possession
    case item
    when RPG::Item
      number = $game_party.item_number(item.id)
      equipped_number = 0
    when RPG::Weapon
      number = $game_party.weapon_number(item.id)
      equipped_number = $game_party.equipped_weapon_number(item.id)
    when RPG::Armor
      number = $game_party.armor_number(item.id)
      equipped_number = $game_party.equipped_armor_number(item.id)
    end
    # If price is less than money in possession, and amount in possession is
    # not 99, then set to normal text color. Otherwise set to disabled color
    if item.price <= $game_party.gold and number < 99
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    x = 4
    y = index * 32
    rect = Rect.new(x, y, self.width - 32, 32)
    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)
    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
    self.contents.draw_text(x + 370, y, 88, 32, (number + equipped_number).to_s, 2)
    self.contents.draw_text(x + 290, y, 88, 32, equipped_number.to_s, 2)
    self.contents.draw_text(x + 460, y, 88, 32, item.price.to_s, 2)
  end
  def update
    super
    @showback_graphic.visible = self.visible
  end
  def dispose
    super
    @showback_graphic.dispose
  end
end

I made a few adjustments to your code. By making the default Window_ShopBuy class a parent class, you can remove the refresh and update_help methods, and simply super call the initialize, update and dispose reducing codes lines and improving efficency. :yes:

I believe what you were trying to do is make your @showback_graphic bitmap visible when your window is visible. To fix this, you can just use the method I created here:
Code:
  def update
    super
    @showback_graphic.visible = self.visible
  end

Everyframe the udpate method is called. It will use the super call and envoke the update method in the parent class. Then, it fixes the sprites visibleness depending on the windows visibleness.


I think that everything from me. Let me know if you have any questions.
 

Mac

Member

I'm still not sure how to do all this, now when i call on it, it doesn't work...so :|

I've never been good at using modules and tidying up.

Do you mind looking at it?
Code:
#==============================================================================
# ** Macs Final Fantasy Tactics Advance Shop
#------------------------------------------------------------------------------
#  V 0.8
#==============================================================================
module FFT_ShopSystem
class Scene_Tactics_Shop
  def main
    $game_temp.map_bgm = $game_system.playing_bgm
    Audio.bgm_play("Audio/BGM/31 - Mysterious Shop", 100, 100)
    @command_window = Window_Tactics_ShopCommand.new
    @spriteset = Spriteset_Map.new
    @gold_window = Window_Gold.new
    @gold_window.x = 480
    @gold_window.y = 416
    @buy_window = Window_Tactics_ShopBuy.new($game_temp.shop_goods)
    @buy_window.active = false
    @buy_window.visible = false
    @buy_window.help_window = @help_window
    @sell_window = Window_Tactics_ShopSell.new
    @sell_window.active = false
    @sell_window.visible = false
    @sell_window.help_window = @help_window
    @number_window = Window_Tactics_ShopNumber.new
    @number_window.active = false
    @number_window.visible = false
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @spriteset.dispose
    @command_window.dispose
    @gold_window.dispose
    @buy_window.dispose
    @sell_window.dispose
    @number_window.dispose
  end
  def update
    @spriteset.update
    @command_window.update
    @gold_window.update
    @buy_window.update
    @sell_window.update
    @number_window.update
    if @command_window.active
      update_command
      return
    end
    if @buy_window.active
      update_buy
      return
    end
    if @sell_window.active
      update_sell
      return
    end
    if @number_window.active
      update_number
      return
    end
  end
  def update_command
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Map.new
      return
    end
    if Input.trigger?(Input::C)
      case @command_window.index
      when 0 
        $game_system.se_play($data_system.decision_se)
        @command_window.visible = false
        @command_window.active = false
        @buy_window.active = true
        @buy_window.visible = true
        @buy_window.refresh
      when 1  
        $game_system.se_play($data_system.decision_se)
        @command_window.visible = false
        @command_window.active = false
        @sell_window.active = true
        @sell_window.visible = true
        @sell_window.refresh
      when 2
        $game_system.se_play($data_system.decision_se)
        $scene = Scene_Map.new
      end
      return
    end
  end
  def update_buy
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @command_window.visible = true
      @command_window.active = true
      @buy_window.active = false
      @buy_window.visible = false
      return
    end
    if 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
      case @item
      when RPG::Item
        number = $game_party.item_number(@item.id)
      when RPG::Weapon
        number = $game_party.weapon_number(@item.id)
      when RPG::Armor
        number = $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 = false
      @buy_window.visible = true
      @number_window.set(@item, max, @item.price)
      @number_window.active = true
      @number_window.visible = true
    end
  end
  def update_sell
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @command_window.visible = true
      @command_window.active = true
      @sell_window.active = false
      @sell_window.visible = false
      return
    end
    if Input.trigger?(Input::C)
      @item = @sell_window.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)
      case @item
      when RPG::Item
        number = $game_party.item_number(@item.id)
      when RPG::Weapon
        number = $game_party.weapon_number(@item.id)
      when RPG::Armor
        number = $game_party.armor_number(@item.id)
      end
      @sell_window.active = false
      @sell_window.visible = true
      @number_window.set(@item, max, @item.price / 2)
      @number_window.active = true
      @number_window.visible = true
    end
  end
  def update_number
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @number_window.active = false
      @number_window.visible = false
      case @command_window.index
      when 0  
        @buy_window.active = true
        @buy_window.visible = true
      when 1 
        @sell_window.active = true
        @sell_window.visible = true
      end
      return
    end
    if Input.trigger?(Input::C)
      $game_system.se_play($data_system.shop_se)
      @number_window.active = false
      @number_window.visible = false
      case @command_window.index
      when 0 
        $game_party.lose_gold(@number_window.number * @item.price)
        case @item
        when RPG::Item
          $game_party.gain_item(@item.id, @number_window.number)
        when RPG::Weapon
          $game_party.gain_weapon(@item.id, @number_window.number)
        when RPG::Armor
          $game_party.gain_armor(@item.id, @number_window.number)
        end
        @gold_window.refresh
        @buy_window.refresh
        @buy_window.active = true
        @buy_window.visible = true
      when 1  
        $game_party.gain_gold(@number_window.number * (@item.price / 2))
        case @item
        when RPG::Item
          $game_party.lose_item(@item.id, @number_window.number)
        when RPG::Weapon
          $game_party.lose_weapon(@item.id, @number_window.number)
        when RPG::Armor
          $game_party.lose_armor(@item.id, @number_window.number)
        end
        @gold_window.refresh
        @sell_window.refresh
        @sell_window.active = true
        @sell_window.visible = true
      end
      return
    end
  end
end
#-----------------------------------SHOP BUY----------------------------------
  class Window_Tactics_ShopBuy < ::Window_ShopBuy
    def initialize(shop_goods)
      super(shop_goods)
      self.x = 20
      self.y = 20
      self.width = 600
      self.height = 228
      self.opacity = 0
      @showback_graphic = Sprite.new
      @showback_graphic.bitmap = RPG::Cache.picture('Shop Window')
      @showback_graphic.x = self.x + 1
      @showback_graphic.y = self.y + 1
      @showback_graphic.z = self.z - 1
      @showback_graphic.visible = self.visible
  end
  def draw_item(index)
    item = @data[index]
    case item
    when RPG::Item
      number = $game_party.item_number(item.id)
      equipped_number = 0
    when RPG::Weapon
      number = $game_party.weapon_number(item.id)
      equipped_number = $game_party.equipped_weapon_number(item.id)
    when RPG::Armor
      number = $game_party.armor_number(item.id)
      equipped_number = $game_party.equipped_armor_number(item.id)
    end
    if item.price <= $game_party.gold and number < 99
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    x = 4
    y = index * 32
    rect = Rect.new(x, y, self.width - 32, 32)
    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)
    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
    self.contents.draw_text(x + 370, y, 88, 32, (number + equipped_number).to_s, 2)
    self.contents.draw_text(x + 290, y, 88, 32, equipped_number.to_s, 2)
    self.contents.draw_text(x + 460, y, 88, 32, item.price.to_s, 2)
  end
  def update
    super
    @showback_graphic.visible = self.visible
  end
  def dispose
    super
    @showback_graphic.dispose
  end
end
  def update_help
    @help_window.set_text(self.item == nil ? "" : self.item.description)
  end
end
#---------------------------SHOP SELL------------------------------------------
class Window_Tactics_ShopSell < :: Window_ShopSell
  def initialize
      self.x = 20
      self.y = 20
      self.width = 600
      self.height = 228
      self.opacity = 0
      @showback_graphic = Sprite.new
      @showback_graphic.bitmap = RPG::Cache.picture('Shop Window')
      @showback_graphic.x = self.x + 1
      @showback_graphic.y = self.y + 1
      @showback_graphic.z = self.z - 1
      @showback_graphic.visible = self.visible
    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 = []
    for i in 1...$data_items.size
      if $game_party.item_number(i) > 0
        @data.push($data_items[i])
      end
    end
    for i in 1...$data_weapons.size
      if $game_party.weapon_number(i) > 0
        @data.push($data_weapons[i])
      end
    end
    for i in 1...$data_armors.size
      if $game_party.armor_number(i) > 0
        @data.push($data_armors[i])
      end
    end
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  def draw_item(index)
    item = @data[index]
    case item
    when RPG::Item
      number = $game_party.item_number(item.id)
      equipped_number = 0
    when RPG::Weapon
      number = $game_party.weapon_number(item.id)
      equipped_number = $game_party.equipped_weapon_number(item.id)
    when RPG::Armor
      number = $game_party.armor_number(item.id)
      equipped_number = $game_party.equipped_armor_number(item.id)
    end
    if item.price > 0
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    x = 4 + index % 1 * (288 + 32)
    y = index / 1 * 32
    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)
    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
    self.contents.draw_text(x + 370, y, 88, 32, (number + equipped_number).to_s, 2)
    self.contents.draw_text(x + 290, y, 88, 32, equipped_number.to_s, 2)
    self.contents.draw_text(x + 460, y, 88, 32, (item.price / 2).to_s, 2)
  end
  def update_help
    @help_window.set_text(self.item == nil ? "" : self.item.description)
  end
end
#-------------------------SHOP NUMBER---------------------------------------
class Window_Tactics_ShopNumber < :: Window_ShopNumber
  def initialize
      self.x = 420
      self.y = 255
      self.width = 90
      self.height = 50
      self.opacity = 0
    self.contents = Bitmap.new(width - 32, height - 32)
    @item = nil
    @max = 1
    @price = 0
    @number = 1
  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 = normal_color
    self.contents.draw_text(3, -6, 32, 32, "×")
    self.contents.draw_text(20, -6, 24, 32, @number.to_s, 2)
    self.cursor_rect.set(20, -6, 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, 160, 328-cx-2, 32, total_price.to_s, 2)
    self.contents.font.color = system_color
    self.contents.draw_text(332-cx, 160, cx, 32, domination, 2)
  end
  def update
    super
    if self.active
      if Input.repeat?(Input::RIGHT) and @number < @max
        $game_system.se_play($data_system.cursor_se)
        @number += 1
        refresh
      end
      if Input.repeat?(Input::LEFT) and @number > 1
        $game_system.se_play($data_system.cursor_se)
        @number -= 1
        refresh
      end
      if Input.repeat?(Input::UP) and @number < @max
        $game_system.se_play($data_system.cursor_se)
        @number = [@number + 10, @max].min
        refresh
      end
      if Input.repeat?(Input::DOWN) and @number > 1
        $game_system.se_play($data_system.cursor_se)
        @number = [@number - 10, 1].max
        refresh
      end
    end
  end
end
 
Try this.
Code:
module FFT_ShopSystem

class Scene_Shop
  def main
    $game_temp.map_bgm = $game_system.playing_bgm
    Audio.bgm_play("Audio/BGM/31 - Mysterious Shop", 100, 100)
    @command_window = FFT_ShopSystem::Window_ShopCommand.new
    @spriteset = Spriteset_Map.new
    @gold_window = Window_Gold.new
    @gold_window.x = 480
    @gold_window.y = 416
    @buy_window = FFT_ShopSystem::Window_ShopBuy.new($game_temp.shop_goods)
    @buy_window.active = false
    @buy_window.visible = false
    @buy_window.help_window = @help_window
    @sell_window = FFT_ShopSystem::Window_ShopSell.new
    @sell_window.active = false
    @sell_window.visible = false
    @sell_window.help_window = @help_window
    @number_window = FFT_ShopSystem::Window_ShopNumber.new
    @number_window.active = false
    @number_window.visible = false
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @spriteset.dispose
    @command_window.dispose
    @gold_window.dispose
    @buy_window.dispose
    @sell_window.dispose
    @number_window.dispose
  end
  def update
    @spriteset.update
    @command_window.update
    @gold_window.update
    @buy_window.update
    @sell_window.update
    @number_window.update
    if @command_window.active
      update_command
      return
    end
    if @buy_window.active
      update_buy
      return
    end
    if @sell_window.active
      update_sell
      return
    end
    if @number_window.active
      update_number
      return
    end
  end
  def update_command
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Map.new
      return
    end
    if Input.trigger?(Input::C)
      case @command_window.index
      when 0 
        $game_system.se_play($data_system.decision_se)
        @command_window.visible = false
        @command_window.active = false
        @buy_window.active = true
        @buy_window.visible = true
        @buy_window.refresh
      when 1  
        $game_system.se_play($data_system.decision_se)
        @command_window.visible = false
        @command_window.active = false
        @sell_window.active = true
        @sell_window.visible = true
        @sell_window.refresh
      when 2
        $game_system.se_play($data_system.decision_se)
        $scene = Scene_Map.new
      end
      return
    end
  end
  def update_buy
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @command_window.visible = true
      @command_window.active = true
      @buy_window.active = false
      @buy_window.visible = false
      return
    end
    if 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
      case @item
      when RPG::Item
        number = $game_party.item_number(@item.id)
      when RPG::Weapon
        number = $game_party.weapon_number(@item.id)
      when RPG::Armor
        number = $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 = false
      @buy_window.visible = true
      @number_window.set(@item, max, @item.price)
      @number_window.active = true
      @number_window.visible = true
    end
  end
  def update_sell
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @command_window.visible = true
      @command_window.active = true
      @sell_window.active = false
      @sell_window.visible = false
      return
    end
    if Input.trigger?(Input::C)
      @item = @sell_window.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)
      case @item
      when RPG::Item
        number = $game_party.item_number(@item.id)
      when RPG::Weapon
        number = $game_party.weapon_number(@item.id)
      when RPG::Armor
        number = $game_party.armor_number(@item.id)
      end
      @sell_window.active = false
      @sell_window.visible = true
      @number_window.set(@item, max, @item.price / 2)
      @number_window.active = true
      @number_window.visible = true
    end
  end
  def update_number
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @number_window.active = false
      @number_window.visible = false
      case @command_window.index
      when 0  
        @buy_window.active = true
        @buy_window.visible = true
      when 1 
        @sell_window.active = true
        @sell_window.visible = true
      end
      return
    end
    if Input.trigger?(Input::C)
      $game_system.se_play($data_system.shop_se)
      @number_window.active = false
      @number_window.visible = false
      case @command_window.index
      when 0 
        $game_party.lose_gold(@number_window.number * @item.price)
        case @item
        when RPG::Item
          $game_party.gain_item(@item.id, @number_window.number)
        when RPG::Weapon
          $game_party.gain_weapon(@item.id, @number_window.number)
        when RPG::Armor
          $game_party.gain_armor(@item.id, @number_window.number)
        end
        @gold_window.refresh
        @buy_window.refresh
        @buy_window.active = true
        @buy_window.visible = true
      when 1  
        $game_party.gain_gold(@number_window.number * (@item.price / 2))
        case @item
        when RPG::Item
          $game_party.lose_item(@item.id, @number_window.number)
        when RPG::Weapon
          $game_party.lose_weapon(@item.id, @number_window.number)
        when RPG::Armor
          $game_party.lose_armor(@item.id, @number_window.number)
        end
        @gold_window.refresh
        @sell_window.refresh
        @sell_window.active = true
        @sell_window.visible = true
      end
      return
    end
  end
end
#-----------------------------------SHOP BUY----------------------------------
class Window_ShopBuy < ::Window_ShopBuy
  def initialize(shop_goods)
    super(shop_goods)
    self.x = 20
    self.y = 20
    self.width = 600
    self.height = 228
    self.opacity = 0
    @showback_graphic = Sprite.new
    @showback_graphic.bitmap = RPG::Cache.picture('Shop Window')
    @showback_graphic.x = self.x + 1
    @showback_graphic.y = self.y + 1
    @showback_graphic.z = self.z - 1
    @showback_graphic.visible = self.visible
  end
  def draw_item(index)
    item = @data[index]
    case item
    when RPG::Item
      number = $game_party.item_number(item.id)
      equipped_number = 0
    when RPG::Weapon
      number = $game_party.weapon_number(item.id)
      equipped_number = $game_party.equipped_weapon_number(item.id)
    when RPG::Armor
      number = $game_party.armor_number(item.id)
      equipped_number = $game_party.equipped_armor_number(item.id)
    end
    if item.price <= $game_party.gold and number < 99
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    x = 4
    y = index * 32
    rect = Rect.new(x, y, self.width - 32, 32)
    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)
    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
    self.contents.draw_text(x + 370, y, 88, 32, (number + equipped_number).to_s, 2)
    self.contents.draw_text(x + 290, y, 88, 32, equipped_number.to_s, 2)
    self.contents.draw_text(x + 460, y, 88, 32, item.price.to_s, 2)
  end
  def update
    super
    @showback_graphic.visible = self.visible
  end
  def dispose
    super
    @showback_graphic.dispose
  end
end
#---------------------------SHOP SELL------------------------------------------
class Window_ShopSell < ::Window_ShopSell
  def initialize
    super
    self.x = 20
    self.y = 20
    self.width = 600
    self.height = 228
    self.opacity = 0
    @showback_graphic = Sprite.new
    @showback_graphic.bitmap = RPG::Cache.picture('Shop Window')
    @showback_graphic.x = self.x + 1
    @showback_graphic.y = self.y + 1
    @showback_graphic.z = self.z - 1
    @showback_graphic.visible = self.visible
  end
  def draw_item(index)
    item = @data[index]
    case item
    when RPG::Item
      number = $game_party.item_number(item.id)
      equipped_number = 0
    when RPG::Weapon
      number = $game_party.weapon_number(item.id)
      equipped_number = $game_party.equipped_weapon_number(item.id)
    when RPG::Armor
      number = $game_party.armor_number(item.id)
      equipped_number = $game_party.equipped_armor_number(item.id)
    end
    if item.price > 0
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    x = 4 + index % 1 * (288 + 32)
    y = index / 1 * 32
    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)
    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
    self.contents.draw_text(x + 370, y, 88, 32, (number + equipped_number).to_s, 2)
    self.contents.draw_text(x + 290, y, 88, 32, equipped_number.to_s, 2)
    self.contents.draw_text(x + 460, y, 88, 32, (item.price / 2).to_s, 2)
  end
  def update
    super
    @showback_graphic.visible = self.visible
  end
  def dispose
    super
    @showback_graphic.dispose
  end
end
#-------------------------SHOP NUMBER---------------------------------------
class Window_ShopNumber < ::Window_ShopNumber
  def initialize
    super
    self.x = 420
    self.y = 255
    self.width = 90
    self.height = 50
    self.opacity = 0
  end
end

end


It seems you are still not understanding why we are making these classes child classes of the original classes.

Let's take a look at one of your old initialize method for example:

Code:
class Window_Tactics_ShopBuy < ::Window_Selectable
  def initialize(shop_goods)
    super(20, 20, 600, 228)
    @shop_goods = $game_temp.shop_goods
    refresh
    self.index = 0
    self.opacity = 0
    @showback_graphic = Sprite.new
    @showback_graphic.bitmap = RPG::Cache.picture('Shop Window')
    @showback_graphic.x = self.x + 1
    @showback_graphic.y = self.y + 1
    @showback_graphic.z = self.z - 1
    @showback_graphic.visible = self.visible
  end

The command super envokes the method in the parent class. This is one of the key in OO; inheritance. The child class shares the same methods/instances/etc. the parent class has, so we can omit methods that are exactly the same as the parents class, or use our super call and then change things like we have been doing.

Anyways....

Here, you can use the super call, change our positioning, size and opacity and then create the sprite image.

Code:
class Window_ShopBuy < ::Window_ShopBuy
  def initialize(shop_goods)
    super(shop_goods)
    self.x = 20
    self.y = 20
    self.width = 600
    self.height = 228
    self.opacity = 0
    @showback_graphic = Sprite.new
    @showback_graphic.bitmap = RPG::Cache.picture('Shop Window')
    @showback_graphic.x = self.x + 1
    @showback_graphic.y = self.y + 1
    @showback_graphic.z = self.z - 1
    @showback_graphic.visible = self.visible
  end

Then that super call is made it accesses all the processing in the parents method (which does require we pass the right arguments). We then no longer need to do things such as set the shop goods, create the contents, etc.

Let me know if there are any errors. Just woke up.
 

Mac

Member

Ahhh i'm beginning to understand more now ^_^ Thanks alot.

One questions how do i call upon the system...cause as you mentioned before...it should be something like
Code:
$game_temp.call_fftshopsystem = true

But it keeps coming up with an error.

Something like 'call_fftshopsystem ='
 
You still need to add this for that to work. ^_^

Code:
class Game_Temp
  attr_accessor :call_fftshopsystem
  alias mac_fftshop_gmtmp_init initialize
  def initialize
    mac_fftshop_gmtmp_init
    @call_fftshopsystem = false
  end
end

class Scene_Shop
  alias mac_fftshop_scnshop_main main
  def main
    if $game_temp.call_fftshopsystem
      $scene = FFT_ShopSystem::Scene_Shop.new
      $game_temp.call_fftshopsystem = false
      return
    end
    mac_fftshop_scnshop_main
  end
end

Now it will switch the scene to your shop scene when the $game_temp.call_fftshopsystem is on and turn it to false, so a call script isn't needed after you call the shop.

Code:
Script : $game_temp.call_fftshopsystem = true
Shop Processing : Blah

I think that should work.
 

Mac

Member

Hmmmm but now that i've done that the Command Window is all messed up, i can't seem to find anything that states my command window before, it seems that the code you give me SS, doesn't have a defined Window_Command as the old image i had there isn't included anymore and its opacity is normal now :|

O wait i think i might have learnt something here
 

Mac

Member

I sorted the problem, and i've learnt a bit more stuff ^_^ thanks to you of course...but now theres a few problems.

1. The shop window flashes for one second on calling.
2. The sell window is messed up command width wise compared to the buy window.
3. Causes an error when you have an item to sell

And there may be more, but i haven't seemed to cross others.

Heres the updated script and the two images(in attachments):-

Code:
class Game_Temp
  attr_accessor :call_fftshopsystem
  alias mac_fftshop_gmtmp_init initialize
  def initialize
    mac_fftshop_gmtmp_init
    @call_fftshopsystem = false
  end
end

class Scene_Shop
  alias mac_fftshop_scnshop_main main
  def main
    if $game_temp.call_fftshopsystem
      $scene = FFT_ShopSystem::Scene_Shop.new
      $game_temp.call_fftshopsystem = false
      return
    end
    mac_fftshop_scnshop_main
  end
end

module FFT_ShopSystem

class Scene_Shop
  def main
    $game_temp.map_bgm = $game_system.playing_bgm
    Audio.bgm_play("Audio/BGM/31 - Mysterious Shop", 100, 100)
    @command_window = Window_ShopCommand.new
    @spriteset = Spriteset_Map.new
    @gold_window = Window_Gold.new
    @gold_window.x = 480
    @gold_window.y = 416
    @buy_window = FFT_ShopSystem::Window_ShopBuy.new($game_temp.shop_goods)
    @buy_window.active = false
    @buy_window.visible = false
    @buy_window.help_window = @help_window
    @sell_window = FFT_ShopSystem::Window_ShopSell.new
    @sell_window.active = false
    @sell_window.visible = false
    @sell_window.help_window = @help_window
    @number_window = FFT_ShopSystem::Window_ShopNumber.new
    @number_window.active = false
    @number_window.visible = false
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @spriteset.dispose
    @command_window.dispose
    @gold_window.dispose
    @buy_window.dispose
    @sell_window.dispose
    @number_window.dispose
  end
  def update
    @spriteset.update
    @command_window.update
    @gold_window.update
    @buy_window.update
    @sell_window.update
    @number_window.update
    if @command_window.active
      update_command
      return
    end
    if @buy_window.active
      update_buy
      return
    end
    if @sell_window.active
      update_sell
      return
    end
    if @number_window.active
      update_number
      return
    end
  end
  def update_command
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Map.new
      return
    end
    if Input.trigger?(Input::C)
      case @command_window.index
      when 0 
        $game_system.se_play($data_system.decision_se)
        @command_window.visible = false
        @command_window.active = false
        @buy_window.active = true
        @buy_window.visible = true
        @buy_window.refresh
      when 1  
        $game_system.se_play($data_system.decision_se)
        @command_window.visible = false
        @command_window.active = false
        @sell_window.active = true
        @sell_window.visible = true
        @sell_window.refresh
      when 2
        $game_system.se_play($data_system.decision_se)
        $scene = Scene_Map.new
      end
      return
    end
  end
  def update_buy
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @command_window.visible = true
      @command_window.active = true
      @buy_window.active = false
      @buy_window.visible = false
      return
    end
    if 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
      case @item
      when RPG::Item
        number = $game_party.item_number(@item.id)
      when RPG::Weapon
        number = $game_party.weapon_number(@item.id)
      when RPG::Armor
        number = $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 = false
      @buy_window.visible = true
      @number_window.set(@item, max, @item.price)
      @number_window.active = true
      @number_window.visible = true
    end
  end
  def update_sell
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @command_window.visible = true
      @command_window.active = true
      @sell_window.active = false
      @sell_window.visible = false
      return
    end
    if Input.trigger?(Input::C)
      @item = @sell_window.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)
      case @item
      when RPG::Item
        number = $game_party.item_number(@item.id)
      when RPG::Weapon
        number = $game_party.weapon_number(@item.id)
      when RPG::Armor
        number = $game_party.armor_number(@item.id)
      end
      @sell_window.active = false
      @sell_window.visible = true
      @number_window.set(@item, max, @item.price / 2)
      @number_window.active = true
      @number_window.visible = true
    end
  end
  def update_number
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @number_window.active = false
      @number_window.visible = false
      case @command_window.index
      when 0  
        @buy_window.active = true
        @buy_window.visible = true
      when 1 
        @sell_window.active = true
        @sell_window.visible = true
      end
      return
    end
    if Input.trigger?(Input::C)
      $game_system.se_play($data_system.shop_se)
      @number_window.active = false
      @number_window.visible = false
      case @command_window.index
      when 0 
        $game_party.lose_gold(@number_window.number * @item.price)
        case @item
        when RPG::Item
          $game_party.gain_item(@item.id, @number_window.number)
        when RPG::Weapon
          $game_party.gain_weapon(@item.id, @number_window.number)
        when RPG::Armor
          $game_party.gain_armor(@item.id, @number_window.number)
        end
        @gold_window.refresh
        @buy_window.refresh
        @buy_window.active = true
        @buy_window.visible = true
      when 1  
        $game_party.gain_gold(@number_window.number * (@item.price / 2))
        case @item
        when RPG::Item
          $game_party.lose_item(@item.id, @number_window.number)
        when RPG::Weapon
          $game_party.lose_weapon(@item.id, @number_window.number)
        when RPG::Armor
          $game_party.lose_armor(@item.id, @number_window.number)
        end
        @gold_window.refresh
        @sell_window.refresh
        @sell_window.active = true
        @sell_window.visible = true
      end
      return
    end
  end
end
#---------------------------------COMMAND WINDOW------------------------------
class Window_ShopCommand < ::Window_ShopCommand
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super
    self.x = 0
    self.y = 350
    self.width = 180
    self.height = 200
    self.opacity = 0
    @command_graphic = Sprite.new
    @command_graphic.bitmap = RPG::Cache.picture('Shop Command')
    @command_graphic.x = self.x + 1
    @command_graphic.y = self.y + 7
    @command_graphic.z = self.z - 1
    @command_graphic.visible = self.visible
    self.contents = Bitmap.new(width - 32, height - 32)
    @item_max = 3
    @row_max = 3
    @commands = ["Buy", "Sell", "Exit"]
    refresh
    self.index = 0
  end
  #---UPDATE---#
    def update
    super
    @command_graphic.visible = self.visible
  end
    def dispose
    super
    @command_graphic.dispose
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    for i in 0...@item_max
      draw_item(i)
    end
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #--------------------------------------------------------------------------
  def draw_item(index)
        y = 2 + index * 30
    self.contents.draw_text(0, y, 68, 32, @commands[index])
  end
end

#-----------------------------------SHOP BUY----------------------------------
class Window_ShopBuy < ::Window_ShopBuy
  def initialize(shop_goods)
    super(shop_goods)
    self.x = 20
    self.y = 20
    self.width = 600
    self.height = 228
    self.opacity = 0
    @showback_graphic = Sprite.new
    @showback_graphic.bitmap = RPG::Cache.picture('Shop Window')
    @showback_graphic.x = self.x + 1
    @showback_graphic.y = self.y + 1
    @showback_graphic.z = self.z - 1
    @showback_graphic.visible = self.visible
  end
  def draw_item(index)
    item = @data[index]
    case item
    when RPG::Item
      number = $game_party.item_number(item.id)
      equipped_number = 0
    when RPG::Weapon
      number = $game_party.weapon_number(item.id)
      equipped_number = $game_party.equipped_weapon_number(item.id)
    when RPG::Armor
      number = $game_party.armor_number(item.id)
      equipped_number = $game_party.equipped_armor_number(item.id)
    end
    if item.price <= $game_party.gold and number < 99
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    x = 4
    y = index * 32
    rect = Rect.new(x, y, self.width - 32, 32)
    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)
    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
    self.contents.draw_text(x + 370, y, 88, 32, (number + equipped_number).to_s, 2)
    self.contents.draw_text(x + 290, y, 88, 32, equipped_number.to_s, 2)
    self.contents.draw_text(x + 460, y, 88, 32, item.price.to_s, 2)
  end
  def update
    super
    @showback_graphic.visible = self.visible
  end
  def dispose
    super
    @showback_graphic.dispose
  end
end
#---------------------------SHOP SELL------------------------------------------
class Window_ShopSell < ::Window_ShopSell
  def initialize
    super
    self.x = 20
    self.y = 20
    self.width = 600
    self.height = 228
    self.opacity = 0
    @showback_graphic = Sprite.new
    @showback_graphic.bitmap = RPG::Cache.picture('Shop Window')
    @showback_graphic.x = self.x + 1
    @showback_graphic.y = self.y + 1
    @showback_graphic.z = self.z - 1
    @showback_graphic.visible = self.visible
  end
  def draw_item(index)
    item = @data[index]
    case item
    when RPG::Item
      number = $game_party.item_number(item.id)
      equipped_number = 0
    when RPG::Weapon
      number = $game_party.weapon_number(item.id)
      equipped_number = $game_party.equipped_weapon_number(item.id)
    when RPG::Armor
      number = $game_party.armor_number(item.id)
      equipped_number = $game_party.equipped_armor_number(item.id)
    end
    if item.price > 0
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    x = 4 + index % 1 * (288 + 32)
    y = index / 1 * 32
    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)
    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
    self.contents.draw_text(x + 370, y, 88, 32, (number + equipped_number).to_s, 2)
    self.contents.draw_text(x + 290, y, 88, 32, equipped_number.to_s, 2)
    self.contents.draw_text(x + 460, y, 88, 32, (item.price / 2).to_s, 2)
  end
  def update
    super
    @showback_graphic.visible = self.visible
  end
  def dispose
    super
    @showback_graphic.dispose
  end
end
#-------------------------SHOP NUMBER---------------------------------------
class Window_ShopNumber < ::Window_ShopNumber
  def initialize
    super
    self.x = 420
    self.y = 255
    self.width = 90
    self.height = 50
    self.opacity = 0
  end
end

end

Thanks again SS
 
Status
Not open for further replies.

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top