1 /* 2 Copyright (C) 2000-2013 The Exult Team 3 4 This program is free software; you can redistribute it and/or 5 modify it under the terms of the GNU General Public License 6 as published by the Free Software Foundation; either version 2 7 of the License, or (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, write to the Free Software 16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 */ 18 19 #ifndef NEWFILE_GUMP_H 20 #define NEWFILE_GUMP_H 21 22 #include "Modal_gump.h" 23 #include <array> 24 #include <memory> 25 26 class Shape_file; 27 class Image_buffer; 28 29 #define MAX_SAVEGAME_NAME_LEN 0x50 30 31 struct SaveGame_Details { 32 // Time that the game was saved (needed????) 33 char real_minute; // 1 34 char real_hour; // 2 35 char real_day; // 3 36 char real_month; // 4 37 short real_year; // 6 38 39 // The Game Time that the save was done at 40 char game_minute; // 7 41 char game_hour; // 8 42 short game_day; // 10 43 44 short save_count; // 12 45 char party_size; // 13 46 47 char unused; // 14 Quite literally unused 48 49 char real_second; // 15 50 51 //Incase we want to add more later 52 char reserved0; // 16 53 char reserved1[48]; // 64 54 }; 55 56 struct SaveGame_Party { 57 char name[18]; // 18 58 short shape; // 20 59 unsigned int exp; // 24 60 unsigned int flags; // 28 61 unsigned int flags2; // 32 62 63 unsigned char food; // 33 64 unsigned char str; // 34 65 unsigned char combat; // 35 66 unsigned char dext; // 36 67 unsigned char intel; // 37 68 unsigned char magic; // 38 69 unsigned char mana; // 39 70 unsigned char training; // 40 71 short health; // 42 72 73 short shape_file; // 44 74 75 //Incase we want to add more later 76 int reserved1; // 48 77 int reserved2; // 52 78 int reserved3; // 56 79 int reserved4; // 60 80 int reserved5; // 64 81 }; 82 83 /* 84 * The file save/load box: 85 */ 86 class Newfile_gump : public Modal_gump { 87 88 public: 89 struct SaveInfo { 90 91 int num = 0; 92 char *filename = nullptr; 93 char *savename = nullptr; 94 bool readable = true; 95 SaveGame_Details *details = nullptr; 96 SaveGame_Party *party = nullptr; 97 std::unique_ptr<Shape_file> screenshot; 98 99 static int CompareGames(const void *a, const void *b); 100 int CompareThis(const SaveInfo *other) const; 101 void SetSeqNumber(); 102 103 ~SaveInfo(); 104 }; 105 106 protected: 107 enum button_ids { 108 id_first = 0, 109 id_load = id_first, 110 id_save, 111 id_delete, 112 id_close, 113 id_page_up, 114 id_line_up, 115 id_line_down, 116 id_page_down, 117 id_count 118 }; 119 std::array<std::unique_ptr<Gump_button>, id_count> buttons; 120 121 static const short btn_cols[5]; // x-coord of each button. 122 static const short btn_rows[5]; // y-coord of each button. 123 124 // Text field info 125 static const short fieldx; // Start Y of each field 126 static const short fieldy; // Start X of first 127 static const short fieldw; // Width of each field 128 static const short fieldh; // Height of each field 129 static const short fieldgap; // Gap between fields 130 static const short fieldcount; // Number of fields 131 static const short textx; // X Offset in field 132 static const short texty; // Y Offset in field 133 static const short textw; // Maximum allowable width of text 134 static const short iconx; // X Offset in field 135 static const short icony; // Y Offset in field 136 137 // Scrollbar and Slider Info 138 static const short scrollx; // X Offset 139 static const short scrolly; // Y Offset 140 static const short scrollh; // Height of Scroll Bar 141 static const short sliderw; // Width of Slider 142 static const short sliderh; // Height of Slider 143 144 // Side Text 145 static const short infox; // X Offset for info 146 static const short infoy; // Y Offset for info 147 static const short infow; // Width of info box 148 static const short infoh; // Height of info box 149 static const char infostring[]; // Text format for info 150 151 static const char *months[12]; // Names of the months 152 153 unsigned char restored = 0; // Set to 1 if we restored a game. 154 155 std::unique_ptr<Image_buffer> back; 156 157 SaveInfo *games = nullptr; // The list of savegames 158 int num_games = 0; // Number of save games 159 int first_free = 0; // The number of the first free savegame 160 161 std::unique_ptr<Shape_file> cur_shot; // Screenshot for current game 162 SaveGame_Details *cur_details = nullptr; // Details of current game 163 SaveGame_Party *cur_party = nullptr; // Party of current game 164 165 // Gamedat is being used as a 'quicksave' 166 int last_selected = -4; // keeping track of the selected line for iOS 167 std::unique_ptr<Shape_file> gd_shot; // Screenshot in Gamedat 168 SaveGame_Details *gd_details = nullptr; // Details in Gamedat 169 SaveGame_Party *gd_party = nullptr; // Parts in Gamedat 170 171 Shape_file *screenshot = nullptr; // The picture to be drawn 172 SaveGame_Details *details = nullptr; // The game details to show 173 SaveGame_Party *party = nullptr; // The party to show 174 bool is_readable = false; // Is the save game readable 175 const char *filename = nullptr; // Filename of the savegame, if exists 176 177 int list_position = -2; // The position in the savegame list (top game) 178 int selected = -3; // The savegame that has been selected (num in list) 179 int cursor = 0; // The position of the cursor 180 int slide_start = -1; // Pixel (v) where a slide started 181 char newname[MAX_SAVEGAME_NAME_LEN]; // The new name for the game 182 183 int BackspacePressed(); 184 int DeletePressed(); 185 int MoveCursor(int count); 186 int AddCharacter(char c); 187 188 void LoadSaveGameDetails(); // Loads (and sorts) all the savegame details 189 void FreeSaveGameDetails(); // Frees all the savegame details 190 191 void PaintSaveName(int line); 192 193 public: 194 Newfile_gump(); 195 ~Newfile_gump() override; 196 197 void load(); // 'Load' was clicked. 198 void save(); // 'Save' was clicked. 199 void delete_file(); // 'Delete' was clicked. 200 201 void scroll_line(int dir); // Scroll Line Button Pressed 202 void scroll_page(int dir); // Scroll Page Button Pressed. 203 line_up()204 void line_up() { 205 scroll_line(-1); 206 } 207 line_down()208 void line_down() { 209 scroll_line(1); 210 } 211 page_up()212 void page_up() { 213 scroll_page(-1); 214 } 215 page_down()216 void page_down() { 217 scroll_page(1); 218 } 219 restored_game()220 int restored_game() { // 1 if user restored. 221 return restored; 222 } 223 // Paint it and its contents. 224 void paint() override; close()225 void close() override { 226 done = true; 227 } 228 // Handle events: 229 void text_input(const char *text) override; // Character typed. 230 bool mouse_down(int mx, int my, int button) override; 231 bool mouse_up(int mx, int my, int button) override; 232 void mouse_drag(int mx, int my) override; 233 void text_input(int chr, int unicode) override; // Character typed. 234 235 void mousewheel_up() override; 236 void mousewheel_down() override; 237 }; 238 239 #endif //NEWFILE_GUMP_H 240