Skip to content

Commit

Permalink
Revert "Removed last active item list number from el.cfg file, instea…
Browse files Browse the repository at this point in the history
…d store in the item list file."

This reverts commit 50ca2cb.

Nothing wrong with this code except it make the file not compatible with
previous clients.  If you run a previous client, you loose your items
lists file.  I've added code to prevent that now but it would be too
late.  Ah well, perhaps another time....
  • Loading branch information
pjbroad committed Feb 6, 2014
1 parent a77ca33 commit a8d317f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 25 deletions.
5 changes: 5 additions & 0 deletions init.c
Expand Up @@ -35,6 +35,7 @@
#include "gl_init.h"
#include "hud.h"
#include "items.h"
#include "item_lists.h"
#include "keys.h"
#include "knowledge.h"
#include "langselwin.h"
Expand Down Expand Up @@ -374,6 +375,8 @@ void read_bin_cfg()
rz=cfg_mem.camera_z;
new_zoom_level=zoom_level=cfg_mem.zoom_level;

item_lists_set_active(cfg_mem.active_item_list);

view_health_bar=cfg_mem.banner_settings & 1;
view_ether_bar=(cfg_mem.banner_settings >> 1) & 1;
view_names=(cfg_mem.banner_settings >> 2) & 1;
Expand Down Expand Up @@ -619,6 +622,8 @@ void save_bin_cfg()
cfg_mem.banner_settings |= view_hp << 3;
cfg_mem.banner_settings |= view_ether << 4;

cfg_mem.active_item_list = item_lists_get_active();

cfg_mem.quantity_selected=(quantities.selected<ITEM_EDIT_QUANT)?quantities.selected :0;

if(quickbar_relocatable>0)
Expand Down
7 changes: 6 additions & 1 deletion init.h
Expand Up @@ -121,8 +121,13 @@ typedef struct
int banner_settings;
/*! @} */

/*!
* \name Item lists - active list index.
*/
/*! @{ */
unsigned int active_item_list;

int unused_01;
int unused_02;

/*!
* \name quest log window position
Expand Down
45 changes: 21 additions & 24 deletions item_lists.cpp
Expand Up @@ -107,7 +107,7 @@ namespace ItemLists
class List_Container
{
public:
List_Container(void) : active_list(0), last_mod_time(0), loaded(false) {}
List_Container(void) : active_list(0), initial_active_list(0), last_mod_time(0), loaded(false) {}
void load(void);
void save(void);
bool add(const char *name);
Expand All @@ -122,6 +122,7 @@ namespace ItemLists
const std::vector<List> & get_lists(void) const { return saved_item_lists; }
bool set_active(size_t new_active_list)
{ if (new_active_list >= size()) return false; active_list = new_active_list; return true; }
void set_initial_active(size_t list_index) { initial_active_list = list_index; }
void set_quantity(size_t item, int quantity)
{ assert(valid_active_list()); last_mod_time = SDL_GetTicks(); return saved_item_lists[active_list].set_quantity(item, quantity); }
void del_item(size_t i)
Expand All @@ -135,8 +136,9 @@ namespace ItemLists
void check_and_timed_save(bool force);
private:
std::vector<List> saved_item_lists;
static size_t FILE_REVISION;
static int FILE_REVISION;
size_t active_list;
size_t initial_active_list;
Uint32 last_mod_time;
bool loaded;
static const char * filename;
Expand Down Expand Up @@ -630,7 +632,7 @@ namespace ItemLists
}


size_t List_Container::FILE_REVISION = 2;
int List_Container::FILE_REVISION = 2;
const char * List_Container::filename = "item_lists.txt";

// Save the item lists to a file in players config directory
Expand All @@ -647,7 +649,7 @@ namespace ItemLists
LOG_TO_CONSOLE(c_red2, item_list_save_error_str);
return;
}
out << FILE_REVISION << " " << get_active() << std::endl << std::endl;
out << FILE_REVISION << std::endl << std::endl;
for (size_t i=0; i<saved_item_lists.size(); ++i)
{
saved_item_lists[i].write(out);
Expand All @@ -668,24 +670,8 @@ namespace ItemLists
std::ifstream in(fullpath.c_str());
if (!in)
return;

// First line is "<file revision> [<active list>]", other parameters could be added....
size_t revision = 0;
size_t initial_active = 0;
std::string first_line;
if (getline_nocr(in, first_line) && !first_line.empty())
{
std::vector<size_t> values;
std::istringstream ss(first_line);
size_t value = 0;
while (ss >> value)
values.push_back(value);
if (values.size() > 0)
revision = values[0];
if (values.size() > 1)
initial_active = values[1];
}

int revision;
in >> revision;
if (revision != FILE_REVISION)
{
LOG_ERROR("%s: %s [%s]\n", __FILE__, item_list_version_error_str, fullpath.c_str() );
Expand All @@ -708,7 +694,7 @@ namespace ItemLists
}
in.close();
sort_list();
set_active(initial_active);
set_active(initial_active_list);
}


Expand Down Expand Up @@ -1530,9 +1516,20 @@ extern "C"
ItemLists::Vars::lists()->save();
ItemLists::Vars::cat_maps()->save();
}


unsigned int item_lists_get_active(void)
{
return static_cast<unsigned int>(ItemLists::Vars::lists()->get_active());
}

void item_lists_set_active(unsigned int active_list)
{
ItemLists::Vars::lists()->set_initial_active(static_cast<size_t>(active_list));
}

void item_lists_reset_pickup_fail_time(void)
{
ItemLists::Vars::win()->reset_pickup_fail_time();
}

}
2 changes: 2 additions & 0 deletions item_lists.h
Expand Up @@ -11,6 +11,8 @@ extern "C"
void toggle_items_list_window(window_info *win);
void update_category_maps(int image_id, Uint16 item_id, int cat_id);
void save_item_lists(void);
unsigned int item_lists_get_active(void);
void item_lists_set_active(unsigned int active_list);
void item_lists_reset_pickup_fail_time(void);

#ifdef __cplusplus
Expand Down

0 comments on commit a8d317f

Please sign in to comment.