Exemple #1
0
 public void PlaySound(string name, int vol)
 {
     if (paused)
     {
         return;
     }
     if (sounds.ContainsKey(name))
     {
         AudioEffect ass = ((AudioEffect)sounds.Get(name));
         ass.AudioEffectVolume(vol);
         ass.PlayAudioEffect();
     }
     else
     {
         if (clipCount > 50)
         {
             int         idx  = sounds.Size() - 1;
             string      k    = (string)sounds.GetKey(idx);
             AudioEffect clip = (AudioEffect)sounds.Remove(k);
             clip.StopAudioEffect();
             clip = null;
             clipCount--;
         }
         asound = new AudioEffect(name);
         asound.AudioEffectVolume(vol);
         asound.PlayAudioEffect();
         sounds.Put(name, asound);
         clipCount++;
     }
 }
Exemple #2
0
 public virtual void ReleaseActionKeys()
 {
     keySize = keyActions.Size();
     if (keySize > 0)
     {
         for (int i = 0; i < keySize; i++)
         {
             ActionKey act = (ActionKey)keyActions.Get(i);
             act.Release();
         }
     }
 }
Exemple #3
0
        public void ReleaseActionKeys()
        {
            int size = keyActions.Size();

            if (size > 0)
            {
                for (int i = 0; i < size; i++)
                {
                    ActionKey act = (ActionKey)keyActions.Get(i);
                    act.Release();
                }
            }
        }
Exemple #4
0
        public void Add(String resName, int x, int y, int w, int h)
        {
            String path = _Update(resName);

            lock (charas)
            {
                String   keyName = path.Replace(" ", "").ToLower();
                AVGChara chara   = (AVGChara)charas.Get(keyName);
                if (chara == null)
                {
                    chara = new AVGChara(path, x, y, w, h);
                    chara.SetFlag(FadeEffect.TYPE_FADE_OUT, charaShowDelay);
                    charas.Put(keyName, chara);
                }
                else
                {
                    chara.SetFlag(FadeEffect.TYPE_FADE_OUT, charaShowDelay);
                    chara.SetX(x);
                    chara.SetY(y);
                }
            }
        }
Exemple #5
0
        public string DoExecute()
        {
            if (isClose)
            {
                return(null);
            }
            this.executeCommand = null;
            this.addCommand     = true;
            this.isInnerCommand = (innerCommand != null);
            this.if_bool        = false;
            this.elseif_bool    = false;

            try
            {
                if (isInnerCommand && isCall)
                {
                    SetVariables(innerCommand.GetVariables());
                    if (innerCommand.Next())
                    {
                        return(innerCommand.DoExecute());
                    }
                    else
                    {
                        InnerCallFalse();
                        return(executeCommand);
                    }
                }
                else if (isInnerCommand && !isCall)
                {
                    SetVariables(innerCommand.GetVariables());
                    if (innerCommand.Next())
                    {
                        return(innerCommand.DoExecute());
                    }
                    else
                    {
                        innerCommand   = null;
                        isInnerCommand = false;
                        return(executeCommand);
                    }
                }

                nowPosFlagName = offsetPos.ToString();
                int length = conditionEnvironmentList.Size();
                if (length > 0)
                {
                    object ifResult = conditionEnvironmentList.Get(length - 1);
                    if (ifResult != null)
                    {
                        backIfBool = (bool)(((Boolean)ifResult));
                    }
                }

                if (scriptList == null)
                {
                    ResetCache();
                    return(executeCommand);
                }
                else if (scriptList.Length - 1 < offsetPos)
                {
                    ResetCache();
                    return(executeCommand);
                }

                string cmd = scriptList[offsetPos];

                if (cmd.StartsWith(RESET_CACHE_TAG))
                {
                    ResetCache();
                    return(executeCommand);
                }

                if (isCache)
                {
                    cacheCommandName = NowCacheOffsetName(cmd);

                    object cache = CollectionUtils.Get(scriptContext, cacheCommandName);
                    if (cache != null)
                    {
                        return((string)cache);
                    }
                }

                if (flaging)
                {
                    flaging = !(cmd.StartsWith(FLAG_LS_E_TAG) || cmd
                                .EndsWith(FLAG_LS_E_TAG));
                    return(executeCommand);
                }

                if (!flaging)
                {
                    if (cmd.StartsWith(FLAG_LS_B_TAG) &&
                        !cmd.EndsWith(FLAG_LS_E_TAG))
                    {
                        flaging = true;
                        return(executeCommand);
                    }
                    else if (cmd.StartsWith(FLAG_LS_B_TAG) &&
                             cmd.EndsWith(FLAG_LS_E_TAG))
                    {
                        return(executeCommand);
                    }
                }

                SetupRandom(cmd);

                SetupSET(cmd);

                if (cmd.EndsWith(END_TAG))
                {
                    functioning = false;
                    return(executeCommand);
                }

                if (cmd.StartsWith(BEGIN_TAG))
                {
                    temps = CommandSplit(cmd);
                    if (temps.Count == 2)
                    {
                        functioning = true;
                        functions.Put(temps[1], new string[0]);
                        return(executeCommand);
                    }
                }

                if (functioning)
                {
                    int      size     = functions.Size() - 1;
                    string[] function = (string[])functions.Get(size);
                    int      index    = function.Length;
                    function        = (string[])CollectionUtils.Expand(function, 1);
                    function[index] = cmd;
                    functions.Set(size, function);
                    return(executeCommand);
                }

                if (((!esleflag && !ifing) || (esleflag && ifing)) &&
                    cmd.StartsWith(CALL_TAG) && !isCall)
                {
                    temps = CommandSplit(cmd);
                    if (temps.Count == 2)
                    {
                        string   functionName = (string)temps[1];
                        string[] funs         = (string[])functions.Get(functionName);
                        if (funs != null)
                        {
                            innerCommand = new Command(scriptName + FLAG
                                                       + functionName, funs);
                            innerCommand.CloseCache();
                            innerCommand.SetVariables(GetVariables());
                            InnerCallTrue();
                            return(null);
                        }
                    }
                }

                if (!if_bool && !elseif_bool)
                {
                    if_bool     = cmd.StartsWith(IF_TAG);
                    elseif_bool = cmd.StartsWith(ELSE_TAG);
                }

                if (if_bool)
                {
                    esleover = esleflag = SetupIF(cmd, nowPosFlagName,
                                                  setEnvironmentList, conditionEnvironmentList);
                    addCommand = false;
                    ifing      = true;
                }
                else if (elseif_bool)
                {
                    string[] value_ren = StringUtils.Split(cmd, " ");
                    if (!backIfBool && !esleflag)
                    {
                        if (value_ren.Length > 1 && IF_TAG.Equals(value_ren[1]))
                        {
                            esleover = esleflag = SetupIF(
                                cmd.Replace(ELSE_TAG, "").Trim(),
                                nowPosFlagName, setEnvironmentList,
                                conditionEnvironmentList);
                            addCommand = false;
                        }
                        else if (value_ren.Length == 1 && ELSE_TAG.Equals(value_ren[0]))
                        {
                            if (!esleover)
                            {
                                esleover = esleflag = SetupIF("if 1==1",
                                                              nowPosFlagName, setEnvironmentList,
                                                              conditionEnvironmentList);
                                addCommand = false;
                            }
                        }
                    }
                    else
                    {
                        esleflag   = false;
                        addCommand = false;
                        conditionEnvironmentList.Put(nowPosFlagName, (bool)(false));
                    }
                }

                if (cmd.StartsWith(IF_END_TAG))
                {
                    conditionEnvironmentList.Clear();
                    backIfBool  = false;
                    addCommand  = false;
                    ifing       = false;
                    if_bool     = false;
                    elseif_bool = false;
                    esleover    = false;
                    return(null);
                }
                if (backIfBool)
                {
                    if (cmd.StartsWith(INCLUDE_TAG))
                    {
                        if (IncludeCommand(cmd))
                        {
                            return(null);
                        }
                    }
                }
                else if (cmd.StartsWith(INCLUDE_TAG) && !ifing && !backIfBool &&
                         !esleflag)
                {
                    if (IncludeCommand(cmd))
                    {
                        return(null);
                    }
                }

                if (cmd.StartsWith(OUT_TAG))
                {
                    isRead         = false;
                    addCommand     = false;
                    executeCommand = (SELECTS_TAG + " " + readBuffer.ToString());
                }

                if (isRead)
                {
                    readBuffer.Append(cmd);
                    readBuffer.Append(FLAG);
                    addCommand = false;
                }

                if (cmd.StartsWith(IN_TAG))
                {
                    readBuffer.Remove(0, readBuffer.Length - (0));
                    isRead = true;
                    return(executeCommand);
                }

                if (addCommand && ifing)
                {
                    if (backIfBool && esleflag)
                    {
                        executeCommand = cmd;
                    }
                }
                else if (addCommand)
                {
                    executeCommand = cmd;
                }

                if (cmd.StartsWith(FLAG_SAVE_TAG))
                {
                    temps = CommandSplit(cmd);
                    if (temps != null && temps.Count == 2)
                    {
                        executeCommand = cmd;
                        SaveCommand(null, null);
                        return(executeCommand);
                    }
                }
                else if (cmd.StartsWith(FLAG_LOAD_TAG))
                {
                    temps = CommandSplit(cmd);
                    if (temps != null && temps.Count == 2)
                    {
                        executeCommand = cmd;
                        LoadCommand(null, -1);
                        return(executeCommand);
                    }
                }

                if (executeCommand != null)
                {
                    printTags = Command.GetNameTags(executeCommand, PRINT_TAG
                                                    + BRACKET_LEFT_TAG, BRACKET_RIGHT_TAG);
                    if (printTags != null)
                    {
                        for (IEnumerator it = printTags.GetEnumerator(); it.MoveNext();)
                        {
                            string key       = (string)it.Current;
                            object value_ren = CollectionUtils.Get(setEnvironmentList, key);
                            if (value_ren != null)
                            {
                                executeCommand = StringUtils
                                                 .ReplaceMatch(
                                    executeCommand,
                                    (PRINT_TAG + BRACKET_LEFT_TAG + key + BRACKET_RIGHT_TAG)
                                    , value_ren.ToString());
                            }
                            else
                            {
                                executeCommand = StringUtils
                                                 .ReplaceMatch(
                                    executeCommand,
                                    (PRINT_TAG + BRACKET_LEFT_TAG + key + BRACKET_RIGHT_TAG)
                                    , key);
                            }
                        }
                    }

                    if (isCache)
                    {
                        CollectionUtils.Put(scriptContext, cacheCommandName, executeCommand);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
            finally
            {
                if (!isInnerCommand)
                {
                    offsetPos++;
                }
            }

            return(executeCommand);
        }
Exemple #6
0
 private LImage PackImage()
 {
     CheckPacked();
     if (packing)
     {
         if (temps.IsEmpty())
         {
             throw new InvalidOperationException("Nothing to Pack !");
         }
         int maxWidth  = 0;
         int maxHeight = 0;
         int totalArea = 0;
         for (int i = 0; i < temps.Size(); i++)
         {
             PackEntry entry  = (PackEntry)temps.Get(i);
             int       width  = entry.image.GetWidth();
             int       height = entry.image.GetHeight();
             if (width > maxWidth)
             {
                 maxWidth = width;
             }
             if (height > maxHeight)
             {
                 maxHeight = height;
             }
             totalArea += width * height;
         }
         Loon.Core.Geom.Point.Point2i size = new Loon.Core.Geom.Point.Point2i(CloseTwoPower(maxWidth),
                                                                              CloseTwoPower(maxHeight));
         bool fitAll = false;
         loop : {
             while (!fitAll)
             {
                 int area = size.x * size.y;
                 if (area < totalArea)
                 {
                     NextSize(size);
                     continue;
                 }
                 Node root = new Node(size.x, size.y);
                 for (int i = 0; i < temps.Size(); i++)
                 {
                     PackEntry entry    = (PackEntry)temps.Get(i);
                     Node      inserted = root.Insert(entry);
                     if (inserted == null)
                     {
                         NextSize(size);
                         goto loop;
                     }
                 }
                 fitAll = true;
             }
         }
         int srcWidth  = size.x;
         int srcHeight = size.y;
         //由于LGraphics操作较耗时,此处直接处理像素(其实也快不了几毫秒,未来将改写为C#混合C/C++)
         LImage image     = LImage.CreateImage(srcWidth, srcHeight, useAlpha);
         int[]  dstPixels = image.GetIntPixels();
         int[]  srcPixels = null;
         for (int i = 0; i < temps.Size(); i++)
         {
             PackEntry entry = (PackEntry)temps.Get(i);
             LImage    img   = entry.image;
             srcPixels = img.GetIntPixels();
             int w = img.Width;
             int h = img.Height;
             int x = entry.bounds.left;
             int y = entry.bounds.top;
             if (x < 0)
             {
                 w += x;
                 x  = 0;
             }
             if (y < 0)
             {
                 h += y;
                 y  = 0;
             }
             if (x + w > srcWidth)
             {
                 w = srcWidth - x;
             }
             if (y + h > srcHeight)
             {
                 h = srcHeight - y;
             }
             if (img.hasAlpha)
             {
                 int findIndex = y * srcWidth + x;
                 int drawIndex = 0;
                 int moveFind  = srcWidth - w;
                 for (int col = 0; col < h; col++)
                 {
                     for (int row = 0; row < w;)
                     {
                         if (srcPixels[drawIndex] != 0)
                         {
                             dstPixels[findIndex] = srcPixels[drawIndex];
                         }
                         row++;
                         findIndex++;
                         drawIndex++;
                     }
                     findIndex += moveFind;
                 }
             }
             else
             {
                 for (int count = 0; count < h; count++)
                 {
                     System.Array.Copy(srcPixels, count * w, dstPixels,
                                       (y + count) * srcWidth + x, w);
                 }
             }
         }
         image.SetIntPixels(dstPixels);
         srcPixels = null;
         dstPixels = null;
         packing   = false;
         return(image);
     }
     return(null);
 }
Exemple #7
0
 public NSObject ObjectForKey(NSObject key)
 {
     return((NSObject)_dict.Get(key));
 }
Exemple #8
0
 private LPixmap PackImage()
 {
     CheckPacked();
     if (packing)
     {
         if (temps.IsEmpty())
         {
             throw new Exception("Nothing to Pack !");
         }
         int maxWidth  = 0;
         int maxHeight = 0;
         int totalArea = 0;
         for (int i = 0; i < temps.Size(); i++)
         {
             PackEntry entry  = (PackEntry)temps.Get(i);
             int       width  = entry.image.GetWidth();
             int       height = entry.image.GetHeight();
             if (width > maxWidth)
             {
                 maxWidth = width;
             }
             if (height > maxHeight)
             {
                 maxHeight = height;
             }
             totalArea += width * height;
         }
         Loon.Core.Geom.Point.Point2i size = new Loon.Core.Geom.Point.Point2i(CloseTwoPower(maxWidth),
                                                                              CloseTwoPower(maxHeight));
         bool fitAll = false;
         while (!fitAll)
         {
             int area = size.x * size.y;
             if (area < totalArea)
             {
                 NextSize(size);
                 continue;
             }
             Node root = new Node(size.x, size.y);
             for (int i = 0; i < temps.Size(); i++)
             {
                 PackEntry entry    = (PackEntry)temps.Get(i);
                 Node      inserted = root.Insert(entry);
                 if (inserted == null)
                 {
                     NextSize(size);
                     continue;
                 }
             }
             fitAll = true;
         }
         LPixmap image = new LPixmap(size.x, size.y, useAlpha);
         for (int i = 0; i < temps.Size(); i++)
         {
             PackEntry entry = (PackEntry)temps.Get(i);
             image.DrawPixmap(entry.image, entry.bounds.left, entry.bounds.top);
         }
         packing = false;
         return(image);
     }
     return(null);
 }
Exemple #9
0
        private void DrawBatchString(float tx, float ty, string text, LColor c,
                                     int startIndex, int endIndex)
        {
            if (isClose)
            {
                return;
            }

            if (displays.Size() > DEFAULT_MAX_CHAR)
            {
                displays.Clear();
            }

            lazyHashCode = 1;

            if (c != null)
            {
                lazyHashCode = LSystem.Unite(lazyHashCode, c.r);
                lazyHashCode = LSystem.Unite(lazyHashCode, c.g);
                lazyHashCode = LSystem.Unite(lazyHashCode, c.b);
                lazyHashCode = LSystem.Unite(lazyHashCode, c.a);
            }

            string key = text + lazyHashCode;

            Display display = (Display)displays.Get(key);

            if (display == null)
            {
                int x = 0, y = 0;

                displayList.GLBegin();
                displayList.SetBatchPos(tx, ty);

                if (c != null)
                {
                    displayList.SetImageColor(c);
                }

                CharDef lastCharDef = null;
                char[]  data        = text.ToCharArray();
                for (int i = 0; i < data.Length; i++)
                {
                    int id = data[i];
                    if (id == '\n')
                    {
                        x  = 0;
                        y += GetLineHeight();
                        continue;
                    }
                    if (id >= chars.Length)
                    {
                        continue;
                    }
                    CharDef charDef = chars[id];
                    if (charDef == null)
                    {
                        continue;
                    }

                    if (lastCharDef != null)
                    {
                        x += lastCharDef.GetKerning(id);
                    }
                    lastCharDef = charDef;

                    if ((i >= startIndex) && (i <= endIndex))
                    {
                        charDef.Draw(x, y);
                    }

                    x += charDef.advance;
                }

                if (c != null)
                {
                    displayList.SetImageColor(LColor.white);
                }

                displayList.GLEnd();

                display = new Display();

                display.cache  = displayList.NewBatchCache();
                display.text   = text;
                display.width  = 0;
                display.height = 0;

                displays.Put(key, display);
            }
            else if (display.cache != null)
            {
                display.cache.x = tx;
                display.cache.y = ty;
                LTextureBatch.Commit(displayList, display.cache);
            }
        }
Exemple #10
0
        public virtual void PaintObjects(GLEx g, int minX, int minY, int maxX, int maxY)
        {
            lock (objects)
            {
                IIterator it = objects.Iterator();
                for (; it.HasNext();)
                {
                    thing = (Actor)it.Next();
                    if (!thing.visible)
                    {
                        continue;
                    }
                    isListener = (thing.actorListener != null);

                    if (isVSync)
                    {
                        if (isListener)
                        {
                            thing.actorListener.Update(elapsedTime);
                        }
                        thing.Update(elapsedTime);
                    }

                    RectBox rect = thing.GetRectBox();
                    actorX      = minX + thing.GetX();
                    actorY      = minY + thing.GetY();
                    actorWidth  = rect.width;
                    actorHeight = rect.height;
                    if (actorX + actorWidth < minX || actorX > maxX ||
                        actorY + actorHeight < minY || actorY > maxY)
                    {
                        continue;
                    }
                    LTexture actorImage = thing.GetImage();
                    if (actorImage != null)
                    {
                        width          = (actorImage.GetWidth() * thing.scaleX);
                        height         = (actorImage.GetHeight() * thing.scaleY);
                        isBitmapFilter = (thing.filterColor != null);
                        thing.SetLastPaintSeqNum(paintSeq++);
                        angle      = thing.GetRotation();
                        colorAlpha = thing.alpha;

                        if (thing.isAnimation)
                        {
                            if (isBitmapFilter)
                            {
                                g.DrawTexture(actorImage, actorX, actorY, width,
                                              height, angle, thing.filterColor);
                            }
                            else
                            {
                                if (colorAlpha != 1f)
                                {
                                    g.SetAlpha(colorAlpha);
                                }
                                g.DrawTexture(actorImage, actorX, actorY, width,
                                              height, angle);
                                if (colorAlpha != 1f)
                                {
                                    g.SetAlpha(1f);
                                }
                            }
                        }
                        else
                        {
                            int texId = actorImage.GetTextureID();

                            LTextureBatch batch = (LTextureBatch)textures
                                                  .GetValue(texId);

                            if (batch == null)
                            {
                                LTextureBatch pBatch = LTextureBatch
                                                       .BindBatchCache(this, texId,
                                                                       actorImage);
                                batch = pBatch;
                                batch.GLBegin();

                                textures.Put(texId, batch);
                            }

                            batch.SetTexture(actorImage);

                            if (isBitmapFilter)
                            {
                                batch.Draw(actorX, actorY, width, height, angle,
                                           thing.filterColor);
                            }
                            else
                            {
                                if (colorAlpha != 1f)
                                {
                                    alphaColor.a = colorAlpha;
                                }
                                batch.Draw(actorX, actorY, width, height, angle,
                                           alphaColor);
                                if (colorAlpha != 1f)
                                {
                                    alphaColor.a = 1;
                                }
                            }
                        }
                    }
                    if (thing.isConsumerDrawing)
                    {
                        if (actorX == 0 && actorY == 0)
                        {
                            thing.Draw(g);
                            if (isListener)
                            {
                                thing.actorListener.Draw(g);
                            }
                        }
                        else
                        {
                            g.Translate(actorX, actorY);
                            thing.Draw(g);
                            if (isListener)
                            {
                                thing.actorListener.Draw(g);
                            }
                            g.Translate(-actorX, -actorY);
                        }
                    }
                }

                int size = textures.Size();
                if (size > 0)
                {
                    for (int i = 0; i < size; i++)
                    {
                        LTextureBatch batch = (LTextureBatch)textures.Get(i);
                        batch.GLEnd();
                    }
                    textures.Clear();
                }
            }
        }
Exemple #11
0
 public object Get(string key)
 {
     return(_map.Get(key));
 }