* Rename a sign. If the new name of the sign is empty, we assume * the user wanted to delete it. So delete it. Ownership of signs * has no meaning/effect whatsoever except for eyecandy * @param flags type of operation * @param sign_id index of the sign to be renamed/removed * @param text the new name or an empty string when resetting to the default * @return the cost of this operation or an
| 65 | * @return the cost of this operation or an error |
| 66 | */ |
| 67 | CommandCost CmdRenameSign(DoCommandFlags flags, SignID sign_id, const std::string &text) |
| 68 | { |
| 69 | Sign *si = Sign::GetIfValid(sign_id); |
| 70 | if (si == nullptr) return CMD_ERROR; |
| 71 | if (!CompanyCanEditSign(si)) return CMD_ERROR; |
| 72 | |
| 73 | /* Rename the signs when empty, otherwise remove it */ |
| 74 | if (!text.empty()) { |
| 75 | if (Utf8StringLength(text) >= MAX_LENGTH_SIGN_NAME_CHARS) return CMD_ERROR; |
| 76 | |
| 77 | if (flags.Test(DoCommandFlag::Execute)) { |
| 78 | /* Assign the new one */ |
| 79 | si->name = text; |
| 80 | if (_game_mode != GM_EDITOR) si->owner = _current_company; |
| 81 | |
| 82 | si->UpdateVirtCoord(); |
| 83 | InvalidateWindowData(WC_SIGN_LIST, 0, 1); |
| 84 | } |
| 85 | } else { // Delete sign |
| 86 | if (flags.Test(DoCommandFlag::Execute)) { |
| 87 | si->sign.MarkDirty(); |
| 88 | if (si->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeSign(si->index)); |
| 89 | delete si; |
| 90 | |
| 91 | InvalidateWindowData(WC_SIGN_LIST, 0, 0); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | return CommandCost(); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Move a sign to the given coordinates. Ownership of signs |
nothing calls this directly
no test coverage detected