Browse Source

GUI List Box items => plString

Michael Hansen 11 years ago
parent
commit
f370c65ad3
  1. 15
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.cpp
  2. 6
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.h
  3. 100
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListElement.cpp
  4. 24
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListElement.h
  5. 97
      Sources/Plasma/FeatureLib/pfPython/pyGUIControlListBox.cpp
  6. 18
      Sources/Plasma/FeatureLib/pfPython/pyGUIControlListBox.h
  7. 13
      Sources/Plasma/FeatureLib/pfPython/pyGUIControlListBoxGlue.cpp

15
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.cpp

@ -1152,23 +1152,12 @@ void pfGUIListBoxMod::ClearAllElements( void )
HandleExtendedEvent( pfGUIListBoxMod::kListCleared );
}
uint16_t pfGUIListBoxMod::AddString( const char *string )
uint16_t pfGUIListBoxMod::AddString( const plString &string )
{
return AddElement( new pfGUIListText( string ) );
}
uint16_t pfGUIListBoxMod::AddString( const wchar_t *string )
{
return AddElement( new pfGUIListText( string ) );
}
int16_t pfGUIListBoxMod::FindString( const char *toCompareTo )
{
pfGUIListText text( toCompareTo );
return FindElement( &text );
}
int16_t pfGUIListBoxMod::FindString( const wchar_t *toCompareTo )
int16_t pfGUIListBoxMod::FindString( const plString &toCompareTo )
{
pfGUIListText text( toCompareTo );
return FindElement( &text );

6
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.h

@ -186,10 +186,8 @@ class pfGUIListBoxMod : public pfGUIControlMod
uint16_t GetNumElements( void );
pfGUIListElement *GetElement( uint16_t idx );
uint16_t AddString( const char *string );
uint16_t AddString( const wchar_t *string );
int16_t FindString( const char *toCompareTo );
int16_t FindString( const wchar_t *toCompareTo );
uint16_t AddString( const plString &string );
int16_t FindString( const plString &toCompareTo );
// Export only
void SetScrollCtrl( pfGUIValueCtrl *ctrl ) { fScrollControl = ctrl; }

100
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListElement.cpp

@ -77,28 +77,14 @@ void pfGUIListElement::Write( hsStream *s, hsResMgr *mgr )
//// Constructor/Destructor //////////////////////////////////////////////////
pfGUIListText::pfGUIListText() : pfGUIListElement( kText )
pfGUIListText::pfGUIListText()
: pfGUIListElement(kText), fJustify(kLeftJustify)
{
fText = nil;
fJustify = kLeftJustify;
}
pfGUIListText::pfGUIListText( const char *text ) : pfGUIListElement( kText )
pfGUIListText::pfGUIListText( const plString &text )
: pfGUIListElement(kText), fText(text), fJustify(kLeftJustify)
{
fText = hsStringToWString(text);
fJustify = kLeftJustify;
}
pfGUIListText::pfGUIListText( const wchar_t *text ) : pfGUIListElement( kText )
{
fText = new wchar_t[ wcslen( text ) + 1 ];
wcscpy( fText, text );
fJustify = kLeftJustify;
}
pfGUIListText::~pfGUIListText()
{
delete [] fText;
}
//// Virtuals ////////////////////////////////////////////////////////////////
@ -107,18 +93,14 @@ void pfGUIListText::Read( hsStream *s, hsResMgr *mgr )
{
pfGUIListElement::Read( s, mgr );
char *text = s->ReadSafeString();
fText = hsStringToWString(text);
delete [] text;
fText = s->ReadSafeString_TEMP();
}
void pfGUIListText::Write( hsStream *s, hsResMgr *mgr )
{
pfGUIListElement::Write( s, mgr );
char *text = hsWStringToString(fText);
s->WriteSafeString(text);
delete [] text;
s->WriteSafeString(fText);
}
bool pfGUIListText::Draw( plDynamicTextMap *textGen, uint16_t x, uint16_t y, uint16_t maxWidth, uint16_t maxHeight )
@ -158,26 +140,7 @@ int pfGUIListText::CompareTo( pfGUIListElement *rightSide )
if( text->fType != kText )
return -2;
return wcscmp( GetText(), text->GetText() );
}
void pfGUIListText::SetText( const char *text )
{
wchar_t *wText = hsStringToWString(text);
SetText(wText);
delete [] wText;
}
void pfGUIListText::SetText( const wchar_t *text )
{
delete [] fText;
if( text != nil )
{
fText = new wchar_t[ wcslen( text ) + 1 ];
wcscpy( fText, text );
}
else
fText = nil;
return GetText().Compare(text->GetText());
}
void pfGUIListText::SetJustify( JustifyTypes justify )
@ -295,26 +258,14 @@ int pfGUIListPicture::CompareTo( pfGUIListElement *rightSide )
//// Constructor/Destructor //////////////////////////////////////////////////
pfGUIListTreeRoot::pfGUIListTreeRoot() : pfGUIListElement( kTreeRoot )
pfGUIListTreeRoot::pfGUIListTreeRoot()
: pfGUIListElement(kTreeRoot), fShowChildren(true)
{
fText = nil;
fShowChildren = true;
}
pfGUIListTreeRoot::pfGUIListTreeRoot( const char *text ) : pfGUIListElement( kTreeRoot )
pfGUIListTreeRoot::pfGUIListTreeRoot( const plString &text )
: pfGUIListElement(kTreeRoot), fText(text)
{
fText = hsStringToWString(text);
}
pfGUIListTreeRoot::pfGUIListTreeRoot( const wchar_t *text ) : pfGUIListElement( kTreeRoot )
{
fText = new wchar_t[ wcslen( text ) + 1 ];
wcscpy( fText, text );
}
pfGUIListTreeRoot::~pfGUIListTreeRoot()
{
delete [] fText;
}
//// Virtuals ////////////////////////////////////////////////////////////////
@ -323,18 +274,14 @@ void pfGUIListTreeRoot::Read( hsStream *s, hsResMgr *mgr )
{
pfGUIListElement::Read( s, mgr );
char *temp = s->ReadSafeString();
fText = hsStringToWString(temp);
delete [] temp;
fText = s->ReadSafeString_TEMP();
}
void pfGUIListTreeRoot::Write( hsStream *s, hsResMgr *mgr )
{
pfGUIListElement::Write( s, mgr );
char *temp = hsWStringToString(fText);
s->WriteSafeString( temp );
delete [] temp;
s->WriteSafeString(fText);
}
bool pfGUIListTreeRoot::Draw( plDynamicTextMap *textGen, uint16_t x, uint16_t y, uint16_t maxWidth, uint16_t maxHeight )
@ -416,26 +363,7 @@ int pfGUIListTreeRoot::CompareTo( pfGUIListElement *rightSide )
if( text->fType != kTreeRoot )
return -2;
return wcscmp( GetTitle(), text->GetTitle() );
}
void pfGUIListTreeRoot::SetTitle( const char *text )
{
wchar_t *wText = hsStringToWString(text);
SetTitle(wText);
delete [] wText;
}
void pfGUIListTreeRoot::SetTitle( const wchar_t *text )
{
delete [] fText;
if( text != nil )
{
fText = new wchar_t[ wcslen( text ) + 1 ];
wcscpy( fText, text );
}
else
fText = nil;
return GetTitle().Compare(text->GetTitle());
}
void pfGUIListTreeRoot::AddChild( pfGUIListElement *el )

24
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListElement.h

@ -118,15 +118,13 @@ class pfGUIListText : public pfGUIListElement
protected:
wchar_t *fText;
plString fText;
uint8_t fJustify; // This is not our JustifyTypes, but from plDynamicTextMap
public:
pfGUIListText();
pfGUIListText( const char *text );
pfGUIListText( const wchar_t *text );
virtual ~pfGUIListText();
pfGUIListText( const plString &text );
virtual void Read( hsStream *s, hsResMgr *mgr );
virtual void Write( hsStream *s, hsResMgr *mgr );
@ -139,9 +137,8 @@ class pfGUIListText : public pfGUIListElement
virtual void SetJustify( JustifyTypes justify );
// These two are virtual so we can derive and override them
virtual const wchar_t *GetText( void ) { return fText; }
virtual void SetText( const char *text );
virtual void SetText( const wchar_t *text );
virtual plString GetText() const { return fText; }
virtual void SetText(const plString &text) { fText = text; }
};
class pfGUIListPicture : public pfGUIListElement
@ -176,7 +173,7 @@ class pfGUIListTreeRoot : public pfGUIListElement
{
protected:
wchar_t *fText;
plString fText;
bool fShowChildren;
hsTArray<pfGUIListElement *> fChildren;
@ -184,9 +181,7 @@ class pfGUIListTreeRoot : public pfGUIListElement
public:
pfGUIListTreeRoot();
pfGUIListTreeRoot( const char *text );
pfGUIListTreeRoot( const wchar_t *text );
virtual ~pfGUIListTreeRoot();
pfGUIListTreeRoot( const plString &text );
virtual void Read( hsStream *s, hsResMgr *mgr );
virtual void Write( hsStream *s, hsResMgr *mgr );
@ -197,11 +192,10 @@ class pfGUIListTreeRoot : public pfGUIListElement
virtual bool MouseClicked( uint16_t localX, uint16_t localY );
const wchar_t *GetTitle( void ) { return fText; }
void SetTitle( const char *text );
void SetTitle( const wchar_t *text );
const plString GetTitle() const { return fText; }
void SetTitle(const plString &text) { fText = text; }
uint32_t GetNumChildren( void ) const { return fChildren.GetCount(); }
uint32_t GetNumChildren() const { return fChildren.GetCount(); }
pfGUIListElement *GetChild( uint32_t i ) const { return fChildren[ i ]; }
void AddChild( pfGUIListElement *el );

97
Sources/Plasma/FeatureLib/pfPython/pyGUIControlListBox.cpp

@ -81,12 +81,12 @@ class pfColorListElement : public pfGUIListText
if ( string1 )
{
fString1 = hsStringToWString(string1);
fText = nil;
fText = plString::Null;
}
else
{
fString1 = nil;
fText = L"";
fText = "";
}
fTextColor1 = color1;
if (string2)
@ -105,12 +105,12 @@ class pfColorListElement : public pfGUIListText
{
fString1 = new wchar_t[wcslen(string1)+1];
wcscpy(fString1,string1);
fText = nil;
fText = plString::Null;
}
else
{
fString1 = nil;
fText = L"";
fText = "";
}
fTextColor1 = color1;
if (string2)
@ -132,7 +132,7 @@ class pfColorListElement : public pfGUIListText
{
delete [] fString1;
fString1 = nil;
fText = nil;
fText = plString::Null;
}
if ( fString2 )
delete [] fString2;
@ -287,14 +287,7 @@ class pfListTextInBox : public pfGUIListText
uint32_t fMinHeight;
public:
pfListTextInBox( const char *text, uint32_t min_width=0, uint32_t min_height=0 ) : pfGUIListText( text )
{
fMinWidth = min_width;
fMinHeight = min_height;
fJustify = pfGUIListText::kCenter;
}
pfListTextInBox( const wchar_t *text, uint32_t min_width=0, uint32_t min_height=0 ) : pfGUIListText( text )
pfListTextInBox( const plString &text, uint32_t min_width=0, uint32_t min_height=0 ) : pfGUIListText( text )
{
fMinWidth = min_width;
fMinHeight = min_height;
@ -510,14 +503,7 @@ uint16_t pyGUIControlListBox::GetNumElements( void )
return 0;
}
void pyGUIControlListBox::SetElement( uint16_t idx, const char* text )
{
wchar_t *wText = hsStringToWString(text);
SetElementW(idx,wText);
delete [] wText;
}
void pyGUIControlListBox::SetElementW( uint16_t idx, std::wstring text )
void pyGUIControlListBox::SetElement( uint16_t idx, const plString& text )
{
if ( fGCkey )
{
@ -532,7 +518,7 @@ void pyGUIControlListBox::SetElementW( uint16_t idx, std::wstring text )
{
// if its a text element type then it should be safe to cast it to a pfGUIListText
pfGUIListText* letext = (pfGUIListText*)le;
letext->SetText(text.c_str());
letext->SetText(text);
}
}
}
@ -562,16 +548,7 @@ void pyGUIControlListBox::SetStringJustify( uint16_t idx, uint32_t justify)
}
std::string pyGUIControlListBox::GetElement( uint16_t idx )
{
std::wstring wRetVal = GetElementW(idx);
char *temp = hsWStringToString(wRetVal.c_str());
std::string retVal = temp;
delete [] temp;
return retVal;
}
std::wstring pyGUIControlListBox::GetElementW( uint16_t idx )
plString pyGUIControlListBox::GetElement( uint16_t idx )
{
if ( fGCkey )
{
@ -596,18 +573,10 @@ std::wstring pyGUIControlListBox::GetElementW( uint16_t idx )
}
}
}
return L"";
}
int16_t pyGUIControlListBox::AddString( const char *string )
{
wchar_t *wString = hsStringToWString(string);
int16_t retVal = AddStringW(wString);
delete [] wString;
return retVal;
return "";
}
int16_t pyGUIControlListBox::AddStringW( std::wstring string )
int16_t pyGUIControlListBox::AddString( const plString &string )
{
if ( fGCkey )
{
@ -615,7 +584,7 @@ int16_t pyGUIControlListBox::AddStringW( std::wstring string )
pfGUIListBoxMod* plbmod = pfGUIListBoxMod::ConvertNoRef(fGCkey->ObjectIsLoaded());
if ( plbmod )
{
pfGUIListText *element = new pfGUIListText( string.c_str() );
pfGUIListText *element = new pfGUIListText(string);
if( fBuildRoots.GetCount() > 0 )
fBuildRoots[ fBuildRoots.GetCount() - 1 ]->AddChild( element );
return plbmod->AddElement( element );
@ -642,22 +611,14 @@ int16_t pyGUIControlListBox::AddImage( pyImage& image, bool respectAlpha )
}
int16_t pyGUIControlListBox::FindString( const char *toCompareTo )
{
wchar_t *wToCompareTo = hsStringToWString(toCompareTo);
int16_t retVal = FindStringW(wToCompareTo);
delete [] wToCompareTo;
return retVal;
}
int16_t pyGUIControlListBox::FindStringW( std::wstring toCompareTo )
int16_t pyGUIControlListBox::FindString( const plString &toCompareTo )
{
if ( fGCkey )
{
// get the pointer to the modifier
pfGUIListBoxMod* plbmod = pfGUIListBoxMod::ConvertNoRef(fGCkey->ObjectIsLoaded());
if ( plbmod )
return plbmod->FindString(toCompareTo.c_str());
return plbmod->FindString(toCompareTo);
}
return -1;
}
@ -737,7 +698,7 @@ void pyGUIControlListBox::Add2TextWColorW( std::wstring str1, pyColor& textcolor
}
}
int16_t pyGUIControlListBox::AddStringInBox( const char *string, uint32_t min_width, uint32_t min_height )
int16_t pyGUIControlListBox::AddStringInBox( const plString &string, uint32_t min_width, uint32_t min_height )
{
if ( fGCkey )
{
@ -754,23 +715,6 @@ int16_t pyGUIControlListBox::AddStringInBox( const char *string, uint32_t min_wi
return -1;
}
int16_t pyGUIControlListBox::AddStringInBoxW( std::wstring string, uint32_t min_width, uint32_t min_height )
{
if ( fGCkey )
{
// get the pointer to the modifier
pfGUIListBoxMod* plbmod = pfGUIListBoxMod::ConvertNoRef(fGCkey->ObjectIsLoaded());
if ( plbmod )
{
pfListTextInBox *element = new pfListTextInBox( string.c_str(), min_width, min_height );
if( fBuildRoots.GetCount() > 0 )
fBuildRoots[ fBuildRoots.GetCount() - 1 ]->AddChild( element );
return plbmod->AddElement( element );
}
}
return -1;
}
int16_t pyGUIControlListBox::AddImageInBox( pyImage& image, uint32_t x, uint32_t y, uint32_t width, uint32_t height, bool respectAlpha )
{
if ( fGCkey )
@ -927,14 +871,7 @@ void pyGUIControlListBox::Unclickable( void )
}
}
void pyGUIControlListBox::AddBranch( const char *name, bool initiallyOpen )
{
wchar_t *wName = hsStringToWString(name);
AddBranchW(wName,initiallyOpen);
delete [] wName;
}
void pyGUIControlListBox::AddBranchW( std::wstring name, bool initiallyOpen )
void pyGUIControlListBox::AddBranch( const plString &name, bool initiallyOpen )
{
if ( fGCkey )
{
@ -942,7 +879,7 @@ void pyGUIControlListBox::AddBranchW( std::wstring name, bool initiallyOpen )
pfGUIListBoxMod* plbmod = pfGUIListBoxMod::ConvertNoRef(fGCkey->ObjectIsLoaded());
if ( plbmod )
{
pfGUIListTreeRoot *root = new pfGUIListTreeRoot( name.c_str() );
pfGUIListTreeRoot *root = new pfGUIListTreeRoot(name);
root->ShowChildren( initiallyOpen );
if( fBuildRoots.GetCount() > 0 )

18
Sources/Plasma/FeatureLib/pfPython/pyGUIControlListBox.h

@ -88,15 +88,12 @@ public:
virtual int32_t GetSelection( void );
virtual void SetSelection( int32_t item );
virtual void Refresh( void );
virtual void SetElement( uint16_t idx, const char* text );
virtual void SetElementW( uint16_t idx, std::wstring text );
virtual void SetElement( uint16_t idx, const plString& text );
virtual void RemoveElement( uint16_t index );
virtual void ClearAllElements( void );
virtual uint16_t GetNumElements( void );
virtual std::string GetElement( uint16_t idx );
virtual std::wstring GetElementW( uint16_t idx );
virtual int16_t AddString( const char *string );
virtual int16_t AddStringW( std::wstring string );
virtual plString GetElement( uint16_t idx );
virtual int16_t AddString( const plString &string );
virtual int16_t AddImage( pyImage& image, bool respectAlpha );
virtual int16_t AddImageInBox( pyImage& image, uint32_t x, uint32_t y, uint32_t width, uint32_t height, bool respectAlpha );
virtual int16_t AddImageAndSwatchesInBox( pyImage& image, uint32_t x, uint32_t y, uint32_t width, uint32_t height, bool respectAlpha,
@ -104,16 +101,14 @@ public:
virtual void SetSwatchSize( uint32_t size );
virtual void SetSwatchEdgeOffset( uint32_t size );
virtual void SetStringJustify( uint16_t idx, uint32_t justify);
virtual int16_t FindString( const char *toCompareTo );
virtual int16_t FindStringW( std::wstring toCompareTo );
virtual int16_t FindString( const plString &toCompareTo );
virtual int16_t AddTextWColor( const char *str, pyColor& textcolor, uint32_t inheritalpha);
virtual int16_t AddTextWColorW( std::wstring str, pyColor& textcolor, uint32_t inheritalpha);
virtual int16_t AddTextWColorWSize( const char *str, pyColor& textcolor, uint32_t inheritalpha, int32_t fontsize);
virtual int16_t AddTextWColorWSizeW( std::wstring str, pyColor& textcolor, uint32_t inheritalpha, int32_t fontsize);
virtual void Add2TextWColor( const char *str1, pyColor& textcolor1,const char *str2, pyColor& textcolor2, uint32_t inheritalpha);
virtual void Add2TextWColorW( std::wstring str1, pyColor& textcolor1, std::wstring str2, pyColor& textcolor2, uint32_t inheritalpha);
virtual int16_t AddStringInBox( const char *string, uint32_t min_width, uint32_t min_height );
virtual int16_t AddStringInBoxW( std::wstring string, uint32_t min_width, uint32_t min_height );
virtual int16_t AddStringInBox( const plString &string, uint32_t min_width, uint32_t min_height );
virtual void ScrollToBegin( void );
virtual void ScrollToEnd( void );
virtual void SetScrollPos( int32_t pos );
@ -125,8 +120,7 @@ public:
// To create tree branches, call AddBranch() with a name, then add elements as usual, including new sub-branches
// via additional AddBranch() calls. Call CloseBranch() to stop writing elements to that branch.
void AddBranch( const char *name, bool initiallyOpen );
void AddBranchW( std::wstring name, bool initiallyOpen );
void AddBranch( const plString &name, bool initiallyOpen );
void CloseBranch( void );
void RemoveSelection( int32_t item );

13
Sources/Plasma/FeatureLib/pfPython/pyGUIControlListBoxGlue.cpp

@ -136,7 +136,7 @@ PYTHON_METHOD_DEFINITION(ptGUIControlListBox, setElementW, args)
PyErr_SetString(PyExc_TypeError, "setElementW expects an unsigned short and a unicode string");
PYTHON_RETURN_ERROR;
}
self->fThis->SetElementW(index, text);
self->fThis->SetElement(index, plString::FromWchar(text));
PYTHON_RETURN_NONE;
}
@ -148,7 +148,7 @@ PYTHON_METHOD_DEFINITION(ptGUIControlListBox, getElement, args)
PyErr_SetString(PyExc_TypeError, "getElement expects an unsigned short");
PYTHON_RETURN_ERROR;
}
return PyString_FromString(self->fThis->GetElement(index).c_str());
return PyString_FromPlString(self->fThis->GetElement(index));
}
PYTHON_METHOD_DEFINITION(ptGUIControlListBox, getElementW, args)
@ -159,8 +159,7 @@ PYTHON_METHOD_DEFINITION(ptGUIControlListBox, getElementW, args)
PyErr_SetString(PyExc_TypeError, "getElementW expects an unsigned short");
PYTHON_RETURN_ERROR;
}
std::wstring retVal = self->fThis->GetElementW(index);
return PyUnicode_FromWideChar(retVal.c_str(), retVal.length());
return PyUnicode_FromStringEx(self->fThis->GetElement(index));
}
PYTHON_METHOD_DEFINITION(ptGUIControlListBox, setStringJustify, args)
@ -195,7 +194,7 @@ PYTHON_METHOD_DEFINITION(ptGUIControlListBox, addStringW, args)
PyErr_SetString(PyExc_TypeError, "addStringW expects a unicode string");
PYTHON_RETURN_ERROR;
}
return PyInt_FromLong(self->fThis->AddStringW(text));
return PyInt_FromLong(self->fThis->AddString(plString::FromWchar(text)));
}
PYTHON_METHOD_DEFINITION(ptGUIControlListBox, findString, args)
@ -217,7 +216,7 @@ PYTHON_METHOD_DEFINITION(ptGUIControlListBox, findStringW, args)
PyErr_SetString(PyExc_TypeError, "findStringW expects a unicode string");
PYTHON_RETURN_ERROR;
}
return PyInt_FromLong(self->fThis->FindStringW(text));
return PyInt_FromLong(self->fThis->FindString(plString::FromWchar(text)));
}
PYTHON_METHOD_DEFINITION(ptGUIControlListBox, addImage, args)
@ -387,7 +386,7 @@ PYTHON_METHOD_DEFINITION(ptGUIControlListBox, addBranchW, args)
wchar_t* name = new wchar_t[strLen + 1];
PyUnicode_AsWideChar((PyUnicodeObject*)textObj, name, strLen);
name[strLen] = L'\0';
self->fThis->AddBranchW(name, initiallyOpen != 0);
self->fThis->AddBranch(plString::FromWchar(name), initiallyOpen != 0);
delete [] name;
PYTHON_RETURN_NONE;
}

Loading…
Cancel
Save