#==============================================================================
# ** Window_Command
#------------------------------------------------------------------------------
# This window deals with general command choices.
#==============================================================================
class Window_Command < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
# width : window width
# commands : command text string array
#--------------------------------------------------------------------------
def initialize(width, commands)
# Compute window height from command quantity
super(4, 60, width, commands.size * 32 + 32)
@item_max = commands.size
@commands = commands
self.contents = Bitmap.new(width - 32, @item_max * 32)
refresh
self.index = 0
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
for i in 0...@item_max
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
rect = Rect.new(4, 32 * index, self.contents.width - 8, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(rect, @commands[index])
end
#--------------------------------------------------------------------------
# * Disable Item
# index : item number
#--------------------------------------------------------------------------
def disable_item(index)
draw_item(index, disabled_color)
end
end
#==============================================================================
# ** Window_PlayTime
#------------------------------------------------------------------------------
# This window displays play time on the menu screen.
#==============================================================================
class Window_PlayTime < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 0, 640, 64)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.font.color = system_color
self.contents.draw_text(4, 0, 64, 32, "Time")
@total_sec = Graphics.frame_count / Graphics.frame_rate
hour = @total_sec / 60 / 60
min = @total_sec / 60 % 60
sec = @total_sec % 60
text = sprintf("%02d:%02d:%02d", hour, min, sec)
self.contents.font.color = normal_color
self.contents.draw_text(64, 0, 120, 32, text, 2)
cx = contents.text_size($data_system.words.gold).width
self.contents.font.color = normal_color
self.contents.draw_text(282, 0, 120-cx-2, 32, $game_party.gold.to_s, 2)
self.contents.font.color = system_color
self.contents.draw_text(256-cx, 0, cx, 32, $data_system.words.gold, 2)
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
if Graphics.frame_count / Graphics.frame_rate != @total_sec
refresh
end
end
end
#==============================================================================
# ** Window_MenuStatus
#------------------------------------------------------------------------------
# This window displays party member status on the menu screen.
#==============================================================================
class Window_MenuStat2 < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(chara)
super(0, 0, 446, 116)
@chara = chara
self.contents = Bitmap.new(width - 16, height - 16)
refresh
self.active = false
self.index = -1
return chara
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
@item_max = 1 #$game_party.actors.size
#for i in 0...$game_party.actors.size
x = 0
y = 0 #i * 116
actor = @chara
if actor != nil
#actor = $game_party.actors[0]
draw_actor_graphic(actor, x + 24, y + 80)
draw_actor_name(actor, x, y - 8)
#draw_actor_class(actor, x - 64, y)
draw_actor_level(actor, x, y + 32)
#draw_actor_state(actor, x + 90, y + 32)
draw_actor_exp(actor, x, y + 56)
draw_actor_hp(actor, x + 192, y + 32)
draw_actor_sp(actor, x + 192, y + 56)
else
self.contents.draw_text(width / 2, height / 2, 32, 120, "Empty")
end
end
#--------------------------------------------------------------------------
# * Cursor Rectangle Update
#--------------------------------------------------------------------------
def update_cursor_rect
if @index < 0
self.cursor_rect.empty
else
self.cursor_rect.set(0, @index * 116, self.width - 32, 96)
end
end
end
class Scene_Menu < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
# menu_index : command cursor's initial position
#--------------------------------------------------------------------------
def initialize(menu_index = 0)
@menu_index = menu_index
end
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Make command window
s1 = $data_system.words.skill
s2 = COMBO_SETUP_NAME
s3 = $data_system.words.item
s4 = $data_system.words.equip
s5 = "Status"
s6 = "Config"
s7 = "Tactics"
s8 = "Dictionary"
s9 = ""
s10 = "File"
@command_window = Window_Command.new(192, [s1, s2, s3, s4, s5, s6, s7, s8, s9, s10])
@command_window.index = @menu_index
# If number of party members is 0
if $game_party.actors.size == 0
# Disable items, skills, equipment, and status
@command_window.disable_item(0)
@command_window.disable_item(1)
@command_window.disable_item(2)
@command_window.disable_item(3)
@command_window.disable_item(4)
@command_window.disable_item(6)
end
# If save is forbidden
if $game_system.save_disabled
# Disable save
@command_window.disable_item(9)
end
# Make play time window
@playtime_window = Window_PlayTime.new
@playtime_window.x = 0
@playtime_window.y = 416
# Make steps window
#@steps_window = Window_Steps.new
#@steps_window.x = 0
#@steps_window.y = 320
# Make gold window
#@gold_window = Window_Gold.new
#@gold_window.x = 0
#@gold_window.y = 416
# Make status window
#if $game_party.actors[0] != nil
@status_window1 = Window_MenuStat2.new($game_party.actors[0])
@status_window1.x = 192
@status_window1.y = 62
@status_window1.z = @command_window.z - 10
#else
# @nilchar_window1 = Window_Nilchar.new
@status_window2 = Window_MenuStat2.new($game_party.actors[1])
@status_window2.x = 192
@status_window2.y = 62 + (118)
@status_window2.z = @command_window.z - 10
@status_window3 = Window_MenuStat2.new($game_party.actors[2])
@status_window3.x = 192
@status_window3.y = 62 + (236)
@status_window3.z = @command_window.z - 10
# Execute transition
Graphics.transition
# Main loop
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame update
update
# Abort loop if screen is changed
if $scene != self
break
end
end
# Prepare for transition
Graphics.freeze
# Dispose of windows
@command_window.dispose
@playtime_window.dispose
#@steps_window.dispose
#@gold_window.dispose
# if @status_window1.exists?
@status_window1.dispose
# else
# @nilchar_window1.dispose
# end
# if @status_window2.exists?
@status_window2.dispose
# else
# @nilchar_window2.dispose
# end
# if @status_window3.exists?
@status_window3.dispose
# else
# @nilchar_window3.dispose
# end
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Update windows
@command_window.update
@playtime_window.update
#@steps_window.update
#@gold_window.update
@status_window1.update
@status_window2.update
@status_window3.update
# If command window is active: call update_command
if @command_window.active
update_command
return
end
# If status window is active: call update_status
if @status_window1.active || @status_window2.active || @status_window2.active
update_status
return
end
end
#--------------------------------------------------------------------------
# * Frame Update (when command window is active)
#--------------------------------------------------------------------------
def update_command
# If B button was pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Switch to map screen
$scene = Scene_Map.new
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# If command other than save or end game, and party members = 0
if $game_party.actors.size == 0 and @command_window.index < 4
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Branch by command window cursor position
case @command_window.index
when 0 # item
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to item screen
$scene = Scene_Item.new
when 1 # skill
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Make status window active
@command_window.active = false
@status_window1.active = true
@status_window1.index = 0
when 2 # equipment
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Make status window active
@command_window.active = false
@status_window1.active = true
@status_window1.index = 0
when 3 # status
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Make status window active
@command_window.active = false
@status_window1.active = true
@status_window1.index = 0
when 4 # save
# If saving is forbidden
if $game_system.save_disabled
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to save screen
$scene = Scene_Save.new
when 5 # end game
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to end game screen
$scene = Scene_End.new
when 6
$game_system.se_play($data_system.decision_se)
$scene = Scene_Equimage.new
end
return
end
end
#--------------------------------------------------------------------------
# * Frame Update (when status window is active)
#--------------------------------------------------------------------------
def update_status
# If B button was pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Make command window active
@command_window.active = true
@status_window1.active = false
@status_window1.index = -1
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# Branch by command window cursor position
case @command_window.index
when 1 # skill
# If this actor's action limit is 2 or more
if $game_party.actors[@status_window.index].restriction >= 2
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to skill screen
$scene = Scene_Skill.new(@status_window.index)
when 2 # equipment
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to equipment screen
$scene = Scene_Equip.new(@status_window.index)
when 3 # status
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to status screen
$scene = Scene_Status.new(@status_window.index)
end
return
end
end
end
Here is the code I'm having issues with...
I tried changing the way in which the character's status is displayed on the main menu page, and finally got most stuff working... however I have a few issues:
1 Now that I have done this, all my menus are broken, probably due to how I rewrote the status method.
2 My message for non existing party member slots should read "Empty" in the center of the frame, but instead it is just blank.
1. Don't rewrite methods. If you need a new method, write a new method. If you want to add on to a method, alias it. If you don't want an old method, overwrite it (not the same as rewrite).
2. This would be in Window_MenuStatus, which I guess you already tried editing?
change this line:
for i in 0...$game_party.actors.size
to
for i in 0...MAX_PARTY_SIZE
, where MAX_PARTY_SIZE is the total number of slots. Then below, just do an if (i < $game_party.actors.size) then the normal stuff then an 'else' then draw_actor_name(A, x, y), where A is the ID of a blank actor whose name is "Empty". Finish it off with an 'end' to close the loop and you are done.
Much as I hate to think I wrote all that crap for the character slots over the course of 4 hours for nothing... I think I should probably just start over... or mess with some other part of the menu.
Is there a way to create an image that isn't inside a Window? I want a backdrop image for the empty space behind my Windows.
I tried just doing a bgimg = Bitmap.new('Graphics/Pictures/bmpname.png') but that just spits out all sorts of complaints. I tried placing the image in a window and making the image much larger that the window, but the window just clips it. I would use Bitmap.new(width - 1, height - 1) but I'm no sure how to assign it a file after it's been called and given parameters.
Any help with that?
Create a new object like this:
class BGImg < Sprite
def initialize(name)
super(0, 0, 640, 480)
self.contents = Bitmap.new(width, height)
self.z = 90
@bitmap = RPG::Cache.picture(name.to_s)
refresh
end
def refresh
self.contents.blt(0, 0, @bitmap, Rect.new(0, 0, 640, 480)
end
end
then in the window, just make a new object like this:
@bgimg = BGImg.new("bmpname.png")
class RPG::Item
def item_type
case @id
when [1,2,3,4,5,6,7,8,9,10,11,12] then return 1
when [17,18,19,20,21,22] then return 2
when [33] then return 3
when [23,24,25,26,27,28,29,30,31,32] then return 4
when [13,14,15,16] then return 5
else return 6
end
return 0
end
end
This is intended to separate the items into categories which will later be filtered by the CMS. Can I use the [] to encase multiple ID's as I've done here, or do I need to address each ID with a separate 'when'?
Also, can 'else' be used with 'case'?
no else, just put the line last. Right now, you have both return 6 and return 0 after everything. Just pick one. And the arrays should work, although I'm not 100% sure...
class RPG::Item
def item_type
case @id
when [1,2,3,4,5,6,7,8,9,10,11,12] then return 1
when [17,18,19,20,21,22] then return 2
when [33] then return 3
when [23,24,25,26,27,28,29,30,31,32] then return 4
when [13,14,15,16] then return 5
end
return 0
end
end
Don't think the arrays work...
Since you'd have to put in [1,2,3,4,5,6,7,8,9,10,11,12] in order to return 1.
Why don't you just do it like...
item_type_1 = [1,2,3,4,5,6,7,8,9,10,11,12]
item_type_2 = [17,18,19,20,21,22]
Etc
case $age
when 0 .. 2
"baby"
when 3 .. 6
"little child"
when 7 .. 12
"child"
when 13 .. 18
"youth"
else
"adult"
end
That is from the help file, which is why I think the arrays should work.
In any case this here does work.
class RPG::Item
def item_type
case @id
when 1,2,3,4,5,6,7,8,9,10,11,12 then return 1
when 17,18,19,20,21,22 then return 2
when 33] then return 3
when 23,24,25,26,27,28,29,30,31,32 then return 4
when 13,14,15,16 then return 5
end
return 0
end
end
Quote from: Blizzard on September 09, 2009, 12:19:40 pm
In any case this here does work.
class RPG::Item
def item_type
case @id
when 1,2,3,4,5,6,7,8,9,10,11,12 then return 1
when 17,18,19,20,21,22 then return 2
when 33 then return 3
when 23,24,25,26,27,28,29,30,31,32 then return 4
when 13,14,15,16 then return 5
end
return 0
end
end
fixed. you had
Quotewhen 33] then return 3
*slaps self* xD I've been hunting a memory leak for the last few hours until an evil bug from earlier reappeared. I'm just tired. xD
I really don't trust iterations like 0..12 and 0...100, as I have had them cause errors, and I don't know exactly how they work, or in cases of error, why they don't.
There was an error in the BGImg code that took me most of the day to figure out, but I finally did, just before my afternoon class started.
Here is the fixed code:
class BGImg < Sprite
def initialize(x, y, width, height ,name)
super(Viewport.new(x, y, width, height))
self.bitmap = Bitmap.new(640, 480)
self.z = 90
@bitmap = RPG::Cache.picture(name.to_s)
refresh
end
def refresh
self.bitmap.blt(0, 0, @bitmap, Rect.new(0, 0, 640, 480))
end
end
Thank you all for your help so far, and while I'd like to say you can all rest, I have a long way to go before my CMS does all that I want it to.
Anyway, one step at a time. I'm also learning a lot through this project. Ok, so next question, is there an underlined text function, or would I need to create one myself?
EDIT:
does anyone have the definition for "cursor_rect" ? I want to change the 'Window_Command's selection cursor to an underline beneath the text, but I'm not sure how to do that aside from replacing cursor_rect, but I don't know what is included in it, as it isn't defined in the editable scripts.
I see a few listings of "self.cursor_rect.set" but there is no "cursor_rect" defined anywhere...
I haven't tried searching for "set" because I'd assume it's defined under "cursor_rect" somewhere.
But I will shortly.
cursor_rect is a property of all windows (anything that inherits from the Window class). The help file says:
The cursor box (Rect). Sets the window's upper left corner using relative coordinates (-16, -16).
I wouldn't really mess with it, because it's related graphically to everything.
So what would you recommend in order to change what the Window_Selectable class uses for a cursor?
Just use some other object in place of cursor_rect and flail about until I stop getting errors...? Essentially write a new method that uses all the properties of cursor_rect, 'simply' by trial and error?
I don't plan on replacing all instances of cursor_rect. I just want to use a different type of selection indicator in certain windows...
I'm franken-scripting a CMS_Selectable class for those windows, essentially the same as the original, but using the new cursor... What I don't know is how to set up the cursor.
I suppose I'll just mess around with it until I see a real problem... I just have to pick a place to start.
make a method that just does whatever you want to the selected area. Have it call that method each time it updates.
To get rid of the old cursor, make a copy of the window skin except without the cursor, and change it in and out for each window.
def update_cursor_CMS
@list_item = self.contents
# If cursor position is less than 0
if @index < 0
self.cursor_rect.empty
return
end
# Get current row
row = @index / @column_max
# If current row is before top row
if row < self.top_row
# Scroll so that current row becomes top row
self.top_row = row
end
# If current row is more to back than back row
if row > self.top_row + (self.page_row_max - 1)
# Scroll so that current row becomes back row
self.top_row = row - (self.page_row_max - 1)
end
# Calculate cursor width
@cursor_width = self.width / @column_max - 32
# Calculate cursor coordinates
x = @index % @column_max * (@cursor_width + 32)
y = @index / @column_max * 32 - self.oy
# Update cursor rectangle
black = Color.new(0,0,0)
@item_width = self.contents.text_size(@commands[@index])
self.contents.fill_rect(x + 4, y + 25, @item_width.width, 4, black)
self.contents.fill_rect(x + 5, y + 26, @item_width.width - 2, 2, normal_color) # Draws your underline
end
Ok, here is my modification to the update_cursor method...
Specifically
this part is what I'm having issues with...
black = Color.new(0,0,0)
@item_width = self.contents.text_size(@commands[@index])
self.contents.fill_rect(x + 4, y + 25, @item_width.width, 4, black)
self.contents.fill_rect(x + 5, y + 26, @item_width.width - 2, 2, normal_color) # Draws your underline
end
This draws the underline at the proper size under each choice, but, it doesn't delete the new underline cursor after the selection is changed... Basically it adds a new underline for every time the selection is changed
In case you need to see it, this is the code from my Window script (placed after the Base script I posted above)
#--------------------------------------------------------------------------
# * Draw Item
# index : item number
# color : text color
#--------------------------------------------------------------------------
def draw_item(index, color)
self.contents.font.color = color
rect = Rect.new(4, (32 * index), self.contents.width - 8, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(rect, @commands[index])
@item_width = self.contents.text_size(@commands[index])
self.contents.fill_rect(Rect.new(@item_width.x,@item_width.y+26,@item_width.width,2),Color.new(0,0,0))
end
Anyone know how to remove a rectangular area from a bitmap?
EDIT: I just had an idea. I might be able to make a sprite that acts as the underline, and do away with the standard selection cursor altogether for this type of command window... I'm gonna take a short nap and think through it...
self.contents.clear is one option. or just change the color to opacity zero and fill a rectangle on top of it(this works because it's all on one layer). Color.new(0, 0, 0, 0) <- the 4th number is opacity.
Quote from: winkio on September 10, 2009, 12:54:27 pm
self.contents.clear is one option. or just change the color to opacity zero and fill a rectangle on top of it(this works because it's all on one layer). Color.new(0, 0, 0, 0) <- the 4th number is opacity.
I tried the transparent rectangle overtop as the very first thing, it didn't work.
self.contents.clear deletes my text as well... this is the problem. I forgot to mention that. Sorry, I've been messing with it for quite a while.
And just so no one misses this...
QuoteEDIT: I just had an idea. I might be able to make a sprite that acts as the underline, and do away with the standard selection cursor altogether for this type of command window... I'm gonna take a short nap and think through it...
this right here
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
its already in your code. If that is not working, then either a) you called it wrong (wrong coordinates most likely) or b) your engine is on shrooms.
Quote from: winkio on September 10, 2009, 03:43:10 pm
this right here
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
its already in your code. If that is not working, then either a) you called it wrong (wrong coordinates most likely) or b) your engine is on shrooms.
Correct, the same variables that created the underline, produced different results when my 'cursor_destroy' method used them...
So, it took me all day, but I finally figured out the magic series of fill_rect calls to make it work properly.
I shall add a picture as a sort of reward for your continued help.
(http://i86.photobucket.com/albums/k99/eremes/so3GUI.png)
(the background image I used was ripped from the PS2 game... I had one I made, but it was terrible in comparison.)
So far so good. Next I will be doing a status portrait rather than a character sprite.
Ok, new issue.
I don't even know where to start with this one:
I want my selection cursor to skip over menu items that are blank (ones that I have created with blank "" strings as placeholders for options I don't want the player to know about yet) to the next non-blank item.
The option I have that is currently blank if for an invention engine that is A: not even started yet, and B: not even supposed to be known about until a ways into the game...
EDIT: Ok... I think I fixed it actually...