mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-01 14:58:14 +00:00
Deduplicate some code, fix some style
This commit is contained in:
1 parent
f2d8d44513
commit
ca54fe9234
8 files changed
+159
-338
No files matched your search
@@ -52,13 +52,6 @@ struct ScanInfos {
|
||||
SceNetAdhocctlScanInfoEmu si;
|
||||
} PACK;
|
||||
|
||||
|
||||
PSPNetconfDialog::PSPNetconfDialog(UtilityDialogType type) : PSPDialog(type) {
|
||||
}
|
||||
|
||||
PSPNetconfDialog::~PSPNetconfDialog() {
|
||||
}
|
||||
|
||||
int PSPNetconfDialog::Init(u32 paramAddr) {
|
||||
// Already running
|
||||
if (ReadStatus() != SCE_UTILITY_STATUS_NONE)
|
||||
@@ -86,7 +79,6 @@ int PSPNetconfDialog::Init(u32 paramAddr) {
|
||||
}
|
||||
|
||||
void PSPNetconfDialog::DrawBanner() {
|
||||
|
||||
PPGeDrawRect(0, 0, 480, 22, CalcFadedColor(0x65636358));
|
||||
|
||||
PPGeStyle textStyle = FadedStyle(PPGeAlign::BOX_VCENTER, 0.6f);
|
||||
@@ -103,134 +95,6 @@ void PSPNetconfDialog::DrawIndicator() {
|
||||
PPGeDrawImage(456, 248, 20.0f, 20.0f, 1, 10, 1, 10, 10, 10, FadedImageStyle());
|
||||
}
|
||||
|
||||
void PSPNetconfDialog::DisplayMessage(std::string_view text1, std::string_view text2a, std::string_view text2b, std::string_view text3a, std::string_view text3b, bool hasYesNo, bool hasOK) {
|
||||
auto di = GetI18NCategory(I18NCat::DIALOG);
|
||||
|
||||
PPGeStyle buttonStyle = FadedStyle(PPGeAlign::BOX_CENTER, FONT_SCALE);
|
||||
PPGeStyle messageStyle = FadedStyle(PPGeAlign::BOX_HCENTER, FONT_SCALE);
|
||||
PPGeStyle messageStyleRight = FadedStyle(PPGeAlign::BOX_RIGHT, FONT_SCALE);
|
||||
PPGeStyle messageStyleLeft = FadedStyle(PPGeAlign::BOX_LEFT, FONT_SCALE);
|
||||
|
||||
std::string text2 = std::string(text2a) + " " + std::string(text2b);
|
||||
std::string text3 = std::string(text3a) + " " + std::string(text3b);
|
||||
|
||||
// Without the scrollbar, we have 350 total pixels.
|
||||
float WRAP_WIDTH = 300.0f;
|
||||
if (UTF8StringNonASCIICount(text1) >= (int)text1.size() / 4) {
|
||||
WRAP_WIDTH = 336.0f;
|
||||
if (text1.size() > 12) {
|
||||
messageStyle.scale = 0.6f;
|
||||
}
|
||||
}
|
||||
|
||||
float totalHeight1 = 0.0f;
|
||||
PPGeMeasureText(nullptr, &totalHeight1, text1, FONT_SCALE, PPGE_LINE_WRAP_WORD, WRAP_WIDTH);
|
||||
float totalHeight2 = 0.0f;
|
||||
if (text2 != " ")
|
||||
PPGeMeasureText(nullptr, &totalHeight2, text2, FONT_SCALE, PPGE_LINE_USE_ELLIPSIS, WRAP_WIDTH);
|
||||
float totalHeight3 = 0.0f;
|
||||
if (text3 != " ")
|
||||
PPGeMeasureText(nullptr, &totalHeight3, text3, FONT_SCALE, PPGE_LINE_USE_ELLIPSIS, WRAP_WIDTH);
|
||||
float marginTop = 0.0f;
|
||||
if (text2 != " " || text3 != " ")
|
||||
marginTop = 11.0f;
|
||||
float totalHeight = totalHeight1 + totalHeight2 + totalHeight3 + marginTop;
|
||||
// The PSP normally only shows about 8 lines at a time.
|
||||
// For improved UX, we intentionally show part of the next line.
|
||||
float visibleHeight = std::min(totalHeight, 175.0f);
|
||||
float h2 = visibleHeight / 2.0f;
|
||||
|
||||
float centerY = 135.0f;
|
||||
float sy = centerY - h2 - 15.0f;
|
||||
float ey = centerY + h2 + 20.0f;
|
||||
float buttonY = centerY + h2 + 5.0f;
|
||||
|
||||
auto drawSelectionBoxAndAdjust = [&](float x) {
|
||||
// Box has a fixed size.
|
||||
float w = 15.0f;
|
||||
float h = 8.0f;
|
||||
PPGeDrawRect(x - w, buttonY - h, x + w, buttonY + h, CalcFadedColor(0x6DCFCFCF));
|
||||
|
||||
centerY -= h + 5.0f;
|
||||
sy -= h + 5.0f;
|
||||
ey = buttonY + h * 2.0f + 5.0f;
|
||||
};
|
||||
|
||||
if (hasYesNo) {
|
||||
if (yesnoChoice == 1) {
|
||||
drawSelectionBoxAndAdjust(204.0f);
|
||||
}
|
||||
else {
|
||||
drawSelectionBoxAndAdjust(273.0f);
|
||||
}
|
||||
|
||||
PPGeDrawText(di->T("Yes"), 203.0f, buttonY - 1.0f, buttonStyle);
|
||||
PPGeDrawText(di->T("No"), 272.0f, buttonY - 1.0f, buttonStyle);
|
||||
if (IsButtonPressed(CTRL_LEFT) && yesnoChoice == 0) {
|
||||
yesnoChoice = 1;
|
||||
}
|
||||
else if (IsButtonPressed(CTRL_RIGHT) && yesnoChoice == 1) {
|
||||
yesnoChoice = 0;
|
||||
}
|
||||
buttonY += 8.0f + 5.0f;
|
||||
}
|
||||
|
||||
if (hasOK) {
|
||||
drawSelectionBoxAndAdjust(240.0f);
|
||||
|
||||
PPGeDrawText(di->T("OK"), 239.0f, buttonY - 1.0f, buttonStyle);
|
||||
buttonY += 8.0f + 5.0f;
|
||||
}
|
||||
|
||||
PPGeScissor(0, (int)(centerY - h2 - 2), 480, (int)(centerY + h2 + 2));
|
||||
PPGeDrawTextWrapped(text1, 240.0f, centerY - h2 - scrollPos_, WRAP_WIDTH, 0, messageStyle);
|
||||
if (!text2a.empty()) {
|
||||
if (!text2b.empty())
|
||||
PPGeDrawTextWrapped(text2a, 240.0f - 5.0f, centerY - h2 - scrollPos_ + totalHeight1 + marginTop, WRAP_WIDTH, 0, messageStyleRight);
|
||||
else
|
||||
PPGeDrawTextWrapped(text2a, 240.0f, centerY - h2 - scrollPos_ + totalHeight1 + marginTop, WRAP_WIDTH, 0, messageStyle);
|
||||
}
|
||||
if (!text2b.empty())
|
||||
PPGeDrawTextWrapped(text2b, 240.0f + 5.0f, centerY - h2 - scrollPos_ + totalHeight1 + marginTop, WRAP_WIDTH, 0, messageStyleLeft);
|
||||
if (!text3a.empty()) {
|
||||
if (!text3b.empty())
|
||||
PPGeDrawTextWrapped(text3a, 240.0f - 5.0f, centerY - h2 - scrollPos_ + totalHeight1 + totalHeight2 + marginTop, WRAP_WIDTH, 0, messageStyleRight);
|
||||
else
|
||||
PPGeDrawTextWrapped(text3a, 240.0f, centerY - h2 - scrollPos_ + totalHeight1 + totalHeight2 + marginTop, WRAP_WIDTH, 0, messageStyle);
|
||||
}
|
||||
if (!text3b.empty())
|
||||
PPGeDrawTextWrapped(text3b, 240.0f + 5.0f, centerY - h2 - scrollPos_ + totalHeight1 + totalHeight2 + marginTop, WRAP_WIDTH, 0, messageStyleLeft);
|
||||
PPGeScissorReset();
|
||||
|
||||
// Do we need a scrollbar?
|
||||
if (visibleHeight < totalHeight) {
|
||||
float scrollSpeed = 5.0f;
|
||||
float scrollMax = totalHeight - visibleHeight;
|
||||
|
||||
float bobHeight = (visibleHeight / totalHeight) * visibleHeight;
|
||||
float bobOffset = (scrollPos_ / scrollMax) * (visibleHeight - bobHeight);
|
||||
float bobY1 = centerY - h2 + bobOffset;
|
||||
PPGeDrawRect(415.0f, bobY1, 420.0f, bobY1 + bobHeight, CalcFadedColor(0xFFCCCCCC));
|
||||
|
||||
auto buttonDown = [this](int btn, int& held) {
|
||||
if (IsButtonPressed(btn)) {
|
||||
held = 0;
|
||||
return true;
|
||||
}
|
||||
return IsButtonHeld(btn, held, 1, 1);
|
||||
};
|
||||
if (buttonDown(CTRL_DOWN, framesDownHeld_) && scrollPos_ < scrollMax) {
|
||||
scrollPos_ = std::min(scrollMax, scrollPos_ + scrollSpeed);
|
||||
}
|
||||
if (buttonDown(CTRL_UP, framesUpHeld_) && scrollPos_ > 0.0f) {
|
||||
scrollPos_ = std::max(0.0f, scrollPos_ - scrollSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
PPGeDrawRect(60.0f, sy, 420.0f, sy + 1.0f, CalcFadedColor(0xFFFFFFFF));
|
||||
PPGeDrawRect(60.0f, ey, 420.0f, ey + 1.0f, CalcFadedColor(0xFFFFFFFF));
|
||||
}
|
||||
|
||||
int PSPNetconfDialog::Update(int animSpeed) {
|
||||
if (ReadStatus() != SCE_UTILITY_STATUS_RUNNING) {
|
||||
return SCE_ERROR_UTILITY_INVALID_STATUS;
|
||||
@@ -283,18 +147,16 @@ int PSPNetconfDialog::Update(int animSpeed) {
|
||||
hideNotice = true;
|
||||
StartFade(true);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
PPGeDrawRect(0, 0, 480, 272, CalcFadedColor(0xC0C8B2AC));
|
||||
DrawBanner();
|
||||
DrawIndicator();
|
||||
|
||||
if (state == PSP_NET_APCTL_STATE_GOT_IP || state == PSP_NET_APCTL_STATE_GETTING_IP) {
|
||||
DisplayMessage(di->T("ObtainingIP", "Obtaining IP address.\nPlease wait..."), di->T("ConnectionName", "Connection Name"), netApctlInfo.name, di->T("SSID"), netApctlInfo.ssid);
|
||||
}
|
||||
else {
|
||||
DisplayMessage2(di->T("ObtainingIP", "Obtaining IP address.\nPlease wait..."), di->T("ConnectionName", "Connection Name"), netApctlInfo.name, di->T("SSID"), netApctlInfo.ssid);
|
||||
} else {
|
||||
// Skipping the Select Connection screen since we only have 1 fake profile
|
||||
DisplayMessage(di->T("ConnectingAP", "Connecting to the access point.\nPlease wait..."), di->T("ConnectionName", "Connection Name"), netApctlInfo.name, di->T("SSID"), netApctlInfo.ssid);
|
||||
DisplayMessage2(di->T("ConnectingAP", "Connecting to the access point.\nPlease wait..."), di->T("ConnectionName", "Connection Name"), netApctlInfo.name, di->T("SSID"), netApctlInfo.ssid);
|
||||
}
|
||||
DisplayButtons(DS_BUTTON_CANCEL, di->T("Cancel"));
|
||||
|
||||
@@ -334,7 +196,7 @@ int PSPNetconfDialog::Update(int animSpeed) {
|
||||
if (timedout) {
|
||||
// FIXME: Do we need to show error message?
|
||||
std::string message(di->T("InternalError", "An internal error has occurred."));
|
||||
DisplayMessage(message + StringFromFormat("\n(%08X)", connResult));
|
||||
DisplayMessage2(message + StringFromFormat("\n(%08X)", connResult));
|
||||
DisplayButtons(DS_BUTTON_CANCEL, di->T("Back"));
|
||||
}
|
||||
else {
|
||||
@@ -342,7 +204,7 @@ int PSPNetconfDialog::Update(int animSpeed) {
|
||||
if (g_Config.iWlanAdhocChannel == PSP_SYSTEMPARAM_ADHOC_CHANNEL_AUTOMATIC)
|
||||
channel = "Automatic";
|
||||
|
||||
DisplayMessage(di->T("ConnectingPleaseWait", "Connecting.\nPlease wait..."), std::string(di->T("Channel:")) + std::string(" ") + std::string(di->T(channel)));
|
||||
DisplayMessage2(di->T("ConnectingPleaseWait", "Connecting.\nPlease wait..."), std::string(di->T("Channel:")) + std::string(" ") + std::string(di->T(channel)));
|
||||
|
||||
// Only Join mode is showing Cancel button on KHBBS and the button will fade out before the dialog is fading out, probably because it's already connected thus can't be canceled anymore
|
||||
if (request.netAction == NETCONF_JOIN_ADHOC)
|
||||
|
||||
Reference in new issue
Block a user