forked from townforge/townforge
game: add an icon to the chop wood dialog
This commit is contained in:
parent
abe2314fad
commit
a2c0441178
@ -5,7 +5,9 @@ WindowInfo
|
||||
|
||||
TBLayout: axis: y, distribution-position: "left top", distribution: "available"
|
||||
|
||||
TBEditField: id: "message", multiline: 1, readonly: 1, gravity: "left right", adapt-to-content: 1, skin: "TBEditField.select-items-message", is-focusable: 0
|
||||
TBLayout: axis: x, distribution: "gravity"
|
||||
TBImageWidget: id: "icon", gravity: "left"
|
||||
TBEditField: id: "message", multiline: 1, readonly: 1, gravity: "left right", adapt-to-content: 1, skin: "TBEditField.select-items-message", is-focusable: 0
|
||||
|
||||
TBSelectList: id: "items", gravity: "all"
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <tb/tb_editfield.h>
|
||||
#include <tb/tb_toggle_container.h>
|
||||
#include <tb/tb_font_desc.h>
|
||||
#include <tb/image/tb_image_widget.h>
|
||||
#include <tb/tb_font_renderer.h>
|
||||
#include "ui-tb-message-box.h"
|
||||
#include "game/game-state.h"
|
||||
@ -18,6 +19,8 @@
|
||||
#include "caching-source-builder.h"
|
||||
#include "ui-select-items.h"
|
||||
|
||||
#define ICON_SIZE 96
|
||||
|
||||
using namespace Urho3D;
|
||||
using namespace tb;
|
||||
|
||||
@ -74,7 +77,7 @@ TBWidget *UISelectItemsDialog::SelectableItemSource::CreateItemWidget(int index,
|
||||
return new UISelectItemsDialog::SelectableItemWidget(item, this, viewer, index);
|
||||
}
|
||||
|
||||
UISelectItemsDialog::UISelectItemsDialog(Context *ctx, const GameState *game, const char *title, const char *message, bool show_gold, const std::function<bool(uint32_t)> &f):
|
||||
UISelectItemsDialog::UISelectItemsDialog(Context *ctx, const GameState *game, const char *title, const char *message, const char *icon, bool show_gold, const std::function<bool(uint32_t)> &f):
|
||||
UITBWindow(ctx, "cc/select-items.tb.txt"),
|
||||
game(game),
|
||||
show_gold(show_gold),
|
||||
@ -86,6 +89,7 @@ UISelectItemsDialog::UISelectItemsDialog(Context *ctx, const GameState *game, co
|
||||
searchWidget = GetWidgetByIDAndType<TBEditField>("search");
|
||||
goldContainerWidget = GetWidgetByIDAndType<TBToggleContainer>(TBIDC("gold-total-container"));
|
||||
goldTotalWidget = GetWidgetByIDAndType<TBTextField>(TBIDC("total-gold"));
|
||||
iconWidget = GetWidgetByIDAndType<TBImageWidget>(TBIDC("icon"));
|
||||
|
||||
SetText(title);
|
||||
if (message)
|
||||
@ -93,6 +97,11 @@ UISelectItemsDialog::UISelectItemsDialog(Context *ctx, const GameState *game, co
|
||||
FillItemList();
|
||||
goldContainerWidget->SetValue(show_gold);
|
||||
goldTotalWidget->SetText("0");
|
||||
if (icon)
|
||||
{
|
||||
iconWidget->SetImage(icon);
|
||||
iconWidget->SetLayoutParams(LayoutParams(ICON_SIZE, ICON_SIZE));
|
||||
}
|
||||
|
||||
SubscribeToEvent(this, E_TB_WIDGET_EVENT, URHO3D_HANDLER(UISelectItemsDialog, HandleTBMessage));
|
||||
SubscribeToEvent(this, E_TB_WINDOW_CLOSED, URHO3D_HANDLER(UISelectItemsDialog, HandleClose));
|
||||
|
@ -21,6 +21,7 @@ namespace tb
|
||||
class TBEditField;
|
||||
class TBButton;
|
||||
class TBToggleContainer;
|
||||
class TBImageWidget;
|
||||
}
|
||||
|
||||
class GameState;
|
||||
@ -31,7 +32,7 @@ URHO3D_EVENT(E_SELECT_ITEMS_CLOSED, SelectItemsClosed) {}
|
||||
class UISelectItemsDialog: public UITBWindow
|
||||
{
|
||||
public:
|
||||
UISelectItemsDialog(Urho3D::Context *ctx, const GameState *game = NULL, const char *title = NULL, const char *message = NULL, bool show_gold = false, const std::function<bool(uint32_t)> &f = [](uint32_t){ return true; });
|
||||
UISelectItemsDialog(Urho3D::Context *ctx, const GameState *game = NULL, const char *title = NULL, const char *message = NULL, const char *icon = NULL, bool show_gold = false, const std::function<bool(uint32_t)> &f = [](uint32_t){ return true; });
|
||||
virtual ~UISelectItemsDialog() override;
|
||||
|
||||
static void RegisterObject(Urho3D::Context* context);
|
||||
@ -86,6 +87,7 @@ private:
|
||||
tb::TBEditField *searchWidget;
|
||||
tb::TBToggleContainer *goldContainerWidget;
|
||||
tb::TBTextField *goldTotalWidget;
|
||||
tb::TBImageWidget *iconWidget;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -2128,7 +2128,7 @@ void UIUrho3D::HandleAssignItems(StringHash eventType, VariantMap& eventData)
|
||||
}
|
||||
|
||||
auto *d = new UISelectItemsDialog(context_, gameState, "Select items to assign",
|
||||
"Food and heating are taken from your inventory and do not need to be assigned to a building", false,
|
||||
"Food and heating are taken from your inventory and do not need to be assigned to a building", NULL, false,
|
||||
[](uint32_t item) { return (item >= ITEM_FIRST_BLOCK && item <= ITEM_LAST_BLOCK) || item == ITEM_LABOUR; });
|
||||
SubscribeToEvent(d, E_SELECT_ITEMS_OKAYED, [this](StringHash eventType, VariantMap& eventData) {
|
||||
SendEvent(E_CRYPTOCITY_ASSIGN_ITEMS, eventData);
|
||||
@ -2140,7 +2140,7 @@ void UIUrho3D::HandleDestroyItems(StringHash eventType, VariantMap& eventData)
|
||||
{
|
||||
auto *d = new UISelectItemsDialog(context_, gameState, "Select items to destroy",
|
||||
"Select which items to destroy. This is irreversible.\n"
|
||||
"If any item contains gold, this gold will be recovered and added to your balance, minus a small smelting fee.", true);
|
||||
"If any item contains gold, this gold will be recovered and added to your balance, minus a small smelting fee.", NULL, true);
|
||||
SubscribeToEvent(d, E_SELECT_ITEMS_OKAYED, [this](StringHash eventType, VariantMap& eventData) {
|
||||
SendEvent(E_CRYPTOCITY_DESTROY_ITEMS, eventData);
|
||||
});
|
||||
@ -2632,7 +2632,7 @@ void UIUrho3D::HandleChopWood(StringHash eventType, VariantMap& eventData)
|
||||
+ std::to_string(cc::get_heating_points(ITEM_TEAK)) + " firewood for teak\n"
|
||||
+ std::to_string(CHOP_WOOD_LABOUR_PER_100_WOOD) + " labour is needed for every 100 wood items chopped";
|
||||
auto *d = new UISelectItemsDialog(context_, gameState, "Select items to chop into firewood", message.c_str(),
|
||||
false,
|
||||
"cc/discoveries/axe-in-stump.svg", false,
|
||||
[](uint32_t item) { return item >= ITEM_FIRST_WOOD && item <= ITEM_LAST_WOOD; });
|
||||
SubscribeToEvent(d, E_SELECT_ITEMS_OKAYED, [this](StringHash eventType, VariantMap& eventData) {
|
||||
SendEvent(E_CRYPTOCITY_CHOP_WOOD, eventData);
|
||||
|
Loading…
Reference in New Issue
Block a user