[Project64] Cleanup Settings/SettingsPage-GameBrowser.cpp

This commit is contained in:
zilmar 2015-12-24 06:39:23 +11:00
parent fd5941fa35
commit 58c125d337
2 changed files with 198 additions and 198 deletions

View File

@ -16,242 +16,242 @@ COptionsGameBrowserPage::COptionsGameBrowserPage(HWND hParent, const RECT & rcDi
m_OrderChanged(false), m_OrderChanged(false),
m_OrderReset(false) m_OrderReset(false)
{ {
if (!Create(hParent, rcDispay)) if (!Create(hParent, rcDispay))
{ {
return; return;
} }
SetDlgItemTextW(m_hWnd, IDC_ROMSEL_TEXT2, GS(RB_ROMS)); SetDlgItemTextW(m_hWnd, IDC_ROMSEL_TEXT2, GS(RB_ROMS));
SetDlgItemTextW(m_hWnd, IDC_ROMSEL_TEXT4, GS(RB_DIRS)); SetDlgItemTextW(m_hWnd, IDC_ROMSEL_TEXT4, GS(RB_DIRS));
SetDlgItemTextW(m_hWnd, IDC_USE_ROMBROWSER, GS(RB_USE)); SetDlgItemTextW(m_hWnd, IDC_USE_ROMBROWSER, GS(RB_USE));
SetDlgItemTextW(m_hWnd, IDC_RECURSION, GS(RB_DIR_RECURSION)); SetDlgItemTextW(m_hWnd, IDC_RECURSION, GS(RB_DIR_RECURSION));
SetDlgItemTextW(m_hWnd, IDC_ROMSEL_TEXT5, GS(RB_AVALIABLE_FIELDS)); SetDlgItemTextW(m_hWnd, IDC_ROMSEL_TEXT5, GS(RB_AVALIABLE_FIELDS));
SetDlgItemTextW(m_hWnd, IDC_ROMSEL_TEXT6, GS(RB_SHOW_FIELDS)); SetDlgItemTextW(m_hWnd, IDC_ROMSEL_TEXT6, GS(RB_SHOW_FIELDS));
SetDlgItemTextW(m_hWnd, IDC_ADD, GS(RB_ADD)); SetDlgItemTextW(m_hWnd, IDC_ADD, GS(RB_ADD));
SetDlgItemTextW(m_hWnd, IDC_REMOVE, GS(RB_REMOVE)); SetDlgItemTextW(m_hWnd, IDC_REMOVE, GS(RB_REMOVE));
SetDlgItemTextW(m_hWnd, IDC_UP, GS(RB_UP)); SetDlgItemTextW(m_hWnd, IDC_UP, GS(RB_UP));
SetDlgItemTextW(m_hWnd, IDC_DOWN, GS(RB_DOWN)); SetDlgItemTextW(m_hWnd, IDC_DOWN, GS(RB_DOWN));
AddModCheckBox(GetDlgItem(IDC_USE_ROMBROWSER), RomBrowser_Enabled); AddModCheckBox(GetDlgItem(IDC_USE_ROMBROWSER), RomBrowser_Enabled);
AddModCheckBox(GetDlgItem(IDC_RECURSION), RomBrowser_Recursive); AddModCheckBox(GetDlgItem(IDC_RECURSION), RomBrowser_Recursive);
m_Avaliable.Attach(GetDlgItem(IDC_AVALIABLE)); m_Avaliable.Attach(GetDlgItem(IDC_AVALIABLE));
m_Using.Attach(GetDlgItem(IDC_USING)); m_Using.Attach(GetDlgItem(IDC_USING));
CRomBrowser::GetFieldInfo(m_Fields); CRomBrowser::GetFieldInfo(m_Fields);
UpdatePageSettings(); UpdatePageSettings();
} }
void COptionsGameBrowserPage::UpdateFieldList(const ROMBROWSER_FIELDS_LIST & Fields) void COptionsGameBrowserPage::UpdateFieldList(const ROMBROWSER_FIELDS_LIST & Fields)
{ {
m_Avaliable.ResetContent(); m_Avaliable.ResetContent();
m_Using.ResetContent(); m_Using.ResetContent();
m_OrderChanged = false; m_OrderChanged = false;
for (int i = 0, n = Fields.size(); i < n; i++) for (int i = 0, n = Fields.size(); i < n; i++)
{ {
if (Fields[i].PosChanged()) if (Fields[i].PosChanged())
{ {
m_OrderChanged = true; m_OrderChanged = true;
} }
int Pos = Fields[i].Pos(); int Pos = Fields[i].Pos();
if (Pos < 0) if (Pos < 0)
{ {
m_Avaliable.SetItemData(m_Avaliable.AddStringW(GS(Fields[i].LangID())), i); m_Avaliable.SetItemData(m_Avaliable.AddStringW(GS(Fields[i].LangID())), i);
continue; continue;
} }
int listCount = m_Using.GetCount(); int listCount = m_Using.GetCount();
if (Pos > listCount) { Pos = listCount; } if (Pos > listCount) { Pos = listCount; }
m_Using.SetItemData(m_Using.InsertStringW(Pos, GS(Fields[i].LangID())), i); m_Using.SetItemData(m_Using.InsertStringW(Pos, GS(Fields[i].LangID())), i);
} }
} }
void COptionsGameBrowserPage::UpdatePageSettings(void) void COptionsGameBrowserPage::UpdatePageSettings(void)
{ {
UpdateFieldList(m_Fields); UpdateFieldList(m_Fields);
CSettingsPageImpl<COptionsGameBrowserPage>::UpdatePageSettings(); CSettingsPageImpl<COptionsGameBrowserPage>::UpdatePageSettings();
FixCtrlState(); FixCtrlState();
} }
void COptionsGameBrowserPage::UseRomBrowserChanged(UINT Code, int id, HWND ctl) void COptionsGameBrowserPage::UseRomBrowserChanged(UINT Code, int id, HWND ctl)
{ {
CheckBoxChanged(Code, id, ctl); CheckBoxChanged(Code, id, ctl);
FixCtrlState(); FixCtrlState();
} }
void COptionsGameBrowserPage::FixCtrlState(void) void COptionsGameBrowserPage::FixCtrlState(void)
{ {
bool bEnabled = (SendDlgItemMessage(IDC_USE_ROMBROWSER, BM_GETCHECK, 0, 0) == BST_CHECKED); bool bEnabled = (SendDlgItemMessage(IDC_USE_ROMBROWSER, BM_GETCHECK, 0, 0) == BST_CHECKED);
::EnableWindow(GetDlgItem(IDC_ROMSEL_TEXT5), bEnabled); ::EnableWindow(GetDlgItem(IDC_ROMSEL_TEXT5), bEnabled);
::EnableWindow(GetDlgItem(IDC_ROMSEL_TEXT6), bEnabled); ::EnableWindow(GetDlgItem(IDC_ROMSEL_TEXT6), bEnabled);
::EnableWindow(GetDlgItem(IDC_AVALIABLE), bEnabled); ::EnableWindow(GetDlgItem(IDC_AVALIABLE), bEnabled);
::EnableWindow(GetDlgItem(IDC_ADD), bEnabled); ::EnableWindow(GetDlgItem(IDC_ADD), bEnabled);
::EnableWindow(GetDlgItem(IDC_REMOVE), bEnabled); ::EnableWindow(GetDlgItem(IDC_REMOVE), bEnabled);
::EnableWindow(GetDlgItem(IDC_USING), bEnabled); ::EnableWindow(GetDlgItem(IDC_USING), bEnabled);
::EnableWindow(GetDlgItem(IDC_UP), bEnabled); ::EnableWindow(GetDlgItem(IDC_UP), bEnabled);
::EnableWindow(GetDlgItem(IDC_DOWN), bEnabled); ::EnableWindow(GetDlgItem(IDC_DOWN), bEnabled);
::EnableWindow(GetDlgItem(IDC_RECURSION), bEnabled); ::EnableWindow(GetDlgItem(IDC_RECURSION), bEnabled);
} }
void COptionsGameBrowserPage::AddFieldClicked(UINT /*Code*/, int /*id*/, HWND /*ctl*/) void COptionsGameBrowserPage::AddFieldClicked(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{ {
int index = m_Avaliable.GetCurSel(); int index = m_Avaliable.GetCurSel();
if (index < 0) if (index < 0)
{ {
return; return;
} }
//remove from list //remove from list
int i = m_Avaliable.GetItemData(index); int i = m_Avaliable.GetItemData(index);
m_Avaliable.DeleteString(index); m_Avaliable.DeleteString(index);
//select next in list //select next in list
int listCount = m_Avaliable.GetCount(); int listCount = m_Avaliable.GetCount();
if (index >= listCount) { index -= 1; } if (index >= listCount) { index -= 1; }
m_Avaliable.SetCurSel(index); m_Avaliable.SetCurSel(index);
//Add to list //Add to list
index = m_Using.AddStringW(GS(m_Fields[i].LangID())); index = m_Using.AddStringW(GS(m_Fields[i].LangID()));
m_Using.SetItemData(index, i); m_Using.SetItemData(index, i);
m_Using.SetCurSel(index); m_Using.SetCurSel(index);
m_OrderChanged = true; m_OrderChanged = true;
m_OrderReset = false; m_OrderReset = false;
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0); SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
} }
void COptionsGameBrowserPage::RemoveFieldClicked(UINT /*Code*/, int /*id*/, HWND /*ctl*/) void COptionsGameBrowserPage::RemoveFieldClicked(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{ {
int index = m_Using.GetCurSel(); int index = m_Using.GetCurSel();
if (index < 0) if (index < 0)
{ {
return; return;
} }
//remove from list //remove from list
int i = m_Using.GetItemData(index); int i = m_Using.GetItemData(index);
m_Using.DeleteString(index); m_Using.DeleteString(index);
//select next in list //select next in list
int listCount = m_Using.GetCount(); int listCount = m_Using.GetCount();
if (index >= listCount) { index -= 1; } if (index >= listCount) { index -= 1; }
m_Using.SetCurSel(index); m_Using.SetCurSel(index);
//Add to list //Add to list
index = m_Avaliable.AddStringW(GS(m_Fields[i].LangID())); index = m_Avaliable.AddStringW(GS(m_Fields[i].LangID()));
m_Avaliable.SetItemData(index, i); m_Avaliable.SetItemData(index, i);
m_Avaliable.SetCurSel(index); m_Avaliable.SetCurSel(index);
m_OrderChanged = true; m_OrderChanged = true;
m_OrderReset = false; m_OrderReset = false;
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0); SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
} }
void COptionsGameBrowserPage::MoveFieldUpClicked(UINT /*Code*/, int /*id*/, HWND /*ctl*/) void COptionsGameBrowserPage::MoveFieldUpClicked(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{ {
int index = m_Using.GetCurSel(); int index = m_Using.GetCurSel();
if (index <= 0) if (index <= 0)
{ {
return; return;
} }
int i = m_Using.GetItemData(index); int i = m_Using.GetItemData(index);
m_Using.DeleteString(index); m_Using.DeleteString(index);
index = m_Using.InsertStringW(index - 1, GS(m_Fields[i].LangID())); index = m_Using.InsertStringW(index - 1, GS(m_Fields[i].LangID()));
m_Using.SetItemData(index, i); m_Using.SetItemData(index, i);
m_Using.SetCurSel(index); m_Using.SetCurSel(index);
m_OrderChanged = true; m_OrderChanged = true;
m_OrderReset = false; m_OrderReset = false;
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0); SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
} }
void COptionsGameBrowserPage::MoveFieldDownClicked(UINT /*Code*/, int /*id*/, HWND /*ctl*/) void COptionsGameBrowserPage::MoveFieldDownClicked(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{ {
int index = m_Using.GetCurSel(); int index = m_Using.GetCurSel();
if (index < 0 || index >= (m_Using.GetCount() - 1)) if (index < 0 || index >= (m_Using.GetCount() - 1))
{ {
return; return;
} }
int i = m_Using.GetItemData(index); int i = m_Using.GetItemData(index);
m_Using.DeleteString(index); m_Using.DeleteString(index);
index = m_Using.InsertStringW(index + 1, GS(m_Fields[i].LangID())); index = m_Using.InsertStringW(index + 1, GS(m_Fields[i].LangID()));
m_Using.SetItemData(index, i); m_Using.SetItemData(index, i);
m_Using.SetCurSel(index); m_Using.SetCurSel(index);
m_OrderChanged = true; m_OrderChanged = true;
m_OrderReset = false; m_OrderReset = false;
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0); SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
} }
void COptionsGameBrowserPage::HidePage() void COptionsGameBrowserPage::HidePage()
{ {
ShowWindow(SW_HIDE); ShowWindow(SW_HIDE);
} }
void COptionsGameBrowserPage::ShowPage() void COptionsGameBrowserPage::ShowPage()
{ {
ShowWindow(SW_SHOW); ShowWindow(SW_SHOW);
} }
void COptionsGameBrowserPage::ApplySettings(bool UpdateScreen) void COptionsGameBrowserPage::ApplySettings(bool UpdateScreen)
{ {
bool bColChanged = false; bool bColChanged = false;
if (m_OrderReset) if (m_OrderReset)
{ {
for (size_t i = 0; i < m_Fields.size(); i++) for (size_t i = 0; i < m_Fields.size(); i++)
{ {
m_Fields[i].ResetPos(); m_Fields[i].ResetPos();
} }
bColChanged = true; bColChanged = true;
} }
else else
{ {
size_t Item, listCount = m_Using.GetCount(); size_t Item, listCount = m_Using.GetCount();
for (Item = 0; Item < listCount; Item++) for (Item = 0; Item < listCount; Item++)
{ {
int Pos = m_Using.GetItemData(Item); int Pos = m_Using.GetItemData(Item);
if (m_OrderReset || m_Fields[Pos].Pos() != Item) if (m_OrderReset || m_Fields[Pos].Pos() != Item)
{ {
m_Fields[Pos].SetColPos(Item); m_Fields[Pos].SetColPos(Item);
bColChanged = true; bColChanged = true;
} }
} }
listCount = m_Avaliable.GetCount(); listCount = m_Avaliable.GetCount();
for (Item = 0; Item < listCount; Item++) for (Item = 0; Item < listCount; Item++)
{ {
int Pos = m_Avaliable.GetItemData(Item); int Pos = m_Avaliable.GetItemData(Item);
if (m_OrderReset || m_Fields[Pos].Pos() != -1) if (m_OrderReset || m_Fields[Pos].Pos() != -1)
{ {
m_Fields[Pos].SetColPos(-1); m_Fields[Pos].SetColPos(-1);
bColChanged = true; bColChanged = true;
} }
} }
} }
if (bColChanged) if (bColChanged)
{ {
g_Settings->SaveBool(RomBrowser_ColoumnsChanged, !g_Settings->LoadBool(RomBrowser_ColoumnsChanged)); g_Settings->SaveBool(RomBrowser_ColoumnsChanged, !g_Settings->LoadBool(RomBrowser_ColoumnsChanged));
} }
CSettingsPageImpl<COptionsGameBrowserPage>::ApplySettings(UpdateScreen); CSettingsPageImpl<COptionsGameBrowserPage>::ApplySettings(UpdateScreen);
} }
bool COptionsGameBrowserPage::EnableReset(void) bool COptionsGameBrowserPage::EnableReset(void)
{ {
if (m_OrderChanged) { return true; } if (m_OrderChanged) { return true; }
return CSettingsPageImpl<COptionsGameBrowserPage>::EnableReset(); return CSettingsPageImpl<COptionsGameBrowserPage>::EnableReset();
} }
void COptionsGameBrowserPage::ResetPage() void COptionsGameBrowserPage::ResetPage()
{ {
if (m_OrderChanged) if (m_OrderChanged)
{ {
ROMBROWSER_FIELDS_LIST Fields; ROMBROWSER_FIELDS_LIST Fields;
CRomBrowser::GetFieldInfo(Fields, true); CRomBrowser::GetFieldInfo(Fields, true);
UpdateFieldList(Fields); UpdateFieldList(Fields);
m_OrderReset = true; m_OrderReset = true;
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0); SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
} }
CSettingsPageImpl<COptionsGameBrowserPage>::ResetPage(); CSettingsPageImpl<COptionsGameBrowserPage>::ResetPage();
} }

View File

@ -11,41 +11,41 @@
#pragma once #pragma once
class COptionsGameBrowserPage : class COptionsGameBrowserPage :
public CSettingsPageImpl<COptionsGameBrowserPage>, public CSettingsPageImpl<COptionsGameBrowserPage>,
public CSettingsPage public CSettingsPage
{ {
BEGIN_MSG_MAP_EX(COptionsGameBrowserPage) BEGIN_MSG_MAP_EX(COptionsGameBrowserPage)
COMMAND_HANDLER_EX(IDC_ADD,BN_CLICKED,AddFieldClicked) COMMAND_HANDLER_EX(IDC_ADD, BN_CLICKED, AddFieldClicked)
COMMAND_HANDLER_EX(IDC_REMOVE,BN_CLICKED,RemoveFieldClicked) COMMAND_HANDLER_EX(IDC_REMOVE, BN_CLICKED, RemoveFieldClicked)
COMMAND_HANDLER_EX(IDC_UP,BN_CLICKED,MoveFieldUpClicked) COMMAND_HANDLER_EX(IDC_UP, BN_CLICKED, MoveFieldUpClicked)
COMMAND_HANDLER_EX(IDC_DOWN,BN_CLICKED,MoveFieldDownClicked) COMMAND_HANDLER_EX(IDC_DOWN, BN_CLICKED, MoveFieldDownClicked)
COMMAND_ID_HANDLER_EX(IDC_USE_ROMBROWSER,UseRomBrowserChanged) COMMAND_ID_HANDLER_EX(IDC_USE_ROMBROWSER, UseRomBrowserChanged)
COMMAND_ID_HANDLER_EX(IDC_RECURSION,CheckBoxChanged) COMMAND_ID_HANDLER_EX(IDC_RECURSION, CheckBoxChanged)
END_MSG_MAP() END_MSG_MAP()
enum { IDD = IDD_Settings_RomBrowser }; enum { IDD = IDD_Settings_RomBrowser };
public: public:
COptionsGameBrowserPage(HWND hParent, const RECT & rcDispay ); COptionsGameBrowserPage(HWND hParent, const RECT & rcDispay);
LanguageStringID PageTitle ( void ) { return TAB_ROMSELECTION; } LanguageStringID PageTitle(void) { return TAB_ROMSELECTION; }
void HidePage ( void ); void HidePage(void);
void ShowPage ( void ); void ShowPage(void);
void ApplySettings ( bool UpdateScreen ); void ApplySettings(bool UpdateScreen);
bool EnableReset ( void ); bool EnableReset(void);
void ResetPage ( void ); void ResetPage(void);
private: private:
void UpdatePageSettings ( void ); void UpdatePageSettings(void);
void UpdateFieldList ( const ROMBROWSER_FIELDS_LIST & Fields ); void UpdateFieldList(const ROMBROWSER_FIELDS_LIST & Fields);
void AddFieldClicked ( UINT Code, int id, HWND ctl ); void AddFieldClicked(UINT Code, int id, HWND ctl);
void RemoveFieldClicked ( UINT Code, int id, HWND ctl ); void RemoveFieldClicked(UINT Code, int id, HWND ctl);
void MoveFieldUpClicked ( UINT Code, int id, HWND ctl ); void MoveFieldUpClicked(UINT Code, int id, HWND ctl);
void MoveFieldDownClicked ( UINT Code, int id, HWND ctl ); void MoveFieldDownClicked(UINT Code, int id, HWND ctl);
void UseRomBrowserChanged ( UINT Code, int id, HWND ctl ); void UseRomBrowserChanged(UINT Code, int id, HWND ctl);
void FixCtrlState ( void ); void FixCtrlState(void);
ROMBROWSER_FIELDS_LIST m_Fields; ROMBROWSER_FIELDS_LIST m_Fields;
CListBox m_Avaliable, m_Using; CListBox m_Avaliable, m_Using;
bool m_OrderChanged, m_OrderReset; bool m_OrderChanged, m_OrderReset;
}; };