Browse Source

Invaders sample high scores: Use table and data bindings instead of data-grid.

Michael Ragazzon 5 years ago
parent
commit
17f050aaf2

+ 0 - 4
CMake/SampleFileList.cmake

@@ -197,8 +197,6 @@ set(invaders_HDR_FILES
     ${PROJECT_SOURCE_DIR}/Samples/invaders/src/Game.h
     ${PROJECT_SOURCE_DIR}/Samples/invaders/src/GameDetails.h
     ${PROJECT_SOURCE_DIR}/Samples/invaders/src/HighScores.h
-    ${PROJECT_SOURCE_DIR}/Samples/invaders/src/HighScoresNameFormatter.h
-    ${PROJECT_SOURCE_DIR}/Samples/invaders/src/HighScoresShipFormatter.h
     ${PROJECT_SOURCE_DIR}/Samples/invaders/src/Invader.h
     ${PROJECT_SOURCE_DIR}/Samples/invaders/src/Mothership.h
     ${PROJECT_SOURCE_DIR}/Samples/invaders/src/Shield.h
@@ -222,8 +220,6 @@ set(invaders_SRC_FILES
     ${PROJECT_SOURCE_DIR}/Samples/invaders/src/Game.cpp
     ${PROJECT_SOURCE_DIR}/Samples/invaders/src/GameDetails.cpp
     ${PROJECT_SOURCE_DIR}/Samples/invaders/src/HighScores.cpp
-    ${PROJECT_SOURCE_DIR}/Samples/invaders/src/HighScoresNameFormatter.cpp
-    ${PROJECT_SOURCE_DIR}/Samples/invaders/src/HighScoresShipFormatter.cpp
     ${PROJECT_SOURCE_DIR}/Samples/invaders/src/Invader.cpp
     ${PROJECT_SOURCE_DIR}/Samples/invaders/src/main.cpp
     ${PROJECT_SOURCE_DIR}/Samples/invaders/src/Mothership.cpp

+ 27 - 3
Samples/assets/invader.rcss

@@ -318,7 +318,7 @@ textarea
 	font-size: 13px;
 }
 
-datagrid input.text
+datagrid input.text, table input.text
 {
 	box-sizing: border-box;
 	width: 100%;
@@ -397,7 +397,8 @@ dataselect selectbox
 
 select selectbox,
 dataselect selectbox,
-datagrid datagridbody
+datagrid datagridbody,
+tbody
 {
 	decorator: tiled-box(
 		selectbox-tl, selectbox-t, selectbox-tr, 
@@ -416,7 +417,8 @@ dataselect selectbox option
 
 select selectbox option:nth-child(even),
 dataselect selectbox option:nth-child(even),
-datagrid datagridrow:nth-child(even)
+datagrid datagridrow:nth-child(even),
+tr:nth-child(even)
 {
 	background: #FFFFFFA0;
 }
@@ -539,6 +541,28 @@ input.range sliderarrowinc:hover  { decorator: image( range-inc-hover  ); }
 input.range sliderarrowdec:active { decorator: image( range-dec-active ); }
 input.range sliderarrowinc:active { decorator: image( range-inc-active ); }
 
+thead tr {
+	height: 35px;
+	decorator: tiled-horizontal( datagridheader-l, datagridheader-c, datagridheader-r );
+}
+thead td {
+	padding-top: 11px;
+}
+
+tbody {
+	/* Margin left/right only affects the background positioning for the decorator, not the cell placement */
+	margin-left: 5px;
+	margin-right: 4px;
+	/* Padding top/bottom adds extra spacing between the header row and the body, and between the body and table bottom */
+	padding-top: 4px;
+	padding-bottom: 4px;
+}
+tbody tr {
+	margin-left: 9px;
+	margin-right: 8px;
+	color: black;
+}
+
 datagrid datagridheader
 {
 	width: auto;

+ 69 - 48
Samples/invaders/data/high_score.rml

@@ -1,52 +1,73 @@
 <rml>
-	<head>
-		<title>High Scores</title>
-		<link type="text/template" href="../../assets/window.rml" />
-		<style>
-			body
-			{
-				width: 440px;
-				height: 440px;
-				
-				margin: auto;
-			}
+<head>
+	<title>High Scores</title>
+	<link type="text/template" href="../../assets/window.rml" />
+	<style>
+		body
+		{
+			width: 440px;
+			height: 440px;
 			
-			div#title_bar div#icon
-			{
-				decorator: image( icon-hiscore );
-			}
+			margin: auto;
+		}
+		
+		div#title_bar div#icon
+		{
+			decorator: image( icon-hiscore );
+		}
+		defender
+		{
+			display: inline-block;
+			width: 64px;
+			height: 16px;
 			
-			datagrid
-			{
-				margin-bottom: 20px;
-			}
-			
-			datagrid datagridbody
-			{
-				min-height: 200px;
-			}
-			datagrid datagridrow
-			{
-				padding-top: 7px;
-				padding-bottom: 7px;
-			}
-			defender
-			{
-				display: inline-block;
-				width: 64px;
-				height: 16px;
-				
-				decorator: defender( high_scores_defender.tga );
-			}			
-		</style>
-	</head>
-	<body template="window" onload="add_score">
-		<datagrid source="high_scores.scores">
-			<col fields="name,name_required" formatter="name" width="40%">Pilot</col>
-			<col fields="colour" formatter="ship" width="20%">Ship</col>
-			<col fields="wave" width="20%">Wave</col>
-			<col fields="score" width="20%">Score</col>
-		</datagrid>
-		<button onclick="check_name; goto main_menu; close game_window">Main Menu</button>
-	</body>
+			decorator: defender( high_scores_defender.tga );
+		}
+		tbody tr {
+			height: 30px;
+		}
+		tbody td
+		{
+			padding-top: 5px;
+			height: 30px;
+			white-space: nowrap;
+			overflow: hidden;
+		}
+	</style>
+</head>
+<body template="window" onload="add_score">
+	<table data-model="high_scores">
+		<thead>
+			<tr>
+				<td style="width: 200%; margin-left: 10px;">Pilot</td>
+				<td style="min-width: 64px;">Ship</td>
+				<td>Wave</td>
+				<td style="min-width: 64px;">Score</td>
+			</tr>
+		</thead>
+		<tbody>
+			<tr data-for="score : scores">
+				<td data-if="score.name_required">
+					<input id="player_input" type="text" name="name" onkeydown="enter_name" autofocus/>
+				</td>
+				<td data-if="!score.name_required">
+					{{score.name}}
+				</td>
+				<td>
+					<defender data-style-color="score.colour"/>
+				</td>
+				<td>
+					{{score.wave}}
+				</td>
+				<td>
+					{{score.score}}
+				</td>
+			</tr>
+			<tr data-if="scores.size == 0">
+				<td colspan="4"><em>No scores recorded. Go play!</em></td>
+			</tr>
+		</tbody>
+	</table>
+	<button onclick="check_name; goto main_menu; close game_window">Main Menu</button>
+</body>
 </rml>

+ 15 - 7
Samples/invaders/data/start_game.rml

@@ -21,6 +21,14 @@
 				width: 200px;
 				margin: auto;
 			}
+			color
+			{
+				display: inline-block;
+				width: 9px;
+				height: 9px;
+				border: 1px #666;
+				margin-right: 0.5em;
+			}
 		</style>
 	</head>
 	<body template="window">
@@ -34,13 +42,13 @@
 				<p>
 					Colour:<br />
 					<select name="colour">
-						<option value="233,116,81">Burnt Sienna</option>
-						<option value="127,255,0">Chartreuse</option>
-						<option value="21,96,189">Denim</option>
-						<option value="246,74,138">French Rose</option>
-						<option value="255,0,255">Fuschia</option>
-						<option value="218,165,32">Goldenrod</option>
-						<option selected value="255,255,240">Ivory</option>
+						<option value="233,116,81"><color style="background: rgb(233,116,81)"/>Burnt Sienna</option>
+						<option value="127,255,0"><color style="background: rgb(127,255,0)"/>Chartreuse</option>
+						<option value="21,96,189"><color style="background: rgb(21,96,189)"/>Denim</option>
+						<option value="246,74,138"><color style="background: rgb(246,74,138)"/>French Rose</option>
+						<option value="255,0,255"><color style="background: rgb(255,0,255)"/>Fuchsia</option>
+						<option value="218,165,32"><color style="background: rgb(218,165,32)"/>Goldenrod</option>
+						<option selected value="255,255,240"><color style="background: rgb(255,255,240)"/>Ivory</option>
 					</select>
 				</p>
 			</div>

+ 48 - 93
Samples/invaders/src/HighScores.cpp

@@ -28,20 +28,37 @@
 
 #include "HighScores.h"
 #include <RmlUi/Core/TypeConverter.h>
+#include <RmlUi/Core/Context.h>
+#include <RmlUi/Core/DataModel.h>
 #include <stdio.h>
+#include <algorithm>
 
 HighScores* HighScores::instance = nullptr;
 
-HighScores::HighScores() : Rml::DataSource("high_scores")
+HighScores::HighScores(Rml::Context* context)
 {
 	RMLUI_ASSERT(instance == nullptr);
 	instance = this;
 
-	for (int i = 0; i < NUM_SCORES; i++)
+	Rml::DataModelConstructor constructor = context->CreateDataModel("high_scores");
+	if (!constructor)
+		return;
+
+	if (auto score_handle = constructor.RegisterStruct<Score>())
 	{
-		scores[i].score = -1;
+		score_handle.RegisterMember("name_required", &Score::name_required);
+		score_handle.RegisterMember("name", &Score::name);
+		score_handle.RegisterMemberFunc("colour", &Score::GetColour);
+		score_handle.RegisterMember("wave", &Score::wave);
+		score_handle.RegisterMember("score", &Score::score);
 	}
 
+	constructor.RegisterArray<ScoreList>();
+
+	constructor.Bind("scores", &scores);
+
+	model_handle = constructor.GetModelHandle();
+
 	LoadScores();
 }
 
@@ -54,9 +71,9 @@ HighScores::~HighScores()
 	instance = nullptr;
 }
 
-void HighScores::Initialise()
+void HighScores::Initialise(Rml::Context* context)
 {
-	new HighScores();
+	new HighScores(context);
 }
 
 void HighScores::Shutdown()
@@ -64,62 +81,16 @@ void HighScores::Shutdown()
 	delete instance;
 }
 
-void HighScores::GetRow(Rml::StringList& row, const Rml::String& table, int row_index, const Rml::StringList& columns)
-{
-	if (table == "scores")
-	{
-		for (size_t i = 0; i < columns.size(); i++)
-		{
-			if (columns[i] == "name")
-			{
-				row.push_back(scores[row_index].name);
-			}
-			else if (columns[i] == "name_required")
-			{
-				row.push_back(Rml::CreateString(4, "%d", scores[row_index].name_required));
-			}
-			else if (columns[i] == "score")
-			{
-				row.push_back(Rml::CreateString(32, "%d", scores[row_index].score));
-			}
-			else if (columns[i] == "colour")
-			{
-				Rml::String colour_string;
-				Rml::TypeConverter< Rml::Colourb, Rml::String >::Convert(scores[row_index].colour, colour_string);
-				row.push_back(colour_string);
-			}
-			else if (columns[i] == "wave")
-			{
-				row.push_back(Rml::CreateString(8, "%d", scores[row_index].wave));
-			}
-		}
-	}
-}
-
-int HighScores::GetNumRows(const Rml::String& table)
+void HighScores::Update()
 {
-	if (table == "scores")
-	{
-		for (int i = 0; i < NUM_SCORES; i++)
-		{
-			if (scores[i].score == -1)
-			{
-				return i;
-			}
-		}
-
-		return NUM_SCORES;
-	}
-
-	return 0;
+	if (instance->model_handle)
+		instance->model_handle.Update();
 }
 
 int HighScores::GetHighScore()
 {
-	if (instance->GetNumRows("scores") == 0)
-	{
+	if (instance->scores.empty())
 		return 0;
-	}
 
 	return instance->scores[0].score;
 }
@@ -137,53 +108,37 @@ void HighScores::SubmitScore(const Rml::Colourb& colour, int wave, int score)
 // Sets the name of the last player to submit their score.
 void HighScores::SubmitName(const Rml::String& name)
 {
-	for (int i = 0; i < instance->GetNumRows("scores"); i++)
+	for (Score& score : instance->scores)
 	{
-		if (instance->scores[i].name_required)
+		if (score.name_required)
 		{
-			instance->scores[i].name = name;
-			instance->scores[i].name_required = false;
-			instance->NotifyRowChange("scores", i, 1);
+			score.name = name;
+			score.name_required = false;
+
+			instance->model_handle.DirtyVariable("scores");
 		}
 	}
 }
 
 void HighScores::SubmitScore(const Rml::String& name, const Rml::Colourb& colour, int wave, int score, bool name_required)
 {
-	for (int i = 0; i < NUM_SCORES; i++)
-	{
-		if (score > scores[i].score)
-		{
-			// If we've already got the maximum number of scores, then we have
-			// to send a NotifyRowRemove message as we're going to delete the last
-			// row from the data source.
-			bool max_rows = scores[NUM_SCORES - 1].score != -1;
+	Score entry;
+	entry.name = name;
+	entry.colour = colour;
+	entry.wave = wave;
+	entry.score = score;
+	entry.name_required = name_required;
 
-			// Push down all the other scores.
-			for (int j = NUM_SCORES - 1; j > i; j--)
-			{
-				scores[j] = scores[j - 1];
-			}
+	auto it = std::find_if(scores.begin(), scores.end(), [score](const Score& other) { return score > other.score; });
 
-			// Insert our new score.
-			scores[i].name = name;
-			scores[i].colour = colour;
-			scores[i].wave = wave;
-			scores[i].score = score;
-			scores[i].name_required = name_required;
+	scores.insert(it, std::move(entry));
 
-			// Send the row removal message (if necessary).
-			if (max_rows)
-			{
-				NotifyRowRemove("scores", NUM_SCORES - 1, 1);
-			}
+	constexpr size_t MaxNumberScores = 10;
 
-			// Then send the rows added message.
-			NotifyRowAdd("scores", i, 1);
+	if (scores.size() > MaxNumberScores)
+		scores.pop_back();
 
-			return;
-		}
-	}
+	model_handle.DirtyVariable("scores");
 }
 
 void HighScores::LoadScores()
@@ -223,13 +178,13 @@ void HighScores::SaveScores()
 
 	if (scores_file)
 	{
-		for (int i = 0; i < GetNumRows("scores"); i++)
+		for (const Score& score : scores)
 		{
 			Rml::String colour_string;
-			Rml::TypeConverter< Rml::Colourb, Rml::String >::Convert(scores[i].colour, colour_string);
+			Rml::TypeConverter< Rml::Colourb, Rml::String >::Convert(score.colour, colour_string);
 
-			Rml::String score = Rml::CreateString(1024, "%s\t%s\t%d\t%d\n", scores[i].name.c_str(), colour_string.c_str(), scores[i].wave, scores[i].score);
-			fputs(score.c_str(), scores_file);
+			Rml::String score_str = Rml::CreateString(1024, "%s\t%s\t%d\t%d\n", score.name.c_str(), colour_string.c_str(), score.wave, score.score);
+			fputs(score_str.c_str(), scores_file);
 		}
 
 		fclose(scores_file);

+ 12 - 9
Samples/invaders/src/HighScores.h

@@ -29,19 +29,16 @@
 #ifndef RMLUI_INVADERS_HIGHSCORES_H
 #define RMLUI_INVADERS_HIGHSCORES_H
 
-#include <RmlUi/Core/Elements/DataSource.h>
 #include <RmlUi/Core/Types.h>
+#include <RmlUi/Core/DataModel.h>
 
-const int NUM_SCORES = 10;
-
-class HighScores : public Rml::DataSource
+class HighScores
 {
 public:
-	static void Initialise();
+	static void Initialise(Rml::Context* context);
 	static void Shutdown();
 
-	void GetRow(Rml::StringList& row, const Rml::String& table, int row_index, const Rml::StringList& columns);
-	int GetNumRows(const Rml::String& table);
+	static void Update();
 
 	static int GetHighScore();
 
@@ -54,7 +51,7 @@ public:
 	static void SubmitName(const Rml::String& name);
 
 private:
-	HighScores();
+	HighScores(Rml::Context* context);
 	~HighScores();
 
 	static HighScores* instance;
@@ -70,9 +67,15 @@ private:
 		Rml::Colourb colour;
 		int score;
 		int wave;
+
+		void GetColour(Rml::Variant& variant) {
+			variant = "rgba(" + Rml::ToString(colour) + ')';
+		}
 	};
+	using ScoreList = Rml::Vector< Score >;
+	ScoreList scores;
 
-	Score scores[NUM_SCORES];
+	Rml::DataModelHandle model_handle;
 };
 
 #endif

+ 0 - 53
Samples/invaders/src/HighScoresNameFormatter.cpp

@@ -1,53 +0,0 @@
-/*
- * This source file is part of RmlUi, the HTML/CSS Interface Middleware
- *
- * For the latest information, see http://github.com/mikke89/RmlUi
- *
- * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
- * Copyright (c) 2019 The RmlUi Team, and contributors
- *
- * 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, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- * 
- * 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. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-
-#include "HighScoresNameFormatter.h"
-
-HighScoresNameFormatter::HighScoresNameFormatter() : Rml::DataFormatter("name")
-{
-}
-
-HighScoresNameFormatter::~HighScoresNameFormatter()
-{
-}
-
-void HighScoresNameFormatter::FormatData(Rml::String& formatted_data, const Rml::StringList& raw_data)
-{
-	// Data format:
-	// raw_data[0] is the name.
-	// raw_data[1] is a bool - True means the name has to be entered. False means the name has been entered already.
-
-	if (raw_data[1] == "1")
-	{
-		formatted_data = "<input id=\"player_input\" type=\"text\" name=\"name\" onkeydown=\"enter_name\" autofocus/>";
-	}
-	else
-	{
-		formatted_data = raw_data[0];
-	}
-}

+ 0 - 47
Samples/invaders/src/HighScoresNameFormatter.h

@@ -1,47 +0,0 @@
-/*
- * This source file is part of RmlUi, the HTML/CSS Interface Middleware
- *
- * For the latest information, see http://github.com/mikke89/RmlUi
- *
- * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
- * Copyright (c) 2019 The RmlUi Team, and contributors
- *
- * 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, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- * 
- * 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. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-
-#ifndef RMLUI_INVADERS_HIGHSCORESNAMEFORMATTER_H
-#define RMLUI_INVADERS_HIGHSCORESNAMEFORMATTER_H
-
-#include <RmlUi/Core/Elements/DataFormatter.h>
-
-/**
-	@author Robert Curry
- */
-
-class HighScoresNameFormatter : public Rml::DataFormatter
-{
-public:
-	HighScoresNameFormatter();
-	~HighScoresNameFormatter();
-
-	void FormatData(Rml::String& formatted_data, const Rml::StringList& raw_data);
-};
-
-#endif

+ 0 - 45
Samples/invaders/src/HighScoresShipFormatter.cpp

@@ -1,45 +0,0 @@
-/*
- * This source file is part of RmlUi, the HTML/CSS Interface Middleware
- *
- * For the latest information, see http://github.com/mikke89/RmlUi
- *
- * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
- * Copyright (c) 2019 The RmlUi Team, and contributors
- *
- * 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, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- * 
- * 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. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-
-#include "HighScoresShipFormatter.h"
-#include <RmlUi/Core/TypeConverter.h>
-
-HighScoresShipFormatter::HighScoresShipFormatter() : Rml::DataFormatter("ship")
-{
-}
-
-HighScoresShipFormatter::~HighScoresShipFormatter()
-{
-}
-
-void HighScoresShipFormatter::FormatData(Rml::String& formatted_data, const Rml::StringList& raw_data)
-{
-	// Data format:
-	// raw_data[0] is the colour, in "%d, %d, %d, %d" format.
-	formatted_data = "<defender style=\"color: rgba(" + raw_data[0] + ");\" />";
-}

+ 0 - 47
Samples/invaders/src/HighScoresShipFormatter.h

@@ -1,47 +0,0 @@
-/*
- * This source file is part of RmlUi, the HTML/CSS Interface Middleware
- *
- * For the latest information, see http://github.com/mikke89/RmlUi
- *
- * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
- * Copyright (c) 2019 The RmlUi Team, and contributors
- *
- * 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, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- * 
- * 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. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-
-#ifndef RMLUI_INVADERS_HIGHSCORESSHIPFORMATTER_H
-#define RMLUI_INVADERS_HIGHSCORESSHIPFORMATTER_H
-
-#include <RmlUi/Core/Elements/DataFormatter.h>
-
-/**
-	@author Robert Curry
- */
-
-class HighScoresShipFormatter : public Rml::DataFormatter
-{
-public:
-	HighScoresShipFormatter();
-	~HighScoresShipFormatter();
-
-	void FormatData(Rml::String& formatted_data, const Rml::StringList& raw_data);
-};
-
-#endif

+ 3 - 7
Samples/invaders/src/main.cpp

@@ -40,8 +40,6 @@
 #include "EventInstancer.h"
 #include "EventManager.h"
 #include "HighScores.h"
-#include "HighScoresNameFormatter.h"
-#include "HighScoresShipFormatter.h"
 
 Rml::Context* context = nullptr;
 
@@ -49,6 +47,8 @@ ShellRenderInterfaceExtensions *shell_renderer;
 
 void GameLoop()
 {
+	HighScores::Update();
+
 	context->Update();
 
 	shell_renderer->PrepareRenderBuffer();
@@ -126,12 +126,8 @@ int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
 	Rml::Factory::RegisterDecoratorInstancer("starfield", &decorator_instancer_starfield);
 	Rml::Factory::RegisterDecoratorInstancer("defender", &decorator_instancer_defender);
 
-	// Register Invader's data formatters
-	HighScoresNameFormatter name_formatter;
-	HighScoresShipFormatter ship_formatter;
-
 	// Construct the game singletons.
-	HighScores::Initialise();
+	HighScores::Initialise(context);
 
 	// Initialise the event instancer and handlers.
 	EventInstancer event_listener_instancer;