Invert color for Face Graphic of actor's menu on Death

I'm looking for a script that invert color of actor's face when under Death state in menu.

TEBmH7l.png


Revert the colors back when actor recovered from Death state. Thank you for your time
You could do an common event that does that, youd need the reverted picture tho but should be easily enough to do with gimp or photoshop, tried it just out and works fine:
1640952331779.png


Not sure if its in VX the same but should be, its a long time since i used it.
Thank you though eventing is a bit much. (depending on # of actors)

VX/ Ace has similar event system as MV/ MZ though a script would save from a few steps.
(image editing + eventing conditions > select actor > select state + selecting graphic + if revert state)

I wonder if a script like this exists on RPG Maker
Because it's a bitmap we can only manipulate a few things.
The only option I see is changing the hue.
0 = normal
360 = normal
180 = image displayed below
1640955666542.png


Ruby:
class Window_MenuStatus < Window_Selectable
  def draw_item(index)
    actor = $game_party.members[index]
    enabled = $game_party.battle_members.include?(actor)
    rect = item_rect(index)
    draw_item_background(index)
    if actor.dead?
      draw_actor_face_hue(actor, rect.x + 1, rect.y + 1, enabled)
    else
      draw_actor_face(actor, rect.x + 1, rect.y + 1, enabled)
    end
    draw_actor_simple_status(actor, rect.x + 108, rect.y + line_height / 2)
  end
  def draw_actor_face_hue(actor, x, y, enabled = true)
    draw_face_hue(actor.face_name, actor.face_index, x, y, enabled)
  end
  def draw_face_hue(face_name, face_index, x, y, enabled = true)
    bitmap = Cache.face(face_name)
    bitmap.hue_change(180)
    rect = Rect.new(face_index % 4 * 96, face_index / 4 * 96, 96, 96)
    contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
    bitmap.dispose
  end
end
@Roninator2 Thanks for explanation.

bitmap isn't related to tilemap?

I just found a script that adds invert effect to tilemap
https://littledrago.blogspot.com/2014/02/rgss-drago-tilemap-effect.html

Not really sure if it works for bitmap.

Drago - Core Engine, contains method for invert
https://littledrago.blogspot.com/2013/07/rgss23-drago-core-engine.html

Code:
  #----------------------------------------------------------------------------
  # ● New method: invert!
  #----------------------------------------------------------------------------
  unless method_defined?(:invert!)
    def invert!
      (t_Fx = width).times do |i|
        height.times do |j|
           color = get_pixel(i, j)
           Graphics.update if (t_Fx += 1) % 10000 == 0
           set_pixel(i, j, color.invert) if color.alpha > 0
         end
      end
    end
  end

If that doesn't apply here, any way for a script to detect face graphic used and redirect to similar filename added "inv" at the end? (if under dead state)

Original file used Actor4
Under dead state Actor4inv

Actor4inv.png
Thank you though eventing is a bit much. (depending on # of actors)

VX/ Ace has similar event system as MV/ MZ though a script would save from a few steps.
(image editing + eventing conditions > select actor > select state + selecting graphic + if revert state)

I wonder if a script like this exists on RPG Maker
I think the idea is great, absolutely!
But when you want something implementing well, to say 'eventing it all is too much' is never a good answer.

It's the same as saying "I want this to work like this, but I can't be bothered doing it - is there a way to have it done for me?"

The first thing I thought was, drop all the images into one huge layer in GIMP, apply a reverse/negative filter, then use the built in guides feature to slice the image into separate ones then simply event it yourself. Little work, easily done.
@C64_Mat I'm not too familiar with rgss or handling of bitmap. Alternative suggestions are fine
Not really sure if it works for bitmap.
Draco's script added a method to perform an invert.
So with that you could do an invert like you want.

If I strip out the minimum necessary then it can be done.
Spoiler: Drago Bitmap invert
Ruby:
class Module
  #-------------------------------------------------------------------------
  # * New method: attr_sec_reader (Attr Secondary Reader)
  #-------------------------------------------------------------------------
  unless method_defined?(:attr_sec_reader)
    def attr_sec_reader(*sym)
      if (1..2) === sym.size
        module_eval("define_method(:#{sym[0]}) { @#{sym[0]} ||= #{sym[1]||0}}")
      elsif sym.size > 2
        (default = sym.pop) && sym.each {|s| attr_sec_reader(s,default)}
      end
    end
  end
  #-------------------------------------------------------------------------
  # * New method: attr_sec_accessor (Attr Secondary Accessor)
  #-------------------------------------------------------------------------
  def attr_sec_accessor(sym = nil, *args)
    (args.size > 0) | sym.nil? || args.push(0)
    (default = args.pop) && (b = [sym].concat(args).compact)
    (b).each {|a| (attr_writer(a) || 0) && attr_sec_reader(a,default)}
  end
  #-------------------------------------------------------------------------
  # * New method: alias_sec_method (Alias Secondary Method)
  #   Note : This method will create alias only if alias name is not defined
  #          and target alias is exist
  #-------------------------------------------------------------------------
  unless method_defined?(:alias_sec_method)
    private
    def alias_sec_method(sym = nil, *args)
      (args.size > 0) | sym.nil? || args.clear
      (t = args.pop) && (b = [sym].concat(args).compact).each do |a|
        c = (t == :initialize ? true : method_defined?(t))
        method_defined?(a) || (c && alias_method(a, t))
      end
    end
  end
  #-------------------------------------------------------------------------
  # * New method: redirect_method
  #-------------------------------------------------------------------------
  unless method_defined?(:redirect_method)
    private
    def redirect_method(sym = nil, *args, &block)
      (args.size > 0) | sym.nil? || args.clear
      (t = args.pop) && (b = [sym].concat(args).compact).each do |a|
        meth = "def #{a}[*args] #{t}(*args) end"
        meth.gsub!(/(['")}\](\d+)])\(\*args\)/i)  {    $1     }#'
        meth.gsub!(/\[\*args\]/i)                 { '(*args)' }
        method_defined?(a) || module_eval(meth)
      end
    end
  end
  #-------------------------------------------------------------------------
  # * New method: define_sec_method
  #   Note : This method will not defining method if method name already
  #          exist
  #-------------------------------------------------------------------------
  unless method_defined?(:define_sec_method)
    private
    def define_sec_method(sym = nil, *args, &block)
      sym && (method_defined?(s = sym.to_sym) || define_method(s,*args,&block))
    end
  end
end

class Color
  #--------------------------------------------------------------------------
  # ● Define Secondary Listing
  #--------------------------------------------------------------------------
  define_sec_method(:invert)   { set(255-red, 255-green, 255-blue, alpha)}
  #----------------------------------------------------------------------------
  # * New method: to_hex
  #----------------------------------------------------------------------------
  def to_hex
    str = [self.blue.to_i, self.green.to_i, self.red.to_i].pack("C*")
    str.inspect.gsub('\\x','')
  end
end
class << Color
  #--------------------------------------------------------------------------
  # ● Define Secondary Listing: red, green, blue, white, black... etc
  #--------------------------------------------------------------------------
  define_sec_method(:red)      {|*a| self.new(255,  0,  0,a.first||255)}
  define_sec_method(:green)    {|*a| self.new(  0,255,  0,a.first||255)}
  define_sec_method(:blue)     {|*a| self.new(  0,  0,255,a.first||255)}
  define_sec_method(:white)    {|*a| self.new(255,255,255,a.first||255)}
  define_sec_method(:purple)   {|*a| self.new(128,  0,128,a.first||255)}
  define_sec_method(:gray)     {|*a| self.new(128,128,128,a.first||255)}
  define_sec_method(:lgray)    {|*a| self.new(211,211,211,a.first||255)}
  define_sec_method(:dgray)    {|*a| self.new( 64, 64, 64,a.first||255)}
  define_sec_method(:pink)     {|*a| self.new(255,175,175,a.first||255)}
  define_sec_method(:orange)   {|*a| self.new(255,165,  0,a.first||255)}
  define_sec_method(:brown)    {|*a| self.new(128, 64,  0,a.first||255)}
  define_sec_method(:chocolate){|*a| self.new(210,105, 30,a.first||255)}
  define_sec_method(:golden)   {|*a| self.new(218,165, 32,a.first||255)}
  define_sec_method(:silver)   {|*a| self.new(192,192,192,a.first||255)}
  define_sec_method(:system)   {|*a| self.new(192,224,255,a.first||255)}
  define_sec_method(:crisis)   {|*a| self.new(255,255, 64,a.first||255)}
  define_sec_method(:knockout) {|*a| self.new(255, 64,  0,a.first||255)}
  #--------------------------------------------------------------------------
  # ● Redirect Listing: cyan, magenta, yellow, black, disabled, erase
  #--------------------------------------------------------------------------
  redirect_method :cyan,       '(red(*args).invert  )'
  redirect_method :magenta,    '(green(*args).invert)'
  redirect_method :yellow,     '(blue(*args).invert )'
  redirect_method :black,      '(white(*args).invert)'
  redirect_method :disabled,   '(black(128).invert  )'
  redirect_method :erase,      '(white(0).invert    )'
  #--------------------------------------------------------------------------
  # ● Alias method: grey, light_grey, dark_grey
  #--------------------------------------------------------------------------
  alias_sec_method :normal,    :white
  alias_sec_method :grey,      :gray
  alias_sec_method :lightgrey, :lightgray, :light_grey, :light_gray, :lgray
  alias_sec_method :darkgrey,  :darkgray,  :dark_grey,  :dark_gray,  :dgray
  #--------------------------------------------------------------------------
  # ● New method: method_missing
  #--------------------------------------------------------------------------
  def method_missing(val,*a)
    val = "#{val}".gsub(/x/i,'')
    if "#{val}".size == 6 && "#{val}".gsub(/(\d+|[a-f])/i,'')
      r = "#{val}"[0..1].hex
      g = "#{val}"[2..3].hex
      b = "#{val}"[4..5].hex
      return self.new(r,g,b,a.first||255)
    end
    text = "Undefined method #{val} for #{self.inspect}"
    raise(NoMethodError, text, caller(1))             
  end
end

class Bitmap
  alias_sec_method(:invert!,            :reversing!  )
  def invert!
    (t_Fx = width).times do |i|
      height.times do |j|
         color = get_pixel(i, j)
         Graphics.update if (t_Fx += 1) % 10000 == 0
         set_pixel(i, j, color.invert) if color.alpha > 0
       end
    end
  end
end
class Window_MenuStatus
  def draw_item(index)
    actor = $game_party.members[index]
    enabled = $game_party.battle_members.include?(actor)
    rect = item_rect(index)
    draw_item_background(index)
    if actor.dead?
      draw_actor_face_invert(actor, rect.x + 1, rect.y + 1, enabled)
    else
      draw_actor_face(actor, rect.x + 1, rect.y + 1, enabled)
    end
    draw_actor_simple_status(actor, rect.x + 108, rect.y + line_height / 2)
  end
  def draw_actor_face_invert(actor, x, y, enabled = true)
    draw_face_invert(actor.face_name, actor.face_index, x, y, enabled)
  end
  def draw_face_invert(face_name, face_index, x, y, enabled = true)
    bitmap = Cache.face(face_name).dup
    bitmap.invert!
    rect = Rect.new(face_index % 4 * 96, face_index / 4 * 96, 96, 96)
    contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
    bitmap.dispose
  end
end
1640961749344.png
Thank you!
I love how horrifying this looks.
Actually there's no such need to copy anything LittleDrago did there to cause the color inversion. It can be coded the following way:

Ruby:
# * Color Inversion Script
#   2021-12-31

# - Warning! - #
# Inverting a bitmap's colors is a time consuming process.

# * Script Calls * #

# - Invert a bitmap entirely!
# some_sprite.bitmap.invert_colors!
# - Invert a window's text colors!
# some_window.contents.invert_colors!
# - Invert a windowskin's colors! # Use a duplicate of the windowskin!
# windowskin.invert_colors!
# - Temporary Color Change
# some_color.invert
# - Permanent Color Change
# some_color.invert!

class Color
  def invert
    Color.new(255 - red, 255 - green, 255 - blue, alpha)
  end

  def invert!
    self.red = 255 - red
    self.green = 255 - green
    self.blue = 255 - blue
    self
  end
end

class Bitmap
  def invert_colors!
    width.times do |x|
      height.times do |y|
        clr = get_pixel(x, y)
        set_pixel(x, y, clr.invert)
      end
    end
  end
end

There's also a need to make a few fixes in his draw_item related methods.
First of all there's no hue involved in faces so the method should be renamed for clarification.
Second you should NOT change a bitmap's colors directly.
It's always better to work with a dup.
Why? Because bitmaps get cached by the engine.
Thus you might need to perform a color inversion every time you draw any face, no matter if the hero is dead or alive. Even if there's a slight possibility this might happen, it's better to avoid this color inversion madness from the very beginning.

(I modified the following script to use my methods names instead.)

Ruby:
class Window_MenuStatus
  def draw_item(index)
    actor = $game_party.members[index]
    enabled = $game_party.battle_members.include?(actor)
    rect = item_rect(index)
    draw_item_background(index)
    if actor.dead?
      draw_actor_face_invert(actor, rect.x + 1, rect.y + 1, enabled)
    else
      draw_actor_face(actor, rect.x + 1, rect.y + 1, enabled)
    end
    draw_actor_simple_status(actor, rect.x + 108, rect.y + line_height / 2)
  end

  def draw_actor_face_invert(actor, x, y, enabled = true)
    draw_face_invert(actor.face_name, actor.face_index, x, y, enabled)
  end

  def draw_face_invert(face_name, face_index, x, y, enabled = true)
    bitmap = Cache.face(face_name).dup
    bitmap.invert_colors!
    rect = Rect.new(face_index % 4 * 96, face_index / 4 * 96, 96, 96)
    contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
    bitmap.dispose
  end
end

Final Thoughts

Keep in mind that inverting a bitmap might actually mean that you're turning it upside down. =_=!
Plus you should NEVER redeclare a class's superclass. There's no real need for it.
@kyonides Thanks. There's obviously a lot I still need to learn.
I know you mentioned about the superclass thing before, but it seems to be standard practice for every script I've seen and I had issues once before when trying that. But this one works fine.
It's also interesting how the invert methods are so different.

I copied all of those methods from Drago's code because of all the declarations he made in the script.
I wasn't going to spend time remaking it since I wasn't sure how. So I just copied parts that it asked for when testing.

Anyways, thanks for the assist.
You (mainly anybody) better read the edits of my previous post because I further clarified why I disagreed with parts of the Window_MenuStatus changes someone, either you or LD, might have applied back then. It's important to keep in mind stuff like bitmaps getting cached by the engine...
Thread closed

Original thread: https://forums.rpgmakerweb.com/threads/invert-color-for-face-graphic-of-actors-menu-on-death.143467/