TinTin++ Mud Client The TinTin++ message board

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
TinTin++ Mud Client

Colorized Status bars

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Finished Scripts
View previous topic :: View next topic  
Author Message
compmstr



Joined: 05 Jul 2010
Posts: 17

PostPosted: Fri Jul 23, 2010 9:51 pm    Post subject: Colorized Status bars Reply with quote

There are two versions of this, one to make a colorized bar (red, yellow, and green in approximate thirds, and one to make a single white bar)

Code:

#nop takes in: total size of bar (including brackets surrounding it)
#nop          value, and max value
#function {makeBarColor}
{
   #nop %1 is bar length;
   #nop %2 is current value;
   #nop %3 is max value;
   #var gfxSize {};
   #math gfxSize {%1 - 2};
   #var gfxBar {};
   #var valueSize {};
   #math valueSize {(%2 * $gfxSize)/ %3};
   #var yellowIndex {};
   #math yellowIndex {$gfxSize / 3};
   #var greenIndex {};
   #math greenIndex {$yellowIndex + ($gfxSize / 3) + 2};
   #var padSize {};
   #math padSize {$gfxSize - $valueSize};
   #format gfxBar {<010>};
   #loop {0} {$valueSize}{cnt}
   {
      #if {$cnt == $yellowIndex}
      {
         #format gfxBar {%s<030>} {$gfxBar};
      };
      #if {$cnt == $greenIndex}
      {
         #format gfxBar {%s<020>} {$gfxBar};
      };
      #if {$cnt != $valueSize}
      {
         #format gfxBar {%s#} {$gfxBar};
      };
   }
   #loop {0} {$padSize} {cnt}
   {
      #if {$cnt != $padSize}
      {
         #format gfxBar {%s-} {$gfxBar};
      }
   }
   #format gfxBar {[%s<070>]} {$gfxBar};
   #var {result} {$gfxBar};
}

#nop single color bar;
#function makeBar
{
   #nop %1 is bar length;
   #nop %2 is current value;
   #nop %3 is max value;
   #var gfxSize {};
   #math gfxSize {%1 - 2};
   #var gfxBar {};
   #var valueSize {};
   #math valueSize {(%2 * $gfxSize)/ %3};
   #var padSize {};
   #math padSize {$gfxSize - $valueSize};
   #format gfxBar {<070>};
   #loop {0} {$valueSize}{cnt}
   {
      #if {$cnt != $valueSize}
      {
         #format gfxBar {%s#} {$gfxBar};
      }
   }
   #loop {0} {$padSize} {cnt}
   {
      #if {$cnt != $padSize}
      {
         #format gfxBar {%s-} {$gfxBar};
      }
   }
   #format gfxBar {[%s<070>]} {$gfxBar};
   #var {result} {$gfxBar};
};


Here is an example of use:
This code will display health and mana bars beside each other on the screen, as well as an exp bar along the entire screen.

Code:

#nop get the screen width
#var scrWidth {};
#unvariable scrWidth;
#var scrWidth {};
#var halfScrWidth {};
#unvariable halfScrWidth;
#var halfScrWidth {};
#format {scrWidth} {%C};
#format {halfScrWidth} {%m} {$scrWidth / 2};
#var len {};
#var barLen {};

#nop Figure out health string:;
#var healthString {HP: $vitals[hp]/$vitals[maxhp]};
#format len {%L} {$healthString};
#math barLen {$halfScrWidth - $len - 2};
#var healthString {$healthString @makeBarColor{{$barLen}
{$vitals[hp]} {$vitals[maxhp]}} };

#nop Figure out the mana string:;
#var manaString {MP: $vitals[mp]/$vitals[maxmp]};
#format len {%L} {$manaString};
#math barLen {$halfScrWidth - $len - 2};
#var manaString {$manaString @makeBarColor{{$barLen} {$vitals[mp]} {$vitals[maxmp]}} };

#nop figure out the exp bar string;
#var expString {EXP: $vitals[exp]};
#format len {%L} {$expString};
#math barLen {$scrWidth - $len - 3};
#var expString {$expString%% @makeBar{{$barLen} {$vitals[exp]} {$vitals[maxexp]}} };


#nop Output the stat bars;
#echo {{$healthString$manaString}{3}};
#echo {{$expString}{2}};


Back to top
View user's profile Send private message
Rothsdad



Joined: 13 Apr 2010
Posts: 35

PostPosted: Tue Jan 11, 2011 11:19 am    Post subject: Reply with quote

may I see ur screenshot of the status bar?
Back to top
View user's profile Send private message
stef70



Joined: 22 Jan 2010
Posts: 9

PostPosted: Wed Jan 12, 2011 4:01 pm    Post subject: My own bar functions Reply with quote

I have 2 functions to generate a scale bar. Here is the the first one that creates a single plain bar using the unicode characters U+2588 to U+258F representing a full 8/8 block to a 1/8 block. Of course, you will need a terminal and a font capable of displaying those unicode characters (The array SCALE8 provides the 8 characters encoded in UTF8).

The function takes 3 arguments: The current value, the maximal value and the length f the scale bar in characters.

Since each character can have 8 steps, a scale of n characters can show up to 8*n steps.

Code:


#unvar SCALE8
#format SCALE8[0] { };
#format SCALE8[1] {\xE2\x96\x8F};
#format SCALE8[2] {\xE2\x96\x8E};
#format SCALE8[3] {\xE2\x96\x8D};
#format SCALE8[4] {\xE2\x96\x8C};
#format SCALE8[5] {\xE2\x96\x8B};
#format SCALE8[6] {\xE2\x96\x8A};
#format SCALE8[7] {\xE2\x96\x89};
#format SCALE8[8] {\xE2\x96\x88};

#function {scale} {
  #var scale1 {%1};          #nop scale value  ; 
  #var scale2 {%2};          #nop scale max value  ;
  #var scaleC {%3};          #nop number of characters in scale ; 
  #math scaleM {$scaleC*8};  #nop scale0 = number of characters in scale ; 
  #math scale3 {(%1*$scaleM)/%2};
  #if {$scale3>$scaleM} {#var scale3 $scaleM}; 
  #if {$scale3<0}       {#var scale3 0}; 
  #var result {} ;
  #loop 1 $scaleC loop {
    #if {$scale3>=8} {
      #var scale4 8;
    }{
      #var scale4 $scale3;
    }
    #math scale3 {$scale3-$scale4};
    #format result {%s%s} {$result} {$SCALE8[$scale4]};
  }
} ;



The following command shows the 65 possible outputs of a scale of 8 characters:
Code:
   
#loop 0 64 x { #echo @scale{{$x} {64} 8 } }


Here is a screenshot showing several white versions of that scale. The scales in my tatus bar also use that function.
[img]
http://www.chauveau-central.net/pub/tt1.png
[/img]
Back to top
View user's profile Send private message
stef70



Joined: 22 Jan 2010
Posts: 9

PostPosted: Wed Jan 12, 2011 4:20 pm    Post subject: Reply with quote

My second scale bar function requires a terminal supporting the XTERM 256color extension.

The bar length is hard coded to 10 characters but it uses a nice gradient of colors.

Code:


#unvar SCALE10
#var SCALE10[0]  {----------}
#var SCALE10[1]  {<fbb>o<088>---------}
#var SCALE10[2]  {<fbb>o<fcb>o<088>--------}
#var SCALE10[3]  {<fbb>o<fcb>o<fdb>o<088>-------}
#var SCALE10[4]  {<fbb>o<fcb>o<fdb>o<feb>o<088>------}
#var SCALE10[5]  {<fbb>o<fcb>o<fdb>o<feb>o<ffb>o<088>-----}
#var SCALE10[6]  {<fbb>o<fcb>o<fdb>o<feb>o<ffb>o<efb>o<088>----}
#var SCALE10[7]  {<fbb>o<fcb>o<fdb>o<feb>o<ffb>o<efb>o<dfb>o<088>---}
#var SCALE10[8]  {<fbb>o<fcb>o<fdb>o<feb>o<ffb>o<efb>o<dfb>o<cfb>o<088>--}
#var SCALE10[9]  {<fbb>o<fcb>o<fdb>o<feb>o<ffb>o<efb>o<dfb>o<cfb>o<bfb>o<088>-}
#var SCALE10[10] {<fbb>o<fcb>o<fdb>o<feb>o<ffb>o<efb>o<dfb>o<cfb>o<bfb>o<afb>o<088>}


#function {scale2} {
  #var scale1 {%1};
  #var scale2 {%2};
  #math scale3 {((%1*100)/%2+5)/10};
  #if {$scale3>10} {#var scale3 10}; 
  #if {$scale3<0}  {#var scale3 0}; 
  #var result $SCALE10[$scale3];
} ;



Here are two commands to display all possible steps in regular and bold fonts
Code:

#loop 0 10 x { #echo @scale2{{$x} {10}} }
#loop 0 10 x { #echo <188>@scale2{{$x} {10}} }



And a screenshot
[img]
http://www.chauveau-central.net/pub/tt2.png
[/img]
Back to top
View user's profile Send private message
tangobravo



Joined: 02 Jan 2010
Posts: 37
Location: TorilMUD

PostPosted: Thu Jan 13, 2011 1:07 pm    Post subject: Reply with quote

Hey Stef70 --

Nice looking status bars! Just curious -- which terminal were you using when you took those screenshots?
Back to top
View user's profile Send private message
stef70



Joined: 22 Jan 2010
Posts: 9

PostPosted: Thu Jan 13, 2011 4:05 pm    Post subject: Reply with quote

That is the standard Gnome Terminal
The term is split using tmux.
The bottom right map is provided by the mud (Aardwolf)
Back to top
View user's profile Send private message
tangobravo



Joined: 02 Jan 2010
Posts: 37
Location: TorilMUD

PostPosted: Thu Jan 13, 2011 5:44 pm    Post subject: Reply with quote

Thanks, Stef70... was guessing Tmux, because I noticed you were in Ubuntu (Hardy or Jaunty, I'm guessing?) and GnuScreen never seemed to handle the drawing of the split characters with lines vs ascii-ish chars... The terminal just didn't quite look like the standard profile of the gnome-terminal that shipped with any version of Ubuntu I could recall =) That's why I was curious...

Hmm... Keep meaning to start a thread for folks to show off they're "setups"... I consider mine pretty solid, but love seeing others, and getting ideas from them, to be sure...

Thanks again!
Back to top
View user's profile Send private message
blkno1



Joined: 03 Dec 2007
Posts: 107

PostPosted: Sat Jan 15, 2011 7:33 am    Post subject: Reply with quote

This look really cool. Trying to convert it to my mud. What vars are manually set and what ones need to be grabbed from the mud? I've been trying to stare and compare, and figuring it out, but to no avail.
Back to top
View user's profile Send private message Yahoo Messenger
rtfm13



Joined: 26 Jun 2010
Posts: 12

PostPosted: Wed Oct 19, 2011 1:01 am    Post subject: Reply with quote

In regards to stef70's code, I'm really fascinated with the 'scale' function using UTF-8 glyphs. But the function is giving me bars that are "longer" than they should be. The code looks alright to me. TT tells me I'm trying to make my prompt longer than the row width. With a console width of 72 ascii chars, and passing a value of 32 ascii chars to the 'scale' function ($scaleC), TT says the prompt is something like 96 chars long. The scale is the only thing I'm drawing to the prompt line. It sounds like a strlen() call with wide characters to me, but I'm not familiar with the TT++ code whatsoever. I'll dig around in the source tomorrow, maybe? Any ideas?

Edit: I'm using Lucida Sans Mono distributed with Debian 6 in plain-ol' xterm. Maybe the locale settings are making a mess of it? ugh
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3459

PostPosted: Wed Oct 19, 2011 5:03 pm    Post subject: Reply with quote

I updated the beta with a fix that should fix this.

Be sure to set: #config CHARSET UTF-8
Back to top
View user's profile Send private message Send e-mail
rtfm13



Joined: 26 Jun 2010
Posts: 12

PostPosted: Wed Oct 19, 2011 11:16 pm    Post subject: Reply with quote

Fix confirmed with Lucida Sans Mono on xterm, Debian 6.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Finished Scripts All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads
TinTin++ Homepage

Powered by phpBB © 2001, 2002 phpBB Group