bishiba

Adept
Veteran
Joined
Apr 6, 2016
Messages
233
Reaction score
132
First Language
Swedish
Primarily Uses
N/A
So essentially exactly what the title says. I want to place these arrows at the edges of my window.
I think I could be able to create the functions for doing this by looking over the up and down arrows. But I am just confused, since if they are in the pictures... shouldn't there already be a function I can use?
1635162259865.png

Best regards,
Bishiba
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,917
Reaction score
3,153
First Language
English
Primarily Uses
RMMZ
drawRightArrow does exist, but it doesn't use the windowskin. It's for drawing the "comparison" arrow on the equip menu. Although there are left and right arrows on the graphic, there don't appear to be any functions that draw them. However, I had a similar need, so here:

JavaScript:
Window.prototype.drawLeftArrow = function(x, y, enabled) {
    this.changePaintOpacity(enabled);
    var bmp = this._windowskin;
    this.contents.blt(bmp, 96 + 24, 24 + 12, 12, 24, x, y);
    this.changePaintOpacity(true);
};

Window.prototype.drawRightArrow = function(x, y, enabled) {
    this.changePaintOpacity(enabled);
    var bmp = this._windowskin;
    this.contents.blt(bmp, 96 + 24 + 12 + 24, 24 + 12, 12, 24, x, y);
    this.changePaintOpacity(true);
};

You don't actually need "enabled" as a parameter, I only had that because I had to change the appearance of the arrow if you couldn't hit left/right.
 

bishiba

Adept
Veteran
Joined
Apr 6, 2016
Messages
233
Reaction score
132
First Language
Swedish
Primarily Uses
N/A
drawRightArrow does exist, but it doesn't use the windowskin. It's for drawing the "comparison" arrow on the equip menu. Although there are left and right arrows on the graphic, there don't appear to be any functions that draw them. However, I had a similar need, so here:

JavaScript:
Window.prototype.drawLeftArrow = function(x, y, enabled) {
    this.changePaintOpacity(enabled);
    var bmp = this._windowskin;
    this.contents.blt(bmp, 96 + 24, 24 + 12, 12, 24, x, y);
    this.changePaintOpacity(true);
};

Window.prototype.drawRightArrow = function(x, y, enabled) {
    this.changePaintOpacity(enabled);
    var bmp = this._windowskin;
    this.contents.blt(bmp, 96 + 24 + 12 + 24, 24 + 12, 12, 24, x, y);
    this.changePaintOpacity(true);
};

You don't actually need "enabled" as a parameter, I only had that because I had to change the appearance of the arrow if you couldn't hit left/right.
Thanks!
It is perfect, I made some slight changes, primarily for ease of access. You don't need to assign x or y values now and they'll go kinda where you'd expect. And I did deactivate the opacity change. I'll reactivate it if the situation occurs where it is needed :)
JavaScript:
Window.prototype.drawLeftArrow = function(x, y, enabled) {
    x = x || 0; //If x is undefined, sets it to the left edge of the window.
    y = y || this.contents.height / 2 - 12; //If y is undefined, sets it to center of window.
    //this.changePaintOpacity(enabled);
    var bmp = this._windowskin;
    this.contents.blt(bmp, 96 + 24, 24 + 12, 12, 24, x, y);
    this.changePaintOpacity(true);
};

Window.prototype.drawRightArrow = function(x, y, enabled) {
    x = x || this.contents.width - 12; //If x is undefined, sets it to the right edge of the window.
    y = y || this.contents.height / 2 - 12; //If y is undefined, sets it to center of window.
    //this.changePaintOpacity(enabled);
    var bmp = this._windowskin;
    this.contents.blt(bmp, 96 + 24 + 12 + 24, 24 + 12, 12, 24, x, y);
    this.changePaintOpacity(true);
};
I am curious, how do I bypass the safe area? The arrows should preferably be touching the edges, or be one or two pixels away from them. But at the moment they are a bit far away.
1635208756490.png
 

autodidact

Veteran
Veteran
Joined
Nov 13, 2020
Messages
73
Reaction score
52
First Language
English
Primarily Uses
RMMV
Hi,

I've been toying with windows and found this method in "rpg_windows.js".

JavaScript:
//Just rename Window_Base to the class name of your HUD window
Window_Base.prototype.standardPadding = function() {
    return 18; //smaller number means you can draw nearer the window border.
};

Overriding this method in your defined custom class window can allow you to decrease the "safe area" to extend to the edges. The problem is that this means that your face graphic and HP bar will then extend to the edges too, which means you'll want to add a margin to keep them positioned as they currently are.
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
2,976
Reaction score
2,299
First Language
EN
Primarily Uses
RMMZ
It's because you're painting them onto the contents bitmap. Instead I would consider making the arrows separate child sprites of the window, like the up/down arrows (cf rpg_core.js). E.g. (untested):
JavaScript:
(function(alias) {
  Window.prototype.createAllParts = function() {
    alias.apply(this, arguments);
    this._leftArrowSprite = new Sprite();
    this._rightArrowSprite = new Sprite();
    this.addChild(this._leftArrowSprite);
    this.addChild(this._rightArrowSprite);
  };
})(Window.prototype.createAllParts);

(function(alias) {
  Window.prototype._refreshArrows = function() {
    alias.apply(this, arguments);
    var w = this._width;
    var h = this._height;
    var p = 24;
    var q = p/2;
    this._leftArrowSprite.bitmap = this._windowskin;
    this._leftArrowSprite.anchor.x = 0.5;
    this._leftArrowSprite.anchor.y = 0.5;
    this._leftArrowSprite.setFrame(96 + 24, 24 + 12, 12, 24);   // source x, y, w, h
    this._leftArrowSprite.move(q, h/2);   // target x, y
    this._rightArrowSprite.bitmap = this._windowskin;
    this._rightArrowSprite.bitmap.anchor.x = 0.5;
    this._rightArrowSprite.bitmap.anchor.y = 0.5;
    this._rightArrowSprite.setFrame(96 + 24 + 12 + 24, 24 + 12, 12, 24);
    this._rightArrowSprite.move(w-q, h/2);
  };
})(Window.prototype._refreshArrows);

(function(alias) {
  Window.prototype._updateArrows = function() {
    alias.apply(this, arguments);
    this._leftArrowSprite.visible = this.isOpen() && this.leftArrowVisible;
    this._rightArrowSprite.visible = this.isOpen() && this.rightArrowVisible;
  };
})(Window.prototype._updateArrows);

(function(alias) {
  Window.prototype.initialize = function() {
    alias.apply(this, arguments);
    this.leftArrowVisible = false;
    this.rightArrowVisible = false;
  };
})(Window.prototype.initialize);
I just copied the windowskin coordinates directly from Trihan's post, and followed the core scripts for the rest. Feel free to use/modify it as you like~

You'd need to add some extra code to set the leftArrowVisible and rightArrowVisible properties when appropriate. You'd also need to manually code the left/right functionality for your window(s).
 

bishiba

Adept
Veteran
Joined
Apr 6, 2016
Messages
233
Reaction score
132
First Language
Swedish
Primarily Uses
N/A
Hi,

I've been toying with windows and found this method in "rpg_windows.js".

JavaScript:
//Just rename Window_Base to the class name of your HUD window
Window_Base.prototype.standardPadding = function() {
    return 18; //smaller number means you can draw nearer the window border.
};

Overriding this method in your defined custom class window can allow you to decrease the "safe area" to extend to the edges. The problem is that this means that your face graphic and HP bar will then extend to the edges too, which means you'll want to add a margin to keep them positioned as they currently are.
Thank you, this works flawlessly! :)

It's because you're painting them onto the contents bitmap. Instead I would consider making the arrows separate child sprites of the window, like the up/down arrows (cf rpg_core.js). E.g. (untested):
JavaScript:
(function(alias) {
  Window.prototype.createAllParts = function() {
    alias.apply(this, arguments);
    this._leftArrowSprite = new Sprite();
    this._rightArrowSprite = new Sprite();
    this.addChild(this._leftArrowSprite);
    this.addChild(this._rightArrowSprite);
  };
})(Window.prototype.createAllParts);

(function(alias) {
  Window.prototype._refreshArrows = function() {
    alias.apply(this, arguments);
    var w = this._width;
    var h = this._height;
    var p = 24;
    var q = p/2;
    this._leftArrowSprite.bitmap = this._windowskin;
    this._leftArrowSprite.anchor.x = 0.5;
    this._leftArrowSprite.anchor.y = 0.5;
    this._leftArrowSprite.setFrame(96 + 24, 24 + 12, 12, 24);   // source x, y, w, h
    this._leftArrowSprite.move(q, h/2);   // target x, y
    this._rightArrowSprite.bitmap = this._windowskin;
    this._rightArrowSprite.bitmap.anchor.x = 0.5;
    this._rightArrowSprite.bitmap.anchor.y = 0.5;
    this._rightArrowSprite.setFrame(96 + 24 + 12 + 24, 24 + 12, 12, 24);
    this._rightArrowSprite.move(w-q, h/2);
  };
})(Window.prototype._refreshArrows);

(function(alias) {
  Window.prototype._updateArrows = function() {
    alias.apply(this, arguments);
    this._leftArrowSprite.visible = this.isOpen() && this.leftArrowVisible;
    this._rightArrowSprite.visible = this.isOpen() && this.rightArrowVisible;
  };
})(Window.prototype._updateArrows);

(function(alias) {
  Window.prototype.initialize = function() {
    alias.apply(this, arguments);
    this.leftArrowVisible = false;
    this.rightArrowVisible = false;
  };
})(Window.prototype.initialize);
I just copied the windowskin coordinates directly from Trihan's post, and followed the core scripts for the rest. Feel free to use/modify it as you like~

You'd need to add some extra code to set the leftArrowVisible and rightArrowVisible properties when appropriate. You'd also need to manually code the left/right functionality for your window(s).
Thank you!
Sadly, it prompts me with the error below.
TypeError: Cannot set property 'bitmap' of undefined

I might put time on this part later, but it doesn't affect the plugin functionality and since @autodidact's advice worked I am very happy with it! :)

Thanks again though! :)
 

Latest Threads

Latest Profile Posts

Mod name: "[Game name] Gameplay Overhaul"
What they actually mean: "Here is a mod that makes the game harder."
I decided to reinstall one of my most favourite game of all times, Gothic 2. Time to get back to Khorinis!
So much game make... I needs to rest. The foods call.
-Casino with bunnysuit green check.png
1638563168795.png
Monday December 6th 2021 at 7PM Hawkzombie will stream A Thief's Voyage on his Twitch.

Hawkzombie Twitch

Check it out.​

Forum statistics

Threads
117,166
Messages
1,105,087
Members
153,257
Latest member
Hollowood04
Top