1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-19 04:53:12 +01:00

get game working with new theme manager

Theme editor currently unavailable.
This commit is contained in:
IntelOrca
2016-01-29 19:39:31 +00:00
parent 0eb57e5fb5
commit caf9bd9939
22 changed files with 233 additions and 467 deletions

View File

@@ -3,6 +3,7 @@
extern "C"
{
#include "../common.h"
#include "themes.h"
#include "window.h"
}
@@ -19,13 +20,6 @@ struct WindowThemeDesc;
// Don't try to load theme files that exceed 64 MiB
constexpr uint64 MAX_THEME_SIZE = 64 * 1024 * 1024;
enum {
UITHEME_FLAG_PREDEFINED = 1 << 0,
UITHEME_FLAG_USE_LIGHTS_RIDE = 1 << 1,
UITHEME_FLAG_USE_LIGHTS_PARK = 1 << 2,
UITHEME_FLAG_USE_ALTERNATIVE_SCENARIO_SELECT_FONT = 1 << 3,
};
/**
* Represents a window theming style such as the colour scheme.
*/
@@ -473,17 +467,35 @@ UITheme UITheme::CreatePredefined(const utf8 * name, const UIThemeWindowEntry *
namespace ThemeManager
{
const utf8 * CurrentThemePath;
UITheme * CurrentTheme;
struct AvailableTheme
{
utf8 Path[MAX_PATH];
utf8 Name[64];
};
const utf8 * CurrentThemePath;
UITheme * CurrentTheme;
List<AvailableTheme> AvailableThemes;
size_t ActiveAvailableThemeIndex = SIZE_MAX;
size_t NumPredefinedThemes = 0;
void GetAvailableThemes(List<AvailableTheme> * outThemes)
{
Guard::ArgumentNotNull(outThemes);
outThemes->Clear();
NumPredefinedThemes = 0;
for (const UITheme * * predefinedTheme = PredefinedThemes; *predefinedTheme != nullptr; predefinedTheme++)
{
AvailableTheme theme;
String::Set(theme.Path, sizeof(theme.Path), String::Empty);
String::Set(theme.Name, sizeof(theme.Name), (*predefinedTheme)->Name);
outThemes->Add(theme);
NumPredefinedThemes++;
}
utf8 themesPattern[MAX_PATH];
platform_get_user_directory(themesPattern, "themes");
Path::Append(themesPattern, sizeof(themesPattern), "*.json");
@@ -496,12 +508,99 @@ namespace ThemeManager
String::Set(theme.Path, sizeof(theme.Path), path);
Path::GetFileNameWithoutExtension(theme.Path, sizeof(theme.Path), path);
outThemes->Add(theme);
if (Path::Equals(CurrentThemePath, path))
{
ActiveAvailableThemeIndex = outThemes->GetCount() - 1;
}
}
}
void LoadTheme(UITheme * theme)
{
if (CurrentTheme != nullptr)
{
if (!(theme->Flags & UITHEME_FLAG_PREDEFINED))
{
delete CurrentTheme;
}
}
CurrentTheme = theme;
gfx_invalidate_screen();
}
void LoadTheme(const utf8 * path)
{
UITheme * theme = UITheme::FromFile(path);
if (theme == nullptr)
{
// Fall-back to default
theme = (UITheme *)&PredefinedThemeRCT2;
}
LoadTheme(theme);
}
void Initialise()
{
ThemeManager::GetAvailableThemes(&ThemeManager::AvailableThemes);
LoadTheme((UITheme *)&PredefinedThemeRCT2);
ActiveAvailableThemeIndex = 1;
}
}
extern "C"
{
void theme_manager_load_available_themes()
{
ThemeManager::GetAvailableThemes(&ThemeManager::AvailableThemes);
}
size_t theme_manager_get_num_available_themes()
{
return ThemeManager::AvailableThemes.GetCount();
}
const utf8 * theme_manager_get_available_theme_path(size_t index)
{
return ThemeManager::AvailableThemes[index].Path;
}
const utf8 * theme_manager_get_available_theme_name(size_t index)
{
return ThemeManager::AvailableThemes[index].Name;
}
size_t theme_manager_get_active_available_theme_index()
{
return ThemeManager::ActiveAvailableThemeIndex;
}
void theme_manager_set_active_available_theme(size_t index)
{
if (index < ThemeManager::NumPredefinedThemes)
{
ThemeManager::LoadTheme((UITheme *)PredefinedThemes[index]);
}
else
{
const utf8 * path = ThemeManager::AvailableThemes[index].Path;
ThemeManager::LoadTheme(path);
}
ThemeManager::ActiveAvailableThemeIndex = index;
}
uint8 theme_get_flags()
{
return ThemeManager::CurrentTheme->Flags;
}
void theme_manager_initialise()
{
ThemeManager::Initialise();
}
void colour_scheme_update(rct_window * window)
{
colour_scheme_update_by_class(window, window->classification);

View File

@@ -1,3 +1,5 @@
#if 0
/*****************************************************************************
* Copyright (c) 2014 Ted John, Peter Hill
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
@@ -249,3 +251,5 @@ void theme_rename_preset(int preset, const char *newName)
}
}
}
#endif

View File

@@ -18,11 +18,37 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#ifndef _COLOUR_SCHEMES_H_
#define _COLOUR_SCHEMES_H_
#ifndef _THEMES_H_
#define _THEMES_H_
#include "../common.h"
#include "window.h"
enum {
UITHEME_FLAG_PREDEFINED = 1 << 0,
UITHEME_FLAG_USE_LIGHTS_RIDE = 1 << 1,
UITHEME_FLAG_USE_LIGHTS_PARK = 1 << 2,
UITHEME_FLAG_USE_ALTERNATIVE_SCENARIO_SELECT_FONT = 1 << 3,
};
void colour_scheme_update(rct_window *window);
void colour_scheme_update_by_class(rct_window *window, rct_windowclass classification);
void theme_manager_initialise();
void theme_manager_load_available_themes();
size_t theme_manager_get_num_available_themes();
const utf8 * theme_manager_get_available_theme_path(size_t index);
const utf8 * theme_manager_get_available_theme_name(size_t index);
size_t theme_manager_get_active_available_theme_index();
void theme_manager_set_active_available_theme(size_t index);
uint8 theme_get_flags();
#if 0
#include "../config.h"
typedef struct {
@@ -52,13 +78,12 @@ theme_preset* theme_get_preset();
theme_window_definition* theme_window_definition_get_by_class(rct_windowclass classification);
theme_window* theme_window_get_by_class(rct_windowclass classification);
void colour_scheme_update(rct_window *window);
void colour_scheme_update_by_class(rct_window *window, rct_windowclass classification);
void theme_change_preset(int preset);
void theme_create_preset(int duplicate, const char *name);
void theme_delete_preset(int preset);
void theme_rename_preset(int preset, const char *newName);
#endif
#endif