New account registration is temporarily disabled.

SCRIPTING A "QUEUE" WINDOW IN XP

Posts

Pages: 1
So, I'm working on a combat system where control passes back and forth between the player party and the enemies (kind of like a lot of turn based strategy games, though this isn't TBS). On the player turn, they can go through their party members' attacks and abilities at their leisure, basically creating a custom queue of actions. Once they're done doing that, they chose a "done" command and then it moves into the phase where the actions are actually executed in the order that they were queued.

Functionally, I have this all working just fine. Visually, not so much. I want a queue window that shows you your queue as you build it, with a vertical list of the actions you've chosen, in the order you chose them. Unfortunately, my custom queue window class doesn't seem to display any action names beyond the first one you pick. It expands as you add items, but rather than showing the new actions names it's just empty space, like so:



That text box on the right side is supposed to be the queue. I think in this pic I've queued about 5 or 6 actions, but as you can see only the first one displays. The rest are just blank space.

Below is the script for the queue window. I've even tried printing out index numbers and action names to the console, from inside draw_item. It looks like it runs through the queue fine, and it's able to pull the names. Furthermore, the battle code I wrote seems to run through the queue and execute the skills in-game just fine. The damn window just isn't displaying properly for some reason. Any help?

Let me know if I'm not explaining myself correctly.
#==============================================================================
# ** Window_ActionQueue
#------------------------------------------------------------------------------
# This window displays queued party actions in battle
#==============================================================================

class Window_ActionQueue < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
# actor : actor
#--------------------------------------------------------------------------
def initialize(queue)
super(480, 64, 160, 0)
self.contents = Bitmap.new(width - 32, height - 32)
self.back_opacity = 160
@queue = queue
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.height = @queue.size * 32 + 32
for i in 0...@queue.size
draw_item(i, normal_color)
end
end
#--------------------------------------------------------------------------
# * Draw Item
# index : item number
# color : text color
#--------------------------------------------------------------------------
def draw_item(index, color)
self.contents.font.color = color
x = 4
y = index * 32
rect = Rect.new(x, y, self.width - 8, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
opacity = self.contents.font.color == normal_color ? 255 : 128
self.contents.draw_text(x, y, self.width - 8, 32, @queue[index].name, 0)
end
end
Where do you change @queue? As far as I can see the only way to change it is to create a new window and pass it the new queue.

(I can't run RMXP so I can't see if it is in the Window_Base class)
Before, I had it set up to where it would pass in a new version if @queue every time I changed it in the battle programming (because that's where I actually operate on it), but I found out that all you have to do is pass it in once in initialize(), and from then on if you change the queue object in the battle scene code, it changes @queue in this code as well. Basically, it seems to be treating what I pass into initialize as a pointer to the queue I made in the battle programming, rather than a new copy of it. Like I said, the length of the queue box changes appropriately when new items get added to the queue. You can see in refresh() that it changes the height based on @queue.size. The size of the box wouldn't change if it didn't know that the queue's size was changing in the battle code.

Even when I had it set up to explicitly update it, I still had the same problem of the text not appearing. So it isn't the cause or a problem. Also, @queue is something new I added, it's not in Windows_Base.
Right, arrays get passed by pointer instead of copied. (I also missed the proper-resizing part). My bad.

The problem is your bitmap. It's still at 448 x 128 when the window is initialized but it's never being resized. So when you try to draw text to it (self.contents), you're drawing off the bitmap so you never see the text show up because there's nothing there to draw on or show.
Well, that's straightforward. Thanks.
Pages: 1