mirror of
https://github.com/amwatson/CitraVR.git
synced 2024-09-19 19:01:38 +02:00
[UI Ribbon] pause/resume game, show/hide lower panel based on lower menu selected
This commit is contained in:
parent
a75f5b7afd
commit
e9eb4a30fd
6 changed files with 48 additions and 20 deletions
|
@ -6,6 +6,7 @@ import android.widget.Button
|
|||
import org.citra.citra_emu.NativeLibrary
|
||||
import org.citra.citra_emu.R
|
||||
import org.citra.citra_emu.vr.VrActivity
|
||||
import org.citra.citra_emu.vr.utils.VrMessageQueue
|
||||
|
||||
class VrRibbonLayer(activity: VrActivity) : VrUILayer(activity, R.layout.vr_ribbon) {
|
||||
|
||||
|
@ -26,6 +27,10 @@ class VrRibbonLayer(activity: VrActivity) : VrUILayer(activity, R.layout.vr_ribb
|
|||
window?.findViewById<View>(menuTypeCurrent.resId)?.visibility = View.GONE
|
||||
menuTypeCurrent = menuTypeNew
|
||||
window?.findViewById<View>(menuTypeCurrent.resId)?.visibility = View.VISIBLE
|
||||
if (menuTypeCurrent == MenuType.MAIN)
|
||||
VrMessageQueue.post(VrMessageQueue.MessageType.CHANGE_LOWER_MENU, 0)
|
||||
else if (menuTypeCurrent == MenuType.POSITION)
|
||||
VrMessageQueue.post(VrMessageQueue.MessageType.CHANGE_LOWER_MENU, 1)
|
||||
}
|
||||
|
||||
fun initializeMainView() {
|
||||
|
@ -62,15 +67,23 @@ class VrRibbonLayer(activity: VrActivity) : VrUILayer(activity, R.layout.vr_ribb
|
|||
false
|
||||
}
|
||||
|
||||
window?.findViewById<Button>(R.id.buttonNextMenu)?.setOnClickListener{ _ ->
|
||||
val btnNext = window?.findViewById<Button>(R.id.buttonNextMenu)
|
||||
val btnPrev = window?.findViewById<Button>(R.id.buttonPrevMenu)
|
||||
btnNext?.setOnClickListener{ _ ->
|
||||
val nextIdx = (menuTypeCurrent.ordinal + 1) % MenuType.values().size
|
||||
switchMenus(MenuType.values()[nextIdx])
|
||||
if ((nextIdx + 1) >= MenuType.values().size)
|
||||
btnNext.visibility = View.INVISIBLE
|
||||
btnPrev?.visibility = View.VISIBLE
|
||||
false
|
||||
}
|
||||
|
||||
window?.findViewById<Button>(R.id.buttonPrevMenu)?.setOnClickListener { _ ->
|
||||
btnPrev?.setOnClickListener { _ ->
|
||||
val prevIdx = (menuTypeCurrent.ordinal - 1 + MenuType.values().size) % MenuType.values().size
|
||||
switchMenus(MenuType.values()[prevIdx])
|
||||
if ((prevIdx - 1) <= 0)
|
||||
btnPrev.visibility = View.INVISIBLE
|
||||
btnNext?.visibility = View.VISIBLE
|
||||
false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,9 @@ object VrMessageQueue {
|
|||
// Keep consistent with MessageQueue.h
|
||||
enum class MessageType(val jniVal: Int) {
|
||||
SHOW_KEYBOARD(0),
|
||||
SHOW_ERROR_MESSAGE(1)
|
||||
SHOW_ERROR_MESSAGE(1),
|
||||
EXIT_NEEDED(2),
|
||||
CHANGE_LOWER_MENU(3)
|
||||
}
|
||||
@JvmStatic
|
||||
fun post(messageType: MessageType, payload: Long) {
|
||||
|
|
|
@ -450,8 +450,7 @@ XrPosef GameSurfaceLayer::GetTopPanelFromHeadPose(uint32_t eye, const XrPosef& h
|
|||
panelPosition.y -= up.z / 25.f;
|
||||
panelPosition.x += up.y / 25.f;
|
||||
|
||||
if (mImmersiveMode == 3)
|
||||
{
|
||||
if (mImmersiveMode == 3) {
|
||||
panelPosition.z += right.x * (0.065f / 2.f) * (1 - 2.f * eye);
|
||||
panelPosition.y -= right.z * (0.065f / 2.f) * (1 - 2.f * eye);
|
||||
panelPosition.x += right.y * (0.065f / 2.f) * (1 - 2.f * eye);
|
||||
|
|
|
@ -15,6 +15,8 @@ License : Licensed under GPLv3 or any later version.
|
|||
|
||||
#include <cstdint>
|
||||
|
||||
enum LowerMenuType : uint16_t { MAIN_MENU = 0, POSITIONAL_MENU = 1 };
|
||||
|
||||
/**
|
||||
* Message class
|
||||
*
|
||||
|
@ -28,7 +30,8 @@ struct Message {
|
|||
enum Type {
|
||||
SHOW_KEYBOARD = 0, // payload 0 = hide keyboard, 1 = show keyboard
|
||||
SHOW_ERROR_MESSAGE = 1, // payload 0 = show error message, 1 = hide error message
|
||||
EXIT_NEEDED = 2 // payload ignored
|
||||
EXIT_NEEDED = 2, // payload ignored
|
||||
CHANGE_LOWER_MENU = 3 // payload indicates menu ID
|
||||
};
|
||||
|
||||
Message() {}
|
||||
|
|
|
@ -207,7 +207,7 @@ public:
|
|||
|
||||
while (true) {
|
||||
// Handle events/state-changes.
|
||||
const AppState appState = HandleEvents(jni);
|
||||
AppState appState = HandleEvents(jni);
|
||||
if (appState.mIsStopRequested) { break; }
|
||||
HandleStateChanges(jni, appState);
|
||||
if (appState.mIsXrSessionActive) {
|
||||
|
@ -385,7 +385,7 @@ private:
|
|||
// Super Immersive Mode update and computation.
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
bool showLowerPanel = true;
|
||||
bool showLowerPanel = appState.ShouldShowLowerPanel();
|
||||
float immersiveModeFactor = (VRSettings::values.vr_immersive_mode < 2)
|
||||
? immersiveScaleFactor[VRSettings::values.vr_immersive_mode]
|
||||
: immersiveScaleFactor[2];
|
||||
|
@ -454,8 +454,8 @@ private:
|
|||
invertedOrientation, gOpenXr->headLocation.pose.position);
|
||||
|
||||
const float gamePosScaler =
|
||||
powf(10.f, VRSettings::values.vr_immersive_positional_game_scaler) *
|
||||
VRSettings::values.vr_factor_3d;
|
||||
powf(10.f, VRSettings::values.vr_immersive_positional_game_scaler) *
|
||||
VRSettings::values.vr_factor_3d;
|
||||
|
||||
inv_transform[3].x = -position.x * gamePosScaler;
|
||||
inv_transform[3].y = -position.y * gamePosScaler;
|
||||
|
@ -815,14 +815,18 @@ private:
|
|||
return newState;
|
||||
}
|
||||
|
||||
void HandleStateChanges(JNIEnv* jni, const AppState& newState) const {
|
||||
if (newState.mIsEmulationPaused != mLastAppState.mIsEmulationPaused) {
|
||||
void HandleStateChanges(JNIEnv* jni, AppState& newState) const {
|
||||
const bool shouldPauseEmulation = !newState.mHasFocus || newState.mShouldShowErrorMessage ||
|
||||
newState.mLowerMenuType == LowerMenuType::POSITIONAL_MENU;
|
||||
if (shouldPauseEmulation != mLastAppState.mIsEmulationPaused) {
|
||||
ALOGI("State change: Emulation paused: {} -> {}", mLastAppState.mIsEmulationPaused,
|
||||
newState.mIsEmulationPaused);
|
||||
if (newState.mIsEmulationPaused) {
|
||||
if (shouldPauseEmulation) {
|
||||
PauseEmulation(jni);
|
||||
newState.mIsEmulationPaused = true;
|
||||
} else {
|
||||
ResumeEmulation(jni);
|
||||
newState.mIsEmulationPaused = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -905,14 +909,10 @@ private:
|
|||
switch (newState.state) {
|
||||
case XR_SESSION_STATE_FOCUSED:
|
||||
ALOGV("{}(): Received XR_SESSION_STATE_FOCUSED event", __func__);
|
||||
if (!mLastAppState.mHasFocus && !mLastAppState.mShouldShowErrorMessage) {
|
||||
newAppState.mIsEmulationPaused = false;
|
||||
}
|
||||
newAppState.mHasFocus = true;
|
||||
break;
|
||||
case XR_SESSION_STATE_VISIBLE:
|
||||
ALOGV("{}(): Received XR_SESSION_STATE_VISIBLE event", __func__);
|
||||
if (mLastAppState.mHasFocus) { newAppState.mIsEmulationPaused = true; }
|
||||
newAppState.mHasFocus = false;
|
||||
break;
|
||||
case XR_SESSION_STATE_READY:
|
||||
|
@ -1022,12 +1022,10 @@ private:
|
|||
newAppState.mShouldShowErrorMessage = shouldShowErrorMessage;
|
||||
if (newAppState.mShouldShowErrorMessage && !newAppState.mIsEmulationPaused) {
|
||||
ALOGD("Pausing emulation due to error message");
|
||||
newAppState.mIsEmulationPaused = true;
|
||||
}
|
||||
if (!newAppState.mShouldShowErrorMessage && newAppState.mIsEmulationPaused &&
|
||||
newAppState.mHasFocus) {
|
||||
ALOGD("Resuming emulation after error message");
|
||||
newAppState.mIsEmulationPaused = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -1036,6 +1034,13 @@ private:
|
|||
newAppState.mIsStopRequested = true;
|
||||
break;
|
||||
}
|
||||
case Message::Type::CHANGE_LOWER_MENU: {
|
||||
newAppState.mLowerMenuType = static_cast<LowerMenuType>(message.mPayload);
|
||||
ALOGI("Received CHANGE_LOWER_MENU message: {}, state change {} -> {}",
|
||||
message.mPayload, mLastAppState.mLowerMenuType,
|
||||
newAppState.mLowerMenuType);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
ALOGE("Unknown message type: %d", message.mType);
|
||||
|
@ -1060,6 +1065,12 @@ private:
|
|||
|
||||
class AppState {
|
||||
public:
|
||||
bool ShouldShowLowerPanel() const {
|
||||
return mLowerMenuType == LowerMenuType::MAIN_MENU;
|
||||
}
|
||||
|
||||
LowerMenuType mLowerMenuType = LowerMenuType::MAIN_MENU;
|
||||
|
||||
bool mIsKeyboardActive = false;
|
||||
bool mShouldShowErrorMessage = false;
|
||||
bool mIsEmulationPaused = false;
|
||||
|
|
|
@ -45,7 +45,7 @@ struct Values {
|
|||
int32_t vr_immersive_mode = 0;
|
||||
bool extra_performance_mode_enabled = false;
|
||||
int32_t vr_si_mode_register_offset = -1;
|
||||
int32_t vr_factor_3d = 100;
|
||||
int32_t vr_factor_3d = 100;
|
||||
int32_t vr_immersive_positional_game_scaler = 0;
|
||||
std::string vr_immersive_eye_indicator;
|
||||
} extern values;
|
||||
|
|
Loading…
Reference in a new issue