Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
GUI_RepositorySelector.h
Go to the documentation of this file.
1/*
2 This source file is part of Rigs of Rods
3 Copyright 2005-2012 Pierre-Michel Ricordel
4 Copyright 2007-2012 Thomas Fischer
5 Copyright 2013-2021 Petr Ohlidal
6
7 For more information, see http://www.rigsofrods.org/
8
9 Rigs of Rods is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License version 3, as
11 published by the Free Software Foundation.
12
13 Rigs of Rods is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20*/
21
26
27#pragma once
28
29#include "Application.h"
30#include "BBDocument.h"
31#include "OgreImGui.h" // ImVec4
32
33#include <future>
34#include <memory>
35#include <thread>
36#include <vector>
37#ifdef USE_CURL
38# include <curl/curl.h>
39#endif //USE_CURL
40
41namespace RoR {
42
44 {
45 // Only one should be set!
47 int attachment_id = -1;
48 // attachment extras
49 std::string attachment_ext;
50 // thumb extras
52 std::string thumb_url;
53 };
54
57 {
58 // rfir_ prefix: RepoFileInstallRequest
62 std::string rfir_filename;
63 std::string rfir_filepath; // Custom path needed for updates (overwrite existing file)
64 int rfir_filesize_bytes = 0; // For display only
65 };
66
67 // This will be removed during OGRE14 migration
68 struct RepoImageRequestHandler: public Ogre::WorkQueue::RequestHandler
69 {
70 Ogre::WorkQueue::Response* handleRequest(const Ogre::WorkQueue::Request* req, const Ogre::WorkQueue* srcQ) override;
71 };
72
73 // `Ogre::Any` holder requires the `<<` operator to be implemented, otherwise it won't compile. ~ This will also be removed during OGRE14 migration
74 inline std::ostream& operator<<(std::ostream& os, RepoImageDownloadRequest& val)
75 {
76 return os;
77 }
78
79namespace GUI {
80
89
91{
93 std::string title;
94 std::string tag_line;
95 std::string icon_url;
96 std::string authors;
97 std::string version;
104 std::string view_url;
107 Ogre::TexturePtr preview_tex;
108
109 // Repo UI state:
112};
113
116
123
132
134{
135 std::vector<ResourceItem> items;
136 std::vector<ResourceCategories> categories;
137 std::vector<ResourceFiles> files;
138};
139
140typedef std::map<int, Ogre::TexturePtr> RepoAttachmentsMap;
141
143
145{
146public:
147 const float ATTACH_MAX_WIDTH = 160.f;
148 const float ATTACH_MAX_HEIGHT = 90.f;
149 const float ATTACH_SPINNER_RADIUS = 20.f;
150 const ImVec2 ATTACH_SPINNER_PADDING = ImVec2(55.f, 25.f);
151 const ImVec4 RESOURCE_TITLE_COLOR = ImVec4(1.f, 1.f, 0.7f, 1.f);
152 const ImVec4 RESOURCE_INSTALL_BTN_COLOR = ImVec4(0.830, 0.655, 0.174, 1.f);
153
156
157 void SetVisible(bool visible);
158 bool IsVisible() const { return m_is_visible; }
159 void Draw();
160 void DrawGalleryView();
161 void DrawResourceView(float searchbox_x);
163 void OpenResource(int resource_id);
164 void RequestInstallRepoFile(int resource_id, int datafile_pos, std::string filepath);
167 void NotifyRepoFileUninstalled(std::string const& filename);
168 void Refresh();
171 void ShowError(CurlFailInfo* failinfo);
172 void DrawThumbnail(ResourceItemArrayPos_t resource_arraypos, ImVec2 image_size, float spinner_size, ImVec2 spinner_cursor);
173 static void DownloadImage(RepoImageDownloadRequest* request);
175 void DrawResourceDescriptionBBCode(const ResourceItem& item, ImVec2 panel_screenpos, ImVec2 panel_size);
176 void DrawAttachment(BBCodeDrawingContext* context, int attachment_id);
177 void DownloadAttachment(int attachment_id, std::string const& attachment_ext);
180
181private:
184 bool CheckRepoFileIsInstalled(ResourceFiles& resfile, std::string& out_filepath);
185
186 bool m_is_visible = false;
187 bool m_draw = false;
195 bool m_show_spinner = false;
196 std::string m_current_sort = "Last Update";
197 std::string m_view_mode = "List";
199 Ogre::TexturePtr m_fallback_thumbnail;
202 std::vector<RepoFileInstallRequest> m_queued_install_requests;
204
205 // This will be removed during OGRE14 migration
206 Ogre::uint16 m_ogre_workqueue_channel = 0;
208
209 // status or error messages
210 std::string m_repofiles_msg;
211 std::string m_repolist_msg;
213 std::string m_repolist_curlmsg;
214 std::string m_repolist_httpmsg;
215};
216
217}// namespace GUI
218}// namespace RoR
Central state/object manager and communications hub.
RepoAttachmentsMap m_repo_attachments
Fully loaded images in memory.
void InstallDownloadedRepoFile(MsgType result, RepoFileInstallRequest *request)
void DrawAttachment(BBCodeDrawingContext *context, int attachment_id)
void DrawResourceDescriptionBBCode(const ResourceItem &item, ImVec2 panel_screenpos, ImVec2 panel_size)
bool CheckRepoFileIsInstalled(ResourceFiles &resfile, std::string &out_filepath)
void RequestInstallRepoFile(int resource_id, int datafile_pos, std::string filepath)
RepoFileInstallRequestID_t GetNextInstallRequestId()
void NotifyRepoFileUninstalled(std::string const &filename)
void QueueInstallRepoFile(RepoFileInstallRequest *request)
void DrawThumbnail(ResourceItemArrayPos_t resource_arraypos, ImVec2 image_size, float spinner_size, ImVec2 spinner_cursor)
std::string m_repolist_curlmsg
Displayed as dimmed text.
RepoFileInstallRequestID_t m_next_install_request_id
ResourceItemArrayPos_t m_resourceview_item_arraypos
RepoImageRequestHandler m_repo_image_request_handler
RepoFileInstallRequestID_t m_active_install_request_id
std::string m_repolist_httpmsg
Displayed as dimmed text.
void ShowError(CurlFailInfo *failinfo)
void DownloadBBCodeAttachmentsRecursive(const bbcpp::BBNode &parent)
void DownloadAttachment(int attachment_id, std::string const &attachment_ext)
void UpdateResources(ResourcesCollection *data)
void LoadDownloadedImage(RepoImageDownloadRequest *request)
To be run on main thread.
void UpdateResourceFilesAndDescription(ResourcesCollection *data)
static void DownloadImage(RepoImageDownloadRequest *request)
To be run on background via Ogre WorkQueue.
std::vector< RepoFileInstallRequest > m_queued_install_requests
Wrapper for classic c-string (local buffer) Refresher: strlen() excludes '\0' terminator; strncat() A...
Definition Str.h:36
MsgType
Global gameplay message loop, see struct Message in GameContext.h.
Definition Application.h:76
const int RESOURCEITEMARRAYPOS_INVALID
std::map< int, Ogre::TexturePtr > RepoAttachmentsMap
Maps attachment ID to Ogre::TexturePtr.
static const RepoFileInstallRequestID_t REPOFILEINSTALLREQUESTID_INVALID
Invalid ID for repository item installation request.
int RepoFileInstallRequestID_t
Unique sequentially generated ID of a repository item installation request; use GUI::RepositorySelect...
std::ostream & operator<<(std::ostream &os, RepoImageDownloadRequest &val)
std::shared_ptr< BBDocument > BBDocumentPtr
Definition BBDocument.h:65
ResFileInstallStatus cached_install_status
std::string cached_install_path
Valid if cached_install_status == RFIS_INSTALLED
bool attachments_dl_queued
Attachments are requested in bulk on first display.
bbcpp::BBDocumentPtr description
std::vector< ResourceItem > items
std::vector< ResourceCategories > categories
std::vector< ResourceFiles > files
Payload for MSG_NET_INSTALL_REPOFILE_REQUEST message - also used for update (overwrites existing)
RepoFileInstallRequestID_t rfir_install_request_id
Ogre::WorkQueue::Response * handleRequest(const Ogre::WorkQueue::Request *req, const Ogre::WorkQueue *srcQ) override