Fission FSN
Loading...
Searching...
No Matches
gfCShareManager.h
Go to the documentation of this file.
1/********************************************************************
2*
3* File: gfCShareManager.h
4*
5* Purpose: Shares game moments: renders the moment's card
6* (gui/share/<id>.txt), builds its text from strings.xml and
7* hands both to the platform. Genre-neutral: the game fills
8* the moment through a provider.
9*
10* Any layout can share with a button action:
11* action = "share stateStatus"
12* With several targets (Steam builds, desktop save), a
13* gui/share/targets.txt chooser is shown if the game has one;
14* its buttons use action = "shareTarget <targetId>".
15*
16* Strings: share_<id>_text, share_<id>_subject (with {field}),
17* share_getTheGame ("... {url}"), shareTarget_<targetId>,
18* and optional result boxes shareResult_<targetId> ({file},
19* {folder}) and shareResult_failed.
20* Settings: shareStoreLink[_<id>] (default false), shareMeUrl,
21* shareSaveReveal (default true: show saved pictures in
22* Finder / Explorer, which takes focus from the game).
23*
24*********************************************************************/
25
26#ifndef gfCShareManagerhdr
27#define gfCShareManagerhdr
28
29#if defined fsShare
30
31#include <functional>
32#include <map>
33#include <memory>
34#include <string>
35
36#include <fsCore/fsStr.h>
39
41
44
45class fsCBrush;
47class fsCEntity;
48
49struct gfSShareMoment
50{
51 fsStr mId; // picks the layout, strings and file name
52 fsStr mVariant; // optional preferred shape, e.g. "square" or "wide"
53 std::map<std::string, std::string> mFields;
54 std::map<fsStr, std::shared_ptr<fsCBrush>> mImages;
55 fsCResourceName mFallbackImage{"", fsCResourceName::eRES_LOCATION_ASSETS}; // when no card can be drawn
56};
57
58class gfCShareManager : public fsIMessageListener
59{
60public:
61
62 static const fsCUniqueId mShareActionMsg;
63 static const fsCUniqueId mShareTargetActionMsg;
64
65 // Fills the moment for a share button; return false to cancel.
66 using Provider = std::function<fsBool(const fsStr& pMomentId, fsCButtonComponent* pSource, gfSShareMoment& pMoment)>;
67 using DoneCallback = std::function<void(fsShareResult)>;
68
69 // Created on first use and kept for the life of the app.
70 static gfCShareManager* instanceGet();
71
72 // False when nothing can be shared here, or in autotest builds.
73 fsBool availableGet() const;
74
75 void providerRegister(const fsStr& pMomentId, Provider pProvider);
76
77 // Builds the moment from its provider, then shares it or offers the target chooser.
78 void momentShare(const fsStr& pMomentId, fsCButtonComponent* pSource);
79
80 // Hides the chooser's ShareTarget_<id> buttons this build doesn't offer and closes their gaps.
81 void targetChooserPrepare(fsCEntity* pChooser) const;
82
83 // Shares straight away; an empty target means the platform's default.
84 void share(const gfSShareMoment& pMoment, const fsStr& pTargetId = fsStr(), DoneCallback pDone = nullptr);
85
86protected:
87
88 void listenersRegisterDo() override;
89 void listenersDeregisterDo() override;
90 fsBool messageProcessDo(const fsCUniqueId& pMessageType,
91 const fsIMessageDispatcher::sMessageParameters& pParam) override;
92
93private:
94
95 gfCShareManager();
96 ~gfCShareManager() override;
97
98 // Tells the player where a quiet save went, or that it failed (see resultShow in the .cpp).
99 void resultShow(const std::string& pTargetId, fsShareResult pResult, const std::string& pDetail) const;
100 fsShareTarget targetGet(const fsStr& pTargetId) const;
101 fsCResourceName layoutGet(const gfSShareMoment& pMoment, const fsShareTarget& pTarget) const;
102 fsShareRequest requestBuild(const gfSShareMoment& pMoment) const;
103 void deliver(fsShareRequest pRequest, const gfSShareMoment& pMoment, const fsShareTarget& pTarget,
104 const std::string& pCardPath, fsBool pCardSaved, const fsPoint& pCardSize, DoneCallback pDone);
105 void pumpSchedule();
106
107#if !defined fsRELEASE
108 // Dev aid: debugSettings shareTestMoment renders that moment's card (provider called with no
109 // button) a few seconds after start-up, without a share sheet, so cards can be checked unattended.
110 void testCardSchedule(fsS32 pFramesLeft);
111 void testCardRender(const fsStr& pMomentId);
112#endif
113
114 std::unique_ptr<fsShareSheetService> mService;
115 fsCShareCache mCache;
116 std::map<fsStr, Provider> mProviders;
117 gfSShareMoment mChooserMoment;
118 fsS32 mPending = 0;
119 fsBool mPumping = false;
120};
121
122#endif
123
124#endif
Definition fsCBrush.h:26
Definition fsCButtonComponent.h:27
Definition fsCEntity.h:39
@ eRES_LOCATION_ASSETS
Definition fsCResourceName.h:37
Definition fsIMessageListener.h:24
fsShareResult
Definition fsShareTypes.h:33
bool fsBool
Definition fsBaseTypes.h:26
int fsS32
Definition fsBaseTypes.h:20