From a51d3618244ce120a7d37c550239ddbfa7381957 Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Tue, 5 Apr 2022 12:00:13 +0200 Subject: [PATCH 1/5] tweaks and changes --- comfy_panel/score.lua | 14 +++-- maps/mountain_fortress_v3/functions.lua | 83 +++++-------------------- modules/rpg.lua | 20 ++---- modules/rpg/functions.lua | 27 ++++++-- modules/rpg/main.lua | 35 +++++------ modules/wave_defense/pause_waves.lua | 7 ++- 6 files changed, 73 insertions(+), 113 deletions(-) diff --git a/comfy_panel/score.lua b/comfy_panel/score.lua index b6465e9c..0dd97163 100644 --- a/comfy_panel/score.lua +++ b/comfy_panel/score.lua @@ -1,10 +1,12 @@ --scoreboard by mewmew +-- modified by Gerkiz local Event = require 'utils.event' local Global = require 'utils.global' local Tabs = require 'comfy_panel.main' local SpamProtection = require 'utils.spam_protection' local Token = require 'utils.token' +local format_number = require 'util'.format_number local Public = {} local this = { @@ -129,7 +131,7 @@ local function add_global_stats(frame, player) l.style.font_color = {r = 175, g = 75, b = 255} l.style.minimal_width = 140 - local rocketsLaunched_label = t.add {type = 'label', caption = player.force.rockets_launched} + local rocketsLaunched_label = t.add {type = 'label', caption = format_number(player.force.rockets_launched, true)} rocketsLaunched_label.style.font = 'default-listbox' rocketsLaunched_label.style.font_color = {r = 0.9, g = 0.9, b = 0.9} rocketsLaunched_label.style.minimal_width = 123 @@ -139,7 +141,7 @@ local function add_global_stats(frame, player) bugs_dead_label.style.font_color = {r = 0.90, g = 0.3, b = 0.3} bugs_dead_label.style.minimal_width = 100 - local killcount_label = t.add {type = 'label', caption = tostring(get_total_biter_killcount(player.force))} + local killcount_label = t.add {type = 'label', caption = format_number(tonumber(get_total_biter_killcount(player.force)), true)} killcount_label.style.font = 'default-listbox' killcount_label.style.font_color = {r = 0.9, g = 0.9, b = 0.9} killcount_label.style.minimal_width = 145 @@ -227,10 +229,10 @@ local function show_score(data) } local lines = { {caption = entry.name, color = special_color}, - {caption = tostring(entry.killscore)}, - {caption = tostring(entry.deaths)}, - {caption = tostring(entry.built_entities)}, - {caption = tostring(entry.mined_entities)} + {caption = format_number(tonumber(entry.killscore), true)}, + {caption = format_number(tonumber(entry.deaths), true)}, + {caption = format_number(tonumber(entry.built_entities), true)}, + {caption = format_number(tonumber(entry.mined_entities), true)} } local default_color = {r = 0.9, g = 0.9, b = 0.9} diff --git a/maps/mountain_fortress_v3/functions.lua b/maps/mountain_fortress_v3/functions.lua index 36cbf75e..2afb295a 100644 --- a/maps/mountain_fortress_v3/functions.lua +++ b/maps/mountain_fortress_v3/functions.lua @@ -149,19 +149,6 @@ local function do_refill_turrets() end end ---[[ local function do_turret_energy() - local power_sources = this.power_sources - - for index = 1, #power_sources do - local ps_data = power_sources[index] - if not (ps_data and ps_data.valid) then - fast_remove(power_sources, index) - return - end - - ps_data.energy = 0xfffff - end -end ]] local function do_magic_crafters() local magic_crafters = this.magic_crafters local limit = #magic_crafters @@ -367,7 +354,7 @@ local function add_magic_crafter_output(entity, output, distance) local fluidbox_index = output.fluidbox_index local data = { entity = entity, - last_tick = round(game.tick), + last_tick = game.tick, base_rate = round(rate, 8), rate = round(rate, 8), item = output.item, @@ -1139,57 +1126,22 @@ function Public.boost_difficulty() local force = game.forces.player - if name == "I'm too young to die" then - force.manual_mining_speed_modifier = force.manual_mining_speed_modifier + 0.5 - force.character_running_speed_modifier = 0.15 - force.manual_crafting_speed_modifier = 0.15 - WPT.set('coin_amount', 1) - WPT.set('upgrades').flame_turret.limit = 12 - WPT.set('upgrades').landmine.limit = 50 - WPT.set('locomotive_health', 10000) - WPT.set('locomotive_max_health', 10000) - WPT.set('bonus_xp_on_join', 500) - WD.set('next_wave', game.tick + 3600 * 15) - WPT.set('spidertron_unlocked_at_zone', 10) - WD.set_normal_unit_current_health(1.0) - WD.set_unit_health_increment_per_wave(0.15) - WD.set_boss_unit_current_health(2) - WD.set_boss_health_increment_per_wave(1.5) - WPT.set('difficulty_set', true) - elseif name == 'Hurt me plenty' then - force.manual_mining_speed_modifier = force.manual_mining_speed_modifier + 0.25 - force.character_running_speed_modifier = 0.1 - force.manual_crafting_speed_modifier = 0.1 - WPT.set('coin_amount', 2) - WPT.set('upgrades').flame_turret.limit = 10 - WPT.set('upgrades').landmine.limit = 50 - WPT.set('locomotive_health', 7000) - WPT.set('locomotive_max_health', 7000) - WPT.set('bonus_xp_on_join', 300) - WD.set('next_wave', game.tick + 3600 * 8) - WPT.set('spidertron_unlocked_at_zone', 8) - WD.set_normal_unit_current_health(1.6) - WD.set_unit_health_increment_per_wave(0.5) - WD.set_boss_unit_current_health(3) - WD.set_boss_health_increment_per_wave(5) - WPT.set('difficulty_set', true) - elseif name == 'Ultra-violence' then - force.character_running_speed_modifier = 0 - force.manual_crafting_speed_modifier = 0 - WPT.set('coin_amount', 4) - WPT.set('upgrades').flame_turret.limit = 3 - WPT.set('upgrades').landmine.limit = 10 - WPT.set('locomotive_health', 5000) - WPT.set('locomotive_max_health', 5000) - WPT.set('bonus_xp_on_join', 50) - WD.set('next_wave', game.tick + 3600 * 5) - WPT.set('spidertron_unlocked_at_zone', 6) - WD.set_normal_unit_current_health(2) - WD.set_unit_health_increment_per_wave(1) - WD.set_boss_unit_current_health(4) - WD.set_boss_health_increment_per_wave(10) - WPT.set('difficulty_set', true) - end + force.manual_mining_speed_modifier = force.manual_mining_speed_modifier + 0.5 + force.character_running_speed_modifier = 0.15 + force.manual_crafting_speed_modifier = 0.15 + WPT.set('coin_amount', 1) + WPT.set('upgrades').flame_turret.limit = 12 + WPT.set('upgrades').landmine.limit = 50 + WPT.set('locomotive_health', 10000) + WPT.set('locomotive_max_health', 10000) + WPT.set('bonus_xp_on_join', 500) + WD.set('next_wave', game.tick + 3600 * 15) + WPT.set('spidertron_unlocked_at_zone', 10) + WD.set_normal_unit_current_health(1.0) + WD.set_unit_health_increment_per_wave(0.15) + WD.set_boss_unit_current_health(2) + WD.set_boss_health_increment_per_wave(1.5) + WPT.set('difficulty_set', true) end function Public.set_spawn_position() @@ -1556,6 +1508,5 @@ Event.add(defines.events.on_player_changed_position, on_player_changed_position) Event.add(defines.events.on_pre_player_left_game, on_pre_player_left_game) Event.add(defines.events.on_player_respawned, on_player_respawned) Event.on_nth_tick(10, tick) --- Event.on_nth_tick(5, do_turret_energy) return Public diff --git a/modules/rpg.lua b/modules/rpg.lua index 0635f7ce..d47ef18a 100644 --- a/modules/rpg.lua +++ b/modules/rpg.lua @@ -119,7 +119,7 @@ local function get_one_punch_chance(player) if rpg_t[player.index].strength < 100 then return 0 end - local chance = math.round(rpg_t[player.index].strength * 0.01, 1) + local chance = math.round(rpg_t[player.index].strength * 0.007, 1) if chance > 100 then chance = 100 end @@ -152,8 +152,8 @@ end local function update_player_stats(player) local strength = rpg_t[player.index].strength - 10 - P.update_single_modifier(player, 'character_inventory_slots_bonus', 'rpg', math.round(strength * 0.2, 3)) - P.update_single_modifier(player, 'character_mining_speed_modifier', 'rpg', math.round(strength * 0.008, 3)) + P.update_single_modifier(player, 'character_inventory_slots_bonus', 'rpg', math.round(strength * 0.1, 3)) + P.update_single_modifier(player, 'character_mining_speed_modifier', 'rpg', math.round(strength * 0.007, 3)) local magic = rpg_t[player.index].magic - 10 local v = magic * 0.15 @@ -831,10 +831,7 @@ local function on_entity_damaged(event) if not event.entity.valid then return end - if - event.cause.get_inventory(defines.inventory.character_ammo)[event.cause.selected_gun_index].valid_for_read and - event.cause.get_inventory(defines.inventory.character_guns)[event.cause.selected_gun_index].valid_for_read - then + if event.cause.get_inventory(defines.inventory.character_ammo)[event.cause.selected_gun_index].valid_for_read and event.cause.get_inventory(defines.inventory.character_guns)[event.cause.selected_gun_index].valid_for_read then return end if not event.cause.player then @@ -873,9 +870,7 @@ local function on_entity_damaged(event) event.cause.surface.create_entity({name = 'blood-explosion-huge', position = event.entity.position}) else damage = damage * math_random(100, 125) * 0.01 - event.cause.player.create_local_flying_text( - {text = math.floor(damage), position = event.entity.position, color = {150, 150, 150}, time_to_live = 90, speed = 2} - ) + event.cause.player.create_local_flying_text({text = math.floor(damage), position = event.entity.position, color = {150, 150, 150}, time_to_live = 90, speed = 2}) end --Handle the custom health pool of the biter health booster, if it is used in the map. @@ -960,10 +955,7 @@ local function on_pre_player_mined_item(event) end local player = game.players[event.player_index] - if - rpg_t[player.index].last_mined_entity_position.x == event.entity.position.x and - rpg_t[player.index].last_mined_entity_position.y == event.entity.position.y - then + if rpg_t[player.index].last_mined_entity_position.x == event.entity.position.x and rpg_t[player.index].last_mined_entity_position.y == event.entity.position.y then return end rpg_t[player.index].last_mined_entity_position.x = entity.position.x diff --git a/modules/rpg/functions.lua b/modules/rpg/functions.lua index 005be6a9..84c07c63 100644 --- a/modules/rpg/functions.lua +++ b/modules/rpg/functions.lua @@ -519,8 +519,8 @@ function Public.update_player_stats(player) local rpg_extra = Public.get('rpg_extra') local rpg_t = Public.get_value_from_player(player.index) local strength = rpg_t.strength - 10 - P.update_single_modifier(player, 'character_inventory_slots_bonus', 'rpg', round(strength * 0.2, 3)) - P.update_single_modifier(player, 'character_mining_speed_modifier', 'rpg', round(strength * 0.007, 3)) + P.update_single_modifier(player, 'character_inventory_slots_bonus', 'rpg', round(strength * 0.1, 3)) + P.update_single_modifier(player, 'character_mining_speed_modifier', 'rpg', round(strength * 0.006, 3)) P.update_single_modifier(player, 'character_maximum_following_robot_count_bonus', 'rpg', round(strength / 2 * 0.03, 3)) local magic = rpg_t.magicka - 10 @@ -555,7 +555,24 @@ function Public.level_up_effects(player) } player.surface.create_entity({name = 'flying-text', position = p, text = '✚', color = {255, math.random(0, 100), 0}}) end - player.play_sound {path = 'utility/achievement_unlocked', volume_modifier = 0.40} + player.play_sound {path = 'utility/achievement_unlocked', volume_modifier = 0.50} +end + +function Public.cast_spell(player, failed) + local position = {x = player.position.x - 0.75, y = player.position.y - 1} + local b = 0.75 + if not failed then + for _ = 1, 3, 1 do + local p = { + (position.x + 0.4) + (b * -1 + math.random(0, b * 20) * 0.1), + position.y + (b * -1 + math.random(0, b * 20) * 0.1) + } + player.surface.create_entity({name = 'flying-text', position = p, text = '✔️', color = {255, math.random(0, 100), 0}}) + end + player.play_sound {path = 'utility/scenario_message', volume_modifier = 0.50} + else + player.play_sound {path = 'utility/cannot_build', volume_modifier = 0.50} + end end function Public.xp_effects(player) @@ -569,7 +586,7 @@ function Public.xp_effects(player) } player.surface.create_entity({name = 'flying-text', position = p, text = '✚', color = {255, math.random(0, 100), 0}}) end - player.play_sound {path = 'utility/achievement_unlocked', volume_modifier = 0.40} + player.play_sound {path = 'utility/achievement_unlocked', volume_modifier = 0.50} end function Public.get_range_modifier(player) @@ -682,7 +699,7 @@ function Public.get_one_punch_chance(player) if rpg_t.strength < 100 then return 0 end - local chance = round(rpg_t.strength * 0.012, 1) + local chance = round(rpg_t.strength * 0.007, 1) if chance > 100 then chance = 100 end diff --git a/modules/rpg/main.lua b/modules/rpg/main.lua index 38fdaaa5..dcf3522e 100644 --- a/modules/rpg/main.lua +++ b/modules/rpg/main.lua @@ -680,10 +680,7 @@ local function on_entity_damaged(event) local original_damage_amount = event.original_damage_amount local final_damage_amount = event.final_damage_amount - if - cause.get_inventory(defines.inventory.character_ammo)[cause.selected_gun_index].valid_for_read or - cause.get_inventory(defines.inventory.character_guns)[cause.selected_gun_index].valid_for_read - then + if cause.get_inventory(defines.inventory.character_ammo)[cause.selected_gun_index].valid_for_read or cause.get_inventory(defines.inventory.character_guns)[cause.selected_gun_index].valid_for_read then local is_explosive_bullets_enabled = Public.get_explosive_bullets() if is_explosive_bullets_enabled then Public.explosive_bullets(event) @@ -1160,7 +1157,7 @@ local function on_player_used_capsule(event) local p = player.print if rpg_t.last_spawned >= game.tick then - return p(({'rpg_main.mana_casting_too_fast', player.name}), Color.warning) + return Public.cast_spell(player, true) end local mana = rpg_t.mana @@ -1183,7 +1180,7 @@ local function on_player_used_capsule(event) } if rpg_t.level < object.level then - return p(({'rpg_main.low_level'}), Color.fail) + return Public.cast_spell(player, true) end if not object.enabled then @@ -1191,12 +1188,12 @@ local function on_player_used_capsule(event) end if not Math2D.bounding_box.contains_point(area, player.position) then - player.print(({'rpg_main.not_inside_pos'}), Color.fail) + Public.cast_spell(player, true) return end if mana < object.mana_cost then - return p(({'rpg_main.no_mana'}), Color.fail) + return Public.cast_spell(player, true) end local target_pos @@ -1223,11 +1220,11 @@ local function on_player_used_capsule(event) if object.entityName == 'suicidal_comfylatron' then Public.suicidal_comfylatron(position, surface) - p(({'rpg_main.suicidal_comfylatron', 'Suicidal Comfylatron'}), Color.success) + Public.cast_spell(player) Public.remove_mana(player, object.mana_cost) elseif object.entityName == 'repair_aoe' then - local ents = Public.repair_aoe(player, position) - p(({'rpg_main.repair_aoe', ents}), Color.success) + Public.repair_aoe(player, position) + Public.cast_spell(player) Public.remove_mana(player, object.mana_cost) elseif object.entityName == 'pointy_explosives' then local entities = @@ -1245,11 +1242,9 @@ local function on_player_used_capsule(event) if detonate_chest and detonate_chest.valid then local success = Explosives.detonate_chest(detonate_chest) if success then - player.print(({'rpg_main.detonate_chest'}), Color.success) Public.remove_mana(player, object.mana_cost) - else - player.print(({'rpg_main.detonate_chest_failed'}), Color.fail) end + Public.cast_spell(player) end elseif object.entityName == 'warp-gate' then local pos = surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 3, 0, 5) @@ -1262,10 +1257,10 @@ local function on_player_used_capsule(event) Public.remove_mana(player, 999999) Public.damage_player_over_time(player, random(8, 16)) player.play_sound {path = 'utility/armor_insert', volume_modifier = 1} - p(({'rpg_main.warped_ok'}), Color.info) + Public.cast_spell(player) elseif object.capsule then -- spawn in capsules i.e objects that are usable with mouse-click player.insert({name = object.entityName, count = object.amount}) - p(({'rpg_main.object_spawned', object.entityName}), Color.success) + Public.cast_spell(player) Public.remove_mana(player, object.mana_cost) elseif projectile_types[object.entityName] then -- projectiles for i = 1, object.amount do @@ -1280,12 +1275,12 @@ local function on_player_used_capsule(event) end end end - p(({'rpg_main.object_spawned', object.entityName}), Color.success) + Public.cast_spell(player) Public.remove_mana(player, object.mana_cost) else if object.target then -- rockets and such surface.create_entity({name = object.entityName, position = position, force = force, target = target_pos, speed = 1}) - p(({'rpg_main.object_spawned', object.entityName}), Color.success) + Public.cast_spell(player) Public.remove_mana(player, object.mana_cost) elseif surface.can_place_entity {name = object.entityName, position = position} then if object.biter then @@ -1311,9 +1306,9 @@ local function on_player_used_capsule(event) e.direction = player.character.direction Public.remove_mana(player, object.mana_cost) end - p(({'rpg_main.object_spawned', object.entityName}), Color.success) + Public.cast_spell(player) else - p(({'rpg_main.out_of_reach'}), Color.fail) + Public.cast_spell(player, true) return end end diff --git a/modules/wave_defense/pause_waves.lua b/modules/wave_defense/pause_waves.lua index b27c8b51..1a1e5ad2 100644 --- a/modules/wave_defense/pause_waves.lua +++ b/modules/wave_defense/pause_waves.lua @@ -69,8 +69,7 @@ function Public.main_gui(player, text) inside_table.add( { type = 'label', - caption = 'We have played for ' .. - Server.format_time(game.ticks_played) .. ' now.\nIf you want to take a quick break,\nplease vote to pause the waves for 5 minutes.' + caption = 'We have played for ' .. Server.format_time(game.ticks_played) .. ' now.\nIf you want to take a quick break,\nplease vote to pause the waves for 5 minutes.' } ) local info_sub_style = info_sub.style @@ -200,6 +199,10 @@ Event.on_nth_tick( return end + if Server.format_time(game.ticks_played) == 0 then + return + end + local greeting = random_greetings[random(1, random_greetings_size)] local players = game.connected_players From f74e99f3f417f08f5ee78516883a5e7d13bfdfe1 Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Tue, 5 Apr 2022 19:27:46 +0200 Subject: [PATCH 2/5] refactor gui --- maps/mountain_fortress_v3/breached_wall.lua | 14 +- maps/mountain_fortress_v3/functions.lua | 22 +-- maps/mountain_fortress_v3/mystical_chest.lua | 1 - .../resource_generator.lua | 134 ++++++++++++------ maps/mountain_fortress_v3/terrain.lua | 14 +- 5 files changed, 114 insertions(+), 71 deletions(-) diff --git a/maps/mountain_fortress_v3/breached_wall.lua b/maps/mountain_fortress_v3/breached_wall.lua index 16fca28e..5df020bc 100644 --- a/maps/mountain_fortress_v3/breached_wall.lua +++ b/maps/mountain_fortress_v3/breached_wall.lua @@ -186,13 +186,13 @@ local compare_player_and_train = function(player, entity) if c_y - t_y <= spidertron_warning_position then local surface = player.surface surface.create_entity( - { - name = 'flying-text', - position = position, - text = 'Warning!!! You are too far from the train!!!', - color = {r = 0.9, g = 0.0, b = 0.0} - } - ) + { + name = 'flying-text', + position = position, + text = 'Warning!!! You are too far from the train!!!', + color = {r = 0.9, g = 0.0, b = 0.0} + } + ) end if c_y - t_y <= gap_between_zones.neg_gap then diff --git a/maps/mountain_fortress_v3/functions.lua b/maps/mountain_fortress_v3/functions.lua index 2afb295a..2bfef1a6 100644 --- a/maps/mountain_fortress_v3/functions.lua +++ b/maps/mountain_fortress_v3/functions.lua @@ -533,10 +533,12 @@ Public.magic_item_crafting_callback = local force = game.forces.player local tech = callback_data.tech - if tech then - if not force.technologies[tech].researched then - entity.destroy() - return + if not callback_data.testing then + if tech then + if not force.technologies[tech].researched then + entity.destroy() + return + end end end @@ -603,11 +605,13 @@ Public.magic_item_crafting_callback_weighted = local force = game.forces.player local tech = stack.tech - if tech then - if force.technologies[tech] then - if not force.technologies[tech].researched then - entity.destroy() - return + if not callback_data.testing then + if tech then + if force.technologies[tech] then + if not force.technologies[tech].researched then + entity.destroy() + return + end end end end diff --git a/maps/mountain_fortress_v3/mystical_chest.lua b/maps/mountain_fortress_v3/mystical_chest.lua index 1b029dc2..7507b535 100644 --- a/maps/mountain_fortress_v3/mystical_chest.lua +++ b/maps/mountain_fortress_v3/mystical_chest.lua @@ -157,7 +157,6 @@ local item_worths = { ['explosive-uranium-cannon-shell'] = 64, ['rocket'] = 8, ['explosive-rocket'] = 8, - ['atomic-bomb'] = 16384, ['flamethrower-ammo'] = 32, ['grenade'] = 16, ['cluster-grenade'] = 64, diff --git a/maps/mountain_fortress_v3/resource_generator.lua b/maps/mountain_fortress_v3/resource_generator.lua index aead9ed7..dc6fad48 100644 --- a/maps/mountain_fortress_v3/resource_generator.lua +++ b/maps/mountain_fortress_v3/resource_generator.lua @@ -8,11 +8,24 @@ local types = { 'furnace' } +local testing = false + +local testing_loot = { + { + stack = { + recipe = 'speed-module-2', + tech = 'speed-module-2', + output = {item = 'speed-module-2', min_rate = 1 / 8 / 60 / 2, distance_factor = 1 / 8 / 60 / 20480} + }, + weight = 4 + } +} + local science_loot = { { stack = { recipe = 'automation-science-pack', - output = {item = 'automation-science-pack', min_rate = 0.5 / 8 / 60, distance_factor = 1 / 5 / 60 / 512} + output = {item = 'automation-science-pack', min_rate = 3 / 800, distance_factor = 1 / 8 / 60 / 20480} }, weight = 4 }, @@ -20,7 +33,7 @@ local science_loot = { stack = { recipe = 'logistic-science-pack', tech = 'logistic-science-pack', - output = {item = 'logistic-science-pack', min_rate = 0.5 / 8 / 60, distance_factor = 1 / 15 / 60 / 512} + output = {item = 'logistic-science-pack', min_rate = 2 / 800, distance_factor = 1 / 8 / 60 / 20480} }, weight = 2 } @@ -31,21 +44,21 @@ local ammo_loot = { stack = { recipe = 'piercing-rounds-magazine', tech = 'military-2', - output = {item = 'piercing-rounds-magazine', min_rate = 1 / 2 / 60, distance_factor = 1 / 10 / 60 / 512} + output = {item = 'piercing-rounds-magazine', min_rate = 1 / 800, distance_factor = 1 / 8 / 60 / 20480} }, weight = 1 }, { stack = { recipe = 'firearm-magazine', - output = {item = 'firearm-magazine', min_rate = 1 / 2 / 60, distance_factor = 1 / 4 / 60 / 512} + output = {item = 'firearm-magazine', min_rate = 2 / 800, distance_factor = 1 / 8 / 60 / 20480} }, weight = 4 }, { stack = { recipe = 'shotgun-shell', - output = {item = 'shotgun-shell', min_rate = 1 / 2 / 60, distance_factor = 1 / 8 / 60 / 512} + output = {item = 'shotgun-shell', min_rate = 2 / 800, distance_factor = 1 / 8 / 60 / 20480} }, weight = 4 }, @@ -53,7 +66,7 @@ local ammo_loot = { stack = { recipe = 'uranium-rounds-magazine', tech = 'uranium-ammo', - output = {item = 'uranium-rounds-magazine', min_rate = 0.1 / 8 / 60, distance_factor = 1 / 25 / 60 / 512} + output = {item = 'uranium-rounds-magazine', min_rate = 2 / 1800, distance_factor = 1 / 8 / 60 / 20480} }, weight = 0.25 } @@ -66,7 +79,7 @@ local oil_loot = { tech = 'oil-processing', output = { min_rate = 1 / 60, - distance_factor = 1 / 10 / 60 / 512, + distance_factor = 1 / 8 / 60 / 20480, item = 'petroleum-gas', fluidbox_index = 2 } @@ -78,9 +91,9 @@ local oil_loot = { recipe = 'advanced-oil-processing', tech = 'advanced-oil-processing', output = { - {min_rate = 0.7 / 60, distance_factor = 3.125 / 60 / 512, item = 'heavy-oil', fluidbox_index = 3}, - {min_rate = 0.82 / 60, distance_factor = 5.625 / 60 / 512, item = 'light-oil', fluidbox_index = 4}, - {min_rate = 0.83 / 60, distance_factor = 6.875 / 60 / 512, item = 'petroleum-gas', fluidbox_index = 5} + {min_rate = 0.7 / 60, distance_factor = 1 / 8 / 60 / 20480, item = 'heavy-oil', fluidbox_index = 3}, + {min_rate = 0.82 / 60, distance_factor = 1 / 8 / 60 / 20480, item = 'light-oil', fluidbox_index = 4}, + {min_rate = 0.83 / 60, distance_factor = 1 / 8 / 60 / 20480, item = 'petroleum-gas', fluidbox_index = 5} } }, weight = 0.1 @@ -95,7 +108,7 @@ local oil_prod_loot = { output = { item = 'lubricant', min_rate = 0.7 / 60, - distance_factor = 1 / 10 / 60 / 512, + distance_factor = 1 / 8 / 60 / 20480, fluidbox_index = 2 } }, @@ -108,7 +121,7 @@ local oil_prod_loot = { output = { item = 'solid-fuel', min_rate = 0.7 / 60, - distance_factor = 1 / 4 / 60 / 512 + distance_factor = 1 / 8 / 60 / 20480 } }, weight = 4 @@ -120,7 +133,7 @@ local oil_prod_loot = { output = { item = 'sulfuric-acid', min_rate = 0.8 / 60, - distance_factor = 1 / 8 / 60 / 512, + distance_factor = 1 / 8 / 60 / 20480, fluidbox_index = 2 } }, @@ -133,7 +146,7 @@ local oil_prod_loot = { output = { item = 'battery', min_rate = 0.6 / 60, - distance_factor = 1 / 25 / 60 / 512 + distance_factor = 1 / 8 / 60 / 20480 } }, weight = 0.75 @@ -145,7 +158,7 @@ local oil_prod_loot = { output = { item = 'sulfur', min_rate = 0.8 / 60, - distance_factor = 1 / 25 / 60 / 512 + distance_factor = 1 / 8 / 60 / 20480 } }, weight = 0.55 @@ -157,7 +170,7 @@ local oil_prod_loot = { output = { item = 'plastic-bar', min_rate = 0.8 / 60, - distance_factor = 1 / 25 / 60 / 512 + distance_factor = 1 / 8 / 60 / 20480 } }, weight = 0.25 @@ -169,7 +182,7 @@ local oil_prod_loot = { output = { item = 'explosives', min_rate = 0.8 / 60, - distance_factor = 1 / 25 / 60 / 512 + distance_factor = 1 / 8 / 60 / 20480 } }, weight = 0.20 @@ -181,7 +194,7 @@ local resource_loot = { stack = { recipe = 'stone-wall', tech = 'stone-walls', - output = {item = 'stone-wall', min_rate = 0.6 / 60, distance_factor = 1 / 6 / 60 / 512} + output = {item = 'stone-wall', min_rate = 0.6 / 60, distance_factor = 1 / 8 / 60 / 20480} }, weight = 10 }, @@ -189,21 +202,21 @@ local resource_loot = { stack = { recipe = 'concrete', tech = 'concrete', - output = {item = 'concrete', min_rate = 1 / 4 / 60, distance_factor = 1 / 6 / 60 / 512} + output = {item = 'concrete', min_rate = 1 / 4 / 60, distance_factor = 1 / 8 / 60 / 20480} }, weight = 6 }, { stack = { recipe = 'iron-gear-wheel', - output = {item = 'iron-gear-wheel', min_rate = 0.6 / 60, distance_factor = 1 / 6 / 60 / 512} + output = {item = 'iron-gear-wheel', min_rate = 0.6 / 60, distance_factor = 1 / 8 / 60 / 20480} }, weight = 12 }, { stack = { recipe = 'inserter', - output = {item = 'inserter', min_rate = 0.6 / 60, distance_factor = 1 / 6 / 60 / 512} + output = {item = 'inserter', min_rate = 0.6 / 60, distance_factor = 1 / 8 / 60 / 20480} }, weight = 12 }, @@ -211,14 +224,14 @@ local resource_loot = { stack = { recipe = 'fast-inserter', tech = 'fast-inserter', - output = {item = 'fast-inserter', min_rate = 1 / 4 / 60, distance_factor = 1 / 6 / 60 / 512} + output = {item = 'fast-inserter', min_rate = 1 / 4 / 60, distance_factor = 1 / 8 / 60 / 20480} }, weight = 4 }, { stack = { recipe = 'electronic-circuit', - output = {item = 'electronic-circuit', min_rate = 1 / 4 / 60, distance_factor = 1 / 6 / 60 / 512} + output = {item = 'electronic-circuit', min_rate = 1 / 4 / 60, distance_factor = 1 / 8 / 60 / 20480} }, weight = 2 }, @@ -226,7 +239,7 @@ local resource_loot = { stack = { recipe = 'advanced-circuit', tech = 'advanced-electronics', - output = {item = 'advanced-circuit', min_rate = 1 / 4 / 60, distance_factor = 1 / 6 / 60 / 512} + output = {item = 'advanced-circuit', min_rate = 1 / 4 / 60, distance_factor = 1 / 8 / 60 / 20480} }, weight = 1 }, @@ -234,28 +247,28 @@ local resource_loot = { stack = { recipe = 'processing-unit', tech = 'advanced-electronics-2', - output = {item = 'processing-unit', min_rate = 1 / 10 / 60, distance_factor = 1 / 8 / 60 / 512} + output = {item = 'processing-unit', min_rate = 1 / 10 / 60, distance_factor = 1 / 8 / 60 / 20480} }, weight = 2 }, { stack = { recipe = 'transport-belt', - output = {item = 'transport-belt', min_rate = 0.6 / 60, distance_factor = 1 / 6 / 60 / 512} + output = {item = 'transport-belt', min_rate = 0.6 / 60, distance_factor = 1 / 8 / 60 / 20480} }, weight = 8 }, { stack = { recipe = 'underground-belt', - output = {item = 'underground-belt', min_rate = 1 / 4 / 60, distance_factor = 1 / 6 / 60 / 512} + output = {item = 'underground-belt', min_rate = 1 / 4 / 60, distance_factor = 1 / 8 / 60 / 20480} }, weight = 8 }, { stack = { recipe = 'small-electric-pole', - output = {item = 'small-electric-pole', min_rate = 1 / 4 / 60, distance_factor = 1 / 6 / 60 / 512} + output = {item = 'small-electric-pole', min_rate = 1 / 4 / 60, distance_factor = 1 / 8 / 60 / 20480} }, weight = 8 }, @@ -263,7 +276,7 @@ local resource_loot = { stack = { recipe = 'fast-transport-belt', tech = 'logistics-2', - output = {item = 'fast-transport-belt', min_rate = 1 / 4 / 60, distance_factor = 1 / 8 / 60 / 512} + output = {item = 'fast-transport-belt', min_rate = 1 / 4 / 60, distance_factor = 1 / 8 / 60 / 20480} }, weight = 5 }, @@ -271,7 +284,7 @@ local resource_loot = { stack = { recipe = 'fast-underground-belt', tech = 'logistics-2', - output = {item = 'fast-underground-belt', min_rate = 1 / 4 / 60, distance_factor = 1 / 8 / 60 / 512} + output = {item = 'fast-underground-belt', min_rate = 1 / 4 / 60, distance_factor = 1 / 8 / 60 / 20480} }, weight = 5 }, @@ -279,7 +292,7 @@ local resource_loot = { stack = { recipe = 'solar-panel', tech = 'solar-energy', - output = {item = 'solar-panel', min_rate = 1 / 6 / 60, distance_factor = 1 / 8 / 60 / 512} + output = {item = 'solar-panel', min_rate = 1 / 15 / 60, distance_factor = 1 / 8 / 60 / 20480} }, weight = 3 }, @@ -287,7 +300,7 @@ local resource_loot = { stack = { recipe = 'productivity-module', tech = 'productivity-module', - output = {item = 'productivity-module', min_rate = 1 / 6 / 60, distance_factor = 1 / 8 / 60 / 512} + output = {item = 'productivity-module', min_rate = 1 / 10 / 60, distance_factor = 1 / 8 / 60 / 20480} }, weight = 0.9 }, @@ -295,7 +308,7 @@ local resource_loot = { stack = { recipe = 'effectivity-module', tech = 'effectivity-module', - output = {item = 'effectivity-module', min_rate = 1 / 6 / 60, distance_factor = 1 / 8 / 60 / 512} + output = {item = 'effectivity-module', min_rate = 1 / 10 / 60, distance_factor = 1 / 8 / 60 / 20480} }, weight = 0.9 }, @@ -303,7 +316,7 @@ local resource_loot = { stack = { recipe = 'speed-module', tech = 'speed-module', - output = {item = 'speed-module', min_rate = 1 / 6 / 60, distance_factor = 1 / 8 / 60 / 512} + output = {item = 'speed-module', min_rate = 1 / 10 / 60, distance_factor = 1 / 8 / 60 / 20480} }, weight = 0.8 }, @@ -311,7 +324,7 @@ local resource_loot = { stack = { recipe = 'productivity-module-2', tech = 'productivity-module-2', - output = {item = 'productivity-module-2', min_rate = 1 / 8 / 60, distance_factor = 1 / 8 / 60 / 512} + output = {item = 'productivity-module-2', min_rate = 1 / 15 / 60, distance_factor = 1 / 8 / 60 / 20480} }, weight = 0.5 }, @@ -319,7 +332,7 @@ local resource_loot = { stack = { recipe = 'effectivity-module-2', tech = 'effectivity-module-2', - output = {item = 'effectivity-module-2', min_rate = 1 / 8 / 60, distance_factor = 1 / 8 / 60 / 512} + output = {item = 'effectivity-module-2', min_rate = 1 / 15 / 60, distance_factor = 1 / 8 / 60 / 20480} }, weight = 0.5 }, @@ -327,7 +340,7 @@ local resource_loot = { stack = { recipe = 'speed-module-2', tech = 'speed-module-2', - output = {item = 'speed-module-2', min_rate = 1 / 8 / 60, distance_factor = 1 / 8 / 60 / 512} + output = {item = 'speed-module-2', min_rate = 1 / 15 / 60, distance_factor = 1 / 8 / 60 / 20480} }, weight = 0.5 }, @@ -335,7 +348,7 @@ local resource_loot = { stack = { recipe = 'productivity-module-3', tech = 'productivity-module-3', - output = {item = 'productivity-module-3', min_rate = 1 / 10 / 60, distance_factor = 1 / 8 / 60 / 512} + output = {item = 'productivity-module-3', min_rate = 1 / 20 / 60, distance_factor = 1 / 8 / 60 / 20480} }, weight = 0.25 }, @@ -343,7 +356,7 @@ local resource_loot = { stack = { recipe = 'effectivity-module-3', tech = 'effectivity-module-3', - output = {item = 'effectivity-module-3', min_rate = 1 / 10 / 60, distance_factor = 1 / 8 / 60 / 512} + output = {item = 'effectivity-module-3', min_rate = 1 / 20 / 60, distance_factor = 1 / 8 / 60 / 20480} }, weight = 0.25 }, @@ -351,7 +364,7 @@ local resource_loot = { stack = { recipe = 'speed-module-3', tech = 'speed-module-3', - output = {item = 'speed-module-3', min_rate = 1 / 10 / 60, distance_factor = 1 / 8 / 60 / 512} + output = {item = 'speed-module-3', min_rate = 1 / 20 / 60, distance_factor = 1 / 8 / 60 / 20480} }, weight = 0.10 } @@ -361,14 +374,14 @@ local furnace_loot = { { stack = { furance_item = 'iron-plate', - output = {item = 'iron-plate', min_rate = 2.0 / 60, distance_factor = 1 / 6 / 60 / 512} + output = {item = 'iron-plate', min_rate = 2.0 / 60, distance_factor = 1 / 8 / 60 / 20480} }, weight = 4 }, { stack = { furance_item = 'copper-plate', - output = {item = 'copper-plate', min_rate = 2.0 / 60, distance_factor = 1 / 6 / 60 / 512} + output = {item = 'copper-plate', min_rate = 2.0 / 60, distance_factor = 1 / 8 / 60 / 20480} }, weight = 4 }, @@ -376,12 +389,13 @@ local furnace_loot = { stack = { furance_item = 'steel-plate', tech = 'steel-processing', - output = {item = 'steel-plate', min_rate = 1.0 / 60, distance_factor = 1 / 8 / 60 / 512} + output = {item = 'steel-plate', min_rate = 1.0 / 60, distance_factor = 1 / 8 / 60 / 20480} }, weight = 1 } } +local testing_weights = Functions.prepare_weighted_loot(testing_loot) local science_weights = Functions.prepare_weighted_loot(science_loot) local building_weights = Functions.prepare_weighted_loot(ammo_loot) local oil_weights = Functions.prepare_weighted_loot(oil_loot) @@ -389,6 +403,15 @@ local oil_prod_weights = Functions.prepare_weighted_loot(oil_prod_loot) local resource_weights = Functions.prepare_weighted_loot(resource_loot) local furnace_weights = Functions.prepare_weighted_loot(furnace_loot) +local testing_callback = { + callback = Functions.magic_item_crafting_callback_weighted, + data = { + loot = testing_loot, + weights = testing_weights, + testing = true + } +} + local science_callback = { callback = Functions.magic_item_crafting_callback_weighted, data = { @@ -437,6 +460,12 @@ local furnace_callback = { } } +local testing_list = { + [1] = {name = 'assembling-machine-1', callback = testing_callback}, + [2] = {name = 'assembling-machine-2', callback = testing_callback}, + [3] = {name = 'assembling-machine-3', callback = testing_callback} +} + local science_list = { [1] = {name = 'assembling-machine-1', callback = science_callback}, [2] = {name = 'assembling-machine-2', callback = science_callback}, @@ -469,6 +498,19 @@ local furnace_list = { [3] = {name = 'electric-furnace', callback = furnace_callback} } +local function spawn_testing_buildings(entities, p, probability) + local callback = testing_list[probability].callback + + entities[#entities + 1] = { + name = testing_list[probability].name, + position = p, + force = 'neutral', + callback = callback, + collision = true, + e_type = types + } +end + local function spawn_science_buildings(entities, p, probability) local callback = science_list[probability].callback @@ -556,6 +598,12 @@ local buildings = { [6] = spawn_oil_prod_buildings } +if testing then + buildings = { + [1] = spawn_testing_buildings + } +end + local function spawn_random_buildings(entities, p, depth) local randomizer = random(1, #buildings) local low = random(1, 2) diff --git a/maps/mountain_fortress_v3/terrain.lua b/maps/mountain_fortress_v3/terrain.lua index 1e953e12..b5390c38 100644 --- a/maps/mountain_fortress_v3/terrain.lua +++ b/maps/mountain_fortress_v3/terrain.lua @@ -315,14 +315,8 @@ local function wall(p, data) if not alert_zone_1 then local x_min = -WPT.level_width / 2 local x_max = WPT.level_width / 2 - WPT.set( - 'zone1_beam1', - surface.create_entity({name = 'electric-beam', position = {x_min, p.y}, source = {x_min, p.y}, target = {x_max, p.y}}) - ) - WPT.set( - 'zone1_beam2', - surface.create_entity({name = 'electric-beam', position = {x_min, p.y}, source = {x_min, p.y}, target = {x_max, p.y}}) - ) + WPT.set('zone1_beam1', surface.create_entity({name = 'electric-beam', position = {x_min, p.y}, source = {x_min, p.y}, target = {x_max, p.y}})) + WPT.set('zone1_beam2', surface.create_entity({name = 'electric-beam', position = {x_min, p.y}, source = {x_min, p.y}, target = {x_max, p.y}})) WPT.set('alert_zone_1', true) WPT.set( 'zone1_text1', @@ -2574,9 +2568,7 @@ Event.add( local locomotive = WPT.get('locomotive') if locomotive and locomotive.valid then local position = locomotive.position - for _, entity in pairs( - surface.find_entities_filtered({area = {{position.x - 5, position.y - 6}, {position.x + 5, position.y + 10}}, type = 'simple-entity'}) - ) do + for _, entity in pairs(surface.find_entities_filtered({area = {{position.x - 5, position.y - 6}, {position.x + 5, position.y + 10}}, type = 'simple-entity'})) do entity.destroy() end end From 95f2e90e55a3406a63614ae94d4a99fd8089f4f8 Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Tue, 5 Apr 2022 19:28:08 +0200 Subject: [PATCH 3/5] refactor more gui --- .luacheckrc | 5 +- comfy_panel/main.lua | 285 ---------- control.lua | 16 +- maps/biter_battles/biter_battles.lua | 37 +- maps/biter_battles_v2/game_over.lua | 2 +- maps/biter_battles_v2/init.lua | 2 +- maps/biter_battles_v2/sciencelogs_tab.lua | 43 +- maps/biter_hatchery/main.lua | 6 +- maps/chronosphere/chrono.lua | 137 ++--- maps/chronosphere/config_tab.lua | 18 +- maps/crab_defender/main.lua | 4 +- maps/fish_defender/main.lua | 4 +- maps/fish_defender_v1/fish_defender.lua | 2 +- maps/fish_defender_v2/main.lua | 4 +- maps/junkyard_pvp/main.lua | 10 +- maps/labyrinth.lua | 20 +- maps/minesweeper/main.lua | 2 +- maps/mountain_fortress_v2/main.lua | 6 +- maps/mountain_fortress_v3/entities.lua | 5 +- maps/mountain_fortress_v3/functions.lua | 8 +- maps/mountain_fortress_v3/gui.lua | 10 +- maps/mountain_fortress_v3/highscore.lua | 32 +- maps/mountain_fortress_v3/ic/gui.lua | 9 +- .../locomotive/market.lua | 40 +- maps/mountain_fortress_v3/main.lua | 10 +- maps/mountain_race/main.lua | 2 +- maps/native_war/main.lua | 12 +- maps/pidgeotto/main.lua | 4 +- maps/planet_prison.lua | 10 +- maps/scrap_towny_ffa/main.lua | 44 +- modules/autostash.lua | 4 +- modules/difficulty_vote_by_amount.lua | 243 +++++---- modules/map_info.lua | 65 +-- modules/rewards.lua | 10 +- modules/rpg.lua | 4 +- modules/rpg/gui.lua | 90 ++-- modules/rpg/main.lua | 3 - modules/rpg/table.lua | 2 + utils/datastore/current_time_data.lua | 4 +- utils/datastore/server_ups_data.lua | 4 +- utils/files/arrow-down.png | Bin 0 -> 364 bytes utils/files/arrow-up.png | Bin 0 -> 373 bytes utils/files/infinity.png | Bin 0 -> 524 bytes utils/files/pin-black.png | Bin 0 -> 741 bytes utils/files/pin-white.png | Bin 0 -> 780 bytes utils/files/settings-black.png | Bin 0 -> 1237 bytes utils/files/settings-white.png | Bin 0 -> 1183 bytes utils/freeplay.lua | 2 +- utils/gui.lua | 505 ++++++++++++++++-- {comfy_panel => utils/gui}/admin.lua | 51 +- {comfy_panel => utils/gui}/bottom_frame.lua | 3 +- {comfy_panel => utils/gui}/config.lua | 212 ++------ {comfy_panel => utils/gui}/group.lua | 29 +- {comfy_panel => utils/gui}/map_score.lua | 18 +- {comfy_panel => utils/gui}/player_list.lua | 29 +- {comfy_panel => utils/gui}/poll.lua | 41 +- {comfy_panel => utils/gui}/score.lua | 32 +- {comfy_panel => utils/gui}/server_select.lua | 37 +- 58 files changed, 1083 insertions(+), 1094 deletions(-) delete mode 100644 comfy_panel/main.lua create mode 100644 utils/files/arrow-down.png create mode 100644 utils/files/arrow-up.png create mode 100644 utils/files/infinity.png create mode 100644 utils/files/pin-black.png create mode 100644 utils/files/pin-white.png create mode 100644 utils/files/settings-black.png create mode 100644 utils/files/settings-white.png rename {comfy_panel => utils/gui}/admin.lua (95%) rename {comfy_panel => utils/gui}/bottom_frame.lua (98%) rename {comfy_panel => utils/gui}/config.lua (78%) rename {comfy_panel => utils/gui}/group.lua (95%) rename {comfy_panel => utils/gui}/map_score.lua (89%) rename {comfy_panel => utils/gui}/player_list.lua (98%) rename {comfy_panel => utils/gui}/poll.lua (97%) rename {comfy_panel => utils/gui}/score.lua (95%) rename {comfy_panel => utils/gui}/server_select.lua (87%) diff --git a/.luacheckrc b/.luacheckrc index aa27f117..9a6c68c0 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -61,8 +61,7 @@ globals = { 'is_loaded', 'is_game_modded', 'is_mod_loaded', - 'require', - 'comfy_panel_tabs' + 'require' } max_line_length = LINE_LENGTH @@ -2010,7 +2009,7 @@ stds.factorio_defines = { } } } - --)) +--)) --[[ Options "ignore", "std", "globals", "unused_args", "self", "compat", "global", "unused", "redefined", diff --git a/comfy_panel/main.lua b/comfy_panel/main.lua deleted file mode 100644 index ceb04627..00000000 --- a/comfy_panel/main.lua +++ /dev/null @@ -1,285 +0,0 @@ ---[[ -Comfy Panel - -To add a tab, insert into the "main_gui_tabs" table. - -Example: main_gui_tabs["mapscores"] = {gui = draw_map_scores, admin = false} -if admin = true, then tab is visible only for admins (usable for map-specific settings) - -draw_map_scores would be a function with the player and the frame as arguments - -]] -local Event = require 'utils.event' -local Server = require 'utils.server' -local SpamProtection = require 'utils.spam_protection' -local Token = require 'utils.token' -local Global = require 'utils.global' -local Gui = require 'utils.gui' - -local main_gui_tabs = {} -local Public = {} -local screen_elements = {} -local this = { - settings = { - mod_gui_top_frame = false - } -} - -Global.register( - this, - function(tbl) - this = tbl - end -) - ---- This adds the given gui to the top gui. ----@param player ----@param frame ----@param name -function Public.add_mod_button(player, frame) - if Gui.get_button_flow(player)[frame.name] and Gui.get_button_flow(player)[frame.name].valid then - return - end - - Gui.get_button_flow(player).add(frame) -end - ----@param state ---- If we should use the new mod gui or not -function Public.set_mod_gui_top_frame(state) - this.settings.mod_gui_top_frame = state or false -end - ---- Get mod_gui_top_frame -function Public.get_mod_gui_top_frame() - return this.settings.mod_gui_top_frame -end - ---- This adds the given gui to the main gui. ----@param tbl -function Public.add_tab_to_gui(tbl) - if not tbl then - return - end - if not tbl.name then - return - end - if not tbl.id then - return - end - local admin = tbl.admin or false - local only_server_sided = tbl.only_server_sided or false - - if not main_gui_tabs[tbl.name] then - main_gui_tabs[tbl.name] = {id = tbl.id, admin = admin, only_server_sided = only_server_sided} - else - error('Given name: ' .. tbl.name .. ' already exists in table.') - end -end - -function Public.screen_to_bypass(elem) - screen_elements[elem] = true - return screen_elements -end - ---- Fetches the main gui tabs. You are forbidden to write as this is local. ----@param key -function Public.get(key) - if key then - return main_gui_tabs[key] - else - return main_gui_tabs - end -end - -function Public.comfy_panel_clear_gui(player) - for _, child in pairs(player.gui.left.children) do - child.destroy() - end - for _, child in pairs(player.gui.screen.children) do - if not screen_elements[child.name] then - child.destroy() - end - end -end - -function Public.comfy_panel_get_active_frame(player) - local main_frame = player.gui.left.comfy_panel - if not main_frame then - return false - end - - local panel = main_frame.tabbed_pane - if not panel then - return - end - local index = panel.selected_tab_index - if not index then - return panel.tabs[1].content - end - return panel.tabs[index].content -end - -function Public.comfy_panel_refresh_active_tab(player) - local frame = Public.comfy_panel_get_active_frame(player) - if not frame then - return - end - - local tab = main_gui_tabs[frame.name] - if not tab then - return - end - local id = tab.id - if not id then - return - end - local func = Token.get(id) - - local data = { - player = player, - frame = frame - } - - return func(data) -end - -local function top_button(player) - if this.settings.mod_gui_top_frame then - Public.add_mod_button(player, {type = 'sprite-button', name = 'comfy_panel_top_button', sprite = 'item/raw-fish'}, 'comfy_panel_top_button') - else - if player.gui.top['comfy_panel_top_button'] then - return - end - local button = player.gui.top.add({type = 'sprite-button', name = 'comfy_panel_top_button', sprite = 'item/raw-fish'}) - button.style.minimal_height = 38 - button.style.maximal_height = 38 - button.style.minimal_width = 40 - button.style.padding = -2 - end -end - -local function main_frame(player) - local tabs = main_gui_tabs - Public.comfy_panel_clear_gui(player) - - local frame = player.gui.left.comfy_panel - if not frame or not frame.valid then - frame = player.gui.left.add({type = 'frame', name = 'comfy_panel'}) - end - - frame.style.margin = 6 - - local tabbed_pane = frame.add({type = 'tabbed-pane', name = 'tabbed_pane'}) - - for name, func in pairs(tabs) do - if func.only_server_sided then - local secs = Server.get_current_time() - if secs then - local tab = tabbed_pane.add({type = 'tab', caption = name, name = 'tab_' .. name}) - local name_frame = tabbed_pane.add({type = 'frame', name = name, direction = 'vertical'}) - name_frame.style.minimal_height = 480 - name_frame.style.maximal_height = 480 - name_frame.style.minimal_width = 800 - name_frame.style.maximal_width = 800 - tabbed_pane.add_tab(tab, name_frame) - end - elseif func.admin == true then - if player.admin then - local tab = tabbed_pane.add({type = 'tab', caption = name, name = 'tab_' .. name}) - local name_frame = tabbed_pane.add({type = 'frame', name = name, direction = 'vertical'}) - name_frame.style.minimal_height = 480 - name_frame.style.maximal_height = 480 - name_frame.style.minimal_width = 800 - name_frame.style.maximal_width = 800 - tabbed_pane.add_tab(tab, name_frame) - end - else - local tab = tabbed_pane.add({type = 'tab', caption = name, name = 'tab_' .. name}) - local name_frame = tabbed_pane.add({type = 'frame', name = name, direction = 'vertical'}) - name_frame.style.minimal_height = 480 - name_frame.style.maximal_height = 480 - name_frame.style.minimal_width = 800 - name_frame.style.maximal_width = 800 - tabbed_pane.add_tab(tab, name_frame) - end - end - - local tab = tabbed_pane.add({type = 'tab', name = 'comfy_panel_close', caption = 'X'}) - tab.style.maximal_width = 32 - local t_frame = tabbed_pane.add({type = 'frame', direction = 'vertical'}) - tabbed_pane.add_tab(tab, t_frame) - - for _, child in pairs(tabbed_pane.children) do - child.style.padding = 8 - child.style.left_padding = 2 - child.style.right_padding = 2 - end - - Public.comfy_panel_refresh_active_tab(player) -end - -function Public.comfy_panel_call_tab(player, name) - main_frame(player) - local tabbed_pane = player.gui.left.comfy_panel.tabbed_pane - for key, v in pairs(tabbed_pane.tabs) do - if v.tab.caption == name then - tabbed_pane.selected_tab_index = key - Public.comfy_panel_refresh_active_tab(player) - end - end -end - -local function on_player_joined_game(event) - local player = game.get_player(event.player_index) - top_button(player) -end - -local function on_gui_click(event) - local element = event.element - if not element or not element.valid then - return - end - - local player = game.get_player(event.player_index) - - local name = element.name - - if name == 'comfy_panel_top_button' then - local is_spamming = SpamProtection.is_spamming(player, nil, 'Comfy Main GUI Click') - if is_spamming then - return - end - if player.gui.left.comfy_panel then - player.gui.left.comfy_panel.destroy() - return - else - main_frame(player) - return - end - end - - if element.caption == 'X' and name == 'comfy_panel_close' then - local is_spamming = SpamProtection.is_spamming(player, nil, 'Comfy Main Gui Close Button') - if is_spamming then - return - end - player.gui.left.comfy_panel.destroy() - return - end - - if not element.caption then - return - end - if element.type ~= 'tab' then - return - end - - Public.comfy_panel_refresh_active_tab(player) -end - -Event.add(defines.events.on_player_joined_game, on_player_joined_game) -Event.add(defines.events.on_player_created, on_player_joined_game) -Event.add(defines.events.on_gui_click, on_gui_click) - -return Public diff --git a/control.lua b/control.lua index bfa1f3f2..49b016e5 100644 --- a/control.lua +++ b/control.lua @@ -28,14 +28,14 @@ require 'modules.show_inventory' require 'modules.inserter_drops_pickup' require 'modules.autostash' -require 'comfy_panel.main' -require 'comfy_panel.player_list' -require 'comfy_panel.admin' -require 'comfy_panel.group' -require 'comfy_panel.poll' -require 'comfy_panel.score' -require 'comfy_panel.config' -require 'comfy_panel.server_select' +require 'utils.gui' +require 'utils.gui.player_list' +require 'utils.gui.admin' +require 'utils.gui.group' +require 'utils.gui.poll' +require 'utils.gui.score' +require 'utils.gui.config' +require 'utils.gui.server_select' require 'utils.freeplay' ---------------- !ENABLE MODULES HERE ---------------- diff --git a/maps/biter_battles/biter_battles.lua b/maps/biter_battles/biter_battles.lua index 886911b6..64695cec 100644 --- a/maps/biter_battles/biter_battles.lua +++ b/maps/biter_battles/biter_battles.lua @@ -1,7 +1,7 @@ -- Biter Battles -- mewmew made this -- --luacheck:ignore local Server = require 'utils.server' -local Score = require 'comfy_panel.score' +local Score = require 'utils.gui.score' local Global = require 'utils.global' require 'modules.splice_double' require 'modules.explosive_biters' @@ -525,15 +525,9 @@ end local function reveal_team(f) local m = 32 if f == 'north' then - game.forces['south'].chart( - game.surfaces['surface'], - {{x = global.force_area[f].x_top - m, y = global.force_area[f].y_top - m}, {x = global.force_area[f].x_bot + m, y = global.force_area[f].y_bot + m}} - ) + game.forces['south'].chart(game.surfaces['surface'], {{x = global.force_area[f].x_top - m, y = global.force_area[f].y_top - m}, {x = global.force_area[f].x_bot + m, y = global.force_area[f].y_bot + m}}) else - game.forces['north'].chart( - game.surfaces['surface'], - {{x = global.force_area[f].x_top - m, y = global.force_area[f].y_top - m}, {x = global.force_area[f].x_bot + m, y = global.force_area[f].y_bot + m}} - ) + game.forces['north'].chart(game.surfaces['surface'], {{x = global.force_area[f].x_top - m, y = global.force_area[f].y_top - m}, {x = global.force_area[f].x_bot + m, y = global.force_area[f].y_bot + m}}) end end @@ -851,10 +845,7 @@ local function on_gui_click(event) join_team(player, global.team_chosen[player.name]) end if (name == 'biter_battle_leave_spectate') and game.tick - global.spectator_spam_protection[player.name] < 1800 then - player.print( - 'Not ready to return to your team yet. Please wait ' .. 30 - (math.round((game.tick - global.spectator_spam_protection[player.name]) / 60, 0)) .. ' seconds.', - {r = 0.98, g = 0.66, b = 0.22} - ) + player.print('Not ready to return to your team yet. Please wait ' .. 30 - (math.round((game.tick - global.spectator_spam_protection[player.name]) / 60, 0)) .. ' seconds.', {r = 0.98, g = 0.66, b = 0.22}) end if (name == 'biter_battle_hide_players') then @@ -1053,15 +1044,11 @@ local function biter_attack_silo(team, requested_amount, mode) if math_random(1, 6) == 1 then for _, biter in pairs(biters_selected_for_attack) do - biter.set_command( - {type = defines.command.attack_area, destination = global.biter_attack_main_target[team], radius = 12, distraction = defines.distraction.by_anything} - ) + biter.set_command({type = defines.command.attack_area, destination = global.biter_attack_main_target[team], radius = 12, distraction = defines.distraction.by_anything}) end else for _, biter in pairs(biters_selected_for_attack) do - biter.set_command( - {type = defines.command.attack_area, destination = global.biter_attack_main_target[team], radius = 12, distraction = defines.distraction.by_enemy} - ) + biter.set_command({type = defines.command.attack_area, destination = global.biter_attack_main_target[team], radius = 12, distraction = defines.distraction.by_enemy}) end end if global.biter_battles_debug then @@ -1279,15 +1266,11 @@ local function biter_attack_silo(team, requested_amount, mode) if t > 8 then if math_random(1, 6) ~= 1 then for _, biter in pairs(biters_selected_for_attack) do - biter.set_command( - {type = defines.command.attack_area, destination = global.biter_attack_main_target[team], radius = 12, distraction = defines.distraction.by_enemy} - ) + biter.set_command({type = defines.command.attack_area, destination = global.biter_attack_main_target[team], radius = 12, distraction = defines.distraction.by_enemy}) end else for _, biter in pairs(biters_selected_for_attack) do - biter.set_command( - {type = defines.command.attack_area, destination = global.biter_attack_main_target[team], radius = 12, distraction = defines.distraction.by_anything} - ) + biter.set_command({type = defines.command.attack_area, destination = global.biter_attack_main_target[team], radius = 12, distraction = defines.distraction.by_anything}) end end if global.biter_battles_debug then @@ -1298,9 +1281,7 @@ local function biter_attack_silo(team, requested_amount, mode) for _, biter in pairs(biters_selected_for_attack) do biter_attack_group.add_member(biter) end - biter_attack_group.set_command( - {type = defines.command.attack_area, destination = global.biter_attack_main_target[team], radius = 12, distraction = defines.distraction.by_enemy} - ) + biter_attack_group.set_command({type = defines.command.attack_area, destination = global.biter_attack_main_target[team], radius = 12, distraction = defines.distraction.by_enemy}) if global.biter_battles_debug then game.players[1].print(#valid_biters .. ' valid biters found.') game.players[1].print(#biters_selected_for_attack .. ' gathering at (x: ' .. gathering_point_x .. ' y: ' .. gathering_point_y .. ')') diff --git a/maps/biter_battles_v2/game_over.lua b/maps/biter_battles_v2/game_over.lua index 63efd7d1..87adffda 100644 --- a/maps/biter_battles_v2/game_over.lua +++ b/maps/biter_battles_v2/game_over.lua @@ -2,7 +2,7 @@ local Functions = require 'maps.biter_battles_v2.functions' local Gui = require 'maps.biter_battles_v2.gui' local Init = require 'maps.biter_battles_v2.init' -local Score = require 'comfy_panel.score' +local Score = require 'utils.gui.score' local Server = require 'utils.server' local Discord = require 'utils.discord' diff --git a/maps/biter_battles_v2/init.lua b/maps/biter_battles_v2/init.lua index b1ce087a..2c52586d 100644 --- a/maps/biter_battles_v2/init.lua +++ b/maps/biter_battles_v2/init.lua @@ -1,7 +1,7 @@ --luacheck:ignore local Terrain = require 'maps.biter_battles_v2.terrain' local Force_health_booster = require 'modules.force_health_booster' -local Score = require 'comfy_panel.score' +local Score = require 'utils.gui.score' local Public = {} diff --git a/maps/biter_battles_v2/sciencelogs_tab.lua b/maps/biter_battles_v2/sciencelogs_tab.lua index cbee5b8e..d6dafd20 100644 --- a/maps/biter_battles_v2/sciencelogs_tab.lua +++ b/maps/biter_battles_v2/sciencelogs_tab.lua @@ -1,7 +1,7 @@ --luacheck: ignore -- science logs tab -- -local Tabs = require 'comfy_panel.main' +local Tabs = require 'utils.gui' local tables = require 'maps.biter_battles_v2.tables' local event = require 'utils.event' local bb_config = require 'maps.biter_battles_v2.config' @@ -13,8 +13,7 @@ local science_list = tables.science_list local evofilter_list = tables.evofilter_list local food_value_table_version = tables.food_value_table_version local Token = require 'utils.token' - -local module_name = 'MutagenLog' +local module_name = Tabs.uid_name() local function initialize_dropdown_users_choice() global.dropdown_users_choice_force = {} @@ -27,8 +26,7 @@ local function get_science_text(food_name, food_short_name) end local function add_science_logs(player, element) - local science_scrollpanel = - element.add {type = 'scroll-pane', name = 'scroll_pane', direction = 'vertical', horizontal_scroll_policy = 'never', vertical_scroll_policy = 'auto'} + local science_scrollpanel = element.add {type = 'scroll-pane', name = 'scroll_pane', direction = 'vertical', horizontal_scroll_policy = 'never', vertical_scroll_policy = 'auto'} science_scrollpanel.style.maximal_height = 530 if global.science_logs_category_potion == nil then @@ -129,8 +127,7 @@ local function add_science_logs(player, element) local dropdown_force = t_filter.add {name = 'dropdown-force', type = 'drop-down', items = forces_list, selected_index = global.dropdown_users_choice_force[player.name]} local dropdown_science = t_filter.add {name = 'dropdown-science', type = 'drop-down', items = science_list, selected_index = global.dropdown_users_choice_science[player.name]} - local dropdown_evofilter = - t_filter.add {name = 'dropdown-evofilter', type = 'drop-down', items = evofilter_list, selected_index = global.dropdown_users_choice_evo_filter[player.name]} + local dropdown_evofilter = t_filter.add {name = 'dropdown-evofilter', type = 'drop-down', items = evofilter_list, selected_index = global.dropdown_users_choice_evo_filter[player.name]} local t = science_scrollpanel.add {type = 'table', name = 'science_logs_header_table', column_count = 4} local column_widths = {tonumber(75), tonumber(310), tonumber(165), tonumber(230)} @@ -171,13 +168,9 @@ local function add_science_logs(player, element) if dropdown_force.selected_index == 1 or real_force_name:match(dropdown_force.get_item(dropdown_force.selected_index)) then if - dropdown_science.selected_index == 1 or - (dropdown_science.selected_index == 2 and (easy_food_name:match('space') or easy_food_name:match('utility') or easy_food_name:match('production'))) or - (dropdown_science.selected_index == 3 and - (easy_food_name:match('space') or easy_food_name:match('utility') or easy_food_name:match('production') or easy_food_name:match('chemical'))) or - (dropdown_science.selected_index == 4 and - (easy_food_name:match('space') or easy_food_name:match('utility') or easy_food_name:match('production') or easy_food_name:match('chemical') or - easy_food_name:match('military'))) or + dropdown_science.selected_index == 1 or (dropdown_science.selected_index == 2 and (easy_food_name:match('space') or easy_food_name:match('utility') or easy_food_name:match('production'))) or + (dropdown_science.selected_index == 3 and (easy_food_name:match('space') or easy_food_name:match('utility') or easy_food_name:match('production') or easy_food_name:match('chemical'))) or + (dropdown_science.selected_index == 4 and (easy_food_name:match('space') or easy_food_name:match('utility') or easy_food_name:match('production') or easy_food_name:match('chemical') or easy_food_name:match('military'))) or easy_food_name:match(dropdown_science.get_item(dropdown_science.selected_index)) then if @@ -221,19 +214,9 @@ local function add_science_logs(player, element) end end -local function comfy_panel_get_active_frame(player) - if not player.gui.left.comfy_panel then - return false - end - if not player.gui.left.comfy_panel.tabbed_pane.selected_tab_index then - return player.gui.left.comfy_panel.tabbed_pane.tabs[1].content - end - return player.gui.left.comfy_panel.tabbed_pane.tabs[player.gui.left.comfy_panel.tabbed_pane.selected_tab_index].content -end - local function build_config_gui(data) local player = data.player - local frame_sciencelogs = comfy_panel_get_active_frame(player) + local frame_sciencelogs = Gui.get_player_active_frame(player) if not frame_sciencelogs then return end @@ -268,4 +251,12 @@ end event.add(defines.events.on_gui_selection_state_changed, on_gui_selection_state_changed) -Tabs.add_tab_to_gui({name = module_name, id = build_config_gui_token, admin = false}) +Tabs.add_tab_to_gui({name = module_name, caption = 'MutagenLog', id = build_config_gui_token, admin = false}) + +Tabs.on_click( + module_name, + function(event) + local player = event.player + Tabs.reload_active_tab(player) + end +) diff --git a/maps/biter_hatchery/main.lua b/maps/biter_hatchery/main.lua index 41b5c6d2..5732c1e4 100644 --- a/maps/biter_hatchery/main.lua +++ b/maps/biter_hatchery/main.lua @@ -1,8 +1,8 @@ --luacheck: ignore require 'modules.no_turrets' require 'modules.no_acid_puddles' -local Tabs = require 'comfy_panel.main' -local Map_score = require 'comfy_panel.map_score' +local Gui = require 'utils.gui' +local Map_score = require 'utils.gui.map_score' local unit_raffle = require 'maps.biter_hatchery.raffle_tables' local Terrain = require 'maps.biter_hatchery.terrain' local Gui = require 'maps.biter_hatchery.gui' @@ -310,7 +310,7 @@ local function on_entity_died(event) for _, child in pairs(player.gui.left.children) do child.destroy() end - Tabs.comfy_panel_call_tab(player, 'Map Scores') + Gui.call_existing_tab(player, 'Map Scores') end for _, e in pairs(entity.surface.find_entities_filtered({type = 'unit'})) do diff --git a/maps/chronosphere/chrono.lua b/maps/chronosphere/chrono.lua index e210b95c..d62b7ce0 100644 --- a/maps/chronosphere/chrono.lua +++ b/maps/chronosphere/chrono.lua @@ -1,6 +1,6 @@ local Chrono_table = require 'maps.chronosphere.table' local Balance = require 'maps.chronosphere.balance' -local Score = require 'comfy_panel.score' +local Score = require 'utils.gui.score' local Difficulty = require 'modules.difficulty_vote' local Upgrades = require 'maps.chronosphere.upgrade_list' local List = require 'maps.chronosphere.production_list' @@ -120,48 +120,48 @@ function Public.restart_settings() global.mining_history = {} get_score.score_table = {} - game.difficulty_settings.technology_price_multiplier = Balance.Tech_price_multiplier - game.map_settings.enemy_evolution.destroy_factor = 0.005 - game.map_settings.enemy_evolution.pollution_factor = 0 - game.map_settings.enemy_evolution.time_factor = 7e-05 - game.map_settings.enemy_expansion.enabled = false - -- game.map_settings.enemy_expansion.max_expansion_cooldown = 3600 - -- game.map_settings.enemy_expansion.min_expansion_cooldown = 3600 - -- game.map_settings.enemy_expansion.settler_group_max_size = 30 - -- game.map_settings.enemy_expansion.settler_group_min_size = 10 - -- game.map_settings.enemy_expansion.max_expansion_distance = 9 - game.map_settings.pollution.enabled = true - game.map_settings.pollution.expected_max_per_chunk = 400 - game.map_settings.pollution.min_to_show_per_chunk = 40 - game.map_settings.pollution.pollution_restored_per_tree_damage = 0.02 - game.map_settings.pollution.min_pollution_to_damage_trees = 1 - game.map_settings.pollution.max_pollution_to_restore_trees = 0 - game.map_settings.pollution.pollution_with_max_forest_damage = 10 - game.map_settings.pollution.pollution_per_tree_damage = 0.1 - game.map_settings.pollution.ageing = 0.1 - game.map_settings.pollution.diffusion_ratio = 0.1 - game.map_settings.pollution.enemy_attack_pollution_consumption_modifier = 5 - game.map_settings.unit_group.min_group_gathering_time = 1800 - game.map_settings.unit_group.max_group_gathering_time = 18000 - game.map_settings.unit_group.max_wait_time_for_late_members = 600 - game.map_settings.path_finder.general_entity_collision_penalty = 1 - game.map_settings.path_finder.general_entity_subsequent_collision_penalty = 1 - game.map_settings.path_finder.short_cache_size = 20 - game.map_settings.path_finder.long_cache_size = 100 - game.map_settings.unit_group.max_gathering_unit_groups = 10 - game.forces.neutral.character_inventory_slots_bonus = 500 - game.forces.enemy.evolution_factor = 0.0001 - game.forces.scrapyard.set_friend('enemy', true) - game.forces.enemy.set_friend('scrapyard', true) - game.forces.enemy.set_ammo_damage_modifier("rocket", -0.5) - game.forces.player.technologies["land-mine"].enabled = false - game.forces.player.technologies["landfill"].enabled = false - game.forces.player.technologies["cliff-explosives"].enabled = false - game.forces.player.technologies["fusion-reactor-equipment"].enabled = false - game.forces.player.technologies["power-armor-mk2"].enabled = false - game.forces.player.technologies["railway"].researched = true - game.forces.player.recipes["pistol"].enabled = false - game.forces.player.ghost_time_to_live = 15 * 60 * 60 + game.difficulty_settings.technology_price_multiplier = Balance.Tech_price_multiplier + game.map_settings.enemy_evolution.destroy_factor = 0.005 + game.map_settings.enemy_evolution.pollution_factor = 0 + game.map_settings.enemy_evolution.time_factor = 7e-05 + game.map_settings.enemy_expansion.enabled = false + -- game.map_settings.enemy_expansion.max_expansion_cooldown = 3600 + -- game.map_settings.enemy_expansion.min_expansion_cooldown = 3600 + -- game.map_settings.enemy_expansion.settler_group_max_size = 30 + -- game.map_settings.enemy_expansion.settler_group_min_size = 10 + -- game.map_settings.enemy_expansion.max_expansion_distance = 9 + game.map_settings.pollution.enabled = true + game.map_settings.pollution.expected_max_per_chunk = 400 + game.map_settings.pollution.min_to_show_per_chunk = 40 + game.map_settings.pollution.pollution_restored_per_tree_damage = 0.02 + game.map_settings.pollution.min_pollution_to_damage_trees = 1 + game.map_settings.pollution.max_pollution_to_restore_trees = 0 + game.map_settings.pollution.pollution_with_max_forest_damage = 10 + game.map_settings.pollution.pollution_per_tree_damage = 0.1 + game.map_settings.pollution.ageing = 0.1 + game.map_settings.pollution.diffusion_ratio = 0.1 + game.map_settings.pollution.enemy_attack_pollution_consumption_modifier = 5 + game.map_settings.unit_group.min_group_gathering_time = 1800 + game.map_settings.unit_group.max_group_gathering_time = 18000 + game.map_settings.unit_group.max_wait_time_for_late_members = 600 + game.map_settings.path_finder.general_entity_collision_penalty = 1 + game.map_settings.path_finder.general_entity_subsequent_collision_penalty = 1 + game.map_settings.path_finder.short_cache_size = 20 + game.map_settings.path_finder.long_cache_size = 100 + game.map_settings.unit_group.max_gathering_unit_groups = 10 + game.forces.neutral.character_inventory_slots_bonus = 500 + game.forces.enemy.evolution_factor = 0.0001 + game.forces.scrapyard.set_friend('enemy', true) + game.forces.enemy.set_friend('scrapyard', true) + game.forces.enemy.set_ammo_damage_modifier('rocket', -0.5) + game.forces.player.technologies['land-mine'].enabled = false + game.forces.player.technologies['landfill'].enabled = false + game.forces.player.technologies['cliff-explosives'].enabled = false + game.forces.player.technologies['fusion-reactor-equipment'].enabled = false + game.forces.player.technologies['power-armor-mk2'].enabled = false + game.forces.player.technologies['railway'].researched = true + game.forces.player.recipes['pistol'].enabled = false + game.forces.player.ghost_time_to_live = 15 * 60 * 60 end function Public.set_difficulty_settings() @@ -244,8 +244,7 @@ function Public.process_jump() objective.chronojumps = objective.chronojumps + 1 objective.passivetimer = 0 objective.chronochargesneeded = Balance.MJ_needed_for_full_charge(Difficulty.get().difficulty_vote_value, objective.chronojumps) - objective.passive_chronocharge_rate = - Balance.MJ_needed_for_full_charge(Difficulty.get().difficulty_vote_value, objective.chronojumps) / Balance.passive_planet_jumptime(objective.chronojumps) + objective.passive_chronocharge_rate = Balance.MJ_needed_for_full_charge(Difficulty.get().difficulty_vote_value, objective.chronojumps) / Balance.passive_planet_jumptime(objective.chronojumps) bitertable.active_biters = {} bitertable.unit_groups = {} bitertable.biter_raffle = {} @@ -274,10 +273,7 @@ function Public.process_jump() objective.computermessage = 5 game.play_sound {path = 'utility/new_objective', volume_modifier = 0.85} end - if - (objective.passivetimer - 180) * objective.passive_chronocharge_rate > objective.chronochargesneeded * 0.75 and - objective.chronojumps >= Balance.jumps_until_overstay_is_on(Difficulty.get().difficulty_vote_value) - then + if (objective.passivetimer - 180) * objective.passive_chronocharge_rate > objective.chronochargesneeded * 0.75 and objective.chronojumps >= Balance.jumps_until_overstay_is_on(Difficulty.get().difficulty_vote_value) then game.print({'chronosphere.message_overstay'}, {r = 0.98, g = 0.36, b = 0.22}) end if objective.world.id == 2 and objective.world.variant.id == 2 then @@ -407,7 +403,12 @@ local function create_chunk_list(surface) chunks[#chunks + 1] = {pos = {x, y}, generated = surface.is_chunk_generated({x, y}), distance = math.sqrt(x * x + y * y)} end end - for k, v in Rand.spairs(chunks, function(t, a, b) return t[b].distance > t[a].distance end) do + for k, v in Rand.spairs( + chunks, + function(t, a, b) + return t[b].distance > t[a].distance + end + ) do if v.generated == false then schedule.chunks_to_generate[#schedule.chunks_to_generate + 1] = v end @@ -415,24 +416,24 @@ local function create_chunk_list(surface) end function Public.setup_world(surface) - local objective = Chrono_table.get_table() - local world = objective.world - if objective.chronojumps <= 2 then - surface.min_brightness = 0.5 - else - surface.min_brightness = 0 - end - surface.brightness_visual_weights = {1, 1, 1} - objective.surface = surface - surface.daytime = world.daytime - local timer = world.dayspeed.timer - if timer == 0 then - surface.freeze_daytime = true - timer = timer + 1 - else - surface.freeze_daytime = false - end - surface.ticks_per_day = timer * 250 + local objective = Chrono_table.get_table() + local world = objective.world + if objective.chronojumps <= 2 then + surface.min_brightness = 0.5 + else + surface.min_brightness = 0 + end + surface.brightness_visual_weights = {1, 1, 1} + objective.surface = surface + surface.daytime = world.daytime + local timer = world.dayspeed.timer + if timer == 0 then + surface.freeze_daytime = true + timer = timer + 1 + else + surface.freeze_daytime = false + end + surface.ticks_per_day = timer * 250 local moisture = world.variant.moisture if moisture ~= 0 then diff --git a/maps/chronosphere/config_tab.lua b/maps/chronosphere/config_tab.lua index 6618fcb8..88ff6dfa 100644 --- a/maps/chronosphere/config_tab.lua +++ b/maps/chronosphere/config_tab.lua @@ -3,9 +3,10 @@ local Chrono_table = require 'maps.chronosphere.table' local Chrono = require 'maps.chronosphere.chrono' local Token = require 'utils.token' -local Tabs = require 'comfy_panel.main' +local Event = require 'utils.event' +local Gui = require 'utils.gui' -local module_name = 'ChronoTrain' +local module_name = Gui.uid_name() local functions = { ['comfy_panel_offline_accidents'] = function(event) @@ -230,7 +231,14 @@ local function on_gui_click(event) end end -Tabs.add_tab_to_gui({name = module_name, id = build_config_gui_token, admin = true}) +Gui.add_tab_to_gui({name = module_name, caption = 'ChronoTrain', id = build_config_gui_token, admin = true}) -local event = require 'utils.event' -event.add(defines.events.on_gui_click, on_gui_click) +Gui.on_click( + module_name, + function(event) + local player = event.player + Gui.reload_active_tab(player) + end +) + +Event.add(defines.events.on_gui_click, on_gui_click) diff --git a/maps/crab_defender/main.lua b/maps/crab_defender/main.lua index 7d31a9ef..1bf5da96 100644 --- a/maps/crab_defender/main.lua +++ b/maps/crab_defender/main.lua @@ -16,10 +16,10 @@ local Map = require 'modules.map_info' local Event = require 'utils.event' local Reset = require 'functions.soft_reset' local Server = require 'utils.server' -local Poll = require 'comfy_panel.poll' +local Poll = require 'utils.gui.poll' local boss_biter = require 'maps.crab_defender.boss_biters' local FDT = require 'maps.crab_defender.table' -local Score = require 'comfy_panel.score' +local Score = require 'utils.gui.score' local math_random = math.random local insert = table.insert local enable_start_grace_period = true diff --git a/maps/fish_defender/main.lua b/maps/fish_defender/main.lua index fe9cf2c7..76889fcd 100644 --- a/maps/fish_defender/main.lua +++ b/maps/fish_defender/main.lua @@ -21,10 +21,10 @@ local Map = require 'modules.map_info' local Event = require 'utils.event' local Reset = require 'functions.soft_reset' local Server = require 'utils.server' -local Poll = require 'comfy_panel.poll' +local Poll = require 'utils.gui.poll' local boss_biter = require 'maps.fish_defender.boss_biters' local FDT = require 'maps.fish_defender.table' -local Score = require 'comfy_panel.score' +local Score = require 'utils.gui.score' local math_random = math.random local insert = table.insert local enable_start_grace_period = true diff --git a/maps/fish_defender_v1/fish_defender.lua b/maps/fish_defender_v1/fish_defender.lua index 4d81aa24..9cce343d 100644 --- a/maps/fish_defender_v1/fish_defender.lua +++ b/maps/fish_defender_v1/fish_defender.lua @@ -17,7 +17,7 @@ require 'modules.biter_evasion_hp_increaser' local event = require 'utils.event' local Server = require 'utils.server' local boss_biter = require 'maps.fish_defender.boss_biters' -local Score = require 'comfy_panel.score' +local Score = require 'utils.gui.score' require 'functions.boss_unit' local map_functions = require 'tools.map_functions' local Difficulty = require 'modules.difficulty_vote' diff --git a/maps/fish_defender_v2/main.lua b/maps/fish_defender_v2/main.lua index bcfef817..15191976 100644 --- a/maps/fish_defender_v2/main.lua +++ b/maps/fish_defender_v2/main.lua @@ -14,8 +14,8 @@ local Event = require 'utils.event' local Reset = require 'functions.soft_reset' local Server = require 'utils.server' local Session = require 'utils.datastore.session_data' -local Poll = require 'comfy_panel.poll' -local Score = require 'comfy_panel.score' +local Poll = require 'utils.gui.poll' +local Score = require 'utils.gui.score' local AntiGrief = require 'utils.antigrief' local Core = require 'utils.core' local format_number = require 'util'.format_number diff --git a/maps/junkyard_pvp/main.lua b/maps/junkyard_pvp/main.lua index 2a3ddeb4..49e4ae33 100644 --- a/maps/junkyard_pvp/main.lua +++ b/maps/junkyard_pvp/main.lua @@ -1,8 +1,8 @@ --luacheck: ignore -local Tabs = require 'comfy_panel.main' +local Gui = require 'utils.gui' local Map_score = require 'modules.map_score' local Terrain = require 'maps.junkyard_pvp.terrain' -local Gui = require 'maps.junkyard_pvp.gui' +local MapGui = require 'maps.junkyard_pvp.gui' require 'maps.junkyard_pvp.surrounded_by_worms' require 'modules.flashlight_toggle_button' require 'modules.rocks_heal_over_time' @@ -65,7 +65,7 @@ function Public.reset_map() Team.set_player_to_spectator(player) end for _, player in pairs(game.forces.spectator.players) do - Gui.rejoin_question(player) + MapGui.rejoin_question(player) end set_player_colors() @@ -119,7 +119,7 @@ local function on_entity_died(event) for _, child in pairs(player.gui.left.children) do child.destroy() end - Tabs.comfy_panel_call_tab(player, 'Map Scores') + Gui.call_existing_tab(player, 'Map Scores') end end end @@ -129,7 +129,7 @@ local function on_player_joined_game(event) local surface = game.surfaces[global.active_surface_index] set_player_colors() - Gui.spectate_button(player) + MapGui.spectate_button(player) if player.surface.index ~= global.active_surface_index then if player.force.name == 'spectator' then diff --git a/maps/labyrinth.lua b/maps/labyrinth.lua index 7553ba35..e87ce7c7 100644 --- a/maps/labyrinth.lua +++ b/maps/labyrinth.lua @@ -10,11 +10,11 @@ local Server = require 'utils.server' local Global = require 'utils.global' local map_functions = require 'tools.map_functions' local simplex_noise = require 'utils.simplex_noise'.d2 -local Score = require 'comfy_panel.score' +local Score = require 'utils.gui.score' local unique_rooms = require 'maps.labyrinth_unique_rooms' local SoftReset = require 'functions.soft_reset' local Autostash = require 'modules.autostash' -local BottomFrame = require 'comfy_panel.bottom_frame' +local BottomFrame = require 'utils.gui.bottom_frame' local this = { settings = { labyrinth_size = 1, @@ -517,10 +517,7 @@ local function grow_cell(chunk_position, surface) -- luacheck: ignore end end end - placed_enemies = - #entities_to_place.biters * 0.35 + #entities_to_place.spitters * 0.35 + #entities_to_place.enemy_buildings * 2 + #entities_to_place.worms * 3 + - #entities_to_place.gun_turrets * 3 + - #entities_to_place.allied_entities + placed_enemies = #entities_to_place.biters * 0.35 + #entities_to_place.spitters * 0.35 + #entities_to_place.enemy_buildings * 2 + #entities_to_place.worms * 3 + #entities_to_place.gun_turrets * 3 + #entities_to_place.allied_entities end for x = 0, 31, 1 do --luacheck: ignore @@ -570,10 +567,7 @@ local function grow_cell(chunk_position, surface) -- luacheck: ignore table.insert(entities_to_place.spitters, {left_top_x + e.position.x, left_top_y + e.position.y}) break end - table.insert( - entities_to_place.misc, - {name = e.name, position = {left_top_x + e.position.x, left_top_y + e.position.y}, direction = e.direction, force = e.force} - ) + table.insert(entities_to_place.misc, {name = e.name, position = {left_top_x + e.position.x, left_top_y + e.position.y}, direction = e.direction, force = e.force}) break end end @@ -1055,8 +1049,7 @@ local function on_entity_died(event) if game.forces.enemy.evolution_factor < 0.5 then local evolution_drop_modifier = (0.1 - game.forces.enemy.evolution_factor) * 10 if evolution_drop_modifier > 0 then - local amount = - math.ceil(math.random(entity_drop_amount[event.entity.name].low, entity_drop_amount[event.entity.name].high) * evolution_drop_modifier) + local amount = math.ceil(math.random(entity_drop_amount[event.entity.name].low, entity_drop_amount[event.entity.name].high) * evolution_drop_modifier) event.entity.surface.spill_item_stack(event.entity.position, {name = ore_spill_raffle[math.random(1, #ore_spill_raffle)], count = amount}, true) end end @@ -1291,8 +1284,7 @@ local function on_built_entity(event) if get_score then if get_score[player.force.name] then if get_score[player.force.name].players[player.name] then - get_score[player.force.name].players[player.name].built_entities = - get_score[player.force.name].players[player.name].built_entities - 1 + get_score[player.force.name].players[player.name].built_entities = get_score[player.force.name].players[player.name].built_entities - 1 end end end diff --git a/maps/minesweeper/main.lua b/maps/minesweeper/main.lua index 8224dc85..29ab396f 100644 --- a/maps/minesweeper/main.lua +++ b/maps/minesweeper/main.lua @@ -13,7 +13,7 @@ Cell Values: require 'modules.satellite_score' local Functions = require 'maps.minesweeper.functions' -local Map_score = require 'comfy_panel.map_score' +local Map_score = require 'utils.gui.map_score' local Map = require 'modules.map_info' local Global = require 'utils.global' diff --git a/maps/mountain_fortress_v2/main.lua b/maps/mountain_fortress_v2/main.lua index 65ae5cc7..b89df14e 100644 --- a/maps/mountain_fortress_v2/main.lua +++ b/maps/mountain_fortress_v2/main.lua @@ -7,8 +7,8 @@ local darkness = false require 'functions.soft_reset' require 'functions.basic_markets' -local ComfyPanel = require 'comfy_panel.main' -local Map_score = require 'comfy_panel.map_score' +local Gui = require 'utils.gui' +local Map_score = require 'utils.gui.map_score' local Collapse = require 'modules.collapse' local RPG = require 'modules.rpg' require 'modules.wave_defense.main' @@ -54,7 +54,7 @@ local function game_over() global.game_reset_tick = game.tick + 1800 for _, player in pairs(game.connected_players) do player.play_sound {path = 'utility/game_lost', volume_modifier = 0.80} - ComfyPanel.comfy_panel_call_tab(player, 'Map Scores') + Gui.call_existing_tab(player, 'Map Scores') end end diff --git a/maps/mountain_fortress_v3/entities.lua b/maps/mountain_fortress_v3/entities.lua index 3c0a42f2..d77584ed 100644 --- a/maps/mountain_fortress_v3/entities.lua +++ b/maps/mountain_fortress_v3/entities.lua @@ -14,7 +14,7 @@ local DefenseSystem = require 'maps.mountain_fortress_v3.locomotive.defense_syst local Collapse = require 'modules.collapse' local Alert = require 'utils.alert' local Task = require 'utils.task' -local Score = require 'comfy_panel.score' +local Score = require 'utils.gui.score' local Token = require 'utils.token' -- local HS = require 'maps.mountain_fortress_v3.highscore' local Discord = require 'utils.discord' @@ -1153,8 +1153,7 @@ local function show_mvps(player) local miners_label = t.add({type = 'label', caption = 'Miners >> '}) miners_label.style.font = 'default-listbox' miners_label.style.font_color = {r = 0.22, g = 0.77, b = 0.44} - local miners_label_text = - t.add({type = 'label', caption = mvp.mined_entities.name .. ' mined a total of ' .. mvp.mined_entities.score .. ' entities!'}) + local miners_label_text = t.add({type = 'label', caption = mvp.mined_entities.name .. ' mined a total of ' .. mvp.mined_entities.score .. ' entities!'}) miners_label_text.style.font = 'default-bold' miners_label_text.style.font_color = {r = 0.33, g = 0.66, b = 0.9} diff --git a/maps/mountain_fortress_v3/functions.lua b/maps/mountain_fortress_v3/functions.lua index 2bfef1a6..2be282db 100644 --- a/maps/mountain_fortress_v3/functions.lua +++ b/maps/mountain_fortress_v3/functions.lua @@ -1281,10 +1281,10 @@ function Public.on_player_joined_game(event) end end - local top = player.gui.top - if top['mod_gui_top_frame'] then - top['mod_gui_top_frame'].destroy() - end + -- local top = player.gui.top + -- if top['mod_gui_top_frame'] then + -- top['mod_gui_top_frame'].destroy() + -- end if player.surface.index ~= active_surface_index then player.teleport(surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 3, 0, 5), surface) diff --git a/maps/mountain_fortress_v3/gui.lua b/maps/mountain_fortress_v3/gui.lua index 32f17f7d..9a159c97 100644 --- a/maps/mountain_fortress_v3/gui.lua +++ b/maps/mountain_fortress_v3/gui.lua @@ -3,6 +3,7 @@ local RPG = require 'modules.rpg.main' local WPT = require 'maps.mountain_fortress_v3.table' local IC_Gui = require 'maps.mountain_fortress_v3.ic.gui' local IC_Minimap = require 'maps.mountain_fortress_v3.ic.minimap' +local Difficulty = require 'modules.difficulty_vote_by_amount' local Gui = require 'utils.gui' local SpamProtection = require 'utils.spam_protection' @@ -195,7 +196,7 @@ local function on_gui_click(event) if player.gui.top[main_frame_name] then local info = player.gui.top[main_frame_name] local wd = player.gui.top['wave_defense'] - local diff = player.gui.top['difficulty_gui'] + local diff = player.gui.top[Difficulty.top_button_name] if info and info.visible then if wd then @@ -256,7 +257,7 @@ local function on_player_changed_surface(event) local rpg_b = player.gui.top[rpg_button] local rpg_f = player.gui.screen[rpg_frame] local rpg_s = player.gui.screen[rpg_settings] - local diff = player.gui.top['difficulty_gui'] + local diff = player.gui.top[Difficulty.top_button_name] local charging = player.gui.top['charging_station'] local frame = player.gui.top[main_frame_name] local spell_gui_frame_name = RPG.spell_gui_frame_name @@ -356,7 +357,7 @@ local function enable_guis(event) local info = player.gui.top[main_button_name] local wd = player.gui.top['wave_defense'] local rpg_b = player.gui.top[rpg_button] - local diff = player.gui.top['difficulty_gui'] + local diff = player.gui.top[Difficulty.top_button_name] local charging = player.gui.top['charging_station'] IC_Gui.remove_toolbar(player) @@ -437,8 +438,7 @@ function Public.update_gui(player) gui.landmine.caption = ' [img=entity.land-mine]: ' .. format_number(upgrades.landmine.built, true) .. ' / ' .. format_number(upgrades.landmine.limit, true) gui.landmine.tooltip = ({'gui.land_mine_placed'}) - gui.flame_turret.caption = - ' [img=entity.flamethrower-turret]: ' .. format_number(upgrades.flame_turret.built, true) .. ' / ' .. format_number(upgrades.flame_turret.limit, true) + gui.flame_turret.caption = ' [img=entity.flamethrower-turret]: ' .. format_number(upgrades.flame_turret.built, true) .. ' / ' .. format_number(upgrades.flame_turret.limit, true) gui.flame_turret.tooltip = ({'gui.flamethrowers_placed'}) gui.train_upgrades.caption = ' [img=entity.locomotive]: ' .. format_number(train_upgrades, true) diff --git a/maps/mountain_fortress_v3/highscore.lua b/maps/mountain_fortress_v3/highscore.lua index ee975add..73b68925 100644 --- a/maps/mountain_fortress_v3/highscore.lua +++ b/maps/mountain_fortress_v3/highscore.lua @@ -2,14 +2,14 @@ local Event = require 'utils.event' local Global = require 'utils.global' local Server = require 'utils.server' local Token = require 'utils.token' -local Tabs = require 'comfy_panel.main' -local Score = require 'comfy_panel.score' +local Gui = require 'utils.gui' +local Score = require 'utils.gui.score' local WPT = require 'maps.mountain_fortress_v3.table' local WD = require 'modules.wave_defense.table' local Core = require 'utils.core' local SpamProtection = require 'utils.spam_protection' -local module_name = 'Highscore' +local module_name = Gui.uid_name() local score_dataset = 'highscores' local score_key = 'mountain_fortress_v3_scores' local set_data = Server.set_data @@ -609,22 +609,18 @@ end local show_score_token = Token.register(show_score) local function on_gui_click(event) - if not event then - return - end - if not event.element then - return - end - if not event.element.valid then + local element = event.element + if not element or not element.valid then return end - local player = game.players[event.element.player_index] - local frame = Tabs.comfy_panel_get_active_frame(player) + local player = game.get_player(event.element.player_index) + + local frame = Gui.get_player_active_frame(player) if not frame then return end - if frame.name ~= module_name then + if frame.name ~= 'Highscore' then return end @@ -681,7 +677,15 @@ Server.on_data_set_changed( end ) -Tabs.add_tab_to_gui({name = module_name, id = show_score_token, admin = false, only_server_sided = true}) +Gui.add_tab_to_gui({name = module_name, caption = 'Highscore', id = show_score_token, admin = false, only_server_sided = true}) + +Gui.on_click( + module_name, + function(event) + local player = event.player + Gui.reload_active_tab(player) + end +) Event.on_init(on_init) Event.add(defines.events.on_player_left_game, on_player_left_game) diff --git a/maps/mountain_fortress_v3/ic/gui.lua b/maps/mountain_fortress_v3/ic/gui.lua index 9c8cec1a..ccb4b8ac 100644 --- a/maps/mountain_fortress_v3/ic/gui.lua +++ b/maps/mountain_fortress_v3/ic/gui.lua @@ -2,7 +2,7 @@ local ICT = require 'maps.mountain_fortress_v3.ic.table' local Functions = require 'maps.mountain_fortress_v3.ic.functions' local Color = require 'utils.color_presets' local Gui = require 'utils.gui' -local Tabs = require 'comfy_panel.main' +local Tabs = require 'utils.gui' local Event = require 'utils.event' local Token = require 'utils.token' local Task = require 'utils.task' @@ -464,7 +464,7 @@ local function toggle(player, recreate) if main_frame then remove_main_frame(main_frame) else - Tabs.comfy_panel_clear_gui(player) + Tabs.clear_all_active_frames(player) draw_main_frame(player) end end @@ -813,10 +813,7 @@ Gui.on_click( if not misc_settings[player.index].final_warning then misc_settings[player.index].final_warning = true - player.print( - '[IC] WARNING! WARNING WARNING! Pressing the save button ONE MORE TIME will DELETE your surface. This action is irreversible!', - Color.red - ) + player.print('[IC] WARNING! WARNING WARNING! Pressing the save button ONE MORE TIME will DELETE your surface. This action is irreversible!', Color.red) Task.set_timeout_in_ticks(600, clear_misc_settings, {player_index = player.index}) return end diff --git a/maps/mountain_fortress_v3/locomotive/market.lua b/maps/mountain_fortress_v3/locomotive/market.lua index 37026bad..6b821bfa 100644 --- a/maps/mountain_fortress_v3/locomotive/market.lua +++ b/maps/mountain_fortress_v3/locomotive/market.lua @@ -19,6 +19,7 @@ local Public = {} local concat = table.concat local main_frame_name = Gui.uid_name() +local close_market_gui_name = Gui.uid_name() local random = math.random local round = math.round @@ -793,31 +794,21 @@ local function gui_opened(event) if data.frame then data.frame = nil end - local frame = - player.gui.screen.add( - { - type = 'frame', - caption = ({'locomotive.market_name'}), - direction = 'vertical', - name = main_frame_name - } - ) + local frame, inside_table = Gui.add_main_frame_with_toolbar(player, 'screen', main_frame_name, nil, close_market_gui_name, 'Market') frame.auto_center = true player.opened = frame - frame.style.minimal_width = 325 - frame.style.minimal_height = 250 - local search_table = frame.add({type = 'table', column_count = 2}) + local search_table = inside_table.add({type = 'table', column_count = 2}) search_table.add({type = 'label', caption = ({'locomotive.search_text'})}) local search_text = search_table.add({type = 'textfield'}) search_text.style.width = 140 - add_space(frame) + add_space(inside_table) local pane = - frame.add { + inside_table.add { type = 'scroll-pane', direction = 'vertical', vertical_scroll_policy = 'always', @@ -828,11 +819,11 @@ local function gui_opened(event) pane.style.minimal_height = 200 pane.style.right_padding = 0 - local flow = frame.add({type = 'flow'}) + local flow = inside_table.add({type = 'flow'}) add_space(flow) - local bottom_grid = frame.add({type = 'table', column_count = 4}) + local bottom_grid = inside_table.add({type = 'table', column_count = 4}) bottom_grid.style.vertically_stretchable = false local bg = bottom_grid.add({type = 'label', caption = ({'locomotive.quantity_text'})}) @@ -848,7 +839,7 @@ local function gui_opened(event) text_input.style.maximal_height = 28 local slider = - frame.add( + inside_table.add( { type = 'slider', minimum_value = 1, @@ -859,7 +850,7 @@ local function gui_opened(event) slider.style.width = 115 text_input.style.width = 60 - local coinsleft = frame.add({type = 'flow'}) + local coinsleft = inside_table.add({type = 'flow'}) coinsleft.add( { @@ -871,7 +862,7 @@ local function gui_opened(event) players[player.index].data.search_text = search_text players[player.index].data.text_input = text_input players[player.index].data.slider = slider - players[player.index].data.frame = frame + players[player.index].data.frame = inside_table players[player.index].data.item_frame = pane players[player.index].data.coins_left = coinsleft @@ -1480,6 +1471,17 @@ local function tick() end end +Gui.on_click( + close_market_gui_name, + function(event) + local player = event.player + if not player or not player.valid or not player.character then + return + end + close_market_gui(player) + end +) + Event.on_nth_tick(5, tick) Event.add(defines.events.on_gui_click, gui_click) Event.add(defines.events.on_gui_value_changed, slider_changed) diff --git a/maps/mountain_fortress_v3/main.lua b/maps/mountain_fortress_v3/main.lua index 384809ab..d3d4e768 100644 --- a/maps/mountain_fortress_v3/main.lua +++ b/maps/mountain_fortress_v3/main.lua @@ -13,8 +13,8 @@ local Discord = require 'utils.discord' local IC = require 'maps.mountain_fortress_v3.ic.table' local ICMinimap = require 'maps.mountain_fortress_v3.ic.minimap' local Autostash = require 'modules.autostash' -local Group = require 'comfy_panel.group' -local PL = require 'comfy_panel.player_list' +local Group = require 'utils.gui.group' +local PL = require 'utils.gui.player_list' local CS = require 'maps.mountain_fortress_v3.surface' local Server = require 'utils.server' local Explosives = require 'modules.explosives' @@ -29,14 +29,14 @@ local Event = require 'utils.event' local WPT = require 'maps.mountain_fortress_v3.table' local Locomotive = require 'maps.mountain_fortress_v3.locomotive' local SpawnLocomotive = require 'maps.mountain_fortress_v3.locomotive.spawn_locomotive' -local Score = require 'comfy_panel.score' -local Poll = require 'comfy_panel.poll' +local Score = require 'utils.gui.score' +local Poll = require 'utils.gui.poll' local Collapse = require 'modules.collapse' local Difficulty = require 'modules.difficulty_vote_by_amount' local Task = require 'utils.task' local Token = require 'utils.token' local Alert = require 'utils.alert' -local BottomFrame = require 'comfy_panel.bottom_frame' +local BottomFrame = require 'utils.gui.bottom_frame' local AntiGrief = require 'utils.antigrief' local Misc = require 'utils.commands.misc' local Modifiers = require 'utils.player_modifiers' diff --git a/maps/mountain_race/main.lua b/maps/mountain_race/main.lua index e5a9488d..3bc128a9 100644 --- a/maps/mountain_race/main.lua +++ b/maps/mountain_race/main.lua @@ -2,7 +2,7 @@ require 'modules.biters_yield_ore' require 'modules.rocks_yield_ore_veins' -local Map_score = require 'comfy_panel.map_score' +local Map_score = require 'utils.gui.map_score' local Collapse = require 'modules.collapse' local Immersive_cargo_wagons = require 'modules.immersive_cargo_wagons.main' local Terrain = require 'maps.mountain_race.terrain' diff --git a/maps/native_war/main.lua b/maps/native_war/main.lua index 0646f6a4..b74074c7 100644 --- a/maps/native_war/main.lua +++ b/maps/native_war/main.lua @@ -2,12 +2,12 @@ require 'modules.biter_reanimator' require 'maps.native_war.share_chat' require 'maps.native_war.mineable_wreckage_yields_scrap' +require 'maps.native_war.gui' local Global = require 'utils.global' -local Tabs = require 'comfy_panel.main' +local Gui = require 'utils.gui' local Map_score = require 'modules.map_score' local Team = require 'maps.native_war.team' local Terrain = require 'maps.native_war.terrain' -local Gui = require 'maps.native_war.gui' local Init = require 'maps.native_war.init' local Settings = require 'maps.native_war.settings' local Reset = require 'functions.soft_reset' @@ -343,7 +343,7 @@ local function on_entity_died(event) for _, child in pairs(player.gui.left.children) do child.destroy() end - Tabs.comfy_panel_call_tab(player, 'Map Scores') + Gui.call_existing_tab(player, 'Map Scores') end end @@ -549,12 +549,10 @@ local function on_entity_damaged(event) if entity.type == 'unit' or entity.type == 'turret' then if cause.type == 'unit' then if cause.name == 'small-biter' or cause.name == 'medium-biter' or cause.name == 'big-biter' or cause.name == 'behemoth-biter' then - local modified_damage = - event.original_damage_amount * global.map_forces[cause.force.name].modifier.damage * global.map_forces[entity.force.name].modifier.resistance + local modified_damage = event.original_damage_amount * global.map_forces[cause.force.name].modifier.damage * global.map_forces[entity.force.name].modifier.resistance entity.health = entity.health - modified_damage elseif cause.name == 'small-spitter' or cause.name == 'medium-spitter' or cause.name == 'big-spitter' or cause.name == 'behemoth-spitter' then - local modified_damage = - event.original_damage_amount * global.map_forces[cause.force.name].modifier.splash * global.map_forces[entity.force.name].modifier.resistance + local modified_damage = event.original_damage_amount * global.map_forces[cause.force.name].modifier.splash * global.map_forces[entity.force.name].modifier.resistance entity.health = entity.health - modified_damage end end diff --git a/maps/pidgeotto/main.lua b/maps/pidgeotto/main.lua index b6e40382..caac57f1 100644 --- a/maps/pidgeotto/main.lua +++ b/maps/pidgeotto/main.lua @@ -15,10 +15,10 @@ local Map = require 'modules.map_info' local Event = require 'utils.event' local Reset = require 'functions.soft_reset' local Server = require 'utils.server' -local Poll = require 'comfy_panel.poll' +local Poll = require 'utils.gui.poll' local boss_biter = require 'maps.pidgeotto.boss_biters' local FDT = require 'maps.pidgeotto.table' -local Score = require 'comfy_panel.score' +local Score = require 'utils.gui.score' local AntiGrief = require 'utils.antigrief' local math_random = math.random local insert = table.insert diff --git a/maps/planet_prison.lua b/maps/planet_prison.lua index 066bf6c2..0827f82d 100644 --- a/maps/planet_prison.lua +++ b/maps/planet_prison.lua @@ -838,15 +838,7 @@ local function on_gui_click(e) return end - if elem.name == 'comfy_panel_top_button' then - if not p.admin then - if p.gui.left['comfy_panel'] and p.gui.left['comfy_panel'].valid then - p.gui.left['comfy_panel'].destroy() - end - redraw_gui(p) - return p.print('Comfy panel is disabled in this scenario.', Color.fail) - end - elseif elem.name == 'chat_toggle' then + if elem.name == 'chat_toggle' then if perks.chat_global then elem.caption = 'NAP chat' perks.chat_global = false diff --git a/maps/scrap_towny_ffa/main.lua b/maps/scrap_towny_ffa/main.lua index 095a7a2d..363bba41 100644 --- a/maps/scrap_towny_ffa/main.lua +++ b/maps/scrap_towny_ffa/main.lua @@ -20,7 +20,7 @@ require 'modules.scrap_towny_ffa.turrets_drop_ammo' require 'modules.scrap_towny_ffa.combat_balance' local Autostash = require 'modules.autostash' -local BottomFrame = require 'comfy_panel.bottom_frame' +local BottomFrame = require 'utils.gui.bottom_frame' local Table = require 'modules.scrap_towny_ffa.table' local Nauvis = require 'modules.scrap_towny_ffa.nauvis' local Biters = require 'modules.scrap_towny_ffa.biters' @@ -40,11 +40,17 @@ local max_ticks_between_spawns = 60 * 10 local min_players_for_enabling_towns = 0 local function load_buffs(player) - if player.force.name ~= 'player' and player.force.name ~= 'rogue' then return end + if player.force.name ~= 'player' and player.force.name ~= 'rogue' then + return + end local ffatable = Table.get_table() local player_index = player.index - if player.character == nil then return end - if ffatable.buffs[player_index] == nil then ffatable.buffs[player_index] = {} end + if player.character == nil then + return + end + if ffatable.buffs[player_index] == nil then + ffatable.buffs[player_index] = {} + end if ffatable.buffs[player_index].character_inventory_slots_bonus ~= nil then player.character.character_inventory_slots_bonus = ffatable.buffs[player_index].character_inventory_slots_bonus end @@ -65,14 +71,14 @@ local function on_player_joined_game(event) player.game_view_settings.show_map_view_options = false player.game_view_settings.show_entity_info = true player.map_view_settings = { - ["show-logistic-network"] = false, - ["show-electric-network"] = false, - ["show-turret-range"] = false, - ["show-pollution"] = false, - ["show-train-station-names"] = false, - ["show-player-names"] = false, - ["show-networkless-logistic-members"] = false, - ["show-non-standard-map-info"] = false + ['show-logistic-network'] = false, + ['show-electric-network'] = false, + ['show-turret-range'] = false, + ['show-pollution'] = false, + ['show-train-station-names'] = false, + ['show-player-names'] = false, + ['show-networkless-logistic-members'] = false, + ['show-non-standard-map-info'] = false } player.show_on_map = false --player.game_view_settings.show_side_menu = false @@ -89,19 +95,21 @@ local function on_player_joined_game(event) ffatable.towns_enabled = true else ffatable.players = ffatable.players + 1 - if ffatable.players >= min_players_for_enabling_towns then ffatable.towns_enabled = true end + if ffatable.players >= min_players_for_enabling_towns then + ffatable.towns_enabled = true + end end player.teleport({0, 0}, game.surfaces['limbo']) Team.set_player_to_outlander(player) Team.give_player_items(player) - player.insert{name="coin", count="100"} - player.insert{name="stone-furnace", count="1"} + player.insert {name = 'coin', count = '100'} + player.insert {name = 'stone-furnace', count = '1'} Team.give_key(player.index) if (testing_mode == true) then player.cheat_mode = true player.force.research_all_technologies() - player.insert{name="coin", count="9900"} + player.insert {name = 'coin', count = '9900'} end -- first time spawn point local spawn_point = Spawn.get_new_spawn_point(player, surface) @@ -150,7 +158,9 @@ end local function on_player_died(event) local ffatable = Table.get_table() local player = game.players[event.player_index] - if ffatable.strikes[player.name] == nil then ffatable.strikes[player.name] = 0 end + if ffatable.strikes[player.name] == nil then + ffatable.strikes[player.name] = 0 + end local ticks_elapsed = game.tick - ffatable.last_respawn[player.name] if ticks_elapsed < max_ticks_between_spawns then diff --git a/modules/autostash.lua b/modules/autostash.lua index 8fe5ccbf..a6683ffa 100644 --- a/modules/autostash.lua +++ b/modules/autostash.lua @@ -4,8 +4,8 @@ local Global = require 'utils.global' local SpamProtection = require 'utils.spam_protection' local Event = require 'utils.event' -local BottomFrame = require 'comfy_panel.bottom_frame' -local ComfyGui = require 'comfy_panel.main' +local BottomFrame = require 'utils.gui.bottom_frame' +local ComfyGui = require 'utils.gui' local floor = math.floor local print_color = {r = 120, g = 255, b = 0} diff --git a/modules/difficulty_vote_by_amount.lua b/modules/difficulty_vote_by_amount.lua index 98fe60e0..0b6714b1 100644 --- a/modules/difficulty_vote_by_amount.lua +++ b/modules/difficulty_vote_by_amount.lua @@ -1,4 +1,5 @@ local Event = require 'utils.event' +local Gui = require 'utils.gui' local Server = require 'utils.server' local Global = require 'utils.global' local SpamProtection = require 'utils.spam_protection' @@ -6,6 +7,11 @@ local SpamProtection = require 'utils.spam_protection' local max = math.max local round = math.round +local main_frame_name = Gui.uid_name() +local selection_button_name = Gui.uid_name() +local close_main_frame = Gui.uid_name() +local top_button_name = Gui.uid_name() + local this = { difficulties = { [1] = { @@ -64,21 +70,29 @@ Global.register( end ) +local function clear_main_frame(player) + local screen = player.gui.center + if screen[main_frame_name] and screen[main_frame_name].valid then + screen[main_frame_name].destroy() + end +end + function Public.difficulty_gui() local tooltip = 'Current difficulty of the map is ' .. this.difficulties[this.difficulty_vote_index].name .. '.' for _, player in pairs(game.connected_players) do - if player.gui.top['difficulty_gui'] then - player.gui.top['difficulty_gui'].caption = this.difficulties[this.difficulty_vote_index].name - player.gui.top['difficulty_gui'].tooltip = this.button_tooltip or tooltip - player.gui.top['difficulty_gui'].style.font_color = this.difficulties[this.difficulty_vote_index].print_color + local top = player.gui.top + if top[top_button_name] then + top[top_button_name].caption = this.difficulties[this.difficulty_vote_index].name + top[top_button_name].tooltip = this.button_tooltip or tooltip + top[top_button_name].style.font_color = this.difficulties[this.difficulty_vote_index].print_color else local b = - player.gui.top.add { + top.add { type = 'button', caption = this.difficulties[this.difficulty_vote_index].name, tooltip = tooltip, - name = 'difficulty_gui' + name = top_button_name } b.style.font = 'heading-2' b.style.font_color = this.difficulties[this.difficulty_vote_index].print_color @@ -130,10 +144,10 @@ local function highest_count(tbl) end local function poll_difficulty(player) - if player.gui.center['difficulty_poll'] then - player.gui.center['difficulty_poll'].destroy() - return + if player.gui.center[main_frame_name] then + clear_main_frame(player) end + if game.tick > this.difficulty_poll_closing_timeout then if player.online_time ~= 0 then local t = math.abs(math.floor((this.difficulty_poll_closing_timeout - game.tick) / 3600)) @@ -148,32 +162,49 @@ local function poll_difficulty(player) return end - local frame = - player.gui.center.add { - type = 'frame', - caption = 'Vote difficulty:', - name = 'difficulty_poll', - direction = 'vertical' - } + local _, inside_frame = Gui.add_main_frame_with_toolbar(player, 'center', main_frame_name, nil, close_main_frame, 'Difficulty') + for i = 1, #this.difficulties, 1 do - local b = frame.add({type = 'button', name = tostring(i), caption = this.difficulties[i].name}) + local button_flow = + inside_frame.add { + type = 'flow', + name = tostring(i) + } + local b = button_flow.add({type = 'button', name = selection_button_name, caption = this.difficulties[i].name}) b.style.font_color = this.difficulties[i].color b.style.font = 'heading-2' b.style.minimal_width = 160 b.tooltip = this.tooltip[i] end - frame.add({type = 'label', caption = '- - - - - - - - - - - - - - - - - -'}) + + local label_flow = + inside_frame.add { + type = 'flow' + } + + label_flow.add({type = 'label', caption = '- - - - - - - - - - - - - - - - - -'}) + + label_flow.style.horizontal_align = 'center' + label_flow.style.horizontally_stretchable = true + + local timeleft_flow = + inside_frame.add { + type = 'flow' + } + timeleft_flow.style.horizontal_align = 'center' + timeleft_flow.style.horizontally_stretchable = true + local b = - frame.add( + timeleft_flow.add( { type = 'button', - name = 'close', - caption = 'Close (' .. math.floor((this.difficulty_poll_closing_timeout - game.tick) / 3600) .. ' minutes left)' + caption = math.floor((this.difficulty_poll_closing_timeout - game.tick) / 3600) .. ' minutes left.' } ) b.style.font_color = {r = 0.66, g = 0.0, b = 0.66} b.style.font = 'heading-3' b.style.minimal_width = 96 + b.enabled = false end local function set_difficulty() @@ -200,8 +231,8 @@ function Public.reset_difficulty_poll(tbl) this.difficulty_player_votes = {} this.difficulty_poll_closing_timeout = tbl.difficulty_poll_closing_timeout or game.tick + 54000 for _, p in pairs(game.connected_players) do - if p.gui.center['difficulty_poll'] then - p.gui.center['difficulty_poll'].destroy() + if p.gui.center[main_frame_name] then + clear_main_frame(p) end poll_difficulty(p) end @@ -215,8 +246,8 @@ function Public.reset_difficulty_poll(tbl) this.difficulty_player_votes = {} this.difficulty_poll_closing_timeout = game.tick + 54000 for _, p in pairs(game.connected_players) do - if p.gui.center['difficulty_poll'] then - p.gui.center['difficulty_poll'].destroy() + if p.gui.center[main_frame_name] then + clear_main_frame(p) end poll_difficulty(p) end @@ -228,15 +259,13 @@ function Public.reset_difficulty_poll(tbl) end local function on_player_joined_game(event) - local player = game.players[event.player_index] + local player = game.get_player(event.player_index) if game.tick < this.difficulty_poll_closing_timeout then if not this.difficulty_player_votes[player.name] then poll_difficulty(player) end else - if player.gui.center['difficulty_poll'] then - player.gui.center['difficulty_poll'].destroy() - end + clear_main_frame(player) end Public.difficulty_gui() end @@ -245,7 +274,7 @@ local function on_player_left_game(event) if game.tick > this.difficulty_poll_closing_timeout then return end - local player = game.players[event.player_index] + local player = game.get_player(event.player_index) if not this.difficulty_player_votes[player.name] then return end @@ -259,73 +288,6 @@ local function on_player_left_game(event) Public.difficulty_gui() end -local function on_gui_click(event) - if not event then - return - end - local player = game.players[event.player_index] - - if not event.element then - return - end - if not event.element.valid then - return - end - - if event.element.name == 'difficulty_gui' then - local is_spamming = SpamProtection.is_spamming(player, nil, 'Difficulty Vote Gui Click') - if is_spamming then - return - end - poll_difficulty(player) - return - end - if event.element.type ~= 'button' then - return - end - if event.element.parent.name ~= 'difficulty_poll' then - return - end - if event.element.name == 'close' then - event.element.parent.destroy() - return - end - if game.tick > this.difficulty_poll_closing_timeout then - event.element.parent.destroy() - return - end - - local is_spamming = SpamProtection.is_spamming(player, nil, 'Difficulty Gui No Func') - if is_spamming then - return - end - - local i = tonumber(event.element.name) - - if this.difficulty_player_votes[player.name] and this.difficulty_player_votes[player.name].index == i then - player.print('You have already voted for ' .. this.difficulties[i].name .. '.', this.difficulties[i].print_color) - return event.element.parent.destroy() - end - - if this.difficulty_player_votes[player.name] then - local index = this.difficulty_player_votes[player.name].index - this.difficulties[index].count = this.difficulties[index].count - 1 - if this.difficulties[index].count <= 0 then - this.difficulties[index].count = 0 - end - end - - this.difficulties[i].count = this.difficulties[i].count + 1 - this.difficulty_player_votes[player.name] = {voted = true, index = i} - - set_difficulty() - Public.difficulty_gui() - event.element.parent.destroy() - local message = '*** ' .. player.name .. ' has voted for ' .. this.difficulties[i].name .. ' difficulty! ***' - game.print(message, this.difficulties[i].print_color) - Server.to_discord_embed(message) -end - function Public.set_tooltip(...) if type(...) == 'table' then this.tooltip = ... @@ -358,9 +320,94 @@ function Public.get(key) end end +Gui.on_click( + selection_button_name, + function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Poll difficulty selection frame name') + if is_spamming then + return + end + local element = event.element + if not element or not element.valid then + return + end + + local player = event.player + if not player or not player.valid or not player.character then + return + end + + local i = tonumber(element.parent.name) + + if this.difficulty_player_votes[player.name] and this.difficulty_player_votes[player.name].index == i then + player.print('You have already voted for ' .. this.difficulties[i].name .. '.', this.difficulties[i].print_color) + clear_main_frame(player) + return + end + + if this.difficulty_player_votes[player.name] then + local index = this.difficulty_player_votes[player.name].index + this.difficulties[index].count = this.difficulties[index].count - 1 + if this.difficulties[index].count <= 0 then + this.difficulties[index].count = 0 + end + end + + this.difficulties[i].count = this.difficulties[i].count + 1 + this.difficulty_player_votes[player.name] = {voted = true, index = i} + + set_difficulty() + Public.difficulty_gui() + clear_main_frame(player) + local message = '*** ' .. player.name .. ' has voted for ' .. this.difficulties[i].name .. ' difficulty! ***' + game.print(message, this.difficulties[i].print_color) + Server.to_discord_embed(message) + end +) + +Gui.on_click( + top_button_name, + function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Poll difficulty top button') + if is_spamming then + return + end + local player = event.player + if not player or not player.valid or not player.character then + return + end + if game.tick > this.difficulty_poll_closing_timeout then + clear_main_frame(player) + return + end + local screen = player.gui.center + if screen[main_frame_name] and screen[main_frame_name].valid then + clear_main_frame(player) + else + poll_difficulty(player) + end + end +) + +Gui.on_click( + close_main_frame, + function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Poll difficulty close button') + if is_spamming then + return + end + local player = event.player + if not player or not player.valid or not player.character then + return + end + clear_main_frame(player) + end +) + Event.add(defines.events.on_player_created, on_player_joined_game) Event.add(defines.events.on_player_joined_game, on_player_joined_game) Event.add(defines.events.on_player_left_game, on_player_left_game) -Event.add(defines.events.on_gui_click, on_gui_click) + +Public.top_button_name = top_button_name return Public diff --git a/modules/map_info.lua b/modules/map_info.lua index 00d5823f..05d21730 100644 --- a/modules/map_info.lua +++ b/modules/map_info.lua @@ -1,10 +1,9 @@ local Event = require 'utils.event' local Global = require 'utils.global' -local Tabs = require 'comfy_panel.main' -local SpamProtection = require 'utils.spam_protection' +local Gui = require 'utils.gui' local Token = require 'utils.token' -local module_name = 'Map Info' +local module_name = Gui.uid_name() local map_info = { localised_category = false, @@ -85,14 +84,6 @@ local function create_map_intro(data) l_3.style.minimal_width = 780 l_3.style.horizontal_align = 'center' l_3.style.vertical_align = 'center' - - local b = frame.add {type = 'button', caption = 'CLOSE', name = 'close_map_intro'} - b.style.font = 'heading-2' - b.style.padding = 2 - b.style.top_margin = 3 - b.style.left_margin = 333 - b.style.horizontal_align = 'center' - b.style.vertical_align = 'center' end local create_map_intro_token = Token.register(create_map_intro) @@ -100,52 +91,20 @@ local create_map_intro_token = Token.register(create_map_intro) local function on_player_joined_game(event) local player = game.players[event.player_index] if player.online_time == 0 then - Tabs.comfy_panel_call_tab(player, 'Map Info') + Gui.call_existing_tab(player, 'Map Info') end end -local function on_gui_click(event) - if not event then - return - end - local player = game.get_player(event.player_index) - if not (player and player.valid) then - return - end - - if not event.element then - return - end - if not event.element.valid then - return - end - - local name = event.element.name - - if not name then - return - end - - if name == 'tab_' .. module_name then - local is_spamming = SpamProtection.is_spamming(player, nil, 'Map Info Main Button') - if is_spamming then - return - end - end - - if name == 'close_map_intro' then - local is_spamming = SpamProtection.is_spamming(player, nil, 'Map Info Close Button') - if is_spamming then - return - end - player.gui.left.comfy_panel.destroy() - return - end -end - -Tabs.add_tab_to_gui({name = module_name, id = create_map_intro_token, admin = false}) +Gui.add_tab_to_gui({name = module_name, caption = 'Map Info', id = create_map_intro_token, admin = false}) Event.add(defines.events.on_player_joined_game, on_player_joined_game) -Event.add(defines.events.on_gui_click, on_gui_click) + +Gui.on_click( + module_name, + function(event) + local player = event.player + Gui.reload_active_tab(player) + end +) return Public diff --git a/modules/rewards.lua b/modules/rewards.lua index 660cab9c..278574fc 100644 --- a/modules/rewards.lua +++ b/modules/rewards.lua @@ -5,7 +5,7 @@ local Event = require 'utils.event' local Token = require 'utils.token' local Task = require 'utils.task' -local Score = require 'comfy_panel.score' +local Score = require 'utils.gui.score' local floor = math.floor local sqrt = math.sqrt local insert = table.insert @@ -197,14 +197,10 @@ local function reward_messages(data) end local print_text = '' - player.surface.create_entity( - {name = 'flying-text', position = {player.position.x, player.position.y}, text = 'Reached Combat Level: ' .. data.next_level, color = {r = 0.2, g = 1.0, b = 0.1}} - ) + player.surface.create_entity({name = 'flying-text', position = {player.position.x, player.position.y}, text = 'Reached Combat Level: ' .. data.next_level, color = {r = 0.2, g = 1.0, b = 0.1}}) -- Loop through all of the rewards for this level and print out flying text for i = 1, #item_rewards, 1 do - player.surface.create_entity( - {name = 'flying-text', position = {player.position.x, player.position.y + (i * 0.5)}, text = item_rewards[i].text, color = {r = 1.0, g = 1.0, b = 1.0}} - ) + player.surface.create_entity({name = 'flying-text', position = {player.position.x, player.position.y + (i * 0.5)}, text = item_rewards[i].text, color = {r = 1.0, g = 1.0, b = 1.0}}) if i > 1 then print_text = item_rewards[i].text .. ' ' .. print_text else diff --git a/modules/rpg.lua b/modules/rpg.lua index d47ef18a..91cd8657 100644 --- a/modules/rpg.lua +++ b/modules/rpg.lua @@ -17,7 +17,7 @@ local math_random = math.random local math_sqrt = math.sqrt local math_floor = math.floor local Global = require 'utils.global' -local Tabs = require 'comfy_panel.main' +local Tabs = require 'utils.gui' local P = require 'utils.player_modifiers' local visuals_delay = 1800 local level_up_floating_text_color = {0, 205, 0} @@ -251,7 +251,7 @@ local function draw_gui(player, forced) end end - Tabs.comfy_panel_clear_gui(player) + Tabs.clear_all_active_frames(player) if player.gui.left.rpg then player.gui.left.rpg.destroy() diff --git a/modules/rpg/gui.lua b/modules/rpg/gui.lua index 0d54ba62..dc979c5b 100644 --- a/modules/rpg/gui.lua +++ b/modules/rpg/gui.lua @@ -1,4 +1,4 @@ -local ComfyGui = require 'comfy_panel.main' +local ComfyGui = require 'utils.gui' local Session = require 'utils.datastore.session_data' local P = require 'utils.player_modifiers' local Gui = require 'utils.gui' @@ -15,6 +15,7 @@ local experience_levels = Public.experience_levels --RPG Frames local main_frame_name = Public.main_frame_name local draw_main_frame_name = Public.draw_main_frame_name +local close_main_frame_name = Public.close_main_frame_name local settings_button_name = Public.settings_button_name local settings_frame_name = Public.settings_frame_name local discard_button_name = Public.discard_button_name @@ -102,20 +103,6 @@ local function add_gui_stat(element, value, width, tooltip, name, color) return e end -local function add_elem_stat(element, value, width, height, font, tooltip, name, color) - local e = element.add({type = 'sprite-button', name = name or nil, caption = value}) - e.tooltip = tooltip or '' - e.style.maximal_width = width - e.style.minimal_width = width - e.style.maximal_height = height - e.style.minimal_height = height - e.style.font = font or 'default-bold' - e.style.horizontal_align = 'center' - e.style.vertical_align = 'center' - e.style.font_color = color or {222, 222, 222} - return e -end - local function add_gui_increase_stat(element, name, player) local rpg_t = Public.get_value_from_player(player.index) local sprite = 'virtual-signal/signal-red' @@ -147,9 +134,9 @@ local function add_separator(element, width) return e end -local function remove_settings_frame(settings_frame) - Gui.remove_data_recursively(settings_frame) - settings_frame.destroy() +local function remove_target_frame(target_frame) + Gui.remove_data_recursively(target_frame) + target_frame.destroy() end local function remove_main_frame(main_frame, screen) @@ -158,7 +145,7 @@ local function remove_main_frame(main_frame, screen) local settings_frame = screen[settings_frame_name] if settings_frame and settings_frame.valid then - remove_settings_frame(settings_frame) + remove_target_frame(settings_frame) end end @@ -167,15 +154,8 @@ local function draw_main_frame(player, location) return end - local main_frame = - player.gui.screen.add( - { - type = 'frame', - name = main_frame_name, - caption = 'RPG', - direction = 'vertical' - } - ) + local main_frame, inside_frame = Gui.add_main_frame_with_toolbar(player, 'screen', main_frame_name, settings_button_name, close_main_frame_name, 'RPG') + if location then main_frame.location = location else @@ -186,23 +166,8 @@ local function draw_main_frame(player, location) local rpg_extra = Public.get('rpg_extra') local rpg_t = Public.get_value_from_player(player.index) - local inside_frame = - main_frame.add { - type = 'frame', - style = 'deep_frame_in_shallow_frame' - } - local inside_frame_style = inside_frame.style - inside_frame_style.padding = 0 - inside_frame_style.maximal_height = 800 - - local inside_table = - inside_frame.add { - type = 'table', - column_count = 1 - } - local scroll_pane = - inside_table.add { + inside_frame.add { type = 'scroll-pane', vertical_scroll_policy = 'never', horizontal_scroll_policy = 'never' @@ -222,8 +187,6 @@ local function draw_main_frame(player, location) local rank = add_gui_stat(main_table, get_class(player), 200, ({'rpg_gui.class_info', get_class(player)})) rank.style.font = 'default-large-bold' - add_elem_stat(main_table, ({'rpg_gui.settings_name'}), 200, 35, nil, ({'rpg_gui.settings_frame'}), settings_button_name) - add_separator(scroll_pane, 400) --!sub top table @@ -286,12 +249,7 @@ local function draw_main_frame(player, location) add_gui_description(left_bottom_table, ({'rpg_gui.life_name'}), w1, ({'rpg_gui.life_tooltip'})) local health_gui = add_gui_stat(left_bottom_table, floor(player.character.health), w2, ({'rpg_gui.life_increase'})) data.health = health_gui - add_gui_stat( - left_bottom_table, - floor(player.character.prototype.max_health + player.character_health_bonus + player.force.character_health_bonus), - w2, - ({'rpg_gui.life_maximum'}) - ) + add_gui_stat(left_bottom_table, floor(player.character.prototype.max_health + player.character_health_bonus + player.force.character_health_bonus), w2, ({'rpg_gui.life_maximum'})) local shield = 0 local shield_max = 0 @@ -487,7 +445,7 @@ function Public.toggle(player, recreate) if main_frame then remove_main_frame(main_frame, screen) else - ComfyGui.comfy_panel_clear_gui(player) + ComfyGui.clear_all_active_frames(player) draw_main_frame(player) end end @@ -661,7 +619,7 @@ Gui.on_click( end end - remove_settings_frame(event.element) + remove_target_frame(event.element) if player.gui.screen[main_frame_name] then toggle(player, true) @@ -690,6 +648,30 @@ Gui.on_click( end ) +Gui.on_click( + close_main_frame_name, + function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'RPG Close Button') + if is_spamming then + return + end + local player = event.player + local screen = player.gui.screen + if not player or not player.valid or not player.character then + return + end + + local main_frame = screen[main_frame_name] + if main_frame and main_frame.valid then + remove_target_frame(main_frame) + end + local settings_frame = screen[settings_frame_name] + if settings_frame and settings_frame.valid then + remove_target_frame(settings_frame) + end + end +) + Gui.on_click( settings_button_name, function(event) diff --git a/modules/rpg/main.lua b/modules/rpg/main.lua index dcf3522e..b7a9f735 100644 --- a/modules/rpg/main.lua +++ b/modules/rpg/main.lua @@ -3,7 +3,6 @@ local Public = require 'modules.rpg.core' local Gui = require 'utils.gui' local Event = require 'utils.event' local AntiGrief = require 'utils.antigrief' -local Color = require 'utils.color_presets' local SpamProtection = require 'utils.spam_protection' local BiterHealthBooster = require 'modules.biter_health_booster_v2' local Explosives = require 'modules.explosives' @@ -1154,8 +1153,6 @@ local function on_player_used_capsule(event) return end - local p = player.print - if rpg_t.last_spawned >= game.tick then return Public.cast_spell(player, true) end diff --git a/modules/rpg/table.lua b/modules/rpg/table.lua index 52686f16..57acf98c 100644 --- a/modules/rpg/table.lua +++ b/modules/rpg/table.lua @@ -15,6 +15,7 @@ local settings_frame_name = Gui.uid_name() local save_button_name = Gui.uid_name() local discard_button_name = Gui.uid_name() local draw_main_frame_name = Gui.uid_name() +local close_main_frame_name = Gui.uid_name() local main_frame_name = Gui.uid_name() local settings_button_name = Gui.uid_name() local spell_gui_button_name = Gui.uid_name() @@ -515,6 +516,7 @@ Public.settings_frame_name = settings_frame_name Public.save_button_name = save_button_name Public.discard_button_name = discard_button_name Public.draw_main_frame_name = draw_main_frame_name +Public.close_main_frame_name = close_main_frame_name Public.main_frame_name = main_frame_name Public.settings_button_name = settings_button_name Public.spell_gui_button_name = spell_gui_button_name diff --git a/utils/datastore/current_time_data.lua b/utils/datastore/current_time_data.lua index 1e5d4339..7ab8f624 100644 --- a/utils/datastore/current_time_data.lua +++ b/utils/datastore/current_time_data.lua @@ -1,6 +1,6 @@ local Server = require 'utils.server' local Event = require 'utils.event' -local ComfyGui = require 'comfy_panel.main' +local Gui = require 'utils.gui' local Color = require 'utils.color_presets' local current_time_label = 'current_time_label' @@ -111,7 +111,7 @@ commands.add_command( end ) -ComfyGui.screen_to_bypass(current_time_label) +Gui.screen_to_bypass(current_time_label) Event.add( defines.events.on_player_display_resolution_changed, diff --git a/utils/datastore/server_ups_data.lua b/utils/datastore/server_ups_data.lua index 9d582376..a05e33f7 100644 --- a/utils/datastore/server_ups_data.lua +++ b/utils/datastore/server_ups_data.lua @@ -1,6 +1,6 @@ local Server = require 'utils.server' local Event = require 'utils.event' -local ComfyGui = require 'comfy_panel.main' +local Gui = require 'utils.gui' local Color = require 'utils.color_presets' local ups_label = 'ups_label' @@ -106,7 +106,7 @@ commands.add_command( end ) -ComfyGui.screen_to_bypass(ups_label) +Gui.screen_to_bypass(ups_label) Event.add( defines.events.on_player_display_resolution_changed, diff --git a/utils/files/arrow-down.png b/utils/files/arrow-down.png new file mode 100644 index 0000000000000000000000000000000000000000..ad7f39f9fd9a0c1ae835e517819761d3ed584c49 GIT binary patch literal 364 zcmV-y0h9iTP)Px$CP_p=R5(w~lRZwuKoCaXY-n=Rm}h~!->>I zS>F5vQPnN5A%{RZRg>{4B^`BH9Ea@p`)!PIGYT?8pLK_`D&vOZ9Ch&tlFXLOS!`ee zMk|#h_4&jFqO^y2xSP-6<@M}VpvsD2bcn6@%k@w*2^tzmkO44FG}ux$bsLD# zdhgdFl1shUOhV`y%vGr>lc^8cP%vnhrC&?m@o|yNkS=KB7~e@srmo2|nMd)LO&ljN zT$LPo8Z0q(MNwX-vEP5@Z&x{la49CMNF<6po_qgrY(M_~Uw8wLNrJTaBeUE90000< KMNUMnLSTZFxtk9F literal 0 HcmV?d00001 diff --git a/utils/files/arrow-up.png b/utils/files/arrow-up.png new file mode 100644 index 0000000000000000000000000000000000000000..19f6820254c5da9ed5f842f7b7c9e07817c85762 GIT binary patch literal 373 zcmV-*0gC>KP)Px$FG)l}R5(wyk}*=lFc3xmDrvX_mPo~UQc}@+!T}5?Ai02}mWndxp>kH?76g4p zicJ&@GnvWY!X8`u-~PW|!G)JxsK=jxE_8Q>W)2vL>^IiVUVm#g0uYqYg%$=iK}g?& zK}-Sriu{Q1_QozsNCBXzh8AFb=r9}+nR2Z3*13fM*-8FP zLPF3MKrc>bk}HOLX0mrr@pg8A2uRToS_1V+o(R8>`)6DM(~s#Bh#D#W(T%s(E=09k zljd8Tv&&@VT=iHEYp1%5K$C0@j0kv9)ubshnvr+_=}wo3XomMJQ{AQ!I%T^1lU|V_j1l=>bu^@Ps|bV_J6Bf~$PJG4 z*~MO9TVW+zqj&TZ<5;<5d!zKdgpV?PVqNBtrJC3N+$kN#ZM-iuoet(=zsGAl#pk0! zbA|5Nj+l3_vDg2A*w>+Gqn&6lGf|;BXvMayiD&)?KHy{X3)Y~)KZoB(T{VEnT_Rfm O0000Px%pGibPR9HvlmcMHhK@`WoZ`M;RBC%6$W|jydDo7yqf{27@sf7e2l|)cP{8jl6 z94M#=N(zaE5X2M)Nogw~R7dL`vn*pu$DQ12e ziwNdHN7N1AexoSY(onxP4(AH{!f^U?E`Xv^LxS-r)+VB1W|&f-pSw)T<`t$(p@)Mdkf}I*4l#rTrPn4 zW2Mz79L}cPH?JCFZsqQRSfHn;$FEc>ZyD&WZ8R%O-Mj!RPxaeJHr!{iaRr@nE|xcBhI-4MC377$F2QV%0iYI zKq)l|pg(R25>yI;;6`Tv;%cP-9l#?h&20V>$Vq@|HQYtp>bO5X^L_2y0!? z0RSoG1tPi!pb|NEd@c-MZfYCiG(7c6O#qlO#$3x{p87D#YLfehPx%#z{m$R9HvVmd|SwK@`WoZ#J!Zk(MH)WM(UrASy_qUc4xXNU0vZNI`m%3W|uo zPW}S{1rR=raPM)JSe4NOVgbvo86R6E!|B5S)9wxFf;Fc z_WOS95>g(NvVZ)409xxj5lt}jX#fg96~F>B&vbWpKgwpaKblcBu>#C&Rb2O$0d4@; z1u(ElKn8vaqAOC$CrKd^1L(582ZKuy#|{kUATR{5tiv!E1Uj#jnoI(b2*545r;Nof z2@oJ!Vq-46Szdl|w6CwHTJ`P#W^BV*Ak3dNtPKsS!LM-;u>j00Dz5w10K)**gb>F8 ztQcb+f^fL@!qLGD5P^xOY-x|T4NxkT_FI-U9|ruXWm%U!&-(x%8)JM468(zQ%68{s z6>wem3^P9ujf^pK4-q{Glnx`lN&otiXy-mD_k3v!!1?ZsQ-&Vk$Cc0CqRt_@^anvuZ{L@&g}}SdJ~js1d&> zWHOn%%zPqfHw{Tqg~4>!j;^cCe2|&~s0qz1%H{GQ0HXjTGp`fTf>|-McHaJ$} za=8uzXkA380Dyu@O@W{dqyXS6z!(XBM?^uXj)%Z00u29bx(hHQUZnp30000< KMNUMnLSTX#h)qQR literal 0 HcmV?d00001 diff --git a/utils/files/settings-black.png b/utils/files/settings-black.png new file mode 100644 index 0000000000000000000000000000000000000000..80b8d27789f19982a51e144b70b493fae502804e GIT binary patch literal 1237 zcmV;`1SPx(k4Z#9R9HvtR!wMJRTTcteMuNfW+5^nnfEhElUf3bF;<#VN}+<5u8M|c;Y#R6 z1WAinHyYhESV~c_n}RDBl}J}E8l(_{wxKmHrxMd7^X{7(GJ;^NBu(Eva_@U@=1npa zClV=wcNQ~q@44rG=kGg*@R%1p=J)a61MrOJb+0jBVCH@Xo&umis1WEb5xrX~l@@p6 z)g61lahy|Nz6v6M0qw*13l^-ACAsv~zYL&o3J9+zk1)eviPwmfa@PP*Y??OEtXwYF zxhJz{Od&jLOy9aL%C)sIR4RYej+ih;gfXZ_7aD3A92{(4sjN%@c(P6L*~K8ZlXu-W z1oL??@=O3}(?N)SN1-r_P$tm(zVCl&+x7t>x(MJmna#eAV)5Z-5Dfuz+4gyh=$sK| zlVm@FF$nz}C63W&3?^#i3k_)&;1>WAMh(+vLEyjhw*Y#3y@B<0HN%V!GNwgl#r7Hu zvB^5y=VIgcF{4`}i7cw!tEDJ5I*5ku`TlGg#1;=Yj&lvb$#jY{7!+GBK+~ZL&y~yN z+W^8?nU(kQF9{aoP<+I|Fq+e`F_M!~%Ht`7_1-HK_7}qN!5qNt=_E4%^oPV1-!Hud z;8CN50?_8V?q$V%I$dZr zH$q}biXVt*)c5`Gw#@;3*x%pZvAVii0`PR~iN%9b_D$4czAcVnz`Er)KNHX$ zr7)H|v(hUT(OMbC05qAjM=$ZDl)=(?6!BtFf4mUhk(1I`oVIx)ez+K`GZ1; zPXHWF5iFDvhsxzrYe|^*hJ;WzH!;EOP>9j{rIOiiSOu=z^D?W4le!FJFQ@E}xkU~W&CEDeN+uK2#+l!!D3EO_o^ zrTBExpsHLLv2!Rw@oedr(%pt0(3_s)TnmAd5&OqQWVlm9G5@EPQjMutiE(3jR5@`3 z>*)AfDWy)#YKz~}3p}rPK&kZ^20HX%?K2?epsCLAty+%`6{X`T&HiC2qzyJenabNme2J-FA z<n#C@g)B4ireDkDI=xKhV+D*RVK#jx36#L4wLjNBsML*Q5EuqwqT0Ia zF#NNr7^n`VwS)s;(TH5yy`glox6FStmKy+3QkvPLmZ`fs6*mOnx_v#&YZn0Q2RH|Y zAR&Hb=AVe@jPLsk4KFs?+;IqYqP!K^{{j33U)bj`USYw500000NkvXXu0mjfvbIj8 literal 0 HcmV?d00001 diff --git a/utils/files/settings-white.png b/utils/files/settings-white.png new file mode 100644 index 0000000000000000000000000000000000000000..ca2315ddf5594f2af554e29e25b7ed38bfe9cdec GIT binary patch literal 1183 zcmV;Q1YrA#P)Px(SxH1eR9HvVR!wLeWf*?mZ?>Bpx;-W-GqbZ10>UCF*q`_l1igr$U?uIrlhBI@ zQbmjxtzH@|QV{G#@Z=#{J%|c==p|@UW9n@c3c7zYspi;KOg1~;TfU!}9k#pft~CUQ zU3T`HZ@%yOp7(v9=OrBQMF+e;{(k^!wc0E>&P4)FffN21MEv<*F~4?isZFMb!%y@-J2SIQ>3*rt28jU8CI)Yi-{+fi-%L`g1j+b0_V}och)=M)x z^(Z>-Ff9XeAsd};sMI_{(f5R^*))f;XsXp}Dd#vhKseMrjip&1g+KJX;)_Jo>6cK< zoC_O`%Mjvhni2LO2B`YVau5VR_XW_bHJ@Y$UlCYn0Bp}qy5Lql&wqT-=9#R|g<*IV zfMFtYF(3(e%J= zHYLk*K@fcRk2#SkZ-D?mGc)ph-A|3N#m&%D|7@!zHc_D?=JwhBvF#QYYu!0E`gb zdC8$d)Cj}N0yvx0uaRskYl7mq6W>=Vm3|qh1F00J%H9J+V3nAbT-V)5%2JhG6xENj zbe2K9pki)!O^qv&b>H`da;bp;5;Fpj*AAe(-nwAozF9X+lO&mx@sPx>ZO_n=EFKF2 z_xqtj)U4N+A;jwzK+IrAm6S24ZUd54%8WT0@ih9;0ddai$p?PXf2lXD0~?Z=nVHX| zY|5CM40^SqC?wzlq%WBHRHeEs*%&Z)V% zIjyck889bc2g*D$@v3ZZA1>^)-y!02x +---@param frame +function Public.add_mod_button(player, frame) + if Public.get_button_flow(player)[frame.name] and Public.get_button_flow(player)[frame.name].valid then + return + end + + Public.get_button_flow(player).add(frame) +end + +---@param state +--- If we should use the new mod gui or not +function Public.set_mod_gui_top_frame(state) + settings.mod_gui_top_frame = state or false +end + +--- Get mod_gui_top_frame +function Public.get_mod_gui_top_frame() + return settings.mod_gui_top_frame +end + +--- This adds the given gui to the main gui. +---@param tbl +function Public.add_tab_to_gui(tbl) + if not tbl then + return + end + + if not tbl.name then + return + end + + if not tbl.caption then + return + end + + if not tbl.id then + return + end + + local admin = tbl.admin or false + local only_server_sided = tbl.only_server_sided or false + + if not main_gui_tabs[tbl.caption] then + main_gui_tabs[tbl.caption] = {id = tbl.id, name = tbl.name, admin = admin, only_server_sided = only_server_sided} + else + error('Given name: ' .. tbl.caption .. ' already exists in table.') + end +end + +function Public.screen_to_bypass(elem) + screen_elements[elem] = true + return screen_elements +end + +--- Fetches the main gui tabs. You are forbidden to write as this is local. +---@param key +function Public.get(key) + if key then + return main_gui_tabs[key] + else + return main_gui_tabs + end +end + +function Public.clear_main_frame(player) + if not player then + return + end + local frame = Public.get_main_frame(player) + if frame then + frame.destroy() + end +end + +function Public.clear_all_active_frames(player) + for _, child in pairs(player.gui.left.children) do + child.destroy() + end + for _, child in pairs(player.gui.screen.children) do + if not screen_elements[child.name] then + child.destroy() + end + end +end + +function Public.get_player_active_frame(player) + local main_frame = Public.get_main_frame(player) + if not main_frame then + return false + end + + local panel = main_frame.tabbed_pane + if not panel then + return + end + local index = panel.selected_tab_index + if not index then + return panel.tabs[1].content + end + + return panel.tabs[index].content +end + +local function get_player_active_tab(player) + local main_frame = Public.get_main_frame(player) + if not main_frame then + return false + end + + local panel = main_frame.tabbed_pane + if not panel then + return + end + local index = panel.selected_tab_index + if not index then + return panel.tabs[1].tab, panel.tabs[1].content + end + + return panel.tabs[index].tab, panel.tabs[index].content +end + +function Public.reload_active_tab(player, forced) + local is_spamming = SpamProtection.is_spamming(player, nil, 'Reload active tab') + if is_spamming and not forced then + return + end + + local frame, main_tab = get_player_active_tab(player) + if not frame then + return + end + + local tab = main_gui_tabs[frame.caption] + if not tab then + return + end + local id = tab.id + if not id then + return + end + local func = Token.get(id) + + local d = { + player = player, + frame = main_tab + } + + return func(d) +end + +local function top_button(player) + if settings.mod_gui_top_frame then + Public.add_mod_button(player, {type = 'sprite-button', name = main_button_name, sprite = 'item/raw-fish'}) + else + if player.gui.top[main_button_name] then + return + end + local button = player.gui.top.add({type = 'sprite-button', name = main_button_name, sprite = 'item/raw-fish'}) + button.style.minimal_height = 38 + button.style.maximal_height = 38 + button.style.minimal_width = 40 + button.style.padding = -2 + end +end + +local function draw_main_frame(player) + local tabs = main_gui_tabs + Public.clear_all_active_frames(player) + + if Public.get_main_frame(player) then + Public.get_main_frame(player).destroy() + end + + local frame, inside_frame = Public.add_main_frame_with_toolbar(player, 'left', main_frame_name, _, close_button_name, 'Comfy Panel') + + local tabbed_pane = inside_frame.add({type = 'tabbed-pane', name = 'tabbed_pane'}) + + for name, func in pairs(tabs) do + if func.only_server_sided then + local secs = Server.get_current_time() + if secs then + local tab = tabbed_pane.add({type = 'tab', caption = name, name = func.name}) + local name_frame = tabbed_pane.add({type = 'frame', name = name, direction = 'vertical'}) + name_frame.style.minimal_height = 480 + name_frame.style.maximal_height = 480 + name_frame.style.minimal_width = 800 + name_frame.style.maximal_width = 800 + tabbed_pane.add_tab(tab, name_frame) + end + elseif func.admin == true then + if player.admin then + local tab = tabbed_pane.add({type = 'tab', caption = name, name = func.name}) + local name_frame = tabbed_pane.add({type = 'frame', name = name, direction = 'vertical'}) + name_frame.style.minimal_height = 480 + name_frame.style.maximal_height = 480 + name_frame.style.minimal_width = 800 + name_frame.style.maximal_width = 800 + tabbed_pane.add_tab(tab, name_frame) + end + else + local tab = tabbed_pane.add({type = 'tab', caption = name, name = func.name}) + local name_frame = tabbed_pane.add({type = 'frame', name = name, direction = 'vertical'}) + name_frame.style.minimal_height = 480 + name_frame.style.maximal_height = 480 + name_frame.style.minimal_width = 800 + name_frame.style.maximal_width = 800 + tabbed_pane.add_tab(tab, name_frame) + end + end + + for _, child in pairs(tabbed_pane.children) do + child.style.padding = 8 + child.style.left_padding = 2 + child.style.right_padding = 2 + end + + Public.reload_active_tab(player, true) + return frame, inside_frame +end + +function Public.call_existing_tab(player, name) + local frame, inside_frame = draw_main_frame(player) + if not frame then + return + end + local tabbed_pane = inside_frame.tabbed_pane + for key, v in pairs(tabbed_pane.tabs) do + if v.tab.caption == name then + tabbed_pane.selected_tab_index = key + Public.reload_active_tab(player, true) + end + end +end + -- Register a handler for the on_gui_checked_state_changed event for LuaGuiElements with element_name. -- Can only have one handler per element name. -- Guarantees that the element and the player are valid when calling the handler. -- Adds a player field to the event table. -Gui.on_checked_state_changed = handler_factory(defines.events.on_gui_checked_state_changed) +Public.on_checked_state_changed = handler_factory(defines.events.on_gui_checked_state_changed) -- Register a handler for the on_gui_click event for LuaGuiElements with element_name. -- Can only have one handler per element name. -- Guarantees that the element and the player are valid when calling the handler. -- Adds a player field to the event table. -Gui.on_click = handler_factory(defines.events.on_gui_click) +Public.on_click = handler_factory(defines.events.on_gui_click) -- Register a handler for the on_gui_closed event for a custom LuaGuiElements with element_name. -- Can only have one handler per element name. -- Guarantees that the element and the player are valid when calling the handler. -- Adds a player field to the event table. -Gui.on_custom_close = handler_factory(defines.events.on_gui_closed) +Public.on_custom_close = handler_factory(defines.events.on_gui_closed) -- Register a handler for the on_gui_elem_changed event for LuaGuiElements with element_name. -- Can only have one handler per element name. -- Guarantees that the element and the player are valid when calling the handler. -- Adds a player field to the event table. -Gui.on_elem_changed = handler_factory(defines.events.on_gui_elem_changed) +Public.on_elem_changed = handler_factory(defines.events.on_gui_elem_changed) -- Register a handler for the on_gui_selection_state_changed event for LuaGuiElements with element_name. -- Can only have one handler per element name. -- Guarantees that the element and the player are valid when calling the handler. -- Adds a player field to the event table. -Gui.on_selection_state_changed = handler_factory(defines.events.on_gui_selection_state_changed) +Public.on_selection_state_changed = handler_factory(defines.events.on_gui_selection_state_changed) -- Register a handler for the on_gui_text_changed event for LuaGuiElements with element_name. -- Can only have one handler per element name. -- Guarantees that the element and the player are valid when calling the handler. -- Adds a player field to the event table. -Gui.on_text_changed = handler_factory(defines.events.on_gui_text_changed) +Public.on_text_changed = handler_factory(defines.events.on_gui_text_changed) -- Register a handler for the on_gui_value_changed event for LuaGuiElements with element_name. -- Can only have one handler per element name. -- Guarantees that the element and the player are valid when calling the handler. -- Adds a player field to the event table. -Gui.on_value_changed = handler_factory(defines.events.on_gui_value_changed) +Public.on_value_changed = handler_factory(defines.events.on_gui_value_changed) -- Register a handler for when the player shows the top LuaGuiElements with element_name. --- Assuming the element_name has been added with Gui.allow_player_to_toggle_top_element_visibility. +-- Assuming the element_name has been added with Public.allow_player_to_toggle_top_element_visibility. -- Can only have one handler per element name. -- Guarantees that the element and the player are valid when calling the handler. -- Adds a player field to the event table. -Gui.on_player_show_top = custom_handler_factory(on_visible_handlers) +Public.on_player_show_top = custom_handler_factory(on_visible_handlers) -- Register a handler for when the player hides the top LuaGuiElements with element_name. --- Assuming the element_name has been added with Gui.allow_player_to_toggle_top_element_visibility. +-- Assuming the element_name has been added with Public.allow_player_to_toggle_top_element_visibility. -- Can only have one handler per element name. -- Guarantees that the element and the player are valid when calling the handler. -- Adds a player field to the event table. -Gui.on_pre_player_hide_top = custom_handler_factory(on_pre_hidden_handlers) +Public.on_pre_player_hide_top = custom_handler_factory(on_pre_hidden_handlers) if _DEBUG then local concat = table.concat local names = {} - Gui.names = names + Public.names = names - function Gui.uid_name() + function Public.uid_name() local info = debug.getinfo(2, 'Sl') local filepath = info.source:match('^.+/currently%-playing/(.+)$'):sub(1, -5) local line = info.currentline @@ -284,7 +665,7 @@ if _DEBUG then return token end - function Gui.set_data(element, value) + function Public.set_data(element, value) local player_index = element.player_index local values = data[player_index] @@ -311,18 +692,66 @@ if _DEBUG then element_map[index] = element end end - set_data = Gui.set_data + set_data = Public.set_data - function Gui.data() + function Public.data() return data end - function Gui.element_map() + function Public.element_map() return element_map end end -Gui.get_button_flow = mod_gui.get_button_flow -Gui.mod_button = mod_gui.get_button_flow +Public.get_button_flow = mod_gui.get_button_flow +Public.mod_button = mod_gui.get_button_flow -return Gui +Public.on_click( + main_button_name, + function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Main button') + if is_spamming then + return + end + local player = event.player + local frame = Public.get_parent_frame(player) + if frame then + frame.destroy() + else + draw_main_frame(player) + end + end +) + +Public.on_click( + close_button_name, + function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Main button') + if is_spamming then + return + end + local player = event.player + local frame = Public.get_parent_frame(player) + if frame then + frame.destroy() + end + end +) + +Event.add( + defines.events.on_player_created, + function(event) + local player = game.get_player(event.player_index) + top_button(player) + end +) + +Event.add( + defines.events.on_player_joined_game, + function(event) + local player = game.get_player(event.player_index) + top_button(player) + end +) + +return Public diff --git a/comfy_panel/admin.lua b/utils/gui/admin.lua similarity index 95% rename from comfy_panel/admin.lua rename to utils/gui/admin.lua index 6037f234..52f7d62a 100644 --- a/comfy_panel/admin.lua +++ b/utils/gui/admin.lua @@ -2,13 +2,13 @@ local Event = require 'utils.event' local Jailed = require 'utils.datastore.jail_data' -local Tabs = require 'comfy_panel.main' +local Gui = require 'utils.gui' local AntiGrief = require 'utils.antigrief' local SpamProtection = require 'utils.spam_protection' local Token = require 'utils.token' local lower = string.lower -local module_name = 'Admin' +local module_name = Gui.uid_name() local function admin_only_message(str) for _, player in pairs(game.connected_players) do @@ -49,10 +49,7 @@ local function bring_player(player, source_player) local pos = source_player.surface.find_non_colliding_position('character', source_player.position, 50, 1) if pos then player.teleport(pos, source_player.surface) - game.print( - player.name .. ' has been teleported to ' .. source_player.name .. '. ' .. bring_player_messages[math.random(1, #bring_player_messages)], - {r = 0.98, g = 0.66, b = 0.22} - ) + game.print(player.name .. ' has been teleported to ' .. source_player.name .. '. ' .. bring_player_messages[math.random(1, #bring_player_messages)], {r = 0.98, g = 0.66, b = 0.22}) end end @@ -67,10 +64,7 @@ local function go_to_player(player, source_player) local pos = player.surface.find_non_colliding_position('character', player.position, 50, 1) if pos then source_player.teleport(pos, player.surface) - game.print( - source_player.name .. ' is visiting ' .. player.name .. '. ' .. go_to_player_messages[math.random(1, #go_to_player_messages)], - {r = 0.98, g = 0.66, b = 0.22} - ) + game.print(source_player.name .. ' is visiting ' .. player.name .. '. ' .. go_to_player_messages[math.random(1, #go_to_player_messages)], {r = 0.98, g = 0.66, b = 0.22}) end end @@ -338,11 +332,11 @@ local function text_changed(event) local antigrief = AntiGrief.get() local player = game.get_player(event.player_index) - local frame = Tabs.comfy_panel_get_active_frame(player) + local frame = Gui.get_player_active_frame(player) if not frame then return end - if frame.name ~= module_name then + if frame.name ~= 'Admin' then return end @@ -644,15 +638,12 @@ local function on_gui_click(event) local name = event.element.name - if name == 'tab_' .. module_name then - local is_spamming = SpamProtection.is_spamming(player, nil, 'Admin tab_Admin') - if is_spamming then - return - end + local frame = Gui.get_player_active_frame(player) + if not frame then + return end - local frame = Tabs.comfy_panel_get_active_frame(player) - if not frame then + if frame.name ~= 'Admin' then return end @@ -661,10 +652,6 @@ local function on_gui_click(event) return end - if frame.name ~= module_name then - return - end - local is_spamming = SpamProtection.is_spamming(player, nil, 'Admin Gui Click') if is_spamming then return @@ -727,11 +714,11 @@ local function on_gui_selection_state_changed(event) end global.admin_panel_selected_history_index[player.name] = event.element.selected_index - local frame = Tabs.comfy_panel_get_active_frame(player) + local frame = Gui.get_player_active_frame(player) if not frame then return end - if frame.name ~= module_name then + if frame.name ~= 'Admin' then return end @@ -748,11 +735,11 @@ local function on_gui_selection_state_changed(event) end global.admin_panel_selected_player_index[player.name] = event.element.selected_index - local frame = Tabs.comfy_panel_get_active_frame(player) + local frame = Gui.get_player_active_frame(player) if not frame then return end - if frame.name ~= module_name then + if frame.name ~= 'Admin' then return end @@ -766,7 +753,15 @@ local function on_gui_selection_state_changed(event) end end -Tabs.add_tab_to_gui({name = module_name, id = create_admin_panel_token, admin = true}) +Gui.add_tab_to_gui({name = module_name, caption = 'Admin', id = create_admin_panel_token, admin = true}) + +Gui.on_click( + module_name, + function(event) + local player = event.player + Gui.reload_active_tab(player) + end +) Event.add(defines.events.on_gui_text_changed, text_changed) Event.add(defines.events.on_gui_click, on_gui_click) diff --git a/comfy_panel/bottom_frame.lua b/utils/gui/bottom_frame.lua similarity index 98% rename from comfy_panel/bottom_frame.lua rename to utils/gui/bottom_frame.lua index 3c9da0cd..0bca097b 100644 --- a/comfy_panel/bottom_frame.lua +++ b/utils/gui/bottom_frame.lua @@ -1,7 +1,6 @@ local Misc = require 'utils.commands.misc' local Event = require 'utils.event' local Global = require 'utils.global' -local ComfyGui = require 'comfy_panel.main' local Gui = require 'utils.gui' local SpamProtection = require 'utils.spam_protection' @@ -288,6 +287,6 @@ Event.add( Public.bottom_guis_frame = bottom_guis_frame Public.set_location = set_location -ComfyGui.screen_to_bypass(bottom_guis_frame) +Gui.screen_to_bypass(bottom_guis_frame) return Public diff --git a/comfy_panel/config.lua b/utils/gui/config.lua similarity index 78% rename from comfy_panel/config.lua rename to utils/gui/config.lua index 4b580c21..638f5c55 100644 --- a/comfy_panel/config.lua +++ b/utils/gui/config.lua @@ -3,14 +3,13 @@ local Event = require 'utils.event' local Color = require 'utils.color_presets' local SessionData = require 'utils.datastore.session_data' local Utils = require 'utils.core' -local Tabs = require 'comfy_panel.main' local SpamProtection = require 'utils.spam_protection' -local BottomFrame = require 'comfy_panel.bottom_frame' +local BottomFrame = require 'utils.gui.bottom_frame' local Token = require 'utils.token' local Global = require 'utils.global' local Gui = require 'utils.gui' -local module_name = 'Config' +local module_name = Gui.uid_name() local Public = {} @@ -117,14 +116,14 @@ local function trust_connected_players() end local functions = { - ['comfy_panel_spectator_switch'] = function(event) + ['spectator_switch'] = function(event) if event.element.switch_state == 'left' then game.get_player(event.player_index).spectator = true else game.get_player(event.player_index).spectator = false end end, - ['comfy_panel_bottom_location'] = function(event) + ['bottom_location'] = function(event) local player = game.get_player(event.player_index) if event.element.switch_state == 'left' then BottomFrame.set_location(player, 'bottom_left') @@ -132,7 +131,7 @@ local functions = { BottomFrame.set_location(player, 'bottom_right') end end, - ['comfy_panel_middle_location'] = function(event) + ['middle_location'] = function(event) local player = game.get_player(event.player_index) local data = BottomFrame.get_player_data(player) if event.element.switch_state == 'left' then @@ -148,7 +147,7 @@ local functions = { BottomFrame.set_location(player, data.bottom_state) end, - ['comfy_panel_portable_button'] = function(event) + ['portable_button'] = function(event) local player = game.get_player(event.player_index) local data = BottomFrame.get_player_data(player) if event.element.switch_state == 'left' then @@ -165,14 +164,14 @@ local functions = { BottomFrame.set_location(player, data.bottom_state) end, - ['comfy_panel_auto_hotbar_switch'] = function(event) + ['auto_hotbar_switch'] = function(event) if event.element.switch_state == 'left' then global.auto_hotbar_enabled[event.player_index] = true else global.auto_hotbar_enabled[event.player_index] = false end end, - ['comfy_panel_blueprint_toggle'] = function(event) + ['blueprint_toggle'] = function(event) if event.element.switch_state == 'left' then game.permissions.get_group('Default').set_allows_action(defines.input_action.open_blueprint_library_gui, true) game.permissions.get_group('Default').set_allows_action(defines.input_action.import_blueprint_string, true) @@ -183,7 +182,7 @@ local functions = { get_actor(event, '[Blueprints]', 'has disabled blueprints!') end end, - ['comfy_panel_spaghett_toggle'] = function(event) + ['spaghett_toggle'] = function(event) if event.element.switch_state == 'left' then this.gui_config.spaghett.enabled = true get_actor(event, '[Spaghett]', 'has enabled spaghett mode!') @@ -222,7 +221,7 @@ local functions = { } local poll_function = { - ['comfy_panel_poll_trusted_toggle'] = function(event) + ['poll_trusted_toggle'] = function(event) if event.element.switch_state == 'left' then this.gui_config.poll_trusted = true get_actor(event, '[Poll Mode]', 'has disabled non-trusted people to do polls.') @@ -231,8 +230,8 @@ local poll_function = { get_actor(event, '[Poll Mode]', 'has allowed non-trusted people to do polls.') end end, - ['comfy_panel_poll_no_notify_toggle'] = function(event) - local poll = is_loaded('comfy_panel.poll') + ['poll_no_notify_toggle'] = function(event) + local poll = is_loaded('utils.gui.poll') local poll_table = poll.get_no_notify_players() if event.element.switch_state == 'left' then poll_table[event.player_index] = false @@ -243,7 +242,7 @@ local poll_function = { } local antigrief_functions = { - ['comfy_panel_disable_antigrief'] = function(event) + ['disable_antigrief'] = function(event) local AG = Antigrief.get() if event.element.switch_state == 'left' then AG.enabled = true @@ -257,7 +256,7 @@ local antigrief_functions = { } local fortress_functions = { - ['comfy_panel_disable_fullness'] = function(event) + ['disable_fullness'] = function(event) local Fullness = is_loaded('modules.check_fullness') local Module = Fullness.get() if event.element.switch_state == 'left' then @@ -268,7 +267,7 @@ local fortress_functions = { get_actor(event, '[Fullness]', 'has disabled the inventory fullness function.') end end, - ['comfy_panel_offline_players'] = function(event) + ['offline_players'] = function(event) local WPT = is_loaded('maps.mountain_fortress_v3.table') local Module = WPT.get() if event.element.switch_state == 'left' then @@ -279,7 +278,7 @@ local fortress_functions = { get_actor(event, '[Offline Players]', 'has disabled the offline player function.') end end, - ['comfy_panel_collapse_grace'] = function(event) + ['collapse_grace'] = function(event) local WPT = is_loaded('maps.mountain_fortress_v3.table') local Module = WPT.get() if event.element.switch_state == 'left' then @@ -290,7 +289,7 @@ local fortress_functions = { get_actor(event, '[Collapse]', 'has disabled the collapse function. You must breach the first zone for collapse to occur!') end end, - ['comfy_panel_spill_items_to_surface'] = function(event) + ['spill_items_to_surface'] = function(event) local WPT = is_loaded('maps.mountain_fortress_v3.table') local Module = WPT.get() if event.element.switch_state == 'left' then @@ -301,7 +300,7 @@ local fortress_functions = { get_actor(event, '[Item Spill]', 'has disabled the item spillage function. Ores no longer drop to surface when mining.') end end, - ['comfy_panel_void_or_tile'] = function(event) + ['void_or_tile'] = function(event) local WPT = is_loaded('maps.mountain_fortress_v3.table') local Module = WPT.get() if event.element.switch_state == 'left' then @@ -312,7 +311,7 @@ local fortress_functions = { get_actor(event, '[Void]', 'has changes the tiles of the zones to: dark-tiles (flammable tiles)') end end, - ['comfy_panel_trusted_only_car_tanks'] = function(event) + ['trusted_only_car_tanks'] = function(event) local WPT = is_loaded('maps.mountain_fortress_v3.table') local Module = WPT.get() if event.element.switch_state == 'left' then @@ -323,7 +322,7 @@ local fortress_functions = { get_actor(event, '[Market]', 'has changed so everybody can buy car/tanks.', true) end end, - ['comfy_panel_allow_decon'] = function(event) + ['allow_decon'] = function(event) local WPT = is_loaded('maps.mountain_fortress_v3.table') if event.element.switch_state == 'left' then local limited_group = game.permissions.get_group('limited') @@ -341,7 +340,7 @@ local fortress_functions = { get_actor(event, '[Decon]', 'has disabled decon on car/tanks/trains.', true) end end, - ['comfy_panel_christmas_mode'] = function(event) + ['christmas_mode'] = function(event) local WPT = is_loaded('maps.mountain_fortress_v3.table') if event.element.switch_state == 'left' then WPT.set('winter_mode', true) @@ -422,13 +421,7 @@ local function build_config_gui(data) if player.spectator then switch_state = 'left' end - add_switch( - scroll_pane, - switch_state, - 'comfy_panel_spectator_switch', - {'gui.spectator_mode'}, - {'gui-description.spectator_mode'} - ) + add_switch(scroll_pane, switch_state, 'spectator_switch', {'gui.spectator_mode'}, {'gui-description.spectator_mode'}) scroll_pane.add({type = 'line'}) @@ -437,24 +430,18 @@ local function build_config_gui(data) if global.auto_hotbar_enabled[player.index] then switch_state = 'left' end - add_switch(scroll_pane, switch_state, 'comfy_panel_auto_hotbar_switch', 'AutoHotbar', 'Automatically fills your hotbar with placeable items.') + add_switch(scroll_pane, switch_state, 'auto_hotbar_switch', 'AutoHotbar', 'Automatically fills your hotbar with placeable items.') scroll_pane.add({type = 'line'}) end - local poll = is_loaded('comfy_panel.poll') + local poll = is_loaded('utils.gui.poll') if poll then local poll_table = poll.get_no_notify_players() switch_state = 'right' if not poll_table[player.index] then switch_state = 'left' end - add_switch( - scroll_pane, - switch_state, - 'comfy_panel_poll_no_notify_toggle', - {'gui.notify_on_polls'}, - {'gui-description.notify_on_polls'} - ) + add_switch(scroll_pane, switch_state, 'poll_no_notify_toggle', {'gui.notify_on_polls'}, {'gui-description.notify_on_polls'}) scroll_pane.add({type = 'line'}) end @@ -475,13 +462,7 @@ local function build_config_gui(data) if bottom_frame and bottom_frame.bottom_state == 'bottom_left' then switch_state = 'left' end - add_switch( - scroll_pane, - switch_state, - 'comfy_panel_bottom_location', - 'Position - bottom', - 'Toggle to select if you want the bottom button on the left side or the right side.' - ) + add_switch(scroll_pane, switch_state, 'bottom_location', 'Position - bottom', 'Toggle to select if you want the bottom button on the left side or the right side.') scroll_pane.add({type = 'line'}) @@ -489,13 +470,7 @@ local function build_config_gui(data) if bottom_frame and bottom_frame.above then switch_state = 'left' end - add_switch( - scroll_pane, - switch_state, - 'comfy_panel_middle_location', - 'Position - middle', - 'Toggle to select if you want the bottom button above the quickbar or the side of the quickbar.' - ) + add_switch(scroll_pane, switch_state, 'middle_location', 'Position - middle', 'Toggle to select if you want the bottom button above the quickbar or the side of the quickbar.') scroll_pane.add({type = 'line'}) @@ -503,13 +478,7 @@ local function build_config_gui(data) if bottom_frame and bottom_frame.portable then switch_state = 'left' end - add_switch( - scroll_pane, - switch_state, - 'comfy_panel_portable_button', - 'Position - portable', - 'Toggle to select if you want the bottom button to be portable or not.' - ) + add_switch(scroll_pane, switch_state, 'portable_button', 'Position - portable', 'Toggle to select if you want the bottom button to be portable or not.') scroll_pane.add({type = 'line'}) end @@ -529,7 +498,7 @@ local function build_config_gui(data) if game.permissions.get_group('Default').allows_action(defines.input_action.open_blueprint_library_gui) then switch_state = 'left' end - add_switch(scroll_pane, switch_state, 'comfy_panel_blueprint_toggle', 'Blueprint Library', 'Toggles the usage of blueprint strings and the library.') + add_switch(scroll_pane, switch_state, 'blueprint_toggle', 'Blueprint Library', 'Toggles the usage of blueprint strings and the library.') scroll_pane.add({type = 'line'}) @@ -545,13 +514,7 @@ local function build_config_gui(data) if this.gui_config.spaghett.enabled then switch_state = 'left' end - add_switch( - scroll_pane, - switch_state, - 'comfy_panel_spaghett_toggle', - {'gui.spaghett_mode'}, - {'gui-description.spaghett_mode'} - ) + add_switch(scroll_pane, switch_state, 'spaghett_toggle', {'gui.spaghett_mode'}, {'gui-description.spaghett_mode'}) if poll then scroll_pane.add({type = 'line'}) @@ -559,7 +522,7 @@ local function build_config_gui(data) if this.gui_config.poll_trusted then switch_state = 'left' end - add_switch(scroll_pane, switch_state, 'comfy_panel_poll_trusted_toggle', 'Poll mode', 'Disables non-trusted plebs to create polls.') + add_switch(scroll_pane, switch_state, 'poll_trusted_toggle', 'Poll mode', 'Disables non-trusted plebs to create polls.') end scroll_pane.add({type = 'line'}) @@ -577,7 +540,7 @@ local function build_config_gui(data) if AG.enabled then switch_state = 'left' end - add_switch(scroll_pane, switch_state, 'comfy_panel_disable_antigrief', 'Antigrief', 'Toggle antigrief function.') + add_switch(scroll_pane, switch_state, 'disable_antigrief', 'Antigrief', 'Toggle antigrief function.') scroll_pane.add({type = 'line'}) if is_loaded('maps.biter_battles_v2.main') then @@ -596,14 +559,7 @@ local function build_config_gui(data) if global.bb_settings.team_balancing then team_balancing_state = 'left' end - local switch = - add_switch( - scroll_pane, - team_balancing_state, - 'bb_team_balancing_toggle', - 'Team Balancing', - 'Players can only join a team that has less or equal players than the opposing.' - ) + local switch = add_switch(scroll_pane, team_balancing_state, 'bb_team_balancing_toggle', 'Team Balancing', 'Players can only join a team that has less or equal players than the opposing.') if not admin then switch.ignored_by_interaction = true end @@ -614,14 +570,7 @@ local function build_config_gui(data) if global.bb_settings.only_admins_vote then only_admins_vote_state = 'left' end - local only_admins_vote_switch = - add_switch( - scroll_pane, - only_admins_vote_state, - 'bb_only_admins_vote', - 'Admin Vote', - 'Only admins can vote for map difficulty. Clears all currently existing votes.' - ) + local only_admins_vote_switch = add_switch(scroll_pane, only_admins_vote_state, 'bb_only_admins_vote', 'Admin Vote', 'Only admins can vote for map difficulty. Clears all currently existing votes.') if not admin then only_admins_vote_switch.ignored_by_interaction = true end @@ -645,13 +594,7 @@ local function build_config_gui(data) if full.fullness_enabled then switch_state = 'left' end - add_switch( - scroll_pane, - switch_state, - 'comfy_panel_disable_fullness', - 'Inventory Fullness', - 'On = Enables inventory fullness.\nOff = Disables inventory fullness.' - ) + add_switch(scroll_pane, switch_state, 'disable_fullness', 'Inventory Fullness', 'On = Enables inventory fullness.\nOff = Disables inventory fullness.') scroll_pane.add({type = 'line'}) @@ -661,13 +604,7 @@ local function build_config_gui(data) if Module.offline_players_enabled then switch_state = 'left' end - add_switch( - scroll_pane, - switch_state, - 'comfy_panel_offline_players', - 'Offline Players', - 'On = Enables offline player inventory drop.\nOff = Disables offline player inventory drop.' - ) + add_switch(scroll_pane, switch_state, 'offline_players', 'Offline Players', 'On = Enables offline player inventory drop.\nOff = Disables offline player inventory drop.') scroll_pane.add({type = 'line'}) @@ -675,13 +612,7 @@ local function build_config_gui(data) if Module.collapse_grace then switch_state = 'left' end - add_switch( - scroll_pane, - switch_state, - 'comfy_panel_collapse_grace', - 'Collapse', - 'On = Enables collapse after wave 100.\nOff = Disables collapse - you must breach the first zone for collapse to occur.' - ) + add_switch(scroll_pane, switch_state, 'collapse_grace', 'Collapse', 'On = Enables collapse after wave 100.\nOff = Disables collapse - you must breach the first zone for collapse to occur.') scroll_pane.add({type = 'line'}) @@ -689,57 +620,33 @@ local function build_config_gui(data) if Module.spill_items_to_surface then switch_state = 'left' end - add_switch( - scroll_pane, - switch_state, - 'comfy_panel_spill_items_to_surface', - 'Spill Ores', - 'On = Enables ore spillage to surface when mining.\nOff = Disables ore spillage to surface when mining.' - ) + add_switch(scroll_pane, switch_state, 'spill_items_to_surface', 'Spill Ores', 'On = Enables ore spillage to surface when mining.\nOff = Disables ore spillage to surface when mining.') scroll_pane.add({type = 'line'}) switch_state = 'right' if Module.void_or_tile then switch_state = 'left' end - add_switch( - scroll_pane, - switch_state, - 'comfy_panel_void_or_tile', - 'Void Tiles', - 'On = Changes the tiles to out-of-map.\nOff = Changes the tiles to lab-dark-2' - ) + add_switch(scroll_pane, switch_state, 'void_or_tile', 'Void Tiles', 'On = Changes the tiles to out-of-map.\nOff = Changes the tiles to lab-dark-2') scroll_pane.add({type = 'line'}) switch_state = 'right' if Module.trusted_only_car_tanks then switch_state = 'left' end - add_switch( - scroll_pane, - switch_state, - 'comfy_panel_trusted_only_car_tanks', - 'Market Purchase', - 'On = Allows only trusted people to buy car/tanks.\nOff = Allows everyone to buy car/tanks.' - ) + add_switch(scroll_pane, switch_state, 'trusted_only_car_tanks', 'Market Purchase', 'On = Allows only trusted people to buy car/tanks.\nOff = Allows everyone to buy car/tanks.') scroll_pane.add({type = 'line'}) switch_state = 'right' if Module.allow_decon then switch_state = 'left' end - add_switch( - scroll_pane, - switch_state, - 'comfy_panel_allow_decon', - 'Deconstruct', - 'On = Allows decon on car/tanks/trains.\nOff = Disables decon on car/tanks/trains.' - ) + add_switch(scroll_pane, switch_state, 'allow_decon', 'Deconstruct', 'On = Allows decon on car/tanks/trains.\nOff = Disables decon on car/tanks/trains.') scroll_pane.add({type = 'line'}) if Module.christmas_mode then switch_state = 'left' end - add_switch(scroll_pane, switch_state, 'comfy_panel_christmas_mode', 'Wintery Mode', 'On = Enables wintery mode.\nOff = Disables wintery mode.') + add_switch(scroll_pane, switch_state, 'christmas_mode', 'Wintery Mode', 'On = Enables wintery mode.\nOff = Disables wintery mode.') scroll_pane.add({type = 'line'}) end end @@ -787,7 +694,7 @@ local function on_gui_switch_state_changed(event) end fortress_functions[event.element.name](event) return - elseif is_loaded('comfy_panel.poll') then + elseif is_loaded('utils.gui.poll') then local is_spamming = SpamProtection.is_spamming(player, nil, 'Config Poll Elem') if is_spamming then return @@ -811,35 +718,16 @@ local function on_robot_built_entity(event) spaghett_deny_building(event) end -local function on_gui_click(event) - if not event then - return - end - local player = game.get_player(event.player_index) - if not (player and player.valid) then - return - end +Gui.add_tab_to_gui({name = module_name, caption = 'Config', id = build_config_gui_token, admin = false}) - if not event.element then - return - end - if not event.element.valid then - return +Gui.on_click( + module_name, + function(event) + local player = event.player + Gui.reload_active_tab(player) end +) - local name = event.element.name - - if name == 'tab_' .. module_name then - local is_spamming = SpamProtection.is_spamming(player, nil, 'Config Main Button') - if is_spamming then - return - end - end -end - -Tabs.add_tab_to_gui({name = module_name, id = build_config_gui_token, admin = false}) - -Event.add(defines.events.on_gui_click, on_gui_click) Event.add(defines.events.on_gui_switch_state_changed, on_gui_switch_state_changed) Event.add(defines.events.on_force_created, on_force_created) Event.add(defines.events.on_built_entity, on_built_entity) diff --git a/comfy_panel/group.lua b/utils/gui/group.lua similarity index 95% rename from comfy_panel/group.lua rename to utils/gui/group.lua index 0b0658f4..c2fa9191 100644 --- a/comfy_panel/group.lua +++ b/utils/gui/group.lua @@ -1,12 +1,12 @@ -- this script adds a group button to create groups for your players -- -local Tabs = require 'comfy_panel.main' +local Gui = require 'utils.gui' local Global = require 'utils.global' local SpamProtection = require 'utils.spam_protection' local Event = require 'utils.event' local Token = require 'utils.token' -local module_name = 'Groups' +local module_name = Gui.uid_name() local this = { player_group = {}, @@ -154,7 +154,7 @@ local build_group_gui_token = Token.register(build_group_gui) local function refresh_gui() for _, p in pairs(game.connected_players) do - local frame = Tabs.comfy_panel_get_active_frame(p) + local frame = Gui.get_player_active_frame(p) if frame then if frame.name == module_name then local new_group_name = frame.frame2.group_table.new_group_name.text @@ -171,7 +171,7 @@ local function refresh_gui() local data = {player = p, frame = frame} build_group_gui(data) - frame = Tabs.comfy_panel_get_active_frame(p) + frame = Gui.get_player_active_frame(p) frame.frame2.group_table.new_group_name.text = new_group_name frame.frame2.group_table.new_group_description.text = new_group_description end @@ -235,18 +235,11 @@ local function on_gui_click(event) local name = element.name - if name and name == 'tab_' .. module_name then - local is_spamming = SpamProtection.is_spamming(player, nil, 'Groups tab_Groups') - if is_spamming then - return - end - end - - local frame = Tabs.comfy_panel_get_active_frame(player) + local frame = Gui.get_player_active_frame(player) if not frame then return end - if frame.name ~= module_name then + if frame.name ~= 'Groups' then return end @@ -380,7 +373,15 @@ function Public.reset_groups() this.tag_groups = {} end -Tabs.add_tab_to_gui({name = module_name, id = build_group_gui_token, admin = false}) +Gui.add_tab_to_gui({name = module_name, caption = 'Groups', id = build_group_gui_token, admin = false}) + +Gui.on_click( + module_name, + function(event) + local player = event.player + Gui.reload_active_tab(player) + end +) Event.add(defines.events.on_gui_click, on_gui_click) Event.add(defines.events.on_player_joined_game, on_player_joined_game) diff --git a/comfy_panel/map_score.lua b/utils/gui/map_score.lua similarity index 89% rename from comfy_panel/map_score.lua rename to utils/gui/map_score.lua index e846d630..eff5d8c7 100644 --- a/comfy_panel/map_score.lua +++ b/utils/gui/map_score.lua @@ -1,7 +1,8 @@ -local Tabs = require 'comfy_panel.main' +local Gui = require 'utils.gui' +local Event = require 'utils.event' local Token = require 'utils.token' -local module_name = 'Map Scores' +local module_name = Gui.uid_name() local Public = {} @@ -100,9 +101,16 @@ local function on_init() } end -Tabs.add_tab_to_gui({name = module_name, id = score_list_token, admin = false}) +Gui.add_tab_to_gui({name = module_name, caption = 'Map Scores', id = score_list_token, admin = false}) -local event = require 'utils.event' -event.on_init(on_init) +Gui.on_click( + module_name, + function(event) + local player = event.player + Gui.reload_active_tab(player) + end +) + +Event.on_init(on_init) return Public diff --git a/comfy_panel/player_list.lua b/utils/gui/player_list.lua similarity index 98% rename from comfy_panel/player_list.lua rename to utils/gui/player_list.lua index 08c0b645..52cb1df7 100644 --- a/comfy_panel/player_list.lua +++ b/utils/gui/player_list.lua @@ -17,7 +17,7 @@ local Where = require 'utils.commands.where' local Session = require 'utils.datastore.session_data' local Jailed = require 'utils.datastore.jail_data' local Supporters = require 'utils.datastore.supporters' -local Tabs = require 'comfy_panel.main' +local Gui = require 'utils.gui' local Global = require 'utils.global' local SpamProtection = require 'utils.spam_protection' local RPG = require 'modules.rpg.table' @@ -25,7 +25,7 @@ local Token = require 'utils.token' local Public = {} -local module_name = 'Players' +local module_name = Gui.uid_name() local this = { player_list = { @@ -740,18 +740,11 @@ local function on_gui_click(event) local name = element.name local player = game.get_player(event.player_index) - if name == 'tab_' .. module_name then - local is_spamming = SpamProtection.is_spamming(player, nil, 'PlayerList tab_Players') - if is_spamming then - return - end - end - - local frame = Tabs.comfy_panel_get_active_frame(player) + local frame = Gui.get_player_active_frame(player) if not frame then return end - if frame.name ~= module_name then + if frame.name ~= 'Players' then return end @@ -900,9 +893,9 @@ end local function refresh() for _, player in pairs(game.connected_players) do - local frame = Tabs.comfy_panel_get_active_frame(player) + local frame = Gui.get_player_active_frame(player) if frame then - if frame.name ~= module_name then + if frame.name ~= 'Players' then return end local data = {player = player, frame = frame, sort_by = this.player_list.sorting_method[player.index]} @@ -938,7 +931,15 @@ function Public.rpg_enabled(value) return this.rpg_enabled end -Tabs.add_tab_to_gui({name = module_name, id = player_list_show_token, admin = false}) +Gui.add_tab_to_gui({name = module_name, caption = 'Players', id = player_list_show_token, admin = false}) + +Gui.on_click( + module_name, + function(event) + local player = event.player + Gui.reload_active_tab(player) + end +) Event.add(defines.events.on_player_joined_game, on_player_joined_game) Event.add(defines.events.on_player_left_game, on_player_left_game) diff --git a/comfy_panel/poll.lua b/utils/gui/poll.lua similarity index 97% rename from comfy_panel/poll.lua rename to utils/gui/poll.lua index c45881a0..704a0158 100644 --- a/comfy_panel/poll.lua +++ b/utils/gui/poll.lua @@ -3,9 +3,8 @@ local Global = require 'utils.global' local Event = require 'utils.event' local Game = require 'utils.game' local Server = require 'utils.server' -local ComfyGui = require 'comfy_panel.main' local session = require 'utils.datastore.session_data' -local Config = require 'comfy_panel.config' +local Config = require 'utils.gui.config' local SpamProtection = require 'utils.spam_protection' local Class = {} @@ -293,11 +292,11 @@ local function update_poll_viewer(data) redraw_poll_viewer_content(data) end -local function draw_main_frame(left, player) +local function draw_main_frame(_, player) local trusted = session.get_trusted_table() - local frame = left.add {type = 'frame', name = main_frame_name, caption = 'Polls', direction = 'vertical'} + local main_frame, inside_frame = Gui.add_main_frame_with_toolbar(player, 'left', main_frame_name, nil, main_button_name, 'Polls') - local poll_viewer_top_flow = frame.add {type = 'table', column_count = 5} + local poll_viewer_top_flow = inside_frame.add {type = 'table', column_count = 5} poll_viewer_top_flow.style.horizontal_spacing = 0 local back_button = poll_viewer_top_flow.add {type = 'button', name = poll_view_back_name, caption = '◀'} @@ -314,9 +313,9 @@ local function draw_main_frame(left, player) local remaining_time_label = poll_viewer_top_flow.add {type = 'label'} - local poll_viewer_content = frame.add {type = 'scroll-pane'} + local poll_viewer_content = inside_frame.add {type = 'scroll-pane'} poll_viewer_content.style.maximal_height = 480 - poll_viewer_content.style.width = 295 + poll_viewer_content.style.width = 274 local poll_index = player_poll_index[player.index] or #polls @@ -329,27 +328,24 @@ local function draw_main_frame(left, player) poll_index = poll_index } - Gui.set_data(frame, data) + Gui.set_data(main_frame, data) Gui.set_data(back_button, data) Gui.set_data(forward_button, data) update_poll_viewer(data) - local bottom_flow = frame.add {type = 'flow', direction = 'horizontal'} + local bottom_flow = inside_frame.add {type = 'flow', direction = 'horizontal'} local left_flow = bottom_flow.add {type = 'flow'} left_flow.style.horizontal_align = 'left' left_flow.style.horizontally_stretchable = true - local close_button = left_flow.add {type = 'button', name = main_button_name, caption = 'Close'} - apply_button_style(close_button) - local right_flow = bottom_flow.add {type = 'flow'} right_flow.style.horizontal_align = 'right' - local comfy_panel_config = Config.get('gui_config') + local config = Config.get('gui_config') - if (trusted[player.name] or player.admin) or comfy_panel_config.poll_trusted == false then + if (trusted[player.name] or player.admin) or config.poll_trusted == false then local create_poll_button = right_flow.add {type = 'button', name = create_poll_button_name, caption = 'Create Poll'} apply_button_style(create_poll_button) else @@ -403,7 +399,7 @@ local function toggle(event) if main_frame then remove_main_frame(main_frame, left, event.player) else - ComfyGui.comfy_panel_clear_gui(event.player) + Gui.clear_all_active_frames(event.player) draw_main_frame(left, event.player) end end @@ -420,7 +416,7 @@ local function update_duration(slider) if value == 0 then label.caption = 'Endless Poll.' else - label.caption = value * duration_step .. ' seconds.' + label.caption = value * duration_step .. ' sec.' end end @@ -551,6 +547,7 @@ local function draw_create_poll_frame(parent, player, previous_data) local scroll_pane = frame.add {type = 'scroll-pane', vertical_scroll_policy = 'always'} scroll_pane.style.maximal_height = 250 scroll_pane.style.maximal_width = 300 + scroll_pane.style.padding = 3 local grid = scroll_pane.add {type = 'table', column_count = 3} @@ -766,8 +763,8 @@ local function player_joined(event) return end - if ComfyGui.get_mod_gui_top_frame() then - ComfyGui.add_mod_button( + if Gui.get_mod_gui_top_frame() then + Gui.add_mod_button( player, { type = 'sprite-button', @@ -936,6 +933,10 @@ Gui.on_text_changed( end if textfield and textfield.valid then + if string.len(textfield.text) >= 50 then + textfield.text = '' + return + end data.question = textfield.text end end @@ -952,6 +953,10 @@ Gui.on_text_changed( end if textfield and textfield.valid then + if string.len(textfield.text) >= 50 then + textfield.text = '' + return + end data.answers[data.count].text = textfield.text end end diff --git a/comfy_panel/score.lua b/utils/gui/score.lua similarity index 95% rename from comfy_panel/score.lua rename to utils/gui/score.lua index 0dd97163..baee7819 100644 --- a/comfy_panel/score.lua +++ b/utils/gui/score.lua @@ -3,7 +3,7 @@ local Event = require 'utils.event' local Global = require 'utils.global' -local Tabs = require 'comfy_panel.main' +local Gui = require 'utils.gui' local SpamProtection = require 'utils.spam_protection' local Token = require 'utils.token' local format_number = require 'util'.format_number @@ -14,7 +14,7 @@ local this = { sort_by = {} } -local module_name = 'Scoreboard' +local module_name = Gui.uid_name() Global.register( this, @@ -255,11 +255,12 @@ local show_score_token = Token.register(show_score) local function refresh_score_full() for _, player in pairs(game.connected_players) do - local frame = Tabs.comfy_panel_get_active_frame(player) + local frame = Gui.get_player_active_frame(player) if frame then - if frame.name == module_name then - show_score({player = player, frame = frame}) + if frame.name ~= 'Scoreboard' then + return end + show_score({player = player, frame = frame}) end end end @@ -280,18 +281,11 @@ local function on_gui_click(event) local player = game.get_player(event.player_index) local name = event.element.name - if name == 'tab_' .. module_name then - local is_spamming = SpamProtection.is_spamming(player, nil, 'Scoreboard tab_Scoreboard') - if is_spamming then - return - end - end - - local frame = Tabs.comfy_panel_get_active_frame(player) + local frame = Gui.get_player_active_frame(player) if not frame then return end - if frame.name ~= module_name then + if frame.name ~= 'Scoreboard' then return end @@ -462,7 +456,15 @@ local function on_built_entity(event) score.built_entities = 1 + (score.built_entities or 0) end -Tabs.add_tab_to_gui({name = module_name, id = show_score_token, admin = false}) +Gui.add_tab_to_gui({name = module_name, caption = 'Scoreboard', id = show_score_token, admin = false}) + +Gui.on_click( + module_name, + function(event) + local player = event.player + Gui.reload_active_tab(player) + end +) Event.add(defines.events.on_player_mined_entity, on_player_mined_entity) Event.add(defines.events.on_player_died, on_player_died) diff --git a/comfy_panel/server_select.lua b/utils/gui/server_select.lua similarity index 87% rename from comfy_panel/server_select.lua rename to utils/gui/server_select.lua index 5f88c2b0..997708ed 100644 --- a/comfy_panel/server_select.lua +++ b/utils/gui/server_select.lua @@ -1,7 +1,6 @@ local Event = require 'utils.event' local Gui = require 'utils.gui' local Server = require 'utils.server' -local ComfyGui = require 'comfy_panel.main' local SpamProtection = require 'utils.spam_protection' local main_frame_name = Gui.uid_name() @@ -33,21 +32,16 @@ local function apply_button_style(button) end local function draw_main_frame(player) + Gui.clear_all_active_frames(player) local instance = get_instance() - local left = player.gui.left - local frame = left.add {type = 'frame', name = main_frame_name, caption = 'Comfy Servers', direction = 'vertical'} + local main_frame, inside_frame = Gui.add_main_frame_with_toolbar(player, 'left', main_frame_name, nil, discard_button_name, 'Comfy Servers') - local inside_frame = - frame.add { - type = 'frame', - style = 'deep_frame_in_shallow_frame' - } local inside_frame_style = inside_frame.style inside_frame_style.padding = 0 inside_frame_style.maximal_height = 800 - player.opened = frame + player.opened = main_frame local instances = {} local server_instances = Server.get_instances() @@ -74,7 +68,7 @@ local function draw_main_frame(player) for _, i in ipairs(instances) do viewer_table.add { type = 'label', - caption = 'Name: ' .. i.name, + caption = i.name, tooltip = i.connected .. '\nVersion: ' .. i.version, style = 'caption_label' } @@ -111,26 +105,16 @@ local function draw_main_frame(player) end end end - - local bottom_flow = frame.add {type = 'flow', direction = 'horizontal'} - - local left_flow = bottom_flow.add {type = 'flow'} - left_flow.style.horizontal_align = 'left' - left_flow.style.horizontally_stretchable = true - - local close_button = left_flow.add {type = 'button', name = discard_button_name, caption = 'Close'} - apply_button_style(close_button) - - local right_flow = bottom_flow.add {type = 'flow'} - right_flow.style.horizontal_align = 'right' end local function toggle(player) local left = player.gui.left local frame = left[main_frame_name] + if not player or not player.valid or not player.character then return end + if frame and frame.valid then Gui.remove_data_recursively(frame) frame.destroy() @@ -140,9 +124,14 @@ local function toggle(player) end local function create_main_button(event) + local multiplayer = game.is_multiplayer() + if not multiplayer then + return + end + local player = game.get_player(event.player_index) - if ComfyGui.get_mod_gui_top_frame() then - ComfyGui.add_mod_button( + if Gui.get_mod_gui_top_frame() then + Gui.add_mod_button( player, { type = 'sprite-button', From dbe79dcdfd9e671de19de290bf00392faa44a089 Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Tue, 5 Apr 2022 19:39:01 +0200 Subject: [PATCH 4/5] minor change --- locale/en/mtn_fortress_v3.cfg | 2 +- maps/mountain_fortress_v3/locomotive/friendly_pet.lua | 2 +- maps/mountain_fortress_v3/locomotive/market.lua | 11 ++++++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/locale/en/mtn_fortress_v3.cfg b/locale/en/mtn_fortress_v3.cfg index 662e2985..07a960cf 100644 --- a/locale/en/mtn_fortress_v3.cfg +++ b/locale/en/mtn_fortress_v3.cfg @@ -51,7 +51,7 @@ map_off=OFF [locomotive] upgrades=Upgrades: items=Items: -shoo=^-^ Please don't shoo at me ^-^ +shoo=[Desync Bro] not_trusted=You need to be trusted to purchase this. coins_left=Coins left: __1__ market_name=Market diff --git a/maps/mountain_fortress_v3/locomotive/friendly_pet.lua b/maps/mountain_fortress_v3/locomotive/friendly_pet.lua index 4fb81377..e086f753 100644 --- a/maps/mountain_fortress_v3/locomotive/friendly_pet.lua +++ b/maps/mountain_fortress_v3/locomotive/friendly_pet.lua @@ -104,7 +104,7 @@ function Public.spawn_biter() target = this.locomotive_biter, target_offset = {0, -3.5}, scale = 1.05, - font = 'default-large-semibold', + font = 'heading-2', color = {r = 175, g = 75, b = 255}, alignment = 'center', scale_with_zoom = false diff --git a/maps/mountain_fortress_v3/locomotive/market.lua b/maps/mountain_fortress_v3/locomotive/market.lua index 6b821bfa..3fcecdd1 100644 --- a/maps/mountain_fortress_v3/locomotive/market.lua +++ b/maps/mountain_fortress_v3/locomotive/market.lua @@ -519,12 +519,14 @@ local function redraw_market_items(gui, player, search_text) return end - gui.add( + local upgrades_label = + gui.add( { type = 'label', caption = ({'locomotive.upgrades'}) } ) + upgrades_label.style.font = 'heading-2' local upgrade_table = gui.add({type = 'table', column_count = 6}) @@ -574,12 +576,14 @@ local function redraw_market_items(gui, player, search_text) ::continue:: end end - gui.add( + local items_label = + gui.add( { type = 'label', caption = ({'locomotive.items'}) } ) + items_label.style.font = 'heading-2' local slider_value = ceil(players[player.index].data.slider.slider_value) local items_table = gui.add({type = 'table', column_count = 6}) @@ -801,7 +805,8 @@ local function gui_opened(event) player.opened = frame local search_table = inside_table.add({type = 'table', column_count = 2}) - search_table.add({type = 'label', caption = ({'locomotive.search_text'})}) + local search_name = search_table.add({type = 'label', caption = ({'locomotive.search_text'})}) + search_name.style.font = 'heading-2' local search_text = search_table.add({type = 'textfield'}) search_text.style.width = 140 From 82affb25ddc17c2484cede1bc7e0b3e8748a29c5 Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Tue, 5 Apr 2022 19:41:44 +0200 Subject: [PATCH 5/5] minor fix --- utils/gui.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/gui.lua b/utils/gui.lua index aa0aa174..5a90aa1c 100644 --- a/utils/gui.lua +++ b/utils/gui.lua @@ -529,7 +529,7 @@ local function draw_main_frame(player) Public.get_main_frame(player).destroy() end - local frame, inside_frame = Public.add_main_frame_with_toolbar(player, 'left', main_frame_name, _, close_button_name, 'Comfy Panel') + local frame, inside_frame = Public.add_main_frame_with_toolbar(player, 'left', main_frame_name, nil, close_button_name, 'Comfy Panel') local tabbed_pane = inside_frame.add({type = 'tabbed-pane', name = 'tabbed_pane'})