void colour_scheme_update_by_class(rct_window * window, rct_windowclass classification) { const WindowTheme * windowTheme; const UIThemeWindowEntry * entry = ThemeManager::CurrentTheme->GetEntry(classification); if (entry != nullptr) { windowTheme = &entry->Theme; } else { const WindowThemeDesc * desc = GetWindowThemeDescriptor(classification); windowTheme = &desc->DefaultTheme; } bool transparent = false; for (int i = 0; i < 6; i++) { window->colours[i] = windowTheme->Colours[i]; if (windowTheme->Colours[i] & COLOUR_FLAG_TRANSLUCENT) { transparent = true; } } // Some windows need to be transparent even if the colours aren't. // There doesn't seem to be any side-effects for all windows being transparent window->flags |= WF_TRANSPARENT; }
void colour_scheme_update_by_class(rct_window * window, rct_windowclass classification) { const WindowTheme * windowTheme; const UIThemeWindowEntry * entry = ThemeManager::CurrentTheme->GetEntry(classification); if (entry != nullptr) { windowTheme = &entry->Theme; } else { const WindowThemeDesc * desc = GetWindowThemeDescriptor(classification); // Some windows don't have a theme set (e.g. main window, title screen) if (desc == nullptr) { return; } windowTheme = &desc->DefaultTheme; } for (sint32 i = 0; i < 6; i++) { window->colours[i] = windowTheme->Colours[i]; } // Some windows need to be transparent even if the colours aren't. // There doesn't seem to be any side-effects for all windows being transparent window->flags |= WF_TRANSPARENT; }
void theme_set_colour(rct_windowclass wc, uint8 index, colour_t colour) { UIThemeWindowEntry entry; entry.WindowClass = wc; auto currentEntry = (UIThemeWindowEntry *)ThemeManager::CurrentTheme->GetEntry(wc); if (currentEntry != nullptr) { entry.Theme = currentEntry->Theme; } else { const WindowThemeDesc * desc = GetWindowThemeDescriptor(wc); if (desc == nullptr) { return; } entry.Theme = desc->DefaultTheme; } entry.Theme.Colours[index] = colour; ThemeManager::CurrentTheme->SetEntry(&entry); theme_save(); }
json_t * UITheme::ToJson() const { // Create entries json_t * jsonEntries = json_object(); for (const UIThemeWindowEntry & entry : Entries) { const WindowThemeDesc * wtDesc = GetWindowThemeDescriptor(entry.WindowClass); if (wtDesc == nullptr) { return nullptr; } json_object_set_new(jsonEntries, wtDesc->WindowClassSZ, entry.ToJson()); } // Create theme object json_t * jsonTheme = json_object(); json_object_set_new(jsonTheme, "name", json_string(Name)); json_object_set_new(jsonTheme, "entries", jsonEntries); json_object_set_new(jsonTheme, "useLightsRide", json_boolean(Flags & UITHEME_FLAG_USE_LIGHTS_RIDE)); json_object_set_new(jsonTheme, "useLightsPark", json_boolean(Flags & UITHEME_FLAG_USE_LIGHTS_PARK)); json_object_set_new(jsonTheme, "useAltScenarioSelectFont", json_boolean(Flags & UITHEME_FLAG_USE_ALTERNATIVE_SCENARIO_SELECT_FONT)); return jsonTheme; }
rct_string_id theme_desc_get_name(rct_windowclass wc) { const WindowThemeDesc * desc = GetWindowThemeDescriptor(wc); if (desc == nullptr) { return STR_EMPTY; } return desc->WindowName; }
uint8 theme_desc_get_num_colours(rct_windowclass wc) { const WindowThemeDesc * desc = GetWindowThemeDescriptor(wc); if (desc == nullptr) { return 0; } return desc->NumColours; }
uint8 theme_get_colour(rct_windowclass wc, uint8 index) { const UIThemeWindowEntry * entry = ThemeManager::CurrentTheme->GetEntry(wc); if (entry == nullptr) { const WindowThemeDesc * desc = GetWindowThemeDescriptor(wc); return desc->DefaultTheme.Colours[index]; } else { return entry->Theme.Colours[index]; } }
UITheme * UITheme::FromJson(const json_t * json) { const char * themeName = json_string_value(json_object_get(json, "name")); if (themeName == nullptr) { ThrowThemeLoadException(); } json_t * jsonEntries = json_object_get(json, "entries"); size_t numEntries = json_object_size(jsonEntries); UITheme * result = nullptr; try { result = new UITheme(themeName); if (json_is_true(json_object_get(json, "useLightsRide"))) { result->Flags |= UITHEME_FLAG_USE_LIGHTS_RIDE; } if (json_is_true(json_object_get(json, "useLightsPark"))) { result->Flags |= UITHEME_FLAG_USE_LIGHTS_PARK; } if (json_is_true(json_object_get(json, "useAltScenarioSelectFont"))) { result->Flags |= UITHEME_FLAG_USE_ALTERNATIVE_SCENARIO_SELECT_FONT; } const char * jkey; json_t * jvalue; size_t i = 0; json_object_foreach(jsonEntries, jkey, jvalue) { const WindowThemeDesc * wtDesc = GetWindowThemeDescriptor(jkey); if (wtDesc == nullptr) continue; UIThemeWindowEntry entry = UIThemeWindowEntry::FromJson(wtDesc, jvalue); result->SetEntry(&entry); } return result; } catch (Exception ex) { delete result; throw ex; } }
json_t * UIThemeWindowEntry::ToJson() const { const WindowThemeDesc * wtDesc = GetWindowThemeDescriptor(WindowClass); json_t * jsonColours = json_array(); for (uint8 i = 0; i < wtDesc->NumColours; i++) { colour_t colour = Theme.Colours[i]; json_array_append_new(jsonColours, json_integer(colour)); } json_t * jsonEntry = json_object(); json_object_set_new(jsonEntry, "colours", jsonColours); return jsonEntry; }
rct_string_id theme_desc_get_name(rct_windowclass wc) { const WindowThemeDesc * desc = GetWindowThemeDescriptor(wc); return desc->WindowName; }