From 22ebe76f336f937e5f949d464ead6d42d1a90c52 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Fri, 16 Aug 2013 16:48:43 +0200 Subject: [PATCH] Move KeyMapping UI to its own file before rewriting. Plus some minor tweaks and fixes. --- CMakeLists.txt | 1 + Common/KeyMap.cpp | 3 + GPU/GLES/DisplayListInterpreter.cpp | 2 - UI/ControlMappingScreen.cpp | 245 +++++++++++++++++ UI/ControlMappingScreen.h | 59 +++++ UI/GameSettingsScreen.cpp | 8 +- UI/Header.h | 0 UI/MainScreen.cpp | 4 +- UI/MenuScreens.cpp | 395 ++++++---------------------- UI/MenuScreens.h | 50 +--- UI/MiscScreens.cpp | 8 +- UI/NativeApp.cpp | 16 +- UI/UI.vcxproj | 3 + UI/UI.vcxproj.filters | 9 + android/jni/Android.mk | 1 + native | 2 +- 16 files changed, 434 insertions(+), 372 deletions(-) create mode 100644 UI/ControlMappingScreen.cpp create mode 100644 UI/ControlMappingScreen.h create mode 100644 UI/Header.h diff --git a/CMakeLists.txt b/CMakeLists.txt index cfc00885ea..27162bd884 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1118,6 +1118,7 @@ set(NativeAppSource UI/UIShader.cpp UI/OnScreenDisplay.cpp UI/PluginScreen.cpp + UI/ControlMappingScreen.cpp UI/ui_atlas.cpp) if(ANDROID) set(NativeAppSource ${NativeAppSource} android/jni/ArmEmitterTest.cpp) diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index d84f3056f0..f40fa81710 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -427,6 +427,9 @@ const KeyMap_IntStrPair axis_names[] = { {JOYSTICK_AXIS_TILT, "Tilt"}, {JOYSTICK_AXIS_MOUSE_REL_X, "MouseDX"}, {JOYSTICK_AXIS_MOUSE_REL_Y, "MouseDY"}, + {JOYSTICK_AXIS_ACCELEROMETER_X, "AccelX"}, + {JOYSTICK_AXIS_ACCELEROMETER_Y, "AccelY"}, + {JOYSTICK_AXIS_ACCELEROMETER_Z, "AccelZ"}, }; static std::string unknown_key_name = "??"; diff --git a/GPU/GLES/DisplayListInterpreter.cpp b/GPU/GLES/DisplayListInterpreter.cpp index edc913f7b1..0c8bb9d811 100644 --- a/GPU/GLES/DisplayListInterpreter.cpp +++ b/GPU/GLES/DisplayListInterpreter.cpp @@ -336,8 +336,6 @@ bool GLES_GPU::FramebufferReallyDirty() { bool dirty = vfb->reallyDirtyAfterDisplay; vfb->reallyDirtyAfterDisplay = false; return dirty; - } else { - ILOG("reallydirty: No display FBO"); } return true; } diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp new file mode 100644 index 0000000000..a312849038 --- /dev/null +++ b/UI/ControlMappingScreen.cpp @@ -0,0 +1,245 @@ +// Copyright (c) 2013- PPSSPP Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0 or later versions. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official git repository and contact information can be found at +// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. + +#include "base/logging.h" +#include "i18n/i18n.h" +#include "input/keycodes.h" +#include "input/input_state.h" +#include "ui/ui.h" +#include "ui/ui_context.h" + +#include "Core/HLE/sceCtrl.h" +#include "Common/KeyMap.h" +#include "Core/Config.h" +#include "UI/ui_atlas.h" +#include "UI/ControlMappingScreen.h" +#include "UI/UIShader.h" + +extern void DrawBackground(float alpha); + +void KeyMappingScreen::update(InputState &input) { + if (input.pad_buttons_down & PAD_BUTTON_BACK) { + g_Config.Save(); + screenManager()->finishDialog(this, DR_OK); + } +} + +void KeyMappingScreen::render() { + UIShader_Prepare(); + UIBegin(UIShader_Get()); + DrawBackground(1.0f); + + UIContext *ctx = screenManager()->getUIContext(); + UIFlush(); + + I18NCategory *keyI18N = GetI18NCategory("KeyMapping"); + I18NCategory *generalI18N = GetI18NCategory("General"); + + +#define KeyBtn(x, y, symbol) \ + if (UIButton(GEN_ID, Pos(x, y), 90, 0, KeyMap::NameKeyFromPspButton(currentMap_, symbol).c_str(), \ + ALIGN_TOPLEFT)) {\ + screenManager()->push(new KeyMappingNewKeyDialog(symbol, currentMap_), 0); \ + UIReset(); \ + } \ + UIText(0, Pos(x+30, y+50), KeyMap::NameDeviceFromPspButton(currentMap_, symbol).c_str(), 0xFFFFFFFF, 0.7f, ALIGN_HCENTER); \ + UIText(0, Pos(x+30, y+80), KeyMap::GetPspButtonName(symbol).c_str(), 0xFFFFFFFF, 0.5f, ALIGN_HCENTER); \ + + + // \ + // UIText(0, Pos(x, y+50), controllerMaps[currentMap_].name.c_str(), 0xFFFFFFFF, 0.5f, ALIGN_HCENTER); + + int pad = 130; + int hlfpad = pad / 2; + + int left = 30; + KeyBtn(left, 30, CTRL_LTRIGGER); + + int top = 120; + KeyBtn(left+hlfpad, top, CTRL_UP); // Up + KeyBtn(left, top+hlfpad, CTRL_LEFT);// Left + KeyBtn(left+pad, top+hlfpad, CTRL_RIGHT); // Right + KeyBtn(left+hlfpad, top+pad, CTRL_DOWN); // Down + + top = 10; + left = 250; + KeyBtn(left+hlfpad, top, VIRTKEY_AXIS_Y_MAX); // Analog Up + KeyBtn(left, top+hlfpad, VIRTKEY_AXIS_X_MIN);// Analog Left + KeyBtn(left+pad, top+hlfpad, VIRTKEY_AXIS_X_MAX); // Analog Right + KeyBtn(left+hlfpad, top+pad, VIRTKEY_AXIS_Y_MIN); // Analog Down + + top = 120; + left = 480; + KeyBtn(left+hlfpad, top, CTRL_TRIANGLE); // Triangle + KeyBtn(left, top+hlfpad, CTRL_SQUARE); // Square + KeyBtn(left+pad, top+hlfpad, CTRL_CIRCLE); // Circle + KeyBtn(left+hlfpad, top+pad, CTRL_CROSS); // Cross + + left = 610; + KeyBtn(left, 30, CTRL_RTRIGGER); + + top += pad + 50; + left = 250; + KeyBtn(left, top, CTRL_SELECT); // Select + KeyBtn(left + pad, top, CTRL_START); //Start + + top = 10; + left = 720; + KeyBtn(left, top, VIRTKEY_UNTHROTTLE); + top += 100; + KeyBtn(left, top, VIRTKEY_SPEED_TOGGLE); + top += 100; + KeyBtn(left, top, VIRTKEY_PAUSE); + top += 100; + KeyBtn(left, top, VIRTKEY_RAPID_FIRE); +#undef KeyBtn + + // TODO: Add rapid fire somewhere? + + if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres - 10), LARGE_BUTTON_WIDTH, 0, generalI18N->T("Back"), ALIGN_RIGHT | ALIGN_BOTTOM)) { + screenManager()->finishDialog(this, DR_OK); + } + + if (UIButton(GEN_ID, Pos(10, dp_yres-10), LARGE_BUTTON_WIDTH, 0, generalI18N->T("Prev"), ALIGN_BOTTOMLEFT)) { + currentMap_--; + if (currentMap_ < 0) + currentMap_ = (int)controllerMaps.size() - 1; + } + if (UIButton(GEN_ID, Pos(10 + 10 + LARGE_BUTTON_WIDTH, dp_yres-10), LARGE_BUTTON_WIDTH, 0, generalI18N->T("Next"), ALIGN_BOTTOMLEFT)) { + currentMap_++; + if (currentMap_ >= (int)controllerMaps.size()) + currentMap_ = 0; + } + char temp[256]; + sprintf(temp, "%s (%i/%i)", controllerMaps[currentMap_].name.c_str(), currentMap_ + 1, (int)controllerMaps.size()); + UIText(0, Pos(10, dp_yres-170), temp, 0xFFFFFFFF, 1.0f, ALIGN_BOTTOMLEFT); + UICheckBox(GEN_ID,10, dp_yres - 80, keyI18N->T("Mapping Active"), ALIGN_BOTTOMLEFT, &controllerMaps[currentMap_].active); + UIEnd(); +} + +void KeyMappingNewKeyDialog::render() { + UIShader_Prepare(); + UIBegin(UIShader_Get()); + DrawBackground(1.0f); + + UIContext *ctx = screenManager()->getUIContext(); + UIFlush(); + + I18NCategory *keyI18N = GetI18NCategory("KeyMapping"); + I18NCategory *generalI18N = GetI18NCategory("General"); + +#define KeyText(x, y, sentence) \ + ui_draw2d.DrawTextShadow(UBUNTU24, (sentence), x, y, 0xFFFFFFFF, ALIGN_TOPLEFT); +#define KeyScale(width) \ + ui_draw2d.SetFontScale(width, width); + + int top = 10; + int left = 10; + int stride = 70; + KeyScale(1.6f); + KeyText(left, top, keyI18N->T("Map a new key for button:")); + KeyText(left, top += stride, (KeyMap::GetPspButtonName(this->pspBtn_)).c_str()); + KeyScale(1.3f); + KeyText(left, top += stride, keyI18N->T("Current key")); + KeyScale(2.0f); + KeyText(left, top += stride, (KeyMap::NameKeyFromPspButton(currentMap_, this->pspBtn_)).c_str()); + KeyScale(1.4f); + KeyText(left, top + stride, (KeyMap::NameDeviceFromPspButton(currentMap_, this->pspBtn_)).c_str()); + + int right = dp_yres; + KeyScale(1.4f); + KeyText(right, top, keyI18N->T("New Key")); + KeyScale(2.0f); + if (last_axis_id_ != -1) { + const std::string axis_direction_name = KeyMap::GetAxisName(last_axis_id_) + (last_axis_direction_ < 0 ? "-" : "+"); + KeyText(right, top += stride, axis_direction_name.c_str()); + KeyScale(1.4f); + KeyText(right, top + stride, GetDeviceName(last_axis_deviceid_)); + bool key_used = KeyMap::IsMappedAxis(last_axis_deviceid_, last_axis_id_, last_axis_direction_); + if (key_used) { + KeyScale(1.0f); + KeyText(left + stride, top + 2*stride, + keyI18N->T("Warning: Key is already used by")); + KeyText(left + stride, top + 3*stride, + (KeyMap::NamePspButtonFromAxis(last_axis_deviceid_, last_axis_id_, last_axis_direction_)).c_str()); + } + } else if (last_kb_key_ != 0) { + KeyText(right, top += stride, KeyMap::GetKeyName(last_kb_key_).c_str()); + KeyScale(1.4f); + KeyText(right, top + stride, GetDeviceName(last_kb_deviceid_)); + bool key_used = KeyMap::IsMappedKey(last_kb_deviceid_, last_kb_key_); + if (key_used) { + KeyScale(1.0f); + KeyText(left + stride, top + 2*stride, + keyI18N->T("Warning: Key is already used by")); + KeyText(left + stride, top + 3*stride, + (KeyMap::NamePspButtonFromKey(last_kb_deviceid_, last_kb_key_)).c_str()); + } + } + + KeyScale(1.0f); +#undef KeyText +#undef KeyScale + + // Save & cancel buttons + if (UIButton(GEN_ID, Pos(10, dp_yres - 10), LARGE_BUTTON_WIDTH, 0, keyI18N->T("Save Mapping"), ALIGN_LEFT | ALIGN_BOTTOM)) { + if (last_axis_id_ != -1) + KeyMap::SetAxisMapping(currentMap_, last_axis_deviceid_, last_axis_id_, last_axis_direction_, pspBtn_); + else + KeyMap::SetKeyMapping(currentMap_, last_kb_deviceid_, last_kb_key_, pspBtn_); + g_Config.Save(); + screenManager()->finishDialog(this, DR_OK); + } + + if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres - 10), LARGE_BUTTON_WIDTH, 0, generalI18N->T("Cancel"), ALIGN_RIGHT | ALIGN_BOTTOM)) { + screenManager()->finishDialog(this, DR_OK); + } + UIEnd(); +} + +void KeyMappingNewKeyDialog::key(const KeyInput &key) { + if (key.flags & KEY_DOWN) { + if (key.keyCode != NKCODE_EXT_MOUSEBUTTON_1) { + last_kb_deviceid_ = key.deviceId; + last_kb_key_ = key.keyCode; + last_axis_id_ = -1; + } + } +} + +void KeyMappingNewKeyDialog::axis(const AxisInput &axis) { + if (axis.value > AXIS_BIND_THRESHOLD) { + last_axis_deviceid_ = axis.deviceId; + last_axis_id_ = axis.axisId; + last_axis_direction_ = 1; + last_kb_key_ = 0; + } + if (axis.value < -AXIS_BIND_THRESHOLD) { + last_axis_deviceid_ = axis.deviceId; + last_axis_id_ = axis.axisId; + last_axis_direction_ = -1; + last_kb_key_ = 0; + } +} + +void KeyMappingNewKeyDialog::update(InputState &input) { + if (input.pad_buttons_down & PAD_BUTTON_BACK) { + g_Config.Save(); + screenManager()->finishDialog(this, DR_OK); + } +} + diff --git a/UI/ControlMappingScreen.h b/UI/ControlMappingScreen.h new file mode 100644 index 0000000000..bfc6dfb272 --- /dev/null +++ b/UI/ControlMappingScreen.h @@ -0,0 +1,59 @@ +// Copyright (c) 2013- PPSSPP Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0 or later versions. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official git repository and contact information can be found at +// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. + +#include "ui/view.h" +#include "ui/ui_screen.h" + +class KeyMappingScreen : public Screen { +public: + KeyMappingScreen() : currentMap_(0) {} + void update(InputState &input); + void render(); +private: + int currentMap_; +}; + +// Dialog box, meant to be pushed +class KeyMappingNewKeyDialog : public Screen { +public: + KeyMappingNewKeyDialog(int btn, int currentMap) { // : PopupScreen("Map Key") { + pspBtn_ = btn; + last_kb_deviceid_ = 0; + last_kb_key_ = 0; + last_axis_deviceid_ = 0; + last_axis_id_ = -1; + currentMap_ = currentMap; + } + void update(InputState &input); + void render(); + void key(const KeyInput &key); + void axis(const AxisInput &axis); + +protected: + virtual bool FillVertical() { return false; } + virtual bool ShowButtons() { return true; } + virtual void OnCompleted(DialogResult result) {} + +private: + int pspBtn_; + int last_kb_deviceid_; + int last_kb_key_; + int last_axis_deviceid_; + int last_axis_id_; + int last_axis_direction_; + int currentMap_; +}; diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 67ea47902c..4393ac65fd 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -26,6 +26,7 @@ #include "UI/GameSettingsScreen.h" #include "UI/GameInfoCache.h" #include "UI/MiscScreens.h" +#include "UI/ControlMappingScreen.h" #include "Core/Config.h" #include "android/jni/TestRunner.h" #include "GPU/GPUInterface.h" @@ -96,7 +97,8 @@ void PopupMultiChoice::ChoiceCallback(int num) { void PopupMultiChoice::Draw(UIContext &dc) { Choice::Draw(dc); - dc.Draw()->DrawText(dc.theme->uiFont, valueText_.c_str(), bounds_.x2() - 8, bounds_.centerY(), 0xFFFFFFFF, ALIGN_RIGHT | ALIGN_VCENTER); + int paddingX = 12; + dc.Draw()->DrawText(dc.theme->uiFont, valueText_.c_str(), bounds_.x2() - paddingX, bounds_.centerY(), 0xFFFFFFFF, ALIGN_RIGHT | ALIGN_VCENTER); } class PopupSliderChoice : public Choice { @@ -146,7 +148,7 @@ void PopupSliderChoice::Draw(UIContext &dc) { Choice::Draw(dc); char temp[4]; sprintf(temp, "%i", *value_); - dc.Draw()->DrawText(dc.theme->uiFont, temp, bounds_.x2() - 8, bounds_.centerY(), 0xFFFFFFFF, ALIGN_RIGHT | ALIGN_VCENTER); + dc.Draw()->DrawText(dc.theme->uiFont, temp, bounds_.x2() - 12, bounds_.centerY(), 0xFFFFFFFF, ALIGN_RIGHT | ALIGN_VCENTER); } EventReturn PopupSliderChoiceFloat::HandleClick(EventParams &e) { @@ -159,7 +161,7 @@ void PopupSliderChoiceFloat::Draw(UIContext &dc) { Choice::Draw(dc); char temp[5]; sprintf(temp, "%2.2f", *value_); - dc.Draw()->DrawText(dc.theme->uiFont, temp, bounds_.x2() - 8, bounds_.centerY(), 0xFFFFFFFF, ALIGN_RIGHT | ALIGN_VCENTER); + dc.Draw()->DrawText(dc.theme->uiFont, temp, bounds_.x2() - 12, bounds_.centerY(), 0xFFFFFFFF, ALIGN_RIGHT | ALIGN_VCENTER); } } diff --git a/UI/Header.h b/UI/Header.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index c150863609..071fa928e6 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -146,7 +146,7 @@ void GameButton::Draw(UIContext &dc) { } else { dc.Draw()->Flush(); dc.RebindTexture(); - dc.Draw()->DrawImage4Grid(I_DROP_SHADOW, x - dropsize, y, x+w + dropsize, y+h+dropsize*1.5, alphaMul(shadowColor, 0.5f), 1.0f); + dc.Draw()->DrawImage4Grid(dc.theme->dropShadow4Grid, x - dropsize, y, x+w + dropsize, y+h+dropsize*1.5, alphaMul(shadowColor, 0.5f), 1.0f); dc.Draw()->Flush(); } } @@ -384,7 +384,7 @@ void GameBrowser::Refresh() { if (!lastText_.empty()) { Add(new Spacer()); - Add(new Choice(lastText_))->OnClick.Handle(this, &GameBrowser::LastClick); + Add(new Choice(lastText_, new UI::LinearLayoutParams(UI::WRAP_CONTENT, UI::WRAP_CONTENT)))->OnClick.Handle(this, &GameBrowser::LastClick); } } diff --git a/UI/MenuScreens.cpp b/UI/MenuScreens.cpp index 6172e0d0f5..b5ea4b063d 100644 --- a/UI/MenuScreens.cpp +++ b/UI/MenuScreens.cpp @@ -61,6 +61,7 @@ #include "UI/PluginScreen.h" #include "UI/MainScreen.h" #include "UI/MiscScreens.h" +#include "UI/ControlMappingScreen.h" #include "GameInfoCache.h" #include "android/jni/TestRunner.h" @@ -637,38 +638,6 @@ void ControlsScreen::update(InputState &input) { } } -void KeyMappingNewKeyDialog::key(const KeyInput &key) { - if (key.flags & KEY_DOWN) { - if (key.keyCode != NKCODE_EXT_MOUSEBUTTON_1) { - last_kb_deviceid = key.deviceId; - last_kb_key = key.keyCode; - last_axis_id = -1; - } - } -} - -void KeyMappingNewKeyDialog::axis(const AxisInput &axis) { - if (axis.value > AXIS_BIND_THRESHOLD) { - last_axis_deviceid = axis.deviceId; - last_axis_id = axis.axisId; - last_axis_direction = 1; - last_kb_key = 0; - } - if (axis.value < -AXIS_BIND_THRESHOLD) { - last_axis_deviceid = axis.deviceId; - last_axis_id = axis.axisId; - last_axis_direction = -1; - last_kb_key = 0; - } -} - -void KeyMappingNewKeyDialog::update(InputState &input) { - if (input.pad_buttons_down & PAD_BUTTON_BACK) { - g_Config.Save(); - screenManager()->finishDialog(this, DR_OK); - } -} - void LanguageScreen::update(InputState &input) { if (input.pad_buttons_down & PAD_BUTTON_BACK) { g_Config.Save(); @@ -676,6 +645,84 @@ void LanguageScreen::update(InputState &input) { } } +void ControlsScreen::render() { + UIShader_Prepare(); + UIBegin(UIShader_Get()); + DrawBackground(1.0f); + + UIContext *ctx = screenManager()->getUIContext(); + UIFlush(); + + I18NCategory *c = GetI18NCategory("Controls"); + I18NCategory *g = GetI18NCategory("General"); + + ui_draw2d.SetFontScale(1.5f, 1.5f); + ui_draw2d.DrawTextShadow(UBUNTU24, c->T("Controls Settings"), dp_xres / 2, 10, 0xFFFFFFFF, ALIGN_HCENTER); + ui_draw2d.SetFontScale(1.0f, 1.0f); + + if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres - 10), LARGE_BUTTON_WIDTH, 0, g->T("Back"), ALIGN_RIGHT | ALIGN_BOTTOM)) { + screenManager()->finishDialog(this, DR_OK); + } + + int x = 30; + int y = 35; + int stride = 40; + int columnw = 440; + + UICheckBox(GEN_ID, x, y += stride, c->T("OnScreen", "On-Screen Touch Controls"), ALIGN_TOPLEFT, &g_Config.bShowTouchControls); + UICheckBox(GEN_ID, x, y += stride, c->T("Tilt", "Tilt to Analog (horizontal)"), ALIGN_TOPLEFT, &g_Config.bAccelerometerToAnalogHoriz); + if (g_Config.bShowTouchControls) { + UICheckBox(GEN_ID, x, y += stride, c->T("Show Left Analog Stick"), ALIGN_TOPLEFT, &g_Config.bShowAnalogStick); + + char scale[256]; + sprintf(scale, "%s %0.2f", c->T("Buttons Scaling:"), g_Config.fButtonScale); + ui_draw2d.DrawTextShadow(UBUNTU24, scale, x + 60, y += stride , 0xFFFFFFFF, ALIGN_LEFT); + HLinear hlinear1(x + 400, y, 20); + if (UIButton(GEN_ID, hlinear1, 80, 0, c->T("Auto"), ALIGN_LEFT)) + g_Config.fButtonScale = 1.15; + if (UIButton(GEN_ID, hlinear1, 60, 0, c->T("-0.1"), ALIGN_LEFT)) + if (g_Config.fButtonScale > 1.15) + g_Config.fButtonScale -= 0.1; + if (UIButton(GEN_ID, hlinear1, 60, 0, c->T("+0.1"), ALIGN_LEFT)) + if (g_Config.fButtonScale < 2.05) + g_Config.fButtonScale += 0.1; + y += 20; + + // This will be a slider in the new UI later + bool bTransparent = g_Config.iTouchButtonOpacity < 65; + bool prev = bTransparent; + UICheckBox(GEN_ID, x, y += stride, c->T("Buttons Opacity"), ALIGN_TOPLEFT, &bTransparent); + if (bTransparent) { + char opacity[256]; + sprintf(opacity, "%s %d", c->T("Opacity :"), g_Config.iTouchButtonOpacity); + ui_draw2d.DrawTextShadow(UBUNTU24, opacity, x + 60, y += stride , 0xFFFFFFFF, ALIGN_LEFT); + HLinear hlinear1(x + 250, y, 20); + if (UIButton(GEN_ID, hlinear1, 80, 0, c->T("Auto"), ALIGN_LEFT)) + g_Config.iTouchButtonOpacity = 15; + if (UIButton(GEN_ID, hlinear1, 40, 0, c->T("-5"), ALIGN_LEFT)) + if (g_Config.iTouchButtonOpacity > 15) + g_Config.iTouchButtonOpacity -= 5; + if (UIButton(GEN_ID, hlinear1, 40, 0, c->T("+5"), ALIGN_LEFT)) + if (g_Config.iTouchButtonOpacity < 65) + g_Config.iTouchButtonOpacity += 5; + y += 20; + } + if (bTransparent != prev) + g_Config.iTouchButtonOpacity = bTransparent ? 15 : 65; + } + y += 10; + // Button to KeyMapping screen + HLinear hlinear(x, y += stride, 20); + if (UIButton(GEN_ID, hlinear, 250, 0, c->T("Key Mapping"), ALIGN_LEFT)) { + screenManager()->push(new KeyMappingScreen()); + } + if (UIButton(GEN_ID, hlinear, 250, 0, c->T("Default Mapping"), ALIGN_LEFT)) { + KeyMap::RestoreDefault(); + } + + UIEnd(); +} + void DeveloperScreen::render() { UIShader_Prepare(); UIBegin(UIShader_Get()); @@ -1556,290 +1603,6 @@ void SystemScreen::render() { UIEnd(); } -void ControlsScreen::render() { - UIShader_Prepare(); - UIBegin(UIShader_Get()); - DrawBackground(1.0f); - - UIContext *ctx = screenManager()->getUIContext(); - UIFlush(); - GameInfo *ginfo = g_gameInfoCache.GetInfo(PSP_CoreParameter().fileToStart, true); - - if (ginfo && ginfo->pic1Texture) { - ginfo->pic1Texture->Bind(0); - uint32_t color = whiteAlpha(ease((time_now_d() - ginfo->timePic1WasLoaded) * 3)) & 0xFFc0c0c0; - ui_draw2d.DrawTexRect(0,0,dp_xres, dp_yres, 0,0,1,1,color); - ui_draw2d.Flush(); - ctx->RebindTexture(); - } - - I18NCategory *c = GetI18NCategory("Controls"); - I18NCategory *g = GetI18NCategory("General"); - - ui_draw2d.SetFontScale(1.5f, 1.5f); - ui_draw2d.DrawTextShadow(UBUNTU24, c->T("Controls Settings"), dp_xres / 2, 10, 0xFFFFFFFF, ALIGN_HCENTER); - ui_draw2d.SetFontScale(1.0f, 1.0f); - - if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres - 10), LARGE_BUTTON_WIDTH, 0, g->T("Back"), ALIGN_RIGHT | ALIGN_BOTTOM)) { - screenManager()->finishDialog(this, DR_OK); - } - - int x = 30; - int y = 35; - int stride = 40; - int columnw = 440; - - UICheckBox(GEN_ID, x, y += stride, c->T("OnScreen", "On-Screen Touch Controls"), ALIGN_TOPLEFT, &g_Config.bShowTouchControls); - UICheckBox(GEN_ID, x, y += stride, c->T("Tilt", "Tilt to Analog (horizontal)"), ALIGN_TOPLEFT, &g_Config.bAccelerometerToAnalogHoriz); - if (g_Config.bShowTouchControls) { - UICheckBox(GEN_ID, x, y += stride, c->T("Show Left Analog Stick"), ALIGN_TOPLEFT, &g_Config.bShowAnalogStick); - - char scale[256]; - sprintf(scale, "%s %0.2f", c->T("Buttons Scaling:"), g_Config.fButtonScale); - ui_draw2d.DrawTextShadow(UBUNTU24, scale, x + 60, y += stride , 0xFFFFFFFF, ALIGN_LEFT); - HLinear hlinear1(x + 400, y, 20); - if (UIButton(GEN_ID, hlinear1, 80, 0, c->T("Auto"), ALIGN_LEFT)) - g_Config.fButtonScale = 1.15; - if (UIButton(GEN_ID, hlinear1, 60, 0, c->T("-0.1"), ALIGN_LEFT)) - if (g_Config.fButtonScale > 1.15) - g_Config.fButtonScale -= 0.1; - if (UIButton(GEN_ID, hlinear1, 60, 0, c->T("+0.1"), ALIGN_LEFT)) - if (g_Config.fButtonScale < 2.05) - g_Config.fButtonScale += 0.1; - y += 20; - - // This will be a slider in the new UI later - bool bTransparent = g_Config.iTouchButtonOpacity < 65; - bool prev = bTransparent; - UICheckBox(GEN_ID, x, y += stride, c->T("Buttons Opacity"), ALIGN_TOPLEFT, &bTransparent); - if (bTransparent) { - char opacity[256]; - sprintf(opacity, "%s %d", c->T("Opacity :"), g_Config.iTouchButtonOpacity); - ui_draw2d.DrawTextShadow(UBUNTU24, opacity, x + 60, y += stride , 0xFFFFFFFF, ALIGN_LEFT); - HLinear hlinear1(x + 250, y, 20); - if (UIButton(GEN_ID, hlinear1, 80, 0, c->T("Auto"), ALIGN_LEFT)) - g_Config.iTouchButtonOpacity = 15; - if (UIButton(GEN_ID, hlinear1, 40, 0, c->T("-5"), ALIGN_LEFT)) - if (g_Config.iTouchButtonOpacity > 15) - g_Config.iTouchButtonOpacity -= 5; - if (UIButton(GEN_ID, hlinear1, 40, 0, c->T("+5"), ALIGN_LEFT)) - if (g_Config.iTouchButtonOpacity < 65) - g_Config.iTouchButtonOpacity += 5; - y += 20; - } - if (bTransparent != prev) - g_Config.iTouchButtonOpacity = bTransparent ? 15 : 65; - } - y += 10; - // Button to KeyMapping screen - HLinear hlinear(x, y += stride, 20); - if (UIButton(GEN_ID, hlinear, 250, 0, c->T("Key Mapping"), ALIGN_LEFT)) { - screenManager()->push(new KeyMappingScreen()); - } - if (UIButton(GEN_ID, hlinear, 250, 0, c->T("Default Mapping"), ALIGN_LEFT)) { - KeyMap::RestoreDefault(); - } - - UIEnd(); -} - -void KeyMappingScreen::update(InputState &input) { - if (input.pad_buttons_down & PAD_BUTTON_BACK) { - g_Config.Save(); - screenManager()->finishDialog(this, DR_OK); - } -} - -void KeyMappingScreen::render() { - UIShader_Prepare(); - UIBegin(UIShader_Get()); - DrawBackground(1.0f); - - UIContext *ctx = screenManager()->getUIContext(); - UIFlush(); - GameInfo *ginfo = g_gameInfoCache.GetInfo(PSP_CoreParameter().fileToStart, true); - - if (ginfo && ginfo->pic1Texture) { - ginfo->pic1Texture->Bind(0); - uint32_t color = whiteAlpha(ease((time_now_d() - ginfo->timePic1WasLoaded) * 3)) & 0xFFc0c0c0; - ui_draw2d.DrawTexRect(0,0,dp_xres, dp_yres, 0,0,1,1,color); - ui_draw2d.Flush(); - ctx->RebindTexture(); - } - - I18NCategory *keyI18N = GetI18NCategory("KeyMapping"); - I18NCategory *generalI18N = GetI18NCategory("General"); - - -#define KeyBtn(x, y, symbol) \ - if (UIButton(GEN_ID, Pos(x, y), 90, 0, KeyMap::NameKeyFromPspButton(currentMap_, symbol).c_str(), \ - ALIGN_TOPLEFT)) {\ - screenManager()->push(new KeyMappingNewKeyDialog(symbol, currentMap_), 0); \ - UIReset(); \ - } \ - UIText(0, Pos(x+30, y+50), KeyMap::NameDeviceFromPspButton(currentMap_, symbol).c_str(), 0xFFFFFFFF, 0.7f, ALIGN_HCENTER); \ - UIText(0, Pos(x+30, y+80), KeyMap::GetPspButtonName(symbol).c_str(), 0xFFFFFFFF, 0.5f, ALIGN_HCENTER); \ - - - // \ - // UIText(0, Pos(x, y+50), controllerMaps[currentMap_].name.c_str(), 0xFFFFFFFF, 0.5f, ALIGN_HCENTER); - - int pad = 130; - int hlfpad = pad / 2; - - int left = 30; - KeyBtn(left, 30, CTRL_LTRIGGER); - - int top = 120; - KeyBtn(left+hlfpad, top, CTRL_UP); // Up - KeyBtn(left, top+hlfpad, CTRL_LEFT);// Left - KeyBtn(left+pad, top+hlfpad, CTRL_RIGHT); // Right - KeyBtn(left+hlfpad, top+pad, CTRL_DOWN); // Down - - top = 10; - left = 250; - KeyBtn(left+hlfpad, top, VIRTKEY_AXIS_Y_MAX); // Analog Up - KeyBtn(left, top+hlfpad, VIRTKEY_AXIS_X_MIN);// Analog Left - KeyBtn(left+pad, top+hlfpad, VIRTKEY_AXIS_X_MAX); // Analog Right - KeyBtn(left+hlfpad, top+pad, VIRTKEY_AXIS_Y_MIN); // Analog Down - - top = 120; - left = 480; - KeyBtn(left+hlfpad, top, CTRL_TRIANGLE); // Triangle - KeyBtn(left, top+hlfpad, CTRL_SQUARE); // Square - KeyBtn(left+pad, top+hlfpad, CTRL_CIRCLE); // Circle - KeyBtn(left+hlfpad, top+pad, CTRL_CROSS); // Cross - - left = 610; - KeyBtn(left, 30, CTRL_RTRIGGER); - - top += pad + 50; - left = 250; - KeyBtn(left, top, CTRL_SELECT); // Select - KeyBtn(left + pad, top, CTRL_START); //Start - - top = 10; - left = 720; - KeyBtn(left, top, VIRTKEY_UNTHROTTLE); - top += 100; - KeyBtn(left, top, VIRTKEY_SPEED_TOGGLE); - top += 100; - KeyBtn(left, top, VIRTKEY_PAUSE); - top += 100; - KeyBtn(left, top, VIRTKEY_RAPID_FIRE); -#undef KeyBtn - - // TODO: Add rapid fire somewhere? - - if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres - 10), LARGE_BUTTON_WIDTH, 0, generalI18N->T("Back"), ALIGN_RIGHT | ALIGN_BOTTOM)) { - screenManager()->finishDialog(this, DR_OK); - } - - if (UIButton(GEN_ID, Pos(10, dp_yres-10), LARGE_BUTTON_WIDTH, 0, generalI18N->T("Prev"), ALIGN_BOTTOMLEFT)) { - currentMap_--; - if (currentMap_ < 0) - currentMap_ = (int)controllerMaps.size() - 1; - } - if (UIButton(GEN_ID, Pos(10 + 10 + LARGE_BUTTON_WIDTH, dp_yres-10), LARGE_BUTTON_WIDTH, 0, generalI18N->T("Next"), ALIGN_BOTTOMLEFT)) { - currentMap_++; - if (currentMap_ >= (int)controllerMaps.size()) - currentMap_ = 0; - } - char temp[256]; - sprintf(temp, "%s (%i/%i)", controllerMaps[currentMap_].name.c_str(), currentMap_ + 1, (int)controllerMaps.size()); - UIText(0, Pos(10, dp_yres-170), temp, 0xFFFFFFFF, 1.0f, ALIGN_BOTTOMLEFT); - UICheckBox(GEN_ID,10, dp_yres - 80, keyI18N->T("Mapping Active"), ALIGN_BOTTOMLEFT, &controllerMaps[currentMap_].active); - UIEnd(); -} - -void KeyMappingNewKeyDialog::render() { - UIShader_Prepare(); - UIBegin(UIShader_Get()); - DrawBackground(1.0f); - - UIContext *ctx = screenManager()->getUIContext(); - UIFlush(); - GameInfo *ginfo = g_gameInfoCache.GetInfo(PSP_CoreParameter().fileToStart, true); - - if (ginfo && ginfo->pic1Texture) { - ginfo->pic1Texture->Bind(0); - uint32_t color = whiteAlpha(ease((time_now_d() - ginfo->timePic1WasLoaded) * 3)) & 0xFFc0c0c0; - ui_draw2d.DrawTexRect(0,0,dp_xres, dp_yres, 0,0,1,1,color); - ui_draw2d.Flush(); - ctx->RebindTexture(); - } - - I18NCategory *keyI18N = GetI18NCategory("KeyMapping"); - I18NCategory *generalI18N = GetI18NCategory("General"); - -#define KeyText(x, y, sentence) \ - ui_draw2d.DrawTextShadow(UBUNTU24, (sentence), x, y, 0xFFFFFFFF, ALIGN_TOPLEFT); -#define KeyScale(width) \ - ui_draw2d.SetFontScale(width, width); - - int top = 10; - int left = 10; - int stride = 70; - KeyScale(1.6f); - KeyText(left, top, keyI18N->T("Map a new key for button:")); - KeyText(left, top += stride, (KeyMap::GetPspButtonName(this->pspBtn)).c_str()); - KeyScale(1.3f); - KeyText(left, top += stride, keyI18N->T("Current key")); - KeyScale(2.0f); - KeyText(left, top += stride, (KeyMap::NameKeyFromPspButton(currentMap_, this->pspBtn)).c_str()); - KeyScale(1.4f); - KeyText(left, top + stride, (KeyMap::NameDeviceFromPspButton(currentMap_, this->pspBtn)).c_str()); - - int right = dp_yres; - KeyScale(1.4f); - KeyText(right, top, keyI18N->T("New Key")); - KeyScale(2.0f); - if (last_axis_id != -1) { - const std::string axis_direction_name = KeyMap::GetAxisName(last_axis_id) + (last_axis_direction < 0 ? "-" : "+"); - KeyText(right, top += stride, axis_direction_name.c_str()); - KeyScale(1.4f); - KeyText(right, top + stride, GetDeviceName(last_axis_deviceid)); - bool key_used = KeyMap::IsMappedAxis(last_axis_deviceid, last_axis_id, last_axis_direction); - if (key_used) { - KeyScale(1.0f); - KeyText(left + stride, top + 2*stride, - keyI18N->T("Warning: Key is already used by")); - KeyText(left + stride, top + 3*stride, - (KeyMap::NamePspButtonFromAxis(last_axis_deviceid, last_axis_id, last_axis_direction)).c_str()); - } - } else if (last_kb_key != 0) { - KeyText(right, top += stride, KeyMap::GetKeyName(last_kb_key).c_str()); - KeyScale(1.4f); - KeyText(right, top + stride, GetDeviceName(last_kb_deviceid)); - bool key_used = KeyMap::IsMappedKey(last_kb_deviceid, last_kb_key); - if (key_used) { - KeyScale(1.0f); - KeyText(left + stride, top + 2*stride, - keyI18N->T("Warning: Key is already used by")); - KeyText(left + stride, top + 3*stride, - (KeyMap::NamePspButtonFromKey(last_kb_deviceid, last_kb_key)).c_str()); - } - } - - KeyScale(1.0f); -#undef KeyText -#undef KeyScale - - // Save & cancel buttons - if (UIButton(GEN_ID, Pos(10, dp_yres - 10), LARGE_BUTTON_WIDTH, 0, keyI18N->T("Save Mapping"), ALIGN_LEFT | ALIGN_BOTTOM)) { - if (last_axis_id != -1) - KeyMap::SetAxisMapping(currentMap_, last_axis_deviceid, last_axis_id, last_axis_direction, pspBtn); - else - KeyMap::SetKeyMapping(currentMap_, last_kb_deviceid, last_kb_key, pspBtn); - g_Config.Save(); - screenManager()->finishDialog(this, DR_OK); - } - - if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres - 10), LARGE_BUTTON_WIDTH, 0, generalI18N->T("Cancel"), ALIGN_RIGHT | ALIGN_BOTTOM)) { - screenManager()->finishDialog(this, DR_OK); - } - UIEnd(); -} class FileListAdapter : public UIListAdapter { public: diff --git a/UI/MenuScreens.h b/UI/MenuScreens.h index de2b61f104..b1e5171dea 100644 --- a/UI/MenuScreens.h +++ b/UI/MenuScreens.h @@ -111,6 +111,12 @@ public: void render(); }; +class ControlsScreen : public Screen { +public: + void update(InputState &input); + void render(); +}; + class SystemScreen : public Screen { public: @@ -129,50 +135,6 @@ private: std::map> langValuesMapping; }; -class ControlsScreen : public Screen -{ -public: - void update(InputState &input); - void render(); -}; - -class KeyMappingScreen : public Screen -{ -public: - KeyMappingScreen() : currentMap_(0) {} - void update(InputState &input); - void render(); -private: - int currentMap_; -}; - -// Dialog box, meant to be pushed -class KeyMappingNewKeyDialog : public Screen -{ -public: - KeyMappingNewKeyDialog(int btn, int currentMap) { - pspBtn = btn; - last_kb_deviceid = 0; - last_kb_key = 0; - last_axis_deviceid = 0; - last_axis_id = -1; - currentMap_ = currentMap; - } - void update(InputState &input); - void render(); - void key(const KeyInput &key); - void axis(const AxisInput &axis); - -private: - int pspBtn; - int last_kb_deviceid; - int last_kb_key; - int last_axis_deviceid; - int last_axis_id; - int last_axis_direction; - int currentMap_; -}; - struct FileSelectScreenOptions { const char* filter; // Enforced extension filter. Case insensitive, extensions separated by ":". bool allowChooseDirectory; diff --git a/UI/MiscScreens.cpp b/UI/MiscScreens.cpp index e5cc4876f9..2fb6e4c91d 100644 --- a/UI/MiscScreens.cpp +++ b/UI/MiscScreens.cpp @@ -271,9 +271,9 @@ void CreditsScreen::render() { const char * credits[] = { "PPSSPP", "", - "", c->T("title", "A fast and portable PSP emulator"), "", + "", c->T("created", "Created by"), "Henrik RydgÄrd", "(aka hrydgard, ector)", @@ -311,6 +311,12 @@ void CreditsScreen::render() { "lioncash", "JulianoAmaralChaves", "", + "", + c->T("specialthanks", "Special thanks to:"), + "Keith Galocy at nVidia (hw, advice)", + "Orphis (build server)", + "", + "", c->T("written", "Written in C++ for speed and portability"), "", "", diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 31ac4bcf56..f979fc527e 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -415,6 +415,8 @@ void NativeInitGraphics() { ui_theme.checkOff = I_SQUARE; ui_theme.whiteImage = SOLIDWHITE; ui_theme.sliderKnob = I_CIRCLE; + ui_theme.dropShadow4Grid = I_DROP_SHADOW; + ui_theme.buttonStyle.background = UI::Drawable(UI::DRAW_4GRID, I_BUTTON); ui_theme.buttonStyle.fgColor = 0xFFFFFFFF; ui_theme.buttonStyle.image = I_BUTTON; @@ -424,13 +426,21 @@ void NativeInitGraphics() { ui_theme.buttonDownStyle.fgColor = 0xFFFFFFFF; ui_theme.buttonDisabledStyle.background = UI::Drawable(UI::DRAW_4GRID, I_BUTTON, 0xFF404040); ui_theme.buttonDisabledStyle.fgColor = 0xFF707070; + ui_theme.itemStyle.background = UI::Drawable(0x55000000); ui_theme.itemStyle.fgColor = 0xFFFFFFFF; - ui_theme.itemFocusedStyle.background = UI::Drawable(0xCC909080); - ui_theme.itemDownStyle.background = UI::Drawable(0xFFFFc080); + ui_theme.itemFocusedStyle.background = UI::Drawable(0xe0ECCA6D); + ui_theme.itemDownStyle.background = UI::Drawable(0xFFE1B12D); ui_theme.itemDownStyle.fgColor = 0xFF000000; - ui_theme.popupTitle.fgColor = 0xFFE5B533; + ui_theme.itemDisabledStyle.background = UI::Drawable(0x55E0D4AF); + ui_theme.itemDisabledStyle.fgColor = 0xFFcccccc; + ui_theme.buttonStyle = ui_theme.itemStyle; + ui_theme.buttonFocusedStyle = ui_theme.itemFocusedStyle; + ui_theme.buttonDownStyle = ui_theme.itemDownStyle; + ui_theme.buttonDisabledStyle = ui_theme.itemDisabledStyle; + + ui_theme.popupTitle.fgColor = 0xFFE5B533; ui_draw2d.Init(); ui_draw2d_front.Init(); diff --git a/UI/UI.vcxproj b/UI/UI.vcxproj index 61772c3fd1..d6d0c93ece 100644 --- a/UI/UI.vcxproj +++ b/UI/UI.vcxproj @@ -19,6 +19,7 @@ + @@ -34,11 +35,13 @@ + + diff --git a/UI/UI.vcxproj.filters b/UI/UI.vcxproj.filters index 6e91becff2..ed6d93fa7f 100644 --- a/UI/UI.vcxproj.filters +++ b/UI/UI.vcxproj.filters @@ -28,6 +28,9 @@ Screens + + Screens + @@ -56,6 +59,12 @@ Screens + + Screens + + + Screens + diff --git a/android/jni/Android.mk b/android/jni/Android.mk index fd2c2ebad7..088beb055d 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -140,6 +140,7 @@ LOCAL_SRC_FILES := \ $(SRC)/UI/OnScreenDisplay.cpp \ $(SRC)/UI/PluginScreen.cpp \ $(SRC)/UI/GameScreen.cpp \ + $(SRC)/UI/ControlMappingScreen.cpp \ $(SRC)/UI/GameSettingsScreen.cpp \ $(SRC)/native/android/app-android.cpp \ $(SRC)/ext/disarm.cpp \ diff --git a/native b/native index 569cdb9c08..4a1c3c4f83 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit 569cdb9c081e7af82125510dbd38ba2cedfff6f3 +Subproject commit 4a1c3c4f83ee1f3ba4b0bc63d3d82b7a698df519