[Dev][Tips and Tricks] Chosing plugin message color.

Other plugins for extending OpenKore's functionality. This forum is only for posting new plugins and commenting on existing plugins. For support, use the Support forum.

Moderator: Moderators

Message
Author
Spherical
Human
Human
Posts: 29
Joined: 03 Jan 2013, 00:05
Noob?: No

[Dev][Tips and Tricks] Chosing plugin message color.

#1 Post by Spherical »

Image
When writing a plugin many of us (or maybe just me) would like to be able to define their own colors with which messages from their plugins are displayed. However, the current messaging system is not very conducive to this so I discovered a workaround by figuring out how control/consolecolors.txt was parsed and its values handled. Below is how to accomplish custom domains and add colors to them.

Before we get started here is a list of acceptable colors (from control/consolecolors.txt):

Code: Select all

black, darkgrey, grey, white, red, darkred, yellow, brown, green, darkgreen, cyan, darkcyan, blue, darkblue, magenta, darkmagenta, default
Now when you set up your plugin (maybe during your hook of in_game (to ensure that it colorconsole.txt has been loaded)?). Add the following:

Code: Select all

$consoleColors{<type>}{<custom domain>} = <color>;
Where:
<type> is the type of call you are using (ie message error warning debug) and
<custom domain> is the name of your custom domain (don't reuse domains already listed in colorconsole.txt).
<color> is a color from the list of colors above.

An Example:

Code: Select all

package customDomainTest;

use strict;
use Globals;
use Plugins;
use Log qw(message);

Plugins::register("colorDomainTest", "Custom Domain Test", \&on_unload, \&on_reload);

my $aiHook = Plugins::addHook('in_game', \&on_load, undef);

sub on_load {
	#This will print the message in the darkmagenta color.
	$consoleColors{'message'}{'Example'} = 'darkmagenta'; 
	message "\n[Custom Domain Test] : This is a test.\n", "Example";
}

sub on_unload {
	Plugins::delHook("AI_pre", $aiHook);
}

sub on_reload {
	&on_unload;
}
1;
This will show:
Image

Note: this will break if someone reloads consolecolors.txt