forked from stepmania/stepmania
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScreenOptionsCourseOverview.cpp
284 lines (251 loc) · 8.75 KB
/
ScreenOptionsCourseOverview.cpp
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#include "global.h"
#include "ScreenOptionsCourseOverview.h"
#include "ScreenManager.h"
#include "RageUtil.h"
#include "GameState.h"
#include "OptionRowHandler.h"
#include "ProfileManager.h"
#include "ScreenMiniMenu.h"
#include "LocalizedString.h"
#include "SongManager.h"
#include "SongUtil.h"
#include "ScreenTextEntry.h"
#include "GameManager.h"
#include "Profile.h"
#include "ScreenPrompt.h"
#include "PlayerState.h"
#include "Style.h"
#include "PrefsManager.h"
#include "RageFmtWrap.h"
using std::vector;
enum CourseOverviewRow
{
CourseOverviewRow_Play,
CourseOverviewRow_Edit,
CourseOverviewRow_Shuffle,
CourseOverviewRow_Rename,
CourseOverviewRow_Delete,
CourseOverviewRow_Save,
NUM_CourseOverviewRow
};
static bool CurrentCourseIsSaved()
{
Course *pCourse = GAMESTATE->m_pCurCourse;
if( pCourse == nullptr )
{
return false;
}
return !pCourse->m_sPath.empty();
}
static const MenuRowDef g_MenuRows[] =
{
MenuRowDef( -1, "Play", true, EditMode_Practice, true, false, 0),
MenuRowDef( -1, "Edit Course", true, EditMode_Practice, true, false, 0),
MenuRowDef( -1, "Shuffle", true, EditMode_Practice, true, false, 0),
MenuRowDef( -1, "Rename", CurrentCourseIsSaved, EditMode_Practice, true, false, 0),
MenuRowDef( -1, "Delete", CurrentCourseIsSaved, EditMode_Practice, true, false, 0),
MenuRowDef( -1, "Save", true, EditMode_Practice, true, false, 0),
};
REGISTER_SCREEN_CLASS( ScreenOptionsCourseOverview );
static LocalizedString ENTER_COURSE_NAME ("ScreenOptionsCourseOverview", "Enter a name for the course.");
static LocalizedString ERROR_SAVING_COURSE ("ScreenOptionsCourseOverview", "Error saving course.");
static LocalizedString COURSE_SAVED ("ScreenOptionsCourseOverview", "Course saved successfully.");
static LocalizedString ERROR_RENAMING ("ScreenOptionsCourseOverview", "Error renaming file.");
static LocalizedString ERROR_DELETING_FILE ("ScreenOptionsCourseOverview", "Error deleting the file '%s'.");
static LocalizedString COURSE_WILL_BE_LOST ("ScreenOptionsCourseOverview", "This course will be lost permanently.");
static LocalizedString CONTINUE_WITH_DELETE ("ScreenOptionsCourseOverview", "Continue with delete?");
AutoScreenMessage( SM_BackFromEnterName );
AutoScreenMessage( SM_BackFromRename );
AutoScreenMessage( SM_BackFromDelete );
void ScreenOptionsCourseOverview::Init()
{
if( PREFSMAN->m_iArcadeOptionsNavigation )
SetNavigation( NAV_THREE_KEY_MENU );
ScreenOptions::Init();
m_soundSave.Load( THEME->GetPathS(m_sName,"Save") );
PLAY_SCREEN.Load(m_sName,"PlayScreen");
EDIT_SCREEN.Load(m_sName,"EditScreen");
}
void ScreenOptionsCourseOverview::BeginScreen()
{
vector<OptionRowHandler*> vHands;
FOREACH_ENUM( CourseOverviewRow, rowIndex )
{
const MenuRowDef &mr = g_MenuRows[rowIndex];
OptionRowHandler *pHand = OptionRowHandlerUtil::MakeSimple( mr );
vHands.push_back( pHand );
}
ScreenOptions::InitMenu( vHands );
ScreenOptions::BeginScreen();
// clear the current song in case it's set when we back out from gameplay
GAMESTATE->set_curr_song(nullptr);
}
ScreenOptionsCourseOverview::~ScreenOptionsCourseOverview()
{
}
void ScreenOptionsCourseOverview::ImportOptions(int, const vector<PlayerNumber>&)
{
//OptionRow &row = *m_pRows[iRow];
}
void ScreenOptionsCourseOverview::ExportOptions(int iRow, const vector<PlayerNumber>&)
{
OptionRow &row = *m_pRows[iRow];
int iIndex = row.GetOneSharedSelection( true );
std::string sValue;
if( iIndex >= 0 )
sValue = row.GetRowDef().m_vsChoices[ iIndex ];
}
void ScreenOptionsCourseOverview::HandleScreenMessage( const ScreenMessage SM )
{
if( SM == SM_GoToPrevScreen )
{
// If we're pointing to an unsaved course, it will be inaccessible once we're back on ScreenOptionsManageCourses.
GAMESTATE->m_pCurCourse.Set( nullptr );
}
else if( SM == SM_GoToNextScreen )
{
int iRow = m_iCurrentRow[GAMESTATE->GetMasterPlayerNumber()];
switch( iRow )
{
case CourseOverviewRow_Play:
EditCourseUtil::PrepareForPlay();
SCREENMAN->SetNewScreen( PLAY_SCREEN.GetValue() );
return; // handled
case CourseOverviewRow_Edit:
SCREENMAN->SetNewScreen( EDIT_SCREEN.GetValue() );
return; // handled
}
}
else if( SM == SM_BackFromEnterName )
{
if( !ScreenTextEntry::s_bCancelledLast )
{
ASSERT( ScreenTextEntry::s_sLastAnswer != "" ); // validate should have assured this
if( EditCourseUtil::RenameAndSave( GAMESTATE->m_pCurCourse, ScreenTextEntry::s_sLastAnswer ) )
{
m_soundSave.Play(true);
SCREENMAN->SystemMessage( COURSE_SAVED.GetValue() );
}
}
}
else if( SM == SM_BackFromRename )
{
if( !ScreenTextEntry::s_bCancelledLast )
{
ASSERT( ScreenTextEntry::s_sLastAnswer != "" ); // validate should have assured this
if( !EditCourseUtil::RenameAndSave(GAMESTATE->m_pCurCourse, ScreenTextEntry::s_sLastAnswer) )
{
ScreenPrompt::Prompt( SM_None, ERROR_RENAMING.GetValue() );
return;
}
SCREENMAN->SetNewScreen( this->m_sName ); // reload
}
}
else if( SM == SM_BackFromDelete )
{
if( ScreenPrompt::s_LastAnswer == ANSWER_YES )
{
if( !EditCourseUtil::RemoveAndDeleteFile(GAMESTATE->m_pCurCourse) )
{
ScreenPrompt::Prompt( SM_None, rage_fmt_wrapper(ERROR_DELETING_FILE, GAMESTATE->m_pCurCourse->m_sPath.c_str()) );
return;
}
GAMESTATE->m_pCurCourse.Set( nullptr );
GAMESTATE->m_pCurTrail[PLAYER_1].Set( nullptr );
/* Our course is gone, so back out. */
StartTransitioningScreen( SM_GoToPrevScreen );
}
}
ScreenOptions::HandleScreenMessage( SM );
}
void ScreenOptionsCourseOverview::AfterChangeValueInRow( int iRow, PlayerNumber pn )
{
ScreenOptions::AfterChangeValueInRow( iRow, pn );
}
void ScreenOptionsCourseOverview::ProcessMenuStart( const InputEventPlus &input )
{
if( IsTransitioning() )
return;
int iRow = m_iCurrentRow[GAMESTATE->GetMasterPlayerNumber()];
switch( iRow )
{
case CourseOverviewRow_Play:
case CourseOverviewRow_Edit:
SCREENMAN->PlayStartSound();
this->BeginFadingOut();
return; // handled
case CourseOverviewRow_Shuffle:
{
Course *pCourse = GAMESTATE->m_pCurCourse;
std::shuffle(pCourse->m_vEntries.begin(), pCourse->m_vEntries.end(), g_RandomNumberGenerator);
Trail *pTrail = pCourse->GetTrailForceRegenCache( GAMESTATE->GetCurrentStyle(input.pn)->m_StepsType );
GAMESTATE->m_pCurTrail[PLAYER_1].Set( pTrail );
SCREENMAN->PlayStartSound();
MESSAGEMAN->Broadcast("CurrentCourseChanged");
}
return; // handled
case CourseOverviewRow_Rename:
ScreenTextEntry::TextEntry(
SM_BackFromRename,
ENTER_COURSE_NAME.GetValue(),
GAMESTATE->m_pCurCourse->GetDisplayFullTitle(),
EditCourseUtil::MAX_NAME_LENGTH,
EditCourseUtil::ValidateEditCourseName );
break;
case CourseOverviewRow_Delete:
ScreenPrompt::Prompt( SM_BackFromDelete, COURSE_WILL_BE_LOST.GetValue()+"\n\n"+CONTINUE_WITH_DELETE.GetValue(), PROMPT_YES_NO, ANSWER_NO );
break;
case CourseOverviewRow_Save:
{
bool bPromptForName = EditCourseUtil::s_bNewCourseNeedsName;
if( bPromptForName )
{
ScreenTextEntry::TextEntry(
SM_BackFromEnterName,
ENTER_COURSE_NAME.GetValue(),
GAMESTATE->m_pCurCourse->GetDisplayFullTitle(),
EditCourseUtil::MAX_NAME_LENGTH,
EditCourseUtil::ValidateEditCourseName );
}
else
{
if( EditCourseUtil::Save( GAMESTATE->m_pCurCourse ) )
{
m_soundSave.Play(true);
SCREENMAN->SystemMessage( COURSE_SAVED.GetValue() );
}
else
{
SCREENMAN->PlayInvalidSound();
SCREENMAN->SystemMessage( ERROR_SAVING_COURSE.GetValue() );
}
}
}
return; // handled
}
ScreenOptions::ProcessMenuStart( input );
}
/*
* (c) 2003-2004 Chris Danford
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/