make BackgroundChooser a bit more flexible

This commit is contained in:
Goober5000 committed 2021-12-11 23:00:07 -05:00
1 parent 5a35c308fb
commit e31518be71
6 files changed
+115 -113

No files matched your search

-87
View File
@@ -1,87 +0,0 @@
// BackgroundChooser.cpp : implementation file
//
#include "stdafx.h"
#include "fred.h"
#include "BackgroundChooser.h"
#include "ship/ship.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// BackgroundChooser dialog
BackgroundChooser::BackgroundChooser(int numBackgrounds)
: CDialog(BackgroundChooser::IDD)
{
//{{AFX_DATA_INIT(BackgroundChooser)
//}}AFX_DATA_INIT
m_numBackgrounds = numBackgrounds;
m_chosenBackground = -1;
}
void BackgroundChooser::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(BackgroundChooser)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(BackgroundChooser, CDialog)
//{{AFX_MSG_MAP(BackgroundChooser)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// BackgroundChooser message handlers
BOOL BackgroundChooser::OnInitDialog()
{
int i;
for (i = 0; i < m_numBackgrounds; i++)
{
char temp[NAME_LENGTH];
sprintf(temp, "Background %d", i + 1);
((CComboBox*) GetDlgItem(IDC_BACKGROUND))->AddString(temp);
}
((CComboBox*) GetDlgItem(IDC_BACKGROUND))->SetCurSel(0);
CDialog::OnInitDialog();
UpdateData(FALSE);
return TRUE;
}
void BackgroundChooser::OnOK()
{
UpdateData(TRUE);
m_chosenBackground = ((CComboBox*) GetDlgItem(IDC_BACKGROUND))->GetCurSel();
CDialog::OnOK();
}
void BackgroundChooser::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
void BackgroundChooser::OnClose()
{
OnCancel();
}
int BackgroundChooser::GetChosenBackground()
{
return m_chosenBackground;
}
+11 -3
View File
@@ -13,7 +13,7 @@
#include "stdafx.h"
#include "FRED.h"
#include "BgBitmapDlg.h"
#include "backgroundchooser.h"
#include "listitemchooser.h"
#include "starfield/starfield.h"
#include "bmpman/bmpman.h"
#include "graphics/light.h"
@@ -1254,11 +1254,19 @@ void bg_bitmap_dlg::OnImportBackground()
if (count > 1)
{
BackgroundChooser dlg(count);
SCP_vector<SCP_string> backgrounds;
for (i = 1; i <= count; ++i)
{
SCP_string str("Background ");
str += std::to_string(i);
backgrounds.push_back(std::move(str));
}
ListItemChooser dlg(backgrounds);
if (dlg.DoModal() == IDCANCEL)
return;
which = dlg.GetChosenBackground();
which = dlg.GetChosenIndex();
}
for (i = 0; i < which + 1; i++)
+4 -4
View File
@@ -2119,14 +2119,14 @@ BEGIN
LTEXT "Restrict departure paths to the following:",IDC_RESTRICT_PATHS_LABEL,7,7,127,11
END
IDD_BACKGROUND_CHOOSER DIALOG 0, 0, 152, 45
IDD_LISTITEM_CHOOSER DIALOG 0, 0, 152, 45
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Choose a background"
CAPTION "Choose an item"
FONT 8, "MS Sans Serif"
BEGIN
DEFPUSHBUTTON "OK",IDOK,95,7,50,14
PUSHBUTTON "Cancel",IDCANCEL,95,24,50,14
COMBOBOX IDC_BACKGROUND,7,16,83,265,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
COMBOBOX IDC_LISTITEM,7,16,83,265,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
END
IDD_FICTION_VIEWER DIALOGEX 0, 0, 205, 85
@@ -2626,7 +2626,7 @@ BEGIN
BOTTOMMARGIN, 80
END
IDD_BACKGROUND_CHOOSER, DIALOG
IDD_LISTITEM_CHOOSER, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 145
+81
View File
@@ -0,0 +1,81 @@
// ListItemChooser.cpp : implementation file
//
#include "stdafx.h"
#include "fred.h"
#include "ListItemChooser.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// ListItemChooser dialog
ListItemChooser::ListItemChooser(const SCP_vector<SCP_string>& listItems)
: CDialog(ListItemChooser::IDD)
{
//{{AFX_DATA_INIT(ListItemChooser)
//}}AFX_DATA_INIT
m_listItems = listItems;
m_chosenItem = -1;
}
void ListItemChooser::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(ListItemChooser)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(ListItemChooser, CDialog)
//{{AFX_MSG_MAP(ListItemChooser)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// ListItemChooser message handlers
BOOL ListItemChooser::OnInitDialog()
{
for (const auto &item: m_listItems)
{
((CComboBox*) GetDlgItem(IDC_LISTITEM))->AddString(item.c_str());
}
((CComboBox*) GetDlgItem(IDC_LISTITEM))->SetCurSel(0);
CDialog::OnInitDialog();
UpdateData(FALSE);
return TRUE;
}
void ListItemChooser::OnOK()
{
UpdateData(TRUE);
m_chosenItem = ((CComboBox*) GetDlgItem(IDC_LISTITEM))->GetCurSel();
CDialog::OnOK();
}
void ListItemChooser::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
void ListItemChooser::OnClose()
{
OnCancel();
}
int ListItemChooser::GetChosenIndex()
{
return m_chosenItem;
}
@@ -1,45 +1,45 @@
#if !defined(_BACKGROUND_CHOOSER_H_)
#define _BACKGROUND_CHOOSER_H_
#if !defined(_LISTITEM_CHOOSER_H_)
#define _LISTITEM_CHOOSER_H_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// BackgroundChooser.h : header file
// ListItemChooser.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// BackgroundChooser dialog
// ListItemChooser dialog
class BackgroundChooser : public CDialog
class ListItemChooser : public CDialog
{
// Construction
// Construction
public:
BackgroundChooser(int numBackgrounds); // standard constructor
ListItemChooser(const SCP_vector<SCP_string>& listItems); // standard constructor
void OnOK();
void OnCancel();
int GetChosenBackground();
int GetChosenIndex();
// Dialog Data
//{{AFX_DATA(BackgroundChooser)
enum { IDD = IDD_BACKGROUND_CHOOSER};
// Dialog Data
//{{AFX_DATA(ListItemChooser)
enum { IDD = IDD_LISTITEM_CHOOSER };
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(BackgroundChooser)
protected:
//{{AFX_VIRTUAL(ListItemChooser)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
int m_numBackgrounds;
int m_chosenBackground;
SCP_vector<SCP_string> m_listItems;
int m_chosenItem;
// Generated message map functions
//{{AFX_MSG(BackgroundChooser)
//{{AFX_MSG(ListItemChooser)
virtual BOOL OnInitDialog();
afx_msg void OnClose();
//}}AFX_MSG
@@ -49,4 +49,4 @@ protected:
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(_BACKGROUND_CHOOSER_H_)
#endif // !defined(_LISTITEM_CHOOSER_H_)
+2 -2
View File
@@ -97,7 +97,7 @@
#define IDD_SET_GLOBAL_SHIP_FLAGS 266
#define IDD_CUSTOM_WING_NAMES 267
#define IDD_RESTRICT_PATHS 270
#define IDD_BACKGROUND_CHOOSER 272
#define IDD_LISTITEM_CHOOSER 272
#define IDB_DATA_05 277
#define IDB_DATA_10 286
#define IDD_ALT_SHIP_CLASS 292
@@ -1074,7 +1074,7 @@
#define IDC_PLAYER_START_CHASE 1583
#define IDC_RESTRICT_PATHS_LABEL 1584
#define IDC_PATH_LIST 1585
#define IDC_BACKGROUND 1586
#define IDC_LISTITEM 1586
#define IDC_ENVMAP 1589
#define IDC_ENVMAP_BROWSE 1590
#define IDC_ENTRY_FORMAT 1590