[RMVXA] [SCRIPTING] I KINDA BROKE SCENE_EQUIP, BUT I'M NOT SURE WHERE EXACTLY...

Posts

Pages: 1
Hi!

I was just moving windows around when I noticed something wrong. The status screen will no longer display the changed parameters (@temp_actor's params) when equipping/unequipping stuff. I've been trying to see where I went wrong for the past two days, but with not much luck. I'm hoping that one of you guys could point out to me what's causing all this...

I've tried plugging in the following in a blank project, and the same problem pops up, so I'm almost certain that the mistake is somewhere in here.

Here's the complete code (Scene_Equip, Windows):
class Window_Help < Window_Base
  def initialize(line_number = 2, x = 0, y = 0, w = Graphics.width)
    super(x, y, w, fitting_height(line_number))
  end
  def set_text(text)
    if text != @text
      @text = text
      refresh
    end
  end
  def clear
    set_text("")
  end
  def set_item(item)
    set_text(item ? item.description : "")
  end
  def refresh
    contents.clear
    draw_text_ex(4, 0, @text)
  end
end

class Window_EquipStatus < Window_Base
  def initialize(x, y, w)
    super(x, y, w, window_height)
    @actor = nil
    @temp_actor = nil
    refresh
  end
  def window_height
    fitting_height(visible_line_number)
  end
  def visible_line_number
    return 6
  end
	  def refresh
      contents.clear
      x = contents.width / 5
      draw_item(x, line_height * 0, 0)
      draw_item(x, line_height * 1, 1)
      draw_item(x, line_height * 2, 2)
      draw_item(x, line_height * 3, 3)
      draw_item(x, line_height * 4, 4)
      draw_item(x, line_height * 5, 6)
	  end
    def draw_item(x, y, param_id) # +30
      draw_param_name(x * 0, y, param_id)
      draw_current_param(x * 2, y, param_id) if @actor
      draw_right_arrow(x * 3, y)
      draw_new_param(x * 4, y, param_id) if @temp_actor
    end
end

class Window_EquipSlot < Window_Selectable
  def visible_line_number
    return 6
  end
  def draw_item(index)
    return unless @actor
    if slot_name(index) == '--'
      draw_horz_line(line_height * index)
      @help_window.clear if @help_window
      return
    else
      rect = item_rect_for_text(index)
      change_color(system_color, enable?(index))
      draw_text(rect.x + 12, rect.y, 92, line_height, slot_name(index))
      draw_item_name(@actor.equips[index], rect.x + 72, rect.y, enable?(index))
    end
  end
  alias norm draw_item_name
  def draw_item_name(item, x, y, enabled = true)
    if item
      norm(item, x, y, enabled = true)
    else
      draw_icon(186, x, y, enabled)
      change_color(normal_color, false)
      draw_text(x + 52, y, self.width, line_height, "--", 0)
    end
  end
  def draw_horz_line(y)
    line_y = y + line_height / 2 - 1
    contents.fill_rect(24, line_y, contents_width - 48, 2, line_color)
  end
  def line_color
    color = normal_color
    color.alpha = 48
    color
  end
end

class Window_EquipItem < Window_ItemList
  def col_max
    return 2
  end
  def draw_item(index)
    item = @data[index]
    rect = item_rect(index)
    rect.width -= 4
    if item
      draw_item_name(item, rect.x, rect.y, enable?(item))
      draw_item_number(rect, item)
    elsif !@data[0]
      draw_icon(186, rect.x, rect.y)
      change_color(normal_color, false)
      draw_text(rect.x + 24, rect.y, self.width, line_height, 'Unequip', 0)
    end
  end
end

class Dis < Window_Base
  def initialize(h, x, y, w)
    super(x, y, w, fitting_height(h))
    @actor = nil
  end
  def actor=(actor)
    return if @actor == actor
    @actor = actor
    refresh
  end
  def refresh
    contents.clear
    contents.font.size = 24
    x, y, w, h = 0, 96 + line_height - 12, contents.width, line_height
    draw_face(@actor.face_name, @actor.face_index, x, y - 96)
    draw_actor_graphic(@actor, x + 16, y)
    draw_text(x, y, w, h, @actor.name, 1)
  end
end

class Scene_Base
  def fitting_height(line_number)
    line_number * line_height + standard_padding * 2
  end
  def line_height
    return 24
  end
  def standard_padding
    return 12
  end
end

class Scene_Equip < Scene_MenuBase
  def start
    super
    create_dis
    create_status_window
    create_slot_window
    create_item_window
    create_help_window
    command_equip
  end
  def create_help_window
    wy = Graphics.height - @item_window.height - fitting_height(2)
    @help_window = Window_Help.new(2, 0, wy)
    @help_window.viewport = @viewport
  end
  def create_dis
    ww = 120
    wx = (Graphics.width - ww) / 2
    @dis = Dis.new(6, wx, 0, ww)
    @dis.actor = @actor
  end
  def create_status_window
    ww = Graphics.width / 2 - 60
    @status_window = Window_EquipStatus.new(0, 0, ww)
    @status_window.viewport = @viewport
    @status_window.actor = @actor
  end
  def create_slot_window
    wx = @status_window.width + 120
    wy = 0
    ww = @status_window.width
    @slot_window = Window_EquipSlot.new(wx, wy, ww)
    @slot_window.viewport = @viewport
    @slot_window.help_window = @help_window
    @slot_window.status_window = @status_window
    @slot_window.actor = @actor
    @slot_window.set_handler(:ok,       method(:on_slot_ok))
    @slot_window.set_handler(:cancel,   method(:on_slot_cancel))
    @slot_window.set_handler(:pagedown, method(:next_actor))
    @slot_window.set_handler(:pageup,   method(:prev_actor))
  end
  def create_item_window
    ww = Graphics.width
    wh = fitting_height(4)
    wx = 0
    wy = Graphics.height - wh
    @item_window = Window_EquipItem.new(wx, wy, ww, wh)
    @item_window.viewport = @viewport
    @item_window.help_window = @help_window
    @item_window.status_window = @status_window
    @item_window.actor = @actor
    @item_window.set_handler(:ok,     method(:on_item_ok))
    @item_window.set_handler(:cancel, method(:on_item_cancel))
    @slot_window.item_window = @item_window
  end
  def on_slot_cancel
    SceneManager.return
  end
  def on_actor_change
    @status_window.actor = @actor
    @slot_window.actor = @actor
    @item_window.actor = @actor
    @dis.actor = @actor
    @slot_window.activate
  end
end

Thanks :)
In 'def create_slot_window' you need:
@slot_window.status_window = @status_window


This sets up some extra bits that gets the equipment preview working.
GRS> It's already there..
def create_slot_window
  wx = @status_window.width + 120
  wy = 0
  ww = @status_window.width
  @slot_window = Window_EquipSlot.new(wx, wy, ww)
  @slot_window.viewport = @viewport
  @slot_window.help_window = @help_window
  @slot_window.status_window = @status_window # <-- over here
  @slot_window.actor = @actor
  @slot_window.set_handler(:ok,       method(:on_slot_ok))
  @slot_window.set_handler(:cancel,   method(:on_slot_cancel))
  @slot_window.set_handler(:pagedown, method(:next_actor))
  @slot_window.set_handler(:pageup,   method(:prev_actor))
end
Huh, must've c/p'd my find wrong. I'll take another look tonight.
Whoops, that should've been
@item_window.status_window = @status_window

The slot window doesn't control the equipment change preview! (but this isn't the problem anyways)

Anyways the real problem is for the Window_EquipItem to update it's 'help' it needs @help_window to not be nil. The order you create the windows means
@item_window.help_window = @help_window

At this point the @help_window is nil so the item window will never attempt to draw the equipment preview. Since your new help window has the item window as a dependency you'll have to change that or just assign the help window to the item window once it's been created.
Yep, that was it. I've looked around the other scenes that I've changed, and found the same oversight repeated...

Thanks for your help grs!
Pages: 1