git repos / blockattack-game

commit 83d6c18d

sago007 · 2018-03-31 16:28
83d6c18d0840eee598078948fe32d44a03c3bbe5 patch · browse files
parent c9a65d81cab457b859c6ee17fd67eaa07af00650

Removed more of the old font

Changed files

M source/code/ScoresDisplay.hpp before
M source/code/highscore.cpp before
M source/code/levelselect.cpp before
diff --git a/source/code/ScoresDisplay.hpp b/source/code/ScoresDisplay.hpp index 774bb25..90a9b31 100644 --- a/source/code/ScoresDisplay.hpp +++ b/source/code/ScoresDisplay.hpp
@@ -52,13 +52,13 @@ private:
void DrawBackgroundAndCalcPlacements();
void Write(SDL_Renderer* target, int x, int y, const char* text);
sago::SagoTextField* getCachedText(const std::string& text);
+ std::map<std::string, std::shared_ptr<sago::SagoTextField> > fieldCache;
bool isActive = true;
bool bMouseUp = false;
int backX = 20;
int backY = 0;
int nextX = 0;
int nextY = 0;
- std::map<std::string, std::shared_ptr<sago::SagoTextField> > fieldCache;
};
#endif /* SCORESDISPLAY_HPP */
diff --git a/source/code/highscore.cpp b/source/code/highscore.cpp index 2da363f..5a346f3 100644 --- a/source/code/highscore.cpp +++ b/source/code/highscore.cpp
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/
Source information and contacts persons can be found at
-http://www.blockattack.net
+https://blockattack.net
===========================================================================
*/
diff --git a/source/code/levelselect.cpp b/source/code/levelselect.cpp index 367181d..89200db 100644 --- a/source/code/levelselect.cpp +++ b/source/code/levelselect.cpp
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/
Source information and contacts persons can be found at
-http://www.blockattack.net
+https://blockattack.net
===========================================================================
*/
@@ -38,8 +38,21 @@ using std::vector;
static bool bMouseUp; //true if the mouse(1) is unpressed
-static void NFont_Write(SDL_Renderer* target, int x, int y, const std::string& text) {
- globalData.standard_blue_font.draw(target, x, y, text);
+static std::map<std::string, std::shared_ptr<sago::SagoTextField> > fieldCache;
+
+static sago::SagoTextField* getCachedText(const std::string& text) {
+ std::shared_ptr<sago::SagoTextField> ptr = fieldCache[text];
+ if (!ptr) {
+ std::shared_ptr<sago::SagoTextField> newText = std::make_shared<sago::SagoTextField>();
+ sagoTextSetBlueFont(*newText.get());
+ newText->SetText(text.c_str());
+ fieldCache[text] = newText;
+ }
+ return fieldCache[text].get();
+}
+
+static void Write(SDL_Renderer* target, int x, int y, const char* text) {
+ getCachedText(text)->Draw(target, x, y);
}
//The function that allows the player to choose PuzzleLevel
@@ -54,6 +67,7 @@ int PuzzleLevelSelect(int Type) {
Uint32 totalScore = 0;
Uint32 totalTime = 0;
int selected = 0;
+ fieldCache.clear();
//Loads the levels, if they havn't been loaded:
if (Type == 0) {
@@ -75,10 +89,10 @@ int PuzzleLevelSelect(int Type) {
DrawBackground(globalData.screen);
globalData.iCheckBoxArea.Draw(globalData.screen,ticks,xplace,yplace);
if (Type == 0) {
- NFont_Write(globalData.screen, xplace+12,yplace+2,_("Select Puzzle") );
+ Write(globalData.screen, xplace+12,yplace+2,_("Select Puzzle") );
}
if (Type == 1) {
- NFont_Write(globalData.screen, xplace+12,yplace+2, _("Stage Clear Level Select") );
+ Write(globalData.screen, xplace+12,yplace+2, _("Stage Clear Level Select") );
}
//Now drow the fields you click in (and a V if clicked):
for (int i = 0; i < nrOfLevels; i++) {
@@ -191,10 +205,10 @@ int PuzzleLevelSelect(int Type) {
timeString = SPrintStringF(_("Time used: %d : %02d"), GetStageTime(selected)/1000/60, (GetStageTime(selected)/1000)%60);
}
- NFont_Write(globalData.screen, 200,200,scoreString.c_str());
- NFont_Write(globalData.screen, 200,250,timeString.c_str());
+ Write(globalData.screen, 200,200,scoreString.c_str());
+ Write(globalData.screen, 200,250,timeString.c_str());
string totalString = SPrintStringF(_("Total score: %i in %i:%02i"), totalScore, totalTime/1000/60, ((totalTime/1000)%60) );
- NFont_Write(globalData.screen, 200,600,totalString.c_str());
+ Write(globalData.screen, 200,600,totalString.c_str());
}
globalData.mouse.Draw(globalData.screen, SDL_GetTicks(), globalData.mousex, globalData.mousey);