diff --git a/Source/UI/Exchange/UIExchangeUI.cpp b/Source/UI/Exchange/UIExchangeUI.cpp index ce2f7ced5..0ed78cca6 100644 --- a/Source/UI/Exchange/UIExchangeUI.cpp +++ b/Source/UI/Exchange/UIExchangeUI.cpp @@ -149,20 +149,18 @@ void CUIListBoxEx::OnWheel(int value // FUNCTION: fn_15200 template <> void CUIListBoxEx::OnScroll(int position) { - auto it = this->items.begin(); - if (it == this->items.end()) { + if (this->items.empty()) { return; } if (this->data.size() == 0) { - for (; it != this->items.end(); ++it) { - ExchangeUI::CUIItem* item = *it; + for (auto* item : this->items) { item->index = -1; item->Show(0); } return; } - const int first = (*it)->index; + const int first = this->items.front()->index; unsigned int row = position / this->rowHeight; if (first != -1) { if (first < static_cast(row)) { @@ -170,13 +168,14 @@ void CUIListBoxEx::OnScroll(int posi std::rotate(this->items.begin(), this->items.begin() + (row - first), this->items.end()); } } else if (first > static_cast(row)) { - if (first - row < static_cast(this->items.size())) { - std::rotate(this->items.begin(), this->items.end() - (first - row), this->items.end()); + const unsigned int shift = first - row; + if (shift < static_cast(this->items.size())) { + std::rotate(this->items.begin(), this->items.end() - shift, this->items.end()); } } } - it = this->items.begin(); + auto it = this->items.begin(); for (int y = this->itemY - position % this->rowHeight; y < this->geometry.height; y += this->rowHeight, ++it, ++row) { if (it == this->items.end() || row >= this->data.size()) { break; @@ -197,8 +196,8 @@ void CUIListBoxEx::OnScroll(int posi } } - for (; it != this->items.end(); ++it) { - ExchangeUI::CUIItem* item = *it; + for (const auto end = this->items.end(); it != end; ++it) { + auto* const item = *it; item->index = -1; item->Show(0); } diff --git a/Source/UI/Items/UIEquipmentPropertiesWnd.cpp b/Source/UI/Items/UIEquipmentPropertiesWnd.cpp index 37edd6bea..ea11591e9 100644 --- a/Source/UI/Items/UIEquipmentPropertiesWnd.cpp +++ b/Source/UI/Items/UIEquipmentPropertiesWnd.cpp @@ -157,19 +157,18 @@ void CUIListBoxEx void CUIListBoxEx::OnScroll(int position) { - auto it = this->items.begin(); - if (it == this->items.end()) { + if (this->items.empty()) { return; } if (this->data.size() == 0) { - for (; it != this->items.end(); ++it) { - (*it)->index = -1; - (*it)->Show(0); + for (auto* item : this->items) { + item->index = -1; + item->Show(0); } return; } - const int first = (*it)->index; + const int first = this->items.front()->index; unsigned int row = position / this->rowHeight; if (first != -1) { if (first < static_cast(row)) { @@ -177,13 +176,14 @@ void CUIListBoxExitems.begin(), this->items.begin() + (row - first), this->items.end()); } } else if (first > static_cast(row)) { - if (first - row < static_cast(this->items.size())) { - std::rotate(this->items.begin(), this->items.end() - (first - row), this->items.end()); + const unsigned int shift = first - row; + if (shift < static_cast(this->items.size())) { + std::rotate(this->items.begin(), this->items.end() - shift, this->items.end()); } } } - it = this->items.begin(); + auto it = this->items.begin(); for (int y = this->itemY - position % this->rowHeight; y < this->geometry.height; y += this->rowHeight, ++it, ++row) { if (it == this->items.end() || row >= this->data.size()) { break; @@ -204,8 +204,8 @@ void CUIListBoxExitems.end(); it != end; ++it) { - EquipmentPropertiesWnd::CUIItemEquipmentPropertiesLine* item = *it; + for (const auto end = this->items.end(); it != end; ++it) { + auto* const item = *it; item->index = -1; item->Show(0); } diff --git a/Source/UI/Quest/UIRenewQuestUI.cpp b/Source/UI/Quest/UIRenewQuestUI.cpp index 84ac26ca7..44eb06404 100644 --- a/Source/UI/Quest/UIRenewQuestUI.cpp +++ b/Source/UI/Quest/UIRenewQuestUI.cpp @@ -721,44 +721,45 @@ void CUIListBoxEx::ClearItems() { // FUNCTION: fn_16444 template <> void CUIListBoxEx::OnScroll(int position) { - auto it = this->items.begin(); - if (it == this->items.end()) { + if (this->items.empty()) { return; } if (this->data.size() == 0) { - for (; it != this->items.end(); ++it) { - RenewQuestUI::CUIQuestItem* item = *it; + for (auto* item : this->items) { item->index = -1; item->Show(0); } return; } - const int first = (*it)->index; - int row = position / this->rowHeight; + const int first = this->items.front()->index; + unsigned int row = position / this->rowHeight; if (first != -1) { - if (first < row) { - if (static_cast(row - first) < this->items.size()) { + if (first < static_cast(row)) { + if (row - first < static_cast(this->items.size())) { std::rotate(this->items.begin(), this->items.begin() + (row - first), this->items.end()); } - } else if (first > row) { - if (static_cast(first - row) < this->items.size()) { - std::rotate(this->items.begin(), this->items.end() - (first - row), this->items.end()); + } else if (first > static_cast(row)) { + const unsigned int shift = first - row; + if (shift < static_cast(this->items.size())) { + std::rotate(this->items.begin(), this->items.end() - shift, this->items.end()); } } } - it = this->items.begin(); + auto it = this->items.begin(); for (int y = this->itemY - position % this->rowHeight; y < this->geometry.height; y += this->rowHeight, ++it, ++row) { - if (it == this->items.end() || static_cast(row) >= this->data.size()) { + if (it == this->items.end() || row >= this->data.size()) { break; } RenewQuestUI::CUIQuestItem* item = *it; if (item) { - if (this->rebind || row != item->index) { + if (this->rebind || row != static_cast(item->index)) { item->index = row; if (this->binder) { - this->binder(item, *std::next(this->data.begin(), row)); + auto node = this->data.begin(); + std::advance(node, static_cast(row)); + this->binder(item, *node); } } item->SetSelected(row == this->selected); @@ -767,9 +768,10 @@ void CUIListBoxEx::OnScroll(int posit } } - for (; it != this->items.end(); ++it) { - (*it)->index = -1; - (*it)->Show(0); + for (const auto end = this->items.end(); it != end; ++it) { + auto* const item = *it; + item->index = -1; + item->Show(0); } } diff --git a/Source/UI/SelectPackageItemBox/UISelectPackageItemBox.cpp b/Source/UI/SelectPackageItemBox/UISelectPackageItemBox.cpp index 68862859a..d85a038aa 100644 --- a/Source/UI/SelectPackageItemBox/UISelectPackageItemBox.cpp +++ b/Source/UI/SelectPackageItemBox/UISelectPackageItemBox.cpp @@ -366,19 +366,18 @@ void CUIListBoxEx void CUIListBoxEx::OnScroll(int position) { - auto it = this->items.begin(); - if (it == this->items.end()) { + if (this->items.empty()) { return; } if (this->data.size() == 0) { - for (; it != this->items.end(); ++it) { - (*it)->index = -1; - (*it)->Show(0); + for (auto* item : this->items) { + item->index = -1; + item->Show(0); } return; } - const int first = (*it)->index; + const int first = this->items.front()->index; unsigned int row = position / this->rowHeight; if (first != -1) { if (first < static_cast(row)) { @@ -386,13 +385,14 @@ void CUIListBoxEx::OnScroll(int po std::rotate(this->items.begin(), this->items.begin() + (row - first), this->items.end()); } } else if (first > static_cast(row)) { - if (first - row < static_cast(this->items.size())) { - std::rotate(this->items.begin(), this->items.end() - (first - row), this->items.end()); + const unsigned int shift = first - row; + if (shift < static_cast(this->items.size())) { + std::rotate(this->items.begin(), this->items.end() - shift, this->items.end()); } } } - it = this->items.begin(); + auto it = this->items.begin(); for (int y = this->itemY - position % this->rowHeight; y < this->geometry.height; y += this->rowHeight, ++it, ++row) { if (it == this->items.end() || row >= this->data.size()) { break; @@ -413,9 +413,10 @@ void CUIListBoxEx::OnScroll(int po } } - for (; it != this->items.end(); ++it) { - (*it)->index = -1; - (*it)->Show(0); + for (const auto end = this->items.end(); it != end; ++it) { + auto* const item = *it; + item->index = -1; + item->Show(0); } } @@ -423,19 +424,18 @@ void CUIListBoxEx::OnScroll(int po // FUNCTION: fn_16677 template <> void CUIListBoxEx::OnScroll(int position) { - auto it = this->items.begin(); - if (it == this->items.end()) { + if (this->items.empty()) { return; } if (this->data.size() == 0) { - for (; it != this->items.end(); ++it) { - (*it)->index = -1; - (*it)->Show(0); + for (auto* item : this->items) { + item->index = -1; + item->Show(0); } return; } - const int first = (*it)->index; + const int first = this->items.front()->index; unsigned int row = position / this->rowHeight; if (first != -1) { if (first < static_cast(row)) { @@ -443,13 +443,14 @@ void CUIListBoxExitems.begin(), this->items.begin() + (row - first), this->items.end()); } } else if (first > static_cast(row)) { - if (first - row < static_cast(this->items.size())) { - std::rotate(this->items.begin(), this->items.end() - (first - row), this->items.end()); + const unsigned int shift = first - row; + if (shift < static_cast(this->items.size())) { + std::rotate(this->items.begin(), this->items.end() - shift, this->items.end()); } } } - it = this->items.begin(); + auto it = this->items.begin(); for (int y = this->itemY - position % this->rowHeight; y < this->geometry.height; y += this->rowHeight, ++it, ++row) { if (it == this->items.end() || row >= this->data.size()) { break; @@ -470,9 +471,10 @@ void CUIListBoxExitems.end(); ++it) { - (*it)->index = -1; - (*it)->Show(0); + for (const auto end = this->items.end(); it != end; ++it) { + auto* const item = *it; + item->index = -1; + item->Show(0); } }