Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[SOLVED]Draw text based on cursor index and switches?

I am currently working on a script i started working on a very long time ago. It is a script were the player can spend points to make the characters in the game learn different skills and increase their attributes. So basically what i'm trying to do is to create a small window that displays the cost of the skill, and the text in this window will change whenever you move the cursor to another skill. Here is the window:

Code:
#==============================================================================
# ** Window_Info_Cost
#------------------------------------------------------------------------------
#  This window is used to show information about the command window.
#==============================================================================
class Window_Info_Cost < Window_Base
def initialize
  super(0, 430, 110, 50)
  self.contents = Bitmap.new(width - 32, height - 32)
end
#--------------------------------------------------------------------------
# * Set Text
#      text  : text you want to see in the window.
#      align : alignment of the text you want to see in the window.
#--------------------------------------------------------------------------
  def set_text(text, align = 0)
    # If at least one part of text and alignment differ from last time
    if text != @text or align != @align
      # Redraw text
      self.contents.clear
      self.contents.font.color = normal_color
      text_rect = self.contents.text_size(text.to_s)
      self.contents.draw_text(0, -15, self.width, height, 'Cost:', align)
      self.contents.draw_text(50, -14, text_rect.width, height, text.to_s, align)
      @text = text
      @align = align
    end
  end
end

I've created a module in my script, and here is the important part of it:
Code:
module Skills
  # This is the cost of the skills
  Victory_Points = [0, 2, 5]
  #These are the switches.
  Switches = [8, 9, 7]
  # These are the names of the skills available to learn.
  Database_Skills = ["Fire", "Heal", "Mass Heal"]
end

If switch 8 is turned on, then the "Fire" skill will be displayed and choosable in a window, i've gotten that far. But what i can't quite figure out is how i could display the different costs(this is in the "Window_Info_Cost" window) of the skills based on if a switch is on. I only want to display the cost if the skill  is available. So let's say switch 8 is turned on, the fire skill is then available, but how do i make it display the number in Skills::Victory_Points[0] ?

And in my Scene in the update i have this line:
Code:
@window_info_cost.set_text(Skills::Victory_Points[@skill_skills.index])
(@skill_skills is the window displaying all the skills)

This will make the window draw the number in the Victory_Points array based on the cursor index in the @skill_skills window.
And everything works, except that it draws every cost. even if you go to a skill that is not available/not seen in the window. So basically what i want is to only draw the numbers in the Victory_Points array if the corresponding switch in Skills::Switches is turned on(When a switch is turned on, a skill becomes available to learn).

I hope i wasn't too confusing. and if you want me to give more information or maybe post a picture of the window(s) and show you what i mean, i'll gladly do it. Anyway, thanks for reading!

Over and out - Gando
 

poccil

Sponsor

Each selectable window derives from Window_Selectable.  That class has a method where a "help window" can be associated with a selectable window.  In your case, that help window is the info cost window. 

For convenience, put the following code in a new script section before the last one:

Code:
class Window_Selectable
  attr_accessor :help_window
end

In the scene class, use the following line of code to attach the info cost window to it (after creating both windows):

Code:
@skill_skills.help_window=@window_info_cost

Then, in the code for the skill list's class (not in the code for the scene's class), add a method called "update_help" which updates the text of the help window as the selection changes:

Code:
def update_help
 self.help_window.set_text(Skills::Victory_Points[self.index])
end

And that's it.  I hope this helps.
 
Thanks for the reply poccil, but that does pretty much the same thing as this line in my scenes update:

Code:
@window_info_cost.set_text(Skills::Victory_Points[@skill_skills.index])

I uploaded some pictures so you can see what i mean:
On this picture everything is fine. The skill "Mass Heal" is displayed because switch 7 is turned on(look in the Switches array) And the cost of the skill is also shown at the bottom left corner if the cursor index is the same as the skills index.
http://i244.photobucket.com/albums/gg9/ ... oints2.png[/img]


But in this picture, i haven't activated the switch for the first skill (the "Fire" skill) but the cost of the fire skill still comes up in the window_info_cost window in the bottom left corner. And what i would want is to only show the cost if the switch that "activates" the skill and makes it available is turned on.
http://i244.photobucket.com/albums/gg9/ ... oints1.png[/img]

If you look at this:
Code:
  Victory_Points = [0, 2, 5]
  Switches = [8, 9, 7]
  Database_Skills = ["Fire", "Heal", "Mass Heal"]

If switch 9 is turned on, the heal skill will be displayed, and if switch 7 is turned on the "Mass heal" skill will be displayed. But the cost of the skills in the Victory_Points array will be displayed even though the skills is not available. And that is the thing i want to change. So if Switch 7 is on, the Mass heal's cost will be displayed if the corsors index is the index of the "mass heal" skill.But now the cost will be displayed anyway even if the skill isn't available.

Anyways, thanks!

Over and out - Gando


EDIT:
I figured out how to solve the problem. In the Window_Info_Cost i changed this line:
Code:
def set_text(text, align = 0)

to:

Code:
def set_text(text, index, align = 0)

and then i put an if statement before the line that draws the text, like this:
Code:
      if $game_switches[Skills::Switches[index]]
        self.contents.draw_text(50, -14, text_rect.width, height, text.to_s, align)
      end

And then the last thing i did was to change the line in my Scene's update:

Code:
@window_info_cost.set_text(Skills::Victory_Points[@skill_skills.index])

To this:

Code:
@window_info_cost.set_text(Skills::Victory_Points[@skill_skills.index],@skill_skills.index)

Anyway, thanks for the help :thumb:
This topic has been resolved!

Over and out - Gando
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top