| 1001 | } |
| 1002 | |
| 1003 | void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override |
| 1004 | { |
| 1005 | switch (widget) { |
| 1006 | case WID_IV_INFO: { |
| 1007 | Industry *i = Industry::Get(this->window_number); |
| 1008 | InfoLine line = IL_NONE; |
| 1009 | |
| 1010 | switch (this->editable) { |
| 1011 | case EA_NONE: break; |
| 1012 | |
| 1013 | case EA_MULTIPLIER: |
| 1014 | if (IsInsideBS(pt.y, this->production_offset_y, this->cheat_line_height)) line = IL_MULTIPLIER; |
| 1015 | break; |
| 1016 | |
| 1017 | case EA_RATE: |
| 1018 | if (pt.y >= this->production_offset_y) { |
| 1019 | int row = (pt.y - this->production_offset_y) / this->cheat_line_height; |
| 1020 | for (auto itp = std::begin(i->produced); itp != std::end(i->produced); ++itp) { |
| 1021 | if (!IsValidCargoType(itp->cargo)) continue; |
| 1022 | row--; |
| 1023 | if (row < 0) { |
| 1024 | line = (InfoLine)(IL_RATE1 + (itp - std::begin(i->produced))); |
| 1025 | break; |
| 1026 | } |
| 1027 | } |
| 1028 | } |
| 1029 | break; |
| 1030 | } |
| 1031 | if (line == IL_NONE) return; |
| 1032 | |
| 1033 | bool rtl = _current_text_dir == TD_RTL; |
| 1034 | Rect r = this->GetWidget<NWidgetBase>(widget)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect).Indent(this->cargo_icon_size.width + WidgetDimensions::scaled.hsep_normal, rtl); |
| 1035 | |
| 1036 | if (r.WithWidth(SETTING_BUTTON_WIDTH, rtl).Contains(pt)) { |
| 1037 | /* Clicked buttons, decrease or increase production */ |
| 1038 | bool decrease = r.WithWidth(SETTING_BUTTON_WIDTH / 2, rtl).Contains(pt); |
| 1039 | switch (this->editable) { |
| 1040 | case EA_MULTIPLIER: |
| 1041 | if (decrease) { |
| 1042 | if (i->prod_level <= PRODLEVEL_MINIMUM) return; |
| 1043 | i->prod_level = static_cast<uint8_t>(std::max<uint>(i->prod_level / 2, PRODLEVEL_MINIMUM)); |
| 1044 | } else { |
| 1045 | if (i->prod_level >= PRODLEVEL_MAXIMUM) return; |
| 1046 | i->prod_level = static_cast<uint8_t>(std::min<uint>(i->prod_level * 2, PRODLEVEL_MAXIMUM)); |
| 1047 | } |
| 1048 | break; |
| 1049 | |
| 1050 | case EA_RATE: |
| 1051 | if (decrease) { |
| 1052 | if (i->produced[line - IL_RATE1].rate <= 0) return; |
| 1053 | i->produced[line - IL_RATE1].rate = std::max(i->produced[line - IL_RATE1].rate / 2, 0); |
| 1054 | } else { |
| 1055 | if (i->produced[line - IL_RATE1].rate >= 255) return; |
| 1056 | /* a zero production industry is unlikely to give anything but zero, so push it a little bit */ |
| 1057 | int new_prod = i->produced[line - IL_RATE1].rate == 0 ? 1 : i->produced[line - IL_RATE1].rate * 2; |
| 1058 | i->produced[line - IL_RATE1].rate = ClampTo<uint8_t>(new_prod); |
| 1059 | } |
| 1060 | break; |
nothing calls this directly
no test coverage detected