CUIEditWnd::CUIEditWnd(GG::X w, const std::string& prompt_text, const std::string& edit_text, GG::Flags<GG::WndFlag> flags/* = Wnd::MODAL*/) : CUIWnd(prompt_text, GG::X0, GG::Y0, w, GG::Y1, flags) { m_edit = new CUIEdit(LeftBorder() + 3, TopBorder() + 3, ClientWidth() - 2 * BUTTON_WIDTH - 2 * CONTROL_MARGIN - 6 - LeftBorder() - RightBorder(), edit_text); m_ok_bn = new CUIButton(UserString("OK"), m_edit->Right() + CONTROL_MARGIN, TopBorder() + 3, BUTTON_WIDTH); m_cancel_bn = new CUIButton(UserString("CANCEL"), m_ok_bn->Right() + CONTROL_MARGIN, TopBorder() + 3, BUTTON_WIDTH); m_ok_bn->OffsetMove(GG::Pt(GG::X0, (m_edit->Height() - m_ok_bn->Height()) / 2)); m_cancel_bn->OffsetMove(GG::Pt(GG::X0, (m_edit->Height() - m_ok_bn->Height()) / 2)); Resize(GG::Pt(w, std::max(m_edit->Bottom(), m_cancel_bn->Bottom()) + BottomBorder() + 3)); MoveTo(GG::Pt((GG::GUI::GetGUI()->AppWidth() - w) / 2, (GG::GUI::GetGUI()->AppHeight() - Height()) / 2)); AttachChild(m_edit); AttachChild(m_ok_bn); AttachChild(m_cancel_bn); GG::Connect(m_ok_bn->LeftClickedSignal, &CUIEditWnd::OkClicked, this); GG::Connect(m_cancel_bn->LeftClickedSignal, &CUIWnd::CloseClicked, static_cast<CUIWnd*>(this)); m_edit->SelectAll(); }
SaveFileDialog::SaveFileDialog (const std::string& extension, bool load ) : CUIWnd ( UserString ( "GAME_MENU_SAVE_FILES" ), ( GG::GUI::GetGUI()->AppWidth() - SAVE_FILE_DIALOG_WIDTH ) / 2, ( GG::GUI::GetGUI()->AppHeight() - SAVE_FILE_DIALOG_HEIGHT ) / 2, SAVE_FILE_DIALOG_WIDTH, SAVE_FILE_DIALOG_HEIGHT, GG::INTERACTIVE | GG::DRAGABLE | GG::MODAL | GG::RESIZABLE ) { m_extension = extension; m_load_only = load; boost::shared_ptr<GG::Font> font = ClientUI::GetFont(); SetMinSize ( GG::Pt ( 2*SAVE_FILE_DIALOG_MIN_WIDTH, 2*SAVE_FILE_DIALOG_MIN_HEIGHT ) ); m_layout = new GG::Layout ( GG::X0, GG::Y0, SAVE_FILE_DIALOG_WIDTH - LeftBorder() - RightBorder(), SAVE_FILE_DIALOG_HEIGHT - TopBorder() - BottomBorder(), 3, 4 ); m_layout->SetCellMargin ( SAVE_FILE_CELL_MARGIN ); m_layout->SetBorderMargin ( SAVE_FILE_CELL_MARGIN*2 ); m_file_list = new SaveFileListBox(); m_file_list->SetStyle ( GG::LIST_SINGLESEL | GG::LIST_SORTDESCENDING ); m_file_list->SetColHeaders ( new SaveFileRow() ); m_confirm_btn = new CUIButton ( UserString ( "OK" ) ); CUIButton* cancel_btn = new CUIButton ( UserString ( "CANCEL" ) ); m_name_edit = new CUIEdit ( GG::X0, GG::Y0, GG::X1, "", font ); GG::TextControl* filename_label = new GG::TextControl ( GG::X0, GG::Y0, UserString ( "SAVE_FILENAME" ), font, ClientUI::TextColor() ); GG::TextControl* directory_label = new GG::TextControl ( GG::X0, GG::Y0, UserString ( "SAVE_DIRECTORY" ), font, ClientUI::TextColor() ); m_current_dir_edit = new CUIEdit ( GG::X0, GG::Y0, GG::X1, PathString ( GetSaveDir() ), font ); m_browse_dir_btn = new CUIButton ( "..." ); m_layout->Add ( m_file_list, 0, 0, 1, 4 ); m_layout->Add ( filename_label, 1, 0, 1, 1 ); m_layout->Add ( m_name_edit, 1, 1, 1, 2 ); m_layout->Add ( m_confirm_btn, 1, 3 ); m_layout->Add ( directory_label,2, 0 ); m_layout->Add ( m_current_dir_edit, 2, 1 ); m_layout->Add ( m_browse_dir_btn, 2, 2 ); m_layout->Add ( cancel_btn, 2, 3 ); m_layout->SetRowStretch ( 0, 1.0 ); m_layout->SetMinimumRowHeight ( 1, font->TextExtent ( m_confirm_btn->Text() ).y ); m_layout->SetMinimumRowHeight ( 2, font->TextExtent ( cancel_btn->Text() ).y ); m_layout->SetMinimumColumnWidth ( 0, std::max ( font->TextExtent ( filename_label->Text() ).x, font->TextExtent ( directory_label->Text() ).x ) ); m_layout->SetColumnStretch ( 1, 1.0 ); m_layout->SetMinimumColumnWidth ( 2, m_browse_dir_btn->MinUsableSize().x + SAVE_FILE_BUTTON_MARGIN*2 ); m_layout->SetMinimumColumnWidth ( 3, std::max ( m_confirm_btn->MinUsableSize().x, cancel_btn->MinUsableSize().x ) + SAVE_FILE_BUTTON_MARGIN ); SetLayout ( m_layout ); GG::Connect ( m_confirm_btn->LeftClickedSignal, &SaveFileDialog::Confirm, this ); GG::Connect ( cancel_btn->LeftClickedSignal, &SaveFileDialog::Cancel, this ); GG::Connect ( m_file_list->SelChangedSignal, &SaveFileDialog::SelectionChanged, this ); GG::Connect ( m_file_list->DoubleClickedSignal, &SaveFileDialog::DoubleClickRow, this ); GG::Connect ( m_browse_dir_btn->LeftClickedSignal, &SaveFileDialog::BrowseDirectories, this ); GG::Connect ( m_name_edit->EditedSignal, &SaveFileDialog::FileNameEdited, this ); UpdatePreviewList(); if(!m_load_only){ m_name_edit->SetText(std::string("save-") + FilenameTimestamp()); m_name_edit->SelectAll(); } }