2010-09-24 19:58:56 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Copyright (C) 2010
|
|
|
|
* by Dimok
|
|
|
|
*
|
|
|
|
* This software is provided 'as-is', without any express or implied
|
|
|
|
* warranty. In no event will the authors be held liable for any
|
|
|
|
* damages arising from the use of this software.
|
|
|
|
*
|
|
|
|
* Permission is granted to anyone to use this software for any
|
|
|
|
* purpose, including commercial applications, and to alter it and
|
|
|
|
* redistribute it freely, subject to the following restrictions:
|
|
|
|
*
|
|
|
|
* 1. The origin of this software must not be misrepresented; you
|
|
|
|
* must not claim that you wrote the original software. If you use
|
|
|
|
* this software in a product, an acknowledgment in the product
|
|
|
|
* documentation would be appreciated but is not required.
|
|
|
|
*
|
|
|
|
* 2. Altered source versions must be plainly marked as such, and
|
|
|
|
* must not be misrepresented as being the original software.
|
|
|
|
*
|
|
|
|
* 3. This notice may not be removed or altered from any source
|
|
|
|
* distribution.
|
|
|
|
***************************************************************************/
|
|
|
|
#include <ogcsys.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "CTheme.h"
|
2011-06-14 19:53:19 +02:00
|
|
|
#include "GUI/gui.h"
|
2010-12-31 00:49:22 +01:00
|
|
|
#include "settings/CSettings.h"
|
2011-07-23 21:49:51 +02:00
|
|
|
#include "banner/OpeningBNR.hpp"
|
2010-12-28 18:02:10 +01:00
|
|
|
#include "FileOperations/fileops.h"
|
2011-01-09 11:45:29 +01:00
|
|
|
#include "menu/menus.h"
|
2011-07-23 21:49:51 +02:00
|
|
|
#include "wad/nandtitle.h"
|
2010-12-28 18:02:10 +01:00
|
|
|
#include "FreeTypeGX.h"
|
|
|
|
|
2011-07-23 21:49:51 +02:00
|
|
|
typedef struct map_entry
|
|
|
|
{
|
|
|
|
char name[8];
|
|
|
|
u8 hash[20];
|
|
|
|
} __attribute__((packed)) map_entry_t;
|
|
|
|
|
|
|
|
static const u8 WIIFONT_HASH[] = {0x32, 0xb3, 0x39, 0xcb, 0xbb, 0x50, 0x7d, 0x50, 0x27, 0x79, 0x25, 0x9a, 0x78, 0x66, 0x99, 0x5d, 0x03, 0x0b, 0x1d, 0x88};
|
|
|
|
static const u8 WIIFONT_HASH_KOR[] = {0xb7, 0x15, 0x6d, 0xf0, 0xf4, 0xae, 0x07, 0x8f, 0xd1, 0x53, 0x58, 0x3e, 0x93, 0x6e, 0x07, 0xc0, 0x98, 0x77, 0x49, 0x0e};
|
|
|
|
|
2010-12-28 18:02:10 +01:00
|
|
|
FreeTypeGX * fontSystem = NULL;
|
2011-07-23 21:49:51 +02:00
|
|
|
static FT_Byte * systemFont = NULL;
|
|
|
|
static u32 systemFontSize = 0;
|
|
|
|
static FT_Byte * customFont = NULL;
|
|
|
|
static u32 customFontSize = 0;
|
2010-09-24 19:58:56 +02:00
|
|
|
|
2010-12-26 18:02:14 +01:00
|
|
|
bool Theme::ShowTooltips = true;
|
2010-09-24 19:58:56 +02:00
|
|
|
|
2011-01-09 11:45:29 +01:00
|
|
|
void Theme::Reload()
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
HaltGui();
|
|
|
|
mainWindow->Remove(bgImg);
|
|
|
|
for(int i = 0; i < 4; ++i)
|
|
|
|
{
|
|
|
|
char image[50];
|
|
|
|
snprintf(image, sizeof(image), "player%i_point.png", i+1);
|
2011-12-28 17:27:30 +01:00
|
|
|
pointer[i]->SetImage(image);
|
2011-07-26 00:28:22 +02:00
|
|
|
}
|
|
|
|
delete btnSoundClick;
|
|
|
|
delete btnSoundClick2;
|
|
|
|
delete btnSoundOver;
|
|
|
|
btnSoundClick = new GuiSound(Resources::GetFile("button_click.wav"), Resources::GetFileSize("button_click.wav"), Settings.sfxvolume);
|
|
|
|
btnSoundClick2 = new GuiSound(Resources::GetFile("button_click2.wav"), Resources::GetFileSize("button_click2.wav"), Settings.sfxvolume);
|
|
|
|
btnSoundOver = new GuiSound(Resources::GetFile("button_over.wav"), Resources::GetFileSize("button_over.wav"), Settings.sfxvolume);
|
|
|
|
delete background;
|
|
|
|
background = Resources::GetImageData(Settings.widescreen ? "wbackground.png" : "background.png");
|
|
|
|
delete bgImg;
|
|
|
|
bgImg = new GuiImage(background);
|
|
|
|
mainWindow->Append(bgImg);
|
|
|
|
ResumeGui();
|
2011-01-09 11:45:29 +01:00
|
|
|
}
|
|
|
|
|
2010-12-28 18:02:10 +01:00
|
|
|
void Theme::CleanUp()
|
2010-09-24 19:58:56 +02:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
ThemeCleanUp();
|
|
|
|
Resources::Clear();
|
|
|
|
ClearFontData();
|
2010-09-24 19:58:56 +02:00
|
|
|
}
|
|
|
|
|
2010-12-28 18:02:10 +01:00
|
|
|
void Theme::SetDefault()
|
2010-09-24 19:58:56 +02:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
ShowTooltips = true;
|
|
|
|
CleanUp();
|
|
|
|
strcpy(Settings.theme, "");
|
|
|
|
LoadFont("");
|
2010-12-28 18:02:10 +01:00
|
|
|
}
|
2010-09-24 19:58:56 +02:00
|
|
|
|
2010-12-28 18:02:10 +01:00
|
|
|
bool Theme::Load(const char * theme_file_path)
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
bool result = LoadTheme(theme_file_path);
|
|
|
|
if(!result)
|
|
|
|
return result;
|
2010-12-28 18:02:10 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
Theme::ShowTooltips = (thInt("1 - Enable tooltips: 0 for off and 1 for on") != 0);
|
2010-12-28 18:02:10 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
FILE * file = fopen(theme_file_path, "rb");
|
|
|
|
if(!file)
|
|
|
|
return false;
|
2010-09-24 19:58:56 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
char line[300];
|
|
|
|
char * Foldername = NULL;
|
2010-09-24 19:58:56 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
while (fgets(line, sizeof(line), file))
|
|
|
|
{
|
|
|
|
char * ptr = strcasestr(line, "Image-Folder:");
|
|
|
|
if(!ptr)
|
|
|
|
continue;
|
2010-09-24 19:58:56 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
ptr += strlen("Image-Folder:");
|
2010-09-24 19:58:56 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
while(*ptr != '\0' && *ptr == ' ') ptr++;
|
2010-09-26 10:33:43 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
Foldername = ptr;
|
2010-09-24 19:58:56 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
while(*ptr != '\\' && *ptr != '"' && *ptr != '\0') ptr++;
|
2010-09-24 19:58:56 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
*ptr = '\0';
|
|
|
|
break;
|
|
|
|
}
|
2010-09-24 19:58:56 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
fclose(file);
|
2010-09-24 19:58:56 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
if(!Foldername)
|
|
|
|
return result;
|
2010-09-24 19:58:56 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
char theme_path[300];
|
|
|
|
snprintf(theme_path, sizeof(theme_path), theme_file_path);
|
2010-12-31 00:49:22 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
char * ptr = strrchr(theme_path, '/');
|
|
|
|
if(ptr) *ptr = '\0';
|
2010-12-31 00:49:22 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
snprintf(theme_path, sizeof(theme_path), "%s/%s", theme_path, Foldername);
|
|
|
|
if(!Resources::LoadFiles(theme_path))
|
|
|
|
{
|
|
|
|
const char * ThemeFilename = strrchr(theme_file_path, '/')+1;
|
|
|
|
char Filename[255];
|
|
|
|
snprintf(Filename, sizeof(Filename), ThemeFilename);
|
2011-01-02 10:23:44 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
char * fileext = strrchr(Filename, '.');
|
|
|
|
if(fileext) *fileext = 0;
|
2011-01-02 10:23:44 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
char * ptr = strrchr(theme_path, '/');
|
|
|
|
*ptr = 0;
|
|
|
|
snprintf(theme_path, sizeof(theme_path), "%s/%s", theme_path, Filename);
|
|
|
|
Resources::LoadFiles(theme_path);
|
|
|
|
}
|
2010-09-24 19:58:56 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
//! Override font.ttf with the theme font.ttf if it exists in the image folder
|
|
|
|
char FontPath[300];
|
|
|
|
snprintf(FontPath, sizeof(FontPath), "%s/font.ttf", theme_path);
|
2010-12-28 18:02:10 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
if(CheckFile(FontPath))
|
|
|
|
Theme::LoadFont(theme_path);
|
2010-12-28 18:02:10 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
return result;
|
2010-09-24 19:58:56 +02:00
|
|
|
}
|
2010-12-28 18:02:10 +01:00
|
|
|
|
2011-07-23 21:49:51 +02:00
|
|
|
bool Theme::loadSystemFont(bool korean)
|
|
|
|
{
|
2011-07-24 18:32:09 +02:00
|
|
|
const char contentMapPath[] ATTRIBUTE_ALIGN(32) = "/shared1/content.map";
|
2011-07-23 21:49:51 +02:00
|
|
|
u8 *contentMap = NULL;
|
|
|
|
u32 mapsize = 0;
|
|
|
|
|
|
|
|
NandTitle::LoadFileFromNand(contentMapPath, &contentMap, &mapsize);
|
|
|
|
if(!contentMap)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
int fileCount = mapsize / sizeof(map_entry_t);
|
|
|
|
|
|
|
|
map_entry_t *mapEntryList = (map_entry_t *) contentMap;
|
|
|
|
|
|
|
|
for (int i = 0; i < fileCount; i++)
|
|
|
|
{
|
|
|
|
if (memcmp(mapEntryList[i].hash, korean ? WIIFONT_HASH_KOR : WIIFONT_HASH, 20) != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Name found, load it and unpack it
|
|
|
|
char font_filename[32] ATTRIBUTE_ALIGN(32);
|
|
|
|
snprintf(font_filename, sizeof(font_filename), "/shared1/%.8s.app", mapEntryList[i].name);
|
|
|
|
|
|
|
|
u8 *fontArchive = NULL;
|
|
|
|
u32 filesize = 0;
|
|
|
|
|
|
|
|
NandTitle::LoadFileFromNand(font_filename, &fontArchive, &filesize);
|
|
|
|
if(!fontArchive)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const U8Header *u8Archive = (U8Header *) fontArchive;
|
|
|
|
const U8Entry *fst = (const U8Entry *) (((const u8 *) u8Archive) + u8Archive->rootNodeOffset);
|
|
|
|
|
|
|
|
if(fst[0].numEntries < 1)
|
|
|
|
{
|
|
|
|
free(fontArchive);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(systemFont)
|
|
|
|
delete [] systemFont;
|
|
|
|
|
|
|
|
systemFontSize = fst[1].fileLength;
|
|
|
|
systemFont = new (std::nothrow) FT_Byte[systemFontSize];
|
|
|
|
if(!systemFont)
|
|
|
|
{
|
|
|
|
free(fontArchive);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(systemFont, fontArchive + fst[1].fileOffset, systemFontSize);
|
|
|
|
|
|
|
|
free(fontArchive);
|
|
|
|
free(contentMap);
|
|
|
|
gprintf("Loaded Wii System Font: %s\n", u8Filename(fst, 1));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(contentMap);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-12-28 18:02:10 +01:00
|
|
|
bool Theme::LoadFont(const char *path)
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
char FontPath[300];
|
|
|
|
bool result = false;
|
|
|
|
FILE *pfile = NULL;
|
2010-12-28 18:02:10 +01:00
|
|
|
|
2011-07-23 21:49:51 +02:00
|
|
|
delete [] customFont;
|
|
|
|
customFont = NULL;
|
2010-12-28 18:02:10 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
snprintf(FontPath, sizeof(FontPath), "%s/font.ttf", path);
|
2010-12-28 18:02:10 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
pfile = fopen(FontPath, "rb");
|
2010-12-28 18:02:10 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
if (pfile)
|
|
|
|
{
|
|
|
|
fseek(pfile, 0, SEEK_END);
|
|
|
|
customFontSize = ftell(pfile);
|
|
|
|
rewind(pfile);
|
2010-12-28 18:02:10 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
customFont = new (std::nothrow) FT_Byte[customFontSize];
|
|
|
|
if (customFont)
|
|
|
|
{
|
|
|
|
fread(customFont, 1, customFontSize, pfile);
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
fclose(pfile);
|
|
|
|
}
|
2010-12-28 18:02:10 +01:00
|
|
|
|
2011-07-23 21:49:51 +02:00
|
|
|
FT_Byte *loadedFont = customFont;
|
|
|
|
u32 loadedFontSize = customFontSize;
|
2011-01-08 13:35:41 +01:00
|
|
|
|
2011-07-24 18:32:09 +02:00
|
|
|
if(!loadedFont && Settings.UseSystemFont)
|
2011-07-23 21:49:51 +02:00
|
|
|
{
|
|
|
|
if(!systemFont)
|
|
|
|
loadSystemFont(CONF_GetLanguage() == CONF_LANG_KOREAN);
|
2011-07-24 18:32:09 +02:00
|
|
|
if(!systemFont)
|
|
|
|
loadSystemFont(CONF_GetLanguage() != CONF_LANG_KOREAN);
|
2011-07-23 21:49:51 +02:00
|
|
|
|
|
|
|
//! Default to system font if no custom is loaded
|
|
|
|
loadedFont = systemFont;
|
|
|
|
loadedFontSize = systemFontSize;
|
|
|
|
}
|
2011-07-24 18:32:09 +02:00
|
|
|
if(!loadedFont)
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
loadedFont = (FT_Byte *) Resources::GetFile("font.ttf");
|
|
|
|
loadedFontSize = Resources::GetFileSize("font.ttf");
|
2011-07-24 18:32:09 +02:00
|
|
|
}
|
|
|
|
|
2011-10-21 20:48:10 +02:00
|
|
|
delete fontSystem;
|
2011-07-23 21:49:51 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
fontSystem = new FreeTypeGX(loadedFont, loadedFontSize, loadedFont == systemFont);
|
2010-12-28 18:02:10 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
return result;
|
2010-12-28 18:02:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Theme::ClearFontData()
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
if (fontSystem)
|
|
|
|
delete fontSystem;
|
|
|
|
fontSystem = NULL;
|
2010-12-28 18:02:10 +01:00
|
|
|
|
2011-07-23 21:49:51 +02:00
|
|
|
if(customFont)
|
2011-07-26 00:28:22 +02:00
|
|
|
delete [] customFont;
|
2011-07-23 21:49:51 +02:00
|
|
|
customFont = NULL;
|
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
if (systemFont)
|
|
|
|
delete [] systemFont;
|
|
|
|
systemFont = NULL;
|
2010-12-28 18:02:10 +01:00
|
|
|
}
|