-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSceneSwitcher.cpp
137 lines (119 loc) · 3.68 KB
/
SceneSwitcher.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <QMainWindow>
#include <QObject>
#include <QMessageBox>
#include <QAbstractButton>
#include <QPushButton>
#include <obs-frontend-api.h>
#include "SC2Data.h"
#include "Observer.h"
#include "SC2State.h"
#include "SceneSwitcher.h"
#include "Constants.h"
#include "Config.h"
#include "obs-util.h"
#include "log.h"
SceneSwitcher::SceneSwitcher(SC2Data *sc2): Observer(sc2){ }
std::string SceneSwitcher::getName() { return "Scene Switcher"; }
void SceneSwitcher::notify(SC2State*& previous, SC2State*& current) {
Config* cfg = Config::Current();
if(cfg->switcherEnabled) {
OBSWeakSource scene;
if(previous->appState != current->appState) {
if(current->appState == APP_LOADING) {
// pre game loading screen
if (previous->appState == APP_MENU) {
if(cfg->switchOnLoad) {
s2log("Loading Screen, entering game. Switching to In Game Scene");
scene = cfg->inGameScene;
}
else {
s2log("Loading Screen, entering game. Switch On Load Disabled - Not Switching");
}
}
}
// entering game
if (current->appState == APP_INGAME && previous->appState != APP_INGAME) {
if (current->gameState == GAME_REPLAY) {
s2log("Entered Replay. Switching to Replay Scene");
scene = cfg->replayScene;
}
else {
s2log("Entered Game. Switching to In Game Scene");
scene = cfg->inGameScene;
}
}
// leaving game
if (current->appState == APP_MENU && previous->appState != APP_MENU) {
s2log("Entered Menus. Finding Menu Scene");
OBSWeakSource tmpScene;
s2log("current->menustate is set: " + std::to_string(current->menuState));
if (current->menuState == MENU_NONE) {
s2log("Menu state is MENU_NONE. Switching to Out of Game Scene");
tmpScene = cfg->outGameScene;
}
else {
s2log("Menustate not MENU_NONE, finding scene");
tmpScene = cfg->menuScenes[current->menuState];
if (!tmpScene) {
s2log("No menu set, using out of game scene");
tmpScene = cfg->outGameScene;
}
}
if(tmpScene) {
s2log("Switching to specified menu Scene");
scene = tmpScene;
}
else {
s2log("No menu scene specified, will not switch");
}
}
}
if (current->appState == APP_MENU && current->menuState != previous->menuState) {
s2log("Menu changed, finding scene");
OBSWeakSource tmpScene2;
if (current->menuState == MENU_NONE) {
s2log("Menu state is MENU_NONE. Switching to Out of Game Scene");
tmpScene2 = cfg->outGameScene;
}
else {
s2log("Menustate not MENU_NONE, finding scene");
tmpScene2 = cfg->menuScenes[current->menuState];
}
if(tmpScene2) {
s2log("Switching to specified menu Scene");
scene = tmpScene2;
}
else {
s2log("No menu scene specified, will not switch");
}
}
if (current->gameState == GAME_OBS && current->appState == APP_INGAME) {
if(current->gameState == GAME_OBS) {
s2log("Detected observer, switching to observer scene");
if(cfg->obsScene) {
scene = cfg->obsScene;
}
else {
s2log("No observer scene found, switching to in game scene");
scene = cfg->inGameScene;
}
}
}
// scene change if necesary
if (scene) {
std::string sceneName = GetWeakSourceName(scene);
s2log("Attempting Scene Switch to: " + sceneName);
obs_source_t *source = obs_weak_source_get_source(scene);
obs_source_t *currentSource = obs_frontend_get_current_scene();
if (source && source != currentSource) {
obs_frontend_set_current_scene(source);
s2log("Switched Scenes");
}
else {
s2log("Could not switch scenes, scene does not exist or already in that scene.");
}
obs_source_release(currentSource);
obs_source_release(source);
}
}
}