Chaos Project

RPG Maker => RPG Maker Scripts => RMXP Script Database => Topic started by: Blizzard on February 08, 2016, 12:01:53 pm

Title: [XP][VXA] XPA_Window
Post by: Blizzard on February 08, 2016, 12:01:53 pm
XPA_Window
Authors: Blizzard
Version: 1.4
Type: Custom Window Class
Key Term: Game Utility

Introduction

This script is an optimized rewrite of RMXP's Window class. It is primarily intended to be used with "XP Ace". It was made to emulate RMXP's Window class as closely as possible. Even when using this with RMXP, you're likely to get a few FPS more than with the default implementation.

This work is licensed under BSD License 2.0:
QuoteCopyright (c) Boris "Blizzard" Mikić
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1.  Redistributions of source code must retain the above copyright notice,
    this list of conditions and the following disclaimer.

2.  Redistributions in binary form must reproduce the above copyright notice,
    this list of conditions and the following disclaimer in the documentation
    and/or other materials provided with the distribution.

3.  Neither the name of the copyright holder nor the names of its contributors
    may be used to endorse or promote products derived from this software
    without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

You may use this script for both non-commercial and commercial products without limitations as long as you fulfill the conditions presented by the above license. The "complete" way to give credit is to include the license somewhere in your product (e.g. in the credits screen), but a "simple" way is also acceptable. The "simple" way to give credit is as follows:
QuoteXPA_Window licensed under BSD License 2.0, Copyright (c) Boris "Blizzard" Mikić

Alternatively, if your font doesn't support diacritic characters, you may use this variant:
QuoteXPA_Window licensed under BSD License 2.0, Copyright (c) Boris "Blizzard" Mikic

In general other similar variants are allowed as long as it is clear who the creator is (e.g. "XPA_Window created by Blizzard" is acceptable). But if possible, prefer to use one of the two variants listed above.

If you fail to give credit and/or claim that this work was created by you, this may result in legal action and/or payment of damages even though this work is free of charge to use normally.


Features

v1.1
v1.2
v1.3
v1.31
v1.4


Screenshots

N / A

Demo

XPA_Window (https://downloads.chaos-project.com/scripts/XPA_Window.zip) (includes full source code for the DLL as well with a Visual Studio project for compilation)

Script

Just make a new script above all of your other scripts and paste this code into it.
Script Download (https://downloads.chaos-project.com/scripts/XPA_Window.txt)

Download this DLL file and place it into the same directory where your Game.exe is. The filename should stay XPA_Window.dll.
DLL Download (https://downloads.chaos-project.com/scripts/XPA_Window.dll)

Instructions

Inside the script in the first comment.

Compatibility

99% compatible with SDK v1.x. 99% compatible with SDK 2.x. Requires the user to run at least Windows XP SP3.

Credits and Thanks


Author's Notes

If you find any bugs, please report them here:
http://forum.chaos-project.com

That's it! N-Joy! =D
Title: Re: [XP][VXA] XPA_Window
Post by: KK20 on September 12, 2017, 03:21:40 am
Interesting thing pointed out by Zexion. In XP, you can specify a blank windowskin in the editor and the game will run normally. In XPA, the game crashes (RGSS3 stopped working). This was due to invalid source coordinates prior to making the DLL call.

Replace the Bitmap class in the script to this:

class Bitmap
 
  def linear_write(dest, source, src)
    if src.x < source.width && src.y < source.height
      XPA_Window_Config::DLL_CALL.call(self.object_id, dest.x, dest.y,
        dest.width, dest.height, source.object_id, src.x, src.y, src.width,
        src.height)
    end
  end
 
end
Title: Re: [XP][VXA] XPA_Window
Post by: Blizzard on September 12, 2017, 02:45:55 pm
Thanks for finding that bug, but I think that the fix should be on the C level since the DLL call should be safe. I'll integrate the fix right away and upload a new version. :) Feel free to update the one in the XPA package as well.

EDIT: Yup, a few "== 0" conditions should have actually been "<= 0" to fix this problem. New version is up. :)

EDIT: LMAO! Turns out I fixed that issue in CP a long time ago already. xD
Title: Re: [XP][VXA] XPA_Window
Post by: KK20 on September 12, 2017, 03:05:57 pm
jesus christ...
Thanks for the update Blizz, will add to the XPA package after work :-*
Title: Re: [XP][VXA] XPA_Window
Post by: KK20 on September 21, 2017, 10:39:20 pm
Another thing to add is that there is no reader for viewport. It's a simple fix really

def viewport
  @_viewport
end


While we're on the topic of viewports, XPA_Window is interesting as it actually defines its own viewports with each creation. Was there a reason for that? In XP, there is no single window in the default scripts that uses a viewport, hence calling it would give you nil. It's kinda weird how that is, given that Window.new can actually take in an optional viewport parameter (XPA_Window is missing that also by the way).

This was brought to my attention by Whitespirits regarding the new Netplayer script (http://www.aldeiarpg.com/t12353-netmaker) where a detailed window would be drawn when hovering over an item in your inventory.

class Window_Base < Window

def draw_help
  @help_window = Sprite.new(self.viewport)

Now normally self.viewport here would just return nil (yeah, this is a huge oversight by the original author). But with XPA_Window, self.viewport will equal the dimensions of the window itself. This created some unintended behaviors where the sprite was not being displayed in the window due to the viewport's limitations.

It's probably best to take a look at the usage of Viewports in XPA_Window's design. I don't think I have ever seen any script assign a viewport to a custom window before; but if we're aiming to be a perfect replica of XP's Window class, we still need to consider it a possibility.
Title: Re: [XP][VXA] XPA_Window
Post by: Blizzard on September 22, 2017, 02:11:30 am
I see, I see. Do you think I should add that fix then? IMO we should extend functionality to fix issue rather than replicate them for consistency's sake. While nobody does use a viewport in a window, I am aware that it's possible, but IDK if the getter worked in RMXP.

I create the viewports upon window creation to be able to manage the window sprites easier and make sure they don't go out of bounds. And it's much easier to change the viewport coordinates rather than for each of the sprites individually. I think I also saw some performance boosts from this as opposed to manually changing all coordinates, but I can't remember anymore.
Title: Re: [XP][VXA] XPA_Window
Post by: KK20 on September 22, 2017, 02:54:32 am
I'm all for improving upon the original design *points to Tilemap* but yeah, we need to make sure we don't remove what was already there for compatibility sake.

Window#viewport does work--I've tested it in XP. I only recall a disposed? method did not exist for some class despite it being in the Help.

I can spend this weekend to go over the design. Curious about that performance boost.
Title: Re: [XP][VXA] XPA_Window
Post by: Blizzard on September 22, 2017, 03:31:49 am
I THINK there was a performance boost. xD
In any case, let me know whether I should add the viewport fix or not.
Title: Re: [XP][VXA] XPA_Window
Post by: KK20 on September 22, 2017, 04:46:27 am
Yes, a fix would be desired.
Title: Re: [XP][VXA] XPA_Window
Post by: Blizzard on September 22, 2017, 12:34:56 pm
Fix is up.