Jragyn

JABS codemonkey
Veteran
Joined
Aug 14, 2012
Messages
317
Reaction score
249
First Language
English
Primarily Uses
RMMZ
This plugin, as it stands, seems to function as intended.


The purpose of it is to display (in a window in the lower right of the screen) a list of things collected, namely EXP / GP / items for a set amount of time, then they disappear.


Compared to other plugins I've made, this isn't a back-end modification or anything, its a brand new window that wasn't there before, doing things I don't think the game already does, so I was hoping that I could get some random people like you guys to give it a whirl and let me know your feedback on it from both "how it looks to the end-user" to "how the code looks to a programmer".


I ask for this mostly because I have questions about how to accomplish other things, but I figured first I would see what the community thought of how it is in the current state. I laced it with as many comments as I could think of to write, for the most part, so hopefully my logic makes sense.


NOTE: It was designed to be used with an ABS (I made it to work in tandem with qABS, but I imagine it would work with any based on how it was designed, and also work entirely without), but to see things show up, you should be able to just... use event commands to give yourself XP/GP/items and see it in the window. I think. Yep.


I have a copy of it on my pastebin, but I'll leave it here in a spoiler too for those that are sketched out by pastebin:

Code:
/* -------------------------------------------------------------------------- */
// J_RecordWindow
// V: 1.0
//

/*:@plugindesc This plugin creates a window that acts as a log for EXP/GOLD/items acquired.
@author J

@help The window here is primarily for use with on-the-map battling. 
      It acts as an alternative to the innate "popup" functionality
      of the existing qABS which to me, felt very barebones and
      kind ugly-looking.

      The main way the plugin works, is that there is a queue of
      things that the window draws. The window stalls for X frames
      (120 by default, so 2 seconds), then starts deleting things
      out of the queue, oldest first, on 1 second intervals. Whenever
      something is added to the queue, the stall timer of 120 frames
      is reset. This repeats until all items are emptied from the
      queue.

      NOTE:
      This plugin draws in the EXP earned either via events or from
      defeating enemies. Note: negative parameters such as losing
      EXP / gold / items will be displayed as "gained -x stuff"
      because it was designed that way. I'm sure you could modify
      the switch with the text if you wanted to make it accommodate
      both negative and positive experiences with exp/gold/items.

      As a person relatively new to writing code for use by others,
      I left a crap-ton of comments all throughout the code if you
      are interested in understanding how it works. If you want to
      optimize it, feel free, but be sure to let me know what you
      did so I can learn how too! :)

      This plugin has no dependencies. 
      Just use as-is.

@param w_width
@desc Window width of the record box.
@default 400

@param w_height
@desc Window height of the record box.
@default 196

@param stallMod
@desc The time in frames (60 frames = 1 second, roughly) before stuff starts disappearing
@default 120

*/
(function() { // start plugin.
/* -------------------------------------------------------------------------- */
var pluginParams = PluginManager.parameters('J_RecordWindow');
var J = J || {}; J.Records = J.Records || {};

J.Records.winWidth = Number(pluginParams['w_width']) || 400; // wide enough for most things
J.Records.winHeight = Number(pluginParams['w_height']) || 196; // enough for 5 lines
J.Records.stallMod = Number(pluginParams['stallMod']) || 120; // 2 second stall

  // draws the _recordWindow onto the map in the lower right corner.
  // this window acts as a record window for all items/exp/gold acquired.
  // it does this by "catching" 4 methods that track these parameters
  // and displays them to the window for a set amount of time.
  Scene_Map.prototype.createRecordBox = function() {
    var wx = Graphics.width - J.Records.winWidth;
    var hy = Graphics.height - J.Records.winHeight;
    if (this._recordWindow) {
      this._recordWindow.update;
    }
    else {
      this._recordWindow = new Window_Record(wx, hy, J.Records.winWidth, J.Records.winHeight);
      this.addWindow(this._recordWindow);
    };
  };

  // latches into the update of the map
  // this permits continuous updating of the _recordWindow
  var _Scene_Map_jrw_update = Scene_Map.prototype.update;
  Scene_Map.prototype.update = function() {
    this.createRecordBox();
    _Scene_Map_jrw_update.call(this);
  };//update

  var _Scene_Map_jrw_stop = Scene_Map.prototype.stop;
  Scene_Map.prototype.stop = function() {
    this._recordWindow.close();
    _Scene_Map_jrw_stop.call(this);
  };
/* -------------------------------------------------------------------------- */
  // latches into the .gainExp function
  // pushes a message into _recordWindow queue for updating
  var _Game_Actor_jrw_gainExp = Game_Actor.prototype.gainExp;
  Game_Actor.prototype.gainExp = function(exp) {
    _Game_Actor_jrw_gainExp.call(this, exp);
    var scene = SceneManager._scene;
    var e = new Record_Item(exp, 1);
    if (scene.constructor == Scene_Map) {
      scene._recordWindow.addItem(e);
    }
  };

  // latches into the event command of experience gained
  // pushes a message into _recordWindow queue for updating
  var _Game_Interpreter_jrw_command315 = Game_Interpreter.prototype.command315;
  Game_Interpreter.prototype.command315 = function() {
    _Game_Interpreter_jrw_command315.call(this);
    var scene = SceneManager._scene;
    var e = new Record_Item(this._params[4], 1);
    if (scene.constructor == Scene_Map) {
      scene._recordWindow.addItem(e);
    }
    return true;
  };

  // latches into the .gainGold function
  // pushes a message into _recordWindow queue for updating
  var _Game_Party_jrw_gainGold = Game_Party.prototype.gainGold;
  Game_Party.prototype.gainGold = function(amount) {
    _Game_Party_jrw_gainGold.call(this, amount);
    var scene = SceneManager._scene;
    var g = new Record_Item(amount, 2);
    if (scene.constructor == Scene_Map) {
      scene._recordWindow.addItem(g);
    }
  };

  // latches into the .gainItem function
  // pushes a message into _recordWindow queue for updating
  // the details of what the "item" properties are were
  // gotten from the F1 help menu under the JS Library at the bottom
  var _Game_Party_jrw_gainItem = Game_Party.prototype.gainItem;
  Game_Party.prototype.gainItem = function(item, amount, includeEquip) {
    _Game_Party_jrw_gainItem.call(this, item, amount, includeEquip);
    var scene = SceneManager._scene;
    if (item != null) { // this check is necessary to prevent errors in Scene_Equip
      var i = new Record_Item(item.name, 0, item.iconIndex);
      if (scene.constructor == Scene_Map) {
        scene._recordWindow.addItem(i);
      }
    }
  };

/* -------------------------------------------------------------------------- */
  // the creation function:
  // mimics the setup of a window like all other windows.
  function Window_Record() { this.initialize.apply(this, arguments); };
  Window_Record.prototype = Object.create(Window_Base.prototype);
  Window_Record.prototype.constructor = Window_Record;

  // the initialization function:
  // things that need to happen only once happen here
  // like setting up variables
  Window_Record.prototype.initialize = function(x, y, width, height) {
    Window_Base.prototype.initialize.call(this, x, y, width, height);
    this._list = [];
    this._stall = 120;
    this.refresh(); // refresh window contients.
    this.activate(); // *@active = true
  };

  // the update function:
  // things that need to be updated every frame happen here.
  Window_Record.prototype.update = function() {
    Window_Base.prototype.update.call(this); // *super()
    this.refresh();
    // do things once per frame here
  };

  // the refresh function:
  // things that need to be drawn to the window will happen here.
  Window_Record.prototype.refresh = function() {
    if (this.contents) {
      this.contents.clear();
      // draw things to the window here
      this.updateItems();
    }
  };

  // function for adding an item to the window
  // adds new item at end of list
  // also resets the stall time back to 3seconds
  Window_Record.prototype.addItem = function(record) {
    this._stall = 120;
    this.contentsOpacity = 255;
    this._list.push(record);
  };

  // function for deleting an item from the window
  // removes the item at 0 index.
  Window_Record.prototype.RemoveItem = function() {
    this.contentsOpacity = 255;
    this._list.shift();
  };

  // function for updating all items in the window
  Window_Record.prototype.updateItems = function() {
    this.contents.fontSize = 18;
    var lh = this.lineHeight() - 4; // should be 36 - 4 = 32.

    if (this._list.length > 0) { // confirms the queue has contents
      var nextItem = this._list[0]; // grabs the first item in queue
      if (this._stall >= 0) { // checks the stall counter
        this._stall--;        // if it is still there, reduces stall
      }
      else {
        if (nextItem._duration <= 0) { // if stall is passed
          this.RemoveItem(nextItem);   // remove item with no duration
        }
        else {
        nextItem._duration--;         // reduces duration of next item
        if (nextItem._duration < 10)
          this.contentsOpacity -= 25;

        }
      }
    }
    
    for (var i = 0; i < this._list.length; i++) { // iterates through each item in the queue
      var modY = lh * (i);
      var item = this._list[i];
      this.drawListItem(item, 0, modY); // draws each item in the list
    }

  };

  Window_Record.prototype.drawListItem = function(i, x, y) {
    var w = J.test_bWidth - (this.standardPadding() * 2);
    switch (i._type) {
      case 0: // for items
        this.drawIcon(i._iconIndex, x, y);
        this.drawText(i._name + " found.", x + 32, y, w);
      break;
      case 1: // for experience
        this.drawIcon(87, x, y);
        this.drawText(i._name + " experience gained.", x + 32, y, w)
      break;
      case 2: // for gold
        this.drawIcon(314, x, y);
        this.drawText(i._name +' picked up.', x + 32, y, w)
      break;
      default: break; // there shouldn't be a need default case
    }
  };
/* -------------------------------------------------------------------------- */
// type 0 = item
// type 1 = exp
// type 2 = gold
// this is a constructor for all things that end up displayed
// within the log/record window.
// icon and duration are optional, EXP / GOLD have icons predefined.
// duration is set in two places: stall and duration.
Record_Item = function(name, type, icon, duration) {
  this._name = name;
  this._type = type;
  this._iconIndex = typeof icon !== 'undefined' ? icon : 0;
  this._duration = typeof duration !== 'undefined' ? duration : 60;
};

/* -------------------------------------------------------------------------- */
})(); // end plugin.
 

Latest Threads

Latest Posts

Latest Profile Posts

And today we got some insides maps from the town i posted last time.

Map044.png
Map045.png
Map046.png
Map047.png Map048.png Map049.png Map050.png
So a big bug that was on a glue trap at home is now magically not on the glue trap. This feeling of terror I'm experiencing could be a fun thing to put in my game project (not the IGMC one).
Hoping that Unite has a character generator with black hairs/lips and other features.. it is such a pain making characters without these...
Today is my dad's birthday! And he's still going strong in his retirement days!

Forum statistics

Threads
123,398
Messages
1,156,272
Members
161,853
Latest member
sxxsxx777
Top