summaryrefslogtreecommitdiff
path: root/utils/scenemanager/waveproperties.cpp
blob: 7dc34f215768e96380606c3784d8bfa1c32f5738 (plain) (blame)
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================//
#include "cbase.h"
#include <mxtk/mx.h>
#include <stdio.h>
#include "resource.h"
#include "WaveProperties.h"
#include "SoundEmitterSystem/isoundemittersystembase.h"
#include "soundentry.h"
#include "cmdlib.h"
#include "workspacemanager.h"
#include "wavebrowser.h"
#include "wavefile.h"
#include "multiplerequest.h"

static CWaveParams g_Params;

static bool WaveLessFunc( const char *const& name1, const char *const& name2 )
{
	if ( stricmp( name1, name2 ) < 0 )
		return true;
	return false;
}

static void WaveProperties_OnOK( HWND hwndDlg )
{
	// Gather info and make changes
	CWaveFile *item = g_Params.items[ 0 ];
	char sentencetext[ 512 ];
						
	GetDlgItemText( hwndDlg, IDC_SENTENCETEXT, sentencetext, sizeof( sentencetext ) );

	bool voiceduck = SendMessage( GetDlgItem( hwndDlg, IDC_VOICEDUCK ), BM_GETCHECK, 0, 0 ) == BST_CHECKED ? true : false;

	MultipleRequestChangeContext();

	// Update ducking on wav files
	item->SetVoiceDuck( voiceduck );
	item->SetSentenceText( sentencetext );

	// Repopulate things
	GetWorkspaceManager()->RefreshBrowsers();
}

char *Q_stristr_slash( char const *pStr, char const *pSearch );

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : hwndDlg - 
//-----------------------------------------------------------------------------
static void WaveProperties_ExportSentence()
{
	int c = g_Params.items.Count();
	if ( c <= 0 )
		return;

	MultipleRequestChangeContext();

	int i;
	for ( i = 0; i < c; i++ )
	{
		CWaveFile *item = g_Params.items[ i ];
		Assert( item );

		char relative[ 512 ];
		item->GetPhonemeExportFile( relative, sizeof( relative ) );
		if ( filesystem->FileExists( relative ) )
		{
			int retval = MultipleRequest( va( "Overwrite '%s'?", relative ) );	
			if ( retval != 0 )
				continue;

			filesystem->RemoveFile( relative );
		}

		item->ExportValveDataChunk( relative );
	}
}

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : hwndDlg - 
//-----------------------------------------------------------------------------
static void WaveProperties_ImportSentence()
{
	int c = g_Params.items.Count();
	if ( c <= 0 )
		return;

	int i;
	for ( i = 0; i < c; i++ )
	{
		CWaveFile *item = g_Params.items[ i ];
		Assert( item );

		char relative[ 512 ];
		item->GetPhonemeExportFile( relative, sizeof( relative ) );
		if ( filesystem->FileExists( relative ) )
		{
			item->ImportValveDataChunk( relative );
		}
	}
}

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : hwndDlg - 
// Output : static
//-----------------------------------------------------------------------------
static void WaveProperties_InitSentenceData( HWND hwndDlg )
{
	CWaveFile *item = g_Params.items[ 0 ];

	SetDlgItemText( hwndDlg, IDC_WAVENAME, item->GetName() );
	SetDlgItemText( hwndDlg, IDC_SENTENCETEXT, item->GetSentenceText() );

	SendMessage( GetDlgItem( hwndDlg, IDC_VOICEDUCK ), BM_SETCHECK, 
		( WPARAM ) item->GetVoiceDuck() ? BST_CHECKED : BST_UNCHECKED,
		( LPARAM )0 );
}

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : hwndDlg - 
//			uMsg - 
//			wParam - 
//			lParam - 
// Output : static BOOL CALLBACK
//-----------------------------------------------------------------------------
static BOOL CALLBACK WavePropertiesDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
	switch(uMsg)
	{
    case WM_INITDIALOG:
		{
			g_Params.PositionSelf( hwndDlg );

			WaveProperties_InitSentenceData( hwndDlg );

			SetWindowText( hwndDlg, g_Params.m_szDialogTitle );

			SetFocus( GetDlgItem( hwndDlg, IDC_WAVENAME ) );
		}
		return FALSE;  
		
    case WM_COMMAND:
		switch (LOWORD(wParam))
		{
		case IDOK:
			{
				WaveProperties_OnOK( hwndDlg );

				EndDialog( hwndDlg, 1 );
			}
			break;
        case IDCANCEL:
			EndDialog( hwndDlg, 0 );
			break;
		case IDC_EXPORTSENTENCE:
			WaveProperties_ExportSentence();
			break;
		case IDC_IMPORTSENTENCE:
			WaveProperties_ImportSentence();
			WaveProperties_InitSentenceData( hwndDlg );
			break;
		}
		return FALSE;
	}
	return FALSE;
}

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *view - 
//			*actor - 
// Output : int
//-----------------------------------------------------------------------------
int WaveProperties( CWaveParams *params )
{
	g_Params = *params;

	int retval = DialogBox( (HINSTANCE)GetModuleHandle( 0 ), 
		MAKEINTRESOURCE( IDD_WAVEPROPERTIES ),
		(HWND)GetWorkspaceManager()->getHandle(),
		(DLGPROC)WavePropertiesDialogProc );

	*params = g_Params;

	return retval;
}