1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-18 03:21:47 +02:00

Merge branch 'master' into develop

# Conflicts:
#	fish_market.lua
This commit is contained in:
Valansch 2017-07-21 23:59:03 +02:00
commit d6082e5c8e
10 changed files with 276 additions and 325 deletions

144
band.lua
View File

@ -20,6 +20,7 @@ do
end
end
local custom_roles = {}
local expand_band_gui
@ -28,7 +29,7 @@ local expand_band_gui
local local_role
local function create_band_gui(event)
local player = game.players[event.player_index]
local player = game.players[event.player_index]
global.band_last_change[event.player_index] = game.tick
if player.gui.top.band_toggle_btn == nil then
local button = player.gui.top.add { name = "band_toggle_btn", type = "sprite-button", caption = "Tag", style = "dialog_button_style" }
@ -48,17 +49,17 @@ end
-- Make a list of random names with roles
local function test_fake_players( t )
local limit = math.random(20,120)
local roles_ind = {}
for role in pairs(roles) do
table.insert( roles_ind, role)
end
for i = 1,limit do
local rolei = math.random(1, #roles_ind)
local role = roles_ind[rolei]
table.insert(t[role],
table.insert(t[role],
{
"Fake#" .. (tostring(math.random())):sub(3,-math.random(1,10)),
{
@ -79,17 +80,17 @@ local function subgui_update_role_counter(gui_parent, count_diff)
local count_label
if gui_parent["role_counter"] then
count_label = gui_parent["role_counter"]
else
else
count_label = gui_parent.add {type = "label", caption = 0, name = "role_counter", single_line = false}
count_label.style.font = "default-small-bold"
count_label.style.maximal_height = 10
count_label.style.maximal_height = 10
count_label.style.top_padding = 0
count_label.style.left_padding = 0
count_label.style.right_padding = 0
count_label.style.bottom_padding = 0
count_label.style.font_color = {r=.55,g=.55,b=.55}
end
local new_count = tonumber(count_label.caption) + count_diff
count_label.caption = new_count
if new_count == 0 then
@ -126,7 +127,7 @@ expand_band_gui = function(player, dev_icons, dev_addfakes, right_click)
local frame = player.gui.left["band_panel"]
if (frame) then
frame.destroy()
if player.gui.center["textfield_item_icon_frame"] then
player.gui.center["textfield_item_icon_frame"].destroy()
end
@ -138,16 +139,28 @@ expand_band_gui = function(player, dev_icons, dev_addfakes, right_click)
end
return
end
local player_role = player.tag:sub(2,-2)
local player_role = player.tag:sub(2,-2)
-- Will be filled: { roleN = {{name,color},...} , ...}
local players_by_role = {}
for role in pairs(roles) do
players_by_role[role] = {}
end
for _,role in pairs(custom_roles) do
roles[role] = nil
end
for _,cplayer in pairs(game.players) do
local role = cplayer.tag:sub(2,-2)
if role ~= "" and roles[role] == nil then
players_by_role[role] = {}
table.insert(custom_roles, role)
roles[role] = {"item/iron-stick",tooltip = {"I'm sure he does something"},verbs = {"enlarged"}}
end
end
if right_click then
for _, oplayer in pairs(game.players) do
local prole = oplayer.tag:sub(2,-2)
@ -167,19 +180,18 @@ expand_band_gui = function(player, dev_icons, dev_addfakes, right_click)
end
end
end
if dev_addfakes then
test_fake_players(players_by_role)
end
player.gui.top.band_toggle_btn.tooltip = ""
local button--reusable variable :D
local frame = player.gui.left.add { type = "frame", direction = "vertical", name = "band_panel", caption = "Choose your role:"}
frame.style.font = "default-listbox"
frame.style.font_color = { r=0.98, g=0.66, b=0.22}
if dev_icons then
local choose
local chooselist = frame.add { type = "flow", direction = "horizontal" }
@ -194,25 +206,25 @@ expand_band_gui = function(player, dev_icons, dev_addfakes, right_click)
choose.style.bottom_padding = 2
end
end
local scroll = frame.add{type = "scroll-pane", name = "scroll", horizontal_scroll_policy = "never", vertical_scroll_policy = "auto"}
scroll.style.maximal_height = 600
scroll.style.minimal_width = 250
scroll.style.bottom_padding = 10
local table_roles = scroll.add{type = "table", name = "table_roles", colspan = 2}
table_roles.style.horizontal_spacing = 15
table_roles.style.vertical_spacing = 4
local name_label
local pname
local pcolor
local show_role_tooltip = math.random() > .5
for role, role_icons in pairs(roles) do
local role_line = table_roles.add { type = "flow", direction = "horizontal" }
button = role_line.add { type = "sprite-button", sprite = get_random_from_table(role_icons), name = "band_role_"..role, style = "recipe_slot_button_style"}
@ -223,14 +235,14 @@ expand_band_gui = function(player, dev_icons, dev_addfakes, right_click)
if show_role_tooltip and role_icons.tooltip then
button.tooltip = get_random_from_table( role_icons.tooltip )
end
local role_cap_line = role_line.add { type = "flow", name = "role_cap_line", direction = "horizontal" }
role_cap_line.style.max_on_row = 1
local role_label = role_cap_line.add { type = "label", caption = role, single_line = true}
-- role_label.style.minimal_width = 0
role_label.style.minimal_height = 0
role_label.style.maximal_height = 12
role_label.style.maximal_height = 12
role_label.style.top_padding = 0
role_label.style.left_padding = 0
role_label.style.right_padding = 0
@ -239,7 +251,7 @@ expand_band_gui = function(player, dev_icons, dev_addfakes, right_click)
if role == player_role then
role_label.style.font_color = {r=.7,g=1,b=.7}
end
subgui_update_role_counter(role_cap_line, #players_by_role[role])
local list_players = table_roles.add { type = "flow", direction = "horizontal" }
@ -255,7 +267,7 @@ expand_band_gui = function(player, dev_icons, dev_addfakes, right_click)
end
end
end
local close_btn_flow = frame.add { type = "flow", direction = "horizontal" }
button = close_btn_flow.add { type = "button", caption = "Close", name = "band_close" }
button.style.font = "default-bold"
@ -265,7 +277,7 @@ expand_band_gui = function(player, dev_icons, dev_addfakes, right_click)
button.style.left_padding = 2
button.style.right_padding = 2
button.style.bottom_padding = 0
button = close_btn_flow.add { type = "button", caption = "Clear tag", name = "band_clear" }
button.style.font = "default-bold"
button.style.font_color = {r=1, g=.7, b=.7}
@ -292,7 +304,7 @@ local function print_role_change(name, role)
str = str .. " (["..local_role.."] squad will miss you)."
end]]--
end
if str then
str = str:gsub('%%name', name)
game.print(str)
@ -304,54 +316,17 @@ local function update_player_role(player, role)
global.update_player_name = player
global.update_player_role_name = role
if global.update_player_role_name then
global.update_player_name.tag = "[" .. global.update_player_role_name .. "]"
else
global.update_player_name.tag = ""
end
-- update other player gui (counter & label)
--[[
for _,cplayer in pairs( game.connected_players ) do
if cplayer.gui.left.band_panel then
local troles = cplayer.gui.left.band_panel.scroll.table_roles
if local_role then
local player_label = troles.children[roles[local_role].index*2]["list_players_" .. cplayer.name]
if player_label then
player_label.destroy()
end
end
if global.update_player_role_name then
subgui_add_player_label( troles.children[roles[global.update_player_role_name].index*2], cplayer.name, cplayer.color)
subgui_update_role_counter( troles.children[roles[global.update_player_role_name].index*2 - 1].role_cap_line, 1)
end
if local_role then
subgui_update_role_counter( troles.children[roles[local_role].index*2 - 1].role_cap_line, -1)
end
end
end
-- update local player gui (role label color)
local troles_local = player.gui.left.band_panel.scroll.table_roles
if local_role then
troles_local.children[roles[local_role].index*2 - 1].children[2].children[1].style.font_color = {r=1,g=1,b=1}
end
if global.update_player_role_name then
troles_local.children[roles[global.update_player_role_name].index*2 - 1].children[2].children[1].style.font_color = {r=.7,g=1,b=.7}
end
--]]
print_role_change(global.update_player_name.name, global.update_player_role_name)
expand_band_gui(player)
expand_band_gui(player)
local_role = role
end
@ -359,11 +334,11 @@ local function on_gui_click(event)
if not (event and event.element and event.element.valid) then return end
local player = game.players[event.element.player_index]
local name = event.element.name
if (name == "band_toggle_btn") then
--player, dev_icons, dev_addfakes
expand_band_gui(player,
player.admin and event.control,
expand_band_gui(player,
player.admin and event.control,
player.admin and event.alt,
event.button == defines.mouse_button_type.right)
end
@ -372,18 +347,17 @@ local function on_gui_click(event)
expand_band_gui(player)
return
end
if (name == "band_clear") then
update_player_role(player, nil)
player.gui.top.band_toggle_btn.caption = "Tag"
player.gui.top.band_toggle_btn.tooltip = ""
player.gui.top.band_toggle_btn.sprite = ""
-- expand_band_gui(player)
return
end
--role button clicked
if name:find("band_role_") == 1 then
if not player.admin and event.tick - global.band_last_change[event.player_index] < option_band_change_interval then
@ -392,20 +366,20 @@ local function on_gui_click(event)
end
local _,role_ind_start = name:find("band_role_")
local name_role = name:sub(role_ind_start + 1)
if player.tag:find(name_role) then
-- current tag = new tag
return
end
for role, role_icons in pairs(roles) do
if (name_role == role) then
global.band_last_change[event.player_index] = event.tick
player.gui.top.band_toggle_btn.caption = ""
player.gui.top.band_toggle_btn.sprite = event.element.sprite --get_random_from_table(role_icons)
update_player_role(player, role)
update_player_role(player, role)
-- expand_band_gui(player)
end
end
@ -424,18 +398,18 @@ local function on_gui_elem_changed(event)
if event.element.elem_type and event.element.elem_value then
local frame = player.gui.center.add{ type = "frame", name = "textfield_item_icon_frame", caption = "SpritePath"}
frame.style.minimal_width = 310
local textfield
local textfield
-- if type(event.element.elem_value ) == 'table' then
-- textfield = frame.add { name = "textfield_item_icon", type = "textfield", text = "virtual-signal/" .. event.element.elem_value.name }
-- else
textfield = frame.add { name = "textfield_item_icon", type = "textfield", text = event.element.elem_type .. "/" .. event.element.elem_value }
-- end
--buggy
textfield.style.minimal_width = 300
end
end
end
Event.register(defines.events.on_gui_elem_changed, on_gui_elem_changed)

View File

@ -12,6 +12,10 @@ Event.register(-1, function()
}
global.scenario.variables.regulars = {
helpower2 = "",
rorror = "",
Medival3 = "",
dpoba = "",
settdigger = ""
}
global.scenario.variables.player_positions = {}
global.scenario.variables.player_walk_distances = {}

View File

@ -16,6 +16,7 @@ require "map_layout"
require "custom_commands"
require "nuke_control"
require "walk_distance"
require "on_tick"

View File

@ -242,6 +242,26 @@ local function afk()
end
end
local function tag(cmd)
if not game.player.admin then
cant_run(cmd.name)
return
end
local params = {}
for param in string.gmatch(cmd.parameter, "%w+") do table.insert(params, param) end
if #params ~= 2 then
game.player.print("Two arguments expect failed. Usage: <player> <tag> Sets a players tag.")
elseif game.players[params[1]] == nil then
game.player.print("Player does not exist.")
else
game.players[params[1]].tag = "[" .. params[2] .. "]"
game.print(params[1] .. " joined [" .. params[2] .. "].")
end
end
commands.add_command("kill", "Will kill you.", kill)
commands.add_command("detrain", "<player> - Kicks the player off a train. (Admins and moderators)", detrain)
commands.add_command("tpplayer", "<player> - Teleports you to the player. (Admins and moderators)", teleport_player)
@ -256,3 +276,4 @@ commands.add_command("regular", '<promote, demote>, <player> Change regular stat
commands.add_command("mods", 'Prints a list of game mods.', print_mods)
commands.add_command("mod", '<promote, demote>, <player> Changes moderator status of a player. (Admins only)', mod)
commands.add_command("afktime", 'Shows how long players have been afk.', afk)
commands.add_command("tag", '<player> <tag> Sets a players tag. (Admins only)', tag)

View File

@ -285,77 +285,50 @@ end
if not global.pet_command_rotation then global.pet_command_rotation = 1 end
local function on_tick(event)
function fish_market_on_180_ticks()
if game.tick % 1000 == 0 then
if global.player_speed_boost_records then
for k,v in pairs(global.player_speed_boost_records) do
if game.tick - v.start_tick > 3000 then
reset_player_runningspeed(game.players[k])
end
end
end
end
if game.tick % 180 == 0 then
if game.tick % 200 == 0 then
if global.player_pets == nil then
return
if game.tick % 900 == 0 then
if global.player_speed_boost_records then
for k,v in pairs(global.player_speed_boost_records) do
if game.tick - v.start_tick > 3000 then
reset_player_runningspeed(game.players[k])
end
end
end
end
if global.player_pets then
for _, pets in pairs(global.player_pets) do
local player = game.players[pets.owner]
if pcall(function () local x = pets.entity.name end) then
if global.pet_command_rotation % 15 == 0 then
local surface = game.surfaces[1]
local pet_pos = pets.entity.position
local pet_name = pets.entity.name
local pet_direction = pets.entity.direction
pets.entity.destroy()
pets.entity = surface.create_entity {name=pet_name, position=pet_pos, direction=pet_direction, force="player"}
end
if global.pet_command_rotation % 2 == 1 then
pets.entity.set_command({type=defines.command.go_to_location, destination=player.position,distraction=defines.distraction.none})
else
local fake_pos = pets.entity.position
pets.entity.set_command({type=defines.command.go_to_location, destination=fake_pos,distraction=defines.distraction.none})
end
else
global.player_pets[pets.id] = nil
local str = player.name .. "´s pet died ;_;"
game.print(str)
end
end
global.pet_command_rotation = global.pet_command_rotation + 1
end
for _, pets in pairs(global.player_pets) do
local player = game.players[pets.owner]
if pcall(function () local x = pets.entity.name end) then
if global.pet_command_rotation % 15 == 0 then
local surface = game.surfaces[1]
local pet_pos = pets.entity.position
local pet_name = pets.entity.name
local pet_direction = pets.entity.direction
pets.entity.destroy()
pets.entity = surface.create_entity {name=pet_name, position=pet_pos, direction=pet_direction, force="player"}
end
if global.pet_command_rotation % 2 == 1 then
pets.entity.set_command({type=defines.command.go_to_location, destination=player.position,distraction=defines.distraction.none})
else
local fake_pos = pets.entity.position
pets.entity.set_command({type=defines.command.go_to_location, destination=fake_pos,distraction=defines.distraction.none})
end
else
global.player_pets[pets.id] = nil
local str = player.name .. "´s pet died ;_;"
game.print(str)
end
end
global.pet_command_rotation = global.pet_command_rotation + 1
end
end
--[[
function help()
local infotext = global.player_pets[1].entity.help()
player = game.players[1]
player.gui.left.direction = "horizontal"
local frame = player.gui.left.add { type = "frame", name = "info_panel"}
frame.style.top_padding = 20
frame.style.left_padding = 20
frame.style.right_padding = 20
frame.style.bottom_padding = 20
local info_table = frame.add { type = "table", colspan = 1, name = "info_table" }
local headline_label = info_table.add { type = "label", name = "headline_label", caption = "redmew fishy info" }
headline_label.style.font = "default-listbox"
headline_label.style.font_color = { r=0.98, g=0.66, b=0.22}
local text_box = info_table.add { type = "text-box", text = infotext, name = "text_box" }
text_box.read_only = true
text_box.selectable = true
text_box.word_wrap = false
text_box.style.right_padding = 5
text_box.style.top_padding = 5
text_box.style.left_padding = 5
text_box.style.bottom_padding = 5
end
--]]
Event.register(defines.events.on_preplayer_mined_item, preplayer_mined_item)
Event.register(defines.events.on_entity_died, fish_drop_entity_died)
Event.register(defines.events.on_market_item_purchased, market_item_purchased)
Event.register(defines.events.on_tick, on_tick)

16
on_tick.lua Normal file
View File

@ -0,0 +1,16 @@
local function on_tick()
if game.tick % 60 == 0 then
poll_on_second()
walk_distance_on_second()
if game.tick % 120 == 0 then
pet_on_120_ticks()
if game.tick % 1200 == 0 then
player_list_on_12_seconds()
end
elseif game.tick % 180 == 0 then
fish_market_on_180_ticks()
end
end
end
Event.register(defines.events.on_tick, on_tick)

58
pet.lua
View File

@ -1,8 +1,8 @@
--[[local function on_player_joined_game(event)
local player = game.players[event.player_index]
if player.gui.top.pet_button == nil then
local button = player.gui.top.add({ type = "sprite-button", name = "pet_button", sprite = "entity/small-biter" })
local button = player.gui.top.add({ type = "sprite-button", name = "pet_button", sprite = "entity/small-biter" })
button.style.minimal_height = 38
button.style.minimal_width = 38
button.style.top_padding = 0
@ -13,8 +13,8 @@
end
local function show_pet_panel(player)
local frame = player.gui.left.add { type = "frame", name = "pet-panel", direction = "vertical" }
local frame = player.gui.left.add { type = "frame", name = "pet-panel", direction = "vertical" }
pet_table = frame.add { type = "table", name = "pet_panel_table", colspan = 2 }
pet_table.add({ type = "sprite-button", name = "pet_button", sprite = "entity/small-biter" })
end
@ -25,19 +25,19 @@ function pet(player, entity_name)
else
player = game.players[player]
end
if not entity_name then
if not entity_name then
entity_name = "small-biter"
end
if not global.player_pets then global.player_pets = {} end
local surface = game.surfaces[1]
local pos = player.position
pos.y = pos.y - 2
local x = 1
x = x + #global.player_pets
global.player_pets[x] = {}
global.player_pets[x].entity = surface.create_entity {name=entity_name, position=pos, force="player"}
global.player_pets[x].owner = player.index
@ -45,44 +45,18 @@ function pet(player, entity_name)
end
local function on_tick()
if game.tick % 120 == 0 then
for _, pets in pairs(global.player_pets) do
local player = game.players[pets.owner]
if pcall(function () local x = pets.entity.name end) then
pets.entity.set_command({type=defines.command.go_to_location, destination=player.position,distraction=defines.distraction.none})
else
global.player_pets[pets.id] = nil
local str = player.name .. "´s pet died ;_;"
game.print(str)
-- game.print(pets.id)
end
end
end
end
--[[
local function try()
local x = global.player_pets[1].entity.name
end
function test()
function pet_on_120_ticks()
for _, pets in pairs(global.player_pets) do
local str = " ID="
str = str .. pets.id
if pcall(function () local x = global.player_pets[pets.id].entity.name end) then
str = str .. pets.entity.name
local player = game.players[pets.owner]
if pcall(function () local x = pets.entity.name end) then
pets.entity.set_command({type=defines.command.go_to_location, destination=player.position,distraction=defines.distraction.none})
else
str = str .. "entity.. HAS.... NOOO... NAAAAAAMEEE"
global.player_pets[pets.id] = nil
local str = player.name .. "´s pet died ;_;"
game.print(str)
end
str = str .. " ownerID="
str = str .. pets.owner
game.print(str)
end
end
]]--
Event.register(defines.events.on_gui_click, on_gui_click)
Event.register(defines.events.on_player_joined_game, on_player_joined_game)
Event.register(defines.events.on_tick, on_tick)

View File

@ -351,26 +351,22 @@ local function on_gui_click(event)
end
local function on_tick()
if game.tick % 1200 == 0 then
for _,player in pairs(game.connected_players) do
if player.gui.left["player-list-panel"] then
local sort_method
if string.find(player.gui.left["player-list-panel"].player_list_panel_header_table.player_list_panel_header_2.caption, symbol_desc) then sort_method = "name_desc" end
if string.find(player.gui.left["player-list-panel"].player_list_panel_header_table.player_list_panel_header_2.caption, symbol_asc) then sort_method = "name_asc" end
if string.find(player.gui.left["player-list-panel"].player_list_panel_header_table.player_list_panel_header_3.caption, symbol_desc) then sort_method = "time_played_desc" end
if string.find(player.gui.left["player-list-panel"].player_list_panel_header_table.player_list_panel_header_3.caption, symbol_asc) then sort_method = "time_played_asc" end
if string.find(player.gui.left["player-list-panel"].player_list_panel_header_table.player_list_panel_header_4.caption, symbol_desc) then sort_method = "distance_desc" end
if string.find(player.gui.left["player-list-panel"].player_list_panel_header_table.player_list_panel_header_4.caption, symbol_asc) then sort_method = "distance_asc" end
if string.find(player.gui.left["player-list-panel"].player_list_panel_header_table.player_list_panel_header_5.caption, symbol_desc) then sort_method = "pokes_desc" end
if string.find(player.gui.left["player-list-panel"].player_list_panel_header_table.player_list_panel_header_5.caption, symbol_asc) then sort_method = "pokes_asc" end
player.gui.left["player-list-panel"].destroy()
player_list_show(player,sort_method)
end
function player_list_on_12_seconds()
for _,player in pairs(game.connected_players) do
if player.gui.left["player-list-panel"] then
local sort_method
if string.find(player.gui.left["player-list-panel"].player_list_panel_header_table.player_list_panel_header_2.caption, symbol_desc) then sort_method = "name_desc" end
if string.find(player.gui.left["player-list-panel"].player_list_panel_header_table.player_list_panel_header_2.caption, symbol_asc) then sort_method = "name_asc" end
if string.find(player.gui.left["player-list-panel"].player_list_panel_header_table.player_list_panel_header_3.caption, symbol_desc) then sort_method = "time_played_desc" end
if string.find(player.gui.left["player-list-panel"].player_list_panel_header_table.player_list_panel_header_3.caption, symbol_asc) then sort_method = "time_played_asc" end
if string.find(player.gui.left["player-list-panel"].player_list_panel_header_table.player_list_panel_header_4.caption, symbol_desc) then sort_method = "distance_desc" end
if string.find(player.gui.left["player-list-panel"].player_list_panel_header_table.player_list_panel_header_4.caption, symbol_asc) then sort_method = "distance_asc" end
if string.find(player.gui.left["player-list-panel"].player_list_panel_header_table.player_list_panel_header_5.caption, symbol_desc) then sort_method = "pokes_desc" end
if string.find(player.gui.left["player-list-panel"].player_list_panel_header_table.player_list_panel_header_5.caption, symbol_asc) then sort_method = "pokes_asc" end
player.gui.left["player-list-panel"].destroy()
player_list_show(player,sort_method)
end
end
end
Event.register(defines.events.on_tick, on_tick)
Event.register(defines.events.on_player_joined_game, on_player_joined_game)
Event.register(defines.events.on_gui_click, on_gui_click)

211
poll.lua
View File

@ -1,11 +1,11 @@
----------------------------------------------------------------------------------------------------------------------------------------
-- Create Polls for your Factory Workers
-- by MewMew -- with some help from RedLabel, Klonan, Morcup, BrainClot
-- Create Polls for your Factory Workers
-- by MewMew -- with some help from RedLabel, Klonan, Morcup, BrainClot
----------------------------------------------------------------------------------------------------------------------------------------
local function create_poll_gui(event)
local player = game.players[event.player_index]
if player.gui.top.poll == nil then
local button = player.gui.top.add { name = "poll", type = "sprite-button", sprite = "item/programmable-speaker" }
button.style.font = "default-bold"
@ -19,32 +19,32 @@ local function create_poll_gui(event)
end
local function poll_show(player)
player.gui.left.direction = "horizontal"
local frame = player.gui.left.add { type = "frame", name = "poll-panel", direction = "vertical" }
player.gui.left.direction = "horizontal"
local frame = player.gui.left.add { type = "frame", name = "poll-panel", direction = "vertical" }
frame.add { type = "table", name = "poll_panel_table", colspan = 2 }
local poll_panel_table = frame.poll_panel_table
if not (global.poll_question == "") then
local str = "Poll #" .. global.score_total_polls_created .. ":"
if global.score_total_polls_created > 1 then
local x = game.tick
x = ((x / 60) / 60) / 60
x = global.score_total_polls_created / x
x = global.score_total_polls_created / x
x = round(x, 0)
str = str .. " (Polls/hour: "
str = str .. x
str = str .. ")"
end
poll_panel_table.add { type = "label", caption = str, single_line = false, name = "poll_number_label" }
poll_panel_table.poll_number_label.style.font_color = { r=0.75, g=0.75, b=0.75}
poll_panel_table.add { type = "label"}
poll_panel_table.add { type = "label"}
--poll_panel_table.add { caption = "----------------------------", type = "label" }
--poll_panel_table.add { type = "label" }
--poll_panel_table.add { type = "label" }
poll_panel_table.add { type = "label", caption = global.poll_question, single_line = false, name = "question_label" }
poll_panel_table.question_label.style.maximal_width = 208
poll_panel_table.question_label.style.maximal_height = 170
@ -52,61 +52,61 @@ local function poll_show(player)
poll_panel_table.question_label.style.font_color = { r=0.98, g=0.66, b=0.22}
poll_panel_table.add { type = "label" }
end
local y = 1
while (y < 4) do
if not (global.poll_answers[y] == "") then
if not (global.poll_answers[y] == "") then
local z = tostring(y)
poll_panel_table.add { type = "label", caption = global.poll_answers[y], single_line = false, name = "answer_label_" .. z }
local answer_label = poll_panel_table["answer_label_" .. z]
answer_label.style.maximal_width = 208
answer_label.style.minimal_width = 208
answer_label.style.maximal_height = 165
answer_label.style.font = "default"
local answerbutton = poll_panel_table.add { type = "button", caption = global.poll_button_votes[y], name = "answer_button_" .. z }
local answerbutton = poll_panel_table.add { type = "button", caption = global.poll_button_votes[y], name = "answer_button_" .. z }
answerbutton.style.font = "default-listbox"
end
y = y + 1
end
frame.add { type = "table", name = "poll_panel_button_table", colspan = 3 }
local poll_panel_button_table = frame.poll_panel_button_table
poll_panel_button_table.add { type = "button", caption = "New Poll", name = "new_poll_assembler_button" }
global.poll_panel_creation_time[player.index] = game.tick
local str = "Hide (" .. global.poll_duration_in_seconds
str = str .. ")"
poll_panel_button_table.add { type = "button", caption = str, name = "poll_hide_button" }
poll_panel_button_table.poll_hide_button.style.minimal_width = 70
poll_panel_button_table.poll_hide_button.style.minimal_width = 70
poll_panel_button_table.new_poll_assembler_button.style.font = "default-bold"
poll_panel_button_table.new_poll_assembler_button.style.minimal_height = 38
poll_panel_button_table.poll_hide_button.style.font = "default-bold"
poll_panel_button_table.poll_hide_button.style.minimal_height = 38
poll_panel_button_table.add { type = "checkbox", caption = "Show Polls", state = global.autoshow_polls_for_player[player.name], name = "auto_show_polls_checkbox" }
poll_panel_button_table.poll_hide_button.style.font = "default-bold"
poll_panel_button_table.poll_hide_button.style.minimal_height = 38
poll_panel_button_table.add { type = "checkbox", caption = "Show Polls", state = global.autoshow_polls_for_player[player.name], name = "auto_show_polls_checkbox" }
end
local function poll(player)
local frame = player.gui.left["poll-assembler"]
frame = frame.table_poll_assembler
global.poll_question = ""
global.poll_question = frame.textfield_question.text
if (global.poll_question == "") then
return
end
global.poll_answers = {"","",""}
global.poll_answers[1] = frame.textfield_answer_1.text
global.poll_answers[2] = frame.textfield_answer_2.text
@ -114,79 +114,79 @@ local function poll(player)
if (global.poll_answers[3] .. global.poll_answers[2] .. global.poll_answers[1] == "") then
return
end
local msg = player.name
msg = msg .. " has created a new Poll!"
global.score_total_polls_created = global.score_total_polls_created + 1
local frame = player.gui.left["poll-assembler"]
frame.destroy()
global.poll_voted = nil
global.poll_voted = nil
global.poll_voted = {}
global.poll_button_votes = {0,0,0}
local x = 1
while (game.players[x] ~= nil) do
local player = game.players[x]
local frame = player.gui.left["poll-panel"]
local frame = player.gui.left["poll-panel"]
if (frame) then
frame.destroy()
end
if (global.autoshow_polls_for_player[player.name] == true) then
poll_show(player)
end
player.print(msg)
x = x + 1
end
---------------------
-- data for score.lua
---------------------
--global.score_total_polls_created = global.score_total_polls_created + 1
--refresh_score()
end
local function poll_refresh()
local x = 1
while (game.players[x] ~= nil) do
local player = game.players[x]
if (player.gui.left["poll-panel"]) then
if (player.gui.left["poll-panel"]) then
local frame = player.gui.left["poll-panel"]
frame = frame.poll_panel_table
if not (frame.answer_button_1 == nil) then
if not (frame.answer_button_1 == nil) then
frame.answer_button_1.caption = global.poll_button_votes[1]
end
if not (frame.answer_button_2 == nil) then
if not (frame.answer_button_2 == nil) then
frame.answer_button_2.caption = global.poll_button_votes[2]
end
if not (frame.answer_button_3 == nil) then
if not (frame.answer_button_3 == nil) then
frame.answer_button_3.caption = global.poll_button_votes[3]
end
end
end
x = x + 1
end
end
local function poll_assembler(player)
local frame = player.gui.left.add { type = "frame", name = "poll-assembler", caption = "" }
local function poll_assembler(player)
local frame = player.gui.left.add { type = "frame", name = "poll-assembler", caption = "" }
local frame_table = frame.add { type = "table", name = "table_poll_assembler", colspan = 2 }
frame_table.add { type = "label", caption = "Question:" }
frame_table.add { type = "textfield", name = "textfield_question", text = "" }
@ -212,25 +212,25 @@ function poll_sync_for_new_joining_player(event)
if not global.poll_duration_in_seconds then global.poll_duration_in_seconds = 99 end
if not global.poll_panel_creation_time then global.poll_panel_creation_time = {} end
if not global.score_total_polls_created then global.score_total_polls_created = 0 end
local player = game.players[event.player_index]
local player = game.players[event.player_index]
global.autoshow_polls_for_player[player.name] = true
local frame = player.gui.left["poll-panel"]
local frame = player.gui.left["poll-panel"]
if (frame == nil) then
if not (global.poll_question == "") then
poll_show(player)
end
end
end
end
local function on_gui_click(event)
if not (event and event.element and event.element.valid) then return end
local player = game.players[event.element.player_index]
local name = event.element.name
if (name == "poll") then
local frame = player.gui.left["poll-panel"]
if (frame) then
@ -238,13 +238,13 @@ local function on_gui_click(event)
else
poll_show(player)
end
local frame = player.gui.left["poll-assembler"]
if (frame) then
frame.destroy()
end
end
if (name == "new_poll_assembler_button") then
local frame = player.gui.left["poll-assembler"]
if (frame) then
@ -253,11 +253,11 @@ local function on_gui_click(event)
poll_assembler(player)
end
end
if (name == "create_new_poll_button") then
if (name == "create_new_poll_button") then
poll(player)
end
if (name == "poll_hide_button") then
local frame = player.gui.left["poll-panel"]
if (frame) then
@ -268,58 +268,55 @@ local function on_gui_click(event)
frame.destroy()
end
end
if (name == "auto_show_polls_checkbox") then
global.autoshow_polls_for_player[player.name] = event.element.state
end
if global.poll_voted[event.player_index] == nil then
global.autoshow_polls_for_player[player.name] = event.element.state
end
if global.poll_voted[event.player_index] == nil then
if(name == "answer_button_1") then
global.poll_button_votes[1] = global.poll_button_votes[1] + 1
global.poll_voted[event.player_index] = player.name
poll_refresh()
end
if(name == "answer_button_2") then
global.poll_button_votes[2] = global.poll_button_votes[2] + 1
global.poll_voted[event.player_index] = player.name
poll_refresh()
end
if(name == "answer_button_3") then
global.poll_button_votes[3] = global.poll_button_votes[3] + 1
global.poll_voted[event.player_index] = player.name
poll_refresh()
end
end
end
end
local function on_tick()
if game.tick % 60 == 0 then
for _, player in pairs(game.connected_players) do
if global.poll_panel_creation_time[player.index] then
local frame = player.gui.left["poll-panel"]
if frame then
local y = (game.tick - global.poll_panel_creation_time[player.index]) / 60
local y = global.poll_duration_in_seconds - y
y = round(y, 0)
if y <= 0 then
frame.destroy()
global.poll_panel_creation_time[player.index] = nil
else
y = "Hide (" .. y
y = y .. ")"
frame.poll_panel_button_table.poll_hide_button.caption = y
end
function poll_on_second()
for _, player in pairs(game.connected_players) do
if global.poll_panel_creation_time[player.index] then
local frame = player.gui.left["poll-panel"]
if frame then
local y = (game.tick - global.poll_panel_creation_time[player.index]) / 60
local y = global.poll_duration_in_seconds - y
y = round(y, 0)
if y <= 0 then
frame.destroy()
global.poll_panel_creation_time[player.index] = nil
else
y = "Hide (" .. y
y = y .. ")"
frame.poll_panel_button_table.poll_hide_button.caption = y
end
end
end
end
end
end
Event.register(defines.events.on_tick, on_tick)
Event.register(defines.events.on_gui_click, on_gui_click)
Event.register(defines.events.on_player_joined_game, create_poll_gui)
Event.register(defines.events.on_player_joined_game, poll_sync_for_new_joining_player)
Event.register(defines.events.on_player_joined_game, poll_sync_for_new_joining_player)

View File

@ -1,10 +1,4 @@
local function on_tick()
if game.tick % 60 == 0 then
on_second()
end
end
function on_second()
function walk_distance_on_second()
local last_positions = global.scenario.variables.player_positions
local d_x = 0
local d_y = 0
@ -29,8 +23,9 @@ end
local function init_player_position(event)
local player = game.players[event.player_index]
global.scenario.variables.player_positions[player.name] = player.position
global.scenario.variables.player_walk_distances[player.name] = 0
if not global.scenario.variables.player_walk_distances[player.name] then
global.scenario.variables.player_walk_distances[player.name] = 0
end
end
Event.register(defines.events.on_tick, on_tick)
Event.register(defines.events.on_player_joined_game, init_player_position)