Removing a player now triggers a confirmation dialog

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3694 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria
2009-07-03 17:52:13 +00:00
parent 1f2f028104
commit 43ec7af757
2 changed files with 176 additions and 55 deletions

View File

@@ -33,6 +33,21 @@ namespace GUIEngine
// global instance of the current dialog if any
static ModalDialog* modalWindow = NULL;
ModalDialog::ModalDialog(const float percentWidth, const float percentHeight)
{
const core::dimension2d<s32>& frame_size = GUIEngine::getDriver()->getCurrentRenderTargetSize();
const int w = (int)(frame_size.Width*percentWidth);
const int h = (int)(frame_size.Height*percentHeight);
m_area = core::rect< s32 >( position2d< s32 >(frame_size.Width/2 - w/2, frame_size.Height/2 - h/2),
dimension2d< s32 >(w, h) );
if(modalWindow != NULL) delete modalWindow;
modalWindow = this;
m_irrlicht_window = GUIEngine::getGUIEnv()->addWindow ( m_area, true /* modal */ );
}
ModalDialog::~ModalDialog()
{
// irrLicht is to stupid to remove focus from deleted widgets
@@ -44,6 +59,28 @@ ModalDialog::~ModalDialog()
if(modalWindow == this) modalWindow = NULL;
}
void ModalDialog::clearWindow()
{
const int children_amount = m_children.size();
for(int i=0; i<children_amount; i++)
{
m_irrlicht_window->removeChild( m_children[i].m_element );
}
m_children.clearAndDeleteAll();
m_irrlicht_window->remove();
m_irrlicht_window = GUIEngine::getGUIEnv()->addWindow ( m_area, true /* modal */ );
/*
const core::list<IGUIElement*>& remainingChildren = m_irrlicht_window->getChildren();
const int amount = remainingChildren.getSize();
for(core::list<IGUIElement*>::Iterator it=remainingChildren.begin(); it != remainingChildren.end(); it++)
{
it->remove();
}
*/
}
void ModalDialog::dismiss()
{
if(modalWindow != NULL) delete modalWindow;
@@ -69,20 +106,11 @@ void ModalDialog::onEnterPressedInternal()
{
}
ModalDialog::ModalDialog(const float percentWidth, const float percentHeight)
{
const core::dimension2d<s32>& frame_size = GUIEngine::getDriver()->getCurrentRenderTargetSize();
const int w = (int)(frame_size.Width*percentWidth);
const int h = (int)(frame_size.Height*percentHeight);
m_area = core::rect< s32 >( position2d< s32 >(frame_size.Width/2 - w/2, frame_size.Height/2 - h/2),
dimension2d< s32 >(w, h) );
#if 0
#pragma mark -
#pragma mark PressAKeyDialog
#endif
if(modalWindow != NULL) delete modalWindow;
modalWindow = this;
m_irrlicht_window = GUIEngine::getGUIEnv()->addWindow ( m_area, true /* modal */ );
}
// ------------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------------
@@ -133,6 +161,12 @@ void PressAKeyDialog::processEvent(std::string& eventSource)
dismiss();
}
}
#if 0
#pragma mark -
#pragma mark EnterPlayerNameDialog
#endif
// ------------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------------
@@ -229,6 +263,11 @@ void EnterPlayerNameDialog::onEnterPressedInternal()
ModalDialog::dismiss();
}
#if 0
#pragma mark -
#pragma mark TrackInfoDialog
#endif
// ------------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------------
@@ -317,11 +356,25 @@ void TrackInfoDialog::onEnterPressedInternal()
}
// ------------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------------
#if 0
#pragma mark -
#pragma mark PlayerInfoDialog
#endif
PlayerInfoDialog::PlayerInfoDialog(Player* player, const float w, const float h) : ModalDialog(w, h)
{
m_player = player;
showRegularDialog();
}
void PlayerInfoDialog::showRegularDialog()
{
clearWindow();
const int y1 = m_area.getHeight()/6;
const int y2 = m_area.getHeight()*2/6;
const int y3 = m_area.getHeight()*3/6;
@@ -332,35 +385,35 @@ PlayerInfoDialog::PlayerInfoDialog(Player* player, const float w, const float h)
const int buttonHeight = textHeight + 10;
{
textCtrl = new TextBoxWidget();
textCtrl->m_type = WTYPE_BUTTON;
textCtrl->m_properties[PROP_ID] = "renameplayer";
textCtrl->m_properties[PROP_TEXT] = player->getName();
textCtrl->x = 50;
textCtrl->y = y1 - textHeight/2;
textCtrl->w = m_area.getWidth()-100;
textCtrl->h = textHeight + 5;
textCtrl->setParent(m_irrlicht_window);
m_children.push_back(textCtrl);
textCtrl->add();
GUIEngine::getGUIEnv()->setFocus( textCtrl->m_element );
textCtrl = new TextBoxWidget();
textCtrl->m_type = WTYPE_BUTTON;
textCtrl->m_properties[PROP_ID] = "renameplayer";
textCtrl->m_properties[PROP_TEXT] = m_player->getName();
textCtrl->x = 50;
textCtrl->y = y1 - textHeight/2;
textCtrl->w = m_area.getWidth()-100;
textCtrl->h = textHeight + 5;
textCtrl->setParent(m_irrlicht_window);
m_children.push_back(textCtrl);
textCtrl->add();
GUIEngine::getGUIEnv()->setFocus( textCtrl->m_element );
}
{
ButtonWidget* widget = new ButtonWidget();
widget->m_type = WTYPE_BUTTON;
widget->m_properties[PROP_ID] = "renameplayer";
widget->m_properties[PROP_TEXT] = _("Rename");
ButtonWidget* widget = new ButtonWidget();
widget->m_type = WTYPE_BUTTON;
widget->m_properties[PROP_ID] = "renameplayer";
widget->m_properties[PROP_TEXT] = _("Rename");
const int textWidth = font->getDimension( stringw(widget->m_properties[PROP_TEXT].c_str()).c_str() ).Width + 40;
const int textWidth = font->getDimension( stringw(widget->m_properties[PROP_TEXT].c_str()).c_str() ).Width + 40;
widget->x = m_area.getWidth()/2 - textWidth/2;
widget->y = y2;
widget->w = textWidth;
widget->h = buttonHeight;
widget->setParent(m_irrlicht_window);
m_children.push_back(widget);
widget->add();
widget->x = m_area.getWidth()/2 - textWidth/2;
widget->y = y2;
widget->w = textWidth;
widget->h = buttonHeight;
widget->setParent(m_irrlicht_window);
m_children.push_back(widget);
widget->add();
}
{
ButtonWidget* widget = new ButtonWidget();
@@ -380,23 +433,81 @@ PlayerInfoDialog::PlayerInfoDialog(Player* player, const float w, const float h)
}
{
ButtonWidget* widget = new ButtonWidget();
widget->m_type = WTYPE_BUTTON;
widget->m_properties[PROP_ID] = "removeplayer";
widget->m_properties[PROP_TEXT] = _("Remove");
ButtonWidget* widget = new ButtonWidget();
widget->m_type = WTYPE_BUTTON;
widget->m_properties[PROP_ID] = "removeplayer";
widget->m_properties[PROP_TEXT] = _("Remove");
const int textWidth = font->getDimension( stringw(widget->m_properties[PROP_TEXT].c_str()).c_str() ).Width + 40;
widget->x = m_area.getWidth()/2 - textWidth/2;
widget->y = y4;
widget->w = textWidth;
widget->h = buttonHeight;
widget->setParent(m_irrlicht_window);
m_children.push_back(widget);
widget->add();
const int textWidth = font->getDimension( stringw(widget->m_properties[PROP_TEXT].c_str()).c_str() ).Width + 40;
widget->x = m_area.getWidth()/2 - textWidth/2;
widget->y = y4;
widget->w = textWidth;
widget->h = buttonHeight;
widget->setParent(m_irrlicht_window);
m_children.push_back(widget);
widget->add();
}
}
void PlayerInfoDialog::showConfirmDialog()
{
clearWindow();
IGUIFont* font = GUIEngine::getFont();
const int textHeight = font->getDimension(L"X").Height;
const int buttonHeight = textHeight + 10;
char message[256];
sprintf(message, _("Do you really want to delete player '%s' ?"), m_player->getName());
core::rect< s32 > area_left(5, 0, m_area.getWidth()-5, m_area.getHeight()/2);
IGUIStaticText* a = GUIEngine::getGUIEnv()->addStaticText( stringw(message).c_str(),
area_left, false /* border */, true /* word wrap */,
m_irrlicht_window);
a->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER);
{
ButtonWidget* widget = new ButtonWidget();
widget->m_type = WTYPE_BUTTON;
widget->m_properties[PROP_ID] = "confirmremove";
widget->m_properties[PROP_TEXT] = _("Confirm Remove");
const int textWidth = font->getDimension( stringw(widget->m_properties[PROP_TEXT].c_str()).c_str() ).Width + 40;
widget->x = m_area.getWidth()/2 - textWidth/2;
widget->y = m_area.getHeight()/2;
widget->w = textWidth;
widget->h = buttonHeight;
widget->setParent(m_irrlicht_window);
m_children.push_back(widget);
widget->add();
}
{
ButtonWidget* widget = new ButtonWidget();
widget->m_type = WTYPE_BUTTON;
widget->m_properties[PROP_ID] = "cancelremove";
widget->m_properties[PROP_TEXT] = _("Cancel Remove");
const int textWidth = font->getDimension( stringw(widget->m_properties[PROP_TEXT].c_str()).c_str() ).Width + 40;
widget->x = m_area.getWidth()/2 - textWidth/2;
widget->y = m_area.getHeight()*3/4;
widget->w = textWidth;
widget->h = buttonHeight;
widget->setParent(m_irrlicht_window);
m_children.push_back(widget);
widget->add();
GUIEngine::getGUIEnv()->setFocus( widget->m_element );
}
}
void PlayerInfoDialog::onEnterPressedInternal()
{
}
@@ -421,10 +532,12 @@ void PlayerInfoDialog::processEvent(std::string& eventSource)
dismiss();
return;
}
if(eventSource == "removeplayer")
{
// FIXME : ask for confirmation
else if(eventSource == "removeplayer")
{
showConfirmDialog();
}
else if(eventSource == "confirmremove")
{
StateManager::deletePlayer( m_player );
// irrLicht is too stupid to remove focus from deleted widgets
@@ -436,7 +549,11 @@ void PlayerInfoDialog::processEvent(std::string& eventSource)
return;
}
if(eventSource == "cancel")
else if(eventSource == "cancelremove")
{
showRegularDialog();
}
else if(eventSource == "cancel")
{
// irrLicht is too stupid to remove focus from deleted widgets
// so do it by hand

View File

@@ -45,6 +45,7 @@ protected:
ModalDialog(const float percentWidth, const float percentHeight);
virtual void onEnterPressedInternal();
void clearWindow();
public:
ptr_vector<Widget> m_children;
@@ -97,6 +98,9 @@ class PlayerInfoDialog : public ModalDialog
{
TextBoxWidget* textCtrl;
Player* m_player;
void showRegularDialog();
void showConfirmDialog();
public:
/**
* Creates a modal dialog with given percentage of screen width and height