File: FictionViewerDlg.cpp

package info (click to toggle)
freespace2 24.0.2%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: trixie
  • size: 43,188 kB
  • sloc: cpp: 583,107; ansic: 21,729; python: 1,174; sh: 464; makefile: 248; xml: 181
file content (173 lines) | stat: -rw-r--r-- 4,047 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// 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()
{
	CComboBox *box;

	box = (CComboBox *) GetDlgItem(IDC_FICTION_MUSIC);
	box->AddString("None");
	for (auto &sm: Spooled_music) {
		box->AddString(sm.name);
	}

	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
	if (!Fiction_viewer_stages.empty())
	{
		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);

	// remove whitespace
	m_story_file.Trim();
	m_font_file.Trim();
	m_voice_file.Trim();

	// if we don't have a story file, remove the fiction stuff
	if (m_story_file.GetLength() == 0)
	{
		// we only edit stage 0, so remove that
		if (!Fiction_viewer_stages.empty())
			Fiction_viewer_stages.erase(Fiction_viewer_stages.begin());

		// set music
		Mission_music[SCORE_FICTION_VIEWER] = -1;
	}
	// we have a story file, so save our data
	else
	{
		// 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);
		}

		// 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);

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

	CDialog::OnOK();
}

void FictionViewerDlg::OnCancel() 
{
	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()
{
	const char *story, *font, *voice;
	if (Fiction_viewer_stages.empty())
	{
		story = "";
		font = "";
		voice = "";
	}
	else
	{
		auto stagep = &Fiction_viewer_stages.at(0);
		story = (LPCSTR)stagep->story_filename;
		font = (LPCSTR)stagep->font_filename;
		voice = (LPCSTR)stagep->voice_filename;
	}

	return strcmp(m_story_file, story) || strcmp(m_font_file, font) || strcmp(m_voice_file, voice)
		|| m_fiction_music != (Mission_music[SCORE_FICTION_VIEWER] + 1);
}