From 1efdc36b22532807d21a0beac94524e3eacfe7bc Mon Sep 17 00:00:00 2001 From: Kahrl Date: Sat, 21 Jan 2012 21:21:41 +0100 Subject: Inventory menu (with dragging) improved. Crafting is now handled via a IACTION_CRAFT inventory action. --- src/player.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/player.cpp') diff --git a/src/player.cpp b/src/player.cpp index b072746c6..688be5d98 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -40,7 +40,6 @@ Player::Player(IGameDef *gamedef): swimming_up(false), inventory(gamedef->idef()), inventory_backup(NULL), - craftresult_is_preview(true), hp(20), peer_id(PEER_ID_INEXISTENT), // protected @@ -64,6 +63,7 @@ void Player::resetInventory() inventory.clear(); inventory.addList("main", PLAYER_INVENTORY_SIZE); inventory.addList("craft", 9); + inventory.addList("craftpreview", 1); inventory.addList("craftresult", 1); } @@ -119,7 +119,6 @@ void Player::serialize(std::ostream &os) args.setFloat("pitch", m_pitch); args.setFloat("yaw", m_yaw); args.setV3F("position", m_position); - args.setBool("craftresult_is_preview", craftresult_is_preview); args.setS32("hp", hp); args.writeLines(os); @@ -157,11 +156,10 @@ void Player::deSerialize(std::istream &is) setPitch(args.getFloat("pitch")); setYaw(args.getFloat("yaw")); setPosition(args.getV3F("position")); + bool craftresult_is_preview = true; try{ craftresult_is_preview = args.getBool("craftresult_is_preview"); - }catch(SettingNotFoundException &e){ - craftresult_is_preview = true; - } + }catch(SettingNotFoundException &e){} try{ hp = args.getS32("hp"); }catch(SettingNotFoundException &e){ @@ -169,6 +167,18 @@ void Player::deSerialize(std::istream &is) } inventory.deSerialize(is); + + if(inventory.getList("craftpreview") == NULL) + { + // Convert players without craftpreview + inventory.addList("craftpreview", 1); + + if(craftresult_is_preview) + { + // Clear craftresult + inventory.getList("craftresult")->changeItem(0, ItemStack()); + } + } } #ifndef SERVER -- cgit v1.2.3