Re: User-defined colors

From: Allan Rolf Gortemaker (umgortem@CC.UMANITOBA.CA)
Date: 02/25/98


> I would be very appreciative to see how you done this one as i'm working
> on something somewhat like this, only storing preferences in files much
> like player object files.  (side note, if you do it right, no pfile wipe
> is needed :P) Anyways, i'm sorta stuck on the idea atm and some new info
> would be very handy.

Ok...I think I follow what you are doing.
Yeah, I agree it could be done without a pwipe but seeing as my mud isn't
even up yet, I didn't really care whether or not it modified the pfile.
Heck, I'd never even thought of posting code till I decided to see what
others thought about it.  Also, if I ever do make it a patch, most patches
I think are used by newbies starting their own muds so a pfile wipe wouldn't
make any difference.  But that's beside the point.  I'll try to see if I
can remember how I have it written.  (It's on my home PC.  I'm at school.)
I'm still working on this currently so its not complete yet...

In structs.h

>Replaced #define PRF_COLOR_1     (1 << 10)
>     and #define PRF_COLOR_2     (1 << 11)  // I think they are 10 and 11
>    with #define PRF_USES_COLOR  (1 << 10)
>     and #define PRF_UNUSED      (1 << 11)  // May need it later anyway

>Macros defining the slots in the array each field is located
>
>  #define COL_SAY  0 // the color of says is held in colorprefs[0]
>  #define COL_TELL 1 // the color of tells is held in colorprefs[1] etc.

>Macros giving each color a number so that it is possible to do something like
>colorprefs[COL_SAY]=COL_RED;
>
>  #define COL_BLK 0
>  #define COL_RED 1  // etc.

>In the player struct I have an array of ints holding the users preferred colors
>
>  int colorprefs[30];
>
>(30 allows more fields to be added later on if wanted without another pwipe.
> Currently only 20 or so fields are defined.)

Currently working on (when I have the time) a function that I have placed right
now in color.c.  I might move it somewhere else later if a find a more suitable
place but I figgered it was dealing with colors so I might as well put it in
the color.c file.

In color.c

> A function that takes an integer value and returns its color code
>
> char getcolor(int color)
> {
>    switch (color) {
>      case COL_BLK:
>        return (code of color black)
>      case COL_RED:
>        return (code of color red)
>      .
>      .
>      .
>      default:
>        return (default/normal color);
>    }
> }

> Could also just put all codes in a colorlist just as:
>   static char *colorlist[]= { . . . };
> then just return colorlist[color];

In act.informative.c

> changed
>   static char *ctypes[]={ "off", "normal", "sparse", "complete", "\n"};
> to
>   static char *coptions[]={ "off", "full", "\n"};

> Can't use "on" cuz do_color calls one_argument which filters out all fill
> words of which "on" is one.

> added
>   static char *cfields[]= { "say", "tell", (all allowable fields), "\n"};
> added
>   static char *ctypes[]={ "black", "red", (all allowable types), "\n"};

> changed one_argument to two_arguements (doesn't affect the above)
> This allows user to enter "color off" or "color full"
> as well as "color say red" or "color tell cyan" etc

> searches the coptions list to see if arg1 is in the list.
> if so and arg1="off" then REMOVE_BIT(PRF_FLAGS(ch), PRF_USES_COLOR);
> if arg1="full" then SET_BIT(PRF_FLAGS(ch), PRF_USES_COLOR);
> and then return;

> if arg1 not in coptions, then it searches the cfields list and gets the
> position in the list it was found at if found.  If not return an error.

> if arg1 found, search ctypes list for arg2 and get position in the list
> it was found at if found.  If not send_to_char an error and return.

> if both args valid then ch->colorprefs[fieldslot]=colorslot

And finally in utils.h

> Macros such as:
> #define GET_SAY(ch) (PRF_FLAGGED(ch, PRF_USES_COLOR) ? \
>                      ch->colorprefs[COL_SAY] : COL_NULL)

> that returns the users preferred color for a given field if they use color
> otherwise return the nul (base) color to prevent non-ansi terminals from
> flipping.

Then anywhere in the program where you have CC_RED(ch, C_ON) or something
similar you just replace with "getcolor(C_SAY)"
e.g.

  What used to be (in perform_tell)
    send_to_char(CCRED(vict, C_ON), vict);
  Is now changed to
    send_to_char(getcolor(C_TELL(vict)), vict);

So I think that's about the extent of it.  Like I said this is from what I
can remember so I may have missed something or messed something up a bit.
Hope that helps a little

Ali Baba


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST