Iavra Generic Popup

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
859
First Language
German
Primarily Uses
Description


Allows to display generic popups messages on the screen.


Author


Iavra


Parameters


@param Display On Scene
@desc A comma-separated list of scenes where popups are allowed.
@default Scene_Map, Scene_Menu




How to Use


To display a new popup, call the following function:


IAVRA.POPUP.popup(text, options, callbacks);


Where "text" is the text to be displayed, "options" is an optional object to override some or all of the default options and "callbacks" is an optional object to override some or all of the default callbacks. Any escape characters can be used inside the "text" parameter, but most will need to have their backslashes doubled.


The following options can be specified:


width
Width of the popup window. It's height will be autofit to its content. Default: 200

duration
How long the popup should be visible. The update callback can choose to ignore this value. Default: 100

lineHeight
Overwrite lineHeight() in Window_Base, use default if empty. Default: (empty)

fontName
Overwrite standardFontFace() in Window_Base, use default if empty. Default: (empty)

fontSize
Overwrite standardFontSize() in Window_Base, use default if empty. Default: (empty)

padding
Overwrite standardPadding() in Window_Base, use default if empty. Default: (empty)

textPadding
Overwrite textPadding() in Window_Base, use default if empty. Default: (empty)

backOpacity
Overwrite standardBackOpacity() in Window_Base, use default if empty. Default: (empty)

windowskin
Overwrite loadWindowskin() in Window_Base, use default if empty. Default: (empty)

scenes
Takes an array of scene classes and overwrites the value specified in "Display On Scene".


The following callbacks can be specified:


init(popup)
Called after the popup has been created, but before text has been drawn on it.

update(popup)
Called every frame. If this function returns a falsy value, the popup is removed. It has access to the popup duration and can either work with or ignore it.

remove(popup) Called when the popup is removed either by running out, clear() or because update() returned false.


To clear all popups, call the following function:


IAVRA.POPUP.clear();




Terms of Use


Free to use for both commercial and non-commercial games. Please give credit.


Download


http://pastebin.com/a9FERYYT


Notes


This plugin doesn't do much on its own, but is meant as a framework for other plugins and might be needed as a dependency for some of mine.
 
Last edited by a moderator:

Ramiro

Now with an army of Mecha-Ralphs!
Veteran
Joined
Aug 5, 2015
Messages
860
Reaction score
366
First Language
Spanish
Just a suggestion than doesn't really change much of the pugin itself.

Try to use plugin commands too, pleople tend to use that now because it is a DSL so it's even easier to understand than javascript calls for non scripters.

They are quite easy to implement.

That doesn't mean you can keep both apis working of course, but "common" people won't use callbacks or advance functions so they can call it as:

IAVRA popup "my message"or

popup "my message"As a plugin command.

Another thing can be a way to edit in javascript the defaults at runtime:

IARVA.POPUP.configure({  textColor: '#ff0000', width: '120px', defaultCallback: function () {}});So if for some reason you need to  use multiple times multiple sets of configurations, the values are stored.
 
Last edited by a moderator:

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
859
First Language
German
Primarily Uses
I will definitely implement the configure()-function, but i'm not sure about the plugin commands, since (i guess) it would split the message at spaces and i'll have to join it again. Might be worth the additional work to make it easier for the user, though.


Also, there is no "textColor" property, but you are free to use any kind of control characters, since the popup uses drawTextEx internally ^^
 
Last edited by a moderator:

wizaerd

Adventurer
Member
Joined
Mar 13, 2012
Messages
219
Reaction score
26
First Language
English
Primarily Uses
Where do these popups pop up at?  I assume the same location as the event itself? Is there anyway to configure a location for the popup to pop up at?  And if so, will it work with your tweening plugin to have the popup move?
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
859
First Language
German
Primarily Uses
Development of this plugin is currently on hiatus (and has a fair amount of errors and badly formatted code in it), while i'm working on a similar, but different plugin.
 

wizaerd

Adventurer
Member
Joined
Mar 13, 2012
Messages
219
Reaction score
26
First Language
English
Primarily Uses
Since I'm already following this thread, will you post here when you either pick it back up, or complete and make available the similar but different plugin?
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
859
First Language
German
Primarily Uses
I updated the OP with a new version of this plugin. Since i wanted to keep it generic, it has evolved in more of a framework that might be used by some of my future plugins.


The default callbacks only display a popup in the upper left corner (0, 0), but i included a short demo, that can be used to get a feeling of the possiblities this provides. It displays popups in the lower left corner, pushing older ones upward whenever a new popup gets displayed and has them fading out, instead of just vanishing.
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
859
First Language
German
Primarily Uses
The plugin has been updated and i will ask a mod to move it to released plugins. Note, that this is not meant to be used alone, but rather as a framework for other plugins that want to display popups/notifications and don't want to deal with it.


I'll soon probably write a plugin that shows loot popups and will make use of this.
 

EnMod

noelquiles.com
Veteran
Joined
Oct 28, 2015
Messages
24
Reaction score
3
First Language
English
Primarily Uses
I updated the OP with a new version of this plugin. Since i wanted to keep it generic, it has evolved in more of a framework that might be used by some of my future plugins.

The default callbacks only display a popup in the upper left corner (0, 0), but i included a short demo, that can be used to get a feeling of the possiblities this provides. It displays popups in the lower left corner, pushing older ones upward whenever a new popup gets displayed and has them fading out, instead of just vanishing.
I'm confused, is the demo link also located in the OP? Not seeing it from my end.
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
859
First Language
German
Primarily Uses
The demo was included in the old version of the plugin, as a test function to be called. I removed it, when the plugin got moved to release.
 

Lantiz

Biterkid
Veteran
Joined
Dec 29, 2012
Messages
719
Reaction score
1,069
First Language
Portuguese
Primarily Uses
RMMV
The default callbacks only display a popup in the upper left corner (0, 0), but i included a short demo, that can be used to get a feeling of the possiblities this provides. It displays popups in the lower left corner, pushing older ones upward whenever a new popup gets displayed and has them fading out, instead of just vanishing.


Can you give me a hint on how to do this?
 

EternalShadow

Veteran
Veteran
Joined
Sep 16, 2012
Messages
5,805
Reaction score
1,051
First Language
English
Primarily Uses
I've just tried to use the script, but it isn't doing anything.


Plugin command:


IAVRA.POPUP.popup(gold, options, callbacks);


(Gold used to be "\V[23]" but that didn't do anything on its own so I put put "gold" for testing for now, and it still doesn't do anything)


The plugin is enabled.


The area it is calling works, I can get a regular textbox to show.


I also tried just:


IAVRA.POPUP.popup(gold);
 
Last edited by a moderator:

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
859
First Language
German
Primarily Uses
I will probably remake the plugin at some point (again), as it's probably a bit too generic for normal usage.
 

ramza

Lunatic Coder
Veteran
Joined
Jan 28, 2013
Messages
598
Reaction score
337
First Language
English
Primarily Uses
RMMV
I haven't seen an update on this in quite a while, and I was looking for a feature upgrade, but it doesn't look like iavra's been a round for a while so I went ahead and did it myself.

I have modded in the ability to set the x/y position on a window by window basis. There didn't seem to be a way to do this included in the original plugin, and my attempts to alias it in my own plugin to add this in were fruitless, so I modified iavra's plugin.

Here is the code:
Code:
/*:
 * @plugindesc version 1.00R Allows to display generic popups messages on the screen.
 * <Iavra Generic Popup>
 * @author Iavra, Ramza
 *
 * @param Display On Scene
 * @desc A comma-separated list of scenes where popups are allowed.
 * @default Scene_Map, Scene_Menu
 *
 * @help
 * To display a new popup, call the following function:
 *
 * IAVRA.POPUP.popup(text, options, callbacks);
 *
 * Where "text" is the text to be displayed, "options" is an optional object to override some or all of the default
 * options and "callbacks" is an optional object to override some or all of the default callbacks. Any escape characters
 * can be used inside the "text" parameter, but most will need to have their backslashes doubled.
 *
 * The following options can be specified:
 *
 * width         Width of the popup window. It's height will be autofit to its content. Default: 200
 * duration      How long the popup should be visible. The update callback can choose to ignore this value. Default: 100
 * lineHeight    Overwrite lineHeight() in Window_Base, use default if empty. Default: (empty)
 * fontName      Overwrite standardFontFace() in Window_Base, use default if empty. Default: (empty)
 * fontSize      Overwrite standardFontSize() in Window_Base, use default if empty. Default: (empty)
 * padding       Overwrite standardPadding() in Window_Base, use default if empty. Default: (empty)
 * textPadding   Overwrite textPadding() in Window_Base, use default if empty. Default: (empty)
 * backOpacity   Overwrite standardBackOpacity() in Window_Base, use default if empty. Default: (empty)
 * windowskin    Overwrite loadWindowskin() in Window_Base, use default if empty. Default: (empty)
 * xPosition     Sets the X position of the popup window
 * yPosition     Sets the Y position of the window
 * scenes        Takes an array of scene classes and overwrites the value specified in "Display On Scene".
 *
 * The following callbacks can be specified:
 *
 * init(popup)   Called after the popup has been created, but before text has been drawn on it.
 * update(popup) Called every frame. If this function returns a falsy value, the popup is removed. It has access to the
 *               popup duration and can either work with or ignore it.
 * remove(popup) Called when the popup is removed either by running out, clear() or because update() returned false.
 *
 * To clear all popups, call the following function:
 *
 * IAVRA.POPUP.clear();
 *
 * Changelog:
 * V1.00R:
 * -Added extra options to set the x/y position of the popup window
 * V1.00
 * -Initial Release
 */

var Imported = Imported || {};
Imported.iavra_generic_popup = true;

//=============================================================================
// namespace IAVRA
//=============================================================================

var IAVRA = IAVRA || {};

(function() {
    "use strict";
    
    /**
     * Since PluginManager.parameters() breaks when the plugin file is renamed, we are using our own solution.
     */
    var _params = $plugins.filter(function(p) { return p.description.contains('<Iavra Generic Popup>'); })[0].parameters;
    
    /**
     * All scenes where popups should be displayed. Whenever a scene gets active that isn't in this list, all popups
     * will be removed.
     */
    var _displayOnScene = _params['Display On Scene'].split(/\s*,\s*/).filter(function(scene) {
        return !!scene;
    }).map(function(scene) { return eval(scene); });
    
    /**
     * Default options to be used when a new popup is created. Can be overwritten for every popup by passing an object
     * containing some or all of the keys.
     */
    var _defaultOptions = {
        width: 200,
        duration: 100,
        lineHeight: undefined,
        fontName: undefined,
        fontSize: undefined,
        padding: undefined,
        textPadding: undefined,
        backOpacity: undefined,
        windowskin: undefined,
        xPosition: 0,
        yPosition: 0,
        scenes: _displayOnScene
    };
    
    /**
     * Default callbacks to be used. Can be overwritten for every popup by passing an object containing some or all of
     * the keys.
     */
    var _defaultCallbacks = {
        init: function(popup) {},
        update: function(popup) { return popup.duration-- > 0; },
        remove: function(popup) {}
    };
    
    /**
     * MV's WindowLayer has issues with windows that are overlapping each other, so we use Pixi's base class directly.
     * We declare the following methods on the container:
     * update()      Calls update() on all popups. Integrates the container in MV's engine.
     * remove(popup) Removes a popup from the container and calls its "remove()" callback, if any.
     * clear()       Removes all popups from the container and calls their "remove()" callbacks, if any.
     */
    var _container = (function($) {
    
        $.update = function() {
            this.children.forEach(function(popup) { popup.update(); });
        };
        
        $.remove = function(popup) {
            popup._callbacks.remove(popup);
            this.removeChild(popup);
        };
        
        $.clear = function() {
            this.children.forEach(function(popup) { popup._callbacks.remove(popup); });
            this.removeChildren();
        };
        
        return $;
    })(new PIXI.DisplayObjectContainer());
    
    /**
     * Utility function that takes 2 objects and iterates over all keys in the first one. If the second object contains
     * that key, its value is taken, otherwise we take the default. The result is merged to a new object and returned.
     */
    var mergeOptions = function(defaults, options) {
        options || (options = {});
        return Object.keys(defaults).reduce(function(map, key) {
            map[key] = options[key] !== undefined ? options[key] : defaults[key];
            return map;
        }, {});
    };
    
    //=============================================================================
    // module IAVRA.POPUP
    //=============================================================================
    
    IAVRA.POPUP = {
        
        /**
         * Adds a new popup with the given text to the container. "options" and "callbacks" are optional objects, that can
         * be used to overwrite the default options and callbacks.
         */
        popup: function(text, options, callbacks) {
            _container.addChild(new IAVRA.POPUP.Window_Popup(text, options, callbacks));
        },
        
        /**
         * Clears all popups, calling their "remove()" callbacks, if specified.
         */
        clear: function() {
            _container.clear();
        }
        
    };
    
    //=============================================================================
    // class IAVRA.POPUP.Window_Popup
    //=============================================================================
    
    IAVRA.POPUP.Window_Popup = function() { this.initialize.apply(this, arguments); };
    (function($) {
        ($.prototype = Object.create(Window_Base.prototype)).constructor = $;
    
        /**
         * Creates a new popup window. The given options and callbacks (if any) are merged with the default values and the
         * popup height is calculated by splitting the given text at newlines.
         */
        $.prototype.initialize = function(text, options, callbacks) {
            this._options = mergeOptions(_defaultOptions, options);
            this._callbacks = mergeOptions(_defaultCallbacks, callbacks);
            var height = this.fittingHeight(text.split('\n').length);
            Window_Base.prototype.initialize.call(this, this._options.xPosition, this._options.yPosition, this._options.width, height);
            this._callbacks.init(this);
            this.drawTextEx(text, 0, 0);
        };
        
        /**
         * Calls the update callback and decreases the popup duration by one. If either the callback returns false or the
         * duration has run out, the popup is removed. It's up to the callback to handle any kind of fading or positioning
         * needed.
         */
        $.prototype.update = function() {
            Window_Base.prototype.update.call(this);
            this._callbacks.update(this) || _container.remove(this);
        };
        
        /**
         * Accessor for the duration of the popup.
         */
        Object.defineProperty($.prototype, 'duration', {
            get: function() { return this._options.duration; },
            set: function(value) { this._options.duration = value; }
        });
        
        /**
         * Overwrite lineHeight
         */
        $.prototype.lineHeight = function() {
            return this._options.lineHeight !== undefined ? this._options.lineHeight : Window_Base.prototype.lineHeight.call(this);
        };
        
        /**
         * Overwrite standardFontFace
         */
        $.prototype.standardFontFace = function() {
            return this._options.fontName !== undefined ? this._options.fontName : Window_Base.prototype.standardFontFace.call(this);
        };
        
        /**
         * Overwrite standardFontSize
         */
        $.prototype.standardFontSize = function() {
            return this._options.fontSize !== undefined ? this._options.fontSize : Window_Base.prototype.standardFontSize.call(this);
        };
        
        /**
         * Overwrite standardPadding
         */
        $.prototype.standardPadding = function() {
            return this._options.padding !== undefined ? this._options.padding : Window_Base.prototype.standardPadding.call(this);
        };
        
        /**
         * Overwrite textPadding
         */
        $.prototype.textPadding = function() {
            return this._options.textPadding !== undefined ? this._options.textPadding : Window_Base.prototype.textPadding.call(this);
        };
        
        /**
         * Overwrite standardBackOpacity
         */
        $.prototype.standardBackOpacity = function() {
            return this._options.backOpacity !== undefined ? this._options.backOpacity : Window_Base.prototype.standardBackOpacity.call(this);
        };
        
        /**
         * Overwrite loadWindowskin
         */
        $.prototype.loadWindowskin = function() {
            if(this._options.windowskin !== undefined) {
                this.windowskin = ImageManager.load(this._options.windowskin);
            } else {
                Window_Base.prototype.loadWindowskin.call(this);
            }
        };
        
        return $;
    })(IAVRA.POPUP.Window_Popup);
    
    //=============================================================================
    // class Scene_Base
    //=============================================================================
    
    (function($) {
        
        /**
         * Registering our container in every scene, on top of regular windows.
         */
        var _alias_createWindowLayer = $.prototype.createWindowLayer;
        $.prototype.createWindowLayer = function() {
            _alias_createWindowLayer.apply(this, arguments);
            this.addChild(_container);
        };
        
        /**
         * When terminating the scene, we remove all popups, that shouldn't be displayed on the next scene.
         */
        var _alias_terminate = $.prototype.terminate;
        $.prototype.terminate = function() {
            _alias_terminate.apply(this, arguments);
            _container.children.forEach(function(popup) {
                popup._options.scenes.some(function(scene) { return SceneManager.isNextScene(scene); }) || _container.remove(popup);
            });
        };
        
    })(Scene_Base);
    
    //=============================================================================
    // module SceneManager
    //=============================================================================
    
    (function($) {
        
        /**
         * We don't want popups to appear on background images, since they are either removed by Scene_Base.terminate() or
         * will probably fade our while the background still shows them. So we hide the container during the snapshot.
         */
        var _alias_snapForBackground = $.snapForBackground;
        $.snapForBackground = function() {
            _container.visible = false;
            _alias_snapForBackground.apply(this, arguments);
            _container.visible = true;
        };
        
    })(SceneManager);
    
})();

If this isn't alright I'll take it down.
 

Attachments

decinbr

Veteran
Veteran
Joined
Mar 20, 2015
Messages
42
Reaction score
3
First Language
brazil
Primarily Uses
I used this command "IAVRA.POPUP.popup("text", {x:40, y:200, width:100, lineHeight:20});" , but nothing happened. Help-me please
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

buinguyenhoangtho wrote on fizzly's profile.
Hello @fizzly, i would like to use your asset/ resource for my project ( is maybe commercial ). May i have your permission? Thanks you !
I have 470+ hours on RMMV but have only made a demo game, is this normal? :kaoswt: (I lose motivation a lot plus I use a 32gb laptop, so..)
I like Iron Maiden.
Benku wrote on Magnus0808's profile.
Hey man you helped me out a long time ago with a plugin i was wondering if you can help me out one more time since its literally the last thing i need help with if not is cool but id figured id ask you one more soild.
Stream will be live shortly with a guest stream! Tonight, a new guest joins~ Feel free to drop by!

Forum statistics

Threads
95,425
Messages
929,067
Members
125,660
Latest member
AphoticAmaranth
Top