PDA

View Full Version : Popup Window Auto Center


Akkadius
12-05-2010, 03:41 PM
Alright, I wanted to make a post for this considering I am going to be making a big cheat sheet list of plugins and I want to be able to refer to this example for this exact function since it does more than one thing, it does quite a bit for just one function.

This is the plugin usage:

###plugin::PWAutoCenter("Text to be centered in popup window", ([Send Character length to window? = 1] [Use AutoCenter based on given character length = 2]));
###If the second arguement is 2, the first arguement has to declare how many characters there are in the line you are presenting. And then it will push the
###Appropriate amount of spaces. IE plugin::PWAutoCenter(56, 2); for example

Let's say you wanted to simply center one phrase on a line into a popup window WITHOUT colors or anything fancy. Then you would do it just like it is mentioned in the other thread like this (Highlighted in Yellow)

sub EVENT_SAY{
if($text=~/hail/i){
my $TextToCenter = plugin::PWAutoCenter("This is the text I want to be centered");
my $TextToCenter2 = plugin::PWAutoCenter("2nd line to be centered");
my $TextToCenter3 = plugin::PWAutoCenter("3rd line");
my $TextToCenter4 = plugin::PWAutoCenter("4th line to be centered");
my $TextToCenter5 = plugin::PWAutoCenter("5th line to be centered, blah, blah, blah, blah, blah");
my $Indent = plugin::PWIndent();
my $Link = plugin::PWHyperLink("http://www.google.com", "Google Search it!");
my $Yel = plugin::PWColor("Yellow");
my $Blu = plugin::PWColor("Light Blue");
my $Red = plugin::PWColor("Red");
my $grn = plugin::PWColor("Forest Green");
quest::popup("Test", "$TextToCenter <br>
$Yel $TextToCenter2 </c> <br>
$Blu $TextToCenter3 </c> <br>
<br><br>
$Red $TextToCenter4 </c> <br>
$grn $TextToCenter5 </c> <br><br><br>
$Indent $Link
");
}
}

That would give you this as a result:

http://img.photobucket.com/albums/v450/Blade654/PWExample-1.jpg

Now the method above works fine, if you have pure raw text to just throw into the plugin. BUT if you want to have two different phrases or words centered together and be DIFFERENT colors, then we start to have a problem because color codes interfere with how the spaces are counted.

SO, I made an optional arguement for this function that will autogenerate spaces for you. Let me start by giving an example. Now before I begin, I must say that this may look like a pain, but really, it is SOOOO much easier than trying to format windows manually with a ton of spaces crapping up your perl script. Let me demonstrate.

I am going to start with a very basic line.

sub EVENT_SAY{
if($text=~/hail/i){
quest::popup("Test", "I am going to start with a very basic line");
}
}


http://img.photobucket.com/albums/v450/Blade654/BasicLine.jpg

Let's say I wanted to color different parts of this line. But if I were to put color codes inside of the center plugin it would throw off the centering script.

So I would do it like this, let me tell you this will be put back into the popup window, this is simply to use the character measuring part of the script.

sub EVENT_SAY{
if($text=~/hail/i){
my $TextToCenter = plugin::PWAutoCenter("I am going to start with a very basic line", 1);
quest::popup("Test", "$TextToCenter");
}
}


Notice the yellow 1 in this arguement, this tells the plugin that you want to count the amount of characters in the plugin, it will show up in your window like this:

http://img.photobucket.com/albums/v450/Blade654/Characters.jpg

Since it has given you the amount of characters, you can use that number for arguement two for the plugin. Like this:

sub EVENT_SAY{
if($text=~/hail/i){
my $Space1 = plugin::PWAutoCenter(19.4, 2);
quest::popup("Test", "$Space1 I am going to start with a very basic line");
}
}


I excluded an image of the preview above because I am limited to 4 images per post. It looks like the image below without the colors.

And now that $Space1 knows how many spaces to give the amount of characters in your line, you can now start adding your colors so it does not throw off the centering process.

sub EVENT_SAY{
if($text=~/hail/i){
my $Space1 = plugin::PWAutoCenter(19.4, 2);
my $Col1 = plugin::PWColor("Light Blue");
my $Col2 = plugin::PWColor("Gold2");
my $Col3 = plugin::PWColor("Firebrick3");
quest::popup("Test", "$Space1 $Col1 I am going to </c> $Col2 start with a </c> $Col3 very basic line </c>");
}
}



http://img.photobucket.com/albums/v450/Blade654/BasicColor.jpg

You can also skip the whole step 1 of the plugin and just start putting in a number and adding to it or subtracting to it to see immediate output in your window. It simply auto creates spaces for you which in itself can be very useful.


For more information on colors, you can find more detail of the plugin function in this post:

http://www.eqemulator.org/forums/showthread.php?t=32624

I hope this makes peoples lives much easier trying to use these cause it does and has for me.


These are available in the repository, see the sticky thread here

http://www.eqemulator.org/forums/showthread.php?t=32608