Advertisement
Guest User

ui_debug_main.script

a guest
Aug 24th, 2015
720
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 67.49 KB | None | 0 0
  1. -- axr_debug_tools UI script
  2. -- Alundaio
  3. --[[
  4. Copyright (C) 2012 Alundaio
  5. This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License-]]
  6. --]]
  7.  
  8. id_to_spawn_table = {
  9.         [1] = "Ammo",
  10.         [2] = "Artefacts",
  11.         [3] = "Items (Consumable)",
  12.         [4] = "Items (Misc.)",
  13.         [5] = "Items (Quest)",
  14.         [6] = "NPC (Mutant)",              
  15.         [7] = "NPC (Stalker)",             
  16.         [8] = "Outfits",
  17.         [9] = "Physic (Misc.)",            
  18.         [10] = "Squads (Mutant)",          
  19.         [11] = "Squads (Stalker)",         
  20.         [12] = "Weapons (Addon)",
  21.         [13] = "Weapons (Misc.)",
  22.         [14] = "Weapons (Pistol)",
  23.         [15] = "Weapons (Rifle)",
  24.         [16] = "Vehicles",
  25.         [17] = "Anomaly",
  26.         [18] = "Phantom"
  27. }
  28.  
  29. function get_spawn_table(name)
  30.     if (name == "Phantom") then
  31.         return {
  32.             "m_phantom_bloodsucker",
  33.             "m_phantom_tushkano",
  34.             "m_phantom_controller",
  35.             "m_phantom_zombi",
  36.             "m_phantom_snork",
  37.             "m_phantom_boar",
  38.             "m_phantom_flesh",
  39.             "m_phantom_dog",
  40.             "m_phantom_pseudodog",
  41.             "m_phantom_cat"
  42.         }
  43.     elseif (name == "Anomaly") then
  44.         return {
  45.                 "zone_mine_gravitational_weak",
  46.                 "zone_mine_thermal_weak",
  47.                 "zone_mine_acidic_weak",
  48.                 "zone_mine_electric_weak",
  49.                 "zone_field_radioactive_weak",
  50.                 "zone_mine_steam_weak",
  51.                 "zone_field_psychic_weak",
  52.                 --"fireball_zone",
  53.                 --"fireball_electric_zone",
  54.                 --"fireball_acidic_zone",
  55.                 "zone_mine_field",
  56.                 "zone_mine_field_soc",
  57.                 "zone_no_gravity",
  58.                 "zone_teleport"
  59.         }
  60.     elseif (name == "Artefacts") then
  61.         return {
  62.                 "af_medusa",            -- 1
  63.                 "af_cristall_flower",   -- 2
  64.                 "af_night_star",        -- 3
  65.                 "af_vyvert",            -- 4
  66.                 "af_gravi",             -- 5
  67.                 "af_gold_fish",         -- 6
  68.                 "af_cristall",          -- 7
  69.                 "af_fireball",          -- 8
  70.                 "af_dummy_glassbeads",  -- 9
  71.                 "af_eye",               -- 10
  72.                 "af_fire",              -- 11
  73.                 "af_blood",             -- 12
  74.                 "af_mincer_meat",       -- 13
  75.                 "af_soul",              -- 14
  76.                 "af_fuzz_kolobok",      -- 15
  77.                 "af_baloon",            -- 16
  78.                 "af_glass",             -- 17
  79.                 "af_electra_sparkler",  -- 18
  80.                 "af_electra_flash",     -- 19
  81.                 "af_electra_moonlight", -- 20
  82.                 "af_dummy_battery",     -- 21
  83.                 "af_dummy_dummy",       -- 22
  84.                 "af_ice",               -- 23
  85.                 "af_compass",           -- 24
  86.                 "af_oasis_heart",       -- 25
  87.                 "jup_b1_half_artifact", -- 26
  88.                 "af_quest_b14_twisted", -- 27
  89.                 "af_drops",             -- 28
  90.                 "af_ameba_slime",       -- 29
  91.                 "af_ameba_slug",        -- 30
  92.                 "af_ameba_mica",        -- 31
  93.                 "af_dummy_spring",      -- 32
  94.                 "af_dummy_pellicle",    -- 33
  95.                 "af_rusty_thorn",       -- 34
  96.                 "af_rusty_kristall",    -- 35
  97.                 "af_rusty_sea", -- 36
  98.                 }
  99.     elseif (name == "Outfits") then
  100.         return {
  101.                 "helm_respirator",
  102.                 "helm_hardhat",
  103.                 "helm_protective",
  104.                 "helm_tactic",
  105.                 "helm_battle",
  106.                 "helm_respirator_joker",
  107.                 "helm_hardhat_snag",
  108.                 "helm_m40",
  109.                
  110.                 --Freedom
  111.                 "svoboda_novice_outfit",
  112.                 "svoboda_light_outfit",
  113.                 "svoboda_heavy_outfit",
  114.                 "svoboda_heavy_outfit_2",
  115.                 "svoboda_exo_outfit",
  116.                
  117.                 --Ecolog
  118.                 "ecolog_outfit_green",
  119.                 "ecolog_outfit_orange",
  120.                 "scientific_outfit",
  121.                 "ecolog_guard_outfit",
  122.                
  123.                 --Stalker
  124.                 "novice_outfit",
  125.                 "stalker_outfit",
  126.                 "stalker_outfit_barge",
  127.                 "exo_outfit",
  128.                
  129.                 --Bandit
  130.                 "bandit_novice_outfit",
  131.                 "banditmerc_outfit",
  132.                 "trenchcoat_outfit",
  133.                
  134.                 -- Duty
  135.                 "dolg_novice_outfit",
  136.                 "dolg_outfit",
  137.                 "dolg_heavy_outfit",
  138.                 "dolg_exo_outfit",
  139.                
  140.                 -- Army
  141.                 "military_outfit",
  142.                 "specops_outfit",
  143.                
  144.                 -- Clear Sky
  145.                 "cs_novice_outfit",
  146.                 "cs_light_outfit",
  147.                 "cs_medium_outfit",
  148.                 "cs_heavy_outfit",
  149.                
  150.                 -- Mercenary
  151.                 "merc_outfit",
  152.                
  153.                
  154.                 "god_outfit"
  155.                 }
  156.     elseif (name == "Items (Misc.)") then
  157.         return {
  158.                 "mutant_part_krovosos_jaw",
  159.                 "mutant_part_boar_leg",
  160.                 "mutant_part_chimera_kogot",
  161.                 "mutant_part_chimera_claw",
  162.                 "mutant_part_dog_tail",
  163.                 "mutant_part_flesh_eye",
  164.                 "mutant_part_psevdodog_tail",
  165.                 "mutant_part_snork_leg",
  166.                 "mutant_part_tushkano_head",
  167.                 "mutant_part_pseudogigant_hand",
  168.                 "mutant_part_pseudogigant_eye",
  169.                 "mutant_part_controller_glass",
  170.                 "mutant_part_controller_hand",
  171.                 "mutant_part_burer_hand",
  172.                 "mutant_part_cat_tail",
  173.                 "mutant_part_fracture_hand",
  174.                 "mutant_part_zombi_hand",
  175.                 "device_torch",
  176.                 "detector_simple",
  177.                 "detector_advanced",
  178.                 "detector_elite",
  179.                 "detector_scientific",
  180.                 "itm_actor_backpack",
  181.                 "itm_backpack",
  182.                 "itm_sleepbag",
  183.                 "itm_pda_common",
  184.                 "itm_pda_uncommon",
  185.                 "itm_pda_rare",
  186.                 "itm_gunsmith_toolkit",
  187.                 "itm_gunsmith_toolkit_tier_2",
  188.                 "stalker_patch",
  189.                 "ecolog_patch",
  190.                 "duty_patch",
  191.                 "merc_patch",
  192.                 "freedom_patch",
  193.                 "bandit_patch",
  194.                 "army_patch",
  195.                 "monolith_patch",
  196.                 "csky_patch"
  197.                 }
  198.     elseif (name == "Items (Consumable)") then
  199.         return {
  200.                 "bandage",
  201.                 "antirad",
  202.                 "medkit",
  203.                 "medkit_army",
  204.                 "medkit_scientic",
  205.  
  206.                 "drug_booster",
  207.                 "drug_coagulant",
  208.                 "drug_psy_blockade",
  209.                 "drug_antidot",
  210.                 "drug_radioprotector",
  211.                 "drug_anabiotic",
  212.  
  213.                 "bread",
  214.                 "kolbasa",
  215.                 "conserva",
  216.                 "vodka",
  217.                 "energy_drink"
  218.                 }
  219.     elseif (name == "Weapons (Addon)") then
  220.         return {
  221.                 "wpn_addon_scope",
  222.                 "wpn_addon_scope_x2.7",
  223.                 "wpn_addon_scope_detector",
  224.                 "wpn_addon_scope_night",
  225.                 "wpn_addon_scope_susat",
  226.                 "wpn_addon_scope_susat_x1.6",
  227.                 "wpn_addon_scope_susat_custom",
  228.                 "wpn_addon_scope_susat_dusk",
  229.                 "wpn_addon_scope_susat_night",
  230.                 "wpn_addon_silencer",
  231.                 "wpn_addon_grenade_launcher",
  232.                 "wpn_addon_grenade_launcher_m203",
  233.                 "wpn_addon_scope_pu",
  234.                 "addons_box",
  235.                 "1p78",
  236.                 "kobra",
  237.                 "pso"
  238.                 }
  239.     elseif (name == "Weapons (Pistol)") then
  240.         return  {
  241.                 "wpn_beretta",
  242.                 "wpn_desert_eagle",
  243.                 "wpn_desert_eagle_nimble",
  244.                 "wpn_pm",
  245.                 "wpn_pm_actor",
  246.                 "wpn_pb",
  247.                 "wpn_fort",
  248.                 "wpn_fort_snag",
  249.                 "wpn_hpsa",
  250.                 "wpn_walther",
  251.                 "wpn_sig220",
  252.                 "wpn_sig220_nimble",
  253.                 "wpn_colt1911",
  254.                 "wpn_usp",
  255.                 "wpn_usp_nimble"
  256.                 }
  257.     elseif (name == "Weapons (Rifle)") then
  258.         return {
  259.                 "wpn_bm16",
  260.                 "wpn_toz34",
  261.                 "wpn_wincheaster1300",
  262.                 "wpn_spas12",
  263.                 "wpn_spas12_nimble",
  264.                 "wpn_protecta",
  265.                 "wpn_protecta_nimble",
  266.                 "wpn_ak74u",
  267.                 "wpn_mp5",
  268.                 "wpn_ak74",
  269.                 "wpn_abakan",
  270.                 "wpn_l85",
  271.                 "wpn_lr300",
  272.                 "wpn_sig550",
  273.                 "wpn_groza",
  274.                 "wpn_val",
  275.                 "wpn_vintorez",
  276.                 "wpn_svu",
  277.                 "wpn_svd",
  278.                 "wpn_rg-6",
  279.                 "wpn_rpg7",
  280.                 "wpn_g36",
  281.                 "wpn_fn2000",
  282.                 "wpn_pkm",
  283.                 "wpn_gauss",
  284.                 "wpn_wincheaster1300_trapper",
  285.                 "wpn_ak74u_snag",
  286.                 "wpn_mp5_nimble",
  287.                 "wpn_sig550_luckygun",
  288.                 "wpn_groza_nimble",
  289.                 "wpn_vintorez_nimble",
  290.                 "wpn_svu_nimble",
  291.                 "wpn_svd_nimble",
  292.                 "wpn_g36_nimble",
  293.                 "wpn_fn2000_nimble",
  294.                 "wpn_pkm_zulus",
  295.                 "pri_a17_gauss_rifle",
  296.                 "wpn_l96",
  297.                 "wpn_mosin",
  298.                 "wpn_sako",
  299.                 "wpn_svt40"
  300.             }
  301.     elseif (name == "Weapons (Misc.)") then
  302.         return  {
  303. --              "explosive_barrel",
  304. --              "explosive_mobiltank",
  305. --              "explosive_dinamit",
  306.                 "grenade_f1",
  307.                 "grenade_rgd5",
  308.                 "grenade_gd-05",
  309.                 "wpn_knife",
  310.                 "wpn_binoc",
  311.                 "wpn_mine"
  312.                 }
  313.     elseif (name == "Items (Quest)") then
  314.         return {
  315.                 "bad_psy_helmet",
  316.                 "good_psy_helmet",
  317.                 "jup_a9_conservation_info",
  318.                 "jup_a9_power_info",
  319.                 "jup_a9_way_info",
  320.                 "jup_a9_evacuation_info",
  321.                 "jup_a9_meeting_info",
  322.                 "jup_a9_losses_info",
  323.                 "jup_a9_delivery_info",
  324.                 "jup_b10_ufo_memory",
  325.                 "jup_b10_ufo_memory_2",
  326.                 "jup_b10_notes_01",
  327.                 "jup_b10_notes_02",
  328.                 "jup_b10_notes_03",
  329.                 "jup_b205_sokolov_note",
  330.                 "jup_b206_plant",
  331.                 "jup_b209_monster_scanner",
  332.                 "jup_b200_tech_materials_wire",
  333.                 "jup_b200_tech_materials_acetone",
  334.                 "jup_b200_tech_materials_textolite",
  335.                 "jup_b200_tech_materials_transistor",
  336.                 "jup_b200_tech_materials_capacitor",
  337.                 "jup_b202_bandit_pda",
  338.                 "device_flash_snag",
  339.                 "jup_b9_blackbox",
  340.                 "jup_b32_scanner_device",
  341.                 "jup_b46_duty_founder_pda",
  342.                 "jup_b207_merc_pda_with_contract",
  343.                 "jup_b47_jupiter_products_info",
  344.                 "jup_b47_merc_pda",
  345.                 "toolkit_1",
  346.                 "toolkit_2",
  347.                 "toolkit_3",
  348.                 "zat_b33_safe_container",
  349.                 "zat_b57_gas",
  350.                 "zat_b12_key_1",
  351.                 "zat_b12_key_2",
  352.                 "zat_b12_documents_1",
  353.                 "zat_b12_documents_2",
  354.                 "device_pda_port_bandit_leader",
  355.                 "zat_b40_notebook",
  356.                 "zat_b40_pda_1",
  357.                 "zat_b40_pda_2",
  358.                 "device_pda_zat_b5_dealer",
  359.                 "zat_b20_noah_pda",
  360.                 "zat_a23_access_card",
  361.                 "zat_a23_gauss_rifle_docs",
  362.                 "zat_b44_barge_pda",
  363.                 "zat_b39_joker_pda",
  364.                 "zat_b22_medic_pda",
  365.                 "pri_b35_lab_x8_key",
  366.                 "pri_b306_envoy_pda",
  367.                 "pri_b36_monolith_hiding_place_pda",
  368.                 "pri_a25_explosive_charge_item",
  369.                 "pri_a19_american_experiment_info",
  370.                 "pri_a19_lab_x16_info",
  371.                 "pri_a19_lab_x10_info",
  372.                 "pri_a19_lab_x7_info",
  373.                 "pri_a19_lab_x18_info",
  374.                 "zat_a23_labx8_key",
  375.                 "lx8_service_instruction"
  376.                 }
  377.     elseif (name == "Ammo") then
  378.         return {
  379.                 "ammo_9x18_fmj",
  380.                 "ammo_9x18_pmm",
  381.                 "ammo_9x19_fmj",
  382.                 "ammo_9x19_pbp",
  383.                 "ammo_11.43x23_fmj",
  384.                 "ammo_11.43x23_hydro",
  385.                 "ammo_5.45x39_fmj",
  386.                 "ammo_5.45x39_ap",
  387.                 "ammo_5.56x45_ss190",
  388.                 "ammo_5.56x45_ap",
  389.                 "ammo_pkm_100",
  390.                 "ammo_7.62x54_7h1",
  391.                 "ammo_gauss",
  392.                 "ammo_gauss_cardan",
  393.                 "ammo_9x39_pab9",
  394.                 "ammo_9x39_ap",
  395.                 "ammo_12x70_buck",
  396.                 "ammo_12x76_zhekan",
  397.                 "ammo_og-7b",
  398.                 "ammo_vog-25",
  399.                 "ammo_m209",
  400.                 "ammo_7.62x51"
  401.                 }
  402.     elseif (name == "NPC (Stalker)") then
  403.         return {
  404.                 "sim_default_stalker_0",
  405.                 "sim_default_stalker_1",
  406.                 "sim_default_stalker_2",
  407.                 "sim_default_stalker_3",
  408.                 "sim_default_stalker_4",
  409.                 "sim_default_bandit_0",
  410.                 "sim_default_bandit_1",
  411.                 "sim_default_bandit_2",
  412.                 "sim_default_bandit_3",
  413.                 "sim_default_bandit_4",
  414.                 "sim_default_killer_0",
  415.                 "sim_default_killer_1",
  416.                 "sim_default_killer_2",
  417.                 "sim_default_killer_3",
  418.                 "sim_default_killer_4",
  419.                 "sim_default_duty_0",
  420.                 "sim_default_duty_1",
  421.                 "sim_default_duty_2",
  422.                 "sim_default_duty_3",
  423.                 "sim_default_duty_4",
  424.                 "sim_default_freedom_0",
  425.                 "sim_default_freedom_1",
  426.                 "sim_default_freedom_2",
  427.                 "sim_default_freedom_3",
  428.                 "sim_default_freedom_4",
  429.                 "sim_default_army_0",
  430.                 "sim_default_army_1",
  431.                 "sim_default_army_2",
  432.                 "sim_default_army_3",
  433.                 "sim_default_army_4",
  434.                 "sim_default_monolith_0",
  435.                 "sim_default_monolith_1",
  436.                 "sim_default_monolith_2",
  437.                 "sim_default_monolith_3",
  438.                 "sim_default_monolith_4",
  439.                 "sim_monolith_sniper",
  440.                 "sim_monolith_specnaz_rg6",
  441.                 "sim_default_zombied_0",
  442.                 "sim_default_zombied_1",
  443.                 "sim_default_zombied_2",
  444.                 "sim_default_zombied_3",
  445.                 "sim_default_zombied_4",
  446.                 "sim_default_csky_0",
  447.                 "sim_default_csky_1",
  448.                 "sim_default_csky_2",
  449.                 "sim_default_csky_3",
  450.                 "sim_default_csky_4",
  451.                 "sim_default_ecolog_0",
  452.                 "sim_default_ecolog_1",
  453.                 "sim_default_ecolog_2",
  454.                 "sim_default_ecolog_3",
  455.                 "sim_default_ecolog_4",
  456.                 "sim_default_military_0",
  457.                 "sim_default_military_1",
  458.                 "sim_default_military_2",
  459.                 "sim_default_military_3",
  460.                 "sim_default_military_4"
  461.                 }
  462.     elseif (name == "NPC (Mutant)") then
  463.         return {
  464.                 "cat_weak",
  465.                 "cat_normal",
  466.                 "cat_strong",
  467.                 "dog_weak",
  468.                 "dog_normal",
  469.                 "dog_strong",
  470.                 "rat_weak",
  471.                 "rat_normal",
  472.                 "rat_strong",
  473.                 "chimera_weak",
  474.                 "chimera_normal",
  475.                 "chimera_strong",
  476.                 "m_controller_normal",
  477.                 "m_controller_normal2",
  478.                 "bloodsucker_weak",
  479.                 "bloodsucker_normal",
  480.                 "bloodsucker_strong",
  481.                 "boar_weak",
  482.                 "boar_normal",
  483.                 "boar_strong",
  484.                 "flesh_weak",
  485.                 "flesh_normal",
  486.                 "flesh_strong",
  487.                 "fracture_weak",
  488.                 "fracture_normal",
  489.                 "fracture_strong",
  490.                 "zombie_weak",
  491.                 "zombie_normal",
  492.                 "zombie_strong",
  493.                 "gigant_weak",
  494.                 "gigant_normal",
  495.                 "gigant_strong",
  496.                 "snork_weak",
  497.                 "snork_normal",
  498.                 "snork_strong",
  499.                 "pseudodog_weak",
  500.                 "pseudodog_normal",
  501.                 "pseudodog_strong",
  502.                 "burer_weak",
  503.                 "burer_normal",
  504.                 "burer_strong",
  505.                 "tushkano_weak",
  506.                 "tushkano_normal",
  507.                 "tushkano_strong",
  508.                 "borya_normal",
  509.                 "psysucker_weak",
  510.                 "psysucker_normal",
  511.                 "psysucker_strong",
  512.                 "m_controller_psy"
  513.                 }
  514.     elseif (name == "Squads (Stalker)") then
  515.         return {
  516.                 "stalker_sim_squad_novice",
  517.                 "stalker_sim_squad_advanced",
  518.                 "stalker_sim_squad_veteran",
  519.                 "bandit_sim_squad_novice",
  520.                 "bandit_sim_squad_advanced",
  521.                 "bandit_sim_squad_veteran",
  522.                 "duty_sim_squad_novice",
  523.                 "duty_sim_squad_advanced",
  524.                 "duty_sim_squad_veteran",
  525.                 "freedom_sim_squad_novice",
  526.                 "freedom_sim_squad_advanced",
  527.                 "freedom_sim_squad_veteran",
  528.                 "army_sim_squad_novice",
  529.                 "army_sim_squad_advanced",
  530.                 "army_sim_squad_veteran",
  531.                 "merc_sim_squad_novice",
  532.                 "merc_sim_squad_advanced",
  533.                 "merc_sim_squad_veteran",
  534.                 "monolith_sim_squad_novice",
  535.                 "monolith_sim_squad_advanced",
  536.                 "monolith_sim_squad_veteran",
  537.                 "csky_sim_squad_novice",
  538.                 "csky_sim_squad_advanced",
  539.                 "csky_sim_squad_veteran",
  540.                 "ecolog_sim_squad_novice",
  541.                 "ecolog_sim_squad_advanced",
  542.                 "ecolog_sim_squad_veteran",
  543.                 "zombied_sim_squad_novice",
  544.                 "zombied_sim_squad_advanced",
  545.                 "zombied_sim_squad_veteran"
  546.                 }
  547.     elseif (name == "Squads (Mutant)") then
  548.         return {
  549.                 "simulation_bloodsucker",
  550.                 "simulation_boar",
  551.                 "simulation_burer",
  552.                 "simulation_dog",
  553.                 "simulation_pseudodog",
  554.                 "simulation_flesh",
  555.                 "simulation_snork",
  556.                 "simulation_controller",
  557.                 "simulation_mix_dogs",
  558.                 "simulation_mix_boar_flesh",
  559.                 "simulation_poltergeist_tele",
  560.                 "simulation_chimera",
  561.                 "simulation_chimera_zaton",
  562.                 "simulation_chimera_pripyat",
  563.                 "simulation_chimera_jupiter",
  564.                 "simulation_psy_dog",
  565.                 "simulation_tushkano",
  566.                 "simulation_gigant",
  567.                 "simulation_cat",
  568.                 "simulation_zombie",
  569.                 "simulation_rat",
  570.                 "simulation_rats",
  571.                 "simulation_fracture",
  572.                 "simulation_psysucker",
  573.                 "simulation_controller_psy"
  574.                 }
  575.     elseif (name == "Vehicles") then
  576.         return {
  577.                 "veh_niva",
  578.                 "veh_uaz_01",
  579.                 "veh_uaz_02",
  580.                 "veh_uaz_buhanka",
  581.                 "veh_zaz",
  582.                 "veh_zaz_968",
  583.                 "veh_moskvich",
  584.                 "veh_tr13",
  585.                 "veh_zil_130",
  586.                 "veh_zil_131",
  587.                 "veh_kamaz_fura",
  588.                 "veh_kamaz",
  589.                 "veh_laz",
  590.                 "veh_kavz",
  591.                 "veh_gaz",
  592.                 "veh_btr",
  593.                 "veh_hl2baggi"
  594.         }
  595.     elseif (name == "Physic (Misc.)") then
  596.         return {
  597.                 "mine_blow",
  598.                 "jup_b209_ph_scanner",
  599.                 "jup_b207_depot_cover",
  600.                 "pri_a28_actor_hideout",
  601.                 "jup_b219_gate",
  602.                 "pri_a25_explosive_charge",
  603.                 "pri_a28_earth_helli_1",
  604.                 "pri_a28_earth_helli_2",
  605.                 "jup_b206_plant_ph",
  606.                 "shooting_target_1",
  607.                 "balon_01",
  608.                 "balon_02",
  609.                 "balon_02link",
  610.                 "balon_02a",
  611.                 "bidon",
  612.                 "bochka_close_1",
  613.                 "bochka_close_2",
  614.                 "bochka_close_3",
  615.                 "bochka_close_4",
  616.                 "gaz_balon",
  617.                 "disel_generator",
  618.                 "krisagenerator",
  619.                 "ventilator_01",
  620.                 "ventilator_02",
  621.                 "ventilator_03",
  622.                 "ventilator_04",
  623.                 "ventilator_05",
  624.                 "notebook",
  625.                 "priemnik_gorizont",
  626.                 "rupor",
  627.                 "transiver",
  628.                 "tv_1",
  629.                 "table_lamp_01",
  630.                 "komp_monitor",
  631.                 "komp_klava",
  632.                 "komp_block",
  633.                 "debris_01",
  634.                 "wood_fence_1",
  635.                 "wood_fence_2",
  636.                 "wood_fence_3",
  637.                 "wood_fence_4",
  638.                 "banka_kraski_1",
  639.                 "kanistra_01",
  640.                 "tiski",
  641.                 "kanistra_02",
  642.                 "vedro_01",
  643.                 "axe",
  644.                 "hammer",
  645.                 "hatch_01",
  646.                 "keyga",
  647.                 "lopata",
  648.                 "molot",
  649.                 "pick",
  650.                 "riffler",
  651.                 "saw",
  652.                 "box_1a",
  653.                 "box_1b",
  654.                 "box_1c",
  655.                 "box_bottle_1",
  656.                 "box_metall_01",
  657.                 "box_wood_01",
  658.                 "box_wood_02",
  659.                 "box_paper"
  660.                 }
  661.     end
  662. end
  663.  
  664. ------------------------------------------------------------
  665. -- List box
  666. ------------------------------------------------------------
  667. class "set_list_text" (CUIListBoxItem)
  668. function set_list_text:__init(height) super(height)
  669.     self.sect                   = self:GetTextItem()
  670.     self.sect:SetWndRect        (Frect():set(0,0,300,22))
  671.     self:SetTextColor           (GetARGB(255, 216, 186, 140))
  672.     self.sect:SetFont           (GetFontLetterica18Russian())
  673.     self.sect:SetWndSize        (vector2():set(400,height))
  674.     self.sect:SetEllipsis       (true)
  675. end
  676.  
  677. ------------------------------------------------------------
  678. -- MAIN DEBUG UI
  679. ------------------------------------------------------------
  680. class "debug_ui" (CUIScriptWnd)
  681. function debug_ui:__init(owner,binds) super()
  682.     self.owner = owner
  683.     self.binds = binds
  684.     self.txt_console = {}
  685.     self.tab_list = {}
  686.     self.console_size = 27
  687.     self:InitControls()
  688.     self:InitCallBacks()
  689.     self.tab:SetActiveTab("spawner")
  690.     self:SendOutput("Alundaio's xrs_debug_tools version 2.5      [Type help for a list of commands]")
  691.     self.console_relay = false
  692. end
  693.  
  694. function debug_ui:__finalize()
  695.  
  696. end
  697.  
  698. function debug_ui:Reinit(level_present)
  699.     self.level_present = level_present
  700.     if not (level_present) then
  701.         self.tab:SetActiveTab("editor")
  702.     else
  703.         self.tab:SetActiveTab("spawner")
  704.     end
  705.    
  706.     self:OnTabChange()
  707. end
  708.  
  709. function debug_ui:CreateTab(uID)
  710.     self.tab_list[uID] = true
  711.     self["dlg_"..uID] = this["debug_ui_"..uID](self,binds)
  712.     self["dlg_"..uID]:InitControls(0,0, self.xml, self)
  713.     self["dlg_"..uID]:Show(false)
  714.     self.dialog:AttachChild(self["dlg_"..uID])
  715.     self.xml:InitWindow("tab_size", 0, self["dlg_"..uID])
  716. end
  717.  
  718. function debug_ui:InitControls()
  719.     self:SetWndRect             (Frect():set(0,0,1024,768))
  720.     self:Enable                 (true)
  721.  
  722.     local xml                   = CScriptXmlInit()
  723.     self.xml = xml
  724.     xml:ParseFile               ("ui_debug_main.xml")
  725.  
  726.     xml:InitStatic              ("background", self)
  727.     self.dialog                 = xml:InitStatic("main_dialog:dialog", self)
  728.  
  729.     -- Menu Quit
  730.     local btn = xml:Init3tButton("main_dialog:btn_quit", self.dialog)
  731.     self:Register(btn,"btn_quit")
  732.  
  733.     -- Teleport Button
  734.     btn = xml:Init3tButton("main_dialog:btn_tp", self.dialog)
  735.     self:Register(btn,"btn_tp")
  736.  
  737.     -- Console
  738.     self.console = xml:InitStatic("console",self)
  739.     self.console_input = xml:InitEditBox("console:input",self)
  740.     self:Register(self.console_input,"console_input")
  741.    
  742.     --self.scroll_v = xml:InitScrollView("console:scroll_v", self.dialog)
  743.     --self.scroll_v:AddWindow(self.console, true)
  744.    
  745.     local offset = vector2()
  746.     offset.x = 10
  747.     offset.y = 10
  748.  
  749.     for i=1,self.console_size do
  750.         self.txt_console[i] = xml:InitTextWnd("console:ln",self.console)
  751.         self.txt_console[i]:SetWndPos(offset)
  752.         offset.y = offset.y + 15
  753.  
  754.         self.txt_console[i]:SetTextColor( GetARGB(255,240, 240, 240))
  755.     end
  756.     self.txt_console[1]:SetTextColor( GetARGB(255,255, 255, 255))
  757.  
  758.     -- Info
  759.     self.form = xml:InitStatic("main_dialog:form",self.dialog)
  760.  
  761.     xml:InitStatic("main_dialog:cap_focus_id", self.dialog)
  762.     self.txt_focus = xml:InitTextWnd("main_dialog:form:txt_focus", self.form)
  763.  
  764.     xml:InitStatic("main_dialog:cap_near_id", self.dialog)
  765.     self.txt_near = xml:InitTextWnd("main_dialog:form:txt_near", self.form)
  766.  
  767.     -- Tabs
  768.     --self:CreateTab("spawner")
  769.     --self:CreateTab("editor")
  770.     --self:CreateTab("object")
  771.     --self:CreateTab("advanced")
  772.  
  773.     -- Dialog Tab
  774.     self.tab = xml:InitTab("main_dialog:tab", self.dialog)
  775.     self:Register(self.tab, "tab")
  776. end
  777.  
  778. function debug_ui:SetCurrentValues()
  779.  
  780. end
  781.  
  782. function debug_ui:ShowConsole()
  783.     if not (self.console:IsShown()) then
  784.         self.console:Show(true)
  785.         self.console_input:Show(true)
  786.     end
  787. end
  788.  
  789. function debug_ui:HideConsole()
  790.     if (self.console:IsShown()) then
  791.         self.console:Show(false)
  792.         self.console_input:Show(false)
  793.     end
  794. end
  795.  
  796. function debug_ui:Update()
  797.     CUIScriptWnd.Update(self)
  798. end
  799.  
  800. function debug_ui:InitCallBacks()
  801.     self:AddCallback("tab", ui_events.TAB_CHANGED, self.OnTabChange, self)
  802.     self:AddCallback("btn_quit", ui_events.BUTTON_CLICKED, self.OnQuit, self)
  803.     self:AddCallback("btn_tp", ui_events.BUTTON_CLICKED, self.OnBtnTeleport, self)
  804.     self:AddCallback("btn_spawn", ui_events.BUTTON_CLICKED, self.OnBtnSpawn, self)
  805.     self:AddCallback("btn_spawn_squad", ui_events.BUTTON_CLICKED, self.OnBtnSpawnSquad, self)
  806.     self:AddCallback("btn_focus", ui_events.BUTTON_CLICKED, self.OnBtnFocus, self)
  807.     self:AddCallback("btn_execute_string", ui_events.BUTTON_CLICKED, self.OnBtnExecuteString, self)
  808.     --self:AddCallback("btn_switch_distance", ui_events.BUTTON_CLICKED, self.OnBtnSwitchDistance, self)
  809.     self:AddCallback("btn_find", ui_events.BUTTON_CLICKED, self.OnBtnFindNearest, self)
  810.     self:AddCallback("btn_set", ui_events.BUTTON_CLICKED, self.OnBtnSetLogic, self)
  811.     self:AddCallback("btn_revert", ui_events.BUTTON_CLICKED, self.OnBtnRevertLogic, self)
  812.     self:AddCallback("btn_reload", ui_events.BUTTON_CLICKED, self.OnBtnReloadIni, self)
  813.     self:AddCallback("console_input", ui_events.EDIT_TEXT_COMMIT, self.OnConsoleInput, self)
  814.  
  815.     --- Spawner Tab
  816.     self:AddCallback("list_sections", ui_events.LIST_ITEM_SELECT,        self.OnSelectSectionList,      self)
  817.     self:AddCallback("list_window",   ui_events.WINDOW_LBUTTON_DB_CLICK, self.OnButton_create_clicked,  self)
  818.     --self:AddCallback("btn_create",      ui_events.BUTTON_CLICKED,          self.OnButton_create_clicked,  self)
  819.    
  820.     -- Icon Editor
  821.     self:AddCallback("editor_list_sections", ui_events.LIST_ITEM_SELECT,         self.OnSelectEditorSectionList,    self)
  822.     self:AddCallback("editor_list_window",    ui_events.WINDOW_LBUTTON_DB_CLICK, self.OnEditorTriggerSectionSelection,  self)
  823.    
  824.     self:AddCallback("fld_icon_x",    ui_events.EDIT_TEXT_COMMIT, self.OnEditIconX, self)
  825.     self:AddCallback("fld_icon_y",    ui_events.EDIT_TEXT_COMMIT, self.OnEditIconY, self)
  826.     self:AddCallback("fld_icon_width",    ui_events.EDIT_TEXT_COMMIT, self.OnEditIconW, self)
  827.     self:AddCallback("fld_icon_height",   ui_events.EDIT_TEXT_COMMIT, self.OnEditIconH, self)
  828.     self:AddCallback("fld_addon_offset_x",    ui_events.EDIT_TEXT_COMMIT, self.OnEditIconOffX,  self)
  829.     self:AddCallback("fld_addon_offset_y",    ui_events.EDIT_TEXT_COMMIT, self.OnEditIconOffY,  self)  
  830.    
  831.     self:AddCallback("editor_list_addon", ui_events.LIST_ITEM_SELECT,   self.OnEditorTriggerAddonSectionSelection,  self)
  832.     self:AddCallback("btn_editor_save", ui_events.BUTTON_CLICKED, self.OnEditorSave, self)
  833.     --
  834.    
  835.     -- level jump tab
  836.     self:AddCallback("list_levels_window",    ui_events.WINDOW_LBUTTON_DB_CLICK, self.JumpLevel,    self)
  837. end
  838.  
  839. function debug_ui:OnConsoleInput()
  840.     local txt = self.console_input:GetText()
  841.     if (txt == "") then
  842.         return
  843.     end
  844.  
  845.     local wrd = ""
  846.     local _strt, _end = string.find(txt,".%S+")
  847.     if (_strt and _end) then
  848.         wrd = string.sub(txt,_strt, _end)
  849.         wrd = string.lower(wrd)
  850.     else
  851.         return "For usage type echo help"
  852.     end
  853.  
  854.     if not (debug_cmd_list.command_exists(wrd)) then
  855.         self:SendOutput("Command %s cannot be found. Type help for a list of commands.",wrd)
  856.         return
  857.     end
  858.  
  859.     -- Grab rest of str
  860.     local args = string.sub(txt,string.len(wrd)+1)
  861.  
  862.     -- Trim
  863.     args = string.gsub(args, "^%s*(.-)%s*$", "%1")
  864.  
  865.     -- Perform execute string on $vars
  866.     local p ={}
  867.     local var_list = debug_cmd_list.get_var_list()
  868.     for s in string.gmatch(args,"$(.-)%$") do
  869.         s = string.gsub(s, "^%s*(.-)%s*$", "%1")
  870.         if (s and s ~= "" and var_list[s]) then
  871.             table.insert(p,s)
  872.         else
  873.             local ls,err = loadstring("return function() local val = " .. s .."; return val; end")
  874.             local func = ls and ls() or err
  875.             local val = func and type(func) == "function" and func()
  876.             table.insert(p,val)
  877.         end
  878.     end
  879.  
  880.     -- replace all %s with returned vals
  881.     local i = 0
  882.     local function sr(a)
  883.         i = i + 1
  884.  
  885.         if ( type(p[i] ~= "userdata") )then
  886.             if ( var_list[p[i]] and type(var_list[p[i]] ~= "userdata") ) then
  887.                 return tostring(var_list[p[i]])
  888.             end
  889.             return tostring(p[i])
  890.         end
  891.         return ""
  892.     end
  893.     local output = string.gsub(args,"%%s",sr)
  894.  
  895.     -- Remove all $exe_strs
  896.     output = string.gsub(output,"$(.-)%$","")
  897.  
  898.     -- Send Output
  899.     self:SendOutput(debug_cmd_list.command_give(wrd,output,self,p))
  900. end
  901.  
  902. function debug_ui:OnBtnTeleport()
  903.     local pos = xrs_debug_tools.LastCameraPos
  904.     if (pos) then
  905.         local car = db.actor:get_attached_vehicle()
  906.         if (car) then
  907.             db.actor:detach_vehicle()
  908.         end
  909.         db.actor:set_actor_position(pos)
  910.        
  911.         self:OnQuit()
  912.     end
  913. end
  914.  
  915. function debug_ui:OnBtnSpawn()
  916.     local txt = self.fld_spawn:GetText()
  917.     if (txt ~= "") then
  918.         self:spawn_section(txt)
  919.     end
  920. end
  921.  
  922. function debug_ui:OnBtnSpawnSquad()
  923.     local sec = self.fld_spawn_squad:GetText()
  924.     local smrt = self.fld_spawn_smart:GetText()
  925.     if (sec ~= "" and smrt ~= "") then
  926.         self:spawn_squad(sec,smrt)
  927.     end
  928. end
  929.  
  930. function debug_ui:SendOutput(txt,...)
  931.     if not (txt) or (txt == "") then
  932.         return
  933.     end
  934.  
  935.     local i = 0
  936.     local out = txt
  937.     local p = {...}
  938.     if (#p > 0) then
  939.         local function sr(a)
  940.             i = i + 1
  941.             return tostring(p[i])
  942.         end
  943.         out = string.gsub(txt,"%%s",sr)
  944.     end
  945.  
  946.     for n=1,#self.txt_console-1,1 do
  947.         local s = self.txt_console[n+1]:GetText()
  948.         self.txt_console[n]:SetText(s)
  949.     end
  950.     self.txt_console[#self.txt_console]:SetText(out)
  951.  
  952.     if (self.console_relay) then
  953.         printf("Debug Console: %s",out)
  954.     end
  955. end
  956.  
  957. function debug_ui:SendOutputList(list,start,finish)
  958.     if not (list and not empty(list)) then
  959.         return
  960.     end
  961.  
  962.     local count = 1
  963.     local n = 1
  964.     local size = #self.txt_console
  965.     for k,v in pairs(list) do
  966.         if (start and count >= start) then
  967.             if (n < (finish or size)) then
  968.                 self:SendOutput(tostring(v))
  969.                 n = n + 1
  970.             else
  971.                 self:SendOutput(tostring(v))
  972.                 return
  973.             end
  974.         else
  975.             count = count + 1
  976.         end
  977.     end
  978.     for i=n,finish do
  979.         self:SendOutput(" ")
  980.     end
  981. end
  982.  
  983. function debug_ui:OnBtnFocus()
  984.     local txt = self.fld_focus:GetText()
  985.     if (txt ~= "") then
  986.         xrs_debug_tools.set_debug_npc(tonumber(txt))
  987.         self.txt_focus:SetText(txt)
  988.     else
  989.         xrs_debug_tools.set_debug_npc()
  990.         self.txt_focus:SetText("")
  991.     end
  992. end
  993.  
  994. function debug_ui:OnBtnExecuteString()
  995.     local txt = self.fld_execute_string:GetText()
  996.     if (txt ~= "") then
  997.         assert(loadstring(txt))()
  998.     end
  999. end
  1000.  
  1001. function debug_ui:OnBtnSwitchDistance()
  1002.     local txt = self.fld_switch_distance:GetText()
  1003.     if (txt ~= "") then
  1004.         local a = alife()
  1005.         local old = a:switch_distance()
  1006.         local amt = tonumber(txt)
  1007.         --alun_utils.debug_write("%s %s ",old,amt)
  1008.         a:switch_distance(amt)
  1009.         self:SendOutput("Switch Distance changed from %s to %s.",old,amt)
  1010.     end
  1011. end
  1012.  
  1013. function debug_ui:OnBtnFindNearest()
  1014.     local txt = self.fld_find:GetText()
  1015.     self:FindNearest(txt)
  1016. end
  1017.  
  1018. function debug_ui:OnBtnSetLogic()
  1019.     local section = self.fld_section:GetText()
  1020.     if (section == "") then
  1021.         return
  1022.     end
  1023.     local id = self.fld_id:GetText()
  1024.     id = id and tonumber(id)
  1025.     local scheme = utils.get_scheme_by_section(section)
  1026.     local logic = self.fld_logic:GetText()
  1027.     local ini_filename = self.fld_filename:GetText()
  1028.  
  1029.     if (id and scheme and section and ini_filename) then
  1030.         local obj = db.storage[id] and db.storage[id].object or level.object_by_id(id)
  1031.         if (obj) then
  1032.             axr_logic.set_new_scheme_and_logic(obj,scheme,section,logic,nil,ini_filename)
  1033.             self:SendOutput("New scheme and logic set for %s.",obj:name())
  1034.         end
  1035.     end
  1036. end
  1037.  
  1038. function debug_ui:OnBtnRevertLogic()
  1039.     local id = self.fld_id:GetText()
  1040.     id = id and tonumber(id)
  1041.     if (id) then
  1042.         local obj = db.storage[id] and db.storage[id].object or level.object_by_id(id)
  1043.         if (obj) then
  1044.             axr_logic.restore_scheme_and_logic(obj)
  1045.             self:SendOutput("Reverted scheme and logic for %s.",obj:name())
  1046.         end
  1047.     end
  1048. end
  1049.  
  1050. function debug_ui:OnBtnReloadIni()
  1051.     local txt = self.fld_reload:GetText()
  1052.     if (txt and txt ~= "") then
  1053.         local st = db.storage[tonumber(txt)]
  1054.         if (st) then
  1055.             st.ini = nil
  1056.             st.ini = xr_logic.get_customdata_or_ini_file(st.object, st.ini_filename)
  1057.             xr_logic.switch_to_section(st.object,nil,nil)
  1058.             self:SendOutput("INI reload performed on %s.",obj:name())
  1059.         end
  1060.     end
  1061. end
  1062.  
  1063. function debug_ui:OnQuit()
  1064.     self:HideDialog()
  1065.     if (self.level_present) then
  1066.         local console = get_console()
  1067.         console:execute("main_menu off")
  1068.     else
  1069.         self.owner:ShowDialog()
  1070.         self.owner:Show(true)
  1071.     end
  1072. end
  1073.  
  1074. function debug_ui:OnTabChange()
  1075.     for k,v in pairs(self.tab_list) do
  1076.         self["dlg_"..k]:Show(false)
  1077.     end
  1078.    
  1079.     local ids = self.tab:GetActiveId()
  1080.    
  1081.     if (ids == "editor" or not self.level_present) then
  1082.         if not (self.dlg_editor) then
  1083.             self:CreateTab("editor")
  1084.         end
  1085.        
  1086.         self.dlg_editor:Show(true)
  1087.        
  1088.         if (self.ui_icon_equipment) then
  1089.             self:HideConsole()
  1090.             self.ui_icon_equipment:Show(true)
  1091.             self.ui_icon_equipment_back:Show(true)
  1092.             self.icon_square:Show(true)
  1093.         end
  1094.         return
  1095.     else
  1096.         if not (self.level_present) then
  1097.             return
  1098.         end
  1099.        
  1100.         if (self.ui_icon_equipment) then
  1101.             self.ui_icon_equipment:Show(false)
  1102.             self.icon_square:Show(false)
  1103.             self.ui_icon_equipment_back:Show(false)
  1104.             self:ShowConsole()
  1105.         end
  1106.     end
  1107.    
  1108.     if not (self["dlg_"..ids]) then
  1109.         self:CreateTab(ids)
  1110.     end
  1111.    
  1112.     self["dlg_"..ids]:Show(true)
  1113. end
  1114.  
  1115. function debug_ui:OnKeyboard(dik, keyboard_action)
  1116.     CUIScriptWnd.OnKeyboard(self,dik,keyboard_action)
  1117.     if keyboard_action == ui_events.WINDOW_KEY_RELEASED then
  1118.         local keybinds = self.binds or {}
  1119.         if dik == DIK_keys.DIK_ESCAPE then
  1120.             self:OnQuit()
  1121.         elseif (keybinds["keybind_teleport_to_cam"] and dik == DIK_keys["DIK_"..keybinds["keybind_teleport_to_cam"]]) then
  1122.             self:OnBtnTeleport()
  1123.         elseif (keybinds["debug_ui_nearest_stalker"] and dik == DIK_keys["DIK_"..keybinds["debug_ui_nearest_stalker"]]) then
  1124.             self:FindNearest("clsid.script_stalker")
  1125.         elseif (keybinds["debug_ui_spawn_position"] and dik == DIK_keys["DIK_"..keybinds["debug_ui_spawn_position"]]) then
  1126.             self.spawn_pos = db.actor:position()
  1127.             self.spawn_lvid = db.actor:level_vertex_id()
  1128.             self.spawn_gvid = db.actor:game_vertex_id()
  1129.             self:SendOutput("Set current spawning position to actor location. [To set to default type spawn reset]")
  1130.         end
  1131.     end
  1132.     return true
  1133. end
  1134.  
  1135. function debug_ui:spawn_section(text)
  1136.     if not system_ini():section_exist(text) then
  1137.         return false
  1138.     end
  1139.  
  1140.     local pos, lvid, gvid
  1141.     if (self.spawn_pos) then
  1142.         pos = self.spawn_pos
  1143.         lvid = self.spawn_lvid
  1144.         gvid = self.spawn_gvid
  1145.     else
  1146.         pos = db.actor:position()
  1147.         lvid = db.actor:level_vertex_id()
  1148.         gvid = db.actor:game_vertex_id()
  1149.     end
  1150.  
  1151.     local obj = alife():create(text,pos,lvid,gvid)
  1152.     --printf("Spawned Object %s as ID: %s",obj:name(),obj.id)
  1153.     self:SendOutput("Object %s created as ID %s.",obj:name(),obj.id)
  1154.     return true
  1155. end
  1156.  
  1157. function debug_ui:spawn_squad(section,smart)
  1158.     if not system_ini():section_exist(section) then
  1159.         self:SendOutput("UISpawner: Section %s does not exist in system INI.",section)
  1160.         return false
  1161.     end
  1162.  
  1163.     if not (smart) then
  1164.         self:SendOutput("UISpawner: Smart by name %s does not exist.",smart)
  1165.         return false
  1166.     end
  1167.     local sim = SIMBOARD
  1168.     if not (sim.smarts_by_names[smart]) then
  1169.         self:SendOutput("UISpawner: Smart by name %s does not exist.",smart)
  1170.         return false
  1171.     end
  1172.     local squad = alun_utils.create_squad(section,smart)
  1173.     self:SendOutput("UISpawner: Squad %s created as ID %s at %s.",squad:name(),squad.id,smart)
  1174.     return true
  1175. end
  1176.  
  1177. function debug_ui:FindNearest(txt)
  1178.     if (txt and txt ~= "") then
  1179.         local near,dist
  1180.         if (string.find(txt,"clsid")) then
  1181.             local cls = string.sub(txt,7)
  1182.             if (clsid[cls]) then
  1183.                 near,dist = alun_utils.nearest_object(clsid[cls],true)
  1184.             end
  1185.         else
  1186.             near,dist = alun_utils.nearest_object(txt,true)
  1187.         end
  1188.  
  1189.  
  1190.         if (near) then
  1191.             local id = near.id
  1192.             local st = near:clsid() == clsid.script_stalker and db.storage[id]
  1193.             if (st) then
  1194.                 local scheme = st.active_scheme
  1195.                 local section = st.active_section
  1196.                 local logic = st.section_logic
  1197.                 local ini_filename = st.ini_filename
  1198.  
  1199.                 if not (self.dlg_object) then
  1200.                     self:CreateTab("object")
  1201.                 end
  1202.                
  1203.                 if (self.fld_id) then
  1204.                     self.fld_id:SetText(id or "")
  1205.                     self.fld_section:SetText(section or "")
  1206.                     self.fld_logic:SetText(logic or "")
  1207.                     self.fld_filename:SetText(ini_filename or "")
  1208.                     if (self.fld_focus) then
  1209.                         self.fld_focus:SetText(id or "")
  1210.                     end
  1211.                     if (self.fld_reload) then
  1212.                         self.fld_reload:SetText(id or "")
  1213.                     end
  1214.                 end
  1215.                 self.txt_near:SetText(id)
  1216.             end
  1217.             self:SendOutput("%s with ID %s found with distance %s",near:name(),id,dist)
  1218.         else
  1219.             --printf("Could not find object matching name")
  1220.             self.txt_near:SetText("Not Found")
  1221.             self:SendOutput("Object with name not found.")
  1222.         end
  1223.     end
  1224. end
  1225.  
  1226. function debug_ui:FillList(name)
  1227.     if not (name) then
  1228.         self:SendOutput("UISpawner: No spawn table could be created for %s",name)
  1229.         return
  1230.     end
  1231.  
  1232.     self.spawn_list:Clear()
  1233.  
  1234.     local spawntbl = get_spawn_table(name)
  1235.  
  1236.     if not (spawntbl) then
  1237.         self:SendOutput("UISpawner: No spawn table could be created for %s",name)
  1238.         return
  1239.     end
  1240.  
  1241.    
  1242.     local is_squad = string.find(name,"Squad")
  1243.     local cant_spawn_actor = string.find(name,"NPC") or string.find(name,"Physic")
  1244.     local is_veh = string.find(name,"Vehicles")
  1245.     local is_anom = string.find(name,"Anomaly")
  1246.     local is_phantom = string.find(name,"Phantom")
  1247.     if (is_squad) then
  1248.     --  self.smarts_list:Show(true)
  1249.     else
  1250.     --  self.smarts_list:Show(false)
  1251.     end
  1252.    
  1253.     local ini = system_ini()
  1254.  
  1255.     table.sort(spawntbl)
  1256.     for i = 1, #spawntbl do
  1257.         if (ini:section_exist(spawntbl[i])) then
  1258.             local _itm = set_list_text(22)
  1259.             --local name = game.translate_string(system_ini():r_string(sections[i], "inv_name"))
  1260.  
  1261.             --_itm.name:SetText(name)
  1262.             _itm.sect:SetText(spawntbl[i])
  1263.  
  1264.             if (is_squad) then
  1265.                 _itm.no_id = true
  1266.                 _itm.squad = true
  1267.             elseif (cant_spawn_actor) then
  1268.                 _itm.no_id = true
  1269.             elseif (is_veh) then
  1270.                 _itm.no_id = true
  1271.                 _itm.spawn_at_look = true
  1272.             elseif (is_anom) then
  1273.                 _itm.no_id = true
  1274.                 _itm.spawn_at_look = true
  1275.                 _itm.is_anom = true
  1276.             elseif (is_phantom) then
  1277.                 _itm.no_id = true
  1278.                 _itm.spawn_at_look = true
  1279.                 _itm.use_level_spawn = true
  1280.             end
  1281.  
  1282.             self.spawn_list:AddExistingItem(_itm)
  1283.         end
  1284.     end
  1285. end
  1286.  
  1287. function debug_ui:FillEditorList(name)
  1288.     self.editor_icon:SetTextureRect(Frect():set(0,0,0,0))
  1289.    
  1290.     if not (name) then
  1291.         self:SendOutput("UIEditor: No spawn table could be created for %s",name)
  1292.         return
  1293.     end
  1294.  
  1295.     self.editor_spawn_list:Clear()
  1296.  
  1297.     local spawntbl = get_spawn_table(name)
  1298.  
  1299.     if not (spawntbl) then
  1300.         self:SendOutput("UIEditor: No spawn table could be created for %s",name)
  1301.         return
  1302.     end
  1303.  
  1304.     local ini = system_ini()
  1305.  
  1306.     table.sort(spawntbl)
  1307.     for i = 1, #spawntbl do
  1308.         if (ini:section_exist(spawntbl[i])) then
  1309.             local _itm = set_list_text(22)
  1310.             _itm.sect:SetText(spawntbl[i])
  1311.             self.editor_spawn_list:AddExistingItem(_itm)
  1312.         end
  1313.     end
  1314. end
  1315.  
  1316. function debug_ui:FillLevelList()
  1317.     local levels = alun_utils.collect_section(game_ini(),"level_maps_single")
  1318.     for i,level in pairs(levels) do
  1319.         local _itm = set_list_text(22)
  1320.         _itm.sect:SetText(game.translate_string(level))
  1321.         _itm.name = level
  1322.         self.levels_list:AddExistingItem(_itm)
  1323.     end
  1324. end
  1325.  
  1326. function debug_ui:JumpLevel()
  1327.     local item
  1328.     item = self.levels_list:GetSelectedItem()
  1329.     if not(item) then
  1330.         self:SendOutput("UIAdvanced: No level was selected in the list.")
  1331.         return
  1332.     end
  1333.    
  1334.     self:OnQuit()
  1335.    
  1336.     _G.JumpToLevel(item.name)
  1337. end
  1338.  
  1339. function debug_ui:OnSelectSectionList()
  1340.     self:FillList(self.sections_list:GetText())
  1341. end
  1342.  
  1343. function debug_ui:OnSelectEditorSectionList()
  1344.     self:FillEditorList(self.editor_sections_list:GetText())
  1345. end
  1346.  
  1347. function debug_ui:OnButton_create_clicked()
  1348.     if self.spawn_list:GetSize() == 0 then
  1349.         self:SendOutput("UISpawner: List is empty.")
  1350.         return
  1351.     end
  1352.  
  1353.     local item
  1354.     item = self.spawn_list:GetSelectedItem()
  1355.     if not(item) then
  1356.         self:SendOutput("UISpawner: No item section was selected in the list.")
  1357.         return
  1358.     end
  1359.  
  1360.     local section = item.sect:GetText()
  1361.  
  1362.     if (item.squad) then
  1363.         local smart = self.smarts_list:GetText()
  1364.         self:spawn_squad(section,smart)
  1365.         return
  1366.     end
  1367.  
  1368.     local pos, lvid, gvid
  1369.    
  1370.     if (item.spawn_at_look) then
  1371.         gvid = db.actor:game_vertex_id()
  1372.         local r = level.get_target_dist and level.get_target_dist() or 3
  1373.         pos = vector():set(db.actor:position())
  1374.         pos:add(device().cam_dir:mul(r))
  1375.         pos = vector():set(pos.x,db.actor:position().y,pos.z)
  1376.         lvid = level.vertex_id(pos)
  1377.     elseif (self.spawn_pos) then
  1378.         pos = self.spawn_pos
  1379.         lvid = self.spawn_lvid
  1380.         gvid = self.spawn_gvid
  1381.     else
  1382.         pos = db.actor:position()
  1383.         lvid = db.actor:level_vertex_id()
  1384.         gvid = db.actor:game_vertex_id()
  1385.     end
  1386.    
  1387.     if (item.use_level_spawn) then
  1388.         if (level.spawn_item) then
  1389.             level.spawn_item(section,pos,lvid,65535,false)
  1390.             self:SendOutput("UISpawner: Spawned")
  1391.         end
  1392.         return
  1393.     end
  1394.  
  1395.     local id = not item.no_id and self.check_to_actor:GetCheck() and 0
  1396.     local se_obj
  1397.     if (id) then
  1398.         se_obj = alife():create(section, vector(), 0, 0, id)
  1399.     else
  1400.         se_obj = alife():create(section, pos, lvid, gvid)
  1401.     end
  1402.  
  1403.     if not (se_obj) then
  1404.         self:SendOutput("UISpawner: Failure to create item with alife create method %s",section)
  1405.         return
  1406.     end
  1407.    
  1408.     if (item.is_anom) then
  1409.         local data = stpk_utils.get_anom_zone_data(se_obj)
  1410.         if (data) then
  1411.             data.object_flags = 31
  1412.             --data.artefact_spawn_count = 1
  1413.             data.restrictor_type = 0
  1414.             data.shapes = {}
  1415.             data.shapes[1] = {}
  1416.             data.shapes[1].shtype = 0
  1417.             data.shapes[1].offset = vector():set(0,0,0)
  1418.             data.shapes[1].radius = 5
  1419.             stpk_utils.set_anom_zone_data(data,se_obj)
  1420.         end
  1421.     end
  1422.  
  1423.     self:SendOutput("UISpawner: Spawned %s on %s as id %s",se_obj:name(),id == 0 and "Actor" or "level",se_obj.id)
  1424. end
  1425.  
  1426. function debug_ui:OnEditorTriggerAddonSectionSelection()
  1427.     local item
  1428.     item = self.editor_spawn_list:GetSelectedItem()
  1429.     if not(item) then
  1430.         self:SendOutput("UIEditor: No item section was selected in the list.")
  1431.         return
  1432.     end
  1433.  
  1434.     local section = item.sect:GetText()
  1435.     local ini = system_ini()
  1436.     if  not (ini:section_exist(section)) then
  1437.         self:SendOutput(strformat("UIEditor: Section %s does not exist",section))
  1438.         return
  1439.     end
  1440.    
  1441.     local addon_sec = self.addon_list:GetText()
  1442.     if not (addon_sec and addon_sec ~= "" and addon_sec ~= "Select Attachment" and ini:section_exist(addon_sec)) then
  1443.         self.editor_icon_addon:SetTextureRect(Frect():set(0,0,0,0))
  1444.         self.fld_addon_offset_x:SetText("")
  1445.         self.fld_addon_offset_y:SetText("")
  1446.         return
  1447.     end
  1448.    
  1449.     local scope_sec = section
  1450.     local ind = self.addon_list:CurrentID()
  1451.     if (self._addons[ind] == "scope" and self._scopes[ind]) then
  1452.         local s = alun_utils.read_from_ini(ini,self._scopes[ind],self._addons[ind].."_name","string")
  1453.         addon_sec = s or addon_sec
  1454.         scope_sec = self._scopes[ind] or section
  1455.     end
  1456.    
  1457.     local scale = 0.75
  1458.    
  1459.     local addon_inv_grid_width = alun_utils.read_from_ini(ini,addon_sec,"inv_grid_width","float",0)
  1460.     local addon_inv_grid_height = alun_utils.read_from_ini(ini,addon_sec,"inv_grid_height","float",0)
  1461.     local addon_inv_grid_x = alun_utils.read_from_ini(ini,addon_sec,"inv_grid_x","float",0)
  1462.     local addon_inv_grid_y = alun_utils.read_from_ini(ini,addon_sec,"inv_grid_y","float",0)
  1463.  
  1464.     local addon_x1 = addon_inv_grid_x*50
  1465.     local addon_y1 = addon_inv_grid_y*50
  1466.  
  1467.     local addon_w = addon_inv_grid_width*50
  1468.     local addon_h = addon_inv_grid_height*50
  1469.  
  1470.     local addon_x2 = addon_x1 + addon_w
  1471.     local addon_y2 = addon_y1 + addon_h
  1472.    
  1473.     local offset_x = alun_utils.read_from_ini(ini,scope_sec,self._addons[ind].."_x","float",0)
  1474.     local offset_y = alun_utils.read_from_ini(ini,scope_sec,self._addons[ind].."_y","float",0)
  1475.    
  1476.     self.editor_icon_addon:InitTexture("ui\\ui_icon_equipment")
  1477.     self.editor_icon_addon:SetTextureRect(Frect():set(addon_x1,addon_y1,addon_x2,addon_y2))
  1478.     self.editor_icon_addon:SetWndSize(vector2():set(addon_w*scale,addon_h*scale))
  1479.    
  1480.     pos = self.editor_icon:GetWndPos()
  1481.     self.editor_icon_addon:SetWndPos(vector2():set(pos.x+offset_x*scale,pos.y+offset_y*scale))
  1482.    
  1483.     self.fld_addon_offset_x:SetText(tostring(offset_x))
  1484.     self.fld_addon_offset_y:SetText(tostring(offset_y))
  1485. end
  1486.  
  1487.  
  1488. function debug_ui:OnEditorTriggerSectionSelection()
  1489.  
  1490.     self.editor_icon:SetTextureRect(Frect():set(0,0,0,0))
  1491.     self.editor_icon_addon:SetTextureRect(Frect():set(0,0,0,0))
  1492.        
  1493.     if self.editor_spawn_list:GetSize() == 0 then
  1494.         self:SendOutput("UIEditor: List is empty.")
  1495.         return
  1496.     end
  1497.    
  1498.     local item
  1499.     item = self.editor_spawn_list:GetSelectedItem()
  1500.     if not(item) then
  1501.         self:SendOutput("UIEditor: No item section was selected in the list.")
  1502.         return
  1503.     end
  1504.  
  1505.     local section = item.sect:GetText()
  1506.     local ini = system_ini()
  1507.     if  not (ini:section_exist(section)) then
  1508.         self:SendOutput(strformat("UIEditor: Section %s does not exist",section))
  1509.         return
  1510.     end
  1511.    
  1512.     self._addons = {} -- temp
  1513.     self._scopes = {} -- temp
  1514.    
  1515.     self.addon_list:ClearList()
  1516.     self.addon_list:AddItem("Select Attachment",0) -- default
  1517.     self._addons[0] = "none"
  1518.    
  1519.     -----------------------
  1520.     local scale = 0.75
  1521.    
  1522.     local inv_grid_width = alun_utils.read_from_ini(ini,section,"inv_grid_width","float",0)
  1523.     local inv_grid_height = alun_utils.read_from_ini(ini,section,"inv_grid_height","float",0)
  1524.     local inv_grid_x = alun_utils.read_from_ini(ini,section,"inv_grid_x","float",0)
  1525.     local inv_grid_y = alun_utils.read_from_ini(ini,section,"inv_grid_y","float",0)
  1526.  
  1527.     self.editor_old_x = inv_grid_x
  1528.     self.editor_old_y = inv_grid_y
  1529.     self.editor_old_w = inv_grid_width
  1530.     self.editor_old_h = inv_grid_height
  1531.    
  1532.     local x1 = inv_grid_x*50
  1533.     local y1 = inv_grid_y*50
  1534.    
  1535.     local w = inv_grid_width*50
  1536.     local h = inv_grid_height*50
  1537.    
  1538.     local x2 = x1 + w
  1539.     local y2 = y1 + h
  1540.    
  1541.     self.editor_icon:InitTexture("ui\\ui_icon_equipment")
  1542.     self.editor_icon:SetTextureRect(Frect():set(x1,y1,x2,y2))
  1543.     self.editor_icon:SetWndSize(vector2():set(w*scale,h*scale))
  1544.    
  1545.     self.fld_icon_x:SetText(tostring(inv_grid_x))
  1546.     self.fld_icon_y:SetText(tostring(inv_grid_y))
  1547.    
  1548.     self.fld_icon_width:SetText(tostring(inv_grid_width))
  1549.     self.fld_icon_height:SetText(tostring(inv_grid_height))
  1550.    
  1551.     local pos = self.ui_icon_equipment:GetWndPos()
  1552.     self.icon_square:SetWndPos(vector2():set( pos.x+x1/4 , pos.y+y1/4 ))
  1553.     self.icon_square:SetWndSize(vector2():set(w/4,h/4))
  1554.    
  1555.     -- attachments
  1556.     local silencer = alun_utils.read_from_ini(ini,section,"silencer_name","string")
  1557.     local grenade_launcher = alun_utils.read_from_ini(ini,section,"grenade_launcher_name","string")
  1558.    
  1559.     local ind = 1
  1560.     if (silencer and ini:section_exist(silencer)) then
  1561.         self.addon_list:AddItem(silencer,ind)
  1562.         self._addons[ind] = "silencer"
  1563.         ind = ind + 1
  1564.     end
  1565.    
  1566.     if (grenade_launcher and ini:section_exist(grenade_launcher)) then
  1567.         self.addon_list:AddItem(grenade_launcher,ind)
  1568.         self._addons[ind] = "grenade_launcher"
  1569.         ind = ind + 1
  1570.     end
  1571.    
  1572.     local scopes = alun_utils.parse_list(ini,section,"scopes_sect")
  1573.     if (scopes and #scopes > 0) then
  1574.         for k,v in pairs(scopes) do
  1575.             self.addon_list:AddItem(v,ind)
  1576.             self._scopes[ind] = v
  1577.             self._addons[ind] = "scope"
  1578.             ind = ind + 1
  1579.         end
  1580.     end
  1581.    
  1582.     self.editor_icon_addon:SetTextureRect(Frect():set(0,0,0,0))
  1583.     self.fld_addon_offset_x:SetText("")
  1584.     self.fld_addon_offset_y:SetText("")
  1585. --[[
  1586.     local name = self.addon_list:GetText()
  1587.     if not (name and name ~= "Select Addon Type") then
  1588.         return
  1589.     end
  1590.    
  1591.     local scopes = name == "scope" and alun_utils.parse_list(ini,section,"scopes_sect")
  1592.     local scope_sec = section
  1593.     if (scopes and #scopes > 0) then
  1594.         scope_sec = scopes[1]
  1595.     end
  1596.    
  1597.     local addon_sec = alun_utils.read_from_ini(ini,scope_sec,name.."_name","string")
  1598.     if not (addon_sec and ini:section_exist(addon_sec)) then
  1599.         return
  1600.     end
  1601.    
  1602.     local addon_inv_grid_width = alun_utils.read_from_ini(ini,addon_sec,"inv_grid_width","float",0)
  1603.     local addon_inv_grid_height = alun_utils.read_from_ini(ini,addon_sec,"inv_grid_height","float",0)
  1604.     local addon_inv_grid_x = alun_utils.read_from_ini(ini,addon_sec,"inv_grid_x","float",0)
  1605.     local addon_inv_grid_y = alun_utils.read_from_ini(ini,addon_sec,"inv_grid_y","float",0)
  1606.  
  1607.     local addon_x1 = addon_inv_grid_x*50
  1608.     local addon_y1 = addon_inv_grid_y*50
  1609.  
  1610.     local addon_w = addon_inv_grid_width*50
  1611.     local addon_h = addon_inv_grid_height*50
  1612.  
  1613.     local addon_x2 = addon_x1 + addon_w
  1614.     local addon_y2 = addon_y1 + addon_h
  1615.    
  1616.     local offset_x = alun_utils.read_from_ini(ini,scope_sec,name.."_x","float",0)
  1617.     local offset_y = alun_utils.read_from_ini(ini,scope_sec,name.."_y","float",0)
  1618.    
  1619.     self.editor_old_offset_x = offset_x
  1620.     self.editor_old_offset_y = offset_y
  1621.    
  1622.     self.editor_icon_addon:InitTexture("ui\\ui_icon_equipment")
  1623.     self.editor_icon_addon:SetTextureRect(Frect():set(addon_x1,addon_y1,addon_x2,addon_y2))
  1624.     self.editor_icon_addon:SetWndSize(vector2():set(addon_w*scale,addon_h*scale))
  1625.    
  1626.     pos = self.editor_icon:GetWndPos()
  1627.     self.editor_icon_addon:SetWndPos(vector2():set(pos.x+offset_x*scale,pos.y+offset_y*scale))
  1628.    
  1629.     self.fld_addon_offset_x:SetText(tostring(offset_x))
  1630.     self.fld_addon_offset_y:SetText(tostring(offset_y))
  1631. --]]
  1632. end
  1633.  
  1634. function debug_ui:OnEditIconX()
  1635.     local v = tonumber(self.fld_icon_x:GetText())
  1636.     if (v and v ~= self.editor_old_x) then
  1637.         self.need_save_x = true
  1638.     end
  1639.    
  1640.     self:OnEditIcon()
  1641. end
  1642.  
  1643. function debug_ui:OnEditIconY()
  1644.     local v = tonumber(self.fld_icon_y:GetText())
  1645.     if (v and v ~= self.editor_old_y) then
  1646.         self.need_save_y = true
  1647.     end
  1648.    
  1649.     self:OnEditIcon()
  1650. end
  1651.  
  1652. function debug_ui:OnEditIconW()
  1653.     local v = tonumber(self.fld_icon_width:GetText())
  1654.     if (v and v ~= self.editor_old_w) then
  1655.         self.need_save_w = true
  1656.     end
  1657.    
  1658.     self:OnEditIcon()
  1659. end
  1660.  
  1661. function debug_ui:OnEditIconH()
  1662.     local v = tonumber(self.fld_icon_height:GetText())
  1663.     if (v and v ~= self.editor_old_h) then
  1664.         self.need_save_h = true
  1665.     end
  1666.    
  1667.     self:OnEditIcon()
  1668. end
  1669.  
  1670. function debug_ui:OnEditIconOffX()
  1671.     local v = tonumber(self.fld_addon_offset_x:GetText())
  1672.     if (v and v ~= self.editor_old_offset_x) then
  1673.         self.need_save_offset_x = true
  1674.     end
  1675.     self:OnEditIcon()
  1676. end
  1677.  
  1678. function debug_ui:OnEditIconOffY()
  1679.     local v = tonumber(self.fld_addon_offset_y:GetText())
  1680.     if (v and v ~= self.editor_old_offset_y) then
  1681.         self.need_save_offset_y = true
  1682.     end
  1683.     self:OnEditIcon()
  1684. end
  1685.  
  1686. function debug_ui:OnEditIcon()
  1687.  
  1688.     local x1 = tonumber(self.fld_icon_x:GetText())
  1689.     local y1 = x1 and tonumber(self.fld_icon_y:GetText())
  1690.    
  1691.     local w = y1 and tonumber(self.fld_icon_width:GetText())
  1692.     local h = w and tonumber(self.fld_icon_height:GetText())
  1693.    
  1694.     if not (x1 and y1 and w and h) then
  1695.         return
  1696.     end
  1697.    
  1698.     local scale = 0.75
  1699.    
  1700.     x1 = x1*50
  1701.     y1 = y1*50
  1702.     w = w*50
  1703.     h = h*50
  1704.    
  1705.     local x2 = x1 + w
  1706.     local y2 = y1 + h
  1707.    
  1708.     --self.editor_icon:InitTexture("ui\\ui_icon_equipment")
  1709.     self.editor_icon:SetTextureRect(Frect():set(x1,y1,x2,y2))
  1710.     self.editor_icon:SetWndSize(vector2():set(w*scale,h*scale))
  1711.    
  1712.     local pos = self.ui_icon_equipment:GetWndPos()
  1713.     self.icon_square:SetWndPos(vector2():set( pos.x+x1/4 , pos.y+y1/4 ))
  1714.     self.icon_square:SetWndSize(vector2():set(w/4,h/4))
  1715.    
  1716.     local name = self.addon_list:GetText()
  1717.     if not (name and name ~= "" and name ~= "Select Attachment") then
  1718.         self.editor_icon_addon:SetTextureRect(Frect():set(0,0,0,0))
  1719.         self.fld_addon_offset_x:SetText("")
  1720.         self.fld_addon_offset_y:SetText("")
  1721.         return
  1722.     end
  1723.    
  1724.     local offset_x = tonumber(self.fld_addon_offset_x:GetText())
  1725.     local offset_y  = offset_x and tonumber(self.fld_addon_offset_y:GetText())
  1726.    
  1727.     if not (offset_y) then
  1728.         self.editor_icon_addon:SetTextureRect(Frect():set(0,0,0,0))
  1729.         self.fld_addon_offset_x:SetText("")
  1730.         self.fld_addon_offset_y:SetText("")
  1731.         return
  1732.     end
  1733.    
  1734.     pos = self.editor_icon:GetWndPos()
  1735.     self.editor_icon_addon:SetWndPos(vector2():set(pos.x+offset_x*scale,pos.y+offset_y*scale))
  1736. end
  1737.  
  1738. function debug_ui:OnEditorSave()
  1739.     if not (self.need_save_x or self.need_save_y or self.need_save_w or self.need_save_h or self.need_save_offset_x or self.need_save_offset_y) then
  1740.         return
  1741.     end
  1742.    
  1743.     local x1 = tonumber(self.fld_icon_x:GetText())
  1744.     local y1 = x1 and tonumber(self.fld_icon_y:GetText())
  1745.    
  1746.     local w = y1 and tonumber(self.fld_icon_width:GetText())
  1747.     local h = w and tonumber(self.fld_icon_height:GetText())
  1748.  
  1749.     if not (h) then
  1750.         return
  1751.     end
  1752.  
  1753.     local offset_x = tonumber(self.fld_addon_offset_x:GetText())
  1754.     local offset_y  = offset_x and tonumber(self.fld_addon_offset_y:GetText())
  1755.    
  1756.     local item = self.editor_spawn_list:GetSelectedItem()
  1757.     if not(item) then
  1758.         self:SendOutput("UIEditorSave: No item section was selected in the list.")
  1759.         return
  1760.     end
  1761.  
  1762.     local section = item.sect:GetText()
  1763.     local ini = system_ini()
  1764.     if  not (ini:section_exist(section)) then
  1765.         self:SendOutput(strformat("UIEditorSave: Section %s does not exist",section))
  1766.         return
  1767.     end
  1768.    
  1769.     local ind = self.addon_list:CurrentID()
  1770.     local addon_sec = self.addon_list:GetTextOf(ind)
  1771.     if (addon_sec == nil or addon_sec == "" or addon_sec == "Select Attachment") then
  1772.         addon_sec = nil
  1773.         self.need_save_offset_x = nil
  1774.         self.need_save_offset_y = nil
  1775.         ind = 0
  1776.     end
  1777.    
  1778.     local search_sec = self._addons[ind] == "scope" and self._scopes[ind] or section
  1779.    
  1780.     local function file_exists(path)
  1781.         return io.open(path) ~= nil
  1782.     end
  1783.    
  1784.     local function on_execute(path,filename,quit)
  1785.         local fullpath = path.."\\"..filename
  1786.         local ltx = io.open(fullpath,"rb")
  1787.         if (ltx) then
  1788.             local data = ltx:read("*all")
  1789.             ltx:close()
  1790.             if (data) then
  1791.                 if (string.find(data,"["..section.."]",nil,true)) then
  1792.                     ltx = alun_utils.cfg_file(fullpath)
  1793.                     if (ltx) then
  1794.                         if (self.need_save_x) then
  1795.                             ltx:SetValue(section,"inv_grid_x",x1)
  1796.                         end
  1797.                         if (self.need_save_y) then
  1798.                             ltx:SetValue(section,"inv_grid_y",y1)
  1799.                         end
  1800.                         if (self.need_save_w) then
  1801.                             ltx:SetValue(section,"inv_grid_width",w)
  1802.                         end
  1803.                         if (self.need_save_h) then
  1804.                             ltx:SetValue(section,"inv_grid_height",h)
  1805.                         end
  1806.                         ltx:SaveExt()
  1807.                     end
  1808.                 end
  1809.                 if (self.need_save_offset_x or self.need_save_offset_y) and (string.find(data,"["..search_sec.."]",nil,true)) then
  1810.                     ltx = alun_utils.cfg_file(fullpath)
  1811.                     if (ltx) then
  1812.                         if (self.need_save_offset_x) then
  1813.                             ltx:SetValue(search_sec,self._addons[ind].."_x",offset_x)
  1814.                         end
  1815.                         if (self.need_save_offset_y) then
  1816.                             ltx:SetValue(search_sec,self._addons[ind].."_y",offset_y)
  1817.                         end
  1818.                         ltx:SaveExt()
  1819.                     end
  1820.                 end
  1821.             end
  1822.         end
  1823.     end
  1824.  
  1825.     local sp = getFS():update_path('$game_config$', '')
  1826.     sp = string.sub(sp,0,string.len(sp)-1)
  1827.     lua_extensions.recurse_subdirectories_and_execute(sp,{"ltx"},on_execute)
  1828.    
  1829.     if (reload_system_ini) then
  1830.         reload_system_ini()
  1831.     end
  1832.    
  1833.     self.need_save_x = nil
  1834.     self.need_save_y = nil 
  1835.     self.need_save_w = nil
  1836.     self.need_save_h = nil
  1837.     self.need_save_offset_x = nil
  1838.     self.need_save_offset_y = nil
  1839. end
  1840.  
  1841.  
  1842. -- SPAWNER UI
  1843. class "debug_ui_spawner" (CUIWindow)
  1844. function debug_ui_spawner:__init(owner, binds) super()
  1845.     self.owner = owner
  1846. end
  1847. function debug_ui_spawner:__finalize()
  1848.  
  1849. end
  1850.  
  1851. function debug_ui_spawner:InitControls(x, y, xml, owner)
  1852.     self:SetWndPos(vector2():set(x-50,y))
  1853.     self:SetWndSize(vector2():set(800,416))
  1854.     self:SetAutoDelete(true)
  1855.  
  1856.     owner.sections_list = xml:InitComboBox("tab_spawner:list_sections", self)
  1857.     owner.sections_list:ClearList()
  1858.     owner.sections_list:SetAutoDelete(true)
  1859.  
  1860.     for i=1,#id_to_spawn_table do
  1861.         owner.sections_list:AddItem(id_to_spawn_table[i],i-1)
  1862.     end
  1863.  
  1864.     owner:Register(owner.sections_list, "list_sections")
  1865.  
  1866.     owner.spawn_list_frame = xml:InitFrame("tab_spawner:list_frame",self)
  1867.     owner.spawn_list = xml:InitListBox("tab_spawner:list",self)
  1868.     owner.spawn_list:ShowSelectedItem(true)
  1869.  
  1870.     owner:Register(owner.spawn_list, "list_window")
  1871.  
  1872.     owner.check_to_actor = xml:InitCheck("tab_spawner:check_own_to_actor",self)
  1873.     owner.check_to_actor:SetCheck(true)
  1874.  
  1875.     --local ctrl = xml:Init3tButton("tab_spawner:btn_create",self)
  1876.     --owner:Register(ctrl, "btn_create")
  1877.  
  1878.  
  1879.     owner.smarts_list = xml:InitComboBox("tab_spawner:list_smarts", self)
  1880.     owner.smarts_list:ClearList()
  1881.     owner.smarts_list:SetAutoDelete(true)
  1882.    
  1883.     local sim = alife()
  1884.     local actor_level = sim:level_name(game_graph():vertex(sim:actor().m_game_vertex_id):level_id())
  1885.     local board = SIMBOARD
  1886.     local smrts = {}
  1887.     for id,t in pairs(board.smarts) do
  1888.         if (t.smrt and actor_level == t.smrt.smart_level) then
  1889.             smrts[#smrts+1] = t.smrt:name()
  1890.         end
  1891.     end
  1892.    
  1893.     table.sort(smrts)
  1894.     for i=1,#smrts do
  1895.         owner.smarts_list:AddItem(smrts[i],i)  
  1896.     end
  1897.  
  1898.     owner.smarts_list:SetText("Squad to Smart")
  1899.    
  1900.     --owner.smarts_list:Show(false)
  1901.    
  1902.     owner.smarts_list_cap = xml:InitStatic("tab_spawner:cap_smarts", self)
  1903.  
  1904.     --owner:Register(owner.smarts_list, "list_smarts")
  1905.  
  1906.     -- Set defaults
  1907.     owner.sections_list:SetText("Spawn Sections")
  1908.     --owner:FillList("Weapons (Rifle)")
  1909.  
  1910.     ------------------------- manual input
  1911.     xml:InitStatic("tab_spawner:cap_spawn", self)
  1912.     owner.fld_spawn = xml:InitEditBox("tab_spawner:fld_spawn", self)
  1913.  
  1914.     btn = xml:Init3tButton("tab_spawner:btn_spawn",self)
  1915.     owner:Register(btn, "btn_spawn")
  1916.  
  1917.     xml:InitStatic("tab_spawner:cap_spawn_squad", self)
  1918.     owner.fld_spawn_squad = xml:InitEditBox("tab_spawner:fld_spawn_squad", self)
  1919.  
  1920.     xml:InitStatic("tab_spawner:cap_spawn_smart", self)
  1921.     owner.fld_spawn_smart = xml:InitEditBox("tab_spawner:fld_spawn_smart", self)
  1922.  
  1923.     btn = xml:Init3tButton("tab_spawner:btn_spawn_squad",self)
  1924.     owner:Register(btn, "btn_spawn_squad")
  1925. end
  1926.  
  1927. -- HUD UI
  1928. class "debug_ui_hud" (CUIWindow)
  1929. function debug_ui_hud:__init(owner, binds) super()
  1930.     self.owner = owner
  1931. end
  1932. function debug_ui_hud:__finalize()
  1933.  
  1934. end
  1935. function debug_ui_hud:InitControls(x, y, xml, owner)
  1936.     self:SetWndPos(vector2():set(x,y))
  1937.     self:SetWndSize(vector2():set(800,416))
  1938.     self:SetAutoDelete(true)
  1939.  
  1940.     xml:InitStatic("tab_hud:cap_focus", self)
  1941.     owner.fld_focus = xml:InitEditBox("tab_hud:fld_focus", self)
  1942.  
  1943.     local btn = xml:Init3tButton("tab_hud:btn_focus",self)
  1944.     owner:Register(btn, "btn_focus")
  1945. end
  1946.  
  1947. -- object UI
  1948. class "debug_ui_object" (CUIWindow)
  1949. function debug_ui_object:__init(owner, binds) super()
  1950.     self.owner = owner
  1951. end
  1952. function debug_ui_object:__finalize()
  1953.  
  1954. end
  1955. function debug_ui_object:InitControls(x, y, xml, owner)
  1956.     self:SetWndPos(vector2():set(x,y))
  1957.     self:SetWndSize(vector2():set(800,416))
  1958.     self:SetAutoDelete(true)
  1959.  
  1960.     xml:InitStatic("tab_object:cap_find", self)
  1961.     owner.fld_find = xml:InitEditBox("tab_object:fld_find", self)
  1962.  
  1963.     local btn
  1964.     btn = xml:Init3tButton("tab_object:btn_find",self)
  1965.     owner:Register(btn, "btn_find")
  1966.  
  1967.     xml:InitStatic("tab_object:cap_id", self)
  1968.     owner.fld_id = xml:InitEditBox("tab_object:fld_id", self)
  1969.  
  1970.     xml:InitStatic("tab_object:cap_section", self)
  1971.     owner.fld_section = xml:InitEditBox("tab_object:fld_section", self)
  1972.  
  1973.     xml:InitStatic("tab_object:cap_logic", self)
  1974.     owner.fld_logic = xml:InitEditBox("tab_object:fld_logic", self)
  1975.  
  1976.     xml:InitStatic("tab_object:cap_filename", self)
  1977.     owner.fld_filename = xml:InitEditBox("tab_object:fld_filename", self)
  1978.  
  1979.     btn = xml:Init3tButton("tab_object:btn_set",self)
  1980.     owner:Register(btn, "btn_set")
  1981.  
  1982.     btn = xml:Init3tButton("tab_object:btn_revert",self)
  1983.     owner:Register(btn, "btn_revert")
  1984.  
  1985.     xml:InitStatic("tab_object:cap_reload", self)
  1986.     owner.fld_reload = xml:InitEditBox("tab_object:fld_reload", self)
  1987.  
  1988.     btn = xml:Init3tButton("tab_object:btn_reload",self)
  1989.     owner:Register(btn, "btn_reload")
  1990. end
  1991.  
  1992. -- ADVANCED UI
  1993. class "debug_ui_advanced" (CUIWindow)
  1994. function debug_ui_advanced:__init(owner, binds) super()
  1995.     self.owner = owner
  1996. end
  1997. function debug_ui_advanced:__finalize()
  1998.  
  1999. end
  2000. function debug_ui_advanced:InitControls(x, y, xml, owner)
  2001.     self:SetWndPos(vector2():set(x,y))
  2002.     self:SetWndSize(vector2():set(800,416))
  2003.     self:SetAutoDelete(true)
  2004.  
  2005.     xml:InitStatic("tab_advanced:cap_execute_string", self)
  2006.     owner.fld_execute_string = xml:InitEditBox("tab_advanced:fld_execute_string", self)
  2007.  
  2008.     local btn = xml:Init3tButton("tab_advanced:btn_execute_string",self)
  2009.     owner:Register(btn, "btn_execute_string")
  2010.  
  2011.     xml:InitStatic("tab_advanced:cap_jump_level", self)
  2012.    
  2013.     owner.levels_list_frame = xml:InitFrame("tab_advanced:list_frame",self)
  2014.     owner.levels_list = xml:InitListBox("tab_advanced:list",self)
  2015.     owner.levels_list:ShowSelectedItem(true)
  2016.  
  2017.     owner:Register(owner.levels_list, "list_levels_window")
  2018.    
  2019.     owner:FillLevelList()
  2020. end
  2021.  
  2022. -- ICON EDITOR
  2023. class "debug_ui_editor" (CUIWindow)
  2024. function debug_ui_editor:__init(owner, binds) super()
  2025.     self.owner = owner
  2026. end
  2027. function debug_ui_editor:__finalize()
  2028.  
  2029. end
  2030. function debug_ui_editor:InitControls(x, y, xml, owner)
  2031.     self:SetWndPos(vector2():set(x-50,y))
  2032.     self:SetWndSize(vector2():set(800,416))
  2033.     self:SetAutoDelete(true)
  2034.  
  2035.     owner.editor_sections_list = xml:InitComboBox("tab_editor:list_sections", self)
  2036.     owner.editor_sections_list:ClearList()
  2037.     owner.editor_sections_list:SetAutoDelete(true)
  2038.  
  2039.     local invalid_ids = {[6] = true , [7] = true, [9] = true, [10] = true, [11] = true}
  2040.     for i=1,#id_to_spawn_table do
  2041.         if not (invalid_ids[i]) then
  2042.             owner.editor_sections_list:AddItem(id_to_spawn_table[i],i-1)
  2043.         end
  2044.     end
  2045.  
  2046.     owner:Register(owner.editor_sections_list, "editor_list_sections")
  2047.  
  2048.     owner.editor_spawn_list_frame = xml:InitFrame("tab_editor:list_frame",self)
  2049.     owner.editor_spawn_list = xml:InitListBox("tab_editor:list",self)
  2050.     owner.editor_spawn_list:ShowSelectedItem(true)
  2051.  
  2052.     owner:Register(owner.editor_spawn_list, "editor_list_window")
  2053.  
  2054.     owner.editor_icon_back = xml:InitStatic("tab_editor:icon_back",self)
  2055.     owner.editor_icon = xml:InitStatic("tab_editor:icon",self)
  2056.    
  2057.     -- Set defaults
  2058.     owner.editor_sections_list:SetText("Weapons (Rifle)")
  2059.     owner:FillEditorList("Weapons (Rifle)")
  2060.    
  2061.    
  2062.     -------
  2063.     xml:InitStatic("tab_editor:cap_w", self)
  2064.     owner.fld_icon_width = xml:InitEditBox("tab_editor:fld_w", self)
  2065.     owner:Register(owner.fld_icon_width,"fld_icon_width")
  2066.    
  2067.     xml:InitStatic("tab_editor:cap_h", self)
  2068.     owner.fld_icon_height = xml:InitEditBox("tab_editor:fld_h", self)
  2069.     owner:Register(owner.fld_icon_height,"fld_icon_height")
  2070.    
  2071.     xml:InitStatic("tab_editor:cap_x", self)
  2072.     owner.fld_icon_x = xml:InitEditBox("tab_editor:fld_x", self)
  2073.     owner:Register(owner.fld_icon_x,"fld_icon_x")
  2074.    
  2075.     xml:InitStatic("tab_editor:cap_y", self)
  2076.     owner.fld_icon_y = xml:InitEditBox("tab_editor:fld_y", self)
  2077.     owner:Register(owner.fld_icon_y,"fld_icon_y")
  2078.    
  2079.    
  2080.     owner.ui_icon_equipment_back = xml:InitFrame("ui_icon_equipment_back",owner)
  2081.     owner.ui_icon_equipment = xml:InitStatic("ui_icon_equipment",owner)
  2082.     owner.ui_icon_equipment:InitTexture("ui\\ui_icon_equipment")
  2083.     --owner.ui_icon_equipment:SetTextureRect(Frect():set(0,0,300,200))
  2084.     owner.ui_icon_equipment:SetWndSize(vector2():set(512,512))
  2085.     owner.ui_icon_equipment_back:SetWndSize(vector2():set(448,540))
  2086.    
  2087.    
  2088.     owner.icon_square = xml:InitFrame("square",owner)
  2089.    
  2090.     xml:InitStatic("tab_editor:cap_addon_x", self)
  2091.     owner.fld_addon_offset_x = xml:InitEditBox("tab_editor:fld_addon_x", self)
  2092.     owner:Register(owner.fld_addon_offset_x,"fld_addon_offset_x")
  2093.    
  2094.     xml:InitStatic("tab_editor:cap_addon_y", self)
  2095.     owner.fld_addon_offset_y = xml:InitEditBox("tab_editor:fld_addon_y", self)
  2096.     owner:Register(owner.fld_addon_offset_y,"fld_addon_offset_y")
  2097.    
  2098.     owner.addon_list = xml:InitComboBox("tab_editor:list_addon", self)
  2099.     owner:Register(owner.addon_list, "editor_list_addon")
  2100.     local t = {"Select Addon Type", "silencer", "grenade_launcher", "scope" }
  2101.     for i=1,#t do
  2102.         owner.addon_list:AddItem(t[i],i-1)
  2103.     end
  2104.    
  2105.     owner.addon_list:SetText("Select Addon Type")
  2106.    
  2107.     owner.editor_icon_addon = xml:InitStatic("tab_editor:icon_addon",self)
  2108.    
  2109.     local btn = xml:Init3tButton("tab_editor:btn_save",self)
  2110.     owner:Register(btn, "btn_editor_save")
  2111. end
  2112.  
  2113. ---------------------------------------------------- Attach Offsets
  2114. local _attached
  2115. local _last_section
  2116.  
  2117. class "debug_ui_attach" (CUIScriptWnd)
  2118. function debug_ui_attach:__init(owner, binds) super()
  2119.     self:SetWndRect             (Frect():set(0,0,1024,768))
  2120.     self:Enable                 (true)
  2121.  
  2122.     local xml                   = CScriptXmlInit()
  2123.     self.xml = xml
  2124.     xml:ParseFile               ("ui_debug_main.xml")
  2125.    
  2126.     self:SetAutoDelete(true)
  2127.     self.owner = owner
  2128.     self.need_save = {}
  2129.  
  2130.     local ctrl = CUIWindow()
  2131.     self.xml:InitWindow("wnd_attach_editor:file_item:main",0,ctrl)
  2132.     self.form = self.xml:InitStatic("wnd_attach_editor:form",self)
  2133.     self.xml:InitFrame("wnd_attach_editor:form:list_frame",self.form)
  2134.  
  2135.     ctrl = self.xml:Init3tButton("wnd_attach_editor:form:btn_attach",self.form)
  2136.     self:Register(ctrl, "button_attach_npc")
  2137.     self:AddCallback("button_attach_npc", ui_events.BUTTON_CLICKED, self.OnAttach, self)
  2138.    
  2139.     --[[
  2140.     ctrl = self.xml:Init3tButton("wnd_attach_editor:form:btn_save",self.form)
  2141.     self:Register(ctrl, "button_attach_save")
  2142.     self:AddCallback("button_attach_save", ui_events.BUTTON_CLICKED, self.OnAttachSave, self)
  2143.     --]]
  2144.    
  2145.     xml:InitStatic("wnd_attach_editor:form:cap_pos", self.form)
  2146.     xml:InitStatic("wnd_attach_editor:form:cap_angle", self.form)
  2147.    
  2148.     self.flds = {"x","y","z","rot_x","rot_y","rot_z"}
  2149.     for i=1,#self.flds do
  2150.         xml:InitStatic("wnd_attach_editor:form:cap_"..self.flds[i], self.form)
  2151.         self["fld_attach_"..self.flds[i]] = xml:InitEditBox("wnd_attach_editor:form:fld_"..self.flds[i], self.form)
  2152.         self:Register(self["fld_attach_"..self.flds[i]],"fld_attach_"..self.flds[i])
  2153.        
  2154.         self:AddCallback("fld_attach_"..self.flds[i],     ui_events.EDIT_TEXT_COMMIT, self["On_fld_attach_"..self.flds[i]], self)
  2155.     end
  2156.  
  2157.     self.attachable = xml:InitComboBox("wnd_attach_editor:form:list_attach", self.form)
  2158.     self:Register(self.attachable, "attach_list")
  2159.     self:AddCallback("attach_list", ui_events.LIST_ITEM_SELECT, self.OnAttachListSelect,self)
  2160.    
  2161.     local sys_ini = system_ini()
  2162.     local t = alun_utils.parse_list(sys_ini,"stalker","attachable_items")
  2163.     if (#t > 0) then
  2164.         for i=1,#t do
  2165.             if (sys_ini:section_exist(t[i])) then
  2166.                 self.attachable:AddItem(t[i],i-1)
  2167.             end
  2168.         end
  2169.     end
  2170.    
  2171.     -- TODO:
  2172.     -- NOT IMPLEMENTED FULLY YET
  2173.     self.weapons = xml:InitComboBox("wnd_attach_editor:form:list_weapons", self.form)
  2174.     self:Register(self.weapons, "weapon_list")
  2175.     self:AddCallback("weapon_list", ui_events.LIST_ITEM_SELECT, self.OnWeaponListSelect,self)
  2176.    
  2177.     local valid_ids = {13,14,15} -- Weapon spawn tables only
  2178.    
  2179.     for n=1,#valid_ids do
  2180.         local slist = get_spawn_table(id_to_spawn_table[valid_ids[n]])
  2181.         if (slist) then
  2182.             local cnt = 0
  2183.             for i=1,#slist do
  2184.                 if (sys_ini:section_exist(slist[i])) then
  2185.                     self.weapons:AddItem(slist[i],cnt)
  2186.                     cnt = cnt + 1
  2187.                 end
  2188.             end
  2189.         end
  2190.     end
  2191. end
  2192. function debug_ui_attach:__finalize()
  2193.  
  2194. end
  2195. function debug_ui_attach:OnAttachListSelect()
  2196.     self._last = "attach"
  2197.     for i=1,#self.flds do
  2198.         self.need_save[self.flds[i]] = nil
  2199.     end
  2200.    
  2201.     local section = self.attachable:GetText()
  2202.     if not (section and system_ini():section_exist(section)) then
  2203.         return
  2204.     end
  2205.    
  2206.     local pos = alun_utils.parse_list(system_ini(),section,"attach_position_offset")
  2207.     local angle = alun_utils.parse_list(system_ini(),section,"attach_angle_offset")
  2208.    
  2209.     if not (#pos > 0) then
  2210.         return
  2211.     end
  2212.    
  2213.     for i=1,#pos do
  2214.         if (self["fld_attach_"..self.flds[i]]) then
  2215.             self["fld_attach_"..self.flds[i]]:SetText(pos[i])
  2216.         end
  2217.     end
  2218.    
  2219.     if not (#angle > 0) then
  2220.         return
  2221.     end
  2222.    
  2223.     for i=1,#angle do
  2224.         if (self["fld_attach_"..self.flds[i+3]]) then
  2225.             self["fld_attach_"..self.flds[i+3]]:SetText(angle[i])
  2226.         end
  2227.     end
  2228. end
  2229. function debug_ui_attach:OnWeaponListSelect()
  2230.     self._last = "weapon"
  2231.     for i=1,#self.flds do
  2232.         self.need_save[self.flds[i]] = nil
  2233.     end
  2234.    
  2235.     local section = self.weapons:GetText()
  2236.     if not (section and system_ini():section_exist(section)) then
  2237.         return
  2238.     end
  2239.    
  2240.     local pos = alun_utils.parse_list(system_ini(),section,"position")
  2241.     local angle = alun_utils.parse_list(system_ini(),section,"orientation")
  2242.    
  2243.     if not (#pos > 0) then
  2244.         return
  2245.     end
  2246.    
  2247.     for i=1,#pos do
  2248.         if (self["fld_attach_"..self.flds[i]]) then
  2249.             self["fld_attach_"..self.flds[i]]:SetText(pos[i])
  2250.         end
  2251.     end
  2252.    
  2253.     if not (#angle > 0) then
  2254.         return
  2255.     end
  2256.    
  2257.     for i=1,#angle do
  2258.         if (self["fld_attach_"..self.flds[i+3]]) then
  2259.             self["fld_attach_"..self.flds[i+3]]:SetText(angle[i])
  2260.         end
  2261.     end
  2262. end
  2263. function debug_ui_attach:OnAttachSave(section)
  2264.     local need_save
  2265.     local fld
  2266.     local vals = {}
  2267.     for i=1,#self.flds do
  2268.         fld = self["fld_attach_"..self.flds[i]]
  2269.         if not (fld) then
  2270.             return
  2271.         end
  2272.        
  2273.         if not (tonumber(fld:GetText())) then
  2274.             return
  2275.         end
  2276.        
  2277.         if (self.need_save[self.flds[i]] == true) then
  2278.             need_save = true
  2279.         end
  2280.        
  2281.         vals[self.flds[i]] = tonumber(fld:GetText())
  2282.     end
  2283.    
  2284.     if not (need_save) then
  2285.         return
  2286.     end
  2287.  
  2288.     local function file_exists(path)
  2289.         return io.open(path) ~= nil
  2290.     end
  2291.    
  2292.     local function on_execute(path,filename,quit)
  2293.         local fullpath = path.."\\"..filename
  2294.         local ltx = io.open(fullpath,"rb")
  2295.         if (ltx) then
  2296.             local data = ltx:read("*all")
  2297.             ltx:close()
  2298.             if (data) then
  2299.                 if (string.find(data,"["..section.."]",nil,true)) then
  2300.                     ltx = alun_utils.cfg_file(fullpath)
  2301.                     if (ltx) then
  2302.                         if (self._last == "attach") then
  2303.                             if (self.need_save.x or self.need_save.y or self.need_save.z) then
  2304.                                 ltx:SetValue(section,"attach_position_offset",vals.x .. ", " .. vals.y .. ", " .. vals.z)
  2305.                             end
  2306.                            
  2307.                             if (self.need_save.rot_x or self.need_save.rot_y or self.need_save.rot_z) then
  2308.                                 ltx:SetValue(section,"attach_angle_offset",vals.rot_x .. ", " .. vals.rot_y .. ", " .. vals.rot_z)
  2309.                             end
  2310.                         elseif (self._last == "weapon") then
  2311.                             if (self.need_save.x or self.need_save.y or self.need_save.z) then
  2312.                                 ltx:SetValue(section,"position",vals.x .. ", " .. vals.y .. ", " .. vals.z)
  2313.                             end
  2314.                            
  2315.                             if (self.need_save.rot_x or self.need_save.rot_y or self.need_save.rot_z) then
  2316.                                 ltx:SetValue(section,"orientation",vals.rot_x .. ", " .. vals.rot_y .. ", " .. vals.rot_z)
  2317.                             end
  2318.                         end
  2319.                        
  2320.                         ltx:SaveExt()
  2321.                         return
  2322.                     end
  2323.                 end
  2324.             end
  2325.         end
  2326.     end
  2327.  
  2328.     local sp = getFS():update_path('$game_config$', '')
  2329.     sp = string.sub(sp,0,string.len(sp)-1)
  2330.     lua_extensions.recurse_subdirectories_and_execute(sp,{"ltx"},on_execute)
  2331.    
  2332.     if (reload_system_ini) then
  2333.         reload_system_ini()
  2334.     end
  2335. end
  2336. function debug_ui_attach:On_fld_attach_x()
  2337.     self:OnEditAttach("x")
  2338. end
  2339. function debug_ui_attach:On_fld_attach_y()
  2340.     self:OnEditAttach("y")
  2341. end
  2342. function debug_ui_attach:On_fld_attach_z()
  2343.     self:OnEditAttach("z")
  2344. end
  2345. function debug_ui_attach:On_fld_attach_rot_x()
  2346.     self:OnEditAttach("rot_x")
  2347. end
  2348. function debug_ui_attach:On_fld_attach_rot_y()
  2349.     self:OnEditAttach("rot_y")
  2350. end
  2351. function debug_ui_attach:On_fld_attach_rot_z()
  2352.     self:OnEditAttach("rot_z")
  2353. end
  2354. function debug_ui_attach:OnEditAttach(fld)
  2355.     if not (_attached) then
  2356.         return
  2357.     end
  2358.     local section = self._last == "attach" and self.attachable:GetText() or self._last == "weapon" and self.weapons:GetText() or nil
  2359.     if not (section and system_ini():section_exist(section)) then
  2360.         return
  2361.     end
  2362.    
  2363.     local itm = level.object_by_id(_attached)
  2364.     if not (itm) then
  2365.         return
  2366.     end
  2367.    
  2368.     if not (section == itm:section()) then
  2369.         printf("ERROR: ui_debug_main.debug_ui_attach : section in combo box is not same section as item! itm=%s selected=%s",itm:section(),section)
  2370.         return
  2371.     end
  2372.    
  2373.     self.need_save[fld] = true
  2374.  
  2375.     self:OnAttachSave(section)
  2376.    
  2377.     itm:attachable_item_load_attach(section)
  2378. end
  2379. function debug_ui_attach:OnKeyboard(dik, keyboard_action)
  2380.     CUIScriptWnd.OnKeyboard(self,dik,keyboard_action)
  2381.     if keyboard_action == ui_events.WINDOW_KEY_RELEASED then
  2382.         local keybinds = self.binds or {}
  2383.         if (dik == DIK_keys.DIK_ESCAPE) then
  2384.             self:OnQuit()
  2385.         end
  2386.     end
  2387.     return true
  2388. end
  2389. local function delayed_attach(id)
  2390.     local itm = id and level.object_by_id(id)
  2391.     if (itm) then
  2392.         itm:enable_attachable_item(true)
  2393.         _attached = itm:id()
  2394.         return true
  2395.     end
  2396.     return false
  2397. end
  2398. function debug_ui_attach:OnAttach()
  2399.     local npc = xrs_debug_tools.get_debug_npc() or xrs_debug_tools.NEAREST_STALKER
  2400.     if not (npc and npc:id() ~= 0) then
  2401.         return
  2402.     end
  2403.    
  2404.     local section = self._last == "attach" and self.attachable:GetText() or self._last == "weapon" and self.weapons:GetText() or nil
  2405.     if not (section and system_ini():section_exist(section)) then
  2406.         return
  2407.     end
  2408.    
  2409.     if (_last_section ~= section) then
  2410.         _last_section = section
  2411.         if (_attached) then
  2412.             local itm = level.object_by_id(_attached)
  2413.             if (itm) then
  2414.                 itm:enable_attachable_item(false)
  2415.             end
  2416.             _attached = nil
  2417.         end
  2418.     end
  2419.        
  2420.     local itm = npc:object(section)
  2421.     if not (itm) then
  2422.         local se_itm = alife():create(section,npc:position(),npc:level_vertex_id(),npc:game_vertex_id(),npc:id())
  2423.         if (se_itm) then
  2424.             CreateTimeEvent(se_itm.id,"delayed_attach",1,delayed_attach,se_itm.id)
  2425.         end
  2426.     else
  2427.         if (_attached) then
  2428.             itm:enable_attachable_item(false)
  2429.         end
  2430.         _attached = itm:id()
  2431.         CreateTimeEvent(itm:id(),"delayed_attach",1,delayed_attach,itm:id())
  2432.     end
  2433. end
  2434. function debug_ui_attach:OnQuit()
  2435.     self:HideDialog()
  2436. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement