Prechádzať zdrojové kódy

added change of window texture from script

quantumde1 1 mesiac pred
rodič
commit
1039144bfb

+ 1 - 1
conf/settings.conf

@@ -2,7 +2,7 @@ TITLE:Remember11 - Self Chapter
 MENU_SCRIPT:scripts/menu.lua
 SCRIPT:scripts/SA00.lua
 DIALOG_END_INDICATOR:res/misc/circle.png
-DIALOG_BOX:res/misc/TEX#win_01b.PNG
+DIALOG_BOX:res/misc/TEX#win_02b.PNG
 FALLBACK_FONT:res/font_en.png
 ICON:res/icon.png
 DEV_SCREEN_WIDTH:1344

+ 2 - 2
source/graphics/effects.d

@@ -30,7 +30,7 @@ Texture2D[] loadAnimationFramesUI(const string fileDir, const string animationFi
     return frames;
 }
 
-void playUIAnimation(Texture2D[] frames)
+void playUIAnimation(Texture2D[] frames, ubyte alpha)
 {
     static float frameTime = 0.0f;
     
@@ -51,7 +51,7 @@ void playUIAnimation(Texture2D[] frames)
             Rectangle(0, 0, screenWidth, screenHeight),
             Vector2(0, 0),
             0,
-            Color(255, 255, 255, 127)
+            Color(255, 255, 255, alpha)
         );
     } else {
         frameTime = 0.0f;

+ 2 - 2
source/graphics/gamelogic.d

@@ -16,7 +16,7 @@ import system.abstraction;
 void gameInit()
 {
     circle = LoadTexture(systemSettings.dialogBoxEndIndicator.toStringz());
-    dialogBackgroundTex = LoadTexture(systemSettings.dialogBoxImage.toStringz());
+    dialogBackgroundTex = LoadTexture(systemSettings.dialogBoxBackground.toStringz());
     if (WindowShouldClose()) {
         currentGameState = GameState.Exit;
     } else {
@@ -70,7 +70,7 @@ void effectsLogic() {
             isCameraMoving = false;
         }
     }
-    playUIAnimation(framesUI);
+    playUIAnimation(framesUI, animationAlpha);
 }
 
 void backgroundLogic() {

+ 26 - 1
source/scripts/lua.d

@@ -350,7 +350,13 @@ extern (C) nothrow int luaL_loadUIAnimation(lua_State *L) {
 extern (C) nothrow int luaL_playUIAnimation(lua_State *L) {
     debug debugWriteln("Animation UI start");
     try {
-        playAnimation = true;
+        if (lua_gettop(L) == 0) playAnimation = true;
+        else {
+            debugWriteln("animationAlpha before reconfig: ", animationAlpha);
+            animationAlpha = luaL_checkinteger(L, 1).to!ubyte;
+            debugWriteln("animationAlpha after reconfig: ", animationAlpha);
+            playAnimation = true;
+        }
     } catch (Exception e) {
         debugWriteln(e.msg);
     }
@@ -376,6 +382,23 @@ extern (C) nothrow int luaL_unloadUIAnimation(lua_State *L) {
     return 0;
 }
 
+extern (C) nothrow int luaL_setDialogBoxBackground(lua_State *L) {
+    string filename = luaL_checkstring(L, 1).to!string;
+    debug debugWriteln("Set dialog background to: ", filename);
+    UnloadTexture(dialogBackgroundTex);
+    dialogBackgroundTex = Texture2D();
+    dialogBackgroundTex = LoadTexture(filename.toStringz());
+    return 0;
+}
+
+extern (C) nothrow int luaL_setDialogBoxEndIndicatorTexture(lua_State *L) {
+    char* filename = cast(char*)luaL_checkstring(L, 1);
+    UnloadTexture(circle);
+    circle = Texture2D();
+    circle = LoadTexture(filename);
+    return 0;
+}
+
 /* system */
 
 extern (C) nothrow int luaL_getScreenWidth(lua_State* L)
@@ -668,6 +691,8 @@ extern (C) nothrow void luaL_loader(lua_State* L)
     lua_register(L, "playAnimationUI", &luaL_playUIAnimation);
     lua_register(L, "stopAnimationUI", &luaL_stopUIAnimation);
     lua_register(L, "unloadAnimationUI", &luaL_unloadUIAnimation);
+    lua_register(L, "setDialogBoxBackground", &luaL_setDialogBoxBackground);
+    lua_register(L, "setDialogEndIndicator", &luaL_setDialogBoxEndIndicatorTexture);
     lua_register(L, "moveCamera", &luaL_moveCamera);
     lua_register(L, "restoreCamera", &luaL_restoreCamera);
     lua_register(L, "isCameraMoving", &luaL_isCameraMoving);

+ 0 - 53
source/ui/effects.d

@@ -7,59 +7,6 @@ import std.string;
 import system.abstraction;
 import std.file;
 
-int screenWidth;
-int screenHeight;
-
-Texture2D[] loadAnimationFramesUI(const string fileDir, const string animationFileName)
-{
-    screenWidth = systemSettings.screenWidth;
-    screenHeight = systemSettings.screenHeight;
-    Texture2D[] frames;
-    uint frameIndex = 1;
-    while (true)
-    {
-        string frameFileName = format("%s-%03d.png", animationFileName, frameIndex);
-        if (std.file.exists(fileDir~"/"~frameFileName) == false) break;
-        debug debugWriteln(frameFileName);
-        Texture2D texture = LoadTexture((fileDir~"/"~frameFileName).toStringz());
-        frames ~= texture;
-        debug debugWriteln("Loaded frame for UI ", frameIndex, " - ", frameFileName);
-        frameIndex++;
-    }
-    debug debugWriteln("Frames for ui animations length: ", frames.length);
-    return frames;
-}
-
-void playUIAnimation(Texture2D[] frames)
-{
-    static float frameTime = 0.0f;
-    
-    if (playAnimation) {
-        frameTime += GetFrameTime();
-        
-        while (frameTime >= frameDuration && frameDuration > 0) {
-            frameTime -= frameDuration;
-            currentFrame = cast(int)((currentFrame + 1) % frames.length);
-        }
-
-        int frameWidth = frames[currentFrame].width;
-        int frameHeight = frames[currentFrame].height;
-        
-        DrawTexturePro(
-            frames[currentFrame],
-            Rectangle(0, 0, frameWidth, frameHeight),
-            Rectangle(0, 0, screenWidth, screenHeight),
-            Vector2(0, 0),
-            0,
-            Color(255, 255, 255, 127)
-        );
-    } else {
-        frameTime = 0.0f;
-        currentFrame = 0;
-    }
-}
-
-
 void fadeEffect(float alpha, bool fadeIn, void delegate(float alpha) renderer)
 {
     const float FadeIncrement = 0.02f;

+ 2 - 1
source/variables.d

@@ -31,7 +31,7 @@ struct SystemSettings {
     string windowTitle;
     string iconPath;
     string dialogBoxEndIndicator;
-    string dialogBoxImage;
+    string dialogBoxBackground;
     string fallbackFont;
     int defaultScreenWidth;
     int defaultScreenHeight;
@@ -148,6 +148,7 @@ int currentFrame = 0;
 
 int currentChoiceCharIndex = 0;
 
+ubyte animationAlpha = 127;
 
 /* lua */