Scapoot
Member
|
Chatbox Messages Multiple Color's
hey everyone... I'm trying to make my chat into multiple colors for different items..
For Example... The username is always red, the guild is always turq, and the msg is always white.
This is the code I have to add the chat msg line to the chatbox.
Code:
Chat.New(ChrData.name + "<" + ChrData.guildName + " Guild>: " + chatMessage + "");
I tried doing this
Code:
Chat.tds.color=RED;
Chat.New(ChrData.name);
Chat.tds.color=TURQ;
Chat.New(S + "<" + ChrData.tribeName + " Tribe>: " + chatMessage + "");
But that would move the message into a new line seperate from the players username, and it would also paint all messages TURQ and leave no RED.
Any ideas?
|
|
12-26-2011 02:50 AM |
|
TBJokers
Member
|
RE: Chatbox Messages Multiple Color's
Oh Hai scapoot! Long time no seen o.o
Anyways, You could do it Chat.new(S +"<" + ChrData.tribename + " Tribe>: " + chatMessage + "").tds.color=TURQ;
I guess that would work..?
Man, it's always that semicolon...
|
|
12-26-2011 05:41 AM |
|
PsychoBoy
Member
|
RE: Chatbox Messages Multiple Color's
There are plenty of ways to do that, for example add Str user to Chatmessage struct and draw it separately:
Code:
void ChatMessage::draw(TextDS &tds, Vec2 &box_top_left, Flt box_width, Flt margin)
{
Rect_LU rect(box_top_left+Vec2(0, -y_min), box_width, height);
rect.draw(background);
rect.min.x+=margin;
tds.color = RED;
D.text(tds, rect, "["+user+"]", AUTO_LINE_SPACE); //draw user
tds.color = TURQ;
rect.min.x+=tds.textWidth(user); //calc how many space user string takes
D.text(tds, rect, text, AUTO_LINE_SPACE); //draw text
}
(This post was last modified: 12-26-2011 06:04 PM by PsychoBoy.)
|
|
12-26-2011 06:03 PM |
|
Driklyn
Member
|
RE: Chatbox Messages Multiple Color's
Try using color codes:
Code:
"[color=F00]Username[/color] <[color=0FF]Guild/Tribe[/color]>: [color=FFF]Message[/color]"
|
|
12-26-2011 08:12 PM |
|
Scapoot
Member
|
RE: Chatbox Messages Multiple Color's
(12-26-2011 05:41 AM)TBJokers Wrote: Oh Hai scapoot! Long time no seen o.o
Anyways, You could do it Chat.new(S +"<" + ChrData.tribename + " Tribe>: " + chatMessage + "").tds.color=TURQ;
I guess that would work..?
Naw Joke, that wouldn't work because it's assigning the color for all future and past chat msgs to be TURQ in all areas.
(12-26-2011 08:12 PM)Driklyn Wrote: Try using color codes:
Code:
"[color=F00]Username[/color] <[color=0FF]Guild/Tribe[/color]>: [color=FFF]Message[/color]"
I had hope for this, but in the end it didn't work haha.
Thanks though!
(12-26-2011 06:03 PM)PsychoBoy Wrote: There are plenty of ways to do that, for example add Str user to Chatmessage struct and draw it separately:
Code:
void ChatMessage::draw(TextDS &tds, Vec2 &box_top_left, Flt box_width, Flt margin)
{
Rect_LU rect(box_top_left+Vec2(0, -y_min), box_width, height);
rect.draw(background);
rect.min.x+=margin;
tds.color = RED;
D.text(tds, rect, "["+user+"]", AUTO_LINE_SPACE); //draw user
tds.color = TURQ;
rect.min.x+=tds.textWidth(user); //calc how many space user string takes
D.text(tds, rect, text, AUTO_LINE_SPACE); //draw text
}
Yay, that worked perfectly ^^!
Thanks!
|
|
12-27-2011 04:09 AM |
|
Driklyn
Member
|
RE: Chatbox Messages Multiple Color's
^^ Won't that solution cause problems if the text spans multiple lines?
I guess color codes don't work with D.text(), you will need to use Text class instead.
|
|
12-27-2011 06:56 AM |
|
Skykill
Member
|
RE: Chatbox Messages Multiple Color's
Yes, multiple colors don't work with TextDS, you need to use Text with color code in the message.
Here is how i do :
Code:
void ConsoleMessage::draw(TextDS &tds, C Vec2 &box_top_left, flt box_width, flt margin, GuiPC &gpc)
{
Rect_LU rect(box_top_left+Vec2(0,-y_min), box_width, height);
rect.draw(background);
rect.min.x+=margin;
//If no color argument is set and we want to have colors on some words of the message
if (color == WHITE)
{
//We use Text instead of TextDS because with that we can set custom colors where we want :p
gpc.offset = Vec2(0, 0);
Text t;
t.create(rect, text, &tds);
t.auto_line = AUTO_LINE_SPACE_SPLIT;
//Needed for use custom code in the message
t.code(text);
t.draw(gpc);
}
//If a color argument is set and we want to have color on the whole message
else
{
TextDS t=tds; t.color=color; D.text(t, rect, text, AUTO_LINE_SPACE_SPLIT);
}
}
(This post was last modified: 12-27-2011 07:09 AM by Skykill.)
|
|
12-27-2011 07:09 AM |
|