Simplify music player interface
authorZefram <zefram@fysh.org>
Thu, 14 Aug 2014 14:29:50 +0000 (15:29 +0100)
committerZefram <zefram@fysh.org>
Fri, 15 Aug 2014 11:25:46 +0000 (12:25 +0100)
Having a track selected now implies playing it, rather than
playing/stopped being a hidden state separate from track selection.

technic/locale/de.txt
technic/locale/es.txt
technic/locale/it.txt
technic/locale/template.txt
technic/machines/LV/music_player.lua

index 6f9f8d2a63c303d74ec35477a26754a014de66e5..31ea1073ebbc9be8cdb42d37af045be362cdcf25 100644 (file)
@@ -113,6 +113,7 @@ Production at %d%% = Produktion bei %d%%
 Choose Milling Program: = Waehle ein Fraesprogramm:
 Slim Elements half / normal height: = Schmale Elemente von halber / normaler Hoehe:
 Current track %s = Aktueller Titel %s
+Stopped =
 Keeping %d/%d map blocks loaded =
 
 ## CNC
index db817f895e02b902247251d0a83112467a384dc8..80a5736dc4c3647f4602ab8bd872c07812e4285a 100644 (file)
@@ -107,6 +107,7 @@ Power level = Nivel de Poder
 %s. Supply: %d Demand: %d = %s. Alimentacion: %d Demanda: %d
 # $1: Production percent
 Production at %d%% = Produccion en %d%%
+Stopped =
 Keeping %d/%d map blocks loaded =
 
 ## CNC Machine
index 7b1c5377cfc4c1de3a0f628cc6d313b0767313a1..4ad5a97dfc34332c7b073a25d92f97fb9b98a2f1 100644 (file)
@@ -110,6 +110,7 @@ Production at %d%% = Produzione a %d%%
 Choose Milling Program: = Scegliere un programma di Fresatura
 Slim Elements half / normal height: = Metà elementi sottili / altezza normale:
 Current track %s = Traccia corrente %s
+Stopped =
 Keeping %d/%d map blocks loaded =
 
 ## CNC
index 8bd5b2d3a5e41577140bb89eefd11a8e81a159c2..4df358608e453712afd45c4da52a401b97140702 100644 (file)
@@ -118,6 +118,7 @@ Production at %d%% =
 Choose Milling Program: =
 Slim Elements half / normal height: =
 Current track %s =
+Stopped =
 Keeping %d/%d map blocks loaded =
 
 ## CNC
index ba5daab4094680a5ffd95293ff326157658474cd..dc7e2d0a1745ab19b41775f4cbbc894bbd8c7876 100644 (file)
@@ -15,22 +15,6 @@ minetest.register_craft({
 
 local music_handles = {}
 
-local music_player_formspec =
-       "invsize[8,9;]"..
-       "label[0,0;"..S("%s Music Player"):format("LV").."]"..
-       "button[4,1;1,1;track1;1]"..
-       "button[5,1;1,1;track2;2]"..
-       "button[6,1;1,1;track3;3]"..
-       "button[4,2;1,1;track4;4]"..
-       "button[5,2;1,1;track5;5]"..
-       "button[6,2;1,1;track6;6]"..
-       "button[4,3;1,1;track7;7]"..
-       "button[5,3;1,1;track8;8]"..
-       "button[6,3;1,1;track9;9]"..
-       "button[4,4;1,2;play;Play]"..
-       "button[6,4;1,2;stop;Stop]"..
-       "label[4,0;"..S("Current track %s"):format("--").."]"
-
 local function play_track(pos, track)
        return minetest.sound_play("technic_track"..tostring(track),
                        {pos = pos, gain = 1.0, loop = true, max_hear_distance = 72,})
@@ -85,6 +69,27 @@ local function stop_player(pos, node)
        end
 end
 
+local function set_display(meta)
+       meta:set_string("formspec",
+                       "size[4,4.5]"..
+                       "item_image[0,0;1,1;technic:music_player]"..
+                       "label[1,0;"..S("%s Music Player"):format("LV").."]"..
+                       "button[0,1;1,1;track1;1]"..
+                       "button[1,1;1,1;track2;2]"..
+                       "button[2,1;1,1;track3;3]"..
+                       "button[0,2;1,1;track4;4]"..
+                       "button[1,2;1,1;track5;5]"..
+                       "button[2,2;1,1;track6;6]"..
+                       "button[0,3;1,1;track7;7]"..
+                       "button[1,3;1,1;track8;8]"..
+                       "button[2,3;1,1;track9;9]"..
+                       "button[3,1;1,1;stop;Stop]"..
+                       "label[0,4;"..minetest.formspec_escape(
+                               meta:get_int("active") == 0 and
+                                       S("Stopped") or
+                                       S("Current track %s"):format(meta:get_int("current_track"))).."]")
+end
+
 minetest.register_node("technic:music_player", {
        description = S("%s Music Player"):format("LV"),
        tiles = {"technic_music_player_top.png", "technic_machine_bottom.png", "technic_music_player_side.png",
@@ -94,42 +99,26 @@ minetest.register_node("technic:music_player", {
        on_construct = function(pos)
                local meta = minetest.get_meta(pos)
                meta:set_string("infotext", S("%s Music Player"):format("LV"))
-               meta:set_int("active", 0)
-               meta:set_int("current_track", 1)
-               meta:set_string("formspec", music_player_formspec)
+               set_display(meta)
        end,
        on_receive_fields = function(pos, formanme, fields, sender)
-               local meta          = minetest.get_meta(pos)
-               local current_track = meta:get_int("current_track")
-               if fields.track1 then current_track = 1 end
-               if fields.track2 then current_track = 2 end
-               if fields.track3 then current_track = 3 end
-               if fields.track4 then current_track = 4 end
-               if fields.track5 then current_track = 5 end
-               if fields.track6 then current_track = 6 end
-               if fields.track7 then current_track = 7 end
-               if fields.track8 then current_track = 8 end
-               if fields.track9 then current_track = 9 end
-               meta:set_int("current_track", current_track)
-               meta:set_string("formspec",
-                               "invsize[8,9;]"..
-                               "label[0,0;"..S("%s Music Player"):format("LV").."]"..
-                               "button[4,1;1,1;track1;1]"..
-                               "button[5,1;1,1;track2;2]"..
-                               "button[6,1;1,1;track3;3]"..
-                               "button[4,2;1,1;track4;4]"..
-                               "button[5,2;1,1;track5;5]"..
-                               "button[6,2;1,1;track6;6]"..
-                               "button[4,3;1,1;track7;7]"..
-                               "button[5,3;1,1;track8;8]"..
-                               "button[6,3;1,1;track9;9]"..
-                               "button[4,4;1,2;play;Play]"..
-                               "button[6,4;1,2;stop;Stop]"..
-                               "label[4,0;"..S("Current track %s")
-                                       :format(current_track).."]")
-               if fields.play or fields.stop then
+               local new_track = nil
+               if fields.stop then new_track = 0 end
+               if fields.track1 then new_track = 1 end
+               if fields.track2 then new_track = 2 end
+               if fields.track3 then new_track = 3 end
+               if fields.track4 then new_track = 4 end
+               if fields.track5 then new_track = 5 end
+               if fields.track6 then new_track = 6 end
+               if fields.track7 then new_track = 7 end
+               if fields.track8 then new_track = 8 end
+               if fields.track9 then new_track = 9 end
+               if new_track then
                        stop_player(pos)
-                       meta:set_int("active", fields.play and 1 or 0)
+                       local meta = minetest.get_meta(pos)
+                       meta:set_int("active", new_track == 0 and 0 or 1)
+                       meta:set_int("current_track", new_track)
+                       set_display(meta)
                end
        end,
        on_destruct = stop_player,