The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX Ace => VXA Scripts Database => Topic started by: modern algebra on July 27, 2013, 03:57:25 AM

Title: [VXA] Change Windowskin
Post by: modern algebra on July 27, 2013, 03:57:25 AM
Change Windowskin
Version: 1.0.1
Author: modern algebra
Date: 27 July 2013

Version History



Description


This script allows you to change the windowskin in-game with a script call. It does not deal with changing the window tone, as there is already an event command that does that ("Change Window Color", page 3, column 1, row 14).

Instructions

Paste the script into its own slot in the Script Editor, above Main but below Materials.

For further instructions on configuration, consult the header of the script.

Script


Code: [Select]
#==============================================================================
#    Change Windowskin
#    Version: 1.0.1
#    Author: modern algebra (rmrk.net)
#    Date: 27 July 2013
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#   
#    This script allows you to change the windowskin in-game.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#   
#    Paste this script into its own slot in the Script Editor, above Main but
#   below Materials.
#
#    To set the initial filename for the windowskin, go to line 46 and change
#   the portion between quotation marks to the name of the desired windowskin.
#
#    To change the windowskin in-game, use the following code in a Script call
#   event command (last button on the last page of event commands)
#
#        $game_system.windowskin = "filename"
#
#    Replace filename with the name of the windowskin graphic you intend to
#   use.
#
#    If you are using another script that allows you to select a windowskin for
#   some windows and do not want it to be affected by this script, then be
#   sure to use a skin that you never use for this script. If you do want it
#   to be controlled by this script, then set it to "Window"
#``````````````````````````````````````````````````````````````````````````````
#  EXAMPLE:
#
#        $game_system.windowskin = "Window"
#
#    Will set the windowskin to the file named Window in the System folder of
#   Graphics.
#==============================================================================

$imported = {} unless $imported
$imported[:MA_ChangeWindowSkin] = true

#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
#    BEGIN Editable Region
#||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
MACW_WINDOWSKIN = "Window"  # Set this to the name of the window file to use.
#||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#    END Editable Region
#//////////////////////////////////////////////////////////////////////////////
if !MACW_WINDOWSKIN.is_a?(String) || MACW_WINDOWSKIN.empty?
  MACW_WINDOWSKIN = "Window"
  msgbox("Error at line 41 of Change Windowskin script:\nMACW_WINDOWSKIN must be a non-empty string!")
end

#==============================================================================
# *** Cache
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased method - self.system
#==============================================================================

class << Cache
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * System
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias macw_systm_2mf0 system
  def system(filename, *args)
    filename = $game_system.macw_windowskin if filename == "Window"
    macw_systm_2mf0(filename, *args) # Call original method
  end
end

#==============================================================================
# ** Game_System
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new attr_accessor - macw_windowskin
#    new attr_reader - macw_old_windowskin
#    aliased method - initialize
#==============================================================================

class Game_System
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Public Instance Variables
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  attr_reader   :macw_old_windowskin
  attr_accessor :macw_windowskin
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Object Initialization
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias macw_ilze_2bd4 initialize
  def initialize(*args)
    @macw_old_windowskin = "Window"
    @macw_windowskin = MACW_WINDOWSKIN
    macw_ilze_2bd4(*args) # Call original method
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Set Windowskin
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def windowskin=(filename)
    @macw_old_windowskin = @macw_windowskin
    @macw_windowskin = filename
  end
end

#==============================================================================
# ** Window_Base
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased method - update
#==============================================================================

class Window_Base
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Update
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias macw_pdat_5ht8 update
  def update(*args)
    macw_pdat_5ht8(*args) # Call original method
    macw_update_windowskin
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Update Windowskin
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def macw_update_windowskin
    if $game_system.macw_windowskin != @macw_check_windowskin
      @macw_check_windowskin = $game_system.macw_windowskin
      $game_system.macw_windowskin = "Window" # Disallow interference w/ check
      # If windowskin governed by this script and no other
      if windowskin == Cache.system($game_system.macw_old_windowskin) ||
        windowskin == Cache.system("Window")
        self.windowskin = Cache.system(@macw_check_windowskin)
      end
      $game_system.macw_windowskin = @macw_check_windowskin # Restore
    end
  end
end

Credit



Thanks


Support


Please post in this topic at RMRK.net if you have any questions, suggestions, error reports, or comments about this script. It is perfectly fine to post here even if this topic has not been posted in for a very long time.

Please do not message me privately, as any concerns you have are likely shared by others and they will benefit from our correspondence being public. Additionally, I am occasionally absent, and posting publically will allow other members to assist you when I am unable to do so quickly.

Known Compatibility Issues

If you are using a custom script that allows you to set windowskins and want it to be controlled by this script, then set the windowskin to "Window" in the other script. If you do not want it to be affected, then set it to a windowskin that you never use when changing it in this script.

I am currently unaware of any other compatibility issues.

Author's Notes


I could have sworn I had written this script a long time ago, but I couldn't find it. Maybe I was thinking of the System Options script I had started writing but abandoned.

Terms of Use


I adopt RMRK's default Terms of Use (http://rmrk.net/index.php/topic,45481.0.html).
Title: Re: [VXA] Change Windowskin
Post by: TheoAllen on July 27, 2013, 05:51:27 AM
I have a little suggestion. Instead of being updated in Scene_Base, it's better if you put them in Window_Base def update. Because, if you look at Scene_File and its subclasses, savefile_windows treated as Array. Not a window instance variable. So, they won't change, I guess.
Title: Re: [VXA] Change Windowskin
Post by: modern algebra on July 27, 2013, 12:30:09 PM
Thanks for the tip and yeah, that's true.

However, the main concern is for Scene_Map and Scene_Battle, since it is the only one, by default, where the method in Game_Interpreter would be called and, hence, that is the only time that method in Scene_Base would be called. For every other scene, the windows will start off with the new windowskin because of the way I aliased the system method in Cache, and that includes the savefile windows.

I also didn't really want to put it into the update method of each window since it seems like a waste of resources to check if the windowskin has changed or to retrieve the windowskin graphic from Cache every frame for every window, though I recognize it is likely negligible.

Originally, I also did not want to change the windowskin for windows that were already being governed by a custom script (i.e. scripts where the creator already lets the person choose the windowskin for, say, message systems). I did so for loading new scenes, but I admit that the method I ultimately used for mid-scene updating failed to do so.

meow, it is always possible that someone will write a battle script or map script that uses windows without putting them in an instance variable, but I figured that would be rare since then they would have to handle disposal and updating in a custom manner.

Anyway, you are right that putting it in the update method of each window would be the safest and most globally compatible way to do it. For that matter, it would permit changing the macw_windowskin method directly from any scene, which may be useful especially if someone wants to change the script so that it works for save files.

Still I think those circumstances are rare, and I am willing to sacrifice them in order to avoid constant checks.

I am thinking I will perhaps change it so that it is at least easily updateable for unconventional scenes which do not store all windows in instance variables.


EDIT::

Scratch that, I do need to fix it. I forgot that Window_Message hides most of its subsidiary windows within the Window_Message class, and the current method would not update the windowskin for those. I suppose I may just have to abandon the whole attempt to retain compatibility with other scripts that control windowskins.