diff options
-rw-r--r-- | src/client/buymenu.cc | 23 | ||||
-rw-r--r-- | src/client/inventorylistview.cc | 14 | ||||
-rw-r--r-- | src/client/trademenu.cc | 49 | ||||
-rw-r--r-- | src/client/trademenu.h | 1 | ||||
-rw-r--r-- | src/core/inventory.cc | 1 | ||||
-rw-r--r-- | src/core/item.cc | 15 | ||||
-rw-r--r-- | src/core/netconnection.cc | 19 | ||||
-rw-r--r-- | src/game/base/cargo.cc | 3 | ||||
-rw-r--r-- | src/ui/button.cc | 28 |
9 files changed, 101 insertions, 52 deletions
diff --git a/src/client/buymenu.cc b/src/client/buymenu.cc index ba93f42..b42dc00 100644 --- a/src/client/buymenu.cc +++ b/src/client/buymenu.cc @@ -65,6 +65,8 @@ void BuyMenu::set_item(core::Info *info) menu_infotext.clear(); menu_namelabel->set_text(0); menu_modelview->set_modelname(0); + menu_buybutton->hide(); + menu_modelview->hide(); // if the information timestamp is 0, the info is available menu_inforecord = info; @@ -78,22 +80,19 @@ void BuyMenu::set_item(core::Info *info) } else { for (core::Info::Text::const_iterator it = menu_inforecord->text().begin(); it != menu_inforecord->text().end(); it++) { menu_infotext.push_back((*it)); - } - - menu_infotimestamp = menu_inforecord->timestamp(); - if (menu_inforecord->type() && !menu_inforecord->timestamp()) { + } + if (menu_inforecord->type()) { menu_namelabel->set_text(menu_inforecord->name()); menu_modelview->set_modelname(menu_inforecord->modelname()); - menu_buybutton->set_command("remote buy " + menu_inforecord->type()->label() + ' ' + menu_inforecord->label() + "; view hide"); - menu_buybutton->set_label("buy " + menu_inforecord->name()); + if (menu_inforecord->label().size()) { + menu_buybutton->set_command("remote buy " + menu_inforecord->type()->label() + ' ' + menu_inforecord->label() + "; view hide"); + menu_buybutton->set_label("buy " + menu_inforecord->type()->label() + ' ' + menu_inforecord->label()); - menu_buybutton->show(); - menu_modelview->show(); - } else { - menu_buybutton->hide(); - menu_modelview->hide(); - } + menu_buybutton->show(); + menu_modelview->show(); + } + } menu_infotimestamp = menu_inforecord->timestamp(); } } diff --git a/src/client/inventorylistview.cc b/src/client/inventorylistview.cc index e2b613b..87cc367 100644 --- a/src/client/inventorylistview.cc +++ b/src/client/inventorylistview.cc @@ -96,13 +96,25 @@ void InventoryListView::draw() if (listview_inventory && listview_infotype) { // inventory was updated if (listview_timestamp != listview_inventory->timestamp()) { + //con_debug << "CLIENT inventory update from " << listview_timestamp << " to " << listview_inventory->timestamp() << std::endl; set_inventory(listview_inventory, listview_infotype); // inventory info was updated } else if (!verify_inventory()) { + //con_debug << "CLIENT inventory info update" << std::endl; set_inventory(listview_inventory, listview_infotype); } } - + + /* + * DEBUG + std::ostringstream str; + if (listview_inventory && listview_infotype) { + str << listview_timestamp << " " << listview_inventory->timestamp() << " " << listview_infotimestamp; + } else { + str << "EMPTY"; + } + ui::Paint::draw_label(global_location(), size(), font(), str.str() , ui::AlignBottom) ; + */ ListView::draw(); } diff --git a/src/client/trademenu.cc b/src/client/trademenu.cc index 91724f7..8aa9a52 100644 --- a/src/client/trademenu.cc +++ b/src/client/trademenu.cc @@ -38,6 +38,12 @@ TradeMenu::TradeMenu(ui::Widget *parent, const char * label) : ui::Window(parent menu_slider = new ui::Slider(menu_tradewindow); menu_slider->set_background(false); menu_slider->set_border(true); + + menu_msgtext = new ui::Label(menu_tradewindow); + menu_msgtext->set_label("label"); + menu_msgtext->set_background(false); + menu_msgtext->set_border(false); + menu_msgtext->set_alignment(ui::AlignCenter); menu_namelabel = new ui::Label(menu_tradewindow); menu_namelabel->set_label("label"); @@ -113,11 +119,17 @@ void TradeMenu::set_itemtype(core::InfoType *item_type) void TradeMenu::set_item(ui::ListItem *item) { menu_infotext.clear(); + menu_namelabel->set_text("Trade"); + menu_tradertext->clear(); - menu_buybutton->hide(); + menu_msgtext->clear(); + menu_msgtext->hide(); menu_slider->hide(); + menu_buybutton->set_command(""); + menu_buybutton->hide(); // FIXME enable/disable button + if (item != menu_listitem) { menu_slider->set_range(0, 2); menu_slider->set_value(1); @@ -148,7 +160,7 @@ void TradeMenu::set_item(ui::ListItem *item) if (item->parent() == menu_inventorylistview) { // item in ship inventory selected (SELL) - + menu_buybutton->set_text("Sell"); menu_traderlistview->deselect(); const core::Item *trader_item = (menu_traderlistview->inventory() ? menu_traderlistview->inventory()->find(item->info()) : 0); @@ -164,14 +176,14 @@ void TradeMenu::set_item(ui::ListItem *item) std::ostringstream commandstr; commandstr << "remote sell " << item->info()->type()->label() << " " << item->info()->label() << " " << amount; menu_buybutton->set_command(commandstr.str()); - menu_buybutton->set_text("Sell"); + + menu_buybutton->enable(); menu_buybutton->show(); } - if (amount < 1) { - menu_buybutton->set_command(""); - menu_buybutton->set_text("^1Can not sell"); - menu_buybutton->show(); + if (amount < 1) { + menu_msgtext->set_text("^1Can not sell"); + menu_msgtext->show(); } std::ostringstream str; @@ -179,7 +191,8 @@ void TradeMenu::set_item(ui::ListItem *item) << "Volume: " << std::setw(12) << std::setprecision(2) << (float)(amount > 0 ? amount : 1) * trader_item->info()->volume(); menu_tradertext->set_text(str.str()); } else { - menu_tradertext->set_text(" ^1Can not sell here"); + menu_msgtext->set_text("^1Can not sell here"); + menu_msgtext->show(); } std::ostringstream labelstr; @@ -192,7 +205,7 @@ void TradeMenu::set_item(ui::ListItem *item) } else if (item->parent() == menu_traderlistview) { // item in trader inventory selected (BUY) - + menu_buybutton->set_text("Buy"); menu_inventorylistview->deselect(); if (menu_inventorylistview->inventory()) { @@ -213,14 +226,20 @@ void TradeMenu::set_item(ui::ListItem *item) std::ostringstream commandstr; commandstr << "remote buy " << item->info()->type()->label() << " " << item->info()->label() << " " << amount; menu_buybutton->set_command(commandstr.str()); - menu_buybutton->set_text("Buy"); + + menu_buybutton->enable(); menu_buybutton->show(); } if (amount < 1) { - menu_buybutton->set_command(""); - menu_buybutton->set_text("^1Can not buy"); - menu_buybutton->show(); + if (item_unit_price > core::localplayer()->credits()) { + menu_msgtext->set_text("^1Not enough credits"); + } else if (item_unit_volume > menu_inventorylistview->inventory()->capacity_available()) { + menu_msgtext->set_text("^1Not enough cargo space"); + } else { + menu_msgtext->set_text("^1Can not buy"); + } + menu_msgtext->show(); } std::ostringstream str; @@ -272,6 +291,10 @@ void TradeMenu::resize() // resize slider menu_slider->set_size(menu_modelview->width(), fontmargin); menu_slider->set_location(menu_modelview->left(), menu_modelview->bottom() - menu_slider->height()); + + // warning text + menu_msgtext->set_size(menu_slider->size()); + menu_msgtext->set_location(menu_slider->location()); // resize scrollpane menu_scrollpane->set_size(menu_tradewindow->width() - 2.0f * ui::UI::elementsize.width() - fontmargin * 4.0f, menu_inventorylistview->height() + 2.0f * fontmargin - ui::UI::elementsize.width()); diff --git a/src/client/trademenu.h b/src/client/trademenu.h index e835043..5ea34aa 100644 --- a/src/client/trademenu.h +++ b/src/client/trademenu.h @@ -51,6 +51,7 @@ private: ui::ModelView *menu_modelview; ui::ScrollPane *menu_scrollpane; ui::Slider *menu_slider; + ui::Label *menu_msgtext; ui::Button *menu_closebutton; ui::Button *menu_buybutton; diff --git a/src/core/inventory.cc b/src/core/inventory.cc index 7957294..28327a3 100644 --- a/src/core/inventory.cc +++ b/src/core/inventory.cc @@ -54,7 +54,6 @@ void Inventory::add(Item *item) return; } inventory_items.push_back(item); - inventory_dirty = true; } void Inventory::remove(Item *item) diff --git a/src/core/item.cc b/src/core/item.cc index e9d9f65..8ab4784 100644 --- a/src/core/item.cc +++ b/src/core/item.cc @@ -14,12 +14,17 @@ namespace core /* ---- class Item ------------------------------------------------- */ +// Note: initializing the timestamp with 1 instead of 0 is a small hack +// since cient-side inventory timestamps are initialized at 0, setting +// the item timestamp to 0 would prevent the client from updating +// the trade window the first time it is opened on a base + Item::Item(const Info *info) { item_info = info; item_amount = 0; item_price = info->price(); - set_timestamp(game() ? game()->timestamp() : 0); + set_timestamp(game() ? game()->timestamp() : 1); } Item::~Item() @@ -31,25 +36,25 @@ Item::~Item() void Item::set_amount(const long amount) { item_amount = amount; - set_timestamp(game() ? game()->timestamp() : 0); + set_timestamp(game() ? game()->timestamp() : 1); } void Item::inc_amount(const long amount) { item_amount += amount; - set_timestamp(game() ? game()->timestamp() : 0); + set_timestamp(game() ? game()->timestamp() : 1); } void Item::dec_amount(const long amount) { item_amount -= amount; - set_timestamp(game() ? game()->timestamp() : 0); + set_timestamp(game() ? game()->timestamp() : 1); } void Item::set_price(const long price) { item_price = price; - set_timestamp(game() ? game()->timestamp() : 0); + set_timestamp(game() ? game()->timestamp() : 1); } void Item::set_timestamp(const unsigned long timestamp) diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc index 11e23c9..3318c1e 100644 --- a/src/core/netconnection.cc +++ b/src/core/netconnection.cc @@ -432,7 +432,7 @@ void NetConnection::send_info_request(Info *info) msg << "inf " << info->id() << "\n"; this->send_raw(msg.str()); - info->set_timestamp(timestamp()); + info->set_timestamp(application()->timestamp()); } // send an inventory update request @@ -871,9 +871,9 @@ void NetConnection::parse_incoming_message(const std::string & message) info->receive_server_update(msgstream); //info->clear_timestamp(); - info->set_timestamp(timestamp()); + info->set_timestamp(application()->timestamp()); - //con_debug << "Received info for " << info->id() << " " << info->type()->label() << ":" << info->label() << std::endl; + //con_debug << "CLIENT info for " << info->id() << " " << info->type()->label() << ":" << info->label() << " timestamp " << info->timestamp() << std::endl; } else if (command.compare("inv") == 0) { @@ -897,9 +897,8 @@ void NetConnection::parse_incoming_message(const std::string & message) return; } - //con_debug << "CLIENT received inv message for entity " << id << " server timestamp " << server_timestamp << " client timestamp " << entity->inventory()->timestamp() << std::endl; - - + //con_debug << "CLIENT received inv message for entity " << id << " client timestamp " << entity->inventory()->timestamp() << " server timestamp " << server_timestamp << std::endl; + if (server_timestamp < entity->inventory()->timestamp()) return; @@ -907,7 +906,7 @@ void NetConnection::parse_incoming_message(const std::string & message) if (!(msgstream >> nbitems)) nbitems = 0; - //con_debug << "CLIENT number of items: " << nbitems << std::endl; + //con_debug << "CLIENT number of items: " << nbitems << std::endl; for (size_t i = 0; i < nbitems; i++) { if (!(msgstream >> id)) { con_warn << "Received inventory update without info id for existing entity " << id << "!" << std::endl; @@ -922,9 +921,11 @@ void NetConnection::parse_incoming_message(const std::string & message) } item->receive_server_update(msgstream); } - - entity->inventory()->set_timestamp(server_timestamp); + entity->inventory()->recalculate(); + entity->inventory()->set_timestamp(server_timestamp); + + //con_debug << "CLIENT inventory updated timestamp " << entity->inventory()->timestamp() << " for " << nbitems << " items" << std::endl; } } diff --git a/src/game/base/cargo.cc b/src/game/base/cargo.cc index 3014a1e..626a1b3 100644 --- a/src/game/base/cargo.cc +++ b/src/game/base/cargo.cc @@ -164,6 +164,7 @@ void Cargo::sell(core::EntityControlable *seller, core::Entity *buyer, const int seller_item->dec_amount(negotiated_amount); seller->owner()->set_credits(seller->owner()->credits() + negotiated_price * negotiated_amount); + seller->owner()->set_dirty(); seller->inventory()->set_dirty(); if (buyer_item->amount() >= 0) { @@ -283,7 +284,7 @@ void Cargo::buy(core::EntityControlable *buyer, core::Entity *seller, const int } buyer_item->inc_amount(negotiated_amount); buyer->owner()->set_credits(buyer->owner()->credits() - negotiated_price * negotiated_amount); - + buyer->owner()->set_dirty(); buyer->inventory()->set_dirty(); // send a cargo purchased message diff --git a/src/ui/button.cc b/src/ui/button.cc index 95158a2..ddcc72d 100644 --- a/src/ui/button.cc +++ b/src/ui/button.cc @@ -49,7 +49,9 @@ void Button::set_command(const std::string &command) void Button::draw_border() { - if (has_mouse_focus()) { + if (disabled()) { + Paint::set_color(palette()->disabled()); + } else if (has_mouse_focus()) { math::Color color(palette()->foreground()); float t = core::application()->time(); t = t - floorf(t); @@ -57,8 +59,9 @@ void Button::draw_border() t = 1 - t; color.a = 0.5f + t; Paint::set_color(color); - } else + } else { Paint::set_color(palette()->border()); + } Paint::draw_border(global_location(), size()); } @@ -68,22 +71,25 @@ void Button::draw() if (!text().size()) return; - if (has_mouse_focus()) + if (disabled()) { + Paint::set_color(palette()->disabled()); + } else if (has_mouse_focus()) { Paint::set_color(palette()->highlight()); - else + } else { Paint::set_color(palette()->foreground()); - + } Paint::draw_label(global_location(), size(), font(), text(), alignment()); } bool Button::on_keypress(const int key, const unsigned int modifier) { if (key == 512 + SDL_BUTTON_LEFT) { - core::cmd() << button_command << std::endl; - audio::play("ui/button"); - - emit(EventButtonClicked); + if (enabled()) { + core::cmd() << button_command << std::endl; + audio::play("ui/button"); + emit(EventButtonClicked); + } return true; } @@ -97,7 +103,9 @@ bool Button::on_keyrelease(const int key, const unsigned int modifier) void Button::on_mouseover(const math::Vector2f &cursor) { - audio::play("ui/select"); + if (enabled()) { + audio::play("ui/select"); + } } } |