~widelands-dev/widelands/trunk

« back to all changes in this revision

Viewing changes to src/wui/waresdisplay.cc

  • Committer: The Widelands Bunnybot
  • Date: 2024-10-19 13:45:54 UTC
  • Revision ID: bunnybot@widelands.org-20241019134554-kz2gcbecf0y7bd7n
170 files were automatically formatted.

(by bunnybot)
5a9087b08ab9bbc48795ff0f7f1f370f60108b1a

Show diffs side-by-side

added added

removed removed

Lines of Context:
155
155
        curware_.set_fixed_width(get_inner_w());
156
156
 
157
157
        curware_.set_text(index != Widelands::INVALID_INDEX ?
158
 
                        (type_ == Widelands::wwWORKER ? tribe_.get_worker_descr(index)->descname() :
159
 
                                                        tribe_.get_ware_descr(index)->descname()) :
160
 
                        "");
 
158
                             (type_ == Widelands::wwWORKER ? tribe_.get_worker_descr(index)->descname() :
 
159
                                                             tribe_.get_ware_descr(index)->descname()) :
 
160
                             "");
161
161
        if (selection_anchor_ != Widelands::INVALID_INDEX) {
162
162
                // Ensure mouse button is still pressed as some
163
163
                // mouse release events do not reach us
468
468
 
469
469
                                const UI::WareInfoStyleInfo& style =
470
470
                                   draw_selected ? g_style_manager->ware_info_style(UI::WareInfoStyle::kHighlight) :
471
 
                               g_style_manager->ware_info_style(UI::WareInfoStyle::kNormal);
 
471
                                                   g_style_manager->ware_info_style(UI::WareInfoStyle::kNormal);
472
472
 
473
473
                                if (update) {
474
474
                                        ware_details_cache_[id].second =
488
488
                                }
489
489
 
490
490
                                const Image* icon = type_ == Widelands::wwWARE ? tribe_.get_ware_descr(id)->icon() :
491
 
                                                             tribe_.get_worker_descr(id)->icon();
 
491
                                                                                 tribe_.get_worker_descr(id)->icon();
492
492
                                background_texture_->blit(
493
493
                                   Rectf(p.x + (w - kWareMenuPicWidth) / 2.f, p.y + 1, icon->width(), icon->height()),
494
494
                                   *icon, Rectf(0, 0, icon->width(), icon->height()), 1.f, BlendMode::Default);
499
499
                        if (!hidden_[id]) {
500
500
                                const UI::WareInfoStyleInfo& style =
501
501
                                   draw_ware_as_selected(id) ?
502
 
                  g_style_manager->ware_info_style(UI::WareInfoStyle::kHighlight) :
503
 
                  g_style_manager->ware_info_style(UI::WareInfoStyle::kNormal);
 
502
                                      g_style_manager->ware_info_style(UI::WareInfoStyle::kHighlight) :
 
503
                                      g_style_manager->ware_info_style(UI::WareInfoStyle::kNormal);
504
504
                                ware_details_cache_[id].second =
505
505
                                   UI::g_fh->render(as_richtext_paragraph(info_for_ware(id), style.info_font()));
506
506
                        }
522
522
 
523
523
        const UI::WareInfoStyleInfo& style =
524
524
           draw_selected ? g_style_manager->ware_info_style(UI::WareInfoStyle::kHighlight) :
525
 
                      g_style_manager->ware_info_style(UI::WareInfoStyle::kNormal);
 
525
                           g_style_manager->ware_info_style(UI::WareInfoStyle::kNormal);
526
526
 
527
527
        uint16_t w = style.icon_background_image()->width();
528
528
 
612
612
 
613
613
        // Indicate trend over the last 5 minutes
614
614
        const std::vector<uint32_t>& history = get_type() == Widelands::wwWARE ?
615
 
                                             *player_.get_ware_stock_statistics(di) :
616
 
                                             *player_.get_worker_stock_statistics(di);
 
615
                                                  *player_.get_ware_stock_statistics(di) :
 
616
                                                  *player_.get_worker_stock_statistics(di);
617
617
        const size_t nr_entries = history.size();
618
618
 
619
619
        if (nr_entries == 0u) {
624
624
        const size_t kSampleEntriesForTrend = 5 * 60 * 1000 / Widelands::kStatisticsSampleTime.get();
625
625
        const uint32_t last_amount =
626
626
           history[nr_entries < kSampleEntriesForTrend ? nr_entries - 1 :
627
 
                                                    nr_entries - kSampleEntriesForTrend];
 
627
                                                         nr_entries - kSampleEntriesForTrend];
628
628
 
629
629
        const UI::BuildingStatisticsStyleInfo& colors = g_style_manager->building_statistics_style();
630
630
        const std::string indicator =
631
631
           current_amount < last_amount ?
632
 
         StyleManager::color_tag(_("↓"), colors.alternative_low_color()) :
 
632
              StyleManager::color_tag(_("↓"), colors.alternative_low_color()) :
633
633
           current_amount > last_amount ?
634
 
         StyleManager::color_tag(_("↑"), colors.alternative_high_color()) :
635
 
         StyleManager::color_tag(_("="), colors.alternative_medium_color());
 
634
              StyleManager::color_tag(_("↑"), colors.alternative_high_color()) :
 
635
              StyleManager::color_tag(_("="), colors.alternative_medium_color());
636
636
        /** TRANSLATORS: The first placeholder is the stock amount of a ware/worker, and the second is an
637
637
         * icon indicating a trend. Very little space is available. */
638
638
        return format(_("%1$s%2$s"), text, indicator);
658
658
        const RGBColor& color =
659
659
           amount < target ? g_style_manager->building_statistics_style().alternative_low_color() :
660
660
           amount > target ? g_style_manager->building_statistics_style().alternative_high_color() :
661
 
                        g_style_manager->building_statistics_style().alternative_medium_color();
 
661
                             g_style_manager->building_statistics_style().alternative_medium_color();
662
662
        return RGBAColor(color.r, color.g, color.b, 160);
663
663
}
664
664
 
697
697
                        } else {
698
698
                                for (const Widelands::Warehouse* warehouse : economy.second->warehouses()) {
699
699
                                        totalstock += (get_type() == Widelands::wwWARE ? warehouse->get_wares() :
700
 
                                                                warehouse->get_workers())
 
700
                                                                                         warehouse->get_workers())
701
701
                                                         .stock(ware);
702
702
                                }
703
703
                        }