VX Windowskin Scriptlet

VX Windowskin Scriptlet
by Kyonides-Arkanthos

Features:

It just lets you change your game's windowskin during gameplay by calling a scene script or just by typing a single command in a script call.

Script Call: RPGWindow.skin = 'File'
Scene Script Call: $scene = Scene_SetWindowskin.new

Here You Can Find The Script Spoiler
  1. #  VX Windowskin Scriptlet
  2. #  by Kyonides-Arkanthos alias Kyonides, Shadowball
  3. #  03.12.2010
  4.  
  5. #  Script Call:        RPGWindow.skin = 'File'
  6. #  Scene Script Call:  $scene = Scene_SetWindowskin.new
  7. module RPGWindow
  8.   def self.skin=(filename)
  9.     @filename = filename
  10.     @windowskin = filename.is_a?(String) ? Cache.system(filename) : filename
  11.   end
  12.  
  13.   def self.skin; @windowskin end
  14.  
  15.   def self.name; @filename end
  16. end
  17.  
  18. class Window_Base
  19.   Windowskin = Cache.system('Window')
  20.   def initialize(x, y, width, height)
  21.     super()
  22.     self.windowskin = RPGWindow.skin.nil? ? Windowskin : RPGWindow.skin
  23.     self.x, self.y, self.z = x, y, 100
  24.     self.width, self.height = width, height
  25.     self.back_opacity, self.openness = 200, 255
  26.     create_contents
  27.     @opening, @closing = false, false
  28.   end
  29.  
  30.   alias :kyon_skin_win_base_up :update
  31.   def update
  32.     if !RPGWindow.skin.nil? and self.windowskin != RPGWindow.skin
  33.       self.windowskin = RPGWindow.skin
  34.     end
  35.     kyon_skin_win_base_up
  36.   end
  37. end
  38.  
  39. # Array Add-on - original de Kyonides-Arkanthos
  40. class Array
  41.   def now; return if @pos.nil?; return self[@pos] end
  42.  
  43.   def now=(value); @pos = value end
  44.  
  45.   def index_now; return !@pos.nil? ? @pos : 0 ; end
  46.  
  47.   def next
  48.     @pos = (@pos.nil? or @pos == self.size-1) ? 0 : @pos+1
  49.     return self[@pos]
  50.   end
  51.   alias :succ :next
  52.  
  53.   def previous
  54.     @pos = (@pos.nil? or @pos == 0) ? self.size-1 : @pos-1
  55.     return self[@pos]
  56.   end
  57.   alias :prev :previous
  58. end
  59.  
  60. class Scene_SetWindowskin < Scene_Base
  61.   WINDOWSKINS = ['Window', 'Window Black', 'Window Gray']
  62.   def start
  63.     @spriteset = Spriteset_Map.new
  64.     @help_window = Window_Help.new
  65.     @help_window.set_text('Escoja un Windowskin',1)
  66.     WINDOWSKINS.now = WINDOWSKINS.index(RPGWindow.name)
  67.     RPGWindow.skin = WINDOWSKINS.now
  68.     @name_window = Window_Help.new
  69.     @name_window.y = 64
  70.     @name_window.set_text(windowskin_name,1)
  71.   end
  72.  
  73.   def terminate
  74.     @help_window.dispose
  75.     @name_window.dispose
  76.     @spriteset.dispose
  77.   end
  78.  
  79.   def windowskin_name
  80.     @name_index = RPGWindow.name + " #{WINDOWSKINS.index_now+1} / " +
  81.       WINDOWSKINS.size.to_s
  82.   end
  83.  
  84.   def update
  85.     @help_window.update
  86.     @name_window.update
  87.     if windowskin_name != @name
  88.       @name_window.set_text(windowskin_name,1)
  89.       @name = @name_index
  90.     end
  91.     if Input.trigger? Input::B
  92.       Sound.play_cancel
  93.       $scene = Scene_Map.new
  94.       return
  95.     elsif Input.trigger? Input::LEFT
  96.       Sound.play_decision
  97.       RPGWindow.skin = WINDOWSKINS.prev
  98.     elsif Input.trigger? Input::RIGHT
  99.       Sound.play_decision
  100.       RPGWindow.skin = WINDOWSKINS.next
  101.     end
  102.   end
  103. end
Expand to see the code.


Author Notes

Free to use in any type of RPG Maker game, just include my name (Kyonides-Arkanthos) in your credits.
This certainly looks like an interesting script, and would definitely be useful to some. My one nitpick with the thing is the commenting, or lack thereof. I realize that you can probably read the script easily, as could several other members of the community. But, what happens when a relatively inexperienced scripter tries to do something with this? What happens when someone tries to learn from this script?

As I said, it is just a nitpick, but I think that commenting the methods in the same way RMXP and RMVX have (those little method headers) will improve readability, and by commenting the actual code, you will enable someone to learn from or modify this script far more easily. As for the header, I think that could be expanded upon. You don't have to go overboard like I do with my scripts, but explaining what those methods actually do would help, as would including your terms of use and contact info.
I know that comments serve a purpose in scripting and programming but I avoid it because I tend to leave silly or extremely simple comments for no good reason. Maybe later I'd include some comments regarding the arguments that should be passed to every single method.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=70250