Ticket #2361: save_check.patch
File save_check.patch, 12.4 KB (added by , 10 years ago) |
---|
-
binaries/data/mods/public/gui/common/functions_utility_loadsave.js
8 8 return n < 10 ? "0" + n : n; 9 9 } 10 10 11 function generateLabel(metadata )11 function generateLabel(metadata, majorVersion) 12 12 { 13 13 var t = new Date(metadata.time*1000); 14 14 15 15 var date = t.getFullYear()+"-"+twoDigits(1+t.getMonth())+"-"+twoDigits(t.getDate()); 16 16 var time = twoDigits(t.getHours())+":"+twoDigits(t.getMinutes())+":"+twoDigits(t.getSeconds()); 17 return "["+date+" "+time+"] "+metadata.initAttributes.map+(metadata.description ? " - "+metadata.description : ""); 17 var label = "["+date+" "+time+"] "+metadata.initAttributes.map.replace("maps/","")+(metadata.description ? " - "+metadata.description : ""); 18 if (majorVersion) 19 label = label + (majorVersion != metadata.version_major ? "\nIncompatible version [" + metadata.version_major+"."+metadata.version_minor+"]": ""); 20 return label; 18 21 } -
binaries/data/mods/public/gui/savedgames/load.js
12 12 return; 13 13 } 14 14 15 // get current save game version from the game 16 var saveGameVersion = Engine.GetCurrentSaveGameVersion(); 17 var majorVersion = saveGameVersion.saveGameVersionMajor; 18 var minorVersion = saveGameVersion.saveGameVersionMinor; 19 15 20 savedGames.sort(sortDecreasingDate); 16 21 17 22 var gameListIDs = [ game.id for each (game in savedGames) ]; 18 var gameListLabels = [ generateLabel(game.metadata) for each (game in savedGames) ]; 23 var gameListLabels = [ generateLabel(game.metadata, majorVersion) for each (game in savedGames) ]; 24 var gameListCompatible = [ (majorVersion == game.metadata.version_major ? 1 : 0) for each (game in savedGames) ]; 19 25 20 26 gameSelection.list = gameListLabels; 21 27 gameSelection.list_data = gameListIDs; 28 gameSelection.list_selectable = gameListCompatible; 22 29 gameSelection.selected = 0; 23 30 } 24 31 -
source/gui/CDropDown.cpp
497 497 if (m_HideScrollBar) 498 498 *scrollbar = false; 499 499 500 DrawList(m_ElementHighlight, "sprite_list", "sprite_selectarea", "textcolor" );500 DrawList(m_ElementHighlight, "sprite_list", "sprite_selectarea", "textcolor", "warncolor"); 501 501 502 502 if (m_HideScrollBar) 503 503 *scrollbar = old; -
source/gui/CList.cpp
54 54 AddSetting(GUIST_int, "selected"); // Index selected. -1 is none. 55 55 AddSetting(GUIST_CStrW, "tooltip"); 56 56 AddSetting(GUIST_CStr, "tooltip_style"); 57 // Each list item has both a name (in 'list') and an associated data string (in 'list_data')57 // Each list item has three: a name (in 'list') and an associated data string (in 'list_data') and a value in list_selectable (0 or 1) 58 58 AddSetting(GUIST_CGUIList, "list"); 59 59 AddSetting(GUIST_CGUIList, "list_data"); // TODO: this should be a list of raw strings, not of CGUIStrings 60 60 AddSetting(GUIST_CGUIList, "list_selectable"); 61 61 62 GUI<bool>::SetSetting(this, "scrollbar", false); 62 63 63 64 // Nothing is selected as default. … … 232 233 233 234 if (set != -1) 234 235 { 235 GUI<int>::SetSetting(this, "selected", set); 236 UpdateAutoScroll(); 236 // check, if it can be selected 237 if(this->canItemBeSelected(set)) 238 { 239 GUI<int>::SetSetting(this, "selected", set); 240 UpdateAutoScroll(); 237 241 238 CStrW soundPath; 239 if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_selected", soundPath) == PSRETURN_OK && !soundPath.empty()) 240 g_SoundManager->PlayAsUI(soundPath.c_str(), false); 242 CStrW soundPath; 243 if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_selected", soundPath) == PSRETURN_OK && !soundPath.empty()) 244 g_SoundManager->PlayAsUI(soundPath.c_str(), false); 245 } 241 246 } 242 247 break; 243 248 } … … 257 262 IGUITextOwner::HandleMessage(Message); 258 263 } 259 264 265 bool CList::canItemBeSelected(unsigned int id) 266 { 267 CGUIList *pListSelectable; 268 GUI<CGUIList>::GetSettingPointer(this, "list_selectable", pListSelectable); 269 270 return pListSelectable->m_Items.size() <= id || pListSelectable->m_Items[id].GetOriginalString().ToInt() != 0; 271 } 272 260 273 InReaction CList::ManuallyHandleEvent(const SDL_Event_* ev) 261 274 { 262 275 int szChar = ev->ev.key.keysym.sym; … … 303 316 int selected; 304 317 GUI<int>::GetSetting(this, "selected", selected); 305 318 306 DrawList(selected, "sprite", "sprite_selectarea", "textcolor" );319 DrawList(selected, "sprite", "sprite_selectarea", "textcolor", "warncolor"); 307 320 } 308 321 309 322 void CList::DrawList(const int &selected, 310 323 const CStr& _sprite, 311 324 const CStr& _sprite_selected, 312 const CStr& _textcolor) 325 const CStr& _textcolor, 326 const CStr& _inactiveTextcolor) 313 327 { 314 328 float bz = GetBufferedZ(); 315 329 … … 376 390 } 377 391 } 378 392 379 CColor color ;393 CColor color, unselColor, colorElement; 380 394 GUI<CColor>::GetSetting(this, _textcolor, color); 395 //GUI<CColor>::GetSetting(this, _inactiveTextcolor, unselColor); // TODO: add the color there...'warncolor' 396 397 unselColor = CColor(255/255.0f, 128/255.0f, 0/255.0f, 1.0f);; 381 398 382 399 for (int i=0; i<(int)pList->m_Items.size(); ++i) 383 400 { … … 399 416 cliparea.left = GetScrollBar(0).GetOuterRect().right; 400 417 } 401 418 402 DrawText(i, color, rect.TopLeft() - CPos(0.f, scroll - m_ItemsYPositions[i]), bz+0.1f, cliparea); 419 // select color 420 if( this->canItemBeSelected(i) ) 421 colorElement = color; 422 else 423 colorElement = unselColor; 424 425 DrawText(i, colorElement, rect.TopLeft() - CPos(0.f, scroll - m_ItemsYPositions[i]), bz+0.1f, cliparea); 403 426 } 404 427 } 405 428 } 406 429 407 void CList::AddItem(const CStrW& str, const CStrW& data )430 void CList::AddItem(const CStrW& str, const CStrW& data, bool selectable) 408 431 { 409 CGUIList *pList, *pListData; 432 //TODO: this seems not to work also in version in SVN or does it ?! 433 CGUIList *pList, *pListData, *pListSelectable; 410 434 GUI<CGUIList>::GetSettingPointer(this, "list", pList); 411 435 GUI<CGUIList>::GetSettingPointer(this, "list_data", pListData); 436 GUI<CGUIList>::GetSettingPointer(this, "list_selectable", pListSelectable); 412 437 413 438 CGUIString gui_string; 414 439 gui_string.SetValue(str); … … 418 443 data_string.SetValue(data); 419 444 pListData->m_Items.push_back( data_string ); 420 445 446 CGUIString sel_string; 447 sel_string.SetValue(selectable ? L"1" : L"0"); 448 pListSelectable->m_Items.push_back( sel_string ); 449 421 450 // TODO Temp 422 451 SetupText(); 423 452 } … … 428 457 429 458 if (child.GetNodeName() == elmt_item) 430 459 { 431 AddItem(child.GetText().FromUTF8(), child.GetText().FromUTF8()); 432 460 XMBAttributeList attrs = child.GetAttributes(); 461 CStr selectable = attrs.GetNamedItem(pFile->GetAttributeID("selectable")); 462 AddItem(child.GetText().FromUTF8(), child.GetText().FromUTF8(), !selectable.empty() || selectable.GetHashCode() == CStr8("true").GetHashCode()); 433 463 return true; 434 464 } 435 else 436 { 437 return false; 438 } 465 return false; 439 466 } 440 467 441 468 void CList::SelectNextElement() -
source/gui/CList.h
79 79 /** 80 80 * Adds an item last to the list. 81 81 */ 82 virtual void AddItem(const CStrW& str, const CStrW& data );82 virtual void AddItem(const CStrW& str, const CStrW& data, bool selectable = true); 83 83 84 84 protected: 85 85 /** … … 122 122 // Extended drawing interface, this is so that classes built on the this one 123 123 // can use other sprite names. 124 124 virtual void DrawList(const int &selected, const CStr& _sprite, 125 const CStr& _sprite_selected, const CStr& _textcolor );125 const CStr& _sprite_selected, const CStr& _textcolor, const CStr& _inactiveTextcolor); 126 126 127 127 // Get the area of the list. This is so that it can easily be changed, like in CDropDown 128 128 // where the area is not equal to m_CachedActualSize. … … 132 132 // (and thus whether list items have possibly changed). 133 133 virtual bool GetModified() const { return m_Modified; } 134 134 135 // checks, if a item can be selected 136 bool canItemBeSelected(unsigned int id); 137 135 138 // List of items. 136 139 //CGUIList m_List; 137 140 -
source/gui/scripting/ScriptFunctions.cpp
364 364 return SavedGames::DeleteSavedGame(name); 365 365 } 366 366 367 CScriptValRooted GetCurrentSaveGameVersion(ScriptInterface::CxPrivate* pCxPrivate) 368 { 369 return SavedGames::GetCurrentSaveGameVersion(*(pCxPrivate->pScriptInterface)); 370 } 371 367 372 void OpenURL(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::string url) 368 373 { 369 374 sys_open_url(url); … … 831 836 scriptInterface.RegisterFunction<void, std::wstring, std::wstring, CScriptVal, &SaveGamePrefix>("SaveGamePrefix"); 832 837 scriptInterface.RegisterFunction<void, &QuickSave>("QuickSave"); 833 838 scriptInterface.RegisterFunction<void, &QuickLoad>("QuickLoad"); 839 scriptInterface.RegisterFunction<CScriptValRooted, &GetCurrentSaveGameVersion>("GetCurrentSaveGameVersion"); 834 840 835 841 // Misc functions 836 842 scriptInterface.RegisterFunction<std::wstring, std::wstring, &SetCursor>("SetCursor"); -
source/ps/SavedGame.cpp
19 19 20 20 #include "SavedGame.h" 21 21 22 #include "graphics/Camera.h" 23 #include "graphics/GameView.h" 22 24 #include "gui/GUIManager.h" 23 25 #include "lib/allocators/shared_ptr.h" 24 26 #include "lib/file/archive/archive_zip.h" 25 27 #include "ps/CLogger.h" 26 28 #include "ps/Filesystem.h" 29 #include "ps/Game.h" 27 30 #include "scriptinterface/ScriptInterface.h" 28 31 #include "simulation2/Simulation2.h" 29 32 30 33 static const int SAVED_GAME_VERSION_MAJOR = 1; // increment on incompatible changes to the format 31 34 static const int SAVED_GAME_VERSION_MINOR = 0; // increment on compatible changes to the format 32 // TODO: we ought to check version numbers when loading files33 35 34 35 36 Status SavedGames::SavePrefix(const std::wstring& prefix, const std::wstring& description, CSimulation2& simulation, shared_ptr<ScriptInterface::StructuredClone> guiMetadataClone, int playerID) 36 37 { 37 38 // Determine the filename to save under … … 47 48 return Save(filename.Filename().string(), description, simulation, guiMetadataClone, playerID); 48 49 } 49 50 51 50 52 Status SavedGames::Save(const std::wstring& name, const std::wstring& description, CSimulation2& simulation, shared_ptr<ScriptInterface::StructuredClone> guiMetadataClone, int playerID) 51 53 { 52 54 // Determine the filename to save under … … 213 215 CScriptValRooted game; 214 216 scriptInterface.Eval("({})", game); 215 217 scriptInterface.SetProperty(game.get(), "id", pathnames[i].Basename()); 218 scriptInterface.SetProperty(game.get(), "saveGameVersionMajor", SAVED_GAME_VERSION_MAJOR); 219 scriptInterface.SetProperty(game.get(), "saveGameVersionMinor", SAVED_GAME_VERSION_MINOR); 216 220 scriptInterface.SetProperty(game.get(), "metadata", metadata); 217 221 games.push_back(game); 218 222 } … … 241 245 // Successfully deleted file 242 246 return true; 243 247 } 248 249 250 CScriptValRooted SavedGames::GetCurrentSaveGameVersion(ScriptInterface& scriptInterface) 251 { 252 CScriptValRooted metainfo; 253 scriptInterface.Eval("({})", metainfo); 254 scriptInterface.SetProperty(metainfo.get(), "saveGameVersionMajor", SAVED_GAME_VERSION_MAJOR); 255 scriptInterface.SetProperty(metainfo.get(), "saveGameVersionMinor", SAVED_GAME_VERSION_MINOR); 256 return metainfo; 257 } 258 No newline at end of file -
source/ps/SavedGame.h
92 92 */ 93 93 bool DeleteSavedGame(const std::wstring& name); 94 94 95 /** 96 * Gets the current version of the save game format. 97 * 98 * @param scriptInterface the ScriptInterface in which to create the return data. 99 * @return list of objects containing saved game data 100 */ 101 CScriptValRooted GetCurrentSaveGameVersion(ScriptInterface& scriptInterface); 95 102 } 96 103 97 104 #endif // INCLUDED_SAVEDGAME