Skip to content

Commit 55346af

Browse files
committed
Add shortcuts to cycle though screen layouts
1 parent b2f85f7 commit 55346af

File tree

5 files changed

+41
-12
lines changed

5 files changed

+41
-12
lines changed

src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,10 @@ pub fn actual_main() {
505505
key_map.store(keymap, Ordering::Relaxed);
506506
false
507507
}
508+
PresentEvent::CycleScreenLayout { offset, swap } => {
509+
screen_layout = screen_layout.apply_settings_event(offset, swap);
510+
false
511+
}
508512
PresentEvent::Pause => true,
509513
PresentEvent::Quit => {
510514
running = false;

src/presenter/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub const PRESENTER_SCREEN_HEIGHT: u32 = 544;
1919

2020
pub enum PresentEvent {
2121
Inputs { keymap: u32, touch: Option<(i16, i16)> },
22+
CycleScreenLayout { offset: i8, swap: bool },
2223
Pause,
2324
Quit,
2425
}

src/presenter/vita.rs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ pub struct Presenter {
8888
presenter_audio: PresenterAudio,
8989
touch_points: Option<(i16, i16)>,
9090
keymap: u32,
91-
was_psn_btn_pressed: bool,
91+
pressed_btn: u32,
92+
show_pause: bool,
9293
}
9394

9495
impl Presenter {
@@ -119,7 +120,8 @@ impl Presenter {
119120
presenter_audio: PresenterAudio::new(),
120121
touch_points: None,
121122
keymap: 0xFFFFFFFF,
122-
was_psn_btn_pressed: false,
123+
pressed_btn: 0,
124+
show_pause: true,
123125
};
124126

125127
init_ui(&mut instance);
@@ -133,11 +135,28 @@ impl Presenter {
133135
let mut pressed = pressed.assume_init();
134136
sceCtrlPeekBufferPositive(0, &mut pressed, 1);
135137

138+
let previous_pressed_btn = self.pressed_btn;
139+
self.pressed_btn = pressed.buttons;
140+
136141
if pressed.buttons & SCE_CTRL_PSBUTTON != 0 {
137-
self.was_psn_btn_pressed = true;
138-
} else if self.was_psn_btn_pressed {
139-
self.was_psn_btn_pressed = false;
140-
return PresentEvent::Pause;
142+
const SHORTCUT_EVENTS: [(PresentEvent, SceCtrlButtons); 3] = [
143+
(PresentEvent::CycleScreenLayout { offset: -1, swap: false }, SCE_CTRL_LTRIGGER),
144+
(PresentEvent::CycleScreenLayout { offset: 1, swap: false }, SCE_CTRL_RTRIGGER),
145+
(PresentEvent::CycleScreenLayout { offset: 0, swap: true }, SCE_CTRL_CROSS),
146+
];
147+
148+
for (event, button) in SHORTCUT_EVENTS {
149+
if previous_pressed_btn & button != 0 && pressed.buttons & button == 0 {
150+
self.show_pause = false;
151+
return event;
152+
}
153+
}
154+
} else if previous_pressed_btn & SCE_CTRL_PSBUTTON != 0 {
155+
if self.show_pause {
156+
return PresentEvent::Pause;
157+
} else {
158+
self.show_pause = true;
159+
}
141160
}
142161

143162
for (host_key, guest_key) in KEY_CODE_MAPPING {
@@ -197,16 +216,17 @@ impl Presenter {
197216
}
198217
}
199218

200-
pub fn on_game_launched(&self) {
201-
unsafe { sceShellUtilLock(SCE_SHELL_UTIL_LOCK_TYPE_PS_BTN | SCE_SHELL_UTIL_LOCK_TYPE_PS_BTN_2) };
219+
pub fn on_game_launched(&mut self) {
220+
self.show_pause = true;
221+
unsafe { sceShellUtilLock(SCE_SHELL_UTIL_LOCK_TYPE_PS_BTN | SCE_SHELL_UTIL_LOCK_TYPE_QUICK_MENU | SCE_SHELL_UTIL_LOCK_TYPE_USB_CONNECTION | SCE_SHELL_UTIL_LOCK_TYPE_PS_BTN_2) };
202222
}
203223

204224
pub fn present_pause(&mut self, gpu_renderer: &GpuRenderer, settings: &mut Settings) -> UiPauseMenuReturn {
205-
unsafe { sceShellUtilUnlock(SCE_SHELL_UTIL_LOCK_TYPE_PS_BTN | SCE_SHELL_UTIL_LOCK_TYPE_PS_BTN_2) };
225+
unsafe { sceShellUtilUnlock(SCE_SHELL_UTIL_LOCK_TYPE_PS_BTN | SCE_SHELL_UTIL_LOCK_TYPE_QUICK_MENU | SCE_SHELL_UTIL_LOCK_TYPE_USB_CONNECTION | SCE_SHELL_UTIL_LOCK_TYPE_PS_BTN_2) };
206226
let ret = show_pause_menu(self, gpu_renderer, settings);
207227
match ret {
208228
UiPauseMenuReturn::Resume => unsafe {
209-
sceShellUtilLock(SCE_SHELL_UTIL_LOCK_TYPE_PS_BTN | SCE_SHELL_UTIL_LOCK_TYPE_PS_BTN_2);
229+
sceShellUtilLock(SCE_SHELL_UTIL_LOCK_TYPE_PS_BTN | SCE_SHELL_UTIL_LOCK_TYPE_QUICK_MENU | SCE_SHELL_UTIL_LOCK_TYPE_USB_CONNECTION | SCE_SHELL_UTIL_LOCK_TYPE_PS_BTN_2);
210230
},
211231
_ => {}
212232
}

src/screen_layouts.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ impl ScreenLayout {
8080
}
8181
}
8282

83+
pub fn apply_settings_event(&self, offset: i8, swap: bool) -> ScreenLayout {
84+
ScreenLayout::new((self.index as isize + offset as isize) as usize % SCREEN_LAYOUTS.len(), self.swap ^ swap)
85+
}
86+
8387
pub fn get_bottom_inverse_mtx(&self) -> &[f32; 9] {
8488
&SCREEN_LAYOUTS[self.index][if self.swap { 2 } else { 3 }]
8589
}

src/settings.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ impl Setting {
158158
lazy_static! {
159159
pub static ref DEFAULT_SETTINGS: Settings = Settings(
160160
[
161-
Setting::new("Screen Layout", "", ScreenLayout::settings_value(), true),
162-
Setting::new("Swap screens", "", SettingValue::Bool(false), true),
161+
Setting::new("Screen Layout", "Press PS + L Trigger or PS + R Trigger to cycle through layouts in game.", ScreenLayout::settings_value(), true),
162+
Setting::new("Swap screens", "Press PS + X to swap screens in game.", SettingValue::Bool(false), true),
163163
Setting::new("Language", "Some ROMs only come with one language. Make sure yours is multilingual.", Language::iter().into(), false),
164164
Setting::new("Framelimit", "Limits gamespeed to 60fps", SettingValue::Bool(true), true),
165165
Setting::new("Audio", "Disabling audio can give a performance boost", SettingValue::Bool(true), true),

0 commit comments

Comments
 (0)