Player dialog is now shown when pressing enter/double-clicking on a player in the list. Fixed dismissing dialogs with escape.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3643 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2009-06-24 17:53:22 +00:00
parent 604c7adeea
commit cf85ff876d
6 changed files with 88 additions and 8 deletions

View File

@ -246,19 +246,53 @@ void TrackInfoDialog::onEnterPressedInternal()
PlayerInfoDialog::PlayerInfoDialog(Player* PlayerInfoDialog, const float w, const float h) : ModalDialog(w, h)
PlayerInfoDialog::PlayerInfoDialog(Player* player, const float w, const float h) : ModalDialog(w, h)
{
const int y1 = m_area.getHeight()/4;
const int y2 = m_area.getHeight()*2/4;
const int y3 = m_area.getHeight()*3/4;
IGUIFont* font = GUIEngine::getFont();
const int textHeight = font->getDimension(L"X").Height;
const int buttonHeight = textHeight + 10;
stringw playerName = player->getName();
core::rect< s32 > area_bottom(50, y1 - textHeight/2, m_area.getWidth()-50, y1 + textHeight/2 + 10);
GUIEngine::getGUIEnv()->addEditBox(playerName.c_str(), area_bottom, true /* border */, m_irrlicht_window);
{
ButtonWidget* widget = new ButtonWidget();
widget->m_type = WTYPE_BUTTON;
widget->m_properties[PROP_TEXT] = _("Rename");
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();
}
{
ButtonWidget* widget = new ButtonWidget();
widget->m_type = WTYPE_BUTTON;
widget->m_properties[PROP_TEXT] = _("Remove");
widget->x = 0;
widget->y = 0;
widget->w = m_area.getWidth();
widget->h = m_area.getHeight();
widget->setParent(m_irrlicht_window);
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 = y3;
widget->w = textWidth;
widget->h = buttonHeight;
widget->setParent(m_irrlicht_window);
m_children.push_back(widget);
widget->add();
}
}
void PlayerInfoDialog::onEnterPressedInternal()
{

View File

@ -305,7 +305,28 @@ namespace StateManager
void eventPlayers(Widget* widget, const std::string& name)
{
new EnterPlayerNameDialog(0.5f, 0.4f);
if(name == "addplayer")
{
new EnterPlayerNameDialog(0.5f, 0.4f);
}
else if(name == "players")
{
std::cout << "Event : players\n";
ListWidget* players = getCurrentScreen()->getWidget<ListWidget>("players");
assert(players != NULL);
std::string selectedPlayer = players->getSelectionName();
const int playerAmount = UserConfigParams::m_player.size();
for(int n=0; n<playerAmount; n++)
{
if(UserConfigParams::m_player[n].getName() == selectedPlayer)
{
new PlayerInfoDialog( &UserConfigParams::m_player[n], 0.5f, 0.4f );
return;
}
} // end for
}
}
// -----------------------------------------------------------------------------

View File

@ -646,6 +646,7 @@ bool Screen::OnEvent(const SEvent& event)
case EGET_BUTTON_CLICKED:
case EGET_SCROLL_BAR_CHANGED:
case EGET_CHECKBOX_CHANGED:
case EGET_LISTBOX_SELECTED_AGAIN:
{
Widget* w = getWidget(id);
if(w == NULL) break;
@ -712,7 +713,7 @@ bool Screen::OnEvent(const SEvent& event)
{
// currently, enter pressed in text ctrl events can only happen in dialogs.
// FIXME : find a cleaner way to route the event to its proper location
ModalDialog::onEnterPressed();
if(ModalDialog::isADialogActive()) ModalDialog::onEnterPressed();
break;
}
default:

View File

@ -420,16 +420,25 @@ namespace StateManager
void escapePressed()
{
// in input sensing mode
if(input_manager->isInMode(InputManager::INPUT_SENSE_KEYBOARD) ||
input_manager->isInMode(InputManager::INPUT_SENSE_GAMEPAD) )
{
ModalDialog::dismiss();
input_manager->setMode(InputManager::MENU);
}
// when another modal dialog is visible
else if(ModalDialog::isADialogActive())
{
ModalDialog::dismiss();
}
// In-game
else if(g_game_mode)
{
// TODO : show in-game menu
resetAndGoToMenu("main.stkgui");
}
// In menus
else
{
popMenu();

View File

@ -1286,3 +1286,16 @@ void ListWidget::addItem(const char* item)
assert(list != NULL);
list->addItem( stringw(item).c_str() );
}
int ListWidget::getSelection() const
{
IGUIListBox* list = dynamic_cast<IGUIListBox*>(m_element);
assert(list != NULL);
return list->getSelected();
}
std::string ListWidget::getSelectionName() const
{
IGUIListBox* list = dynamic_cast<IGUIListBox*>(m_element);
assert(list != NULL);
return stringc( list->getListItem( list->getSelected() ) ).c_str();
}

View File

@ -352,6 +352,8 @@ namespace GUIEngine
void add();
void addItem(const char* item);
int getSelection() const;
std::string getSelectionName() const;
};
}