1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-22 03:38:48 +02:00

RPG spell switcher + minifix for difficulty module

This commit is contained in:
hanakocz 2021-02-03 11:22:44 +01:00
parent 6df0069a18
commit a5855b3082
7 changed files with 301 additions and 26 deletions

View File

@ -68,6 +68,12 @@ health_tooltip=Health regen bonus: __1__
[rpg_settings]
name=RPG Settings
spell_name=Spells
mana_cost=Mana cost of selected spell
mana=Current Mana
mana_max=Max Mana
spell_gui_setup=Spells MiniGui Setup
spell_gui_tooltip=Set your 3 spells for useful Spell Switcher. Opened or closed by this fish button.\n
save_changes=Save changes
discard_changes=Discard changes
not_trusted=Not trusted.\nChecked: true\nUnchecked: false

View File

@ -178,7 +178,7 @@ end
local function set_difficulty()
local index = highest_count(this.difficulties)
if not index then
if not index or not this.difficulties[index] then
return
end

View File

@ -15,6 +15,7 @@ local points_per_level = RPG.points_per_level
--RPG Frames
local main_frame_name = RPG.main_frame_name
local spell_gui_frame_name = RPG.spell_gui_frame_name
local travelings = {
'bzzZZrrt',
@ -240,6 +241,17 @@ function Public.update_mana(player)
data.mana.caption = rpg_t[player.index].mana
end
end
if player.gui.screen[spell_gui_frame_name] then
local f = player.gui.screen[spell_gui_frame_name]
if f['spell_table'] then
if f['spell_table']['mana'] then
f['spell_table']['mana'].caption = math.floor(rpg_t[player.index].mana)
end
if f['spell_table']['maxmana'] then
f['spell_table']['maxmana'].caption = math.floor(rpg_t[player.index].mana_max)
end
end
end
if rpg_t[player.index].mana < 1 then
return
@ -286,6 +298,18 @@ function Public.reward_mana(player, mana_to_add)
data.mana.caption = rpg_t[player.index].mana
end
end
if player.gui.screen[spell_gui_frame_name] then
local f = player.gui.screen[spell_gui_frame_name]
if f['spell_table'] then
if f['spell_table']['mana'] then
f['spell_table']['mana'].caption = math.floor(rpg_t[player.index].mana)
end
if f['spell_table']['maxmana'] then
f['spell_table']['maxmana'].caption = math.floor(rpg_t[player.index].mana_max)
end
end
end
if rpg_t[player.index].mana_max < 1 then
return
end
@ -499,6 +523,9 @@ function Public.rpg_reset_player(player, one_time_reset)
mana_max = 0,
last_spawned = 0,
dropdown_select_index = 1,
dropdown_select_index1 = 1,
dropdown_select_index2 = 1,
dropdown_select_index3 = 1,
allocate_index = 1,
flame_boots = false,
enable_entity_spawn = false,
@ -531,6 +558,9 @@ function Public.rpg_reset_player(player, one_time_reset)
mana_max = 0,
last_spawned = 0,
dropdown_select_index = 1,
dropdown_select_index1 = 1,
dropdown_select_index2 = 1,
dropdown_select_index3 = 1,
allocate_index = 1,
flame_boots = false,
enable_entity_spawn = false,

View File

@ -21,6 +21,11 @@ local settings_button_name = RPG.settings_button_name
local settings_frame_name = RPG.settings_frame_name
local discard_button_name = RPG.discard_button_name
local save_button_name = RPG.save_button_name
local spell_gui_button_name = RPG.spell_gui_button_name
local spell_gui_frame_name = RPG.spell_gui_frame_name
local spell1_button_name = RPG.spell1_button_name
local spell2_button_name = RPG.spell2_button_name
local spell3_button_name = RPG.spell3_button_name
local sub = string.sub
@ -554,6 +559,9 @@ Gui.on_click(
local health_bar_gui_input = data.health_bar_gui_input
local reset_gui_input = data.reset_gui_input
local conjure_gui_input = data.conjure_gui_input
local spell_gui_input1 = data.spell_gui_input1
local spell_gui_input2 = data.spell_gui_input2
local spell_gui_input3 = data.spell_gui_input3
local magic_pickup_gui_input = data.magic_pickup_gui_input
local movement_speed_gui_input = data.movement_speed_gui_input
local flame_boots_gui_input = data.flame_boots_gui_input
@ -641,6 +649,18 @@ Gui.on_click(
if conjure_gui_input and conjure_gui_input.valid and conjure_gui_input.selected_index then
rpg_t[player.index].dropdown_select_index = conjure_gui_input.selected_index
end
if spell_gui_input1 and spell_gui_input1.valid and spell_gui_input1.selected_index then
rpg_t[player.index].dropdown_select_index1 = spell_gui_input1.selected_index
end
if spell_gui_input2 and spell_gui_input2.valid and spell_gui_input2.selected_index then
rpg_t[player.index].dropdown_select_index2 = spell_gui_input2.selected_index
end
if spell_gui_input3 and spell_gui_input3.valid and spell_gui_input3.selected_index then
rpg_t[player.index].dropdown_select_index3 = spell_gui_input3.selected_index
end
if player.gui.screen[spell_gui_frame_name] then
Settings.update_spell_gui(player, nil)
end
if reset_gui_input and reset_gui_input.valid and reset_gui_input.state then
if not rpg_t[player.index].reset then
@ -708,4 +728,90 @@ Gui.on_click(
end
)
Gui.on_click(
spell_gui_button_name,
function(event)
local player = event.player
local screen = player.gui.screen
local frame = screen[spell_gui_frame_name]
if not player or not player.valid or not player.character then
return
end
local surface_name = RPG.get('rpg_extra').surface_name
if sub(player.surface.name, 0, #surface_name) ~= surface_name then
return
end
if frame and frame.valid then
frame.destroy()
else
Settings.spell_gui_settings(player)
end
end
)
Gui.on_click(
spell1_button_name,
function(event)
local player = event.player
local screen = player.gui.screen
local frame = screen[spell_gui_frame_name]
if not player or not player.valid or not player.character then
return
end
local surface_name = RPG.get('rpg_extra').surface_name
if sub(player.surface.name, 0, #surface_name) ~= surface_name then
return
end
if frame and frame.valid then
Settings.update_spell_gui(player, 1)
end
end
)
Gui.on_click(
spell2_button_name,
function(event)
local player = event.player
local screen = player.gui.screen
local frame = screen[spell_gui_frame_name]
if not player or not player.valid or not player.character then
return
end
local surface_name = RPG.get('rpg_extra').surface_name
if sub(player.surface.name, 0, #surface_name) ~= surface_name then
return
end
if frame and frame.valid then
Settings.update_spell_gui(player, 2)
end
end
)
Gui.on_click(
spell3_button_name,
function(event)
local player = event.player
local screen = player.gui.screen
local frame = screen[spell_gui_frame_name]
if not player or not player.valid or not player.character then
return
end
local surface_name = RPG.get('rpg_extra').surface_name
if sub(player.surface.name, 0, #surface_name) ~= surface_name then
return
end
if frame and frame.valid then
Settings.update_spell_gui(player, 3)
end
end
)
return Public

View File

@ -8,6 +8,11 @@ local Public = {}
local settings_frame_name = RPG.settings_frame_name
local save_button_name = RPG.save_button_name
local discard_button_name = RPG.discard_button_name
local spell_gui_button_name = RPG.spell_gui_button_name
local spell_gui_frame_name = RPG.spell_gui_frame_name
local spell1_button_name = RPG.spell1_button_name
local spell2_button_name = RPG.spell2_button_name
local spell3_button_name = RPG.spell3_button_name
local function create_input_element(frame, type, value, items, index)
if type == 'slider' then
@ -22,6 +27,84 @@ local function create_input_element(frame, type, value, items, index)
return frame.add({type = 'text-box', text = value})
end
function Public.update_spell_gui(player, spell_index)
local rpg_t = RPG.get('rpg_t')
local spells, names = RPG.rebuild_spells()
local main_frame = player.gui.screen[spell_gui_frame_name]
if not main_frame then return end
local spell_table = main_frame['spell_table']
if spell_index then
if spell_index == 1 then
rpg_t[player.index].dropdown_select_index = rpg_t[player.index].dropdown_select_index1
elseif spell_index == 2 then
rpg_t[player.index].dropdown_select_index = rpg_t[player.index].dropdown_select_index2
elseif spell_index == 3 then
rpg_t[player.index].dropdown_select_index = rpg_t[player.index].dropdown_select_index3
end
end
spell_table[spell1_button_name].tooltip = names[rpg_t[player.index].dropdown_select_index1] or '---'
spell_table[spell1_button_name].sprite = spells[rpg_t[player.index].dropdown_select_index1].sprite
spell_table[spell2_button_name].tooltip = names[rpg_t[player.index].dropdown_select_index2] or '---'
spell_table[spell2_button_name].sprite = spells[rpg_t[player.index].dropdown_select_index2].sprite
spell_table[spell3_button_name].tooltip = names[rpg_t[player.index].dropdown_select_index3] or '---'
spell_table[spell3_button_name].sprite = spells[rpg_t[player.index].dropdown_select_index3].sprite
if rpg_t[player.index].dropdown_select_index1 == rpg_t[player.index].dropdown_select_index then
spell_table[spell1_button_name].enabled = false
spell_table[spell1_button_name].number = 1
else
spell_table[spell1_button_name].enabled = true
spell_table[spell1_button_name].number = nil
end
if rpg_t[player.index].dropdown_select_index2 == rpg_t[player.index].dropdown_select_index then
spell_table[spell2_button_name].enabled = false
spell_table[spell2_button_name].number = 1
else
spell_table[spell2_button_name].enabled = true
spell_table[spell2_button_name].number = nil
end
if rpg_t[player.index].dropdown_select_index3 == rpg_t[player.index].dropdown_select_index then
spell_table[spell3_button_name].enabled = false
spell_table[spell3_button_name].number = 1
else
spell_table[spell3_button_name].enabled = true
spell_table[spell3_button_name].number = nil
end
spell_table['mana-cost'].caption = spells[rpg_t[player.index].dropdown_select_index].mana_cost
spell_table['mana'].caption = math.floor(rpg_t[player.index].mana)
spell_table['maxmana'].caption = math.floor(rpg_t[player.index].mana_max)
end
function Public.spell_gui_settings(player)
local rpg_t = RPG.get('rpg_t')
local spells, names = RPG.rebuild_spells()
local main_frame = player.gui.screen[spell_gui_frame_name]
if not main_frame or not main_frame.valid then
main_frame =
player.gui.screen.add(
{
type = 'frame',
name = spell_gui_frame_name,
caption = ({'rpg_settings.spell_name'}),
direction = 'vertical'
}
)
main_frame.auto_center = true
local table = main_frame.add({type = 'table', column_count = 3, name = 'spell_table'})
table.add({type = 'sprite-button', sprite = spells[rpg_t[player.index].dropdown_select_index1].sprite, name = spell1_button_name, tooltip = names[rpg_t[player.index].dropdown_select_index1] or '---'})
table.add({type = 'sprite-button', sprite = spells[rpg_t[player.index].dropdown_select_index2].sprite, name = spell2_button_name, tooltip = names[rpg_t[player.index].dropdown_select_index2] or '---'})
table.add({type = 'sprite-button', sprite = spells[rpg_t[player.index].dropdown_select_index3].sprite, name = spell3_button_name, tooltip = names[rpg_t[player.index].dropdown_select_index3] or '---'})
local b1 = table.add({type = 'sprite-button', name = 'mana-cost', tooltip = {'rpg_settings.mana_cost'}, caption = 0})
local b2 = table.add({type = 'sprite-button', name = 'mana', tooltip = {'rpg_settings.mana'}, caption = 0})
local b3 = table.add({type = 'sprite-button', name = 'maxmana', tooltip = {'rpg_settings.mana_max'}, caption = 0})
b1.style.font_color = {r = 0.98, g = 0.98, b = 0.98}
b2.style.font_color = {r = 0.98, g = 0.98, b = 0.98}
b3.style.font_color = {r = 0.98, g = 0.98, b = 0.98}
Public.update_spell_gui(player, nil)
else
main_frame.destroy()
end
end
function Public.extra_settings(player)
local player_modifiers = P.get_table()
local rpg_extra = RPG.get('rpg_extra')
@ -194,6 +277,9 @@ function Public.extra_settings(player)
local enable_entity_gui_input
local conjure_gui_input
local spell_gui_input1
local spell_gui_input2
local spell_gui_input3
local flame_boots_gui_input
local stone_path_gui_input
local one_punch_gui_input
@ -429,6 +515,15 @@ function Public.extra_settings(player)
})
end
end
mana_frame.add({type = 'label', caption = {'rpg_settings.spell_gui_setup'}, tooltip = {'rpg_settings.spell_gui_tooltip'}})
local spell_grid = mana_frame.add({type = 'table', column_count = 4, name = 'spell_grid_table'})
spell_gui_input1 = create_input_element(spell_grid, 'dropdown', false, names, rpg_t[player.index].dropdown_select_index1)
spell_gui_input1.style.maximal_width = 135
spell_gui_input2 = create_input_element(spell_grid, 'dropdown', false, names, rpg_t[player.index].dropdown_select_index2)
spell_gui_input2.style.maximal_width = 135
spell_gui_input3 = create_input_element(spell_grid, 'dropdown', false, names, rpg_t[player.index].dropdown_select_index3)
spell_gui_input3.style.maximal_width = 135
spell_select_button = spell_grid.add({type = 'sprite-button', name = spell_gui_button_name, sprite = 'item/raw-fish'})
end
if rpg_extra.enable_auto_allocate then
@ -490,6 +585,9 @@ function Public.extra_settings(player)
if rpg_extra.enable_mana then
data.conjure_gui_input = conjure_gui_input
data.spell_gui_input1 = spell_gui_input1
data.spell_gui_input2 = spell_gui_input2
data.spell_gui_input3 = spell_gui_input3
data.enable_entity_gui_input = enable_entity_gui_input
end

View File

@ -10,7 +10,8 @@ function Public.conjure_items()
type = 'item',
mana_cost = 60,
tick = 100,
enabled = true
enabled = true,
sprite = 'recipe/stone-wall'
}
spells[#spells + 1] = {
@ -20,7 +21,8 @@ function Public.conjure_items()
type = 'item',
mana_cost = 50,
tick = 100,
enabled = true
enabled = true,
sprite = 'recipe/wooden-chest'
}
spells[#spells + 1] = {
name = {'entity-name.iron-chest'},
@ -29,7 +31,8 @@ function Public.conjure_items()
type = 'item',
mana_cost = 110,
tick = 200,
enabled = true
enabled = true,
sprite = 'recipe/iron-chest'
}
spells[#spells + 1] = {
name = {'entity-name.steel-chest'},
@ -38,7 +41,8 @@ function Public.conjure_items()
type = 'item',
mana_cost = 150,
tick = 300,
enabled = true
enabled = true,
sprite = 'recipe/steel-chest'
}
spells[#spells + 1] = {
name = {'entity-name.transport-belt'},
@ -47,7 +51,8 @@ function Public.conjure_items()
type = 'item',
mana_cost = 80,
tick = 100,
enabled = true
enabled = true,
sprite = 'recipe/transport-belt'
}
spells[#spells + 1] = {
name = {'entity-name.fast-transport-belt'},
@ -56,7 +61,8 @@ function Public.conjure_items()
type = 'item',
mana_cost = 110,
tick = 200,
enabled = true
enabled = true,
sprite = 'recipe/fast-transport-belt'
}
spells[#spells + 1] = {
name = {'entity-name.express-transport-belt'},
@ -65,7 +71,8 @@ function Public.conjure_items()
type = 'item',
mana_cost = 150,
tick = 300,
enabled = true
enabled = true,
sprite = 'recipe/express-transport-belt'
}
spells[#spells + 1] = {
name = {'entity-name.underground-belt'},
@ -74,7 +81,8 @@ function Public.conjure_items()
type = 'item',
mana_cost = 80,
tick = 100,
enabled = true
enabled = true,
sprite = 'recipe/underground-belt'
}
spells[#spells + 1] = {
name = {'entity-name.fast-underground-belt'},
@ -83,7 +91,8 @@ function Public.conjure_items()
type = 'item',
mana_cost = 110,
tick = 200,
enabled = true
enabled = true,
sprite = 'recipe/fast-underground-belt'
}
spells[#spells + 1] = {
name = {'entity-name.express-underground-belt'},
@ -92,7 +101,8 @@ function Public.conjure_items()
type = 'item',
mana_cost = 150,
tick = 300,
enabled = true
enabled = true,
sprite = 'recipe/express-underground-belt'
}
spells[#spells + 1] = {
name = {'entity-name.sand-rock-big'},
@ -101,7 +111,8 @@ function Public.conjure_items()
type = 'entity',
mana_cost = 80,
tick = 350,
enabled = true
enabled = true,
sprite = 'entity/sand-rock-big'
}
spells[#spells + 1] = {
name = {'entity-name.small-biter'},
@ -111,7 +122,8 @@ function Public.conjure_items()
type = 'entity',
mana_cost = 55,
tick = 200,
enabled = true
enabled = true,
sprite = 'entity/small-biter'
}
spells[#spells + 1] = {
name = {'entity-name.small-spitter'},
@ -121,7 +133,8 @@ function Public.conjure_items()
type = 'entity',
mana_cost = 55,
tick = 200,
enabled = true
enabled = true,
sprite = 'entity/small-spitter'
}
spells[#spells + 1] = {
name = {'entity-name.medium-biter'},
@ -131,7 +144,8 @@ function Public.conjure_items()
type = 'entity',
mana_cost = 100,
tick = 300,
enabled = true
enabled = true,
sprite = 'entity/medium-biter'
}
spells[#spells + 1] = {
name = {'entity-name.medium-spitter'},
@ -140,7 +154,8 @@ function Public.conjure_items()
type = 'entity',
mana_cost = 100,
tick = 300,
enabled = true
enabled = true,
sprite = 'entity/medium-spitter'
}
spells[#spells + 1] = {
name = {'entity-name.biter-spawner'},
@ -150,7 +165,8 @@ function Public.conjure_items()
type = 'entity',
mana_cost = 800,
tick = 1420,
enabled = true
enabled = true,
sprite = 'entity/biter-spawner'
}
spells[#spells + 1] = {
name = {'entity-name.spitter-spawner'},
@ -160,7 +176,8 @@ function Public.conjure_items()
type = 'entity',
mana_cost = 800,
tick = 1420,
enabled = true
enabled = true,
sprite = 'entity/spitter-spawner'
}
spells[#spells + 1] = {
name = {'item-name.grenade'},
@ -173,7 +190,8 @@ function Public.conjure_items()
type = 'special',
mana_cost = 110,
tick = 150,
enabled = true
enabled = true,
sprite = 'recipe/grenade'
}
spells[#spells + 1] = {
name = {'item-name.cluster-grenade'},
@ -186,7 +204,8 @@ function Public.conjure_items()
type = 'special',
mana_cost = 150,
tick = 200,
enabled = true
enabled = true,
sprite = 'recipe/cluster-grenade'
}
spells[#spells + 1] = {
name = {'item-name.rocket'},
@ -200,7 +219,8 @@ function Public.conjure_items()
type = 'special',
mana_cost = 60,
tick = 320,
enabled = true
enabled = true,
sprite = 'recipe/rocket'
}
spells[#spells + 1] = {
name = {'spells.acid_stream'},
@ -214,7 +234,8 @@ function Public.conjure_items()
type = 'special',
mana_cost = 90,
tick = 100,
enabled = true
enabled = true,
sprite = 'virtual-signal/signal-S'
}
spells[#spells + 1] = {
name = {'spells.raw_fish'},
@ -228,7 +249,8 @@ function Public.conjure_items()
type = 'special',
mana_cost = 140,
tick = 320,
enabled = true
enabled = true,
sprite = 'item/raw-fish'
}
spells[#spells + 1] = {
name = {'spells.comfylatron'},
@ -242,7 +264,8 @@ function Public.conjure_items()
type = 'special',
mana_cost = 250,
tick = 320,
enabled = true
enabled = true,
sprite = 'entity/compilatron'
}
spells[#spells + 1] = {
name = {'spells.distractor'},
@ -256,7 +279,8 @@ function Public.conjure_items()
type = 'special',
mana_cost = 340,
tick = 320,
enabled = true
enabled = true,
sprite = 'recipe/distractor-capsule'
}
spells[#spells + 1] = {
name = {'spells.warp'},
@ -267,7 +291,8 @@ function Public.conjure_items()
type = 'special',
mana_cost = 340,
tick = 2000,
enabled = true
enabled = true,
sprite = 'virtual-signal/signal-W'
}
return spells
end

View File

@ -17,6 +17,11 @@ local discard_button_name = Gui.uid_name()
local draw_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()
local spell_gui_frame_name = Gui.uid_name()
local spell1_button_name = Gui.uid_name()
local spell2_button_name = Gui.uid_name()
local spell3_button_name = Gui.uid_name()
Global.register(
this,
@ -457,6 +462,11 @@ Public.discard_button_name = discard_button_name
Public.draw_main_frame_name = draw_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
Public.spell_gui_frame_name = spell_gui_frame_name
Public.spell1_button_name = spell1_button_name
Public.spell2_button_name = spell2_button_name
Public.spell3_button_name = spell3_button_name
local on_init = function()
Public.reset_table()