-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAchievementSound1.c
163 lines (137 loc) · 5.22 KB
/
AchievementSound1.c
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
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <SDL/SDL_ttf.h>
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define SCREEN_BPP 16
#define DEFAULT 0
#define XBOX 1
#define PLAYSTATION 2
void drawOption(SDL_Surface* screen, const char* text, TTF_Font* font, SDL_Rect rect, int selected)
{
SDL_Color yellow = { 255, 255, 0 };
SDL_Color white = { 255, 255, 255 };
SDL_Surface* textSurface = TTF_RenderText_Solid(font, text, selected ? yellow : white);
if (textSurface == NULL) {
printf("Failed to render text: %s\n", TTF_GetError());
return;
}
SDL_BlitSurface(textSurface, NULL, screen, &rect);
SDL_FreeSurface(textSurface);
}
int main(int argc, char* argv[])
{
// Initialize SDL
if (SDL_Init(SDL_INIT_VIDEO) == -1)
{
printf("SDL initialization failed: %s\n", SDL_GetError());
return 1;
}
// Initialize SDL_ttf
if (TTF_Init() == -1)
{
printf("SDL_ttf initialization failed: %s\n", TTF_GetError());
return 1;
}
// Set up the screen
SDL_Surface* screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE);
if (screen == NULL)
{
printf("Video mode initialization failed: %s\n", SDL_GetError());
return 1;
}
// Load font
TTF_Font* font = TTF_OpenFont("arial.ttf", 24);
if (font == NULL)
{
printf("Failed to load font: %s\n", TTF_GetError());
return 1;
}
// Set up option rectangles
SDL_Rect defaultRect = {80, 120, 480, 60};
SDL_Rect xboxRect = {80, 200, 480, 60};
SDL_Rect playstationRect = {80, 280, 480, 60};
int quit = 0;
int selectedOption = DEFAULT;
SDL_Event e; // Declare the SDL event variable
// Main loop
while (!quit)
{
// Handle events
while (SDL_PollEvent(&e))
{
if (e.type == SDL_QUIT)
{
quit = 1;
}
else if (e.type == SDL_KEYDOWN)
{
switch (e.key.keysym.sym)
{
case SDLK_UP:
// Move selection up
if (selectedOption > DEFAULT)
{
selectedOption--;
}
break;
case SDLK_DOWN:
// Move selection down
if (selectedOption < PLAYSTATION)
{
selectedOption++;
}
break;
case SDLK_RETURN:
case SDLK_SPACE:
break;
default:
// Perform the appropriate action and quit the program
switch (selectedOption)
{
case XBOX:
break;
case PLAYSTATION:
break;
default:
// The default option does not require any action, so just quit the program
quit = 1;
}
// Move the selected unlock sound file from /mnt/SDCARD/unlock to /mnt/SDCARD/RetroArch/.retroarch/assets
if (selectedOption == 2) {
// Move the selected unlock sound file from /mnt/SDCARD/unlock to /mnt/SDCARD/RetroArch/.retroarch/assets
if (rename("/mnt/SDCARD/unlock/xboxunlock.ogg", "/mnt/SDCARD/RetroArch/.retroarch/assets/unlock.ogg") != 0) {
printf("Error: Failed to move Xbox unlock sound file.\n");
} else {
printf("Xbox unlock sound file moved successfully.\n");
}
} else if (selectedOption == 3) {
// Move the selected unlock sound file from /mnt/SDCARD/unlock to /mnt/SDCARD/RetroArch/.retroarch/assets
if (rename("/mnt/SDCARD/unlock/psunlock.ogg", "/mnt/SDCARD/RetroArch/.retroarch/assets/unlock.ogg") != 0) {
printf("Error: Failed to move PlayStation unlock sound file.\n");
} else {
printf("PlayStation unlock sound file moved successfully.\n");
}
}
// Quit the program
quit = 1;
break;
}
}
}
// Clear the screen
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
// Draw the options
drawOption(screen, "Default Achievement Unlock Sound", font, defaultRect, selectedOption == DEFAULT);
drawOption(screen, "Xbox Achievement Unlock Sound", font, xboxRect, selectedOption == XBOX);
drawOption(screen, "Playstation Trophy Unlock Sound", font, playstationRect, selectedOption == PLAYSTATION);
// Update the screen
SDL_Flip(screen);
}
// Clean up
TTF_CloseFont(font);
TTF_Quit();
SDL_Quit();
return 0;
}