Merge pull request #2191 from aquanull/PSPDialog

Psp dialog improvements
This commit is contained in:
Henrik Rydgård 2013-06-11 01:49:34 -07:00
commit cf7fafc15c
13 changed files with 610 additions and 372 deletions

View File

@ -18,8 +18,10 @@
#include "../Util/PPGeDraw.h"
#include "PSPDialog.h"
#include "ChunkFile.h"
#include "i18n/i18n.h"
#define FADE_TIME 0.5
const float FONT_SCALE = 0.55f;
PSPDialog::PSPDialog() : status(SCE_UTILITY_STATUS_SHUTDOWN)
, lastButtons(0)
@ -44,20 +46,13 @@ PSPDialog::DialogStatus PSPDialog::GetStatus()
void PSPDialog::StartDraw()
{
PPGeBegin();
PPGeDrawRect(0, 0, 480, 272, CalcFadedColor(0x70606060));
}
void PSPDialog::EndDraw()
{
PPGeEnd();
}
void PSPDialog::DisplayMessage(std::string text)
{
PPGeDrawRect(30, 30, 450, 31, CalcFadedColor(0xFFFFFFFF));
PPGeDrawRect(30, 200, 450, 201, CalcFadedColor(0xFFFFFFFF));
PPGeDrawTextWrapped(text.c_str(), 40, 50, 420, PPGE_ALIGN_LEFT, 0.55f, CalcFadedColor(0xFFFFFFFF));
}
int PSPDialog::Shutdown(bool force)
{
status = SCE_UTILITY_STATUS_SHUTDOWN;
@ -75,7 +70,7 @@ void PSPDialog::UpdateFade()
{
if(isFading)
{
fadeTimer += 1.0f/30; // Probably need a more real value of delta time
fadeTimer += 1.0f/30.0f; // Probably need a more real value of delta time
if(fadeTimer < FADE_TIME)
{
if(fadeIn)
@ -116,13 +111,38 @@ void PSPDialog::DoState(PointerWrap &p)
p.Do(isFading);
p.Do(fadeIn);
p.Do(fadeValue);
p.Do(okButtonImg);
p.Do(cancelButtonImg);
p.Do(okButtonFlag);
p.Do(cancelButtonFlag);
p.DoMarker("PSPDialog");
}
pspUtilityDialogCommon *PSPDialog::GetCommonParam()
{
// FIXME
return 0;
}
bool PSPDialog::IsButtonPressed(int checkButton)
{
if(isFading) return false;
return (!(lastButtons & checkButton)) && (buttons & checkButton);
return !isFading && !(lastButtons & checkButton) && (buttons & checkButton);
}
void PSPDialog::DisplayButtons(int flags)
{
I18NCategory *d = GetI18NCategory("Dialog");
float x1 = 183.5f, x2 = 261.5f;
if (GetCommonParam()->buttonSwap == 1) {
x1 = 261.5f;
x2 = 183.5f;
}
if (flags & DS_BUTTON_OK) {
PPGeDrawImage(okButtonImg, x2, 256, 11.5f, 11.5f, 0, CalcFadedColor(0xFFFFFFFF));
PPGeDrawText(d->T("Enter"), x2 + 14.5f, 252, PPGE_ALIGN_LEFT, FONT_SCALE, CalcFadedColor(0xFFFFFFFF));
}
if (flags & DS_BUTTON_CANCEL) {
PPGeDrawText(d->T("Back"), x1 + 14.5f, 252, PPGE_ALIGN_LEFT, FONT_SCALE, CalcFadedColor(0xFFFFFFFF));
PPGeDrawImage(cancelButtonImg, x1, 256, 11.5f, 11.5f, 0, CalcFadedColor(0xFFFFFFFF));
}
}

View File

@ -54,6 +54,7 @@ public:
virtual int Update();
virtual int Shutdown(bool force = false);
virtual void DoState(PointerWrap &p);
virtual pspUtilityDialogCommon *GetCommonParam();
enum DialogStatus
{
@ -64,13 +65,21 @@ public:
SCE_UTILITY_STATUS_SHUTDOWN = 4
};
enum DialogStockButton
{
DS_BUTTON_NONE = 0x00,
DS_BUTTON_OK = 0x01,
DS_BUTTON_CANCEL = 0x02,
DS_BUTTON_BOTH = 0x03,
};
DialogStatus GetStatus();
void StartDraw();
void EndDraw();
protected:
bool IsButtonPressed(int checkButton);
void DisplayMessage(std::string text);
void DisplayButtons(int flags);
void StartFade(bool fadeIn_);
void UpdateFade();
@ -85,4 +94,9 @@ protected:
bool isFading;
bool fadeIn;
u32 fadeValue;
int okButtonImg;
int cancelButtonImg;
int okButtonFlag;
int cancelButtonFlag;
};

View File

@ -23,6 +23,8 @@
#include "ChunkFile.h"
#include "i18n/i18n.h"
const float FONT_SCALE = 0.55f;
PSPMsgDialog::PSPMsgDialog()
: PSPDialog()
, flag(0)
@ -128,45 +130,61 @@ int PSPMsgDialog::Init(unsigned int paramAddr)
return 0;
}
void PSPMsgDialog::DisplayBack()
void PSPMsgDialog::DisplayMessage(std::string text, bool hasYesNo)
{
I18NCategory *d = GetI18NCategory("Dialog");
PPGeDrawImage(cancelButtonImg, 290, 220, 12, 12, 0, CalcFadedColor(0xFFFFFFFF));
PPGeDrawText(d->T("Back"), 310, 218, PPGE_ALIGN_LEFT, 0.5f, CalcFadedColor(0xFFFFFFFF));
}
void PSPMsgDialog::DisplayYesNo()
{
I18NCategory *d = GetI18NCategory("Dialog");
PPGeDrawText(d->T("Yes"), 200, 150, PPGE_ALIGN_LEFT, 0.55f, CalcFadedColor(yesnoChoice == 1?0xFF0000FF:0xFFFFFFFF));
PPGeDrawText(d->T("No"), 320, 150, PPGE_ALIGN_LEFT, 0.55f, CalcFadedColor(yesnoChoice == 0?0xFF0000FF:0xFFFFFFFF));
if (IsButtonPressed(CTRL_LEFT) && yesnoChoice == 0)
const float WRAP_WIDTH = 350.0f;
float y = 136.0f, h;
int n;
PPGeMeasureText(0, &h, &n, text.c_str(), FONT_SCALE, PPGE_LINE_WRAP_WORD, WRAP_WIDTH);
float h2 = h * (float)n / 2.0f;
if (hasYesNo)
{
yesnoChoice = 1;
I18NCategory *d = GetI18NCategory("Dialog");
const char *choiceText;
u32 yesColor, noColor;
float x, w;
if (yesnoChoice == 1) {
choiceText = d->T("Yes");
x = 208.0f;
yesColor = 0xFF0FFFFF;
noColor = 0xFFFFFFFF;
}
else {
choiceText = d->T("No");
x = 272.0f;
yesColor = 0xFFFFFFFF;
noColor = 0xFF0FFFFF;
}
PPGeMeasureText(&w, &h, 0, choiceText, FONT_SCALE);
w = w / 2.0f + 5.5f;
h /= 2.0f;
float y2 = y + h2 + 4.0f;
h2 += h + 4.0f;
y = 132.0f - h;
PPGeDrawRect(x - w, y2 - h, x + w, y2 + h, CalcFadedColor(0x6DCFCFCF));
PPGeDrawText(d->T("Yes"), 208.0f, y2, PPGE_ALIGN_CENTER, FONT_SCALE, CalcFadedColor(yesColor));
PPGeDrawText(d->T("No"), 272.0f, y2, PPGE_ALIGN_CENTER, FONT_SCALE, CalcFadedColor(noColor));
if (IsButtonPressed(CTRL_LEFT) && yesnoChoice == 0) {
yesnoChoice = 1;
}
else if (IsButtonPressed(CTRL_RIGHT) && yesnoChoice == 1) {
yesnoChoice = 0;
}
}
else if (IsButtonPressed(CTRL_RIGHT) && yesnoChoice == 1)
{
yesnoChoice = 0;
}
}
void PSPMsgDialog::DisplayOk()
{
I18NCategory *d = GetI18NCategory("Dialog");
PPGeDrawImage(okButtonImg, 200, 220, 12, 12, 0, CalcFadedColor(0xFFFFFFFF));
PPGeDrawText(d->T("Enter"), 220, 218, PPGE_ALIGN_LEFT, 0.5f, CalcFadedColor(0xFFFFFFFF));
PPGeDrawTextWrapped(text.c_str(), 240.0f, y, WRAP_WIDTH, PPGE_ALIGN_CENTER, FONT_SCALE, CalcFadedColor(0xFFFFFFFF));
float sy = 122.0f - h2, ey = 150.0f + h2;
PPGeDrawRect(60.0f, sy, 420.0f, sy + 1.0f, CalcFadedColor(0xFFFFFFFF));
PPGeDrawRect(60.0f, ey, 420.0f, ey + 1.0f, CalcFadedColor(0xFFFFFFFF));
}
int PSPMsgDialog::Update()
{
if (status != SCE_UTILITY_STATUS_RUNNING)
{
return 0;
}
if((flag & DS_ERROR))
if ((flag & DS_ERROR))
{
status = SCE_UTILITY_STATUS_FINISHED;
}
@ -180,7 +198,7 @@ int PSPMsgDialog::Update()
cancelButtonImg = I_CROSS;
okButtonFlag = CTRL_CIRCLE;
cancelButtonFlag = CTRL_CROSS;
if(messageDialog.common.buttonSwap == 1)
if (messageDialog.common.buttonSwap == 1)
{
okButtonImg = I_CROSS;
cancelButtonImg = I_CIRCLE;
@ -189,17 +207,21 @@ int PSPMsgDialog::Update()
}
StartDraw();
// white -> RGB(168,173,189), black -> RGB(129,134,150)
// (255 - a) + (x * a / 255) = 173, x * a / 255 = 134
// a = 255 - w + b = 158, x = b * 255 / a = ?
// but is not drawn using x * a + y * (255 - a) here?
//PPGeDrawRect(0, 0, 480, 272, CalcFadedColor(0x9EF2D8D0));
PPGeDrawRect(0, 0, 480, 272, CalcFadedColor(0xC0C8B2AC));
if((flag & DS_MSG) || (flag & DS_ERRORMSG))
DisplayMessage(msgText);
if ((flag & DS_MSG) || (flag & DS_ERRORMSG))
DisplayMessage(msgText, (flag & DS_YESNO) != 0);
if(flag & DS_YESNO)
DisplayYesNo();
if (flag & (DS_OK | DS_VALIDBUTTON))
DisplayOk();
DisplayButtons(DS_BUTTON_OK);
if(flag & DS_CANCELBUTTON)
DisplayBack();
if (flag & DS_CANCELBUTTON)
DisplayButtons(DS_BUTTON_CANCEL);
if (IsButtonPressed(cancelButtonFlag) && (flag & DS_CANCELBUTTON))
{
@ -210,9 +232,9 @@ int PSPMsgDialog::Update()
messageDialog.buttonPressed = 0;
StartFade(false);
}
else if(IsButtonPressed(okButtonFlag) && (flag & DS_VALIDBUTTON))
else if (IsButtonPressed(okButtonFlag) && (flag & DS_VALIDBUTTON))
{
if(yesnoChoice == 0)
if (yesnoChoice == 0)
{
messageDialog.buttonPressed = 2;
}
@ -252,9 +274,10 @@ void PSPMsgDialog::DoState(PointerWrap &p)
p.Do(messageDialogAddr);
p.DoArray(msgText, sizeof(msgText));
p.Do(yesnoChoice);
p.Do(okButtonImg);
p.Do(cancelButtonImg);
p.Do(okButtonFlag);
p.Do(cancelButtonFlag);
p.DoMarker("PSPMsgDialog");
}
pspUtilityDialogCommon *PSPMsgDialog::GetCommonParam()
{
return &messageDialog.common;
}

View File

@ -61,13 +61,12 @@ public:
virtual int Update();
virtual int Shutdown(bool force = false);
virtual void DoState(PointerWrap &p);
virtual pspUtilityDialogCommon *GetCommonParam();
int Abort();
private :
void DisplayBack();
void DisplayYesNo();
void DisplayEnter();
void DisplayOk();
void DisplayMessage(std::string text, bool hasYesNo = false);
enum Flags
{
@ -89,10 +88,5 @@ private :
char msgText[512];
int yesnoChoice;
int okButtonImg;
int cancelButtonImg;
int okButtonFlag;
int cancelButtonFlag;
};

View File

@ -748,6 +748,7 @@ int PSPOskDialog::Update()
UpdateFade();
StartDraw();
PPGeDrawRect(0, 0, 480, 272, CalcFadedColor(0x63636363));
RenderKeyboard();
if (g_Config.bButtonPreference)
{
@ -873,3 +874,8 @@ void PSPOskDialog::DoState(PointerWrap &p)
p.Do(inputChars);
p.DoMarker("PSPOskDialog");
}
pspUtilityDialogCommon *PSPOskDialog::GetCommonParam()
{
return &oskParams->base;
}

View File

@ -162,6 +162,8 @@ public:
virtual int Update();
virtual int Shutdown(bool force = false);
virtual void DoState(PointerWrap &p);
virtual pspUtilityDialogCommon *GetCommonParam();
private:
void ConvertUCS2ToUTF8(std::string& _string, const PSPPointer<u16> em_address);
void ConvertUCS2ToUTF8(std::string& _string, const wchar_t *input);

View File

@ -18,12 +18,15 @@
#include "PSPSaveDialog.h"
#include "../Util/PPGeDraw.h"
#include "../HLE/sceCtrl.h"
#include "../HLE/sceUtility.h"
#include "../Core/MemMap.h"
#include "../Config.h"
#include "Core/Reporting.h"
#include "Core/HW/MemoryStick.h"
#include "i18n/i18n.h"
const float FONT_SCALE = 0.55f;
PSPSaveDialog::PSPSaveDialog()
: PSPDialog()
, display(DS_NONE)
@ -161,7 +164,7 @@ int PSPSaveDialog::Init(int paramAddr)
default:
{
ERROR_LOG_REPORT(HLE, "Load/Save function %d not coded. Title: %s Save: %s File: %s", param.GetPspParam()->mode, param.GetGameName(param.GetPspParam()).c_str(), param.GetGameName(param.GetPspParam()).c_str(), param.GetFileName(param.GetPspParam()).c_str());
param.GetPspParam()->result = 0;
param.GetPspParam()->common.result = 0;
status = SCE_UTILITY_STATUS_INITIALIZE;
display = DS_NONE;
return 0; // Return 0 should allow the game to continue, but missing function must be implemented and returning the right value or the game can block.
@ -178,7 +181,7 @@ int PSPSaveDialog::Init(int paramAddr)
INFO_LOG(HLE,"size : %d",param.GetPspParam()->size);
INFO_LOG(HLE,"language : %d",param.GetPspParam()->language);
INFO_LOG(HLE,"buttonSwap : %d",param.GetPspParam()->buttonSwap);
INFO_LOG(HLE,"result : %d",param.GetPspParam()->result);
INFO_LOG(HLE,"result : %d",param.GetPspParam()->common.result);
INFO_LOG(HLE,"mode : %d",param.GetPspParam()->mode);
INFO_LOG(HLE,"bind : %d",param.GetPspParam()->bind);
INFO_LOG(HLE,"overwriteMode : %d",param.GetPspParam()->overwriteMode);
@ -242,45 +245,69 @@ const std::string PSPSaveDialog::GetSelectedSaveDirName()
}
}
void PSPSaveDialog::DisplayBanner(int which)
{
I18NCategory *d = GetI18NCategory("Dialog");
PPGeDrawRect(0, 0, 480, 23, CalcFadedColor(0x65636358));
const char *title;
switch (which)
{
case DB_SAVE:
title = d->T("Save");
break;
case DB_LOAD:
title = d->T("Load");
break;
case DB_DELETE:
title = d->T("Delete");
break;
default:
title = "";
break;
}
// TODO: Draw a hexagon icon
PPGeDrawText(title, 30, 11, PPGE_ALIGN_VCENTER, 0.6f, CalcFadedColor(0xFFFFFFFF));
}
void PSPSaveDialog::DisplaySaveList(bool canMove)
{
int displayCount = 0;
for(int i = 0; i < param.GetFilenameCount(); i++)
for (int i = 0; i < param.GetFilenameCount(); i++)
{
int textureColor = CalcFadedColor(0xFFFFFFFF);
if(param.GetFileInfo(i).size == 0 && param.GetFileInfo(i).textureData == 0)
if (param.GetFileInfo(i).size == 0 && param.GetFileInfo(i).textureData == 0)
textureColor = CalcFadedColor(0xFF777777);
// Calc save image position on screen
float w = 150;
float w = 144;
float h = 80;
float x = 20;
if(displayCount != currentSelectedSave) {
w = 80;
h = 40;
x = 55;
float x = 27;
if (displayCount != currentSelectedSave) {
w = 81;
h = 45;
x = 58.5f;
}
float y = 96;
if(displayCount < currentSelectedSave)
y -= 10 + 40 * (currentSelectedSave - displayCount );
else if(displayCount > currentSelectedSave)
y += 91 + 40 * (displayCount - currentSelectedSave - 1);
float y = 97;
if (displayCount < currentSelectedSave)
y -= 13 + 45 * (currentSelectedSave - displayCount);
else if (displayCount > currentSelectedSave)
y += 48 + 45 * (displayCount - currentSelectedSave);
int tw = 256;
int th = 256;
if(param.GetFileInfo(i).textureData != 0) {
if (param.GetFileInfo(i).textureData != 0) {
tw = param.GetFileInfo(i).textureWidth;
th = param.GetFileInfo(i).textureHeight;
PPGeSetTexture(param.GetFileInfo(i).textureData, param.GetFileInfo(i).textureWidth, param.GetFileInfo(i).textureHeight);
} else
PPGeDisableTexture();
PPGeDrawImage(x, y, w, h, 0, 0 ,1 ,1 ,tw, th, textureColor);
PPGeDrawImage(x, y, w, h, 0, 0, 1, 1, tw, th, textureColor);
PPGeSetDefaultTexture();
displayCount++;
}
if(canMove) {
if (canMove) {
if (IsButtonPressed(CTRL_UP) && currentSelectedSave > 0)
currentSelectedSave--;
else if (IsButtonPressed(CTRL_DOWN) && currentSelectedSave < (param.GetFilenameCount()-1))
@ -292,33 +319,33 @@ void PSPSaveDialog::DisplaySaveIcon()
{
int textureColor = CalcFadedColor(0xFFFFFFFF);
if(param.GetFileInfo(currentSelectedSave).size == 0)
if (param.GetFileInfo(currentSelectedSave).size == 0)
textureColor = CalcFadedColor(0xFF777777);
// Calc save image position on screen
float w = 150;
float w = 144;
float h = 80;
float x = 20;
float y = 80;
float x = 27;
float y = 97;
int tw = 256;
int th = 256;
if(param.GetFileInfo(currentSelectedSave).textureData != 0) {
if (param.GetFileInfo(currentSelectedSave).textureData != 0) {
tw = param.GetFileInfo(currentSelectedSave).textureWidth;
th = param.GetFileInfo(currentSelectedSave).textureHeight;
PPGeSetTexture(param.GetFileInfo(currentSelectedSave).textureData, param.GetFileInfo(currentSelectedSave).textureWidth, param.GetFileInfo(currentSelectedSave).textureHeight);
} else
PPGeDisableTexture();
PPGeDrawImage(x, y, w, h, 0, 0 ,1 ,1 ,tw, th, textureColor);
if(param.GetFileInfo(currentSelectedSave).textureData != 0)
if (param.GetFileInfo(currentSelectedSave).textureData != 0)
PPGeSetDefaultTexture();
}
void PSPSaveDialog::DisplaySaveDataInfo1()
{
if(param.GetFileInfo(currentSelectedSave).size == 0) {
if (param.GetFileInfo(currentSelectedSave).size == 0) {
I18NCategory *d = GetI18NCategory("Dialog");
PPGeDrawText(d->T("New Save"), 180, 100, PPGE_ALIGN_LEFT, 0.5f, CalcFadedColor(0xFFFFFFFF));
PPGeDrawText(d->T("New Save"), 180, 136, PPGE_ALIGN_VCENTER, FONT_SCALE, CalcFadedColor(0xFFFFFFFF));
} else {
char title[512];
char time[512];
@ -327,10 +354,10 @@ void PSPSaveDialog::DisplaySaveDataInfo1()
char am_pm[] = "AM";
char hour_time[10] ;
int hour = param.GetFileInfo(currentSelectedSave).modif_time.tm_hour ;
int min = param.GetFileInfo(currentSelectedSave).modif_time.tm_min ;
if (g_Config.itimeformat) {
if( hour > 12 ) {
int hour = param.GetFileInfo(currentSelectedSave).modif_time.tm_hour;
int min = param.GetFileInfo(currentSelectedSave).modif_time.tm_min;
if (g_Config.itimeformat == PSP_SYSTEMPARAM_TIME_FORMAT_12HR) {
if (hour > 12) {
strcpy(am_pm, "PM");
hour -= 12;
}
@ -338,42 +365,51 @@ void PSPSaveDialog::DisplaySaveDataInfo1()
} else
snprintf(hour_time,10,"%02d:%02d", hour, min);
snprintf(title,512,"%s", param.GetFileInfo(currentSelectedSave).title);
snprintf(time,512,"%02d/%02d/%d %s %lld KB"
, param.GetFileInfo(currentSelectedSave).modif_time.tm_mday
, param.GetFileInfo(currentSelectedSave).modif_time.tm_mon + 1
, param.GetFileInfo(currentSelectedSave).modif_time.tm_year + 1900
, hour_time
, param.GetFileInfo(currentSelectedSave).size / 1024
);
snprintf(saveTitle,512,"%s", param.GetFileInfo(currentSelectedSave).saveTitle);
snprintf(saveDetail,512,"%s", param.GetFileInfo(currentSelectedSave).saveDetail);
snprintf(title, 512, "%s", param.GetFileInfo(currentSelectedSave).title);
int day = param.GetFileInfo(currentSelectedSave).modif_time.tm_mday;
int month = param.GetFileInfo(currentSelectedSave).modif_time.tm_mon + 1;
int year = param.GetFileInfo(currentSelectedSave).modif_time.tm_year + 1900;
s64 sizeK = param.GetFileInfo(currentSelectedSave).size / 1024;
switch (g_Config.iDateFormat) {
case PSP_SYSTEMPARAM_DATE_FORMAT_DDMMYYYY:
snprintf(time, 512, "%02d/%02d/%d %s %lld KB", day, month, year, hour_time, sizeK);
break;
case PSP_SYSTEMPARAM_DATE_FORMAT_MMDDYYYY:
snprintf(time, 512, "%02d/%02d/%d %s %lld KB", month, day, year, hour_time, sizeK);
break;
case PSP_SYSTEMPARAM_DATE_FORMAT_YYYYMMDD:
// fall through
default:
snprintf(time, 512, "%d/%02d/%02d %s %lld KB", year, month, day, hour_time, sizeK);
}
snprintf(saveTitle, 512, "%s", param.GetFileInfo(currentSelectedSave).saveTitle);
snprintf(saveDetail, 512, "%s", param.GetFileInfo(currentSelectedSave).saveDetail);
PPGeDrawRect(180, 139, 980, 140, CalcFadedColor(0xFFFFFFFF));
PPGeDrawRect(180, 136, 980, 137, CalcFadedColor(0xFFFFFFFF));
std::string titleTxt = title;
std::string timeTxt = time;
std::string saveTitleTxt = saveTitle;
std::string saveDetailTxt = saveDetail;
PPGeDrawText(titleTxt.c_str(), 180, 120, PPGE_ALIGN_LEFT, 0.6f, CalcFadedColor(0xFFC0C0C0));
PPGeDrawText(timeTxt.c_str(), 180, 141, PPGE_ALIGN_LEFT, 0.45f, CalcFadedColor(0xFFFFFFFF));
PPGeDrawText(saveTitleTxt.c_str(), 175, 163, PPGE_ALIGN_LEFT, 0.45f, CalcFadedColor(0xFFFFFFFF));
PPGeDrawText(saveDetailTxt.c_str(), 175, 185, PPGE_ALIGN_LEFT, 0.45f, CalcFadedColor(0xFFFFFFFF));
PPGeDrawText(titleTxt.c_str(), 180, 136, PPGE_ALIGN_BOTTOM, 0.6f, CalcFadedColor(0xFFC0C0C0));
PPGeDrawText(timeTxt.c_str(), 180, 137, PPGE_ALIGN_LEFT, 0.45f, CalcFadedColor(0xFFFFFFFF));
PPGeDrawText(saveTitleTxt.c_str(), 175, 159, PPGE_ALIGN_LEFT, FONT_SCALE, CalcFadedColor(0xFFFFFFFF));
PPGeDrawText(saveDetailTxt.c_str(), 175, 181, PPGE_ALIGN_LEFT, 0.45f, CalcFadedColor(0xFFFFFFFF));
}
}
void PSPSaveDialog::DisplaySaveDataInfo2()
{
if(param.GetFileInfo(currentSelectedSave).size == 0) {
if (param.GetFileInfo(currentSelectedSave).size == 0) {
} else {
char txt[1024];
char date[256];
char am_pm[] = "AM";
char hour_time[10] ;
int hour = param.GetFileInfo(currentSelectedSave).modif_time.tm_hour ;
int min = param.GetFileInfo(currentSelectedSave).modif_time.tm_min ;
if (g_Config.itimeformat) {
if( hour > 12 ) {
int hour = param.GetFileInfo(currentSelectedSave).modif_time.tm_hour;
int min = param.GetFileInfo(currentSelectedSave).modif_time.tm_min;
if (g_Config.itimeformat == PSP_SYSTEMPARAM_TIME_FORMAT_12HR) {
if (hour > 12) {
strcpy(am_pm, "PM");
hour -= 12;
}
@ -381,38 +417,74 @@ void PSPSaveDialog::DisplaySaveDataInfo2()
} else
snprintf(hour_time,10,"%02d:%02d", hour, min);
snprintf(txt,1024,"%s\n%02d/%02d/%d %s\n%lld KB"
, param.GetFileInfo(currentSelectedSave).saveTitle
, param.GetFileInfo(currentSelectedSave).modif_time.tm_mday
, param.GetFileInfo(currentSelectedSave).modif_time.tm_mon + 1
, param.GetFileInfo(currentSelectedSave).modif_time.tm_year + 1900
, hour_time
, param.GetFileInfo(currentSelectedSave).size / 1024
);
const char *saveTitle = param.GetFileInfo(currentSelectedSave).saveTitle;
int day = param.GetFileInfo(currentSelectedSave).modif_time.tm_mday;
int month = param.GetFileInfo(currentSelectedSave).modif_time.tm_mon + 1;
int year = param.GetFileInfo(currentSelectedSave).modif_time.tm_year + 1900;
s64 sizeK = param.GetFileInfo(currentSelectedSave).size / 1024;
switch (g_Config.iDateFormat) {
case PSP_SYSTEMPARAM_DATE_FORMAT_DDMMYYYY:
snprintf(date, 256, "%02d/%02d/%d", day, month, year);
break;
case PSP_SYSTEMPARAM_DATE_FORMAT_MMDDYYYY:
snprintf(date, 256, "%02d/%02d/%d", month, day, year);
break;
case PSP_SYSTEMPARAM_DATE_FORMAT_YYYYMMDD:
// fall through
default:
snprintf(date, 256, "%d/%02d/%02d", year, month, day);
}
snprintf(txt, 1024, "%s\n%s %s\n%lld KB", saveTitle, date, hour_time, sizeK);
std::string saveinfoTxt = txt;
PPGeDrawText(saveinfoTxt.c_str(), 10, 180, PPGE_ALIGN_LEFT, 0.45f, CalcFadedColor(0xFFFFFFFF));
PPGeDrawText(saveinfoTxt.c_str(), 8, 200, PPGE_ALIGN_LEFT, 0.45f, CalcFadedColor(0xFFFFFFFF));
}
}
void PSPSaveDialog::DisplayConfirmationYesNo(std::string text)
void PSPSaveDialog::DisplayMessage(std::string text, bool hasYesNo)
{
I18NCategory *d = GetI18NCategory("Dialog");
PPGeDrawRect(200, 85, 460, 86, CalcFadedColor(0xFFFFFFFF));
PPGeDrawRect(200, 160, 460, 161, CalcFadedColor(0xFFFFFFFF));
PPGeDrawText(text.c_str(), 320, 100, PPGE_ALIGN_HCENTER, 0.5f, 0xFFFFFFFF);
PPGeDrawText(d->T("Yes"), 275, 130, PPGE_ALIGN_LEFT, 0.5f, CalcFadedColor(yesnoChoice == 1?0xFF0000FF:0xFFFFFFFF));
PPGeDrawText(d->T("No"), 340, 130, PPGE_ALIGN_LEFT, 0.5f, CalcFadedColor(yesnoChoice == 0?0xFF0000FF:0xFFFFFFFF));
if (IsButtonPressed(CTRL_LEFT) && yesnoChoice == 0)
yesnoChoice = 1;
else if (IsButtonPressed(CTRL_RIGHT) && yesnoChoice == 1)
yesnoChoice = 0;
}
void PSPSaveDialog::DisplayInfo(std::string text)
{
PPGeDrawRect(200, 100, 460, 101, CalcFadedColor(0xFFFFFFFF));
PPGeDrawRect(200, 140, 460, 141, CalcFadedColor(0xFFFFFFFF));
PPGeDrawText(text.c_str(), 320, 110, PPGE_ALIGN_HCENTER, 0.5f, CalcFadedColor(0xFFFFFFFF));
const float WRAP_WIDTH = 254.0f;
float y = 136.0f, h;
int n;
PPGeMeasureText(0, &h, &n, text.c_str(), FONT_SCALE, PPGE_LINE_WRAP_WORD, WRAP_WIDTH);
float h2 = h * (float)n / 2.0f;
if (hasYesNo)
{
I18NCategory *d = GetI18NCategory("Dialog");
const char *choiceText;
u32 yesColor, noColor;
float x, w;
if (yesnoChoice == 1) {
choiceText = d->T("Yes");
x = 302.0f;
yesColor = 0xFF0FFFFF;
noColor = 0xFFFFFFFF;
}
else {
choiceText = d->T("No");
x = 366.0f;
yesColor = 0xFFFFFFFF;
noColor = 0xFF0FFFFF;
}
PPGeMeasureText(&w, &h, 0, choiceText, FONT_SCALE);
w = w / 2.0f + 5.5f;
h /= 2.0f;
float y2 = y + h2 + 4.0f;
h2 += h + 4.0f;
y = 132.0f - h;
PPGeDrawRect(x - w, y2 - h, x + w, y2 + h, CalcFadedColor(0x6DCFCFCF));
PPGeDrawText(d->T("Yes"), 302.0f, y2, PPGE_ALIGN_CENTER, FONT_SCALE, CalcFadedColor(yesColor));
PPGeDrawText(d->T("No"), 366.0f, y2, PPGE_ALIGN_CENTER, FONT_SCALE, CalcFadedColor(noColor));
if (IsButtonPressed(CTRL_LEFT) && yesnoChoice == 0) {
yesnoChoice = 1;
}
else if (IsButtonPressed(CTRL_RIGHT) && yesnoChoice == 1) {
yesnoChoice = 0;
}
}
PPGeDrawTextWrapped(text.c_str(), 334.0f, y, WRAP_WIDTH, PPGE_ALIGN_CENTER, FONT_SCALE, CalcFadedColor(0xFFFFFFFF));
float sy = 122.0f - h2, ey = 150.0f + h2;
PPGeDrawRect(202.0f, sy, 466.0f, sy + 1.0f, CalcFadedColor(0xFFFFFFFF));
PPGeDrawRect(202.0f, ey, 466.0f, ey + 1.0f, CalcFadedColor(0xFFFFFFFF));
}
void PSPSaveDialog::DisplayTitle(std::string name)
@ -420,22 +492,6 @@ void PSPSaveDialog::DisplayTitle(std::string name)
PPGeDrawText(name.c_str(), 10, 10, PPGE_ALIGN_LEFT, 0.45f, CalcFadedColor(0xFFFFFFFF));
}
void PSPSaveDialog::DisplayEnterBack()
{
I18NCategory *d = GetI18NCategory("Dialog");
PPGeDrawImage(cancelButtonImg, 180, 257, 11, 11, 0, CalcFadedColor(0xFFFFFFFF));
PPGeDrawImage(okButtonImg, 270, 257, 11, 11, 0, CalcFadedColor(0xFFFFFFFF));
PPGeDrawText(d->T("Back"), 195, 255, PPGE_ALIGN_LEFT, 0.45f, CalcFadedColor(0xFFFFFFFF));
PPGeDrawText(d->T("Enter"), 285, 255, PPGE_ALIGN_LEFT, 0.45f, CalcFadedColor(0xFFFFFFFF));
}
void PSPSaveDialog::DisplayBack()
{
I18NCategory *d = GetI18NCategory("Dialog");
PPGeDrawImage(cancelButtonImg, 180, 257, 11, 11, 0, CalcFadedColor(0xFFFFFFFF));
PPGeDrawText(d->T("Back"), 195, 255, PPGE_ALIGN_LEFT, 0.45f, CalcFadedColor(0xFFFFFFFF));
}
int PSPSaveDialog::Update()
{
switch (status) {
@ -461,7 +517,7 @@ int PSPSaveDialog::Update()
cancelButtonImg = I_CROSS;
okButtonFlag = CTRL_CIRCLE;
cancelButtonFlag = CTRL_CROSS;
if (param.GetPspParam()->buttonSwap == 1) {
if (param.GetPspParam()->common.buttonSwap == 1) {
okButtonImg = I_CROSS;
cancelButtonImg = I_CIRCLE;
okButtonFlag = CTRL_CROSS;
@ -474,15 +530,15 @@ int PSPSaveDialog::Update()
{
case DS_SAVE_LIST_CHOICE:
StartDraw();
// TODO : use focus param for selected save by default
DisplaySaveList();
DisplaySaveDataInfo1();
DisplayEnterBack();
DisplayButtons(DS_BUTTON_OK | DS_BUTTON_CANCEL);
DisplayBanner(DB_SAVE);
if (IsButtonPressed(cancelButtonFlag)) {
param.GetPspParam()->result = SCE_UTILITY_DIALOG_RESULT_CANCEL;
param.GetPspParam()->common.result = SCE_UTILITY_DIALOG_RESULT_CANCEL;
StartFade(false);
} else if (IsButtonPressed(okButtonFlag)) {
// Save exist, ask user confirm
@ -506,11 +562,13 @@ int PSPSaveDialog::Update()
DisplaySaveIcon();
DisplaySaveDataInfo2();
DisplayConfirmationYesNo(d->T("Confirm Save", "Do you want to save this data?"));
DisplayMessage(d->T("Confirm Save", "Do you want to save this data?"), true);
DisplayButtons(DS_BUTTON_OK | DS_BUTTON_CANCEL);
DisplayBanner(DB_SAVE);
DisplayEnterBack();
if (IsButtonPressed(cancelButtonFlag) || (IsButtonPressed(okButtonFlag) && yesnoChoice == 0)) {
param.GetPspParam()->result = SCE_UTILITY_DIALOG_RESULT_CANCEL;
param.GetPspParam()->common.result = SCE_UTILITY_DIALOG_RESULT_CANCEL;
StartFade(false);
} else if (IsButtonPressed(okButtonFlag)) {
display = DS_SAVE_SAVING;
@ -531,14 +589,16 @@ int PSPSaveDialog::Update()
DisplaySaveIcon();
DisplaySaveDataInfo2();
DisplayConfirmationYesNo(d->T("Do you want to overwrite the data?"));
DisplayMessage(d->T("Do you want to overwrite the data?"), true);
DisplayButtons(DS_BUTTON_OK | DS_BUTTON_CANCEL);
DisplayBanner(DB_SAVE);
DisplayEnterBack();
if (IsButtonPressed(cancelButtonFlag) || (IsButtonPressed(okButtonFlag) && yesnoChoice == 0)) {
if (param.GetPspParam()->mode != SCE_UTILITY_SAVEDATA_TYPE_SAVE)
display = DS_SAVE_LIST_CHOICE;
else {
param.GetPspParam()->result = SCE_UTILITY_DIALOG_RESULT_CANCEL;
param.GetPspParam()->common.result = SCE_UTILITY_DIALOG_RESULT_CANCEL;
StartFade(false);
}
} else if (IsButtonPressed(okButtonFlag)) {
@ -563,7 +623,9 @@ int PSPSaveDialog::Update()
DisplaySaveIcon();
DisplaySaveDataInfo2();
DisplayInfo(d->T("Saving","Saving\nPlease Wait..."));
DisplayMessage(d->T("Saving","Saving\nPlease Wait..."));
DisplayBanner(DB_SAVE);
EndDraw();
break;
@ -572,12 +634,14 @@ int PSPSaveDialog::Update()
DisplaySaveIcon();
DisplaySaveDataInfo2();
DisplayBack();
DisplayInfo(d->T("Save completed"));
DisplayMessage(d->T("Save completed"));
DisplayButtons(DS_BUTTON_CANCEL);
DisplayBanner(DB_SAVE);
if (IsButtonPressed(cancelButtonFlag)) {
param.GetPspParam()->result = SCE_UTILITY_DIALOG_RESULT_SUCCESS;
param.GetPspParam()->common.result = SCE_UTILITY_DIALOG_RESULT_SUCCESS;
// Set the save to use for autosave and autoload
param.SetSelectedSave(param.GetFileInfo(currentSelectedSave).idx);
StartFade(false);
@ -592,9 +656,11 @@ int PSPSaveDialog::Update()
DisplaySaveList();
DisplaySaveDataInfo1();
DisplayEnterBack();
DisplayButtons(DS_BUTTON_OK | DS_BUTTON_CANCEL);
DisplayBanner(DB_LOAD);
if (IsButtonPressed(cancelButtonFlag)) {
param.GetPspParam()->result = SCE_UTILITY_DIALOG_RESULT_CANCEL;
param.GetPspParam()->common.result = SCE_UTILITY_DIALOG_RESULT_CANCEL;
StartFade(false);
} else if (IsButtonPressed(okButtonFlag)) {
display = DS_LOAD_LOADING;
@ -610,18 +676,20 @@ int PSPSaveDialog::Update()
DisplaySaveIcon();
DisplaySaveDataInfo2();
DisplayConfirmationYesNo(d->T("ConfirmLoad", "Load this data?"));
DisplayMessage(d->T("ConfirmLoad", "Load this data?"), true);
DisplayButtons(DS_BUTTON_OK | DS_BUTTON_CANCEL);
DisplayBanner(DB_LOAD);
DisplayEnterBack();
if (IsButtonPressed(cancelButtonFlag) || (IsButtonPressed(okButtonFlag) && yesnoChoice == 0)) {
param.GetPspParam()->result = SCE_UTILITY_DIALOG_RESULT_CANCEL;
param.GetPspParam()->common.result = SCE_UTILITY_DIALOG_RESULT_CANCEL;
StartFade(false);
} else if (IsButtonPressed(okButtonFlag)) {
display = DS_LOAD_LOADING;
if (param.Load(param.GetPspParam(), GetSelectedSaveDirName(), currentSelectedSave))
display = DS_LOAD_DONE;
else {
param.GetPspParam()->result = SCE_UTILITY_DIALOG_RESULT_CANCEL;
param.GetPspParam()->common.result = SCE_UTILITY_DIALOG_RESULT_CANCEL;
StartFade(false);
}
}
@ -634,7 +702,9 @@ int PSPSaveDialog::Update()
DisplaySaveIcon();
DisplaySaveDataInfo2();
DisplayInfo(d->T("Loading","Loading\nPlease Wait..."));
DisplayMessage(d->T("Loading","Loading\nPlease Wait..."));
DisplayBanner(DB_LOAD);
EndDraw();
break;
@ -643,12 +713,14 @@ int PSPSaveDialog::Update()
DisplaySaveIcon();
DisplaySaveDataInfo2();
DisplayBack();
DisplayInfo(d->T("Load completed"));
DisplayMessage(d->T("Load completed"));
DisplayButtons(DS_BUTTON_CANCEL);
DisplayBanner(DB_LOAD);
if (IsButtonPressed(cancelButtonFlag)) {
param.GetPspParam()->result = SCE_UTILITY_DIALOG_RESULT_SUCCESS;
param.GetPspParam()->common.result = SCE_UTILITY_DIALOG_RESULT_SUCCESS;
// Set the save to use for autosave and autoload
param.SetSelectedSave(param.GetFileInfo(currentSelectedSave).idx);
StartFade(false);
@ -659,12 +731,13 @@ int PSPSaveDialog::Update()
case DS_LOAD_NODATA:
StartDraw();
DisplayBack();
DisplayMessage(d->T("There is no data"));
DisplayInfo(d->T("There is no data"));
DisplayButtons(DS_BUTTON_CANCEL);
DisplayBanner(DB_LOAD);
if (IsButtonPressed(cancelButtonFlag)) {
param.GetPspParam()->result = SCE_UTILITY_SAVEDATA_ERROR_LOAD_NO_DATA;
param.GetPspParam()->common.result = SCE_UTILITY_SAVEDATA_ERROR_LOAD_NO_DATA;
StartFade(false);
}
@ -677,9 +750,11 @@ int PSPSaveDialog::Update()
DisplaySaveList();
DisplaySaveDataInfo1();
DisplayEnterBack();
DisplayButtons(DS_BUTTON_OK | DS_BUTTON_CANCEL);
DisplayBanner(DB_DELETE);
if (IsButtonPressed(cancelButtonFlag)) {
param.GetPspParam()->result = SCE_UTILITY_DIALOG_RESULT_CANCEL;
param.GetPspParam()->common.result = SCE_UTILITY_DIALOG_RESULT_CANCEL;
StartFade(false);
} else if (IsButtonPressed(okButtonFlag)) {
yesnoChoice = 0;
@ -694,9 +769,13 @@ int PSPSaveDialog::Update()
DisplaySaveIcon();
DisplaySaveDataInfo2();
DisplayConfirmationYesNo(d->T("DeleteConfirm", " This save data will be deleted.\nAre you sure you want to continue?"));
DisplayMessage(d->T("DeleteConfirm",
"This save data will be deleted.\nAre you sure you want to continue?"),
true);
DisplayButtons(DS_BUTTON_OK | DS_BUTTON_CANCEL);
DisplayBanner(DB_DELETE);
DisplayEnterBack();
if (IsButtonPressed(cancelButtonFlag))
display = DS_DELETE_LIST_CHOICE;
else if (IsButtonPressed(okButtonFlag)) {
@ -717,16 +796,19 @@ int PSPSaveDialog::Update()
case DS_DELETE_DELETING:
StartDraw();
DisplayInfo(d->T("Deleting","Deleting\nPlease Wait..."));
DisplayMessage(d->T("Deleting","Deleting\nPlease Wait..."));
DisplayBanner(DB_DELETE);
EndDraw();
break;
case DS_DELETE_DONE:
StartDraw();
DisplayBack();
DisplayMessage(d->T("Delete completed"));
DisplayInfo(d->T("Delete completed"));
DisplayButtons(DS_BUTTON_CANCEL);
DisplayBanner(DB_DELETE);
if (IsButtonPressed(cancelButtonFlag)) {
if (param.GetFilenameCount() == 0)
@ -740,12 +822,13 @@ int PSPSaveDialog::Update()
case DS_DELETE_NODATA:
StartDraw();
DisplayBack();
DisplayMessage(d->T("There is no data"));
DisplayInfo(d->T("There is no data"));
DisplayButtons(DS_BUTTON_CANCEL);
DisplayBanner(DB_DELETE);
if (IsButtonPressed(cancelButtonFlag)) {
param.GetPspParam()->result = SCE_UTILITY_SAVEDATA_ERROR_DELETE_NO_DATA;
param.GetPspParam()->common.result = SCE_UTILITY_SAVEDATA_ERROR_DELETE_NO_DATA;
StartFade(false);
}
@ -759,33 +842,33 @@ int PSPSaveDialog::Update()
case SCE_UTILITY_SAVEDATA_TYPE_LOAD: // Only load and exit
case SCE_UTILITY_SAVEDATA_TYPE_AUTOLOAD:
if (param.Load(param.GetPspParam(), GetSelectedSaveDirName(), currentSelectedSave))
param.GetPspParam()->result = 0;
param.GetPspParam()->common.result = 0;
else
param.GetPspParam()->result = SCE_UTILITY_SAVEDATA_ERROR_LOAD_NO_DATA;
param.GetPspParam()->common.result = SCE_UTILITY_SAVEDATA_ERROR_LOAD_NO_DATA;
status = SCE_UTILITY_STATUS_FINISHED;
break;
case SCE_UTILITY_SAVEDATA_TYPE_SAVE: // Only save and exit
case SCE_UTILITY_SAVEDATA_TYPE_AUTOSAVE:
if (param.Save(param.GetPspParam(), GetSelectedSaveDirName()))
param.GetPspParam()->result = 0;
param.GetPspParam()->common.result = 0;
else
param.GetPspParam()->result = SCE_UTILITY_SAVEDATA_ERROR_SAVE_MS_NOSPACE;
param.GetPspParam()->common.result = SCE_UTILITY_SAVEDATA_ERROR_SAVE_MS_NOSPACE;
status = SCE_UTILITY_STATUS_FINISHED;
break;
case SCE_UTILITY_SAVEDATA_TYPE_SIZES:
if (param.GetSizes(param.GetPspParam()))
param.GetPspParam()->result = 0;
param.GetPspParam()->common.result = 0;
else
param.GetPspParam()->result = SCE_UTILITY_SAVEDATA_ERROR_SIZES_NO_DATA;
param.GetPspParam()->common.result = SCE_UTILITY_SAVEDATA_ERROR_SIZES_NO_DATA;
status = SCE_UTILITY_STATUS_FINISHED;
break;
case SCE_UTILITY_SAVEDATA_TYPE_LIST:
param.GetList(param.GetPspParam());
param.GetPspParam()->result = 0;
param.GetPspParam()->common.result = 0;
status = SCE_UTILITY_STATUS_FINISHED;
break;
case SCE_UTILITY_SAVEDATA_TYPE_FILES:
param.GetPspParam()->result = param.GetFilesList(param.GetPspParam());
param.GetPspParam()->common.result = param.GetFilesList(param.GetPspParam());
status = SCE_UTILITY_STATUS_FINISHED;
break;
case SCE_UTILITY_SAVEDATA_TYPE_GETSIZE:
@ -793,11 +876,11 @@ int PSPSaveDialog::Update()
bool result = param.GetSize(param.GetPspParam());
// TODO: According to JPCSP, should test/verify this part but seems edge casey.
if (MemoryStick_State() != PSP_MEMORYSTICK_STATE_DRIVER_READY)
param.GetPspParam()->result = SCE_UTILITY_SAVEDATA_ERROR_RW_NO_MEMSTICK;
param.GetPspParam()->common.result = SCE_UTILITY_SAVEDATA_ERROR_RW_NO_MEMSTICK;
else if (result)
param.GetPspParam()->result = 0;
param.GetPspParam()->common.result = 0;
else
param.GetPspParam()->result = SCE_UTILITY_SAVEDATA_ERROR_RW_NO_DATA;
param.GetPspParam()->common.result = SCE_UTILITY_SAVEDATA_ERROR_RW_NO_DATA;
status = SCE_UTILITY_STATUS_FINISHED;
}
break;
@ -805,40 +888,40 @@ int PSPSaveDialog::Update()
// TODO: This should probably actually delete something.
// For now, always say it couldn't be deleted.
WARN_LOG(HLE, "FAKE sceUtilitySavedata DELETEDATA: %s", param.GetPspParam()->saveName);
param.GetPspParam()->result = SCE_UTILITY_SAVEDATA_ERROR_RW_BAD_STATUS;
param.GetPspParam()->common.result = SCE_UTILITY_SAVEDATA_ERROR_RW_BAD_STATUS;
status = SCE_UTILITY_STATUS_FINISHED;
break;
//case SCE_UTILITY_SAVEDATA_TYPE_AUTODELETE:
case SCE_UTILITY_SAVEDATA_TYPE_SINGLEDELETE:
if (param.Delete(param.GetPspParam(), param.GetSelectedSave()))
param.GetPspParam()->result = 0;
param.GetPspParam()->common.result = 0;
else
param.GetPspParam()->result = SCE_UTILITY_SAVEDATA_ERROR_DELETE_NO_DATA;
param.GetPspParam()->common.result = SCE_UTILITY_SAVEDATA_ERROR_DELETE_NO_DATA;
status = SCE_UTILITY_STATUS_FINISHED;
break;
// TODO: Should reset the directory's other files.
case SCE_UTILITY_SAVEDATA_TYPE_MAKEDATA:
case SCE_UTILITY_SAVEDATA_TYPE_MAKEDATASECURE:
if (param.Save(param.GetPspParam(), GetSelectedSaveDirName(), param.GetPspParam()->mode == SCE_UTILITY_SAVEDATA_TYPE_MAKEDATASECURE))
param.GetPspParam()->result = 0;
param.GetPspParam()->common.result = 0;
else
param.GetPspParam()->result = SCE_UTILITY_SAVEDATA_ERROR_RW_NO_DATA;
param.GetPspParam()->common.result = SCE_UTILITY_SAVEDATA_ERROR_RW_NO_DATA;
status = SCE_UTILITY_STATUS_FINISHED;
break;
case SCE_UTILITY_SAVEDATA_TYPE_WRITEDATA:
case SCE_UTILITY_SAVEDATA_TYPE_WRITEDATASECURE:
if (param.Save(param.GetPspParam(), GetSelectedSaveDirName(), param.GetPspParam()->mode == SCE_UTILITY_SAVEDATA_TYPE_WRITEDATASECURE))
param.GetPspParam()->result = 0;
param.GetPspParam()->common.result = 0;
else
param.GetPspParam()->result = SCE_UTILITY_SAVEDATA_ERROR_RW_NO_DATA;
param.GetPspParam()->common.result = SCE_UTILITY_SAVEDATA_ERROR_RW_NO_DATA;
status = SCE_UTILITY_STATUS_FINISHED;
break;
case SCE_UTILITY_SAVEDATA_TYPE_READDATA:
case SCE_UTILITY_SAVEDATA_TYPE_READDATASECURE:
if (param.Load(param.GetPspParam(), GetSelectedSaveDirName(), currentSelectedSave, param.GetPspParam()->mode == SCE_UTILITY_SAVEDATA_TYPE_READDATASECURE))
param.GetPspParam()->result = 0;
param.GetPspParam()->common.result = 0;
else
param.GetPspParam()->result = SCE_UTILITY_SAVEDATA_ERROR_RW_NO_DATA; // not sure if correct code
param.GetPspParam()->common.result = SCE_UTILITY_SAVEDATA_ERROR_RW_NO_DATA; // not sure if correct code
status = SCE_UTILITY_STATUS_FINISHED;
break;
default:
@ -855,7 +938,7 @@ int PSPSaveDialog::Update()
lastButtons = buttons;
if (status == SCE_UTILITY_STATUS_FINISHED)
Memory::Memcpy(requestAddr,&request,request.size);
Memory::Memcpy(requestAddr,&request,request.common.size);
return 0;
}
@ -885,9 +968,10 @@ void PSPSaveDialog::DoState(PointerWrap &p)
p.Do(requestAddr);
p.Do(currentSelectedSave);
p.Do(yesnoChoice);
p.Do(okButtonImg);
p.Do(cancelButtonImg);
p.Do(okButtonFlag);
p.Do(cancelButtonFlag);
p.DoMarker("PSPSaveDialog");
}
pspUtilityDialogCommon *PSPSaveDialog::GetCommonParam()
{
return &param.GetPspParam()->common;
}

View File

@ -71,18 +71,17 @@ public:
virtual int Update();
virtual int Shutdown(bool force = false);
virtual void DoState(PointerWrap &p);
virtual pspUtilityDialogCommon *GetCommonParam();
private :
void DisplayBanner(int which);
void DisplaySaveList(bool canMove = true);
void DisplaySaveIcon();
void DisplayTitle(std::string name);
void DisplayEnterBack();
void DisplayBack();
void DisplaySaveDataInfo1();
void DisplaySaveDataInfo2();
void DisplayConfirmationYesNo(std::string text);
void DisplayInfo(std::string text);
void DisplayMessage(std::string text, bool hasYesNo = false);
const std::string GetSelectedSaveDirName();
enum DisplayState
@ -108,6 +107,14 @@ private :
DS_DELETE_NODATA
};
enum DialogBanner
{
DB_NONE,
DB_SAVE,
DB_LOAD,
DB_DELETE
};
DisplayState display;
SavedataParam param;
@ -116,10 +123,5 @@ private :
int currentSelectedSave;
int yesnoChoice;
int okButtonImg;
int cancelButtonImg;
int okButtonFlag;
int cancelButtonFlag;
};

View File

@ -1305,7 +1305,7 @@ int SavedataParam::GetFirstDataSave()
{
if (saveDataList[i].size != 0)
{
idx = i;;
idx = i;
break;
}
}

View File

@ -20,6 +20,7 @@
#include "Core/HLE/sceKernel.h"
#include "Core/HLE/sceRtc.h"
#include "Core/System.h"
#include "Core/Dialog/PSPDialog.h"
#undef st_ctime
#undef st_atime
#undef st_mtime
@ -54,10 +55,10 @@ enum SceUtilitySavedataType
enum SceUtilitySavedataFocus
{
SCE_UTILITY_SAVEDATA_FOCUS_NAME = 0, // specified by saveName[]
SCE_UTILITY_SAVEDATA_FOCUS_FIRSTLIST = 1, // first listed (on screen or of all)?
SCE_UTILITY_SAVEDATA_FOCUS_LASTLIST = 2, // last listed (on screen or of all)?
SCE_UTILITY_SAVEDATA_FOCUS_FIRSTLIST = 1, // first listed (on screen or of all?)
SCE_UTILITY_SAVEDATA_FOCUS_LASTLIST = 2, // last listed (on screen or of all?)
SCE_UTILITY_SAVEDATA_FOCUS_LATEST = 3, // latest by modification date (first if none)
SCE_UTILITY_SAVEDATA_FOCUS_OLDEST = 4, // doldest by modification date (first if none)
SCE_UTILITY_SAVEDATA_FOCUS_OLDEST = 4, // oldest by modification date (first if none)
SCE_UTILITY_SAVEDATA_FOCUS_FIRSTDATA = 5, // first non-empty (first if none)
SCE_UTILITY_SAVEDATA_FOCUS_LASTDATA = 6, // last non-empty (first if none)
SCE_UTILITY_SAVEDATA_FOCUS_FIRSTEMPTY = 7, // first empty (what if no empty?)
@ -130,15 +131,7 @@ struct SceUtilitySavedataFileListInfo
// Structure to hold the parameters for the sceUtilitySavedataInitStart function.
struct SceUtilitySavedataParam
{
SceSize size; // Size of the structure
int language;
int buttonSwap;
int unknown[4];
int result;
int unknown2[4];
pspUtilityDialogCommon common;
int mode; // 0 to load, 1 to save
int bind;

View File

@ -55,11 +55,36 @@ static u32 dataSize = 0x10000; // should be enough for a frame of gui...
static u32 palettePtr;
static u32 paletteSize = 2 * 16;
// Vertex collector
static u32 vertexStart;
static u32 vertexCount;
// Used for formating text
struct AtlasCharVertex
{
float x;
float y;
const AtlasChar *c;
};
struct AtlasTextMetrics
{
float x;
float y;
float maxWidth;
float lineHeight;
float scale;
int numLines;
};
typedef std::vector<AtlasCharVertex> AtlasCharLine;
typedef std::vector<AtlasCharLine> AtlasLineArray;
static AtlasCharLine char_one_line;
static AtlasLineArray char_lines;
static AtlasTextMetrics char_lines_metrics;
//only 0xFFFFFF of data is used
static void WriteCmd(u8 cmd, u32 data) {
Memory::Write_U32((cmd << 24) | (data & 0xFFFFFF), dlWritePtr);
@ -184,6 +209,9 @@ void __PPGeDoState(PointerWrap &p)
p.Do(vertexStart);
p.Do(vertexCount);
p.Do(char_lines);
p.Do(char_lines_metrics);
p.DoMarker("PPGeDraw");
}
@ -298,80 +326,6 @@ static const AtlasChar *PPGeGetChar(const AtlasFont &atlasfont, unsigned int cva
return c;
}
static void PPGeMeasureText(const char *text, float scale, float *w, float *h) {
const AtlasFont &atlasfont = *ppge_atlas.fonts[0];
unsigned int cval;
float wacc = 0;
float maxw = 0;
int lines = 1;
UTF8 utf(text);
while (true) {
if (utf.end())
break;
cval = utf.next();
if (cval == '\n') {
if (wacc > maxw) maxw = wacc;
wacc = 0;
lines++;
}
const AtlasChar *c = PPGeGetChar(atlasfont, cval);
if (c) {
wacc += c->wx * scale;
}
}
if (wacc > maxw) maxw = wacc;
if (w) *w = maxw;
if (h) *h = atlasfont.height * scale * lines;
}
static void PPGeDoAlign(int flags, float *x, float *y, float *w, float *h) {
if (flags & PPGE_ALIGN_HCENTER) *x -= *w / 2;
if (flags & PPGE_ALIGN_RIGHT) *x -= *w;
if (flags & PPGE_ALIGN_VCENTER) *y -= *h / 2;
if (flags & PPGE_ALIGN_BOTTOM) *y -= *h;
}
// Draws some text using the one font we have.
// Mostly stolen from DrawBuffer.
void PPGeDrawText(const char *text, float x, float y, int align, float scale, u32 color) {
if (!dlPtr)
return;
const AtlasFont &atlasfont = *ppge_atlas.fonts[0];
unsigned int cval;
float w, h;
PPGeMeasureText(text, scale, &w, &h);
if (align) {
PPGeDoAlign(align, &x, &y, &w, &h);
}
BeginVertexData();
y += atlasfont.ascend*scale;
float sx = x;
UTF8 utf(text);
while (true) {
if (utf.end())
break;
cval = utf.next();
if (cval == '\n') {
// This is not correct when centering or right-justifying, need to set x depending on line width (tricky)
y += atlasfont.height * scale;
x = sx;
continue;
}
const AtlasChar *ch = PPGeGetChar(atlasfont, cval);
if (ch) {
const AtlasChar &c = *ch;
float cx1 = x + c.ox * scale;
float cy1 = y + c.oy * scale;
float cx2 = x + (c.ox + c.pw) * scale;
float cy2 = y + (c.oy + c.ph) * scale;
Vertex(cx1, cy1, c.sx, c.sy, atlasWidth, atlasHeight, color);
Vertex(cx2, cy2, c.ex, c.ey, atlasWidth, atlasHeight, color);
x += c.wx * scale;
}
}
EndVertexDataAndDraw(GE_PRIM_RECTANGLES);
}
static float NextWordWidth(UTF8 utf, const AtlasFont &atlasfont, float scale) {
float w = 0.0;
bool finished = false;
@ -418,64 +372,183 @@ static float NextWordWidth(UTF8 utf, const AtlasFont &atlasfont, float scale) {
return w;
}
void PPGeDrawTextWrapped(const char *text, float x, float y, float wrapWidth, int align, float scale, u32 color) {
if (!dlPtr)
return;
// Break a single text string into mutiple lines.
static AtlasTextMetrics BreakLines(const char *text, const AtlasFont &atlasfont, float x, float y,
int align, float scale, int wrapType, float wrapWidth, bool dryRun)
{
y += atlasfont.ascend * scale;
float sx = x, sy = y;
// TODO: Can we wrap it smartly on the screen edge?
if (wrapWidth <= 0) {
wrapWidth = 480.f;
}
// used for replacing with ellipsis
float wrapCutoff = 8.0f;
const AtlasChar *dot = PPGeGetChar(atlasfont, '.');
if (dot) {
wrapCutoff = dot->wx * scale * 3.0f;
}
//const float wrapGreyZone = 2.0f; // Grey zone for punctuations at line ends
int numLines = 1;
float maxw = 0;
float lineHeight = atlasfont.height * scale;
for (UTF8 utf(text); !utf.end(); )
{
float lineWidth = 0;
while (!utf.end())
{
uint32_t cval = utf.next();
if (cval == '\n') {
++numLines;
break;
}
if (cval == '\r') {
// We simply ignore this.
continue;
}
const AtlasChar *c = PPGeGetChar(atlasfont, cval);
if (c)
{
if (wrapType > 0)
{
float nextWidth = NextWordWidth(utf, atlasfont, scale);
if (lineWidth + nextWidth > wrapWidth) {
if (wrapType & PPGE_LINE_WRAP_WORD) {
// TODO: Should check if we have had at least one other word instead.
if (lineWidth > 0) {
++numLines;
break;
}
}
if (wrapType & PPGE_LINE_USE_ELLIPSIS) {
if (nextWidth >= wrapCutoff) {
// TODO: Truncate the word with an ellipsis.
// The word is not too short.
}
}
}
}
if (!dryRun)
{
AtlasCharVertex cv;
cv.x = x + c->ox * scale;
cv.y = y + c->oy * scale;
cv.c = c;
char_one_line.push_back(cv);
}
float ww = c->wx * scale;
lineWidth += ww;
x += ww;
}
}
y += lineHeight;
x = sx;
if (lineWidth > maxw) {
maxw = lineWidth;
}
if (!dryRun)
{
char_lines.push_back(char_one_line);
char_one_line.clear();
}
}
const float w = maxw;
const float h = (float)numLines * lineHeight;
if (align)
{
if (!dryRun)
{
for (auto i = char_lines.begin(); i != char_lines.end(); ++i)
{
for (auto j = i->begin(); j != i->end(); ++j)
{
if (align & PPGE_ALIGN_HCENTER) j->x -= w / 2.0f;
else if (align & PPGE_ALIGN_RIGHT) j->x -= w;
if (align & PPGE_ALIGN_VCENTER) j->y -= h / 2.0f;
else if (align & PPGE_ALIGN_BOTTOM) j->y -= h;
}
}
}
if (align & PPGE_ALIGN_HCENTER) sx -= w / 2.0f;
else if (align & PPGE_ALIGN_RIGHT) sx -= w;
if (align & PPGE_ALIGN_VCENTER) sy -= h / 2.0f;
else if (align & PPGE_ALIGN_BOTTOM) sy -= h;
}
AtlasTextMetrics metrics = { sx, sy, w, lineHeight, scale, numLines };
return metrics;
}
void PPGeMeasureText(float *w, float *h, int *n,
const char *text, float scale, int WrapType, int wrapWidth)
{
const AtlasFont &atlasfont = *ppge_atlas.fonts[0];
unsigned int cval;
float w, h;
// TODO: Could ideally try to handle center, right align better.
PPGeMeasureText(text, scale, &w, &h);
if (align && w < wrapWidth) {
PPGeDoAlign(align, &x, &y, &w, &h);
}
BeginVertexData();
y += atlasfont.ascend*scale;
float sx = x;
bool skipWrap = false;
const float wrapCutoff = wrapWidth * 0.8f;
UTF8 utf(text);
while (true) {
if (utf.end())
break;
cval = utf.next();
if (cval == '\n') {
// This is not correct when centering or right-justifying, need to set x depending on line width (tricky)
y += atlasfont.height * scale;
x = sx;
skipWrap = false;
continue;
}
const AtlasChar *ch = PPGeGetChar(atlasfont, cval);
if (ch) {
const AtlasChar &c = *ch;
float cx1 = x + c.ox * scale;
float cy1 = y + c.oy * scale;
float cx2 = x + (c.ox + c.pw) * scale;
float cy2 = y + (c.oy + c.ph) * scale;
Vertex(cx1, cy1, c.sx, c.sy, atlasWidth, atlasHeight, color);
Vertex(cx2, cy2, c.ex, c.ey, atlasWidth, atlasHeight, color);
x += c.wx * scale;
AtlasTextMetrics metrics = BreakLines(text, atlasfont, 0, 0, 0, scale, WrapType, wrapWidth, true);
if (w) *w = metrics.maxWidth;
if (h) *h = metrics.lineHeight;
if (n) *n = metrics.numLines;
}
float nextWidth = NextWordWidth(utf, atlasfont, scale);
// This word is too long, and we're not near the end of the line.
if (nextWidth > wrapCutoff && wrapWidth + sx - x > wrapCutoff) {
skipWrap = true;
}
// Pretend the word is only a single character long.
if (skipWrap) {
nextWidth = c.wx * scale;
}
void PPGePrepareText(const char *text, float x, float y, int align, float scale, int WrapType, int wrapWidth)
{
const AtlasFont &atlasfont = *ppge_atlas.fonts[0];
char_lines_metrics = BreakLines(text, atlasfont, x, y, align, scale, WrapType, wrapWidth, false);
}
if (x + nextWidth > wrapWidth) {
// This is not correct when centering or right-justifying, need to set x depending on line width (tricky)
y += atlasfont.height * scale;
x = sx;
skipWrap = false;
void PPGeMeasureCurrentText(float *x, float *y, float *w, float *h, int *n)
{
if (x) *x = char_lines_metrics.x;
if (y) *y = char_lines_metrics.y;
if (w) *w = char_lines_metrics.maxWidth;
if (h) *h = char_lines_metrics.lineHeight;
if (n) *n = char_lines_metrics.numLines;
}
// Draws some text using the one font we have.
// Mostly rewritten.
void PPGeDrawCurrentText(u32 color)
{
if (dlPtr)
{
float scale = char_lines_metrics.scale;
BeginVertexData();
for (auto i = char_lines.cbegin(); i != char_lines.cend(); ++i)
{
for (auto j = i->cbegin(); j != i->cend(); ++j)
{
float cx1 = j->x;
float cy1 = j->y;
const AtlasChar &c = *j->c;
float cx2 = cx1 + c.pw * scale;
float cy2 = cy1 + c.ph * scale;
Vertex(cx1, cy1, c.sx, c.sy, atlasWidth, atlasHeight, color);
Vertex(cx2, cy2, c.ex, c.ey, atlasWidth, atlasHeight, color);
}
}
EndVertexDataAndDraw(GE_PRIM_RECTANGLES);
}
EndVertexDataAndDraw(GE_PRIM_RECTANGLES);
char_one_line.clear();
char_lines.clear();
AtlasTextMetrics zeroBox = { 0 };
char_lines_metrics = zeroBox;
}
void PPGeDrawText(const char *text, float x, float y, int align, float scale, u32 color)
{
PPGePrepareText(text, x, y, align, scale, PPGE_LINE_USE_ELLIPSIS);
PPGeDrawCurrentText(color);
}
void PPGeDrawTextWrapped(const char *text, float x, float y, float wrapWidth, int align, float scale, u32 color)
{
PPGePrepareText(text, x, y, align, scale, PPGE_LINE_USE_ELLIPSIS | PPGE_LINE_WRAP_WORD, wrapWidth);
PPGeDrawCurrentText(color);
}
// Draws a "4-patch" for button-like things that can be resized

View File

@ -41,7 +41,6 @@ void __PPGeShutdown();
void PPGeBegin();
void PPGeEnd();
// If you want to draw using this texture but not go through the PSP GE emulation,
// jsut call this. Will bind the texture to unit 0.
void PPGeBindTexture();
@ -62,13 +61,41 @@ enum {
PPGE_ALIGN_BOTTOMRIGHT = PPGE_ALIGN_BOTTOM | PPGE_ALIGN_RIGHT,
};
enum {
PPGE_ESCAPE_NONE,
PPGE_ESCAPE_BACKSLASHED,
};
enum {
PPGE_LINE_NONE = 0,
PPGE_LINE_USE_ELLIPSIS = 1, // use ellipses in too long words
PPGE_LINE_WRAP_WORD = 2,
PPGE_LINE_WRAP_CHAR = 4,
};
// Get the metrics of the bounding box of the text without changing the buffer or state.
void PPGeMeasureText(float *w, float *h, int *n,
const char *text, float scale, int WrapType = PPGE_LINE_NONE, int wrapWidth = 0);
// Overwrite the current text lines buffer so it can be drawn later.
void PPGePrepareText(const char *text, float x, float y, int align, float scale,
int WrapType = PPGE_LINE_NONE, int wrapWidth = 0);
// Get the metrics of the bounding box of the currently stated text.
void PPGeMeasureCurrentText(float *x, float *y, float *w, float *h, int *n);
// These functions must be called between PPGeBegin and PPGeEnd.
// Draw currently buffered text using the state from PPGeGetTextBoundingBox() call.
// Clears the buffer and state when done.
void PPGeDrawCurrentText(u32 color = 0xFFFFFFFF);
// Draws some text using the one font we have.
// Clears the text buffer when done.
void PPGeDrawText(const char *text, float x, float y, int align, float scale = 1.0f, u32 color = 0xFFFFFFFF);
void PPGeDrawTextWrapped(const char *text, float x, float y, float wrapWidth, int align, float scale = 1.0f, u32 color = 0xFFFFFFFF);
// Draws a "4-patch" for button-like things that can be resized
// Draws a "4-patch" for button-like things that can be resized.
void PPGeDraw4Patch(int atlasImage, float x, float y, float w, float h, u32 color = 0xFFFFFFFF);
// Just blits an image to the screen, multiplied with the color.

2
lang

@ -1 +1 @@
Subproject commit a2f8b62322a1d0551d965f22ca6dab7d8dab8a27
Subproject commit bbadce3313a26df53366019e9b7b9bf9b38fd7b7