From 3f0850c5770966a462e02afe5cc970788e49eb56 Mon Sep 17 00:00:00 2001 From: spartanj Date: Sun, 5 Jun 2011 03:53:40 -0300 Subject: [PATCH] Continued working on the Map Editor. Fixed a lot of bugs and minor details on the UI Controls. Added basic support for icons on the UI themes. --- src/gaming/cmap.cpp | 18 +- src/gaming/cmap.hpp | 13 +- src/gaming/ctilelayer.cpp | 4 + src/gaming/ctilelayer.hpp | 2 + src/gaming/mapeditor/cmapeditor.cpp | 311 ++++++++++++++++++++++---- src/gaming/mapeditor/cmapeditor.hpp | 46 +++- src/gaming/mapeditor/cuigotypenew.cpp | 63 ++++++ src/gaming/mapeditor/cuigotypenew.hpp | 31 +++ src/gaming/mapeditor/cuilayernew.cpp | 88 ++++++++ src/gaming/mapeditor/cuilayernew.hpp | 43 ++++ src/gaming/mapeditor/cuimapnew.cpp | 100 +++++++++ src/gaming/mapeditor/cuimapnew.hpp | 37 +++ src/gaming/maphelper.hpp | 2 +- src/test/eetest.cpp | 22 +- src/ui/cuiaquatheme.cpp | 2 +- src/ui/cuicheckbox.cpp | 19 +- src/ui/cuicheckbox.hpp | 2 + src/ui/cuicommondialog.cpp | 37 +-- src/ui/cuicommondialog.hpp | 2 + src/ui/cuidropdownlist.cpp | 31 +-- src/ui/cuilistbox.cpp | 42 ++-- src/ui/cuilistbox.hpp | 6 +- src/ui/cuilistboxitem.cpp | 1 - src/ui/cuimanager.cpp | 4 + src/ui/cuimanager.hpp | 3 + src/ui/cuimenu.cpp | 54 +++-- src/ui/cuipushbutton.cpp | 27 ++- src/ui/cuipushbutton.hpp | 8 +- src/ui/cuiradiobutton.cpp | 19 +- src/ui/cuiradiobutton.hpp | 2 + src/ui/cuispinbox.cpp | 10 +- src/ui/cuispinbox.hpp | 2 +- src/ui/cuitextinput.cpp | 7 + src/ui/cuitextinput.hpp | 2 + src/ui/cuitheme.cpp | 54 ++++- src/ui/cuitheme.hpp | 13 +- src/utils/string.cpp | 8 + src/utils/string.hpp | 3 + src/window/cinputtextbuffer.cpp | 1 - 39 files changed, 980 insertions(+), 159 deletions(-) create mode 100644 src/gaming/mapeditor/cuigotypenew.cpp create mode 100644 src/gaming/mapeditor/cuigotypenew.hpp create mode 100644 src/gaming/mapeditor/cuilayernew.cpp create mode 100644 src/gaming/mapeditor/cuilayernew.hpp create mode 100644 src/gaming/mapeditor/cuimapnew.cpp create mode 100644 src/gaming/mapeditor/cuimapnew.hpp diff --git a/src/gaming/cmap.cpp b/src/gaming/cmap.cpp index 4bbb74ab8..fb9301be9 100644 --- a/src/gaming/cmap.cpp +++ b/src/gaming/cmap.cpp @@ -11,7 +11,7 @@ using namespace EE::Graphics; namespace EE { namespace Gaming { cMap::cMap() : - mWindow( NULL ), + mWindow( cEngine::instance()->GetCurrentWindow() ), mLayers( NULL ), mFlags( 0 ), mMaxLayers( 0 ), @@ -64,9 +64,12 @@ void cMap::Create( eeSize Size, Uint32 MaxLayers, eeSize TileSize, Uint32 Flags, ViewSize( viewSize ); } -void cMap::AddLayer( Uint32 Type, Uint32 flags, std::string name ) { +cLayer * cMap::AddLayer( Uint32 Type, Uint32 flags, std::string name ) { eeASSERT( NULL != mLayers ); + if ( mLayerCount >= mMaxLayers ) + return NULL; + switch ( Type ) { case MAP_LAYER_TILED: mLayers[ mLayerCount ] = eeNew( cTileLayer, ( this, mSize, flags, name ) ); @@ -75,10 +78,12 @@ void cMap::AddLayer( Uint32 Type, Uint32 flags, std::string name ) { mLayers[ mLayerCount ] = eeNew( cObjectLayer, ( this, flags, name ) ); break; default: - return; + return NULL; } mLayerCount++; + + return mLayers[ mLayerCount - 1 ]; } cLayer* cMap::GetLayer( Uint32 index ) { @@ -170,6 +175,9 @@ void cMap::GetMouseOverTile() { if ( mMouseOverTile.y >= mSize.Height() ) mMouseOverTile.y = mSize.Height() - 1; + + // Clamped pos + mMouseOverTileFinal = eeVector2u( mMouseOverTile.x, mMouseOverTile.y ); } void cMap::Update() { @@ -181,6 +189,10 @@ const eeSize& cMap::ViewSize() const { return mViewSize; } +const eeVector2u& cMap::GetMouseTilePos() const { + return mMouseOverTileFinal; +} + void cMap::ViewSize( const eeSize& viewSize ) { mViewSize = viewSize; diff --git a/src/gaming/cmap.hpp b/src/gaming/cmap.hpp index 6e128ace1..b7943ccaf 100644 --- a/src/gaming/cmap.hpp +++ b/src/gaming/cmap.hpp @@ -20,15 +20,15 @@ class cMap { virtual ~cMap(); - virtual void Create( eeSize Size, Uint32 MaxLayers, eeSize TileSize, Uint32 Flags = 0, eeSize viewSize = eeSize( 640, 480 ), cWindow * Window = NULL ); + virtual void Create( eeSize Size, Uint32 MaxLayers, eeSize TileSize, Uint32 Flags = 0, eeSize viewSize = eeSize( 800, 600 ), cWindow * Window = NULL ); - virtual void AddLayer( Uint32 Type, Uint32 flags, std::string name ); + virtual cLayer * AddLayer( Uint32 Type, Uint32 flags, std::string name ); - virtual cLayer* GetLayer( Uint32 index ); + virtual cLayer * GetLayer( Uint32 index ); - virtual cLayer* GetLayerByHash( Uint32 hash ); + virtual cLayer * GetLayerByHash( Uint32 hash ); - virtual cLayer* GetLayer( const std::string& name ); + virtual cLayer * GetLayer( const std::string& name ); virtual void Load( const std::string& path ); @@ -77,6 +77,8 @@ class cMap { Uint32 DrawGrid() const; void Reset(); + + const eeVector2u& GetMouseTilePos() const; protected: cWindow * mWindow; cLayer** mLayers; @@ -91,6 +93,7 @@ class cMap { eeVector2i mStartTile; eeVector2i mEndTile; eeVector2i mMouseOverTile; + eeVector2u mMouseOverTileFinal; cGameObject * CreateGameObject( const Uint32& Type, const Uint32& Flags ); diff --git a/src/gaming/ctilelayer.cpp b/src/gaming/ctilelayer.cpp index b34a525cf..44b58f13d 100644 --- a/src/gaming/ctilelayer.cpp +++ b/src/gaming/ctilelayer.cpp @@ -90,4 +90,8 @@ void cTileLayer::RemoveGameObject( const eeVector2u& TilePos ) { } } +cGameObject * cTileLayer::GetGameObject( const eeVector2u& TilePos ) { + return mTiles[ TilePos.x ][ TilePos.y ]; +} + }} diff --git a/src/gaming/ctilelayer.hpp b/src/gaming/ctilelayer.hpp index bc53014c3..d10d47081 100644 --- a/src/gaming/ctilelayer.hpp +++ b/src/gaming/ctilelayer.hpp @@ -17,6 +17,8 @@ class cTileLayer : public cLayer { virtual void AddGameObject( cGameObject * obj, const eeVector2u& TilePos ); virtual void RemoveGameObject( const eeVector2u& TilePos ); + + virtual cGameObject * GetGameObject( const eeVector2u& TilePos ); protected: friend class cMap; diff --git a/src/gaming/mapeditor/cmapeditor.cpp b/src/gaming/mapeditor/cmapeditor.cpp index 02f9c630e..7478cdab8 100644 --- a/src/gaming/mapeditor/cmapeditor.cpp +++ b/src/gaming/mapeditor/cmapeditor.cpp @@ -1,10 +1,21 @@ #include "cmapeditor.hpp" +#include "cuimapnew.hpp" +#include "cuilayernew.hpp" +#include "cuigotypenew.hpp" +#include "../ctilelayer.hpp" +#include "../cobjectlayer.hpp" +#include "../cgameobjectshape.hpp" +#include "../cgameobjectshapeex.hpp" +#include "../cgameobjectsprite.hpp" #include "../../ui/cuimanager.hpp" #include "../../ui/cuithememanager.hpp" #include "../../ui/cuiwinmenu.hpp" #include "../../ui/cuipopupmenu.hpp" +#include "../../ui/cuispinbox.hpp" +#include "../../ui/cuicheckbox.hpp" #include "../../ui/cuicommondialog.hpp" #include "../../graphics/cshapegroupmanager.hpp" +#include "../../graphics/cglobalshapegroup.hpp" #include "../../graphics/ctexturegrouploader.hpp" using namespace EE::Graphics; @@ -13,7 +24,10 @@ namespace EE { namespace Gaming { namespace MapEditor { cMapEditor::cMapEditor( cUIWindow * AttatchTo, const MapEditorCloseCb& callback ) : mUIWindow( AttatchTo ), - mCloseCb( callback ) + mCloseCb( callback ), + mGOTypeList( NULL ), + mChkAnim( NULL ), + mCurLayer( NULL ) { if ( NULL == cUIThemeManager::instance()->DefaultTheme() ) { eePRINT( "cMapEditor needs a default theme seted to work." ); @@ -54,15 +68,15 @@ void cMapEditor::CreateWinMenu() { cUIWinMenu * WinMenu = mTheme->CreateWinMenu( mUIContainer ); cUIPopUpMenu * PU1 = mTheme->CreatePopUpMenu(); - PU1->Add( "New..." ); - PU1->Add( "Open..." ); + PU1->Add( "New...", mTheme->GetIconByName( "document-new" ) ); + PU1->Add( "Open...", mTheme->GetIconByName( "document-open" ) ); PU1->AddSeparator(); - PU1->Add( "Save" ); - PU1->Add( "Save As..." ); + PU1->Add( "Save", mTheme->GetIconByName( "document-save" ) ); + PU1->Add( "Save As...", mTheme->GetIconByName( "document-save-as" ) ); PU1->AddSeparator(); - PU1->Add( "Close" ); + PU1->Add( "Close", mTheme->GetIconByName( "document-close" ) ); PU1->AddSeparator(); - PU1->Add( "Quit" ); + PU1->Add( "Quit", mTheme->GetIconByName( "quit" ) ); PU1->AddEventListener( cUIEvent::EventOnItemClicked, cb::Make1( this, &cMapEditor::FileMenuClick ) ); WinMenu->AddMenuButton( "File", PU1 ); @@ -109,59 +123,144 @@ void cMapEditor::CreateWinMenu() { mWinContainer->Enabled( true ); } -void cMapEditor::FileMenuClick( const cUIEvent * Event ) { - if ( !Event->Ctrl()->IsTypeOrInheritsFrom( UI_TYPE_MENUITEM ) ) - return; - - const String& txt = reinterpret_cast ( Event->Ctrl() )->Text(); - - if ( "New..." == txt ) { - CreateNewMap(); - } else if ( "Quit" == txt ) { - if ( mUIWindow == cUIManager::instance()->MainControl() ) { - cUIManager::instance()->GetWindow()->Close(); - } else { - mUIWindow->CloseWindow(); - } - } -} - void cMapEditor::CreateETGMenu() { Int32 Width = 200; + Int32 DistToBorder = 5; - cUITextBox * Txt = mTheme->CreateTextBox( mWinContainer, eeSize( Width, 16 ), eeVector2i( mWinContainer->Size().Width() - Width - 5, 4 ), UI_CONTROL_DEFAULT_ALIGN | UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); + Uint32 TxtFlags = UI_CONTROL_DEFAULT_ALIGN | UI_ANCHOR_RIGHT | UI_ANCHOR_TOP | UI_DRAW_SHADOW; + + cUITextBox * Txt = mTheme->CreateTextBox( mWinContainer, eeSize( Width, 16 ), eeVector2i( mWinContainer->Size().Width() - Width - DistToBorder, 4 ), TxtFlags ); Txt->Text( "Shape Groups:" ); - mShapeGroupsList = mTheme->CreateDropDownList( mWinContainer, eeSize( Width, 21 ), eeVector2i( mWinContainer->Size().Width() - Width - 5, Txt->Pos().y +Txt->Size().Height() + 4 ), UI_CONTROL_DEFAULT_ALIGN | UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); + mShapeGroupsList = mTheme->CreateDropDownList( mWinContainer, eeSize( Width, 21 ), eeVector2i( mWinContainer->Size().Width() - Width - DistToBorder, Txt->Pos().y +Txt->Size().Height() + 4 ), UI_CONTROL_DEFAULT_ALIGN | UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); mShapeGroupsList->AddEventListener( cUIEvent::EventOnItemSelected, cb::Make1( this, &cMapEditor::OnShapeGroupChange ) ); - mShapeList = mTheme->CreateListBox( mWinContainer, eeSize( Width, 156 ), eeVector2i( mWinContainer->Size().Width() - Width - 5, mShapeGroupsList->Pos().y + mShapeGroupsList->Size().Height() + 4 ), UI_CONTROL_DEFAULT_ALIGN | UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); + mShapeList = mTheme->CreateListBox( mWinContainer, eeSize( Width, 156 ), eeVector2i( mWinContainer->Size().Width() - Width - DistToBorder, mShapeGroupsList->Pos().y + mShapeGroupsList->Size().Height() + 4 ), UI_CONTROL_DEFAULT_ALIGN | UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); mShapeList->AddEventListener( cUIEvent::EventOnItemSelected, cb::Make1( this, &cMapEditor::OnShapeChange ) ); - mGfxPreview = mTheme->CreateGfx( NULL, mWinContainer, eeSize( Width, Width ), eeVector2i( mWinContainer->Size().Width() - Width - 5, mShapeList->Pos().y + mShapeList->Size().Height() + 4 ), UI_VALIGN_CENTER | UI_HALIGN_CENTER | UI_ANCHOR_RIGHT | UI_ANCHOR_TOP | UI_AUTO_FIT ); + mGfxPreview = mTheme->CreateGfx( NULL, mWinContainer, eeSize( Width, Width ), eeVector2i( mWinContainer->Size().Width() - Width - DistToBorder, mShapeList->Pos().y + mShapeList->Size().Height() + 4 ), UI_VALIGN_CENTER | UI_HALIGN_CENTER | UI_ANCHOR_RIGHT | UI_ANCHOR_TOP | UI_AUTO_FIT ); mGfxPreview->Border( true ); - Txt = mTheme->CreateTextBox( mWinContainer, eeSize( Width, 16 ), eeVector2i( mWinContainer->Size().Width() - Width - 5, mGfxPreview->Pos().y + mGfxPreview->Size().Height() + 4 ), UI_CONTROL_DEFAULT_ALIGN | UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); + Txt = mTheme->CreateTextBox( mWinContainer, eeSize( Width, 16 ), eeVector2i( mWinContainer->Size().Width() - Width - DistToBorder, mGfxPreview->Pos().y + mGfxPreview->Size().Height() + 4 ), TxtFlags ); Txt->Text( "Add Game Object as..." ); - mTypeAdd = mTheme->CreateDropDownList( mWinContainer, eeSize( Width, 1 ), eeVector2i( mWinContainer->Size().Width() - Width - 5, Txt->Pos().y + Txt->Size().Height() + 4 ), UI_CONTROL_DEFAULT_ALIGN | UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); + mGOTypeList = mTheme->CreateDropDownList( mWinContainer, eeSize( Width - 26, 21 ), eeVector2i( mWinContainer->Size().Width() - Width - DistToBorder, Txt->Pos().y + Txt->Size().Height() + 4 ), UI_CONTROL_DEFAULT_ALIGN | UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); std::vector items; items.push_back( "Shape" ); items.push_back( "ShapeEx" ); items.push_back( "Sprite" ); - mTypeAdd->ListBox()->AddListBoxItems( items ); - mTypeAdd->ListBox()->SetSelected(0); + mGOTypeList->ListBox()->AddListBoxItems( items ); + mGOTypeList->AddEventListener( cUIEvent::EventOnItemSelected, cb::Make1( this, &cMapEditor::OnTypeChange ) ); + mGOTypeList->ListBox()->SetSelected(0); - Txt = mTheme->CreateTextBox( mWinContainer, eeSize( Width, 16 ), eeVector2i( mWinContainer->Size().Width() - Width - 5, mTypeAdd->Pos().y + mTypeAdd->Size().Height() + 4 ), UI_CONTROL_DEFAULT_ALIGN | UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); + mBtnGOTypeAdd = mTheme->CreatePushButton( mWinContainer, eeSize( 24, 21 ), eeVector2i( mGOTypeList->Pos().x + mGOTypeList->Size().Width() + 2, mGOTypeList->Pos().y ), UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, mTheme->GetIconByName( "add" ) ); + mBtnGOTypeAdd->AddEventListener( cUIEvent::EventMouseClick, cb::Make1( this, &cMapEditor::AddNewGOType ) ); + + if ( NULL == mBtnGOTypeAdd->Icon()->Shape() ) + mBtnGOTypeAdd->Text( "..." ); + + Txt = mTheme->CreateTextBox( mWinContainer, eeSize( Width, 16 ), eeVector2i( mWinContainer->Size().Width() - Width - DistToBorder, mGOTypeList->Pos().y + mGOTypeList->Size().Height() + 4 ), TxtFlags ); Txt->Text( "Layers:" ); - mLayerList = mTheme->CreateDropDownList( mWinContainer, eeSize( Width, 21 ), eeVector2i( mWinContainer->Size().Width() - Width - 5, Txt->Pos().y + Txt->Size().Height() + 4 ), UI_CONTROL_DEFAULT_ALIGN | UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); - mLayerList->ListBox()->AddListBoxItem( "Floor" ); - mLayerList->ListBox()->SetSelected(0); + mLayerList = mTheme->CreateDropDownList( mWinContainer, eeSize( Width, 21 ), eeVector2i( mWinContainer->Size().Width() - Width - DistToBorder, Txt->Pos().y + Txt->Size().Height() + 4 ), UI_CONTROL_DEFAULT_ALIGN | UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); + mLayerList->AddEventListener( cUIEvent::EventOnItemSelected, cb::Make1( this, &cMapEditor::OnLayerSelect ) ); + + Txt = mTheme->CreateTextBox( mWinContainer, eeSize( Width, 16 ), eeVector2i( mWinContainer->Size().Width() - Width - DistToBorder, mLayerList->Pos().y + mLayerList->Size().Height() + 4 ), TxtFlags ); + Txt->Text( "Game Object Flags:" ); + + Uint32 ChkFlags = UI_CONTROL_DEFAULT_ALIGN | UI_AUTO_SIZE | UI_ANCHOR_RIGHT | UI_ANCHOR_TOP; + + mChkMirrored = mTheme->CreateCheckBox( mWinContainer, eeSize(), eeVector2i( mWinContainer->Size().Width() - Width - DistToBorder, Txt->Pos().y + Txt->Size().Height() + 4 ), ChkFlags ); + mChkMirrored->Text( "Mirrored" ); + mChkMirrored->AddEventListener( cUIEvent::EventMouseClick, cb::Make1( this, &cMapEditor::ChkClickMirrored ) ); + + mChkFliped = mTheme->CreateCheckBox( mWinContainer, eeSize(), eeVector2i( mChkMirrored->Pos().x + mChkMirrored->Size().Width() + 32, mChkMirrored->Pos().y ), ChkFlags ); + mChkFliped->Text( "Fliped" ); + mChkFliped->AddEventListener( cUIEvent::EventMouseClick, cb::Make1( this, &cMapEditor::ChkClickFliped ) ); + + mChkBlocked = mTheme->CreateCheckBox( mWinContainer, eeSize(), eeVector2i( mChkMirrored->Pos().x, mChkMirrored->Pos().y + mChkMirrored->Size().Height() + 4 ), ChkFlags ); + mChkBlocked->Text( "Blocked" ); + mChkBlocked->AddEventListener( cUIEvent::EventMouseClick, cb::Make1( this, &cMapEditor::ChkClickBlocked ) ); + + mChkAnim = mTheme->CreateCheckBox( mWinContainer, eeSize(), eeVector2i( mChkFliped->Pos().x, mChkFliped->Pos().y + mChkFliped->Size().Height() + 4 ), ChkFlags ); + mChkAnim->Text( "Animated" ); + mChkAnim->AddEventListener( cUIEvent::EventMouseClick, cb::Make1( this, &cMapEditor::ChkClickAnimated ) ); FillSGCombo(); } +void cMapEditor::UpdateGfx() { + if ( mChkMirrored->Active() && mChkFliped->Active() ) + mGfxPreview->RenderType( RN_FLIPMIRROR ); + else if( mChkMirrored->Active() ) + mGfxPreview->RenderType( RN_MIRROR ); + else if ( mChkFliped->Active() ) + mGfxPreview->RenderType( RN_FLIP ); + else + mGfxPreview->RenderType( RN_NORMAL ); +} + +void cMapEditor::UpdateFlags() { + mCurGOFlags = 0; + + if ( mChkMirrored->Active() ) + mCurGOFlags |= GObjFlags::GAMEOBJECT_MIRRORED; + + if ( mChkFliped->Active() ) + mCurGOFlags |= GObjFlags::GAMEOBJECT_FLIPED; + + if ( mChkBlocked->Active() ) + mCurGOFlags |= GObjFlags::GAMEOBJECT_BLOCKED; + + if ( mChkAnim->Active() ) + mCurGOFlags |= GObjFlags::GAMEOBJECT_ANIMATED; +} + +void cMapEditor::OnTypeChange( const cUIEvent * Event ) { + if ( mGOTypeList->Text() == "Shape" ) + mCurGOType = GAMEOBJECT_TYPE_SHAPE; + else if ( mGOTypeList->Text() == "ShapeEx" ) + mCurGOType = GAMEOBJECT_TYPE_SHAPEEX; + else if ( mGOTypeList->Text() == "Sprite" ) + mCurGOType = GAMEOBJECT_TYPE_SPRITE; + else + mCurGOType = MakeHash( mGOTypeList->Text() ); + + if ( NULL != mChkAnim && NULL != mGOTypeList && mChkAnim->Active() && mGOTypeList->Text() != "Sprite" ) + mChkAnim->Active( false ); +} + +void cMapEditor::ChkClickMirrored( const cUIEvent * Event ) { + UpdateGfx(); + UpdateFlags(); +} + +void cMapEditor::ChkClickFliped( const cUIEvent * Event ) { + UpdateGfx(); + UpdateFlags(); +} + +void cMapEditor::ChkClickBlocked( const cUIEvent * Event ) { + UpdateFlags(); +} + +void cMapEditor::ChkClickAnimated( const cUIEvent * Event ) { + UpdateFlags(); + + if ( mChkAnim->Active() ) { + mGOTypeList->ListBox()->SetSelected( "Sprite" ); + } +} + +void cMapEditor::AddNewGOType( const cUIEvent * Event ) { + eeNew( cUIGOTypeNew, ( cb::Make2( this, &cMapEditor::OnNewGOTypeAdded ) ) ); +} + +void cMapEditor::OnNewGOTypeAdded( std::string name, Uint32 hash ) { + if ( "" != name ) + mGOTypeList->ListBox()->AddListBoxItem( name ); +} + void cMapEditor::FillSGCombo() { cShapeGroupManager * SGM = cShapeGroupManager::instance(); std::list& Res = SGM->GetResources(); @@ -199,7 +298,7 @@ void cMapEditor::FillShapeList() { if ( items.size() ) { mShapeList->AddListBoxItems( items ); - mShapeList->SetSelected(0); + mShapeList->SetSelected( 0 ); } } } @@ -219,7 +318,13 @@ void cMapEditor::OnShapeGroupChange( const cUIEvent * Event ) { } void cMapEditor::CreateNewMap() { + eeNew( cUIMapNew, ( mUIMap, cb::Make0( this, &cMapEditor::MapCreated ) ) ); +} +void cMapEditor::MapCreated() { + mMapHScroll->Value( 0 ); + mMapVScroll->Value( 0 ); + OnMapSizeChange( NULL ); } void cMapEditor::CreateUIMap() { @@ -231,8 +336,9 @@ void cMapEditor::CreateUIMap() { mUIMap = eeNew( cUIMap, ( Params ) ); mUIMap->Visible( true ); mUIMap->Enabled( true ); - mUIMap->Map()->Create( eeSize( 50, 50 ), 16, eeSize( 32, 32 ), MAP_FLAG_DRAW_GRID | MAP_FLAG_CLAMP_BODERS | MAP_FLAG_CLIP_AREA, Params.Size ); + mUIMap->Map()->Create( eeSize( 100, 100 ), 16, eeSize( 32, 32 ), MAP_FLAG_DRAW_GRID | MAP_FLAG_CLAMP_BODERS | MAP_FLAG_CLIP_AREA, Params.Size ); mUIMap->AddEventListener( cUIEvent::EventOnSizeChange, cb::Make1( this, &cMapEditor::OnMapSizeChange ) ); + mUIMap->AddEventListener( cUIEvent::EventMouseDown, cb::Make1( this, &cMapEditor::OnMapMouseDown ) ); mMapHScroll = mTheme->CreateScrollBar( mWinContainer, eeSize( Params.Size.Width(), 15 ), eeVector2i( 0, Params.Size.Height() ), UI_ANCHOR_LEFT | UI_ANCHOR_RIGHT | UI_ANCHOR_BOTTOM ); mMapHScroll->AddEventListener( cUIEvent::EventOnValueChange, cb::Make1( this, &cMapEditor::OnScrollMapH ) ); @@ -240,7 +346,7 @@ void cMapEditor::CreateUIMap() { mMapVScroll = mTheme->CreateScrollBar( mWinContainer, eeSize( 15, Params.Size.Height() ), eeVector2i( Params.Size.Width(), 0 ), UI_ANCHOR_TOP | UI_ANCHOR_RIGHT | UI_ANCHOR_BOTTOM, true ); mMapVScroll->AddEventListener( cUIEvent::EventOnValueChange, cb::Make1( this, &cMapEditor::OnScrollMapV ) ); - OnMapSizeChange( NULL ); + MapCreated(); } void cMapEditor::OnMapSizeChange( const cUIEvent *Event ) { @@ -272,6 +378,38 @@ void cMapEditor::OnScrollMapV( const cUIEvent * Event ) { mUIMap->Map()->Offset( Off ) ; } +void cMapEditor::MapOpen( const cUIEvent * Event ) { + cUICommonDialog * CDL = reinterpret_cast ( Event->Ctrl() ); + + mUIMap->Map()->Load( CDL->GetFullPath() ); + + MapCreated(); +} + +void cMapEditor::FileMenuClick( const cUIEvent * Event ) { + if ( !Event->Ctrl()->IsTypeOrInheritsFrom( UI_TYPE_MENUITEM ) ) + return; + + const String& txt = reinterpret_cast ( Event->Ctrl() )->Text(); + + if ( "New..." == txt ) { + CreateNewMap(); + } else if ( "Open..." == txt ) { + cUICommonDialog * TGDialog = mTheme->CreateCommonDialog( NULL, eeSize(), eeVector2i(), UI_CONTROL_DEFAULT_FLAGS_CENTERED, UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL, eeSize(), 255, UI_CDL_DEFAULT_FLAGS, "*.eem" ); + + TGDialog->Title( "Open Map" ); + TGDialog->AddEventListener( cUIEvent::EventOpenFile, cb::Make1( this, &cMapEditor::MapOpen ) ); + TGDialog->Center(); + TGDialog->Show(); + } else if ( "Quit" == txt ) { + if ( mUIWindow == cUIManager::instance()->MainControl() ) { + cUIManager::instance()->GetWindow()->Close(); + } else { + mUIWindow->CloseWindow(); + } + } +} + void cMapEditor::EditMenuClick( const cUIEvent * Event ) { } @@ -286,7 +424,6 @@ void cMapEditor::ViewMenuClick( const cUIEvent * Event ) { mUIMap->Map()->DrawGrid( reinterpret_cast ( Event->Ctrl() )->Active() ); } } - void cMapEditor::MapMenuClick( const cUIEvent * Event ) { if ( !Event->Ctrl()->IsTypeOrInheritsFrom( UI_TYPE_MENUITEM ) ) return; @@ -303,6 +440,19 @@ void cMapEditor::MapMenuClick( const cUIEvent * Event ) { } } +void cMapEditor::LayerMenuClick( const cUIEvent * Event ) { + if ( !Event->Ctrl()->IsTypeOrInheritsFrom( UI_TYPE_MENUITEM ) ) + return; + + const String& txt = reinterpret_cast ( Event->Ctrl() )->Text(); + + if ( "Add Tile Layer..." == txt ) { + eeNew( cUILayerNew, ( mUIMap, MAP_LAYER_TILED, cb::Make1( this, &cMapEditor::OnLayerAdd ) ) ); + } else if ( "Add Object Layer..." == txt ) { + eeNew( cUILayerNew, ( mUIMap, MAP_LAYER_OBJECT, cb::Make1( this, &cMapEditor::OnLayerAdd ) ) ); + } +} + void cMapEditor::TextureGroupOpen( const cUIEvent * Event ) { cUICommonDialog * CDL = reinterpret_cast ( Event->Ctrl() ); @@ -312,13 +462,27 @@ void cMapEditor::TextureGroupOpen( const cUIEvent * Event ) { cTextureGroupLoader tgl( CDL->GetFullPath() ); if ( tgl.IsLoaded() ) { - FillSGCombo(); + mShapeGroupsList->ListBox()->AddListBoxItem( sgname ); } } } -void cMapEditor::LayerMenuClick( const cUIEvent * Event ) { +void cMapEditor::OnLayerAdd( cUILayerNew * UILayer ) { + bool SetSelected = ( 0 == mLayerList->ListBox()->Count() ) ? true : false; + mLayerList->ListBox()->AddListBoxItem( UILayer->Name() ); + + if ( SetSelected ) { + mCurLayer = UILayer->Layer(); + mLayerList->ListBox()->SetSelected(0); + } +} + +void cMapEditor::OnLayerSelect( const cUIEvent * Event ) { + cLayer * tLayer = mUIMap->Map()->GetLayer( mLayerList->Text() ); + + if ( NULL != tLayer ) + mCurLayer = tLayer; } void cMapEditor::WindowClose( const cUIEvent * Event ) { @@ -328,4 +492,67 @@ void cMapEditor::WindowClose( const cUIEvent * Event ) { eeDelete( this ); } +cGameObject * cMapEditor::CreateGameObject() { + cGameObject * tObj = NULL; + + if ( GAMEOBJECT_TYPE_SHAPE == mCurGOType ) { + + tObj = eeNew( cGameObjectShape, ( mCurGOFlags, mGfxPreview->Shape() ) ); + + } else if ( GAMEOBJECT_TYPE_SHAPEEX == mCurGOType ) { + + tObj = eeNew( cGameObjectShapeEx, ( mCurGOFlags, mGfxPreview->Shape() ) ); + + } else if ( GAMEOBJECT_TYPE_SPRITE == mCurGOType ) { + + if ( mChkAnim->Active() ) { + + cSprite * tAnimSprite = eeNew( cSprite, ( RemoveNumbersAtEnd( mGfxPreview->Shape()->Name() ) ) ); + tObj = eeNew( cGameObjectSprite, ( mCurGOFlags, tAnimSprite ) ); + + } else { + + cSprite * tStaticSprite = eeNew( cSprite, ( mGfxPreview->Shape() ) ); + tObj = eeNew( cGameObjectSprite, ( mCurGOFlags, tStaticSprite ) ); + + } + } else { + //! Creates an empty game object. The client will interpret the GameObject Type, and instanciate the corresponding class. + tObj = eeNew( cGameObject, ( mCurGOFlags ) ); + } + + return tObj; +} + +void cMapEditor::AddGameObjectToTile() { + cTileLayer * tLayer = reinterpret_cast ( mCurLayer ); + cMap * tMap = mUIMap->Map(); + cGameObject * tObj = CreateGameObject(); + + if ( NULL != tObj ) + tLayer->AddGameObject( tObj, tMap->GetMouseTilePos() ); +} + +void cMapEditor::RemoveGameObjectFromTile() { + cTileLayer * tLayer = reinterpret_cast ( mCurLayer ); + cMap * tMap = mUIMap->Map(); + + tLayer->RemoveGameObject( tMap->GetMouseTilePos() ); +} + +void cMapEditor::OnMapMouseDown( const cUIEvent * Event ) { + const cUIEventMouse * MEvent = reinterpret_cast ( Event ); + + if ( NULL == mCurLayer || NULL == mGfxPreview->Shape() || cUIManager::instance()->DownControl() != mUIMap ) + return; + + if ( MEvent->Flags() & EE_BUTTON_LMASK ) { + if ( mCurLayer->Type() == MAP_LAYER_TILED ) + AddGameObjectToTile(); + } else if ( MEvent->Flags() & EE_BUTTON_RMASK ) { + if ( mCurLayer->Type() == MAP_LAYER_TILED ) + RemoveGameObjectFromTile(); + } +} + }}} diff --git a/src/gaming/mapeditor/cmapeditor.hpp b/src/gaming/mapeditor/cmapeditor.hpp index fdb514afa..0ece6d73c 100644 --- a/src/gaming/mapeditor/cmapeditor.hpp +++ b/src/gaming/mapeditor/cmapeditor.hpp @@ -9,6 +9,8 @@ using namespace EE::UI; namespace EE { namespace Gaming { namespace MapEditor { +class cUILayerNew; + class cMapEditor { public: typedef cb::Callback0 MapEditorCloseCb; @@ -31,8 +33,16 @@ class cMapEditor { cShapeGroup * mCurSG; cUIScrollBar * mMapHScroll; cUIScrollBar * mMapVScroll; - cUIDropDownList * mTypeAdd; + cUIDropDownList * mGOTypeList; cUIDropDownList * mLayerList; + cUICheckBox * mChkMirrored; + cUICheckBox * mChkFliped; + cUICheckBox * mChkBlocked; + cUICheckBox * mChkAnim; + cLayer * mCurLayer; + cUIPushButton * mBtnGOTypeAdd; + Uint32 mCurGOType; + Uint32 mCurGOFlags; void WindowClose( const cUIEvent * Event ); @@ -64,13 +74,47 @@ class cMapEditor { void OnShapeGroupChange( const cUIEvent * Event ); + void MapOpen( const cUIEvent * Event ); + void OnShapeChange( const cUIEvent * Event ); + void OnTypeChange( const cUIEvent * Event ); + void OnScrollMapH( const cUIEvent * Event ); void OnScrollMapV( const cUIEvent * Event ); void OnMapSizeChange( const cUIEvent * Event ); + + void OnLayerSelect( const cUIEvent * Event ); + + void MapCreated(); + + void ChkClickMirrored( const cUIEvent * Event ); + + void ChkClickFliped( const cUIEvent * Event ); + + void ChkClickBlocked( const cUIEvent * Event ); + + void ChkClickAnimated( const cUIEvent * Event ); + + void OnMapMouseDown( const cUIEvent * Event ); + + void OnLayerAdd( cUILayerNew * UILayer ); + + void AddNewGOType( const cUIEvent * Event ); + + void OnNewGOTypeAdded( std::string name, Uint32 hash ); + + void UpdateGfx(); + + void UpdateFlags(); + + void AddGameObjectToTile(); + + void RemoveGameObjectFromTile(); + + cGameObject * CreateGameObject(); }; }}} diff --git a/src/gaming/mapeditor/cuigotypenew.cpp b/src/gaming/mapeditor/cuigotypenew.cpp new file mode 100644 index 000000000..e8b63548d --- /dev/null +++ b/src/gaming/mapeditor/cuigotypenew.cpp @@ -0,0 +1,63 @@ +#include "cuigotypenew.hpp" +#include "../../ui/cuitextinput.hpp" + +namespace EE { namespace Gaming { namespace MapEditor { + +cUIGOTypeNew::cUIGOTypeNew( cb::Callback2 Cb ) : + mUITheme( NULL ), + mUIWindow( NULL ), + mUIInput( NULL ), + mCb( Cb ) +{ + mUITheme = cUIThemeManager::instance()->DefaultTheme(); + + if ( NULL == mUITheme ) + return; + + mUIWindow = mUITheme->CreateWindow( NULL, eeSize( 278, 114 ), eeVector2i(), UI_CONTROL_DEFAULT_FLAGS_CENTERED, UI_WIN_DEFAULT_FLAGS | UI_WIN_MODAL ); + mUIWindow->AddEventListener( cUIEvent::EventOnWindowClose, cb::Make1( this, &cUIGOTypeNew::WindowClose ) ); + mUIWindow->Title( "Add GameObject Type" ); + + Int32 InitialY = 16; + Int32 DistFromTitle = 18; + + cUITextBox * Txt = mUITheme->CreateTextBox( mUIWindow->Container(), eeSize(), eeVector2i( 16, InitialY ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + Txt->Text( "GameObject Type Name" ); + + mUIInput = mUITheme->CreateTextInput( mUIWindow->Container(), eeSize( 120, 22 ), eeVector2i( Txt->Pos().x + DistFromTitle, Txt->Pos().y + DistFromTitle ), UI_CONTROL_DEFAULT_FLAGS | UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_AUTO_SIZE, true, 64 ); + + cUIPushButton * OKButton = mUITheme->CreatePushButton( mUIWindow->Container(), eeSize( 80, 22 ), eeVector2i(), UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, mUITheme->GetIconByName( "add" ) ); + OKButton->Pos( mUIWindow->Container()->Size().Width() - OKButton->Size().Width() - 4, mUIWindow->Container()->Size().Height() - OKButton->Size().Height() - 4 ); + OKButton->AddEventListener( cUIEvent::EventMouseClick, cb::Make1( this, &cUIGOTypeNew::OKClick ) ); + OKButton->Text( "Add" ); + + cUIPushButton * CancelButton = mUITheme->CreatePushButton( mUIWindow->Container(), OKButton->Size(), eeVector2i( OKButton->Pos().x - OKButton->Size().Width() - 4, OKButton->Pos().y ), UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, mUITheme->GetIconByName( "cancel" ) ); + CancelButton->AddEventListener( cUIEvent::EventMouseClick, cb::Make1( this, &cUIGOTypeNew::CancelClick ) ); + CancelButton->Text( "Cancel" ); + + mUIWindow->Center(); + mUIWindow->Show(); +} + +cUIGOTypeNew::~cUIGOTypeNew() { + +} + +void cUIGOTypeNew::OKClick( const cUIEvent * Event ) { + if ( mUIInput->Text().size() ) { + if ( mCb.IsSet() ) + mCb( mUIInput->Text().ToUtf8(), MakeHash( mUIInput->Text().ToUtf8() ) ); + } + + mUIWindow->CloseWindow(); +} + +void cUIGOTypeNew::CancelClick( const cUIEvent * Event ) { + mUIWindow->CloseWindow(); +} + +void cUIGOTypeNew::WindowClose( const cUIEvent * Event ) { + eeDelete( this ); +} + +}}} diff --git a/src/gaming/mapeditor/cuigotypenew.hpp b/src/gaming/mapeditor/cuigotypenew.hpp new file mode 100644 index 000000000..88b097101 --- /dev/null +++ b/src/gaming/mapeditor/cuigotypenew.hpp @@ -0,0 +1,31 @@ +#ifndef EE_GAMINGCUIGOTYPENEW_HPP +#define EE_GAMINGCUIGOTYPENEW_HPP + +#include "base.hpp" +#include "../../ui/cuiwindow.hpp" + +using namespace EE::UI; + +namespace EE { namespace Gaming { namespace MapEditor { + +class cUIGOTypeNew { + public: + cUIGOTypeNew( cb::Callback2 Cb ); + + virtual ~cUIGOTypeNew(); + protected: + cUITheme * mUITheme; + cUIWindow * mUIWindow; + cUITextInput * mUIInput; + cb::Callback2 mCb; + + void WindowClose( const cUIEvent * Event ); + + void CancelClick( const cUIEvent * Event ); + + void OKClick( const cUIEvent * Event ); +}; + +}}} + +#endif diff --git a/src/gaming/mapeditor/cuilayernew.cpp b/src/gaming/mapeditor/cuilayernew.cpp new file mode 100644 index 000000000..91178b0b6 --- /dev/null +++ b/src/gaming/mapeditor/cuilayernew.cpp @@ -0,0 +1,88 @@ +#include "cuilayernew.hpp" +#include "../../ui/cuitextinput.hpp" + +namespace EE { namespace Gaming { namespace MapEditor { + +cUILayerNew::cUILayerNew( cUIMap * Map, EE_LAYER_TYPE Type, cb::Callback1 NewLayerCb ) : + mTheme( NULL ), + mUIMap( Map ), + mType( Type ), + mNewLayerCb( NewLayerCb ), + mUIWindow( NULL ), + mLayer( NULL ) +{ + mTheme = cUIThemeManager::instance()->DefaultTheme(); + + if ( NULL == mTheme ) + return; + + mUIWindow = mTheme->CreateWindow( NULL, eeSize( 278, 114 ), eeVector2i(), UI_CONTROL_DEFAULT_FLAGS_CENTERED, UI_WIN_DEFAULT_FLAGS | UI_WIN_MODAL ); + mUIWindow->AddEventListener( cUIEvent::EventOnWindowClose, cb::Make1( this, &cUILayerNew::WindowClose ) ); + + if ( MAP_LAYER_TILED == mType ) + mUIWindow->Title( "New Tile Layer" ); + else if ( MAP_LAYER_OBJECT == mType ) + mUIWindow->Title( "New Object Layer" ); + + Int32 InitialY = 16; + Int32 DistFromTitle = 18; + + cUITextBox * Txt = mTheme->CreateTextBox( mUIWindow->Container(), eeSize(), eeVector2i( 16, InitialY ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + Txt->Text( "Layer Name" ); + + mUILayerName = mTheme->CreateTextInput( mUIWindow->Container(), eeSize( 120, 22 ), eeVector2i( Txt->Pos().x + DistFromTitle, Txt->Pos().y + DistFromTitle ), UI_CONTROL_DEFAULT_FLAGS | UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_AUTO_SIZE, true, 64 ); + mUILayerName->Text( "Layer " + toStr( mUIMap->Map()->LayerCount() + 1 ) ); + + cUIPushButton * OKButton = mTheme->CreatePushButton( mUIWindow->Container(), eeSize( 80, 22 ), eeVector2i(), UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, mTheme->GetIconByName( "add" ) ); + OKButton->Pos( mUIWindow->Container()->Size().Width() - OKButton->Size().Width() - 4, mUIWindow->Container()->Size().Height() - OKButton->Size().Height() - 4 ); + OKButton->AddEventListener( cUIEvent::EventMouseClick, cb::Make1( this, &cUILayerNew::OKClick ) ); + OKButton->Text( "Add" ); + + cUIPushButton * CancelButton = mTheme->CreatePushButton( mUIWindow->Container(), OKButton->Size(), eeVector2i( OKButton->Pos().x - OKButton->Size().Width() - 4, OKButton->Pos().y ), UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, mTheme->GetIconByName( "cancel" ) ); + CancelButton->AddEventListener( cUIEvent::EventMouseClick, cb::Make1( this, &cUILayerNew::CancelClick ) ); + CancelButton->Text( "Cancel" ); + + mUIWindow->Center(); + mUIWindow->Show(); +} + +cUILayerNew::~cUILayerNew() { + +} + +void cUILayerNew::OKClick( const cUIEvent * Event ) { + if ( mUILayerName->Text().size() ) { + mLayer = mUIMap->Map()->AddLayer( mType, 0, mUILayerName->Text() ); + + if ( mNewLayerCb.IsSet() ) + mNewLayerCb( this ); + } + + mUIWindow->CloseWindow(); +} + +void cUILayerNew::CancelClick( const cUIEvent * Event ) { + mUIWindow->CloseWindow(); +} + +void cUILayerNew::WindowClose( const cUIEvent * Event ) { + eeDelete( this ); +} + +const EE_LAYER_TYPE& cUILayerNew::Type() const { + return mType; +} + +cUITextInput * cUILayerNew::UILayerName() const { + return mUILayerName; +} + +const String& cUILayerNew::Name() const { + return mUILayerName->Text(); +} + +cLayer * cUILayerNew::Layer() const { + return mLayer; +} + +}}} diff --git a/src/gaming/mapeditor/cuilayernew.hpp b/src/gaming/mapeditor/cuilayernew.hpp new file mode 100644 index 000000000..5b096736b --- /dev/null +++ b/src/gaming/mapeditor/cuilayernew.hpp @@ -0,0 +1,43 @@ +#ifndef EE_GAMINGCUILAYERNEW_HPP +#define EE_GAMINGCUILAYERNEW_HPP + +#include "base.hpp" +#include "../../ui/cuiwindow.hpp" +#include "cuimap.hpp" + +using namespace EE::UI; + +namespace EE { namespace Gaming { namespace MapEditor { + +class cUILayerNew { + public: + cUILayerNew( cUIMap * Map, EE_LAYER_TYPE Type, cb::Callback1 NewLayerCb = cb::Callback1() ); + + virtual ~cUILayerNew(); + + const EE_LAYER_TYPE& Type() const; + + cUITextInput * UILayerName() const; + + const String& Name() const; + + cLayer * Layer() const; + protected: + cUITheme * mTheme; + cUIMap * mUIMap; + EE_LAYER_TYPE mType; + cb::Callback1 mNewLayerCb; + cUIWindow * mUIWindow; + cUITextInput * mUILayerName; + cLayer * mLayer; + + void WindowClose( const cUIEvent * Event ); + + void CancelClick( const cUIEvent * Event ); + + void OKClick( const cUIEvent * Event ); +}; + +}}} + +#endif diff --git a/src/gaming/mapeditor/cuimapnew.cpp b/src/gaming/mapeditor/cuimapnew.cpp new file mode 100644 index 000000000..38c87a8d4 --- /dev/null +++ b/src/gaming/mapeditor/cuimapnew.cpp @@ -0,0 +1,100 @@ +#include "cuimapnew.hpp" +#include "../../ui/cuispinbox.hpp" + +namespace EE { namespace Gaming { namespace MapEditor { + +cUIMapNew::cUIMapNew( cUIMap * Map, cb::Callback0 NewMapCb ) : + mTheme( NULL ), + mUIWindow( NULL ), + mUIMap( Map ), + mNewMapCb( NewMapCb ) +{ + mTheme = cUIThemeManager::instance()->DefaultTheme(); + + if ( NULL == mTheme ) + return; + + mUIWindow = mTheme->CreateWindow( NULL, eeSize( 278, 214 ), eeVector2i(), UI_CONTROL_DEFAULT_FLAGS_CENTERED, UI_WIN_DEFAULT_FLAGS | UI_WIN_MODAL ); + mUIWindow->AddEventListener( cUIEvent::EventOnWindowClose, cb::Make1( this, &cUIMapNew::WindowClose ) ); + mUIWindow->Title( "New Map" ); + + Int32 InitialY = 16; + Int32 DistFromTitle = 18; + + cUITextBox * Txt = mTheme->CreateTextBox( mUIWindow->Container(), eeSize(), eeVector2i( 16, InitialY ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + Txt->Text( "Map size" ); + + Txt = mTheme->CreateTextBox( mUIWindow->Container(), eeSize( 46, 24 ), eeVector2i( Txt->Pos().x + DistFromTitle, Txt->Pos().y + DistFromTitle ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW ); + Txt->Text( "Width:" ); + + mUIMapWidth = mTheme->CreateSpinBox( mUIWindow->Container(), eeSize( 53, 24 ), eeVector2i( Txt->Pos().x + Txt->Size().Width(), Txt->Pos().y ), UI_CONTROL_DEFAULT_FLAGS, 25, false ); + mUIMapWidth->MinValue(1); + + Txt = mTheme->CreateTextBox( mUIWindow->Container(), eeSize( 46, 24 ), eeVector2i( Txt->Pos().x, Txt->Pos().y + Txt->Size().Height() + 8 ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW ); + Txt->Text( "Height:" ); + + mUIMapHeight = mTheme->CreateSpinBox( mUIWindow->Container(), eeSize( 53, 24 ), eeVector2i( Txt->Pos().x + Txt->Size().Width(), Txt->Pos().y ), UI_CONTROL_DEFAULT_FLAGS, 18, false ); + mUIMapHeight->MinValue(1); + + Txt = mTheme->CreateTextBox( mUIWindow->Container(), eeSize(), eeVector2i( mUIWindow->Container()->Size().Width() / 2, InitialY ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + Txt->Text( "Tile size" ); + + Txt = mTheme->CreateTextBox( mUIWindow->Container(), eeSize( 46, 24 ), eeVector2i( Txt->Pos().x + DistFromTitle, Txt->Pos().y + DistFromTitle ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW ); + Txt->Text( "Width:" ); + + mUIMapTWidth = mTheme->CreateSpinBox( mUIWindow->Container(), eeSize( 53, 24 ), eeVector2i( Txt->Pos().x + Txt->Size().Width(), Txt->Pos().y ), UI_CONTROL_DEFAULT_FLAGS, 32, false ); + mUIMapTWidth->MinValue(1); + + Txt = mTheme->CreateTextBox( mUIWindow->Container(), eeSize( 46, 24 ), eeVector2i( Txt->Pos().x, Txt->Pos().y + Txt->Size().Height() + 8 ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW ); + Txt->Text( "Height:" ); + + mUIMapTHeight = mTheme->CreateSpinBox( mUIWindow->Container(), eeSize( 53, 24 ), eeVector2i( Txt->Pos().x + Txt->Size().Width(), Txt->Pos().y ), UI_CONTROL_DEFAULT_FLAGS, 32, false ); + mUIMapTHeight->MinValue(1); + + Txt = mTheme->CreateTextBox( mUIWindow->Container(), eeSize(), eeVector2i( 16, mUIWindow->Container()->Size().Height() / 2 ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + Txt->Text( "Max layers" ); + + mUIMapMaxLayers = mTheme->CreateSpinBox( mUIWindow->Container(), eeSize( 53, 24 ), eeVector2i( Txt->Pos().x + DistFromTitle, Txt->Pos().y + DistFromTitle ), UI_CONTROL_DEFAULT_FLAGS, 8, false ); + + cUIPushButton * OKButton = mTheme->CreatePushButton( mUIWindow->Container(), eeSize( 80, 22 ), eeVector2i(), UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, mTheme->GetIconByName( "ok" ) ); + OKButton->Pos( mUIWindow->Container()->Size().Width() - OKButton->Size().Width() - 4, mUIWindow->Container()->Size().Height() - OKButton->Size().Height() - 4 ); + OKButton->AddEventListener( cUIEvent::EventMouseClick, cb::Make1( this, &cUIMapNew::OKClick ) ); + OKButton->Text( "OK" ); + + cUIPushButton * CancelButton = mTheme->CreatePushButton( mUIWindow->Container(), OKButton->Size(), eeVector2i( OKButton->Pos().x - OKButton->Size().Width() - 4, OKButton->Pos().y ), UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, mTheme->GetIconByName( "cancel" ) ); + CancelButton->AddEventListener( cUIEvent::EventMouseClick, cb::Make1( this, &cUIMapNew::CancelClick ) ); + CancelButton->Text( "Cancel" ); + + mUIWindow->Center(); + mUIWindow->Show(); +} + +cUIMapNew::~cUIMapNew() { +} + +void cUIMapNew::OKClick( const cUIEvent * Event ) { + Int32 w = static_cast( mUIMapWidth->Value() ); + Int32 h = static_cast( mUIMapHeight->Value() ); + Int32 tw = static_cast( mUIMapTWidth->Value() ); + Int32 th = static_cast( mUIMapTHeight->Value() ); + Int32 ml = static_cast( mUIMapMaxLayers->Value() ); + + if ( w > 0 && h > 0 && tw > 0 && th > 0 && ml > 0 ) { + mUIMap->Map()->Create( eeSize( w, h ), ml, eeSize( tw, th ), MAP_FLAG_CLAMP_BODERS | MAP_FLAG_CLIP_AREA | MAP_FLAG_DRAW_GRID, mUIMap->Map()->ViewSize() ); + + if ( mNewMapCb.IsSet() ) + mNewMapCb(); + } + + mUIWindow->CloseWindow(); +} + +void cUIMapNew::CancelClick( const cUIEvent * Event ) { + mUIWindow->CloseWindow(); +} + +void cUIMapNew::WindowClose( const cUIEvent * Event ) { + eeDelete( this ); +} + +}}} diff --git a/src/gaming/mapeditor/cuimapnew.hpp b/src/gaming/mapeditor/cuimapnew.hpp new file mode 100644 index 000000000..27fc70a16 --- /dev/null +++ b/src/gaming/mapeditor/cuimapnew.hpp @@ -0,0 +1,37 @@ +#ifndef EE_GAMINGCUIMAPNEW_HPP +#define EE_GAMINGCUIMAPNEW_HPP + +#include "base.hpp" +#include "../../ui/cuiwindow.hpp" +#include "cuimap.hpp" + +using namespace EE::UI; + +namespace EE { namespace Gaming { namespace MapEditor { + +class cUIMapNew { + public: + cUIMapNew( cUIMap * Map, cb::Callback0 NewMapCb = cb::Callback0() ); + + virtual ~cUIMapNew(); + protected: + cUITheme * mTheme; + cUIWindow * mUIWindow; + cUIMap * mUIMap; + cUISpinBox * mUIMapWidth; + cUISpinBox * mUIMapHeight; + cUISpinBox * mUIMapTWidth; + cUISpinBox * mUIMapTHeight; + cUISpinBox * mUIMapMaxLayers; + cb::Callback0 mNewMapCb; + + void WindowClose( const cUIEvent * Event ); + + void CancelClick( const cUIEvent * Event ); + + void OKClick( const cUIEvent * Event ); +}; + +}}} + +#endif diff --git a/src/gaming/maphelper.hpp b/src/gaming/maphelper.hpp index 18821bda9..8def09014 100644 --- a/src/gaming/maphelper.hpp +++ b/src/gaming/maphelper.hpp @@ -19,7 +19,7 @@ enum EE_GAMEOBJECT_TYPE { GAMEOBJECT_TYPE_SHAPE, GAMEOBJECT_TYPE_SHAPEEX, GAMEOBJECT_TYPE_SPRITE, - GAMEOBJECT_TYPE_USER = 100 + GAMEOBJECT_TYPE_USER = 10 }; enum EE_LAYER_TYPE { diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index 6424bf039..a42641494 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -115,7 +115,7 @@ void cEETest::Init() { if ( Mus->OpenFromPack( &PAK, "music.ogg" ) ) { Mus->Loop(true); - Mus->Volume( 100.f ); + Mus->Volume( 0.f ); Mus->Play(); } @@ -173,8 +173,6 @@ void cEETest::CreateAquaTextureAtlas() { return; #endif - //cUIThemeManager::instance()->Add( cUITheme::LoadFromPath( MyPath + "data/aqua/", "aqua", "aqua" ) ); - std::string tgpath( MyPath + "data/aquatg/aqua" ); std::string Path( MyPath + "data/aqua" ); @@ -266,6 +264,8 @@ void cEETest::CreateUI() { cUIManager::instance()->Init(); //UI_MANAGER_HIGHLIGHT_FOCUS + //cUIThemeManager::instance()->Add( cUITheme::LoadFromPath( MyPath + "data/aqua/", "aqua", "aqua" ) ); + cTextureGroupLoader tgl( MyPath + "data/aquatg/aqua.etg" ); tgl.GetTexture()->TextureFilter( TEX_FILTER_NEAREST ); @@ -335,10 +335,10 @@ void cEETest::CreateUI() { cUIPushButton::CreateParams ButtonParams; ButtonParams.Parent( C ); - ButtonParams.Flags = UI_VALIGN_CENTER | UI_HALIGN_CENTER; + ButtonParams.Flags = UI_VALIGN_CENTER | UI_HALIGN_CENTER | UI_AUTO_SIZE; ButtonParams.PosSet( 225, 216 ); - ButtonParams.Size = eeSize( 90, 22 ); - ButtonParams.SetIcon( cGlobalShapeGroup::instance()->GetByName( "aqua_button_ok" ) ); + ButtonParams.Size = eeSize( 90, 0 ); + ButtonParams.SetIcon( mTheme->GetIconByName( "ok" ) ); cUIPushButton * Button = eeNew( cUIPushButton, ( ButtonParams ) ); Button->Visible( true ); Button->Enabled( true ); @@ -472,8 +472,8 @@ void cEETest::CreateUI() { mComboBox->ListBox()->SetSelected( 0 ); Menu = mTheme->CreatePopUpMenu(); - Menu->Add( "New", cGlobalShapeGroup::instance()->GetByName( "aqua_button_ok" ) ); - Menu->Add( "Open..." ); + Menu->Add( "New", mTheme->GetIconByName( "document-new" ) ); + Menu->Add( "Open...", mTheme->GetIconByName( "document-open" ) ); Menu->AddSeparator(); Menu->Add( "Show Screen 1" ); Menu->Add( "Show Screen 2" ); @@ -539,7 +539,7 @@ void cEETest::CreateUI() { cUIGfx::CreateParams TxtGfxParams; TxtGfxParams.Flags = UI_VALIGN_CENTER | UI_HALIGN_CENTER; - TxtGfxParams.Shape = cGlobalShapeGroup::instance()->GetByName( "aqua_button_ok" ); + TxtGfxParams.Shape = mTheme->GetIconByName( "ok" ); for ( Uint32 i = 0; i < 100; i++ ) { cUIGridCell * Cell = eeNew( cUIGridCell, ( CellParams ) ); @@ -708,7 +708,7 @@ void cEETest::ButtonClick( const cUIEvent * Event ) { if ( MouseEvent->Flags() & EE_BUTTONS_LRM ) { cUIGfx::CreateParams GfxParams; GfxParams.Parent( cUIManager::instance()->MainControl() ); - GfxParams.Shape = cShapeGroupManager::instance()->GetShapeByName( "aqua_button_ok" ); + GfxParams.Shape = mTheme->GetIconByName( "ok" ); cUIGfx * Gfx = eeNew( cUIGfx, ( GfxParams ) ); Gfx->Visible( true ); Gfx->Enabled( false ); @@ -852,8 +852,6 @@ void cEETest::LoadTextures() { mBlindy.AddFramesByPattern( "rn" ); mBlindy.Position( 320.f, 0.f ); - cGlobalShapeGroup::instance()->Add( eeNew( Graphics::cShape, ( TF->Load( MyPath + "data/aqua/aqua_button_ok.png" ), "aqua_button_ok" ) ) ); - mBoxSprite = eeNew( cSprite, () ); mBoxSprite->CreateStatic( cGlobalShapeGroup::instance()->Add( eeNew( Graphics::cShape, ( TN[3], "ilmare" ) ) ) ); mCircleSprite = eeNew( cSprite, () ); diff --git a/src/ui/cuiaquatheme.cpp b/src/ui/cuiaquatheme.cpp index bbea2c819..25c4e0e2a 100644 --- a/src/ui/cuiaquatheme.cpp +++ b/src/ui/cuiaquatheme.cpp @@ -28,7 +28,7 @@ cUIPopUpMenu * cUIAquaTheme::CreatePopUpMenu( cUIControl * Parent, const eeSize& if ( UseDefaultThemeValues() ) { MenuParams.MinWidth = 100; - MenuParams.MinSpaceForIcons = 16; + MenuParams.MinSpaceForIcons = 24; MenuParams.MinRightMargin = 8; } diff --git a/src/ui/cuicheckbox.cpp b/src/ui/cuicheckbox.cpp index 758978578..dec55e306 100644 --- a/src/ui/cuicheckbox.cpp +++ b/src/ui/cuicheckbox.cpp @@ -1,4 +1,5 @@ #include "cuicheckbox.hpp" +#include "cuimanager.hpp" namespace EE { namespace UI { @@ -66,6 +67,17 @@ void cUICheckBox::DoAfterSetTheme() { Padding( eeRecti(0,0,0,0) ); } +void cUICheckBox::AutoSize() { + cUITextBox::AutoSize(); + + if ( mFlags & UI_AUTO_SIZE ) { + mActiveButton->CenterVertical(); + mInactiveButton->CenterVertical(); + + mSize.Width( (eeInt)mTextCache->GetTextWidth() + mActiveButton->Size().Width() ); + } +} + void cUICheckBox::OnSizeChange() { cUITextBox::OnSizeChange(); @@ -76,8 +88,13 @@ void cUICheckBox::OnSizeChange() { Uint32 cUICheckBox::OnMessage( const cUIMessage * Msg ) { switch ( Msg->Msg() ) { case cUIMessage::MsgClick: { - if ( Msg->Flags() & EE_BUTTON_LMASK ) + if ( Msg->Flags() & EE_BUTTON_LMASK ) { SwitchState(); + } + + if ( Msg->Sender() == mActiveButton || Msg->Sender() == mInactiveButton ) { + SendMouseEvent( cUIEvent::EventMouseClick, cUIManager::instance()->GetMousePos(), cUIManager::instance()->PressTrigger() ); + } return 1; } diff --git a/src/ui/cuicheckbox.hpp b/src/ui/cuicheckbox.hpp index c65a214db..77a60f317 100644 --- a/src/ui/cuicheckbox.hpp +++ b/src/ui/cuicheckbox.hpp @@ -42,6 +42,8 @@ class EE_API cUICheckBox : public cUITextBox { virtual Uint32 OnMessage( const cUIMessage * Msg ); void DoAfterSetTheme(); + + virtual void AutoSize(); }; }} diff --git a/src/ui/cuicommondialog.cpp b/src/ui/cuicommondialog.cpp index 5809efb46..8204a8f2d 100644 --- a/src/ui/cuicommondialog.cpp +++ b/src/ui/cuicommondialog.cpp @@ -43,9 +43,9 @@ cUICommonDialog::cUICommonDialog( const cUICommonDialog::CreateParams& Params ) cUIPushButton::CreateParams ButtonParams; ButtonParams.Parent( Container() ); - ButtonParams.PosSet( Container()->Size().Width() - 81, Container()->Size().Height() - 54 ); - ButtonParams.SizeSet( 75, 22 ); - ButtonParams.Flags = UI_HALIGN_CENTER | UI_ANCHOR_RIGHT | UI_VALIGN_CENTER; + ButtonParams.PosSet( Container()->Size().Width() - 86, Container()->Size().Height() - 54 ); + ButtonParams.SizeSet( 80, 22 ); + ButtonParams.Flags = UI_HALIGN_CENTER | UI_ANCHOR_RIGHT | UI_VALIGN_CENTER | UI_AUTO_SIZE; mButtonOpen = eeNew( cUIPushButton, ( ButtonParams ) ); mButtonOpen->Visible( true ); mButtonOpen->Enabled( true ); @@ -66,7 +66,7 @@ cUICommonDialog::cUICommonDialog( const cUICommonDialog::CreateParams& Params ) TInputParams.Flags = UI_AUTO_PADDING | UI_CLIP_ENABLE | UI_ANCHOR_RIGHT | UI_ANCHOR_LEFT | UI_ANCHOR_TOP | UI_VALIGN_CENTER; TInputParams.PosSet( 70, 6 ); TInputParams.SizeSet( Container()->Size().Width() - TInputParams.Pos.x - 42, 22 ); - mPath = eeNew( cUITextInput, ( TInputParams ) ); + mPath = eeNew( cUITextInput, ( TInputParams ) ); mPath->AddEventListener( cUIEvent::EventOnPressEnter, cb::Make1( this, &cUICommonDialog::OnPressEnter ) ); mPath->Visible( true ); mPath->Enabled( true ); @@ -131,6 +131,17 @@ cUICommonDialog::cUICommonDialog( const cUICommonDialog::CreateParams& Params ) cUICommonDialog::~cUICommonDialog() { } +void cUICommonDialog::SetTheme( cUITheme * Theme ) { + cUIWindow::SetTheme( Theme ); + + cShape * Icon = Theme->GetIconByName( "go-up" ); + + if ( NULL != Icon ) { + mButtonUp->Text( "" ); + mButtonUp->Icon( Icon ); + } +} + void cUICommonDialog::RefreshFolder() { std::vector flist = FilesGetInPath( String( mCurPath ) ); std::vector files; @@ -243,16 +254,16 @@ void cUICommonDialog::Open() { CloseWindow(); } -} - -void cUICommonDialog::OnPressEnter( const cUIEvent * Event ) { - if ( IsDirectory( mPath->Text() ) ) { - std::string tpath = mPath->Text(); - DirPathAddSlashAtEnd( tpath ); - mPath->Text( tpath ); +} + +void cUICommonDialog::OnPressEnter( const cUIEvent * Event ) { + if ( IsDirectory( mPath->Text() ) ) { + std::string tpath = mPath->Text(); + DirPathAddSlashAtEnd( tpath ); + mPath->Text( tpath ); mCurPath = mPath->Text(); - RefreshFolder(); - } + RefreshFolder(); + } } void cUICommonDialog::AddFilePattern( std::string pattern, bool select ) { diff --git a/src/ui/cuicommondialog.hpp b/src/ui/cuicommondialog.hpp index 0e23c0a82..a86bdbeb5 100644 --- a/src/ui/cuicommondialog.hpp +++ b/src/ui/cuicommondialog.hpp @@ -34,6 +34,8 @@ class cUICommonDialog : public cUIWindow { ~cUICommonDialog(); + virtual void SetTheme( cUITheme * Theme ); + void RefreshFolder(); virtual Uint32 OnMessage( const cUIMessage *Msg ); diff --git a/src/ui/cuidropdownlist.cpp b/src/ui/cuidropdownlist.cpp index db00f35e3..5bf18d640 100644 --- a/src/ui/cuidropdownlist.cpp +++ b/src/ui/cuidropdownlist.cpp @@ -52,36 +52,7 @@ void cUIDropDownList::OnSizeChange() { void cUIDropDownList::AutoSizeControl() { if ( mFlags & UI_AUTO_SIZE ) { - if ( NULL != mSkinState && NULL != mSkinState->GetSkin() ) { - if ( mSkinState->GetSkin()->GetType() == cUISkin::UISkinComplex ) { - Uint32 tHeight = 0; - - cUISkinComplex * tComplex = reinterpret_cast ( mSkinState->GetSkin() ); - - cShape * tShape = tComplex->GetShapeSide( cUISkinState::StateNormal, cUISkinComplex::Center ); - - if ( NULL != tShape ) - tHeight += tShape->RealSize().Height(); - - tShape = tComplex->GetShapeSide( cUISkinState::StateNormal, cUISkinComplex::Up ); - - if ( NULL != tShape ) - tHeight += tShape->RealSize().Height(); - - tShape = tComplex->GetShapeSide( cUISkinState::StateNormal, cUISkinComplex::Down ); - - if ( NULL != tShape ) - tHeight += tShape->RealSize().Height(); - - Size( mSize.x, tHeight ); - } else { - cShape * tShape = mSkinState->GetSkin()->GetShape( cUISkinState::StateNormal ); - - if ( NULL != tShape ) { - Size( mSize.x, tShape->RealSize().Height() ); - } - } - } + Size( mSize.x, GetSkinShapeSize().Height() ); } } diff --git a/src/ui/cuilistbox.cpp b/src/ui/cuilistbox.cpp index 35428918d..274efeaff 100644 --- a/src/ui/cuilistbox.cpp +++ b/src/ui/cuilistbox.cpp @@ -640,7 +640,16 @@ std::list cUIListBox::GetItemsSelected() { Uint32 cUIListBox::GetItemIndex( cUIListBoxItem * Item ) { for ( Uint32 i = 0; i < mItems.size(); i++ ) { - if ( mItems[i] == Item ) + if ( Item == mItems[i] ) + return i; + } + + return 0xFFFFFFFF; +} + +Uint32 cUIListBox::GetItemIndex( const String& Text ) { + for ( Uint32 i = 0; i < mTexts.size(); i++ ) { + if ( Text == mTexts[i] ) return i; } @@ -731,6 +740,10 @@ Uint32 cUIListBox::Count() { return (Uint32)mItems.size(); } +void cUIListBox::SetSelected( const String& Text ) { + SetSelected( GetItemIndex( Text ) ); +} + void cUIListBox::SetSelected( Uint32 Index ) { if ( Index < mItems.size() ) { if ( IsMultiSelect() ) { @@ -739,8 +752,13 @@ void cUIListBox::SetSelected( Uint32 Index ) { return; } } else { - if ( mSelected.size() ) + if ( mSelected.size() ) { + if ( NULL != mItems[ mSelected.front() ] ) { + mItems[ mSelected.front() ]->Unselect(); + } + mSelected.clear(); + } } mSelected.push_back( Index ); @@ -764,15 +782,13 @@ void cUIListBox::SelectPrev() { if ( NULL == mItems[ SelIndex ] ) CreateItemIndex( SelIndex ); - mItems[ mSelected.front() ]->Unselect(); - if ( mItems[ SelIndex ]->Pos().y < 0 ) { mVScrollBar->Value( (eeFloat)( SelIndex * mRowHeight ) / (eeFloat)( ( mItems.size() - 1 ) * mRowHeight ) ); mItems[ SelIndex ]->SetFocus(); } - mItems[ SelIndex ]->Select(); + SetSelected( SelIndex ); } } } @@ -788,15 +804,13 @@ void cUIListBox::SelectNext() { if ( NULL == mItems[ SelIndex ] ) CreateItemIndex( SelIndex ); - mItems[ mSelected.front() ]->Unselect(); - if ( mItems[ SelIndex ]->Pos().y + (Int32)RowHeight() > mContainer->Size().Height() ) { mVScrollBar->Value( (eeFloat)( SelIndex * mRowHeight ) / (eeFloat)( ( mItems.size() - 1 ) * mRowHeight ) ); mItems[ SelIndex ]->SetFocus(); } - mItems[ SelIndex ]->Select(); + SetSelected( SelIndex ); } } } @@ -816,29 +830,25 @@ Uint32 cUIListBox::OnKeyDown( const cUIEventKey &Event ) { mLastTickMove = eeGetTicks(); SelectPrev(); - } else if ( KEY_PAGEUP == Event.KeyCode() ) { + } else if ( KEY_HOME == Event.KeyCode() ) { mLastTickMove = eeGetTicks(); if ( mSelected.front() != 0 ) { - mItems[ mSelected.front() ]->Unselect(); - mVScrollBar->Value( 0 ); mItems[ 0 ]->SetFocus(); - mItems[ 0 ]->Select(); + SetSelected( 0 ); } - } else if ( KEY_PAGEDOWN == Event.KeyCode() ) { + } else if ( KEY_END == Event.KeyCode() ) { mLastTickMove = eeGetTicks(); if ( mSelected.front() != Count() - 1 ) { - mItems[ mSelected.front() ]->Unselect(); - mVScrollBar->Value( 1 ); mItems[ Count() - 1 ]->SetFocus(); - mItems[ Count() - 1 ]->Select(); + SetSelected( Count() - 1 ); } } } diff --git a/src/ui/cuilistbox.hpp b/src/ui/cuilistbox.hpp index 4fe025e69..9b1c9f9c2 100644 --- a/src/ui/cuilistbox.hpp +++ b/src/ui/cuilistbox.hpp @@ -82,6 +82,8 @@ class EE_API cUIListBox : public cUIComplexControl { Uint32 GetItemIndex( cUIListBoxItem * Item ); + Uint32 GetItemIndex( const String& Text ); + cUIListBoxItem * GetItemSelected(); String GetItemSelectedText() const; @@ -128,6 +130,8 @@ class EE_API cUIListBox : public cUIComplexControl { void SetSelected( Uint32 Index ); + void SetSelected( const String& Text ); + void SelectPrev(); void SelectNext(); @@ -167,7 +171,7 @@ class EE_API cUIListBox : public cUIComplexControl { std::list mSelected; std::vector mItems; - std::vector mTexts; + std::vector mTexts; void UpdateScroll( bool FromScrollChange = false ); diff --git a/src/ui/cuilistboxitem.cpp b/src/ui/cuilistboxitem.cpp index 70f3e5f3b..fb74320d2 100644 --- a/src/ui/cuilistboxitem.cpp +++ b/src/ui/cuilistboxitem.cpp @@ -80,7 +80,6 @@ void cUIListBoxItem::Update() { if ( IsMouseOver() ) { if ( Flags & EE_BUTTONS_WUWD && LBParent->VerticalScrollBar()->Visible() ) { LBParent->VerticalScrollBar()->Slider()->ManageClick( Flags ); - //LBParent->UpdateScroll( true ); } } } diff --git a/src/ui/cuimanager.cpp b/src/ui/cuimanager.cpp index 21fd2de5f..34de5d3bf 100644 --- a/src/ui/cuimanager.cpp +++ b/src/ui/cuimanager.cpp @@ -219,6 +219,10 @@ void cUIManager::Update() { mControl->CheckClose(); } +cUIControl * cUIManager::DownControl() const { + return mDownControl; +} + void cUIManager::Draw() { mControl->InternalDraw(); cGlobalBatchRenderer::instance()->Draw(); diff --git a/src/ui/cuimanager.hpp b/src/ui/cuimanager.hpp index 30df4ce2e..fe334f17b 100644 --- a/src/ui/cuimanager.hpp +++ b/src/ui/cuimanager.hpp @@ -70,6 +70,9 @@ class EE_API cUIManager : public tSingleton { void SendMouseDown( cUIControl * ToCtrl, const eeVector2i& Pos, const Uint32 Flags ); cWindow * GetWindow() const; + + /** Control where the mouse click started to be down */ + cUIControl * DownControl() const; protected: cWindow * mWindow; cInput * mKM; diff --git a/src/ui/cuimenu.cpp b/src/ui/cuimenu.cpp index fc6a04841..eb0c994f0 100644 --- a/src/ui/cuimenu.cpp +++ b/src/ui/cuimenu.cpp @@ -51,15 +51,22 @@ cUIMenuItem * cUIMenu::CreateMenuItem( const String& Text, cShape * Icon ) { Params.FontColor = mFontColor; Params.FontShadowColor = mFontShadowColor; Params.FontOverColor = mFontOverColor; - Params.Flags = UI_CLIP_ENABLE | UI_VALIGN_CENTER | UI_HALIGN_LEFT; + Params.Icon = Icon; + + if ( mRowHeight < mMinSpaceForIcons ) + Params.IconMinSize = eeSize( mMinSpaceForIcons, mRowHeight ); + else + Params.IconMinSize = eeSize( mMinSpaceForIcons, mMinSpaceForIcons ); + + if ( mFlags & UI_AUTO_SIZE ) { + Params.Flags = UI_VALIGN_CENTER | UI_HALIGN_LEFT; + } else { + Params.Flags = UI_CLIP_ENABLE | UI_VALIGN_CENTER | UI_HALIGN_LEFT; + } cUIMenuItem * tCtrl = eeNew( cUIMenuItem, ( Params ) ); tCtrl->Text( Text ); - - if ( NULL != Icon ) - tCtrl->Icon( Icon ); - tCtrl->Visible( true ); tCtrl->Enabled( true ); @@ -77,9 +84,19 @@ cUIMenuCheckBox * cUIMenu::CreateMenuCheckBox( const String& Text ) { Params.FontColor = mFontColor; Params.FontShadowColor = mFontShadowColor; Params.FontOverColor = mFontOverColor; - Params.Flags = UI_CLIP_ENABLE | UI_VALIGN_CENTER | UI_HALIGN_LEFT; Params.Size = eeSize( 0, mRowHeight ); + if ( mRowHeight < mMinSpaceForIcons ) + Params.IconMinSize = eeSize( mMinSpaceForIcons, mRowHeight ); + else + Params.IconMinSize = eeSize( mMinSpaceForIcons, mMinSpaceForIcons ); + + if ( mFlags & UI_AUTO_SIZE ) { + Params.Flags = UI_VALIGN_CENTER | UI_HALIGN_LEFT; + } else { + Params.Flags = UI_CLIP_ENABLE | UI_VALIGN_CENTER | UI_HALIGN_LEFT; + } + cUIMenuCheckBox * tCtrl = eeNew( cUIMenuCheckBox, ( Params ) ); tCtrl->Text( Text ); @@ -101,15 +118,22 @@ cUIMenuSubMenu * cUIMenu::CreateSubMenu( const String& Text, cShape * Icon, cUIM Params.FontShadowColor = mFontShadowColor; Params.FontOverColor = mFontOverColor; Params.SubMenu = SubMenu; - Params.Flags = UI_CLIP_ENABLE | UI_VALIGN_CENTER | UI_HALIGN_LEFT; + Params.Icon = Icon; + + if ( mRowHeight < mMinSpaceForIcons ) + Params.IconMinSize = eeSize( mMinSpaceForIcons, mRowHeight ); + else + Params.IconMinSize = eeSize( mMinSpaceForIcons, mMinSpaceForIcons ); + + if ( mFlags & UI_AUTO_SIZE ) { + Params.Flags = UI_VALIGN_CENTER | UI_HALIGN_LEFT; + } else { + Params.Flags = UI_CLIP_ENABLE | UI_VALIGN_CENTER | UI_HALIGN_LEFT; + } cUIMenuSubMenu * tCtrl = eeNew( cUIMenuSubMenu, ( Params ) ); tCtrl->Text( Text ); - - if ( NULL != Icon ) - tCtrl->Icon( Icon ); - tCtrl->Visible( true ); tCtrl->Enabled( true ); @@ -181,14 +205,6 @@ Uint32 cUIMenu::Add( cUIControl * Control ) { void cUIMenu::SetControlSize( cUIControl * Control, const Uint32& Pos ) { if ( Control->IsTypeOrInheritsFrom( UI_TYPE_MENUITEM ) ) { Control->Size( mSize.Width() - mPadding.Left - mPadding.Right, mRowHeight ); - - cUIMenuItem * tItem = reinterpret_cast (Control); - - if ( NULL == tItem->Icon()->Shape() ) { - tItem->Padding( eeRecti( mBiggestIcon, 0, 0, 0 ) ); - } else { - tItem->Padding( eeRecti( 0, 0, 0, 0 ) ); - } } else { Control->Size( mSize.Width() - mPadding.Left - mPadding.Right, Control->Size().Height() ); } diff --git a/src/ui/cuipushbutton.cpp b/src/ui/cuipushbutton.cpp index 8d1f10dcc..9d8848e87 100644 --- a/src/ui/cuipushbutton.cpp +++ b/src/ui/cuipushbutton.cpp @@ -15,8 +15,19 @@ cUIPushButton::cUIPushButton( const cUIPushButton::CreateParams& Params ) : cUIGfx::CreateParams GfxParams; GfxParams.Parent( this ); GfxParams.Shape = Params.Icon; - GfxParams.Flags = UI_AUTO_SIZE; + + if ( Params.IconMinSize.x != 0 && Params.IconMinSize.y != 0 ) { + GfxParams.Flags = UI_VALIGN_CENTER | UI_HALIGN_CENTER; + } else { + GfxParams.Flags = UI_AUTO_SIZE | UI_VALIGN_CENTER | UI_HALIGN_CENTER; + } + mIcon = eeNew( cUIGfx, ( GfxParams ) ); + + if ( Params.IconMinSize.x != 0 && Params.IconMinSize.y != 0 ) { + mIcon->Size( Params.IconMinSize ); + } + mIcon->Visible( true ); mIcon->Enabled( false ); @@ -24,7 +35,7 @@ cUIPushButton::cUIPushButton( const cUIPushButton::CreateParams& Params ) : cUITextBox::CreateParams TxtParams = Params; TxtParams.Parent( this ); - TxtParams.Flags = Params.Flags; + TxtParams.Flags = HAlignGet( Params.Flags ) | VAlignGet( Params.Flags ); TxtParams.Font = Params.Font; TxtParams.FontColor = Params.FontColor; TxtParams.FontShadowColor = Params.FontShadowColor; @@ -70,6 +81,11 @@ void cUIPushButton::OnSizeChange() { } } + if ( NULL != mTextBox && 0 == mTextBox->Text().size() ) { + mIcon->Center(); + } + + /** Auto Size only for height? May be set another flag to this... *//** if ( mFlags & UI_AUTO_SIZE ) { if ( NULL != mTextBox ) { eeRecti P = MakePadding(); @@ -91,7 +107,7 @@ void cUIPushButton::OnSizeChange() { if ( NULL != mTextBox && 0 == mTextBox->Text().size() ) { mIcon->Center(); } - } + }*/ } cUIPushButton::~cUIPushButton() { @@ -99,6 +115,7 @@ cUIPushButton::~cUIPushButton() { void cUIPushButton::SetTheme( cUITheme * Theme ) { cUIControl::SetTheme( Theme, "button" ); + DoAfterSetTheme(); } @@ -111,6 +128,10 @@ void cUIPushButton::DoAfterSetTheme() { mIconSpace = RMargin.Left; } + if ( mFlags & UI_AUTO_SIZE ) { + mSize.Height( GetSkinShapeSize().Height() ); + } + AutoPadding(); OnSizeChange(); diff --git a/src/ui/cuipushbutton.hpp b/src/ui/cuipushbutton.hpp index 36f6f72c8..52482bc08 100644 --- a/src/ui/cuipushbutton.hpp +++ b/src/ui/cuipushbutton.hpp @@ -19,7 +19,8 @@ class EE_API cUIPushButton : public cUIComplexControl { FontOverColor( 0, 0, 0, 255 ), Icon( NULL ), IconHorizontalMargin( 0 ), - IconAutoMargin( true ) + IconAutoMargin( true ), + IconMinSize( 0, 0 ) { cUITheme * Theme = cUIThemeManager::instance()->DefaultTheme(); @@ -50,6 +51,7 @@ class EE_API cUIPushButton : public cUIComplexControl { cShape * Icon; Int32 IconHorizontalMargin; bool IconAutoMargin; + eeSize IconMinSize; }; cUIPushButton( const cUIPushButton::CreateParams& Params ); @@ -58,9 +60,9 @@ class EE_API cUIPushButton : public cUIComplexControl { virtual void SetTheme( cUITheme * Theme ); - void Icon( cShape * Icon ); + virtual void Icon( cShape * Icon ); - cUIGfx * Icon() const; + virtual cUIGfx * Icon() const; void Text( const String& text ); diff --git a/src/ui/cuiradiobutton.cpp b/src/ui/cuiradiobutton.cpp index d0730701b..2d05b631b 100644 --- a/src/ui/cuiradiobutton.cpp +++ b/src/ui/cuiradiobutton.cpp @@ -1,4 +1,5 @@ #include "cuiradiobutton.hpp" +#include "cuimanager.hpp" namespace EE { namespace UI { @@ -66,6 +67,17 @@ void cUIRadioButton::SetTheme( cUITheme * Theme ) { Padding( eeRecti(0,0,0,0) ); } +void cUIRadioButton::AutoSize() { + cUITextBox::AutoSize(); + + if ( mFlags & UI_AUTO_SIZE ) { + mActiveButton->CenterVertical(); + mInactiveButton->CenterVertical(); + + mSize.Width( (eeInt)mTextCache->GetTextWidth() + mActiveButton->Size().Width() ); + } +} + void cUIRadioButton::OnSizeChange() { cUITextBox::OnSizeChange(); @@ -76,8 +88,13 @@ void cUIRadioButton::OnSizeChange() { Uint32 cUIRadioButton::OnMessage( const cUIMessage * Msg ) { switch ( Msg->Msg() ) { case cUIMessage::MsgClick: { - if ( Msg->Flags() & EE_BUTTON_LMASK ) + if ( Msg->Flags() & EE_BUTTON_LMASK ) { SwitchState(); + } + + if ( Msg->Sender() == mActiveButton || Msg->Sender() == mInactiveButton ) { + SendMouseEvent( cUIEvent::EventMouseClick, cUIManager::instance()->GetMousePos(), cUIManager::instance()->PressTrigger() ); + } return 1; } diff --git a/src/ui/cuiradiobutton.hpp b/src/ui/cuiradiobutton.hpp index 1bab0be8b..9127096d4 100644 --- a/src/ui/cuiradiobutton.hpp +++ b/src/ui/cuiradiobutton.hpp @@ -44,6 +44,8 @@ class EE_API cUIRadioButton : public cUITextBox { virtual Uint32 OnKeyDown( const cUIEventKey& Event ); virtual Uint32 OnMessage( const cUIMessage * Msg ); + + virtual void AutoSize(); }; }} diff --git a/src/ui/cuispinbox.cpp b/src/ui/cuispinbox.cpp index a00938a06..bc217cb83 100644 --- a/src/ui/cuispinbox.cpp +++ b/src/ui/cuispinbox.cpp @@ -14,6 +14,10 @@ cUISpinBox::cUISpinBox( const cUISpinBox::CreateParams& Params ) : cUITextInput::CreateParams InputParams( Params ); InputParams.PosSet( 0, 0 ); InputParams.Parent( this ); + + if ( InputParams.Flags & UI_AUTO_SIZE ) + InputParams.Flags &= ~UI_AUTO_SIZE; + InputParams.Flags |= UI_AUTO_PADDING; mInput = eeNew( cUITextInput, ( InputParams ) ); @@ -78,6 +82,10 @@ void cUISpinBox::SetTheme( cUITheme * Theme ) { } } + if ( mFlags & UI_AUTO_SIZE ) { + mSize.Height( mInput->GetSkinShapeSize().Height() ); + } + AdjustChilds(); } @@ -129,7 +137,7 @@ Uint32 cUISpinBox::OnMessage( const cUIMessage * Msg ) { void cUISpinBox::AddValue( const eeFloat& value ) { if ( !mInput->Text().size() ) - mInput->Text( "0" ); + mInput->Text( toStr( static_cast( mMinValue ) ) ); Value( mValue + value ); } diff --git a/src/ui/cuispinbox.hpp b/src/ui/cuispinbox.hpp index 78e18aaef..d2043082c 100644 --- a/src/ui/cuispinbox.hpp +++ b/src/ui/cuispinbox.hpp @@ -13,7 +13,7 @@ class EE_API cUISpinBox : public cUIComplexControl { inline CreateParams() : cUITextInput::CreateParams(), DefaultValue( 0.f ), - AllowDotsInNumbers( true ) + AllowDotsInNumbers( false ) { MaxLenght = 24; } diff --git a/src/ui/cuitextinput.cpp b/src/ui/cuitextinput.cpp index ea5e9af7d..157e4ffc0 100644 --- a/src/ui/cuitextinput.cpp +++ b/src/ui/cuitextinput.cpp @@ -154,6 +154,13 @@ void cUITextInput::SetTheme( cUITheme * Theme ) { cUIControl::SetTheme( Theme, "textinput" ); AutoPadding(); + AutoSize(); +} + +void cUITextInput::AutoSize() { + if ( mFlags & UI_AUTO_SIZE ) { + Size( mSize.x, GetSkinShapeSize().Height() ); + } } void cUITextInput::AutoPadding() { diff --git a/src/ui/cuitextinput.hpp b/src/ui/cuitextinput.hpp index c2d9943db..a52263672 100644 --- a/src/ui/cuitextinput.hpp +++ b/src/ui/cuitextinput.hpp @@ -59,6 +59,8 @@ class EE_API cUITextInput : public cUITextBox { void AlignFix(); + virtual void AutoSize(); + void PrivOnPressEnter(); void AutoPadding(); diff --git a/src/ui/cuitheme.cpp b/src/ui/cuitheme.cpp index 485ebf157..5ac0445af 100644 --- a/src/ui/cuitheme.cpp +++ b/src/ui/cuitheme.cpp @@ -29,6 +29,8 @@ namespace EE { namespace UI { static std::list UI_THEME_ELEMENTS; +static std::list UI_THEME_ICONS; + static void LoadThemeElements() { if ( !UI_THEME_ELEMENTS.size() ) { UI_THEME_ELEMENTS.push_back( "control" ); @@ -92,12 +94,29 @@ static void LoadThemeElements() { UI_THEME_ELEMENTS.push_back( "winmenu" ); UI_THEME_ELEMENTS.push_back( "winmenubutton" ); } + + if ( !UI_THEME_ICONS.size() ) { + UI_THEME_ICONS.push_back( "ok" ); + UI_THEME_ICONS.push_back( "cancel" ); + UI_THEME_ICONS.push_back( "go-up" ); + UI_THEME_ICONS.push_back( "quit" ); + UI_THEME_ICONS.push_back( "add" ); + UI_THEME_ICONS.push_back( "document-open" ); + UI_THEME_ICONS.push_back( "document-close" ); + UI_THEME_ICONS.push_back( "document-new" ); + UI_THEME_ICONS.push_back( "document-save" ); + UI_THEME_ICONS.push_back( "document-save-as" ); + } } void cUITheme::AddThemeElement( const std::string& Element ) { UI_THEME_ELEMENTS.push_back( Element ); } +void cUITheme::AddThemeIcon( const std::string& Icon ) { + UI_THEME_ICONS.push_back( Icon ); +} + cUITheme * cUITheme::LoadFromShapeGroup( cUITheme * tTheme, cShapeGroup * ShapeGroup ) { cTimeElapsed TE; @@ -109,6 +128,8 @@ cUITheme * cUITheme::LoadFromShapeGroup( cUITheme * tTheme, cShapeGroup * ShapeG std::vector ElemFound; std::vector ElemType; + tTheme->ShapeGroup( ShapeGroup ); + for ( std::list::iterator it = UI_THEME_ELEMENTS.begin() ; it != UI_THEME_ELEMENTS.end(); it++ ) { Uint32 IsComplex = 0; @@ -142,6 +163,7 @@ cUITheme * cUITheme::LoadFromPath( cUITheme * tTheme, const std::string& Path, c Uint32 i; bool Found; std::string Element; + std::string ElemName; std::string RPath( Path ); DirPathAddSlashAtEnd( RPath ); @@ -154,10 +176,12 @@ cUITheme * cUITheme::LoadFromPath( cUITheme * tTheme, const std::string& Path, c cShapeGroup * tSG = eeNew( cShapeGroup, ( tTheme->Abbr() ) ); + tTheme->ShapeGroup( tSG ); + for ( std::list::iterator it = UI_THEME_ELEMENTS.begin() ; it != UI_THEME_ELEMENTS.end(); it++ ) { Uint32 IsComplex = 0; - Element = std::string( tTheme->Abbr() + "_" + *it ); + Element = tTheme->Abbr() + "_" + *it; Found = SearchFilesOfElement( tSG, RPath, Element, IsComplex, ImgExt ); @@ -167,6 +191,16 @@ cUITheme * cUITheme::LoadFromPath( cUITheme * tTheme, const std::string& Path, c } } + // Load the icons from path. + for ( std::list::iterator it = UI_THEME_ICONS.begin() ; it != UI_THEME_ICONS.end(); it++ ) { + ElemName = tTheme->Abbr() + "_icon_" + *it; + Element = RPath + ElemName + "." + ImgExt; + + if ( FileExists( Element ) ) { + tSG->Add( eeNew( cShape, ( cTextureFactory::instance()->Load( Element ), ElemName ) ) ); + } + } + if ( tSG->Count() ) cShapeGroupManager::instance()->Add( tSG ); else @@ -179,6 +213,8 @@ cUITheme * cUITheme::LoadFromPath( cUITheme * tTheme, const std::string& Path, c tTheme->Add( eeNew( cUISkinSimple, ( ElemFound[i] ) ) ); } + + cLog::instance()->Write( "UI Theme Loaded in: " + toStr( TE.ElapsedSinceStart() ) + " ( from path )" ); return tTheme; @@ -275,6 +311,7 @@ cUITheme::cUITheme( const std::string& Name, const std::string& Abbr, cFont * De mName( Name ), mNameHash( MakeHash( mName ) ), mAbbr( Abbr ), + mShapeGroup( NULL ), mFont( DefaultFont ), mFontColor( 0, 0, 0, 255 ), mFontShadowColor( 255, 255, 255, 200 ), @@ -359,6 +396,21 @@ const bool& cUITheme::UseDefaultThemeValues() const { return mUseDefaultThemeValues; } +cShapeGroup * cUITheme::ShapeGroup() const { + return mShapeGroup; +} + +void cUITheme::ShapeGroup( cShapeGroup * SG ) { + mShapeGroup = SG; +} + +cShape * cUITheme::GetIconByName( const std::string& name ) { + if ( NULL != mShapeGroup ) + return mShapeGroup->GetByName( mAbbr + "_icon_" + name ); + + return NULL; +} + cUIGfx * cUITheme::CreateGfx( cShape * Shape, cUIControl * Parent, const eeSize& Size, const eeVector2i& Pos, const Uint32& Flags, eeColorA ShapeColor, EE_RENDERTYPE ShapeRender ) { cUIGfx::CreateParams GfxParams; GfxParams.Parent( Parent ); diff --git a/src/ui/cuitheme.hpp b/src/ui/cuitheme.hpp index ab42d6b19..8f9e3b512 100644 --- a/src/ui/cuitheme.hpp +++ b/src/ui/cuitheme.hpp @@ -44,6 +44,8 @@ class EE_API cUITheme : public tResourceManager { static void AddThemeElement( const std::string& Element ); + static void AddThemeIcon( const std::string& Icon ); + cUITheme( const std::string& Name, const std::string& Abbr, cFont * DefaultFont = NULL ); virtual ~cUITheme(); @@ -82,6 +84,10 @@ class EE_API cUITheme : public tResourceManager { const bool& UseDefaultThemeValues() const; + cShapeGroup * ShapeGroup() const; + + cShape * GetIconByName( const std::string& name ); + virtual cUIGfx * CreateGfx( cShape * Shape, cUIControl * Parent = NULL, const eeSize& Size = eeSize(), const eeVector2i& Pos = eeVector2i(), const Uint32& Flags = UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, eeColorA ShapeColor = eeColorA(255,255,255,255), EE_RENDERTYPE ShapeRender = RN_NORMAL ); virtual cUISprite * CreateSprite( cSprite * Sprite, cUIControl * Parent = NULL, const eeSize& Size = eeSize(), const eeVector2i& Pos = eeVector2i(), const Uint32& Flags = UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, bool DeallocSprite = true, EE_RENDERTYPE SpriteRender = RN_NORMAL ); @@ -102,7 +108,7 @@ class EE_API cUITheme : public tResourceManager { virtual cUISlider * CreateSlider( cUIControl * Parent = NULL, const eeSize& Size = eeSize(), const eeVector2i& Pos = eeVector2i(), const Uint32& Flags = UI_CONTROL_DEFAULT_FLAGS, bool VerticalSlider = false, bool AllowHalfSliderOut = true, bool ExpandBackground = false ); - virtual cUISpinBox * CreateSpinBox( cUIControl * Parent = NULL, const eeSize& Size = eeSize(), const eeVector2i& Pos = eeVector2i(), const Uint32& Flags = UI_CONTROL_DEFAULT_FLAGS | UI_CLIP_ENABLE, eeFloat DefaultValue = 0.f, bool AllowDotsInNumbers = true ); + virtual cUISpinBox * CreateSpinBox( cUIControl * Parent = NULL, const eeSize& Size = eeSize(), const eeVector2i& Pos = eeVector2i(), const Uint32& Flags = UI_CONTROL_DEFAULT_FLAGS | UI_CLIP_ENABLE | UI_AUTO_SIZE, eeFloat DefaultValue = 0.f, bool AllowDotsInNumbers = true ); virtual cUIComboBox * CreateComboBox( cUIControl * Parent = NULL, const eeSize& Size = eeSize(), const eeVector2i& Pos = eeVector2i(), const Uint32& Flags = UI_CONTROL_DEFAULT_FLAGS | UI_CLIP_ENABLE | UI_AUTO_PADDING, Uint32 MinNumVisibleItems = 6, bool PopUpToMainControl = false, cUIListBox * ListBox = NULL ); @@ -116,7 +122,7 @@ class EE_API cUITheme : public tResourceManager { virtual cUIProgressBar * CreateProgressBar( cUIControl * Parent = NULL, const eeSize& Size = eeSize(), const eeVector2i& Pos = eeVector2i(), const Uint32& Flags = UI_CONTROL_DEFAULT_FLAGS, bool DisplayPercent = false, bool VerticalExpand = false, eeVector2f MovementSpeed = eeVector2f( 64, 0 ), eeRectf FillerMargin = eeRectf() ); - virtual cUIPushButton * CreatePushButton( cUIControl * Parent = NULL, const eeSize& Size = eeSize(), const eeVector2i& Pos = eeVector2i(), const Uint32& Flags = UI_CONTROL_DEFAULT_FLAGS, cShape * Icon = NULL, Int32 IconHorizontalMargin = 0, bool IconAutoMargin = true ); + virtual cUIPushButton * CreatePushButton( cUIControl * Parent = NULL, const eeSize& Size = eeSize(), const eeVector2i& Pos = eeVector2i(), const Uint32& Flags = UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, cShape * Icon = NULL, Int32 IconHorizontalMargin = 0, bool IconAutoMargin = true ); virtual cUIWinMenu * CreateWinMenu( cUIControl * Parent = NULL, const eeSize& Size = eeSize(), const eeVector2i& Pos = eeVector2i(), const Uint32& Flags = UI_CONTROL_DEFAULT_FLAGS, Uint32 MarginBetweenButtons = 0, Uint32 ButtonMargin = 4, Uint32 MenuHeight = 0, Uint32 FirstButtonMargin = 1 ); @@ -127,6 +133,7 @@ class EE_API cUITheme : public tResourceManager { std::string mName; Uint32 mNameHash; std::string mAbbr; + cShapeGroup * mShapeGroup; cFont * mFont; eeColorA mFontColor; eeColorA mFontShadowColor; @@ -134,6 +141,8 @@ class EE_API cUITheme : public tResourceManager { eeColorA mFontSelectedColor; bool mUseDefaultThemeValues; + void ShapeGroup( cShapeGroup * SG ); + static bool SearchFilesOfElement( cShapeGroup * SG, const std::string& Path, std::string Element, Uint32& IsComplex, const std::string ImgExt ); static bool SearchFilesInGroup( cShapeGroup * SG, std::string Element, Uint32& IsComplex ); diff --git a/src/utils/string.cpp b/src/utils/string.cpp index 5caa9d81f..332f55b12 100644 --- a/src/utils/string.cpp +++ b/src/utils/string.cpp @@ -275,4 +275,12 @@ void ReplaceSubStr( std::string &target, const std::string& that, const std::str } } +std::string RemoveNumbersAtEnd( std::string txt ) { + while ( txt.size() && txt[ txt.size() - 1 ] >= '0' && txt[ txt.size() - 1 ] <= '9' ) { + txt.resize( txt.size() - 1 ); + } + + return txt; +} + }} diff --git a/src/utils/string.hpp b/src/utils/string.hpp index cc5dd1f0e..20497c594 100755 --- a/src/utils/string.hpp +++ b/src/utils/string.hpp @@ -106,6 +106,9 @@ Int32 EE_API StrStartsWith( const String& Start, const String Str ); /** Replaces a substring by another string inside a string */ void EE_API ReplaceSubStr(std::string &target, const std::string& that, const std::string& with ); +/** Removes the numbers at the end of the string */ +std::string EE_API RemoveNumbersAtEnd( std::string txt ); + }} #endif diff --git a/src/window/cinputtextbuffer.cpp b/src/window/cinputtextbuffer.cpp index d08ab4d33..3583de511 100755 --- a/src/window/cinputtextbuffer.cpp +++ b/src/window/cinputtextbuffer.cpp @@ -136,7 +136,6 @@ void cInputTextBuffer::Update( InputEvent* Event ) { if ( Active() ) { cInput * Input = mWindow->GetInput(); - ChangedSinceLastUpdate( false ); Uint32 c = eeConvertKeyCharacter( Event->key.keysym.sym, Event->key.keysym.unicode, Event->key.keysym.mod ); if ( SupportFreeEditing() ) {