@StoreClass.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. /******************************************************************************/
  2. /******************************************************************************/
  3. class StoreClass : ClosableWindow
  4. {
  5. static Str ItemPath(int item_id);
  6. static Str ItemRes (int item_id, C Str&file, C Str&name);
  7. class Item
  8. {
  9. class ItemFile
  10. {
  11. bool free;
  12. Str name, file;
  13. public:
  14. ItemFile();
  15. };
  16. class Temp
  17. {
  18. bool ready;
  19. int cat, sub_cat, price, computer_id,
  20. subscription; // number of days, 30=month, 365=year
  21. Str name, video, icon, image[3], desc_short, desc;
  22. Memc<ItemFile> files;
  23. void reset();
  24. Temp(C TextNode &node);
  25. public:
  26. Temp();
  27. };
  28. static void SetFiles(MemPtr<ItemFile>files, C TextNode&node);
  29. static bool XmlChar(char c);
  30. static Str DecodeText(C Str &str);
  31. bool requested_details, has_details, like, uses_computer_id, uses_github_account, has_temp;
  32. int id, price, category, sub_category, purchased, popularity, author, likes, sold, developer_discount, subscription;
  33. Str name, desc_short, desc, video, price_text, icon_path, time_ago, image_path[3], developer_name, developer_paypal, developer_support, license_keys;
  34. DateTime date_added, developer_date_joined;
  35. ImagePtr icon;
  36. Memc<ItemFile> files;
  37. Temp temp;
  38. Item();
  39. Str buyText(bool include_price)C;
  40. bool isNew(); // if haven't been published yet
  41. void getDetails(bool force=false);
  42. Temp& setTemp();
  43. void setIcon(bool force=false);
  44. void setPrice(int price);
  45. Item(C TextNode &node);
  46. void setDetails(C TextData &data);
  47. };
  48. class NewItem : ClosableWindow
  49. {
  50. Text t_name, terms;
  51. TextLine name;
  52. Button b_create;
  53. TextBlack ts;
  54. static void Create(NewItem &new_item);
  55. ClosableWindow& create();
  56. virtual ClosableWindow& rect(C Rect &rect)override;
  57. virtual ClosableWindow& show()override;
  58. virtual void update(C GuiPC &gpc)override;
  59. };
  60. class Login : ClosableWindow
  61. {
  62. Text t_email, t_pass;
  63. TextLine email, pass;
  64. Button login, forgot_pass, terms;
  65. static void LoginDo (Login &login);
  66. static void ForgotPass(Login &login);
  67. static void Cancel (Login &login);
  68. static void ShowTerms (Login &login);
  69. ClosableWindow& create();
  70. virtual ClosableWindow& rect(C Rect &rect)override;
  71. virtual ClosableWindow& show()override;
  72. virtual void update(C GuiPC &gpc)override;
  73. };
  74. class Register : ClosableWindow
  75. {
  76. Text text;
  77. Button yes, cancel;
  78. static void Yes (Register &reg);
  79. static void Cancel(Register &reg);
  80. Register& create(C Vec2 &pos);
  81. Register& activate();
  82. };
  83. class ConfirmPayPal : ClosableWindow
  84. {
  85. Text text;
  86. TextLine paypal;
  87. TextBlack ts;
  88. Button confirm;
  89. static void Confirm(ConfirmPayPal &cp);
  90. ConfirmPayPal& create();
  91. void setPos();
  92. ConfirmPayPal& activate()override;
  93. virtual void update(C GuiPC &gpc)override;
  94. };
  95. class BecomeSeller : ClosableWindow
  96. {
  97. TextNoTest text;
  98. TextBlack ts;
  99. Button engine_license;
  100. static void EngineLicense(BecomeSeller &bs);
  101. BecomeSeller& create(C Vec2 &pos);
  102. };
  103. class Contribute : ClosableWindow
  104. {
  105. Text text;
  106. TextBlack ts;
  107. TextLine amount;
  108. Button contribute;
  109. static void Buy(Contribute &contr);
  110. ClosableWindow& create();
  111. virtual void update(C GuiPC &gpc)override;
  112. };
  113. class ItemList : List<Item>
  114. {
  115. virtual void draw(C GuiPC &gpc)override;
  116. };
  117. const_mem_addr class Purchase
  118. {
  119. Str license_key;
  120. Text t_license_key;
  121. Button copy, set_computer_id, set_github_account;
  122. static void Copy(Purchase &p);
  123. void create(GuiObj &parent, C Str &license_key, bool computer_id, bool github_account);
  124. };
  125. const_mem_addr class DownloadFile : Window
  126. {
  127. class WindowIOEx : WindowIO
  128. {
  129. static void Hidden(WindowIOEx &w);
  130. virtual WindowIO& hide()override;
  131. };
  132. class ProgressNoTest : Progress
  133. {
  134. virtual GuiObj* test(C GuiPC &gpc, C Vec2 &pos, GuiObj* &mouse_wheel)override;
  135. };
  136. bool saved, temp;
  137. int item_id;
  138. Str file, dest;
  139. WindowIOEx win_io;
  140. Download down;
  141. long file_size;
  142. DateTime file_modify_time;
  143. File file_done;
  144. ProgressNoTest progress;
  145. Button open, import, retry, cancel;
  146. Text text;
  147. TextBlack ts;
  148. static void Open (DownloadFile &df); // explore file and delete window
  149. static void Import(DownloadFile &df); // open CopyElms and delete window
  150. static void Cancel(DownloadFile &df); // delete
  151. static void Retry(DownloadFile &df);
  152. void download(bool resume);
  153. static void Select(C Str &name, DownloadFile &df);
  154. void select(C Str &name);
  155. bool valid()C;
  156. void create(int item_id, C Str &file, bool temp);
  157. virtual void update(C GuiPC &gpc)override;
  158. public:
  159. DownloadFile();
  160. };
  161. const_mem_addr class ItemFile
  162. {
  163. Str name, file;
  164. bool temp, is_free;
  165. Button download, rename, remove, free;
  166. static bool ItemDownloadable();
  167. static void Download(ItemFile &df);
  168. static void Rename (ItemFile &df);
  169. static void Remove (ItemFile &df);
  170. static void SetFree(ItemFile &df);
  171. void create(GuiObj &parent, C Item::ItemFile &file, bool temp=false);
  172. public:
  173. ItemFile();
  174. };
  175. class RenameFile : ClosableWindow
  176. {
  177. TextLine new_name;
  178. Str file, name;
  179. static void OK(RenameFile &rf);
  180. void ok();
  181. RenameFile& create(C Vec2 &pos);
  182. RenameFile& activate(ItemFile &df);
  183. virtual void update(C GuiPC &gpc)override;
  184. };
  185. class RemoveFile : ClosableWindow
  186. {
  187. Text t_name;
  188. Button ok;
  189. Str file;
  190. static void OK(RemoveFile &fr);
  191. void activate(ItemFile &df);
  192. RemoveFile& create(C Vec2 &pos);
  193. };
  194. class PublishConfirm : ClosableWindow
  195. {
  196. Text text;
  197. Button ok;
  198. static void OK(PublishConfirm &pc);
  199. void publish();
  200. PublishConfirm& create(C Vec2 &pos);
  201. };
  202. const_mem_addr class Upload
  203. {
  204. bool chunked;
  205. Download down;
  206. File src;
  207. Progress progress;
  208. TextBlack ts;
  209. Text text;
  210. Button cancel;
  211. int item_id, index;
  212. long sent;
  213. GuiObj *dest;
  214. Str set, display, item_file, name;
  215. Memc<HTTPParam> params;
  216. static void Cancel(Upload &up);
  217. void create(GuiObj &parent, int item_id, C Str &name, C Str &display=S);
  218. void rect(C Rect &rect);
  219. void pos(C Vec2 &pos);
  220. bool checkChunked();
  221. void update();
  222. void transfer();
  223. bool visible()C;
  224. void visible(bool on);
  225. public:
  226. Upload();
  227. };
  228. class ItemImage : GuiImage
  229. {
  230. bool editable, hoverable;
  231. void setEditable(bool editable);
  232. ItemImage& create(bool hoverable=false);
  233. virtual GuiObj* test(C GuiPC &gpc, C Vec2 &pos, GuiObj* &mouse_wheel)override;
  234. virtual void draw(C GuiPC &gpc)override;
  235. public:
  236. ItemImage();
  237. };
  238. class Line : GuiCustom
  239. {
  240. virtual void draw(C GuiPC &gpc)override;
  241. };
  242. static void ItemWebsite(StoreClass &store);
  243. static void ItemVideo(StoreClass &store);
  244. static void ItemCID(StoreClass &store);
  245. static void ItemLike(StoreClass &store);
  246. static void ItemRefresh(StoreClass &store);
  247. static void ItemPublish(StoreClass &store);
  248. static void ItemCategory(StoreClass &store);
  249. static void Buy(StoreClass &store);
  250. static void DeveloperPage(StoreClass &store);
  251. static void Back(StoreClass &store);
  252. static void Filter(StoreClass &store);
  253. static void Readies(StoreClass &store);
  254. static bool Check(Download &down);
  255. static Str MD5Text(C Str8 &text);
  256. static void SetUserParams(MemPtr<HTTPParam> params, C Str&user, C Str&password, int key, C Str&cmd=S);
  257. static void OpenSupport(C Str &support);
  258. static void ItemSupport(StoreClass &store);
  259. static void DevSupport(StoreClass &store);
  260. static void CloseDevPage(StoreClass &store);
  261. static void Account(StoreClass &store);
  262. static void NewItemDo(StoreClass &store);
  263. static void LoginToggle(StoreClass &store);
  264. static void Logout(StoreClass &store);
  265. static cchar8 *categories_t[]
  266. ;
  267. static cchar8 *source_code_cats[]
  268. ;
  269. static cchar8 *game_cats[]
  270. ;
  271. static cchar8 *asset_cats[]
  272. ;
  273. static cchar8 *item_t[]
  274. ;
  275. Button purchased, readies, back;
  276. Tabs categories, sub_categories[5],
  277. mode, // item_list, item_details (this is invisible)
  278. item_tabs; // images, files
  279. Memc<Item> items;
  280. ItemList items_list;
  281. Region items_region, item_files_region, item_desc_region;
  282. Memx<Purchase> item_purchases;
  283. Memx<ItemFile> item_files;
  284. Memx<DownloadFile> download_files;
  285. bool downloaded, dev_editable, item_editable;
  286. Memx<Download> store_commands;
  287. Memx<Upload> store_uploads;
  288. bool user_seller;
  289. int user_id, user_key, user_discount, cur_item, cur_dev, cur_dev_discount;
  290. flt item_files_region_height;
  291. Str user_name, cur_dev_name, user_email, login_email, user_pass, login_pass, user_support, cur_dev_support, user_paypal, cur_dev_paypal;
  292. DateTime user_date;
  293. Text hello_user, t_item_name, t_item_developer, t_item_sold, t_item_likes, t_item_video, t_item_desc, t_item_id, t_item_date, t_item_support, t_item_price, t_item_cid, t_dev_name, t_dev_paypal, t_dev_support, t_dev_date, t_dev_discount, t_new_files;
  294. TextLine filter_name, e_dev_name, e_dev_paypal, e_dev_support, e_dev_discount, e_item_name, e_item_video, e_item_desc, e_item_price;
  295. CheckBox item_cid;
  296. ComboBox item_category;
  297. TextBlack ts_name, ts_dev_name, ts_desc, ts_stats;
  298. ItemImage item_icon, item_images[3];
  299. Button b_new_item, b_login, b_logout, account, item_www, item_developer, item_like, item_video, buy, item_refresh, item_support, item_publish, dev_support, close_dev_page;
  300. Line line;
  301. ImagePtr ok_image, fail_image;
  302. Login login;
  303. Register _register;
  304. BecomeSeller become_seller;
  305. ConfirmPayPal confirm_paypal;
  306. Contribute contribute;
  307. RenameFile rename_file;
  308. RemoveFile remove_file;
  309. PublishConfirm publish_confirm;
  310. NewItem new_item;
  311. MemberDesc price_sort, date_sort;
  312. ImagePtr image_preview;
  313. flt image_preview_step;
  314. Node<MenuElm> categories_node;
  315. Item* findItem(int id);
  316. bool loggedIn()C;
  317. bool isAdmin()C;
  318. bool isPurchased(int id);
  319. bool isSeller()C;
  320. void clearDownloadFiles();
  321. void setUserParams(MemPtr<HTTPParam> params, C Str &cmd);
  322. void sendCommand(C Str &cmd, C Str &name=S, C Str &value=S, C Str&name2=S, C Str &value2=S, C Str&name3=S, C Str&value3=S);
  323. void sendCommandPost(C Str &cmd, C Str &name, C Str &value, C Str&post_name, C Str &post_value);
  324. void setLogin();
  325. void loginDo(int mode, C Str &email, C Str &pass);
  326. void logout();
  327. void setCategory(int cat, int sub);
  328. void getCategory(int &cat, int &sub);
  329. void create();
  330. virtual Rect sizeLimit()C override;
  331. void filter();
  332. void setFilesRects();
  333. void setDescSize();
  334. virtual Window& rect(C Rect &rect)override;
  335. void downloadItems();
  336. virtual Window& show()override;
  337. void setItemImages(Item &item);
  338. void setItemDetails(Item &item);
  339. void refreshDev();
  340. void openDeveloper(int id, C Str &name=S, C Str &support=S, C Str &paypal=S, C DateTime &date=DateTime().zero(), int discount=0);
  341. void openItem(int id);
  342. void itemGotDetails(Item &item);
  343. bool itemCanUploadFile(Item &item, C Str &file);
  344. void drop(Memc<Str> &names, GuiObj *obj, C Vec2 &screen_pos);
  345. virtual void update(C GuiPC &gpc)override;
  346. virtual void draw(C GuiPC &gpc)override;
  347. public:
  348. StoreClass();
  349. };
  350. /******************************************************************************/
  351. /******************************************************************************/
  352. extern StoreClass AppStore;
  353. /******************************************************************************/