File: FictionViewerDlg.cpp

package info (click to toggle)
freespace2 3.7.4%2Brepack-1.1
  • links: PTS, VCS
  • area: non-free
  • in suites: bullseye
  • size: 22,268 kB
  • sloc: cpp: 393,535; ansic: 4,106; makefile: 1,091; xml: 181; sh: 137
file content (144 lines) | stat: -rw-r--r-- 3,584 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// FictionViewerDlg.cpp : implementation file
//

#include "stdafx.h"
#include "fred.h"
#include "FictionViewerDlg.h"
#include "missionui/fictionviewer.h"
#include "gamesnd/eventmusic.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// FictionViewerDlg dialog


FictionViewerDlg::FictionViewerDlg(CWnd* pParent /*=NULL*/)
	: CDialog(FictionViewerDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(FictionViewerDlg)
	m_story_file = _T("");
	m_font_file = _T("");
	m_voice_file = _T("");
	m_fiction_music = 0;
	//}}AFX_DATA_INIT
}


void FictionViewerDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(FictionViewerDlg)
	DDX_Text(pDX, IDC_STORY_FILE, m_story_file);
	DDX_Text(pDX, IDC_FONT_FILE, m_font_file);
	DDX_Text(pDX, IDC_VOICE_FILE, m_voice_file);
	DDX_CBIndex(pDX, IDC_FICTION_MUSIC, m_fiction_music);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(FictionViewerDlg, CDialog)
	//{{AFX_MSG_MAP(FictionViewerDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// FictionViewerDlg message handlers

BOOL FictionViewerDlg::OnInitDialog()
{
	int i;
	CComboBox *box;

	box = (CComboBox *) GetDlgItem(IDC_FICTION_MUSIC);
	box->AddString("None");
	for (i=0; i<Num_music_files; i++){
		box->AddString(Spooled_music[i].name);		
	}

	// make sure we have at least one stage
	if (Fiction_viewer_stages.empty())
	{
		fiction_viewer_stage stage;
		memset(&stage, 0, sizeof(fiction_viewer_stage));
		stage.formula = Locked_sexp_true;

		Fiction_viewer_stages.push_back(stage);
	}
	else if (Fiction_viewer_stages.size() > 1)
	{
		MessageBox("You have multiple fiction viewer stages defined for this mission.  At present, FRED will only allow you to edit the first stage.");
	}

	// init fields based on first fiction viewer stage
	fiction_viewer_stage *stagep = &Fiction_viewer_stages.at(0);
	m_story_file = _T(stagep->story_filename);
	m_font_file = _T(stagep->font_filename);
	m_voice_file = _T(stagep->voice_filename);

	// music is managed through the mission
	m_fiction_music = Mission_music[SCORE_FICTION_VIEWER] + 1;

	CDialog::OnInitDialog();
	UpdateData(FALSE);
	return TRUE;
}

void FictionViewerDlg::OnOK() 
{
	UpdateData(TRUE);

	// store the fields in the data structure
	fiction_viewer_stage *stagep = &Fiction_viewer_stages.at(0);
	strcpy_s(stagep->story_filename, (LPCSTR)m_story_file);
	strcpy_s(stagep->font_filename, (LPCSTR)m_font_file);
	strcpy_s(stagep->voice_filename, (LPCSTR)m_voice_file);

	// if we don't have a story file, remove this stage (stage 0)
	if (strlen(stagep->story_filename) == 0)
		Fiction_viewer_stages.erase(Fiction_viewer_stages.begin());

	// set music
	Mission_music[SCORE_FICTION_VIEWER] = m_fiction_music - 1;

	CDialog::OnOK();
}

void FictionViewerDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}

void FictionViewerDlg::OnClose()
{
	int z;

	UpdateData(TRUE);

	if (query_modified()) {
		z = MessageBox("Do you want to keep your changes?", "Close", MB_ICONQUESTION | MB_YESNOCANCEL);
		if (z == IDCANCEL){
			return;
		}

		if (z == IDYES) {
			OnOK();
			return;
		}
	}

	CDialog::OnClose();
}

int FictionViewerDlg::query_modified()
{
	fiction_viewer_stage *stagep = &Fiction_viewer_stages.at(0);

	return strcmp(m_story_file, stagep->story_filename) || strcmp(m_font_file, stagep->font_filename) ||
		strcmp(m_voice_file, stagep->voice_filename) || m_fiction_music != (Mission_music[SCORE_FICTION_VIEWER] + 1);
}