File: campaignfilelistbox.cpp

package info (click to toggle)
freespace2 24.2.0%2Brepack-3
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 43,740 kB
  • sloc: cpp: 595,005; ansic: 21,741; python: 1,174; sh: 457; makefile: 243; xml: 181
file content (107 lines) | stat: -rw-r--r-- 3,110 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
/*
 * Copyright (C) Volition, Inc. 1999.  All rights reserved.
 *
 * All source code herein is the property of Volition, Inc. You may not sell 
 * or otherwise commercially exploit the source or things you created based on the 
 * source.
 *
*/

// CampaignFilelistBox.cpp : implementation file
//

#include "stdafx.h"

#include "FRED.h"
#include "CampaignFilelistBox.h"
#include "CampaignTreeWnd.h"

#include "mission/missioncampaign.h"
#include "mission/missionparse.h"

#include <freespace.h>

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

/////////////////////////////////////////////////////////////////////////////
// campaign_filelist_box

campaign_filelist_box::campaign_filelist_box()
{
}

campaign_filelist_box::~campaign_filelist_box()
{
}


BEGIN_MESSAGE_MAP(campaign_filelist_box, CListBox)
	//{{AFX_MSG_MAP(campaign_filelist_box)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// campaign_filelist_box message handlers

void campaign_filelist_box::initialize(const CString &path)
{
	int i, z;
	SCP_vector<SCP_string> mission_filenames;
	SCP_string filter;
	mission a_mission;

	ResetContent();

	// if there's a path, cf_get_file_list will look there; if not, it will use the file filter in the standard location
	if (!path.IsEmpty())
	{
		filter = (LPCTSTR)path;
		if (filter.back() != DIR_SEPARATOR_CHAR)
			filter += DIR_SEPARATOR_CHAR;
	}
	filter += "*.fs2";

	extern int Skip_packfile_search;
	Skip_packfile_search = 1;
	cf_get_file_list(mission_filenames, CF_TYPE_MISSIONS, filter.c_str());
	Skip_packfile_search = 0;


	for (i = 0; i < (int)mission_filenames.size(); i++)
	{
		// add the extension; the file list box wants to display it, and we need it for absolute paths anyway
		mission_filenames[i] += ".fs2";

		// make a call to get the mission info for this mission.  Passing a mission as the second
		// parameter will prevent The_mission from getting overwritten.
		if (path.IsEmpty())
			get_mission_info(mission_filenames[i].c_str(), &a_mission);
		else
		{
			auto file_to_load = mission_filenames[i];
			if (!path.IsEmpty())
				file_to_load = (LPCTSTR)path + file_to_load;
			get_mission_info(file_to_load.c_str(), &a_mission, true, true);
		}

		// only add missions of the appropriate type to the file listbox
		if ( (Campaign.type == CAMPAIGN_TYPE_SINGLE) && (a_mission.game_type & (MISSION_TYPE_SINGLE|MISSION_TYPE_TRAINING)) )
			AddString(mission_filenames[i].c_str());
		else if ( (Campaign.type == CAMPAIGN_TYPE_MULTI_COOP) && (a_mission.game_type & MISSION_TYPE_MULTI_COOP) )
			AddString(mission_filenames[i].c_str());
		else if ( (Campaign.type == CAMPAIGN_TYPE_MULTI_TEAMS) && (a_mission.game_type & MISSION_TYPE_MULTI_TEAMS) )
			AddString(mission_filenames[i].c_str());
	} 
	

	for (i=0; i<Campaign.num_missions; i++) {
		z = FindString(-1, Campaign.missions[i].name);
		if (z != LB_ERR) {
			DeleteString(z);  // take out all missions already in the campaign
			i--;  // recheck for name just in case there are two (should be impossible but can't be sure)
		}
	}
}