Permalink
Browse files

Merge pull request #10378 from unknownbrackets/ui-gamepad

Reset views after loading per game config
  • Loading branch information...
hrydgard committed Dec 9, 2017
2 parents 6e3cb0c + c097910 commit 8d5c85fa40be9190d6d464201c969a63b316b872
@@ -63,6 +63,7 @@ class Host {
virtual bool CreateDesktopShortcut(std::string argumentPath, std::string title) {return false;}
virtual void NotifyUserMessage(const std::string &message, float duration = 1.0f, u32 color = 0x00FFFFFF, const char *id = nullptr) {}
virtual void SendUIMessage(const std::string &message, const std::string &value) {}
// Used for headless.
virtual bool ShouldSkipUI() { return false; }
@@ -248,6 +248,7 @@ bool Load_PSP_ISO(FileLoader *fileLoader, std::string *error_string) {
//in case we didn't go through EmuScreen::boot
g_Config.loadGameConfig(id);
host->SendUIMessage("config_loaded", "");
INFO_LOG(LOADER,"Loading %s...", bootpath.c_str());
return __KernelLoadExec(bootpath.c_str(), 0, error_string);
}
@@ -144,7 +144,6 @@ void EmuScreen::bootGame(const std::string &filename) {
return;
}
bootComplete();
RecreateViews();
}
return;
}
@@ -155,6 +154,8 @@ void EmuScreen::bootGame(const std::string &filename) {
std::shared_ptr<GameInfo> info = g_gameInfoCache->GetInfo(nullptr, filename, 0);
if (info && !info->id.empty()) {
g_Config.loadGameConfig(info->id);
// Reset views in case controls are in a different place.
RecreateViews();
}
invalid_ = true;
@@ -356,6 +357,9 @@ void EmuScreen::sendMessage(const char *message, const char *value) {
bootPending_ = true;
gamePath_ = value;
}
} else if (!strcmp(message, "config_loaded")) {
// In case we need to position touch controls differently.
RecreateViews();
} else if (!strcmp(message, "control mapping") && screenManager()->topScreen() == this) {
UpdateUIState(UISTATE_MENU);
releaseButtons();
@@ -53,6 +53,10 @@ class NativeHost : public Host {
void NotifyUserMessage(const std::string &message, float duration = 1.0f, u32 color = 0x00FFFFFF, const char *id = nullptr) override {
osm.Show(message, duration, color, -1, true, id);
}
void SendUIMessage(const std::string &message, const std::string &value) override {
NativeMessageReceived(message.c_str(), value.c_str());
}
};
#if !defined(MOBILE_DEVICE) && defined(USING_QT_UI)
@@ -134,6 +138,10 @@ class QtHost : public Host {
osm.Show(message, duration, color, -1, true, id);
}
void SendUIMessage(const std::string &message, const std::string &value) override {
NativeMessageReceived(message.c_str(), value.c_str());
}
bool GPUDebuggingActive()
{
auto dialogDisplayList = mainWindow->GetDialogDisplaylist();
@@ -371,3 +371,7 @@ void WindowsHost::ToggleDebugConsoleVisibility() {
void WindowsHost::NotifyUserMessage(const std::string &message, float duration, u32 color, const char *id) {
osm.Show(message, duration, color, -1, true, id);
}
void WindowsHost::SendUIMessage(const std::string &message, const std::string &value) {
NativeMessageReceived(message.c_str(), value.c_str());
}
@@ -65,6 +65,7 @@ class WindowsHost : public Host {
bool CreateDesktopShortcut(std::string argumentPath, std::string title) override;
void NotifyUserMessage(const std::string &message, float duration = 1.0f, u32 color = 0x00FFFFFF, const char *id = nullptr) override;
void SendUIMessage(const std::string &message, const std::string &value) override;
std::shared_ptr<KeyboardDevice> keyboard;
@@ -12,6 +12,46 @@ void Tween::Apply(View *view) {
DoApply(view, pos);
}
template <typename Value>
void TweenBase<Value>::PersistData(PersistStatus status, std::string anonId, PersistMap &storage) {
struct TweenData {
float start;
float duration;
Value from;
Value to;
bool finishApplied;
};
PersistBuffer &buffer = storage["TweenBase::" + anonId];
switch (status) {
case UI::PERSIST_SAVE:
buffer.resize(sizeof(TweenData) / sizeof(int));
{
TweenData &data = *(TweenData *)&buffer[0];
data.start = start_;
data.duration = duration_;
data.from = from_;
data.to = to_;
data.finishApplied = finishApplied_;
}
break;
case UI::PERSIST_RESTORE:
if (buffer.size() >= sizeof(TweenData) / sizeof(int)) {
TweenData data = *(TweenData *)&buffer[0];
start_ = data.start;
duration_ = data.duration;
from_ = data.from;
to_ = data.to;
finishApplied_ = data.finishApplied;
}
break;
}
}
template void TweenBase<uint32_t>::PersistData(PersistStatus status, std::string anonId, PersistMap &storage);
template void TweenBase<Visibility>::PersistData(PersistStatus status, std::string anonId, PersistMap &storage);
uint32_t ColorTween::Current(float pos) {
return colorBlend(to_, from_, pos);
}
@@ -23,6 +23,8 @@ class Tween {
return finishApplied_ && time_now() >= start_ + duration_;
}
virtual void PersistData(PersistStatus status, std::string anonId, PersistMap &storage) = 0;
protected:
float DurationOffset() {
return time_now() - start_;
@@ -41,6 +43,7 @@ class Tween {
};
// This is the class all tweens inherit from. Shouldn't be used directly, see below.
// Note: Value cannot safely be a pointer (without overriding PersistData.)
template <typename Value>
class TweenBase: public Tween {
public:
@@ -102,6 +105,8 @@ class TweenBase: public Tween {
return Current(Position());
}
void PersistData(PersistStatus status, std::string anonId, PersistMap &storage) override;
protected:
virtual Value Current(float pos) = 0;
@@ -224,6 +224,11 @@ void View::PersistData(PersistStatus status, std::string anonId, PersistMap &sto
}
break;
}
ITOA stringify;
for (int i = 0; i < (int)tweens_.size(); ++i) {
tweens_[i]->PersistData(status, tag + "/" + stringify.p((int)i), storage);
}
}
Point View::GetFocusPosition(FocusDirection dir) {

0 comments on commit 8d5c85f

Please sign in to comment.