]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
[script] Add support for the password dialogue in the example script theme
authorCharlie Brej <cbrej@cs.man.ac.uk>
Tue, 30 Jun 2009 15:58:39 +0000 (16:58 +0100)
committerCharlie Brej <cbrej@cs.man.ac.uk>
Tue, 30 Jun 2009 15:58:39 +0000 (16:58 +0100)
src/plugins/splash/script/script-lib-sprite.script
themes/script/Makefile.am
themes/script/box.png [new file with mode: 0644]
themes/script/bullet.png [new file with mode: 0644]
themes/script/entry.png [new file with mode: 0644]
themes/script/lock.png [new file with mode: 0644]
themes/script/script.script

index 95f279efe0a4b9472149e8ba32741798e4e4c5f9..847778abffc63dbd305633aa6ea91dd7d183fda1 100644 (file)
@@ -1,26 +1,5 @@
-fun SpriteUpdate(sprite){
-    SpriteSetX(sprite.native, sprite.x);
-    SpriteSetY(sprite.native, sprite.y);
-    SpriteSetZ(sprite.native, sprite.z);
-    SpriteSetImage(sprite.native, sprite.image);
+fun SpriteSetPosition(sprite, x, y, z){
+    SpriteSetX(sprite, x);
+    SpriteSetY(sprite, y);
+    SpriteSetZ(sprite, z);
     }
-
-
-fun SpriteNewWithImage(filename){
-    local.sprite;
-    
-    sprite.image = ImageNew(filename);
-    sprite.native = SpriteNew();
-    if (sprite.image == NULL) return NULL;
-    SpriteSetImage(sprite.native, sprite.image);
-    
-    sprite.x = 0;
-    sprite.y = 0;
-    sprite.z = 0;
-    
-    SpriteUpdate(sprite);
-    
-    return sprite;
-    }
-
-
index b66a801336e453281c7ece07d776dcc4679a17b1..add4bb97a1e2014ee37008ea25a35b0c9fabd08f 100644 (file)
@@ -1,7 +1,11 @@
 themedir = $(datadir)/plymouth/themes/script
 dist_theme_DATA =                                                     \
                     script.plymouth                                   \
-                    script.script
+                    script.script                                     \
+                    box.png                                           \
+                    bullet.png                                        \
+                    entry.png                                         \
+                    lock.png
 
 
 MAINTAINERCLEANFILES = Makefile.in script.plymouth
diff --git a/themes/script/box.png b/themes/script/box.png
new file mode 100644 (file)
index 0000000..54876e6
Binary files /dev/null and b/themes/script/box.png differ
diff --git a/themes/script/bullet.png b/themes/script/bullet.png
new file mode 100644 (file)
index 0000000..dd52736
Binary files /dev/null and b/themes/script/bullet.png differ
diff --git a/themes/script/entry.png b/themes/script/entry.png
new file mode 100644 (file)
index 0000000..a9f4157
Binary files /dev/null and b/themes/script/entry.png differ
diff --git a/themes/script/lock.png b/themes/script/lock.png
new file mode 100644 (file)
index 0000000..a0f8c12
Binary files /dev/null and b/themes/script/lock.png differ
index a84448ed001371cebe0370c948922b83510a3dc3..59a43e97998ee3bc2e42973cf96eaa8b1645c6b9 100644 (file)
+
+
+
 index = 0;
+while (1){
+    index_string = "" + index;
+    if (index < 10) index_string = "0" + index_string;
+    frame_image[index] = ImageNew("../spinfinity/throbber-" + index_string + ".png");
+    if (!frame_image[index]) break;
+    index++;
+    }
+frame_count = index + 1;
+frame_index = 0;
+throbber_sprite = SpriteNew();
 
-while (index<30){
-    mystring = index;
-    if (index<10) mystring = "0" + index;
-    sprites[index] = SpriteNewWithImage("../spinfinity/throbber-" + mystring + ".png");
-    sprites[index].orig_image = sprites[index].image;
-    sprites[index].xd = (50 + index)/10;
-    sprites[index].yd = (50 + index)/10;
-    index = index + 1;
+fun refresh (){
+    if (status == "normal"){
+        frame_index = (frame_index + 20/50) % frame_count;
+        int_frame_index = MathInt(frame_index);
+        SpriteSetImage (throbber_sprite, frame_image[int_frame_index]);
+        SpriteSetX (throbber_sprite, 400 - ImageGetWidth(frame_image[int_frame_index])  / 2);
+        SpriteSetY (throbber_sprite, 300 - ImageGetHeight(frame_image[int_frame_index]) / 2);
+        SpriteSetOpacity (throbber_sprite, 1);
+        }
+    if (status != "normal"){
+        SpriteSetOpacity (throbber_sprite, 0);
+        }
     }
 
-random = 1;
-count = 0;
-progress=0;
+refresh ();                         # do one at the start
+PlymouthSetRefreshFunction (refresh);
+
+
+
+
+
+
+
+
+
+
+
+
 
-fun update_logo_sprite (sprite){
-    image_width =  ImageGetWidth (sprite.image);
-    image_height = ImageGetHeight(sprite.image);
+#-----------------------------------------Dialogue stuff --------------------------------
+
+
+status = "normal";
+
+fun dialogue_setup(){
+    local.box;
+    local.lock;
+    local.entry;
+    local.bullet_image;
+    
+    box.image = ImageNew("box.png");
+    lock.image = ImageNew("lock.png");
+    entry.image = ImageNew("entry.png");
+    bullet_image = ImageNew("bullet.png");
+    
+    box.sprite = SpriteNew();
+    SpriteSetImage(box.sprite, box.image);
+    box.x = 400 - ImageGetWidth (box.image)/2;
+    box.y = 300 - ImageGetHeight(box.image)/2;
+    box.z = 10000;
+    SpriteSetPosition(box.sprite, box.x, box.y, box.z);
     
-    if (sprite.x < 0)
-        sprite.xd = +(global.random % 5 + 1);
-    if (sprite.y < 0)
-        sprite.yd = +(global.random % 5 + 1);
-    if ((sprite.x + image_width) > 800)
-        sprite.xd = -((global.random % 5 + 1));
-    if ((sprite.y + image_height) > 600)
-        sprite.yd = -((global.random % 5 + 1));
-
-    global.random = (1 + global.random * 7) % 101;
+    lock.sprite = SpriteNew();
+    SpriteSetImage(lock.sprite, lock.image);
+    lock.x = box.x + ImageGetWidth(box.image)/2 - (ImageGetWidth(lock.image) + ImageGetWidth(entry.image)) / 2;
+    lock.y = box.y + ImageGetHeight(box.image)/2 - ImageGetHeight(lock.image)/2;
+    lock.z = box.z + 1;
+    SpriteSetPosition(lock.sprite, lock.x, lock.y, lock.z);
     
-    sprite.x = sprite.x + sprite.xd*global.progress;
-    sprite.y = sprite.y + sprite.yd*global.progress;
-    sprite.image = ImageRotate(sprite.orig_image, count*0.1);
-    SpriteUpdate(sprite);
+    entry.sprite = SpriteNew();
+    SpriteSetImage(entry.sprite, entry.image);
+    entry.x = lock.x + ImageGetWidth(lock.image);
+    entry.y = box.y + ImageGetHeight(box.image)/2 - ImageGetHeight(entry.image)/2;
+    entry.z = box.z + 1;
+    SpriteSetPosition(entry.sprite, entry.x, entry.y, entry.z);
+    
+    
+    global.dialogue = local;
     }
-
-
-fun refresh (){
+    
+fun dialogue_opacity(opacity){
+    global.dialogue.opacity = opacity;
+    local = global.dialogue;
+    SpriteSetOpacity (box.sprite, opacity);
+    SpriteSetOpacity (lock.sprite, opacity);
+    SpriteSetOpacity (entry.sprite, opacity);
     index = 0;
-    count++;
-    while (!(index>=30)){
-        update_logo_sprite (sprites[index]);
+    while (bullet[index]){
+        SpriteSetOpacity(bullet[index].sprite, opacity);
         index++;
         }
-    return;
     }
 
-fun on_progress (duration, progress){
-    global.progress = progress*300;
+fun display_normal (){
+    global.status = "normal";
+    if (!global.dialogue) return;
+    dialogue_setup();
+    dialogue_opacity (0);
     }
-    
-fun on_keyboard (key){
+
+PlymouthSetDisplayNormalFunction(display_normal);
+
+fun display_password (prompt, bullets){
+    global.status = "password";
+    if (!global.dialogue) dialogue_setup();
+    dialogue_opacity (1);
     index = 0;
-    if (key == "a"){
-        while (!(index>=30)){
-            sprites[index].x = 0;
-            index++;
+    while (dialogue.bullet[index] || index < bullets){
+        if (!dialogue.bullet[index]){
+            dialogue.bullet[index].sprite = SpriteNew();
+            SpriteSetImage(dialogue.bullet[index].sprite, dialogue.bullet_image);
+            dialogue.bullet[index].x = dialogue.entry.x + index * ImageGetWidth(dialogue.bullet_image);
+            SpriteSetX(dialogue.bullet[index].sprite, dialogue.bullet[index].x);
+            dialogue.bullet[index].y = dialogue.entry.y + ImageGetHeight(dialogue.entry.image)/2 - ImageGetHeight(dialogue.bullet_image)/2;
+            SpriteSetY(dialogue.bullet[index].sprite, dialogue.bullet[index].y);
+            dialogue.bullet[index].z = dialogue.entry.z + 1;
+            SpriteSetZ(dialogue.bullet[index].sprite, dialogue.bullet[index].z);
             }
-        }
-    if (key == "b"){
-        while (!(index>=30)){
-            sprites[index].y = 0;
-            index++;
+        SpriteSetOpacity(dialogue.bullet[index].sprite, 0);
+        if (index < bullets){
+            SpriteSetOpacity(dialogue.bullet[index].sprite, 1);
             }
+        
+        index++;
         }
-    return;
     }
-
-
-// This is a comment
-# As is this (both are acceptable because people do forget which to use)
-/* A block comment /* with a nested sub-comment */ */
-
-PlymouthSetRefreshFunction(refresh);
-PlymouthSetKeyboardInputFunction(on_keyboard);
-PlymouthSetBootProgressFunction(on_progress);
-PlymouthSetUpdateStatusFunction(on_keyboard);
+PlymouthSetDisplayPasswordFunction(display_password);