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.

Poccil : Composit Windowskin (Demystified & Resolved!)

Woohoo, everything in this post has been figured out! A big applaus to poccil for loaning his smarts to me in creating this custom component Windowskin script!

Here is a screenshot of the windowskin in action....

I've combined...

Back          = "dark_eternal"
Borders       = "Royal"
Scrolls       = "Royal"
Cursor        = "Orange Glass"
Pause         = "dark_eternal"
Arrows        = "Royal"

and it created this!

http://i224.photobucket.com/albums/dd28 ... xample.png[/img]

All I had to do to apply it to my CMS settings was....

Code:
module CMS
################################################################################
#==============================================================================#
# ~**                 CUSTOMIZABLE CONSTANTS - BEGIN                       **~ #
#==============================================================================#
################################################################################
#===============================================================================
# * Default Settings used within CMS Menu Windows.
#===============================================================================
  # Show faces and Map BG in menu?
  Faces         = true
  ShowMap       = true
  # Default Windowskin
  Windowskin    = "003-Red01"
  # Composit Windowskin Switch
  Custom_WS     = true
  # Composit Windowskin Properties
  Back          = "dark_eternal"
  Borders       = "Royal"
  Scrolls       = "Royal"
  Cursor        = "Orange Glass"
  Pause         = "dark_eternal"
  Arrows        = "Royal"
  Rect_Color    = Color.new(204, 224, 240, 160)
  # Font Information
  Font_Type     = "Georgia"
  Font_Size     = 22
  # Window Information
  Opacity       = 200
  B_Opacity     = 255
  Z_Offset      = 600
  #....etc
end

Then in the module CMS's  "MACL", I wrote method.

Code:
module CMS
  #-----------------------------------------------------------------------------
  # * Method for applying composit/custom windowskin to CMS Menu Windows
  #-----------------------------------------------------------------------------
  def self.apply_windowskin
    boolean = Custom_WS
    if boolean
      RPG::Cache.create_windowskin(Back, Borders, Scrolls, Cursor, Pause, Arrows)
    else
      RPG::Cache.windowskin(Windowskin) rescue RPG::Cache.windowskin("001-Blue01")
    end
  end
  #...etc, etc...
end # Of CMS Module

Finally, to apply it to my CMS windows, I set it like so...

Code:
class Window_PlayerStats < Window_Base
  def initialize
    #super(0, 320, 160, 160)
    super(-160, 320, 160, 160)
    self.contents           = Bitmap.new(width - 32, height - 32)
    self.windowskin         = CMS.apply_windowskin
    self.opacity            = CMS::Opacity
    self.contents.font.name = CMS::Font_Type
    self.contents.font.size = CMS::Font_Size
    refresh
  end
  #...etc
end

CONCLUSION

This is a great new feature we can use when creating a CMS, credits to poccil for this feature ! :thumb:
 

poccil

Sponsor

Basically, you want to create a composite windowskin containing elements from other windowskins.  I will create such a script for you.  Please wait.

EDIT:  This script does what you want.  It returns a Bitmap object containing
elements from other windowskins.

Code:
module RPG
module Cache
 def self.ensureWindowskin(name)
  return windowskin(name) rescue windowskin("001-Blue01")
 end
 def self.createWindowskin(skinForBG,skinForBorders,skinForScrolls,
    skinForCursor,skinForPause,skinForArrows)
    # Calculate key
  key=":windowskin:"+skinForBG+"_"+skinForBorders+"_"+skinForScrolls
  key+="_"+skinForCursor+"_"+skinForPause+"_"+skinForArrows
    # Get windowskins
  skinForBG=ensureWindowskin(skinForBG)
  skinForCursor=ensureWindowskin(skinForCursor)
  skinForPause=ensureWindowskin(skinForPause)
  skinForArrows=ensureWindowskin(skinForArrows)
  skinForScrolls=ensureWindowskin(skinForScrolls)
  skinForBorders=ensureWindowskin(skinForBorders)
  if @cache[key] && !@cache[key].disposed?
   return @cache[key]
 end
  # Create bitmap
  bitmap=Bitmap.new(192,128)
  # Copy background
  bitmap.blt(0,0,skinForBG,Rect.new(0,0,128,128))
  # Copy borders
  bitmap.blt(128,0,skinForBorders,Rect.new(128,0,64,64))
  bitmap.fill_rect(144,16,32,32,Color.new(0,0,0,0))
  # Copy scrollbar
  bitmap.blt(144,16,skinForScrolls,Rect.new(144,16,32,32))
  # Copy cursor
  bitmap.blt(128,64,skinForCursor,Rect.new(128,64,32,32))
  # Copy pause
  bitmap.blt(160,64,skinForPause,Rect.new(160,64,32,32))
  # Copy arrows
  bitmap.blt(128,96,skinForArrows,Rect.new(128,96,64,32))
  @cache[key]=bitmap
  return bitmap
 end
end
end

That code defines a new method, "createWindowskin", in RPG::Cache.

Here's an example of how to create a bitmap with that function using a script.  Note that the code uses four different windowskins to achieve this effect.

Code:
mywindowskin = RPG::Cache.createWindowskin(
 "royal",  # Windowskin file for background
 "windowskin", # Windowskin file for borders
 "001-blue01", # Windowskin file for scrolls
 "windowskin23", # Windowskin file for cursor
 "royal", # Windowskin file for pause icon
 "windowskin23" # Windowskin file for arrows
)

I hope this helps.
 
Sorry, but I had to revive my old topic for the greater good (instead of making a new one)

Poccil, I've modified your script, but I can't figure out how to get it to work... I've never actually got it to work from the start, can you tell me what I did wrong?

The modified version is up top, I can't ever get it to create anything. I have it re-worked individually so that somebody can create a new windowskin in-game from the Config menu, only thing missing is this script (working, that is...).

If you can revise this script for me, to where it'll at least work. I'm not sure if I re-organized it properly either, I need you to work your magic (again)

Also, if you can re-work me a module, so that game author-defined windowskins can be written into the script, I'll work on the player-defined stuff based on that (and allow it to save to a soft .rxdata file they can recall or delete at will.)
 

poccil

Sponsor

Your script had several problems, which I will explain below.

*  Your code used a hash table as the cache key.  Because the ordering of a hash table is undefined, it is a poor candidate for a key.  Use a string instead.
*  The elements of the windowskin were created in the wrong order, so the wrong windowskin was used for the wrong element.
*  The "mywindowskin" code is only an example of how to use the windowskin script, it is not really considered part of the script.

The corrected code follows.

Code:
module RPG module Cache
  #-----------------------------------------------------------------------------
  # * RPG::Cache.ensure_windowskin(name)
  #-----------------------------------------------------------------------------
  def self.ensure_windowskin(name)
    return RPG::Cache.windowskin(name) rescue windowskin("001-Blue01")
  end
  #-----------------------------------------------------------------------------
  # * RPG::Cache.create_windowskin()
  #-----------------------------------------------------------------------------
  # Syntax
  #   o n1 : Windowskin Background
  #   o n2 : Windowskin Borders
  #   o n3 : Windowskin Scrolls
  #   o n4 : Windowskin Cursor
  #   o n5 : Windowskin Pause
  #   o n6 : Windowskin Arrows
  #-----------------------------------------------------------------------------
  def self.create_windowskin(n1, n2, n3, n4, n5, n6)
    # Create bitmap
    bitmap = Bitmap.new(192, 128)
    # Calculate key
    key= ":windowskin:"+n1+"_"+n2+"_"+n3
    key+=           "_"+n4+"_"+n5+"_"+n6
    # Return @cache[key] unless nil or disposed
    if @cache[key] && !@cache[key].disposed?
      return @cache[key]
    end
    # Apply settings
    create_background(bitmap, n1)
    create_border(bitmap, n2)
    create_fill_rect(bitmap, nil)
    create_scroll(bitmap, n3)
    create_cursor(bitmap, n4)
    create_pause(bitmap, n5)
    create_arrows(bitmap, n6)
    @cache[key] = bitmap
    # Return Composit Windowskin
    return bitmap
  end
  #-----------------------------------------------------------------------------
  # * Apply Background
  #-----------------------------------------------------------------------------
  def self.create_background(bitmap, n = nil)
    bitmap.blt(0, 0, ensure_windowskin(n), Rect.new(0, 0, 128, 128))
    return
  end
  #-----------------------------------------------------------------------------
  # * Apply Cursor
  #-----------------------------------------------------------------------------
  def self.create_cursor(bitmap, n = nil)
    bitmap.blt(128,64,ensure_windowskin(n), Rect.new(128, 64, 32, 32))
    return
  end
  #-----------------------------------------------------------------------------
  # * Apply Pause
  #-----------------------------------------------------------------------------
  def self.create_pause(bitmap, n = nil)
    bitmap.blt(160,64,ensure_windowskin(n), Rect.new(160, 64, 32, 32))
    return
  end
  #-----------------------------------------------------------------------------
  # * Apply Arrows
  #-----------------------------------------------------------------------------
  def self.create_arrows(bitmap, n = nil)
    bitmap.blt(128,96,ensure_windowskin(n), Rect.new(128, 96, 64, 32))
    return
  end
  #-----------------------------------------------------------------------------
  # * Apply Scrollbar
  #-----------------------------------------------------------------------------
  def self.create_scroll(bitmap, n = nil)
    bitmap.blt(144,16,ensure_windowskin(n), Rect.new(144, 16, 32, 32))
    return
  end
  #-----------------------------------------------------------------------------
  # * Apply Border
  #-----------------------------------------------------------------------------
  def self.create_border(bitmap, n = nil)
    bitmap.blt(128, 0,ensure_windowskin(n), Rect.new(128,  0, 64, 64))
    return
  end
  #-----------------------------------------------------------------------------
  # * Fill Rect
  #-----------------------------------------------------------------------------
  def self.create_fill_rect(bitmap, color = Color.new(0, 0, 0, 0))
    if color.is_a?(Color) 
      bitmap.fill_rect(144, 16, 32, 32, color) 
    end
    return
  end
end # of module RPG::Cache
end # of module RPG
 
I don't mean to be a bother, but I'm still puzzled on how it's 'supposed' to work.

Okay... can you walk me through on how to setup and apply the created 'composit' skin to show up as your windowskin? I need to be able to re-call it for certain windows too, like...

I set the windowskin for my CMS seperate from normal windows, which is defined like so...

Code:
module CMS
  Windowskin = composit_windowskin("name")
  #...
end


class Window_Example < Window_Base
  def initialize
    #....
    self.windowskin = RPG::Cache.windowskin(CMS::Windowskin)
    #...
  end
end

Or if I wanted to set it with Ccoa's UMS, for the message window, again, how would I call it?

[Modified for correct formatting.  --Peter O.]
 

poccil

Sponsor

The method "composite_windowskin" returns a bitmap containing elements from various windowskins.  Here is how the code would appear on a custom window:
Code:
class Window_Example < Window_Base
  def initialize
    #....
    self.windowskin = RPG::Cache.create_windowskin(
       "royal",  "windowskin", "001-blue01",  "windowskin23",  "royal",  "windowskin23"
    )
  end
end

Outside of the window, you can change the window's windowskin like this.  Assume that there is a variable named "mywindow" defined in the program.
Code:
    mywindow.windowskin = RPG::Cache.create_windowskin(
       "001-blue01",  "windowskin", "windowskin23",  "windowskin23",  "royal",  "windowskin23"
    )
Your example, "CMS::Windowskin", is probably supposed to store a composite windowskin, like this:
Code:
module CMS
  Windowskin = RPG::Cache.create_windowskin(
       "001-blue01",  "windowskin", "windowskin23",  "windowskin23",  "royal",  "windowskin23"
    )
    #....
end
Note, however that "CMS::Windowskin" is a constant, which means it can't be modified once it's set.  If you want users to redefine the window composition defined here, you must change it to a set of methods that read and write the value:
Code:
module CMS
  @windowskin = RPG::Cache.create_windowskin(
       "001-blue01",  "windowskin", "windowskin23",  "windowskin23",  "royal",  "windowskin23"
  )
  attr_accessor :windowskin
end
The windowskin can then be accessed with "CMS.windowskin" and can be set with "CMS.windowskin=value" or something similar.

I hope this helps.
 
I placed a quick FAQ in the opening post that shows you how I applied this feature to all of my CMS's windows.

This topic has been resolved! If anybody else has any questions related to this topic, please create a new topic and I (or somebody else) will be glad to help you.

~Thanks poccil
 

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