From e7759b0d372c8f6ff57270fe2e8d2532685b32cc Mon Sep 17 00:00:00 2001 From: SimonFlapse Date: Fri, 1 Mar 2019 10:18:39 +0100 Subject: [PATCH] Converted to rich text - Reducing the footprint --- features/gui/score.lua | 65 +++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 23 deletions(-) diff --git a/features/gui/score.lua b/features/gui/score.lua index 3837108e..7589d1c3 100644 --- a/features/gui/score.lua +++ b/features/gui/score.lua @@ -10,6 +10,17 @@ local concat = table.concat local main_frame_name = Gui.uid_name() local main_button_name = Gui.uid_name() +local descriptions = { + {disc = 'Satellites launched', icon = '[img=item.satellite]'}, + {disc = 'Biters liberated', icon = '[img=entity.medium-biter]'}, + {disc = 'Buildings by hand', icon = '[img=utility.hand]'}, + {disc = 'Buildings by robots', icon = '[img=item.construction-robot]'}, + {disc = 'Trees chopped', icon = '[img=entity.tree-02]'}, + {disc = 'Rocks smashed', icon = '[img=entity.rock-huge]'}, + {disc = 'Kills by train', icon = '[img=item.locomotive]'}, + {disc = 'Coins spent', icon = '[img=item.coin]'}, +} + local function create_score_gui(event) local player = Game.get_player_by_index(event.player_index) if not player then @@ -27,14 +38,14 @@ local function refresh_score() local players = game.connected_players local count = game.forces.player.get_item_launched('satellite') - local satellites_launched = concat {'Satellites launched: ', count, ' '} - local biters_liberated = concat {'Biters liberated: ', PlayerStats.get_total_biter_kills(), ' '} - local buildings_by_hand = concat {'Buildings by hand: ', PlayerStats.get_total_player_built_entities(), ' '} - local buildings_by_robot = concat {'Buildings by robots: ', PlayerStats.get_total_robot_built_entities(), ' '} - local trees_chopped = concat {'Trees chopped: ', PlayerStats.get_total_player_trees_mined(), ' '} - local rocks_smashed = concat {'Rocks smashed: ', PlayerStats.get_total_player_rocks_mined(), ' '} - local kills_by_train = concat {'Kills by train: ', PlayerStats.get_total_train_kills(), ' '} - local coins_spent = concat {'Coins spent: ', PlayerStats.get_total_coins_spent(), ' '} + local satellites_launched = concat {descriptions[1].icon .. ' ', count, ' '} + local biters_liberated = concat {descriptions[2].icon .. ' ', PlayerStats.get_total_biter_kills(), ' '} + local buildings_by_hand = concat {descriptions[3].icon .. ' ', PlayerStats.get_total_player_built_entities(), ' '} + local buildings_by_robot = concat {descriptions[4].icon .. ' ', PlayerStats.get_total_robot_built_entities(), ' '} + local trees_chopped = concat {descriptions[5].icon .. ' ', PlayerStats.get_total_player_trees_mined(), ' '} + local rocks_smashed = concat {descriptions[6].icon .. ' ', PlayerStats.get_total_player_rocks_mined(), ' '} + local kills_by_train = concat {descriptions[7].icon .. ' ', PlayerStats.get_total_train_kills(), ' '} + local coins_spent = concat {descriptions[8].icon .. ' ', PlayerStats.get_total_coins_spent(), ' '} for i = 1, #players do local player = players[i] @@ -64,7 +75,7 @@ local function score_show(top) local count = game.forces.player.get_item_launched('satellite') local frame = top.add {type = 'frame', name = main_frame_name} - local score_table = frame.add {type = 'table', name = 'score_table', column_count = 4} + local score_table = frame.add {type = 'table', name = 'score_table', column_count = 8} local style = score_table.style style.vertical_spacing = 4 style.horizontal_spacing = 16 @@ -73,23 +84,26 @@ local function score_show(top) score_table.add { type = 'label', name = 'label_satellites_launched', - caption = concat {'Satellites launched: ', count, ' '} + caption = concat {descriptions[1].icon .. ' ', count, ' '}, + tooltip = descriptions[1].disc } - score_label_style(label, Color.orange) + score_label_style(label, Color.white) label = score_table.add { type = 'label', name = 'label_biters_killed', - caption = concat {'Biters liberated: ', PlayerStats.get_total_biter_kills(), ' '} + caption = concat {descriptions[2].icon .. ' ', PlayerStats.get_total_biter_kills(), ' '}, + tooltip = descriptions[2].disc } - score_label_style(label, Color.red) + score_label_style(label, Color.white) label = score_table.add { type = 'label', name = 'label_player_built_entities', - caption = concat {'Buildings by hand: ', PlayerStats.get_total_player_built_entities(), ' '} + caption = concat {descriptions[3].icon .. ' ', PlayerStats.get_total_player_built_entities(), ' '}, + tooltip = descriptions[3].disc } score_label_style(label, Color.white) @@ -97,7 +111,8 @@ local function score_show(top) score_table.add { type = 'label', name = 'label_robot_built_entities', - caption = concat {'Buildings by robots: ', PlayerStats.get_total_robot_built_entities(), ' '} + caption = concat {descriptions[4].icon .. ' ', PlayerStats.get_total_robot_built_entities(), ' '}, + tooltip = descriptions[4].disc } score_label_style(label, Color.white) @@ -105,33 +120,37 @@ local function score_show(top) score_table.add { type = 'label', name = 'label_player_mined_trees', - caption = concat {'Trees chopped: ', PlayerStats.get_total_player_trees_mined(), ' '} + caption = concat {descriptions[5].icon .. ' ', PlayerStats.get_total_player_trees_mined(), ' '}, + tooltip = descriptions[5].disc } - score_label_style(label, Color.lime) + score_label_style(label, Color.white) label = score_table.add { type = 'label', name = 'label_player_mined_stones', - caption = concat {'Rocks smashed: ', PlayerStats.get_total_player_rocks_mined(), ' '} + caption = concat {descriptions[6].icon .. ' ', PlayerStats.get_total_player_rocks_mined(), ' '}, + tooltip = descriptions[6].disc } - score_label_style(label, Color.lime) + score_label_style(label, Color.white) label = score_table.add { type = 'label', name = 'label_kills_by_train', - caption = concat {'Kills by train: ', PlayerStats.get_total_train_kills(), ' '} + caption = concat {descriptions[7].icon .. ' ', PlayerStats.get_total_train_kills(), ' '}, + tooltip = descriptions[7].disc } - score_label_style(label, Color.yellow) + score_label_style(label, Color.white) label = score_table.add { type = 'label', name = 'label_coins_spent', - caption = concat {'Coins spent: ', PlayerStats.get_total_coins_spent(), ' '} + caption = concat {descriptions[8].icon .. ' ', PlayerStats.get_total_coins_spent(), ' '}, + tooltip = descriptions[8].disc } - score_label_style(label, Color.yellow) + score_label_style(label, Color.white) end local function rocket_launched(event)