Indie Dev

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

[Scripting] Window PadIding?

Status
Not open for further replies.

LTN Games

Master Mind
Resource Team
Xy$
0.01
Okay so I been working on my HUD plugin for Sock Quest nd I'm having a small issue with some of my elements getting cut off due to an imaginary padding or something lol. I don't think it has to do with the padding of the main window considering I set it to 5. Anyways here is a screenshot of the issue, I placed my gold element to be drawn a bit beneath the actor name, and as you can see half of it is cut off for some unknown reason. It also affects the face image as well.
HudPluginBroken.png
Here is my code below, I'm not sure what it has to do with, I'm assuming the main initialize of the window, but I still don't understand why there is such a big gap below. It may be a bit messy, I hope it's not too hard to read, it's more experimental right now, sorry.

JavaScript:
//------------------------------------------------------------------------------
//LTN_SimpleHUD
//------------------------------------------------------------------------------
/*:
* @plugindesc A simple HUD displayed on the map.
*
* @author LTN Games
* @param --Window Settings--
*
* @param HUD BG Image
* @desc Select an image you want as the backgroundd for the HUD.
* @default hudbg
*
* @param HUD BG  Opacity
* @desc Chnage the opacity of the BG Image for the HUD. 0 - 255
* @default 255
*
* @param HUD X Pos
* @desc The X position on screen for the HUD
* @default 0
*
* @param HUD Y Pos
* @desc  The Y position on screen for the HUD
* @default 5
*
* @param HUD Width
* @desc The X position on screen for the HUD
* @default 350
*
* @param HUD Height
* @desc  The Y position on screen for the HUD
* @default 120
*
*/
// -
//===========================================================================
// PARAMETERS
//===========================================================================
(function() {
  var LTN = LTN || {};
  LTN.SimpleHud = LTN.SimpleHud || {};

  LTN.Parameters = PluginManager.parameters('LTN_SimpleHUD');
  LTN.Param = LTN.Param || {};
  LTN.Param.bgFilename   =  String(LTN.Parameters['HUD BG Image']);
  LTN.Param.bgOpacity    =  Number(LTN.Parameters['HUD BG  Opacity']);
  LTN.Param.hudX         =  Number(LTN.Parameters['HUD X Pos']) || 0;
  LTN.Param.hudY         =  Number(LTN.Parameters['HUD Y Pos']) || 0;
  LTN.Param.hudWidth     =  Number(LTN.Parameters['HUD Width']) || 350;
  LTN.Param.hudHeight    =  Number(LTN.Parameters['HUD Height'])|| 200;

  //===========================================================================
  // Scene Map:
  //===========================================================================
  //----------------------------------------------
  // Aliased Nethod:  Create On Map
  //------------------------------------------------------------------------------
  LTN.SimpleHUD_oldMapCreateDisplayObjects = Scene_Map.prototype.createDisplayObjects;
  //------------------------------------------------------------------------------
  Scene_Map.prototype.createDisplayObjects = function() {
    LTN.SimpleHUD_oldMapCreateDisplayObjects.call(this);
    this.createSimpleHUDWindow();
  };

  //----------------------------------------------
  // New Method: Create Simple HUD Window & add as child.
  //----------------------------------------------
  Scene_Map.prototype.createSimpleHUDWindow = function() {
    this._simpleHUDWindow = new Window_SimpleHUD();
    this.addChild(this._simpleHUDWindow);
  };
  //=============================================================================
  // New Window: Window Pop
  //=============================================================================
  function Window_SimpleHUD() {
    this.initialize.apply(this, arguments);
  }

  Window_SimpleHUD.prototype = Object.create(Window_Base.prototype);
  Window_SimpleHUD.prototype.constructor = Window_SimpleHUD;
  //-------=====---------
  //Initialize
  //-------=====---------
  Window_SimpleHUD.prototype.initialize = function(x, y, width, height) {
    var width          = LTN.Param.hudWidth;
    var height         = LTN.Param.hudHeight;
    var px             = LTN.Param.hudX;
    var py             = LTN.Param.hudY;
    Window_Base.prototype.initialize.call(this, px, py, width, height);
    this.opacity = 255;
    this.padding = 5;
    this._actor = $gameParty.members()[0];
    this.refresh();
  };
  //-------=====---------
  //Update -
  //-------=====---------
  Window_SimpleHUD.prototype.update = function() {
    if(this._actor.hp -- || this._actor.hp ++) this.refresh();
    if(this._actor.mp -- || this._actor.mp ++) this.refresh();
  };
  //-------=====---------
  //Refresh
  //-------=====---------
  Window_SimpleHUD.prototype.refresh = function() {
    this.contents.clear();
    this.drawHudElements(this._actor);
  };
  //-------=====---------
  // Draw Actor Name
  //-------=====---------
  Window_SimpleHUD.prototype.drawHudElements = function(actor) {
    if(!LTN.Param.bgFilename) this.drawBgImage();
    this.resetTextColor();
    this.drawActorName(actor, 160, 70, 60);
    this.resetTextColor();
    this.drawActorLevel(actor, 260, 70, 60);
    this.resetTextColor();
    this.drawGold(185, 100, 60);
    this.drawActorHp(actor, 160, 0, 170);
    this.drawActorMp(actor, 160, 35, 170);
    this.loadFace(actor, 0, 0, 144, 144);
  };
  //-------=====---------
  // Draw Actor Face
  //-------=====---------
  Window_SimpleHUD.prototype.loadFace = function(actor, x, y, width, height){
  if(ImageManager.isReady()){
    this.drawActorFace(actor, x, y, width, height);
  }
};
//-------=====---------
// Draw Actor Name
//-------=====---------
Window_SimpleHUD.prototype.drawActorName = function(actor, x, y, width) {
  width = width || 168;
  this.changeTextColor('white');
  this.drawText(actor.name(), x, y, width);
};
//-------=====---------
// Draw Actor Level
//-------=====---------
Window_SimpleHUD.prototype.drawActorLevel = function(actor, x, y, width) {
  width = width || 168;
  this.changeTextColor('white');
  this.drawText('Lvl' + ' ' + actor.level, x, y, width);
};
//-------=====---------
// Draw Gold
//-------=====---------
Window_SimpleHUD.prototype.drawGold = function(x, y, width) {
  var gold         = $gameParty.gold();
  var currencyUnit = TextManager.currencyUnit;
  var gX            = x;
  var gY            = y;
  var gWidth        = width;
  var gIcon         = 208;
  var gString       = gold + ' ' + currencyUnit;
  this.drawIcon(gIcon, x - 32, y);
  this.drawText(gString, gX, gY, gWidth);
};
//-------=====---------
// Draw Actor HP
//-------=====---------
Window_SimpleHUD.prototype.drawActorHp = function(actor, x, y, width){
  width = width || 186;
  var color1 = 'rgba(187, 29, 29, 255)';
  var color2 = 'rgba(164, 25, 62, 255)';
  this.drawGauge(x, y, width, actor.hpRate(), color1, color2);
  this.changeTextColor(this.systemColor());
  this.drawText(TextManager.hpA, x, y, 30);
  this.drawCurrentAndMax(actor.hp, actor.mhp, x, y, width,
    this.hpColor(actor), this.normalColor());
  };
  //-------=====---------
  // Draw Actor MMP
  //-------=====---------
  Window_SimpleHUD.prototype.drawActorMp = function(actor, x, y, width){
    width = width || 186;
    var color1 = 'rgb(14, 22, 212)';
    var color2 = 'rgb(59, 114, 236)';
    this.drawGauge(x, y, width, actor.mpRate(), color1, color2);
    this.changeTextColor(this.systemColor());
    this.drawText(TextManager.mpA, x, y, 30);
    this.drawCurrentAndMax(actor.mp, actor.mmp, x, y, width,
      this.mpColor(actor), this.normalColor());
    };
    //-------=====---------
    // Draw BG Image
    //-------=====---------
    Window_SimpleHUD.prototype.drawBgImage = function() {
      var filename  = LTN.Param.bgFilename;
      var bgOpacity = LTN.Param.bgOpacity;
      this._bgSprite1 = new Sprite(ImageManager.loadPicture(filename));
      this._bgSprite1.opacity = bgOpacity;
      this.addChildToBack(this._bgSprite1);
    };
    //-------=====---------
    // Draw Gauge
    //-------=====---------
    Window_SimpleHUD.prototype.drawGauge = function(x, y, width, rate, color1, color2) {
      var fillW = Math.floor(width * rate);
      var gaugeY = y + this.lineHeight() - 8;
      this.contents.fillRect(x, gaugeY, width, 6, this.gaugeBackColor());
      this.contents.gradientFillRect(x, gaugeY, fillW, 6, color1, color2);
    };
  })();
 

Boy Who Codes

Praised Adventurer
Xy$
0.00
It has to do with your standard padding that holds the objects drawn visually on a window. Add this into your code for example:

Code:
  Window_SimpleHUD.prototype.standardPadding = function() {
      return 0;
  };
This removes the capping for the drawn object. Make your window width to 145.
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
That worked great, thank you @Soul .
I was going to try this, but I got confused when I realized that the updatePadding() method for window_base is just setting the padding to standardPadding() method. I thought that if I put this.padding = 5; in my initialize method, it would have overwritten the standardPadding. Can you explain to me why this was not correct? Is padding being set somewhere else as well? Maybe I'm just tired, and it's right in front of me.
Anyways thank again for helping, my hud is looking much better now.
HudPluginWorking.png
 

Boy Who Codes

Praised Adventurer
Xy$
0.00
Let's see. It was placed that way in MV because it inherits anything that's on the window base. So when a window gets created, it assumes that you are using the same padding for the ones displayed on the screen, and when the window changes, the padding changes too. The reason why even if you changed the padding to 5 and still displays the same thing, because it gets inherited and updated from its base. That is the reason I had to create the same method specifically for your window so it won't get the same value from the window base.

I hope I explained it well.
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
Yes, thank you, You explained that perfectly, basically my window will inherit the standardPadding from Window_Base unless I make my own. So even though I was setting the padding, the window was still inheriting the function standardPadding and setting it to that. Seems basic enough.
 
Status
Not open for further replies.
Top