Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_RewindComponent.c
Go to the documentation of this file.
1[ComponentEditorProps(category: "GameScripted/GameMode/Components", description: "")]
5
6class SCR_RewindComponent : SCR_BaseGameModeComponent
7{
9 protected const static string s_RewindPointName = "Rewind";
11 protected bool m_bWasRewinded;
12
13 //------------------------------------------------------------------------------------------------
15 static SCR_RewindComponent GetInstance()
16 {
17 BaseGameMode gameMode = GetGame().GetGameMode();
18 if (!gameMode)
19 return null;
20
21 return SCR_RewindComponent.Cast(gameMode.FindComponent(SCR_RewindComponent));
22 }
23
24 //------------------------------------------------------------------------------------------------
32
33 //------------------------------------------------------------------------------------------------
35 bool CanRewind()
36 {
37 return GetGame().GetSaveGameManager().IsSavingEnabled();
38 }
39
40 //------------------------------------------------------------------------------------------------
43 {
44 return m_RewindPoint != null;
45 }
46
47 //------------------------------------------------------------------------------------------------
50 {
51 return m_bWasRewinded;
52 }
53
54 //------------------------------------------------------------------------------------------------
57 {
58 if (!Replication.IsServer() || HasRewindPoint())
59 return;
60
61 GetGame().GetSaveGameManager().RequestSavePoint(ESaveGameType.AUTO, s_RewindPointName, ESaveGameRequestFlags.BLOCKING, new SaveGameOperationCallback(OnRewindPointCreated));
62 }
63
64 //------------------------------------------------------------------------------------------------
65 protected void OnRewindPointCreated(bool success)
66 {
67 if (!success)
68 return;
69
70 m_RewindPoint = GetGame().GetSaveGameManager().GetActiveSave();
72
74 }
75
76 //------------------------------------------------------------------------------------------------
79 {
80 if (!m_RewindPoint)
81 return;
82
83 GetGame().GetSaveGameManager().Delete(m_RewindPoint);
84 }
85
86 //------------------------------------------------------------------------------------------------
87 protected void OnRewindDeleted()
88 {
89 if (!m_RewindPoint)
90 return;
91
92 m_RewindPoint = null;
94
96 }
97
98 //------------------------------------------------------------------------------------------------
100 void Rewind()
101 {
102 if (!m_RewindPoint)
103 return;
104
105 GetGame().GetSaveGameManager().Load(m_RewindPoint);
106 }
107
108 //------------------------------------------------------------------------------------------------
109 override void OnPostInit(IEntity owner)
110 {
111 if (SCR_Global.IsEditMode(owner))
112 return;
113
114 const SaveGameManager manager = GetGame().GetSaveGameManager();
115 EventProvider.ConnectEvent(manager.OnSaveCreated, OnSavedCreated);
116 EventProvider.ConnectEvent(manager.OnSaveDeleted, OnSaveDeleted);
117
118 // When loading a rewind we remember it to pause game time later, but delete it anyway. If user hits play again it will make a new rewind point
119 const SaveGame save = manager.GetActiveSave();
120 m_bWasRewinded = save && IsRewindPoint(save);
122 }
123
124 //------------------------------------------------------------------------------------------------
125 override void OnDelete(IEntity owner)
126 {
127 if (SCR_Global.IsEditMode(owner))
128 return;
129
130 EventProvider.DisconnectEvent(GetGame().GetSaveGameManager().OnSaveCreated, OnSavedCreated);
133 }
134
135 //------------------------------------------------------------------------------------------------
138 {
139 const SaveGameManager manager = GetGame().GetSaveGameManager();
140 manager.GetSaves(manager.GetCurrentMissionResource(), new SaveGameObtainCallback(ProcessRemoveUnusedRewindPoints));
141 }
142
143 //------------------------------------------------------------------------------------------------
144 protected void ProcessRemoveUnusedRewindPoints(bool success, array<SaveGame> saves)
145 {
146 const SaveGameManager manager = GetGame().GetSaveGameManager();
147 const int currentPlaythrough = manager.GetCurrentPlaythroughNumber();
148 const SaveGame activeSave = manager.GetActiveSave();
149 foreach (SaveGame save : saves)
150 {
151 if (save != activeSave && (save.GetPlaythroughNumber() == currentPlaythrough) && IsRewindPoint(save))
152 manager.Delete(save);
153 }
154 }
155
156 //------------------------------------------------------------------------------------------------
157 bool IsRewindPoint(notnull const SaveGame save)
158 {
159 return (save == m_RewindPoint) || (save.GetType() == ESaveGameType.AUTO && save.GetSavePointName() == s_RewindPointName);
160 }
161
162 //------------------------------------------------------------------------------------------------
163 [ReceiverAttribute()]
164 protected void OnSavedCreated(SaveGame save)
165 {
166 if (save && save.GetType() == ESaveGameType.MANUAL)
168 }
169
170 //------------------------------------------------------------------------------------------------
171 [ReceiverAttribute()]
172 protected void OnSaveDeleted(SaveGame save)
173 {
174 if (save == m_RewindPoint)
176 }
177}
178
179class SCR_RewindDialog : SCR_ConfigurableDialogUi
180{
181 //------------------------------------------------------------------------------------------------
182 void SCR_RewindDialog()
183 {
184 SCR_ConfigurableDialogUi.CreateFromPreset(SCR_CommonDialogs.DIALOGS_CONFIG, "rewind", this);
185 }
186
187 //------------------------------------------------------------------------------------------------
188 override void OnConfirm()
189 {
190 SCR_RewindComponent.GetInstance().Rewind();
191 }
192}
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
void SCR_BaseGameModeComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
SaveGame m_RewindPoint
bool IsRewindPoint(notnull const SaveGame save)
void CreateRewindPoint()
Create a rewind point for this session.
void OnSavedCreated(SaveGame save)
void RemoveUnusedRewindPoints()
Remove any rewind points that were not cleaned up from last playthrough.
void Rewind()
Rewind to existing rewind point of this session.
void OnRewindDeleted()
void OnSaveDeleted(SaveGame save)
void DeleteRewindPoint()
Remove existing rewind point for this session.
bool HasRewindPoint()
bool m_bWasRewinded
void ProcessRemoveUnusedRewindPoints(bool success, array< SaveGame > saves)
bool CanRewind()
bool WasRewinded()
ScriptInvokerVoid GetOnRewindPointChanged()
SCR_RewindComponentClass m_OnRewindPointChanged
void OnRewindPointCreated(bool success)
ScriptInvokerBase< ScriptInvokerVoidMethod > ScriptInvokerVoid
Class for broadcasting events to registered receivers.
static proto bool ConnectEvent(func eventSender, func eventReceiver)
static proto bool DisconnectEvent(func eventSender, func eventReceiver)
Main replication API.
Definition Replication.c:14
static SCR_ConfigurableDialogUi CreateFromPreset(ResourceName presetsResourceName, string tag, SCR_ConfigurableDialogUi customDialogObj=null)
Creates a dialog from preset.
static bool IsEditMode()
Definition Functions.c:1566
ESaveGameRequestFlags
ESaveGameType