Ok this is extremely hard to explain. I tried to write a 100 line explanation in here, after I saw I failed I tried to create an image to better explain it which also failed http://img208.imageshack.us/img208/7383/48821020.png
It seems impossible because the complexity it extremely high. In the most raw is, I need to assign Id’s for each part of a string. Currently I can assign Id’s for a string example:
He: hey
She: Hi
He: What's up
She: Not much, you?
He: I'm fine, i'm selling a <Scale Armor> wanna buy it?
She: Next time maybe.
I can return What's up by using the function CString szText = GetTextAtLine(3); because What's up is located on the third line of the chat. Each line has an Id, the Id is the line number. Each line also has a pointer to a class named CItemElem. CItemElem holds all the information about an item.
I Locate the pointer by using the following function CItemElem *pItem = GetItemAtLineId(5), it would return the a pointer stored at map<unsigned int,CItemElem*>mItemChat where unsigned int is the line indetifier. Everytime someone talks something in chat if an item has been input at the chat a new element is inserted into the STL map with it’s line id.
CItemElem* CEditString::GetItemAtLineId( unsigned long uLine )
{
for( map<unsigned int,CItemElem*>::iterator it = m_mItemChat.begin(); it != m_mItemChat.end(); ++it )
{
if( uLine == it->first )
return( it->second );
}
return NULL;
}
So as you can see I can locate a CItemElem pointer by the line Id, but now my problem is I need to locate multiple items at the string because a max of 3 items can be input in a sentence at time:
He: Hey guys i'm selling <Scale Boots> <Wooden Sword> <Water Helmet> cool items!
Currently I can return only 1 item at a chat sentence at a time because I can locate the item by the line Id. I’ve been toasting my brain the past hours, please enlighten me how to be able to return more than one item at the same sentence Id.
Thanks a lot!
As the comments suggest, use a vector of
CItemElem*as the value in the map or, write another class that wraps it for more readability also considering the future need of adding any other type thanCItemElem. Also if string position is a required key in finding the item, then amapcan be used instead of avector. Set each string position that spans the item to the pointer to that particular item so it can be easily retrieved when you have the string position in which the mouse is over.Then use
CLineElem*in the mapm_mItemChatinstead ofCItemElem*