Error in drawing numbers

Status
Not open for further replies.

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
I have a small script by Mithran which I have to post here as there is no thread for it, and it doesn't show up in his posting activity.
Code:
# add xparams to equip status window
# example script by Mithran at forums.rpgmakerweb.com
# Terms of Use: use as you see fit (learn, edit, repost, commercial allowed)
module Vocab
  XPARAM = # xparam terms
  ["HIT", # 0 HIT  HIT rate
  "EVA", # 1 EVA  EVAsion rate
  "CRI",# 2 CRI  CRItical rate
  "CEV", # 3 CEV  Critical EVasion rate
  "MEV",  # 4 MEV  Magic EVasion rate
  "MRF",# 5 MRF  Magic ReFlection rate
  "CNT", # 6 CNT  CouNTer attack rate
  "HRG",# 7 HRG  Hp ReGeneration rate
  "MRG", # 8 MRG  Mp ReGeneration rate
  "TRG",# 9 TRG  Tp ReGeneration rate
  ]
  def self.xparam(param_id)
    XPARAM[param_id]
  end
end

class Window_EquipStatus
  XPARAM_DISPLAY_MULT = true # if true, multiply xparam as %
  FONT_SIZE = 21 # font point size of this window
  SKIP_XPARAMS = [7, 8] # skip drawing these xparams
  alias initialize_setfont initialize
  # making a copy of the origina method so it can be used in the redefinition
  def initialize(*args)
    initialize_setfont(*args) # calling original method
    if FONT_SIZE
      contents.font.size = FONT_SIZE # setting custom font size
      refresh # redrawing window
    end
  end
 
  alias refresh_drawxparam refresh
  def refresh
    refresh_drawxparam
    off = 0
    10.times {|i| # 10 times, one for each number of xparams
    if SKIP_XPARAMS.include?(i) # if this xparam is to be omitted
      off += 1 # increase offset variable so there are no gaps in drawing
      next # skip drawing and move onto the next one
    end
    draw_item_ex(0, line_height * (7 + i - off), i) # draw item calls all other draw methods
    }
  end
  
  def draw_item_ex(x, y, param_id)
    # calls all seperate draw methods, see below
    # this method basically passes the origin of where each item should be drawn
    draw_xparam_name(x + 4, y, param_id)
    draw_current_xparam(x + 94, y, param_id) if @actor
    draw_right_arrow(x + 126, y)
    draw_new_xparam(x + 150, y, param_id) if @temp_actor
  end
 
  def draw_xparam_name(x, y, param_id) # draw the parameter name
    change_color(system_color)
    draw_text(x, y, 80, line_height, Vocab.xparam(param_id))
  end
 
  def draw_current_xparam(x, y, param_id) # draw current value of xparam
    change_color(normal_color)
    text = !XPARAM_DISPLAY_MULT ? sprintf("%0.2f", @actor.xparam(param_id)) : "#{(@actor.xparam(param_id) * 100).to_i}%"
    draw_text(x, y, 32, line_height, text, 2)
  end
 
  def draw_new_xparam(x, y, param_id)
    new_value = @temp_actor.xparam(param_id)
    change_color(param_change_color(new_value - @actor.xparam(param_id)))
    text = !XPARAM_DISPLAY_MULT ? sprintf("%0.2f", new_value) : "#{(new_value * 100).to_i}%"
    # above line - get text to be drawn.  if using display mult, multiply value
    # by 100 and add a percent sign instead of displaying the decimal
    # if not, display two decimal values with a leading zero
    draw_text(x, y, 32, line_height, text, 2)
  end
 
  def window_height
    344 # default of Graphics.height minus the help window's height
    # calculating this dynamically would require redefining a few other methods
  end
 
  def line_height
    return FONT_SIZE if FONT_SIZE # if font size is set, use it for line height
    super # if not set, use the default value
  end

end

class Scene_Equip
 
  def create_item_window
    # redefining this and using math to put the item window in the correct place
    wx = @status_window.width
    wy = @slot_window.y + @slot_window.height
    ww = Graphics.width - @status_window.width
    wh = Graphics.height - wy
    @item_window = Window_EquipItemCompact.new(wx, wy, ww, wh)
    @item_window.viewport = @viewport
    @item_window.help_window = @help_window
    @item_window.status_window = @status_window
    @item_window.actor = @actor
    @item_window.set_handler(:ok,     method(:on_item_ok))
    @item_window.set_handler(:cancel, method(:on_item_cancel))
    @slot_window.item_window = @item_window
  end
end

class Window_EquipItemCompact < Window_EquipItem
  # compact version of the equip item window with one column
  def col_max
    1
  end
end

What it does is add exparams to the equip screen. It does that without a problem. However, there is something about the way the numbers are drawn that means when there are three characters (in this example "99%") the left side of the first digit is slightly cut off. Changing the size of the font does not alter this.
upload_2018-5-23_13-5-19.png


I think this can be solved by inserting a space before where the digits are actually drawn, but I have no idea whereabouts in the script that is done. (I'm making that assumption because that was the cure for a similar problem with a Yanfly script. The solution can be seen in this post.)

Can anyone tell me where to make the edit and exactly what I should do?

Thanks.
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,522
Reaction score
14,255
First Language
English
Primarily Uses
RMVXA
It looks like it is not allocating enough space for the numbers. You may need to tweak the numbers in these lines:

draw_current_xparam(x + 94, y, param_id) if @actor
draw_right_arrow(x + 126, y)
draw_new_xparam(x + 150, y, param_id) if @temp_actor

Try replacing 94 with say 78, 126 with 118 and 150 with 144. See if that helps.
 
  • Like
Reactions: Kes

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
@bgillisp That moves the whole column left, but still leaves the numbers clipped.
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,522
Reaction score
14,255
First Language
English
Primarily Uses
RMVXA
Ok, so it is somewhere else that is setting number size. I'll have to look more.

Edit: Ok, it is this code which draws the text, the previous code just states where to draw it. So some kind of edit is needed here:

def draw_current_xparam(x, y, param_id) # draw current value of xparam
change_color(normal_color)
text = !XPARAM_DISPLAY_MULT ? sprintf("%0.2f", @actor.xparam(param_id)) : "#{(@actor.xparam(param_id) * 100).to_i}%"
draw_text(x, y, 32, line_height, text, 2)
end

It looks to me the edit is needed on the 32. Does anything happen if we change the 32 to 40? Does it fix it, or does it just stretch it out with the same error?
 
  • Like
Reactions: Kes

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
@bgillisp I could see no discernable difference, even when I upped the edit to 50, or took it down to 24 (just as an experiment)
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,522
Reaction score
14,255
First Language
English
Primarily Uses
RMVXA
Ok, that eliminates that idea, though if it did work it would only fix the first set of numbers, not the second as those are different codes. The last idea I have is to try to edit this line in the same area:

text = !XPARAM_DISPLAY_MULT ? sprintf("%0.2f", @actor.xparam(param_id)) : "#{(@actor.xparam(param_id) * 100).to_i}%"

Try changing the sprintf("%0.2f" part to sprintf(" %0.2f" that should add a space to the front. See if that helps. And see what it does to the first column, as this code only affects that, but if it does work then we can edit the other columns too.
 
  • Like
Reactions: Kes

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
@bgillisp I had high hopes for this suggestion as it is similar to the Yanfly fix, but sadly, nope, does nothing.
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,522
Reaction score
14,255
First Language
English
Primarily Uses
RMVXA
Ok, I have to admit I'm stumped now. Sorry. I'll post more if I find another idea that might work.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
@bgillisp But your last suggestion did prompt something which is, in fact, the solution.
Further along that same line is the bit:
"#{(@actor.xparam(param_id) * 100).to_i}%"

Working on the same logic, I inserted a space so that it became
" #{ etc
And then did the same on the other instance which draws the comparison column.
Problem solved.

upload_2018-5-23_14-44-8.png

So thank you very much for directing me to that line. I can now look at my Equip Screen with an unjaundiced eye.
 

IAmJakeSauvage

Veteran
Veteran
Joined
Dec 4, 2015
Messages
417
Reaction score
671
First Language
English
Primarily Uses
RMMV
Have you tried changing the 32's on these lines? The width of the column itself looks to be about 32px - maybe that will increase it? :kaoswt2:

draw_text(x, y, 32, line_height, text, 2)

EDIT: Nevermind - you got it!
 
  • Like
Reactions: Kes

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
@IAmJakeSauvage That was bgillisp's first thought as well. But as you've seen, the solution lay elsewhere .
 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,849
Messages
1,016,981
Members
137,563
Latest member
cexojow
Top