Changing Window Styles in Game
#1
Hi All,

I need help with a script that is meant to change windows styles during the game. A menu lets you select the window styles and should then apply them. This is working as styles for menus and the battle scenes do change but doesn't seem to apply to text boxes when talking to characters...

Script is below from the whole of the options screen -the section I believe controls the windows styles is Window_Windowskin: have I missed something?


Code:
#==============================================================================
# ■ Window_Base
#==============================================================================

class Window_Base
  #--------------------------------------------------------------------------
  def draw_meter(now, max, x, y, width, height, start_color, end_color=start_color )
    self.contents.fill_rect(x, y, width, height, Color.new(0,0,0,255))
    now = now > max ? max : now
    percentage = max != 0 ? (width) * now / max.to_f : 0
    if start_color == end_color
      self.contents.fill_rect(x, y, percentage, height, start_color)
    else
      for i in 0..percentage-1
        r = start_color.red + (end_color.red - start_color.red) / percentage * i
        g = start_color.green + (end_color.green - start_color.green) / percentage * i
        b = start_color.blue + (end_color.blue - start_color.blue) / percentage * i
        a = start_color.alpha + (end_color.alpha - start_color.alpha) / percentage * i
        self.contents.fill_rect(x+i, y, 1, height, Color.new(r, g, b, a))
      end
    end
  end
  #--------------------------------------------------------------------------
end


#==============================================================================
# ■ Window_Option
#==============================================================================

class Window_Option < Window_Base
  #--------------------------------------------------------------------------
  def initialize
    super(6*32, 128, 13*32+16, 2*24+32)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = "Berlin Sans FB"
    self.contents.font.size = 20
    refresh
  end
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    
    self.contents.fill_rect(20, 0+10, 200, 6, Color.new(0, 0, 0, 255))
    self.contents.fill_rect(20, 24+10, 200, 6, Color.new(0, 0, 0, 255))
    
    draw_meter($game_system.se_volume, 100, 21, 1+10, 198, 4, Color.new(255, 255, 255, 255))
    draw_meter($game_system.me_volume, 100, 21, 25+10, 198, 4, Color.new(255, 255, 255, 255))
    
    self.contents.font.color = Color.new( 80, 32, 32)
    self.contents.draw_text(0, 0, width-32, 24, "0")
    self.contents.draw_text(224, 0, 32, 24, "100")
    self.contents.draw_text(0, 0, width-32-2, 24, $game_system.se_volume.to_s + "/ 100", 2)

    self.contents.draw_text(0, 24, width-32, 24, "0")
    self.contents.draw_text(224, 24, 32, 24, "100")
    self.contents.draw_text(0, 24, width-32-2, 24, $game_system.me_volume.to_s + "/ 100", 2)
  end
  #--------------------------------------------------------------------------
end


#==============================================================================
# ■ Window_OptionCommand
#==============================================================================

class Window_OptionCommand < Window_Selectable
  #--------------------------------------------------------------------------
  def initialize
    super(16, 160, 5*32, 4*24+32)
    @commands = [" ", " ", " ", " "]
    @description = ["",
                                "",
                                "",
                                ""]
    @item_max = 4
    @column_max = 1
    self.contents = Bitmap.new(width - 32, height-32)
    self.contents.font.name = "Berlin Sans FB"
    self.contents.font.size = 20
    for i in 0..(@item_max-1)
      draw_item(i, normal_color)
    end
    self.z = 200
    self.index = 0
  end
  #--------------------------------------------------------------------------
  def draw_item(index, color)
    self.contents.font.color = Color.new( 80, 32, 32)
    rect = Rect.new(0, 24*index, width-32, 24)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.draw_text(rect, @commands[index], 1)
  end
  #--------------------------------------------------------------------------
  def update_help
    @help_window.set_text(@description[index], 1)
  end
  #--------------------------------------------------------------------------
  def update_cursor_rect
    self.cursor_rect.set(0, 24*index, width-32, 24)
  end
  #--------------------------------------------------------------------------
end


#==============================================================================
# ■ Window_Windowskin
#==============================================================================

class Window_Windowskin < Window_Selectable
  #--------------------------------------------------------------------------
  def initialize
    super(6*32, 128+3*24+8, 13*32+16, 32+64)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.index = -1
    self.active = false
    @column_max = @item_max = 3#ZVB# Inserisci il numero di windowskin presenti nell'omonima cartella
    refresh
  end
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    for i in 0..@item_max-1
      x = i % @column_max * (width-32)/@column_max
      y = i / @column_max * 64
      bitmap = RPG::Cache.windowskin("Windowskin#{i + 1}")
      self.contents.blt(x, y, bitmap, Rect.new(64, 0, 128, 64), 255)
    end
  end
  #--------------------------------------------------------------------------
  def update_cursor_rect
    x = index % @column_max * (width-32)/@column_max
    y = index / @column_max * 64
    if @index < 0
      self.cursor_rect.empty
    else
      self.cursor_rect.set(x, y, 128, 64)
    end
  end
  #--------------------------------------------------------------------------
end


#==============================================================================
# ■ Scene_Option
#==============================================================================

class Scene_Option
  #--------------------------------------------------------------------------
  def initialize(index=0)
    @index = index
  end
  #--------------------------------------------------------------------------
  def main
    @command_window = Window_OptionCommand.new
    @help_window = Window_Help.new
    @command_window.help_window = @help_window
    @option_window = Window_Option.new
    @windowskin_window = Window_Windowskin.new
    @se_regulation = false
    @me_regulation = false
    @menu = Plane.new    
    @menu.bitmap = RPG::Cache.picture("opzioni")
    @menu.opacity = 255
    @command_window .windowskin = RPG::Cache.windowskin("vuota")
    @help_window .windowskin = RPG::Cache.windowskin("vuota")
    @option_window .windowskin = RPG::Cache.windowskin("vuota")
    @windowskin_window .windowskin = RPG::Cache.windowskin("vuota")
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @help_window.dispose
    @command_window.dispose
    @option_window.dispose
    @windowskin_window.dispose
  end
  #--------------------------------------------------------------------------
  def update
    @help_window.update
    @command_window.update
    @option_window.update
    @windowskin_window.update
    if @command_window.active
      @command_window.help_window = @help_window
      update_command
      return
    end
    if @windowskin_window.active
      @help_window.set_text("")
      update_windowskin
      return
    end
    if @se_regulation == true
      update_se_regulation
    end
    if @me_regulation == true
      update_me_regulation
    end
  end
  #--------------------------------------------------------------------------
  def update_command
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Menu.new(4)
      return
    end
    if Input.trigger?(Input::C)
      case @command_window.index
      when 0
        $game_system.se_play($data_system.decision_se)
        @command_window.active = false
        @se_regulation = true
      when 1
        $game_system.se_play($data_system.decision_se)
        @command_window.active = false
        @me_regulation = true
      when 2
        $game_system.se_play($data_system.decision_se)
        @command_window.active = false
        @windowskin_window.index = 0
        @windowskin_window.active = true
      when 3
        $game_system.se_play($data_system.decision_se)
        $scene = Scene_Formation.new
      end
      return
    end
  end
  #--------------------------------------------------------------------------
  def update_se_regulation
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @se_regulation = false
      @command_window.active = true
      return
    end
    if Input.trigger?(Input::C)
      $game_system.se_play($data_system.decision_se)
      @se_regulation = false
      @command_window.active = true
      return
    end
    if Input.repeat?(Input::RIGHT) and $game_system.se_volume < 100
      $game_system.se_play($data_system.cursor_se)
      $game_system.se_volume += 1
      @option_window.refresh
    end
    if Input.repeat?(Input::LEFT) and $game_system.se_volume > 0
      $game_system.se_play($data_system.cursor_se)
      $game_system.se_volume -= 1
      @option_window.refresh
    end
  end
  #--------------------------------------------------------------------------
  def update_me_regulation
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @me_regulation = false
      @command_window.active = true
      return
    end
    if Input.trigger?(Input::C)
      $game_system.se_play($data_system.decision_se)
      @me_regulation = false
      @command_window.active = true
      return
    end
    if Input.repeat?(Input::RIGHT) and $game_system.me_volume < 100
      $game_system.me_volume += 1
      
      $game_system.bgm_memorize
      $game_system.bgm_stop
      $game_system.bgm_restore
      
      @option_window.refresh
    end
    if Input.repeat?(Input::LEFT) and $game_system.me_volume > 0
      $game_system.me_volume -= 1
      
      $game_system.bgm_memorize
      $game_system.bgm_stop
      $game_system.bgm_restore
      
      @option_window.refresh
    end
  end
  #--------------------------------------------------------------------------
  def update_windowskin
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @windowskin_window.active = false
      @command_window.active = true
      @windowskin_window.index = -1
      return
    end
    if Input.trigger?(Input::C)
      $game_system.se_play($data_system.decision_se)
      $data_system.windowskin_name = $game_system.windowskin_name = "Windowskin#{@windowskin_window.index + 1}"
      return
    end
  end
  #--------------------------------------------------------------------------
end

Here is a video of the current behaviour if it helps...

http://www.mediafire.com/?6gg5v9f8yrnstgb

As always any help or pointers would be appreciated - Many Thanks!
Reply }
#2
Oh it's you again! Hi!


I played around with this a bit, and noticed that the windowskin of one of my custom windows didn't change either. Then I found this in Window_Base:
Code:
#--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    # Reset if windowskin was changed
    if $game_system.windowskin_name != @windowskin_name
      @windowskin_name = $game_system.windowskin_name
      self.windowskin = RPG::Cache.windowskin(@windowskin_name)
    end
  end

And I figured out what I need to do. If you window has an 'update' method, make sure it calls 'super' at the end of it. That way it will run Window_Base's 'update' and properly change the windowskin.
Reply }
#3
Hi MechanicalPen!

Thanks for the super fast response!

Now it might just be me being a bit dense - but I still can't get it to work!

I've called "super" in the Window_Windowskin section and it doesn't seem to work...

Which section did you put it in to get it working?

Thanks so much!
Reply }
#4
No, you must add 'super' to your message window. Because that is the window not properly updating its windowskin.

Find your "one-letter-at-a-time" script and search for an 'update' method. Add 'super' at the end of it.
Reply }
#5
Hi,

Thanks for your suggestion - I went through and carefully checked all the windows styles - I believe the one that handles the text boxes is the standard "Windows_Message" - they all had a super in the def update sections.

I wonder if I should just add some code in this section:

Code:
#--------------------------------------------------------------------------
  def update_windowskin
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @windowskin_window.active = false
      @command_window.active = true
      @windowskin_window.index = -1
      return
    end
    if Input.trigger?(Input::C)
      $game_system.se_play($data_system.decision_se)
      $data_system.windowskin_name = $game_system.windowskin_name = "Windowskin#{@windowskin_window.index + 1}"
      return
    end
  end
  #--------------------------------------------------------------------------

That way after the new window is updated the update command will be called form here. Do you happen to know the script or syntax for changing just the text box style? If not I'll look it up - thanks for the tips and advise you've provided so far.
Reply }
#6
The "Change Windowskin" event just uses "$game_system.windowskin_name = operator[0]" So your code SHOULD work! Let me take a look at that old demo you uploaded, see if I can find the problem using that.

EDIT: Aha! I knew it. Look at the AMS script, it has these declarations.
Code:
@message_box_skin = "Windowskin1"   #Choose the WindowSkin for the Message Box
@name_box_skin = "Windowskin1"       #Choose the WindowSkin for the Name Box

This fix is not going to be as easy as I thought... I don't have time to walk you through it right now, but try adding something like:

Code:
if @message_box_skin != $game_system.windowskin_name
    @message_box_skin = $game_system.windowskin_name
end

To the update section in the AMS script. There might be better ways to solve this though, as I said I don't have time to look for a good solution right now (I'm late for class!) Good luck!
Reply }
#7
Hi,

I tried adding the code you specified to the AMS script under the update section (See below)

Code:
def update

super

if
  @message_box_skin != $game_system.windowskin_name
  @message_box_skin = $game_system.windowskin_name
end


if @fade_in
  self.contents_opacity += 24
  if @input_number_window != nil
    @input_number_window.contents_opacity += 24
  end
  if self.contents_opacity == 255
    @fade_in = false
  end
  return
end
@now_text = nil if @now_text == ""

if @now_text != nil and @mid_stop == false
  if @write_wait > 0
    @write_wait -= 1
    return
  end
  text_not_skip = LETTER_BY_LETTER_MODE
  while true
    @max_x = @x if @max_x < @x
    @max_y = @y if @max_y < @y
    if (c = @now_text.slice!(/./m)) != nil
      if c == "\000"
        c = "\\"
      end
      
      if c == "\001"
        @now_text.sub!(/\[([0123456789ABCDEF#]+)\]/, "")
        temp_color = $1
        color = temp_color.to_i
        leading_x = temp_color.to_s.slice!(/./m)
        if leading_x == "#"
          self.contents.font.color = hex_color(temp_color)
          next
        end
        if color >= 0 and color <= 7
          self.contents.font.color = text_color(color)
        end
        next
      end

      if c == "\002"
        if @gold_window == nil and @popchar <= 0
          @gold_window = Window_Gold.new
          @gold_window.x = 560 - @gold_window.width
          if $game_temp.in_battle
            @gold_window.y = 192
          else
            @gold_window.y = self.y >= 128 ? 32 : 384
          end
          @gold_window.opacity = self.opacity
          @gold_window.back_opacity = self.back_opacity
        end
        c = ""
      end

      if c == "\003"
        @now_text.sub!(/\[([0-9]+)\]/, "")
        speed = $1.to_i
        if speed >= 0 and speed <= 19
          @write_speed = speed
        end
        c = ""
      end

      if c == "\004"
        @now_text.sub!(/\[(.*?)\]/, "")
        buftxt = $1.dup.to_s
        if buftxt.match(/\//) == nil and buftxt != "" then
          $soundname_on_speak = "Audio/SE/" + buftxt
        else
          $soundname_on_speak = buftxt.dup
        end
        c = ""
      elsif c == "\004"
        c = ""
      end
      
      if c == "\005"
        @write_wait += 5
        c = ""
      end
      
      if c == "\006"
        @write_wait += 20
        c = ""
      end
      
      if c == "\016"
        text_not_skip = false
        c = ""
      end
      
      if c == "\017"
        text_not_skip = true
        c = ""
      end
      
      if c == "\020"
        @mid_stop = true
        c = ""
      end
      
      if c == "\021"
        terminate_message
        return
      end
      
      if c == "\023"
        @indent = @x
        c = ""
      end

      if c == "\024"
        @now_text.sub!(/\[([0-9]+)\]/, "")
        @opacity = $1.to_i
        color = self.contents.font.color
        self.contents.font.name = $ams.font_type
        self.contents.font.size = $ams.font_size
        self.contents.font.color = Color.new(color.red, color.green, color.blue, color.alpha * @opacity / 255)
        c = ""
      end

      if c == "\025"
        @now_text.sub!(/\[([0-9]+)\]/, "")
        self.contents.font.size = [[$1.to_i, 6].max, 32].min
        c = ""
      end

      if c == "\026"
        @now_text.sub!(/\[([0-9]+)\]/, "")
        @x += $1.to_i
        c = ""
      end
      
      if c == "\027"
        @now_text.sub!(/\[(.*?)\]/, "")
        @x += ruby_draw_text(self.contents, @x, @y * line_height + (line_height - self.contents.font.size), $1, @opacity)
        if $soundname_on_speak != ""
          Audio.se_play($soundname_on_speak)
        end
      c = ""
      end

      if c == "\030"
        @now_text.sub!(/\[(.*?)\]/, "")
        self.contents.blt(@x , @y * line_height + 8, RPG::Cache.icon($1), Rect.new(0, 0, 24, 24))
        if $soundname_on_speak != ""
          Audio.se_play($soundname_on_speak)
        end
        @x += 24
        c = ""
      end

      if c == "\n"
        @lines += 1
        @y += 1
        @x = 0 + @indent + @face_indent
        if @lines >= $game_temp.choice_start
          @x = 8 + @indent + @face_indent
          @cursor_width = @max_choice_x
        end
        c = ""
      end
      
      if c == "\022"
        @now_text.sub!(/\[([0-9]+)\]/, "")
        @x += gaiji_draw(4 + @x, @y * line_height + (line_height - self.contents.font.size), $1.to_i)
        c = ""
      end
      
      #NEW
      #Dubealex's Text Skip On/OFF Command
       if c == "\100"
          if @alex_skip==false
             @alex_skip=true
          else
            @alex_skip=false
          end
         c = ""
       end  
       #end of new command
                                   
      if c != ""
        self.contents.draw_text(0+@x, 32 * @y, 40, 32, c)
        @x += self.contents.text_size(c).width
        if $soundname_on_speak != "" then
          Audio.se_play($soundname_on_speak)
        end
      end
      
#SKIP_TEXT_CODE

# B = Escape, 0 (On The NumPad), X
# C = Enter, Space Bar and C
# A = Shift, Z

  if Input.press?(Input::C) # <-- Change the value on that line
    if @alex_skip==false      
    text_not_skip = false
    end
      end
    else
      text_not_skip = true
      break
    end
    
    if text_not_skip
      break
    end
  end
  @write_wait += @write_speed
  return
end

if @input_number_window != nil
  @input_number_window.update
  if Input.trigger?(Input::C)
    $game_system.se_play($data_system.decision_se)
    $game_variables[$game_temp.num_input_variable_id] =
      @input_number_window.number
    $game_map.need_refresh = true
    @input_number_window.dispose
    @input_number_window = nil
    terminate_message
  end
  return
end

if @contents_showing
  if $game_temp.choice_max == 0
    self.pause = true
  end
  
  if Input.trigger?(Input::B)
    if $game_temp.choice_max > 0 and $game_temp.choice_cancel_type > 0
      $game_system.se_play($data_system.cancel_se)
      $game_temp.choice_proc.call($game_temp.choice_cancel_type - 1)
      terminate_message
    end
  end
  
  if Input.trigger?(Input::C)
    if $game_temp.choice_max > 0
      $game_system.se_play($data_system.decision_se)
      $game_temp.choice_proc.call(self.index)
    end
    if @mid_stop
      @mid_stop = false
      return
    else
      terminate_message
    end
  end
  return
end

if @fade_out == false and $game_temp.message_text != nil
  @contents_showing = true
  $game_temp.message_window_showing = true
  refresh
  Graphics.frame_reset
  self.visible = true
  self.contents_opacity = 0
  if @input_number_window != nil
    @input_number_window.contents_opacity = 0
  end
  @fade_in = true
  return
end

if self.visible
  @fade_out = true
  self.opacity -= 48
  if self.opacity == 0
    self.visible = false
    @fade_out = false
    $game_temp.message_window_showing = false
  end
  return
end
end



That didn't work and I also added it at the end of the update def too but that didn't work either - the text box just refuses to update! At least now I'm looking in the right place, I thought this was being controlled by the Window_Message script before!

I tired tweaking a few more things in the AMS scrit but still no luck...
Reply }
#8
Okay undo that then...

try.... changing
Code:
self.windowskin = RPG::Cache.windowskin($ams.message_box_skin)
to
Code:
self.windowskin = RPG::Cache.windowskin($game_system.windowskin_name)

edit: Also, you may want to change
Code:
self.windowskin = RPG::Cache.windowskin($ams.name_box_skin)
to
Code:
self.windowskin = RPG::Cache.windowskin($game_system.windowskin_name)
Reply }
#9
That WORKED!

Thank you so much for all your help! I would never have spotted this. I just have to test it under various circumstances but it all looks good so far.

I'll make sure to include you in the credits!
Reply }


Possibly Related Threads…
Thread Author Replies Views Last Post
   Sorting Items in Shop Window Mel 13 17,623 01-18-2018, 05:49 AM
Last Post: DerVVulfman
   Game Performance Mel 21 22,376 11-24-2016, 03:42 AM
Last Post: finalholylight
   Showing only specific skills in a window Mel 2 5,869 01-12-2016, 01:34 PM
Last Post: Mel
   Game Variables List for Copy/Paste JayRay 4 6,983 01-15-2015, 06:18 AM
Last Post: JayRay
   [RMXP]Game Over and Atoa Battle Status mishaps firestalker 8 10,902 08-07-2014, 01:59 AM
Last Post: firestalker
   [Brainstorming] Pallete Changing. MechanicalPen 6 7,709 02-14-2014, 09:46 PM
Last Post: DerVVulfman
   Help with changing background music volume JackMonty 7 9,430 12-10-2012, 10:59 AM
Last Post: JackMonty
   Something I noticed about the Advanced Shop Status Window yamina-chan 5 9,943 08-21-2011, 09:16 PM
Last Post: yamina-chan
   [Atoa SBS] Changing the command window font MegaPowerNinja 3 8,300 04-12-2011, 10:23 PM
Last Post: Victor Sant
   Repositioning the actor command window. MegaPowerNinja 4 9,369 04-12-2011, 05:21 AM
Last Post: MegaPowerNinja



Users browsing this thread: 1 Guest(s)