Jr13San
Модостроитель
- Регистрация
- 1 Апр 2010
- Сообщения
- 462
- Благодарности
- 285
- Баллы
- 230
Myszax, here are two test funcs. Try it, maybe something will work:
[Google translate]
Enable menu loop func:
And in my opinion, in the 'Archolos' mod, in the loading menu, there is no choice of a quick save slot (maximum 15 slots). So the idea of simulating switching to a specific slot is not suitable in this case.
To see messages in the console, enable the option in the "SystemPack.ini" file:
C++:
namespace GOTHIC_ENGINE {
// The function returns the slot number of the last save,
// using information about the date and time of saving
// Returns:
// "0" - if the last quick save slot was
// "-1" - if there are no save files,
// "1 ... 20" - in other cases
int GetLastSaveGameSlot()
{
int lastSaveSlot = -1; // variable to store the current slot number
long lastTime; // variable to store the current timestamp
const int maxSlots = 20; // maximum number of slots for save files
// full path to the internal save folder
zSTRING fullPathToSaves = zoptions->GetDirString(zTOptionPaths::DIR_ROOT) + zoptions->GetDirString(zTOptionPaths::DIR_SAVEGAMES);
// name of the subfolder with save files
// (first check the quick save folder, then regular slots)
zSTRING subPath = "quicksave";
// full path to the save file
// (constantly generated in a loop)
zSTRING fullPathToSaveFile = "";
// declare a structure for receiving file parameters
zFILE_STATS stats;
// go through all save slots (quicksave and 1-20)
for (int i = 0; i <= maxSlots; i++)
{
// the first thing to check is the "quicksave" subfolder,
// in other cases: "savegame" + slot number
if (i > 0)
// so, we form the name of the subfolder
subPath = "savegame" + Z(i);
// then create the full path to the main save file
// under the selected slot (save folder + subfolder + file)
fullPathToSaveFile = fullPathToSaves + subPath + "\\SAVEDAT.SAV";
// open access to the file
zFILE_FILE file(fullPathToSaveFile);
// if file parameters are not received
if (file.GetStats(stats) != zERR_NONE)
// means we move on to checking the next slot
continue;
// Otherwise, we work with the save file.
// Check if the current slot is not yet designated,
// this means there was no first record with which we can compare something
if (lastSaveSlot == -1)
{
// therefore we record in a variable the date and time of saving,
// expressed in seconds, relative to 1900
lastTime = stats.modifyDate.ToTime_t();
// remember the slot standard
lastSaveSlot = i;
// continue searching through slots
continue;
}
// Otherwise, there is something to compare with.
// Therefore, we compare timestamps to determine the new current save.
// To do this, we convert the date and time the file was saved into an equivalent number of seconds.
long currentTime = stats.modifyDate.ToTime_t();
// Check if the current save was made later
if (currentTime > lastTime)
{
// update data about the last save
lastTime = currentTime;
// remember the slot number
lastSaveSlot = i;
}
} /* end of loop */
// at the end of the function - return the current number of the storage slot
return lastSaveSlot;
}
// Test - Loading the last saved game,
// when you press the F12 key, in the menu of any mode!
void TestFunc_LoadLastSaveGame()
{
// if the F12 key is not pressed
if (!zKeyToggled(KEY_F12) /* || zCMenu::inGameMenu */)
// exit
return;
// otherwise, we get the last save slot (-1 ... 20)
int lastSlotNr = GetLastSaveGameSlot();
// display the slot number to the console (for debugging)
cmd << "\nLastSaveGameSlot = " << lastSlotNr << endl;
// if no saves are found
if (lastSlotNr < 0)
{
// report this to the console
cmd << "Saves not found -> Exit!" <<endl;
// and exit
return;
}
// otherwise, we get a pointer to the active menu
zCMenu* menu = zCMenu::GetActive();
// if the menu is open
if (menu)
// close it
menu->HandleEvent(KEY_ESCAPE);
// and finally load the game in the specified slot
gameMan->Read_Savegame(lastSlotNr);
}
// Set focus to the last save,
// when pressing the F12 key, only in main menu mode
void TestFunc_SetFocusToLastSaveGame()
{
// focus flag on the last save (1 - on, 0 - off)
static BOOL bUseQuickFocus = FALSE;
/********************/
// Execution block
/********************/
// if focusing on the last save is started
if (bUseQuickFocus == TRUE)
{
// trying to get a pointer to the save loading menu
zCMenu* menuLoadSaveGame = zCMenu::GetByName("MENU_SAVEGAME_LOAD");
// if the pointer is received
if (menuLoadSaveGame)
{
// get the last save slot
// (after preliminary check, it will already be from 1 to 15)
int lastSlotNr = GetLastSaveGameSlot();
// set focus to the selected slot (this is safe, because access to the element has been pre-evaluated)
menuLoadSaveGame->SetActiveItem(menuLoadSaveGame->m_listItems[lastSlotNr + 8]);
// simulate focus switching back and forth
// to update the save information of the selected item
menuLoadSaveGame->HandleEvent(KEY_UP);
menuLoadSaveGame->HandleEvent(KEY_DOWN);
/*******************************/
// Start a save (if required)
/*******************************/
// simulate pressing the "Enter" key
// menuLoadSaveGame->HandleEvent(KEY_RETURN);
}
// focus attempt used,
// so we reset the flag
bUseQuickFocus = FALSE;
// and exit the function
return;
}
/****************************/
// Block issuing the task
/****************************/
// if the F12 key is not pressed OR the menu is already called in the game OR the focusing process is already running
if (!zKeyToggled(KEY_F12) || zCMenu::inGameMenu || bUseQuickFocus == TRUE)
// exit
return;
// (for debugging)
cmd << "\nF12" << endl;
// otherwise, we try to get a pointer to the main menu
zCMenu* menuMain = zCMenu::GetByName("MENU_MAIN");
// and menu element for loading saves
zCMenuItem* menuItemLoadSaveGame = zCMenuItem::GetByName("MENUITEM_MAIN_SAVEGAME_LOAD");
// if pointers are not received
if (!menuMain || !menuItemLoadSaveGame)
// exit the function
return;
// otherwise, we get the last save slot (-1 ... 20)
int lastSlotNr = GetLastSaveGameSlot();
// if there are no saves or there are, but only "quick save"
if (lastSlotNr < 1) // (-1, 0)
{
// error comment
string comment = "";
// if the last save is 'quick save'
if (lastSlotNr == 0)
comment = ", is quick save.";
else // otherwise, no save files are found in the range from (1 to 20)
comment = ", saved files not found.";
// Can't set focus to last save!
cmd << string::Combine("Can not set focus on your last save game! (lastSlotNr = '%i')%s", lastSlotNr, comment) << endl;
// exit the function, because The "Archolos" mod does not have a 'quick save' item in the save loading menu
return;
}
// otherwise, we try to get a pointer to the save loading menu
zCMenu* menuLoadSaveGame = zCMenu::GetByName("MENU_SAVEGAME_LOAD");
// if the pointer is received
if (menuLoadSaveGame)
{
// calculate the index of the selected element in this menu
lastSlotNr += 8;
// get the number of items in the save loading menu
int numItems = menuLoadSaveGame->m_listItems.GetNum();
// if the index of the selected element is beyond the lower or upper limit of the array
if ((lastSlotNr < 0) || (lastSlotNr > numItems - 1))
{
// warn about this
cmd << string::Combine("Element %i/%i is out of range!", lastSlotNr, numItems) << endl;
// and exit the function
return;
}
// otherwise, take the intended focus element in the save loading menu
zCMenuItem* focusItem = menuLoadSaveGame->m_listItems[lastSlotNr];
// if the internal name of the element does not contain the keyword "SLOT"
if (!focusItem->GetName().HasWordI("SLOT"))
{
// print a warning that the intended focus element is not what we want
cmd << string::Combine("Element '%z' is not menu item slot", focusItem->GetName()) << endl;
// exit
return;
}
}
// otherwise, launch the save loading menu
menuMain->ForceSelAction(SEL_ACTION_STARTMENU, "MENU_SAVEGAME_LOAD", menuItemLoadSaveGame);
// and allow focus to be controlled in this menu
// (but already in the next iteration of the menu cycle, in which we will get to the 'Execution block')
bUseQuickFocus = TRUE;
}
// Loop while menu rendering
void Game_MenuLoop()
{
// Call test 1
// TestFunc_LoadLastSaveGame();
// Or call test 2
TestFunc_SetFocusToLastSaveGame();
}
// some base and your funcs ...
} /* end of namespace */
Enable menu loop func:
And in my opinion, in the 'Archolos' mod, in the loading menu, there is no choice of a quick save slot (maximum 15 slots). So the idea of simulating switching to a specific slot is not suitable in this case.
To see messages in the console, enable the option in the "SystemPack.ini" file:
INI:
[CORE]
ShowDebugWindow = true
Последнее редактирование: