about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/title.c69
1 files changed, 41 insertions, 28 deletions
diff --git a/src/title.c b/src/title.c
index 01cc508..25e0112 100644
--- a/src/title.c
+++ b/src/title.c
@@ -6,18 +6,7 @@ struct LeaderboardEntries {
     char Name[16];
 };
 
-struct LeaderboardEntries Top10[10] = {
-    0, " ",
-    0, " ",
-    0, " ",
-    0, " ",
-    0, " ",
-    0, " ",
-    0, " ",
-    0, " ",
-    0, " ",
-    0, " "
-};
+struct LeaderboardEntries Top10[10];
 
 static int compare_int(const void *Score1, const void *Score2) {
     const struct LeaderboardEntries *Entry1 = *(struct LeaderboardEntries**) Score1;
@@ -37,7 +26,7 @@ static void order_leaderboard() {
     if((LeaderboardFile = fopen(LeaderboardFilePath, "r")) == NULL) {
         return; //If it doesn't exist yet, we don't need to care.
     }
-    
+
     // Init a temporary pointer to store scores and names into. This will be organized into Top10.
     struct LeaderboardEntries *TmpStore[UINT16_MAX*2];
     for (int size = 0; size < (UINT16_MAX*2); size++) //If there's 131,000 entries, I dunno what to tell you. You really like pong...
@@ -52,15 +41,15 @@ static void order_leaderboard() {
         fscanf(LeaderboardFile, "%s %d\n", TmpStore[a]->Name, &TmpStore[a]->Score);
     }
     qsort(TmpStore, size, sizeof(struct LeaderboardEntries *), compare_int);
+
     for(int i = 0; i < size; i++) { //Copy first 10 elements into top10
-        strcpy(Top10[i].Name, TmpStore[i]->Name);
-        Top10[i].Score = TmpStore[i]->Score;
+	strcpy(Top10[i].Name, TmpStore[i]->Name);
+	Top10[i].Score = TmpStore[i]->Score;
     }
 
     // Cleanup
     // Free TmpStore
-    for(int i = 0; i < (UINT16_MAX*2); i++)
-    	free(TmpStore[i]); //Truth be told, I dunno if this even works, since the amount of memory used is kilobytes...
+    free(*TmpStore); //Truth be told, I dunno if this even works, since the amount of memory used is kilobytes...
     // Close leaderboard file.
     if (LeaderboardFile != NULL) {
 	    fclose(LeaderboardFile);
@@ -77,7 +66,6 @@ static void score_screen(Camera2D *MainCamera) {
     if((LeaderboardFile = fopen(LeaderboardFilePath, "r")) == NULL) {
         return; //If it doesn't exist yet, we don't need to care.
     }
-    
     // Init a temporary pointer to store scores and names into. This will be organized into Top10.
     struct LeaderboardEntries *Scores[UINT16_MAX*2];
     for (int size = 0; size < (UINT16_MAX*2); size++) //If there's 131,000 entries, I dunno what to tell you. You really like pong...
@@ -92,12 +80,14 @@ static void score_screen(Camera2D *MainCamera) {
     // Load Scores and Names
     int size = 0;
     for (int a = 0; !feof(LeaderboardFile); a++, size++) { //Load data from file into array.
-        fscanf(LeaderboardFile, "%s %d\n", Scores[a]->Name, &Scores[a]->Score);
+        fscanf(LeaderboardFile, "%s %d", Scores[a]->Name, &Scores[a]->Score);
+	if(feof(LeaderboardFile)) {
+		break;
+	}
     }
     qsort(Scores, size, sizeof(struct LeaderboardEntries *), compare_int);
 
     //Begin drawing scores.
-
     //Mouse
     bool LookingAtScores = true;
     bool MouseCursorIn = true;
@@ -106,13 +96,17 @@ static void score_screen(Camera2D *MainCamera) {
     Rectangle MouseCursor = {0,0,1,1};
     Texture2D MouseCursorSprite = LoadTexture("resources/cursor.png");
 
+    //Page Buttons Rectangles
+    Rectangle PrevPage = {5, 720-50, 70, 45};
+    Rectangle NextPage = {1280-70, 720-50, 70, 45};
+
     int Page = 0;
     bool EndOfPages = false;
     while(LookingAtScores == true && GameGoing == true) {
         // Update Camera
         MainCamera->zoom = GetScreenHeight()/720.0f;
-	    MainCamera->offset = (Vector2){GetScreenWidth()/2.0f, GetScreenHeight()/2.0f};
-	    MainCamera->target = (Vector2){1280/2.0f, 720/2.0f};
+	MainCamera->offset = (Vector2){GetScreenWidth()/2.0f, GetScreenHeight()/2.0f};
+	MainCamera->target = (Vector2){1280/2.0f, 720/2.0f};
 
         //Mouse
         if (MouseCursorIn == true) {
@@ -127,7 +121,6 @@ static void score_screen(Camera2D *MainCamera) {
                 MouseCursor.x += OldPosition.x-NewPosition.x;
             }
         }
-
         if (IsKeyPressed(KEY_ESCAPE)) {
             EnableCursor();
             MouseCursorIn = false;
@@ -135,20 +128,40 @@ static void score_screen(Camera2D *MainCamera) {
             DisableCursor();
             MouseCursorIn = true;
         }
+
         EndOfPages = false;
         BeginDrawing();
             ClearBackground(BLACK);
             BeginMode2D(*MainCamera);
                 DrawRectangle(0, 0, 1280, 720, (Color){20, 20, 20, 255});
-                DrawText("<--", 5, 720-50, 48, WHITE);
-                DrawText("-->", 1280-70, 720-50, 48, WHITE);
-                for (int i = 1; i <= 10; i++) {
+		// Scores
+		int a = 0;
+                for (int i = 1+(10*Page); i <= 10+(10*Page); i++, a++) {
                     if(Scores[i-1]->Name[0] != ' ') {
-                        DrawText(TextFormat("%d. %s: %d", i, Scores[i-1]->Name, Scores[i-1]->Score), 500, 50*i, 48, WHITE);
+                        DrawText(TextFormat("%d. %s: %d", i, Scores[i-1]->Name, Scores[i-1]->Score), 460, 60+(50*a), 48, WHITE);
                     } else {
                         EndOfPages = true;
                     }
                 }
+		// Page Buttons
+		if(CheckCollisionRecs(MouseCursor, PrevPage)) {
+			DrawRectangleRec(PrevPage, RED);
+			if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
+				if(Page > 0) {
+					Page--;
+				}
+			}
+		} else if(CheckCollisionRecs(MouseCursor, NextPage) && EndOfPages == false) {
+			DrawRectangleRec(NextPage, RED);
+			if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
+				if(EndOfPages == false) {
+					Page++;
+				}
+			}
+		}
+                DrawText("<--", 5, 720-50, 48, WHITE);
+                DrawText("-->", 1280-70, 720-50, 48, WHITE);
+		// Cursor
                 DrawTexture(MouseCursorSprite, MouseCursor.x, MouseCursor.y, WHITE);
             EndMode2D();
         EndDrawing();
@@ -297,7 +310,7 @@ static void settings(Camera2D *MainCamera, Mix_Music *TitleScreenMusic) {
             DrawText("Windowed", 100, 242, 42, WHITE);
             DrawText("Fullscreen", 100, 284, 42, WHITE);
             DrawText("Borderless", 100, 326, 42, WHITE);
-	        DrawTexture(MouseCursorSprite, MouseCursor.x, MouseCursor.y, WHITE);
+	    DrawTexture(MouseCursorSprite, MouseCursor.x, MouseCursor.y, WHITE);
         EndMode2D();
         EndDrawing();
     }
specific code to tray.c' href='/danisanti/profani-tty/commit/src/tray.c?id=de65f505a80ab2cee79fbcc01d24c9eed01691e1'>de65f505 ^
a2726b6a ^


82de077b ^
520eee23 ^
dc0c3cc6 ^

520eee23 ^







697db019 ^

718a708b ^
a2726b6a ^
4abdad03 ^



82de077b ^



697db019 ^
4abdad03 ^
82de077b ^
4abdad03 ^
a2726b6a ^
a3a73cf0 ^
74e06116 ^
a2726b6a ^
74e06116 ^
82de077b ^


74e06116 ^
a2726b6a ^
82de077b ^
a2726b6a ^
82de077b ^

e43f3e95 ^
697db019 ^
e43f3e95 ^
82de077b ^

697db019 ^
72856f9b ^
697db019 ^
e43f3e95 ^
82de077b ^


697db019 ^
82de077b ^

697db019 ^
82de077b ^
b300fa5b ^
82de077b ^


697db019 ^
718a708b ^

520eee23 ^





697db019 ^

dc0c3cc6 ^

697db019 ^
dc0c3cc6 ^




d00615be ^




dc0c3cc6 ^
d00615be ^









dc0c3cc6 ^

697db019 ^
dc0c3cc6 ^

697db019 ^
de65f505 ^

12727744 ^
de65f505 ^





de65f505 ^

12727744 ^
de65f505 ^
20a0313d ^

de65f505 ^










12727744 ^
de65f505 ^

12727744 ^
de65f505 ^
12727744 ^

de65f505 ^


c6a6e3a5 ^






90042602 ^





c6a6e3a5 ^
12727744 ^
dc0c3cc6 ^
718a708b ^
697db019 ^
20a0313d ^
c6a6e3a5 ^

dc0c3cc6 ^

697db019 ^
12727744 ^
dc0c3cc6 ^
697db019 ^
dc0c3cc6 ^

92a50000 ^
dc0c3cc6 ^


520eee23 ^
1e60d17d ^
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