| 184 | } |
| 185 | |
| 186 | void SetupEmbeddedScriptPopup::onClose(CCObject* obj) { |
| 187 | if (m_madeChanges && !m_doSave && !m_confirmedExit) { |
| 188 | globed::confirmPopup( |
| 189 | "Note", |
| 190 | "Are you sure you want to <cr>discard</c> all the changes you've made?", |
| 191 | "Cancel", "Discard", |
| 192 | [this](auto) { |
| 193 | m_confirmedExit = true; |
| 194 | this->onClose(nullptr); |
| 195 | } |
| 196 | ); |
| 197 | |
| 198 | return; |
| 199 | } |
| 200 | |
| 201 | // commit changes |
| 202 | if (m_doSave) { |
| 203 | auto res = m_script.encode(true, m_scriptPrefix); |
| 204 | if (!res) { |
| 205 | log::error("Failed to save script: {}", res.unwrapErr()); |
| 206 | globed::alertFormat("Error", "Failed to save script: {}", res.unwrapErr()); |
| 207 | } else { |
| 208 | auto data = std::move(res).unwrap(); |
| 209 | m_object->m_text = gd::string((const char*) data.data(), data.size()); |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | BasePopup::onClose(obj); |
| 214 | } |
| 215 | |
| 216 | SetupEmbeddedScriptPopup* SetupEmbeddedScriptPopup::create(TextGameObject* obj) { |
| 217 | auto ret = new SetupEmbeddedScriptPopup(); |
no test coverage detected