From 0835ecd1f77fe98b1dcc84130d068f8fadb6af0d Mon Sep 17 00:00:00 2001 From: Rick Date: Mon, 22 Nov 2021 21:33:39 +0000 Subject: [PATCH] hedit: add button to delete handlings (#360) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Make grid a little smaller to add delete button and shift other buttons slightly upwards * Add message for successful delete (only english) * Create function to delete node from save file * Correct the debug messages * Add Arabic translation by [SW]Falcon * Add Turkish translation by ᴏᴠ | Gürkan * Update polish.lua * Added Russian translation by Google Translate * Add Spanish translation by Fantome * Refactor variable * Update russian.lua * ru fix typo * Revert "Add Spanish translation by Fantome" This reverts commit 76388a65c3dabfd9e9a48a2b8a14ca467e9431d7. * Revert "Added Russian translation by Google Translate" This reverts commit e5ec614b0c0d11567ac56bb1a632b6373b631444. * Revert "Update polish.lua" This reverts commit 703da786849e553e9fe23eb8193860669b01a7e7. * Revert "Add Turkish translation by ᴏᴠ | Gürkan" This reverts commit 3653216f1bb0d715471e011820d8c0fd205564f3. * Revert "Add Arabic translation by [SW]Falcon" This reverts commit a318b2b562b29057e38fa922ac7843ed4f1b082a. * Revert "Update russian.lua" This reverts commit 62919c98fd7a979d2f99c74b1441b07f368f768e. Co-authored-by: Inder00 Co-authored-by: Konstantin --- .../hedit/client/gui/languages/arabic.lua | 1 + .../hedit/client/gui/languages/english.lua | 2 ++ .../hedit/client/gui/languages/polish.lua | 3 +- .../hedit/client/gui/languages/russian.lua | 1 + .../hedit/client/gui/languages/spanish.lua | 1 + .../hedit/client/gui/languages/turkish.lua | 1 + .../hedit/client/gui/templates/default.lua | 31 +++++++++++++++++-- [gameplay]/hedit/client/utils.lua | 27 ++++++++++++++++ 8 files changed, 63 insertions(+), 4 deletions(-) diff --git a/[gameplay]/hedit/client/gui/languages/arabic.lua b/[gameplay]/hedit/client/gui/languages/arabic.lua index 83f6d82f6..5f721835d 100644 --- a/[gameplay]/hedit/client/gui/languages/arabic.lua +++ b/[gameplay]/hedit/client/gui/languages/arabic.lua @@ -36,6 +36,7 @@ guiLanguage.arabic = { successSave = "تم حفظ اعدادات وزانيتك بنجاح", successLoad = "تم تحميل اعدادات وزانيتك بنجاح", + successDelete = "", wantTheSettings = "هل انت متاكد من انك تريد تطبيق هذه الاعدادات ? معدل وزانيات سيتم اعادة تشغيله", diff --git a/[gameplay]/hedit/client/gui/languages/english.lua b/[gameplay]/hedit/client/gui/languages/english.lua index 730251551..b7b73ecb4 100644 --- a/[gameplay]/hedit/client/gui/languages/english.lua +++ b/[gameplay]/hedit/client/gui/languages/english.lua @@ -36,6 +36,7 @@ guiLanguage.english = { successSave = "Successfully saved your handling settings!", successLoad = "Successfully loaded your handling settings!", + sucessDelete = "Successfully deleted your handling settings!", wantTheSettings = "Are you sure you would like to apply these settings? The handling editor will restart.", @@ -154,6 +155,7 @@ guiLanguage.english = { descriptionLabel = "Description", saveButton = "Save", loadButton = "Load", + deleteButton = "Delete", grid = "", nameEdit = "", descriptionEdit = "" diff --git a/[gameplay]/hedit/client/gui/languages/polish.lua b/[gameplay]/hedit/client/gui/languages/polish.lua index cb365cd23..a106f2cba 100644 --- a/[gameplay]/hedit/client/gui/languages/polish.lua +++ b/[gameplay]/hedit/client/gui/languages/polish.lua @@ -36,7 +36,8 @@ guiLanguage.polish = { successSave = "Pomyslnie zapisano twoje ustawienia", successLoad = "Pomyslnie wczytano twoje ustawienia!", - + sucessDelete = "", + wantTheSettings = "Czy na pewno chcesz zastosowac te ustawienia? Edytor uruchomi sie ponownie.", vehicle = "Pojazd", diff --git a/[gameplay]/hedit/client/gui/languages/russian.lua b/[gameplay]/hedit/client/gui/languages/russian.lua index 0e201b237..47266b451 100644 --- a/[gameplay]/hedit/client/gui/languages/russian.lua +++ b/[gameplay]/hedit/client/gui/languages/russian.lua @@ -36,6 +36,7 @@ successSave = "Вы успешно сохранили ваш хэндлинг!", successLoad = "Вы успешно загрузили ваш хэндлинг!", + sucessDelete = "", wantTheSettings = "Вы уверены, что хотите применить эти настройки? Редактор хэндлинга будет перезагружен.", diff --git a/[gameplay]/hedit/client/gui/languages/spanish.lua b/[gameplay]/hedit/client/gui/languages/spanish.lua index 85f831ba2..2589c63ab 100644 --- a/[gameplay]/hedit/client/gui/languages/spanish.lua +++ b/[gameplay]/hedit/client/gui/languages/spanish.lua @@ -40,6 +40,7 @@ successSave = "Se guardo el handling con exito!", successLoad = "Se cargo el handling con exito!", + sucessDelete = "", confirmVersionReset = "Estas seguro de que deseas establecer la version del editor a la de este servidor? Tus handlings guardados pueden llegar a ser incompatibles.", successVersionReset = "La version de editor se ha actualizado.", diff --git a/[gameplay]/hedit/client/gui/languages/turkish.lua b/[gameplay]/hedit/client/gui/languages/turkish.lua index 3ce90ef81..c656e1c47 100644 --- a/[gameplay]/hedit/client/gui/languages/turkish.lua +++ b/[gameplay]/hedit/client/gui/languages/turkish.lua @@ -36,6 +36,7 @@ guiLanguage.turkish = { successSave = "Başarıyla işleme ayarlarını kurtardı!", successLoad = "Başarıyla senin kullanımı ayarlarını yüklenen!", + sucessDelete = "", wantTheSettings = "Bu ayarları uygulamak istiyorum emin misiniz? Taşıma editörü yeniden başlar.", diff --git a/[gameplay]/hedit/client/gui/templates/default.lua b/[gameplay]/hedit/client/gui/templates/default.lua index 951710513..d456387ae 100644 --- a/[gameplay]/hedit/client/gui/templates/default.lua +++ b/[gameplay]/hedit/client/gui/templates/default.lua @@ -658,7 +658,7 @@ template.viewcontents = { grid = { type = "gridlist", pos = { 72, 83 }, - size = { 285, 246 }, + size = { 285, 220 }, runfunction = function ( this ) guiGridListAddColumn ( this, "Name", 0.5 ) guiGridListAddColumn ( this, "Model", 0.4 ) @@ -782,7 +782,7 @@ template.viewcontents = { }, saveButton = { type = "button", - pos = { 289, 334 }, + pos = { 289, 309 }, size = { 68, 25 }, events = { onClick = function ( this ) @@ -813,7 +813,7 @@ template.viewcontents = { loadButton = { type = "button", - pos = { 289, 359 }, + pos = { 289, 334 }, size = { 68, 25 }, events = { onClick = function ( this ) @@ -838,6 +838,31 @@ template.viewcontents = { end end } + }, + + deleteButton = { + type = "button", + pos = { 289, 359 }, + size = { 68, 25 }, + events = { + onClick = function ( this ) + local content = heditGUI.viewItems.save.guiItems + local row,col = guiGridListGetSelectedItem ( content.grid ) + + if row ~= -1 and col ~= -1 then + local name = string.lower ( guiGridListGetItemText ( content.grid, row, col ) ) + + local function func ( ) + if deleteClientHandling ( pVehicle, name ) then + guiCreateWarningMessage ( getText ( "sucessDelete" ), 3 ) + end + end + + guiCreateWarningMessage ( getText ( "confirmDelete" ), 2, {func} ) + return true + end + end + } } } }, diff --git a/[gameplay]/hedit/client/utils.lua b/[gameplay]/hedit/client/utils.lua index eb05e8c80..ed36357e1 100644 --- a/[gameplay]/hedit/client/utils.lua +++ b/[gameplay]/hedit/client/utils.lua @@ -307,6 +307,33 @@ function loadClientHandling ( vehicle, name ) return true end +function deleteClientHandling ( vehicle, name ) + if not isValidVehicle ( vehicle ) then + if DEBUGMODE then + error ( "Invalid vehicle element at 'deleteClientHandling'! ["..tostring(vehicle).."]", 2 ) + end + + return false + end + + if not isClientHandlingExisting ( name ) then + if DEBUGMODE then + error ( "Handling name given at 'deleteClientHandling' does not exist! ["..tostring(name).."]", 2 ) + end + + return false + end + + name = string.lower ( name ) + local handling = xmlCache.clientsaves[name].saveNode + + xmlDestroyNode ( handling ) + xmlSaveFile ( xmlFile[client_handling_file] ) + + xmlCache.clientsaves[name] = nil + + return true +end -- Imports a handling line in handling.cfg format, given a proper method. -- Valid methods: III, VC, SA, and IV