[VX ACE] SHOW VARIABLES ON MAIN MENU?

Posts

Pages: 1
unity
You're magical to me.
12540
I was wondering if it's possible to have the main menu show a couple of variables above the gold counter in VX Ace (or, anywhere on the screen, really). I've seen at least one script that does this, but that one completely changes a bunch of other stuff and I don't think it'd be compatible with Yanfly's Ace Menu system, which I'm using.

If anyone knows a script that does this, it would be very much appreciated. Thanks a lot! :D
Marrend
Guardian of the Description Thread
21781
I have no idea about the Yanfly Ace Menu. However, under the default code, this is probably done as a function call Scene_Menu.start. Such as...

def start
  super
  create_command_window
  create_gold_window
  create_status_window
  # Next line is not from the default code.
  create_variable_window
end

Now, if "create_gold_window" is any indication of what you want to do...

def create_gold_window
  @gold_window = Window_Gold.new
  @gold_window.x = 0
  @gold_window.y = Graphics.height - @gold_window.height
end

...then it seems you're going to need to set up a variable that instantiates a class of Window_Base (at minimum) to get this window to display.



*Edit:
The hell? Am I actually handing out scripting advice?
unity
You're magical to me.
12540
Wow, thanks! I'll play around with that and see if I can come up with something that works. You wouldn't happen to know the code to display a variable for the player to see, would you?
All variables are stored under the $game_variable global; something like this should draw a line of text that contains a variable:

draw_text(x, y, width, line_height, $game_variable[varnum], 2)

Of course, this needs to be within the window that the line is being drawn in (and I lifted it directly from the gold window methods, with a few changes to make it less annoying.

So, at this point, it'll depend if you want it in its own window on the menu or as part of another window. If you want it in it's own window, I can pass that to you pretty quickly; if you want it in another window... well, that'll be fairly quick to do as well, you'll just have to decide which one.

In case you're wondering, this is the break down of that code line:
The draw_text functions uses the following parameters -
x - the x position of the text being drawn within the window
y - the y position of the text being drawn withing the window
width - how much horizontal space to fit the text into; if your text is too long for the space, it will be squished to fit
line_height - how much vertical space to fit the text into; I've never had it happen, but I assume it will squish the text if the space is too small
$game_varaible - the text to be drawn; it can be pretty much anything - you might need to make it $game_variable.to_s if it feeds an error; I remember it being necessary in XP, but I haven't done menu tinkering in Ace yet
2 - this is the alignment of the text; 2 in particular will right align it. If you don't provide a value, it will default to left alignment (0, I think). You can also use 0 or 1 (left or center - I'm pretty sure those're the values)
unity
You're magical to me.
12540
Wow, thanks! I'm cool with it being in the same window as the gold, if that makes it easier. Maybe something like so:

=================================
= Spirit Energy: (Variable One)
= Level Cap: (Variable Two)
= Gold: (gold amount
=================================

If that makes any sense.
Marrend
Guardian of the Description Thread
21781
So, I did a bit of digging to see what all functions were called with the default Gold_Window class. The one that draws the actual text of the gold display looks to me like the Window_Base.draw_currency function. It looks a bit like...

def draw_currency_value(value, unit, x, y, width)
  cx = text_size(unit).width
  change_color(normal_color)
  draw_text(x, y, width - cx - 2, line_height, value, 2)
  change_color(system_color)
  draw_text(x, y, width, line_height, unit, 2)
end

...that. So, I'm thinking your function would look a bit like...

def draw_currency_value(value, unit, x, y, width)
  cx = text_size(unit).width
  change_color(normal_color)
  # Spirit Energy display
  text = "Spirit: " + $game_variables[1]
  draw_text(x, y, width - cx - 2, line_height, text, 2)
  # Level cap display
  text = "Max Lvl: " + $game_variables[2]
  draw_text(x, y + line_height, width - cx - 2, line_height, text, 2)
  # Gold Display
  draw_text(x, y + line_height*2, width - cx - 2, line_height, value, 2)
  change_color(system_color)
  draw_text(x, y + line_height*2, width, line_height, unit, 2)
end

...though, to be honest, I'm not terribly confident this would display what is intended to be displayed.

*Edit:

...and this is, partly, why. Friends, let me introduce you to Window_Gold.initialize.

def initialize
  super(0, 0, window_width, fitting_height(1))
  refresh
end

The fitting_height function forces there to be one visible line of text in the window. Changing it 3 would probably help, though, I'm still not quite sure if the draw_currency_value function I wrote above would actually work.
All right, this is the script I based these edits on:
https://github.com/Archeia/YEARepo/blob/master/Menu/Ace_Menu_Engine.rb
(The normal dropbox links are down, so my assumption is this is the right one.)
Tested as working in an empty project with just the Yanfly Ace Menu Engine as a script.

This one doesn't appear to make an alterations to the gold window as it sits, which makes this so much easier to do. And thus, voila, a quick and dirty version:

class Window_Gold < Window_Base
def initialize
super(0, 0, window_width, fitting_height(3))
refresh
end

def refresh
contents.clear
draw_spirit_energy(4,0,contents.width - 8)
draw_level_cap(4,line_height,contents.width-8)
draw_currency_value(value, currency_unit, 4,line_height * 2, contents.width - 8)
end

def draw_spirit_energy(x,y,width)
change_color(system_color)
draw_text(x,y,width,line_height,"Spirit Energy")
change_color(normal_color)
draw_text(x, y, width - 2, line_height, $game_variables[1], 2)
end

def draw_level_cap(x,y,width)
change_color(system_color)
draw_text(x,y,width,line_height,"Level Cap")
change_color(normal_color)
draw_text(x, y, width - 2, line_height, $game_variables[2], 2)
end

def draw_currency_value(value, unit, x, y, width)
cx = text_size(unit).width
change_color(system_color)
draw_text(x, y, width, line_height, unit)
change_color(normal_color)
draw_text(x, y, width - 2, line_height, value, 2)
end
end

Paste below Yanfly's script but above Main and it should work. Very basic, uses Variable 1 as your Spirit Energy, Variable 2 as your Level Cap, and isn't exactly "pretty" - I wasn't sure the aesthetic you're going for. I can help clean it up a little if you'd like, but best to make sure I've got the idea of what you're doing first.

Marrend: Your version will, in fact, work with the fitting height changed. My only slight concern later being another script possibly making changes to the draw_currency_value method, which would undo all those changes (hence why I made the draw function for spirit energy and level cap into different functions - they don't need to be, it's just a modularity thing).
unity
You're magical to me.
12540
Thanks so much, Travio! This is PERFECT! :D

And thanks for your efforts as well, Marrend! You're always helping me out and I really appreciate it! ^.^
Pages: 1