Advertisement
Guest User

GoblinListPlugin

a guest
Dec 25th, 2017
1,794
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 30.72 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Globalization;
  5. using SharpDX;
  6. using SharpDX.Direct2D1;
  7.  
  8. using Turbo.Plugins.Default;
  9. using Turbo.Plugins.Jack.Decorators.TopTables;  //table
  10.  
  11.  
  12. namespace Turbo.Plugins.gjuz
  13. {
  14.     public class GoblinListPlugin : BasePlugin, IInGameTopPainter, IAfterCollectHandler , INewAreaHandler
  15.     {
  16.         /**
  17.         plan:
  18.         toDo
  19.             sorting -> table
  20.             golbin party handling -> rifts
  21.             bandit shrine handling
  22.            
  23.        
  24.         export data??
  25.         **/
  26.        
  27.         private HashSet<uint> GelatinousSpawns = new HashSet<uint>()
  28.         {
  29.             // 408354,      //Gelatinous Sire       groß
  30.             429796,         //Gelatinous Spawn      mittel
  31.             429797          //Gelatinous Spawn      klein
  32.         };
  33.        
  34.         /* international */
  35.         public Dictionary<uint, string> Goblins { get; set; }   //international names set here
  36.         public List<uint> ElementOrder { get; set; }            //order in table set here
  37.        
  38.         public string MainBanner1 { get; set; }                 //international strings
  39.         public string MainBanner2 { get; set; }                 //international strings
  40.         public string MainBanner3 { get; set; }                 //international strings
  41.         public string GoblinCount0 { get; set; }                //international strings
  42.         public string GoblinCount1 { get; set; }                //international strings
  43.         public string SubBanner { get; set; }                   //international strings
  44.         /* international */
  45.        
  46.        
  47.        
  48.         /** init **/
  49.         private bool _init;
  50.         /** show **/
  51.         private bool _show;
  52.        
  53.         /** data **/
  54.         /** act, Golbin, Map, count **/
  55.         private Dictionary<int, Dictionary<uint, Dictionary<string, int>>> GoblinMapper;
  56.         /* act 0-5 */   /* goblin snos */   /* map name */  /* count */
  57.         private HashSet<uint> _lastGob;
  58.         // private HashSet<uint> _lastGobRift;
  59.         private int _gobCnt;
  60.        
  61.         /** tabelle **/
  62.         public TopTable Table { get; private set; }
  63.         private List<string> _lineHeads;
  64.         private int _cols;
  65.         private int _rows;
  66.        
  67.         /** table highlight **/
  68.         private int mouseLine;
  69.         private int mouseCol;
  70.         private RectangleF TableRect;
  71.        
  72.         /** Draw **/
  73.         private int _drawPageAct;
  74.         private int _drawSubpage;
  75.         private int _ActSubPages;
  76.         public int MaxRows { get; set; }
  77.        
  78.         /** Wii Menu **/
  79.         private IWatch _openDialogWatch;    // for opening closing ListDialog
  80.         private IWatch _closeDialogWatch;   // for opening closing ListDialog
  81.         private IWatch _routingWatch;       // for switching pages in ListDialog
  82.         public long openingTimeMS { get; set; }
  83.         public long closingTimeMS { get; set; }
  84.         public long routingTimeMS { get; set; }
  85.         private float _routingButtonSize;
  86.         private float _routingButtonSizeSmall;
  87.         /** Wii Menu Buttons - for drawing and menu function **/
  88.         private RectangleF openDlgRect;
  89.         private RectangleF openDlgImgRect;
  90.         private RectangleF rectPrevAct;
  91.         private RectangleF nextPrevAct;
  92.         private RectangleF rectPrevSubPage;
  93.         private RectangleF nextPrevSubPage;
  94.         /** Buttons **/
  95.         private string _OpenButtonText;
  96.         public TopLabelDecorator RoutingButton { get; set; }
  97.         private string _RoutingButtonText;
  98.         public IFont TimeLeftFont { get; set; }
  99.         public IBrush TimeLeftClockBrush { get; set; }
  100.        
  101.        
  102.         /** Texture Ids **/
  103.         private List<uint> actId = new List<uint>() {
  104.             1805812053,
  105.             1805812053,
  106.             1806997974,
  107.             1808183895,
  108.             1809369816,
  109.             1810555737
  110.         };
  111.         private List<uint> ringId = new List<uint>() {
  112.             2734730716,
  113.             2734730717,
  114.             2734730718,
  115.             2734730742,
  116.             2734730743,
  117.             2734730744
  118.         };
  119.         private uint act0Id = 3572241856;
  120.         private uint bannerscrollId = 1640038511;
  121.         private uint buttontexId = 2326263137;
  122.         private uint dlgBGId = 679903159;
  123.         private uint dlgImgId = 2605755780;
  124.         private uint dlgCloseId = 1429036410;
  125.         private uint dlgActiveId = 672253601;
  126.         private uint wimpelId = 995379405;
  127.         private uint smallBannerId = 1611575647;
  128.         /** Textures **/
  129.         private List<ITexture> actTexture;
  130.         private List<ITexture> ringTexture;
  131.         private ITexture act0Texture;
  132.         private ITexture bannerscrollTexture;
  133.         private ITexture buttonTexture;
  134.         private ITexture dlgBGTexture;
  135.         private ITexture dlgImgTexture;
  136.         private ITexture dlgCloseTexture;
  137.         private ITexture dlgActiveTexture;
  138.         private ITexture wimpelTexture;
  139.         private ITexture smallBannerTexture;
  140.         /** fronts **/
  141.         public IFont BannerFont { get; set; }
  142.         public IFont SmallBannerFont { get; set; }
  143.         public IFont GoblinCountFont { get; set; }
  144.         public IFont SubpageCountFont { get; set; }
  145.        
  146.        
  147.        
  148.         public GoblinListPlugin()
  149.         {
  150.             Enabled = true;
  151.         }
  152.        
  153.         public override void Load(IController hud)
  154.         {
  155.             base.Load(hud);
  156.            
  157.             /** strings **/
  158.             MainBanner1 = "List of all Goblins found ";
  159.             MainBanner2 = "somwhere else";
  160.             MainBanner3 = "in Act ";
  161.             GoblinCount0 = "No Goblins here";
  162.             GoblinCount1 = " Goblins";
  163.             SubBanner = "Subpage";
  164.            
  165.             /** short names of goblins **/
  166.             Goblins = new Dictionary<uint, string> ()   //short strings
  167.             {
  168.                 {429785, "Malevolent"},             //"Malevolent Tormentor"
  169.                 {429787, "Blood"},                  //"Blood Thief"
  170.                 {429794, "Collector"},              //"Odious Collector"
  171.                 {429793, "Gems"},                   //"Gem Hoarder"
  172.                 {429792, "Gelatinous"},             //"Gelatinous Sire"
  173.                 {429803, "Gold"},                   //"Gilded Baron"
  174.                 {429789, "Insufferable"},           //"Insufferable Miscreant"
  175.                 {451059, "Menagerist"},             //"Menagerist Goblin"
  176.                 {429795, "Treasure"},               //"Treasure Goblin"
  177.                 {405624, "Rainbow"},                //"Rainbow Goblin"
  178.             };
  179.            
  180.             /** order of table **/
  181.             ElementOrder = new List<uint>()
  182.             {
  183.                 405624,     //Rainbow Goblin
  184.                 429792,     //Gelatinous Sire
  185.                 429785,     //Malevolent Tormentor
  186.                 429789,     //Insufferable Miscreant
  187.                 429787,     //Blood Thief
  188.                 429794,     //Odious Collector
  189.                 429793,     //Gem Hoarder
  190.                 429803,     //Gilded Baron
  191.                 429795,     //Treasure Goblin
  192.                 451059,     //Menagerist Goblin
  193.             };
  194.            
  195.             _lastGob = new HashSet<uint>();
  196.            
  197.            
  198.             /** Textures **/
  199.             actTexture = new List<ITexture>();
  200.             foreach (uint id in actId)
  201.                 actTexture.Add(Hud.Texture.GetTexture(id));
  202.             ringTexture = new List<ITexture>();
  203.             foreach (uint id in ringId)
  204.                 ringTexture.Add(Hud.Texture.GetTexture(id));
  205.             act0Texture = Hud.Texture.GetTexture(act0Id);
  206.             bannerscrollTexture = Hud.Texture.GetTexture(bannerscrollId);
  207.             buttonTexture = Hud.Texture.GetTexture(buttontexId);
  208.             dlgBGTexture = Hud.Texture.GetTexture(dlgBGId);
  209.             dlgImgTexture = Hud.Texture.GetTexture(dlgImgId);
  210.             dlgCloseTexture = Hud.Texture.GetTexture(dlgCloseId);
  211.             dlgActiveTexture = Hud.Texture.GetTexture(dlgActiveId);
  212.             wimpelTexture = Hud.Texture.GetTexture(wimpelId);
  213.             smallBannerTexture = Hud.Texture.GetTexture(smallBannerId);
  214.            
  215.            
  216.             /** fronts **/
  217.             BannerFont = Hud.Render.CreateFont("tahoma", 10f, 255, 0, 0, 0, false, false, true);
  218.             SmallBannerFont = Hud.Render.CreateFont("tahoma", 7f, 255, 0, 0, 0, false, false, true);
  219.             GoblinCountFont = Hud.Render.CreateFont("tahoma", 10f, 255, 255, 255, 255, false, false, true);
  220.             SubpageCountFont = Hud.Render.CreateFont("tahoma", 7f, 255, 255, 255, 255, false, false, true);
  221.            
  222.            
  223.            
  224.             /** Draw **/
  225.             _drawPageAct = 1;
  226.             _drawSubpage = 0;
  227.             _ActSubPages = 0;
  228.             MaxRows = 25;
  229.            
  230.             /** Wii Menu **/
  231.             _openDialogWatch = Hud.Time.CreateWatch();
  232.             _closeDialogWatch = Hud.Time.CreateWatch();
  233.             _routingWatch = Hud.Time.CreateWatch();
  234.             openingTimeMS = 3000;
  235.             closingTimeMS = 1000;
  236.             routingTimeMS = 1500;
  237.             _routingButtonSizeSmall = 35f;
  238.             _routingButtonSize = 50f;
  239.             /** Wii Menu Buttons - for drawing and menu function **/
  240.             TimeLeftFont = Hud.Render.CreateFont("tahoma", 7, 255, 255, 255, 255, false, false, 255, 0, 0, 0, true);
  241.             TimeLeftClockBrush = Hud.Render.CreateBrush(220, 0, 0, 0, 0);
  242.             /** RoutingButton **/
  243.             RoutingButton = new TopLabelDecorator(Hud)
  244.             {
  245.                 TextFont = Hud.Render.CreateFont("tahoma", 8, 200, 255, 255, 255, true, false, false),
  246.                 // Option #2: Use textures for background
  247.                 BackgroundTexture1 = Hud.Texture.ButtonTextureGray,
  248.                 BackgroundTexture2 = Hud.Texture.BackgroundTextureBlue,
  249.                 BackgroundTextureOpacity2 = 0.25f,
  250.                 HintFunc = () => "",
  251.                 TextFunc = () => _RoutingButtonText
  252.             };
  253.            
  254.         }
  255.        
  256.         /** sorting **/
  257.        
  258.        
  259.         /** Table **/
  260.         private void InitTable()
  261.         {
  262.             /** for reinit **/
  263.             if (Table != null)
  264.                 Table.Dispose();
  265.            
  266.            
  267.             /* DifficultiesInfoPlugin */
  268.             _lineHeads = GoblinMapper[_drawPageAct][ElementOrder.First()].Keys.ToList();
  269.             _cols = ElementOrder.Count();
  270.             _rows = _lineHeads.Count();
  271.            
  272.             /* Table */
  273.             Table = new TopTable(Hud)
  274.             {
  275.                 RatioPositionX = 0.5f,  //um Hud.Window.Size.Width->50% zentriert -> HorizontalCenter
  276.                 RatioPositionY = 0.3f,  //ab Hud.Window.Size.Height->20% -> !VerticalCenter
  277.                 HorizontalCenter = true,
  278.                 VerticalCenter = false,
  279.                 PositionFromRight = false,
  280.                 PositionFromBottom = false,
  281.                 ShowHeaderLeft = true,
  282.                 ShowHeaderTop = true,
  283.                 ShowHeaderRight = false,
  284.                 ShowHeaderBottom = false,
  285.                 DefaultCellDecorator = new TopTableCellDecorator(Hud)
  286.                 {
  287.                     BackgroundBrush = Hud.Render.CreateBrush(255, 0, 0, 0, 0),
  288.                     BorderBrush = Hud.Render.CreateBrush(255, 255, 255, 255, -1),
  289.                     TextFont = Hud.Render.CreateFont("tahoma", 8, 255, 255, 255, 255, false, false, true),
  290.                 },
  291.                 DefaultHighlightDecorator = new TopTableCellDecorator(Hud)
  292.                 {
  293.                     BackgroundBrush = Hud.Render.CreateBrush(255, 0, 0, 242, 0),
  294.                     BorderBrush = Hud.Render.CreateBrush(255, 255, 255, 255, -1),
  295.                     TextFont = Hud.Render.CreateFont("tahoma", 8, 255, 255, 255, 255, false, false, true),
  296.                 },
  297.                 DefaultHeaderDecorator = new TopTableCellDecorator(Hud)
  298.                 {
  299.                     TextFont = Hud.Render.CreateFont("tahoma", 8, 255, 255, 255, 255, false, false, true),
  300.                 }
  301.             };
  302.            
  303.            
  304.            
  305.             /* Columns - Header */
  306.             TopTableHeader[] _colHeads = new TopTableHeader[_cols];
  307.            
  308.             _colHeads[0] = new TopTableHeader(Hud, (pos, curPos) => GetColumnHeaderText(pos))
  309.             {
  310.                 RatioHeight = 22 / 1080f, // define only once on first column, value on others will be ignored
  311.                 RatioWidth = 0.075f,
  312.                 // HighlightFunc = (pos, curPos) => HighlightColumn(pos),
  313.                 HighlightFunc = (pos, curPos) => mouseCol == pos,
  314.                 TextAlign = HorizontalAlign.Center,
  315.             };
  316.            
  317.             for (int i = 1; i < _cols; i++)
  318.             {
  319.                 _colHeads[i] = new TopTableHeader(Hud, (pos, curPos) => GetColumnHeaderText(pos))
  320.                 {
  321.                     RatioWidth = 0.075f,
  322.                     // HighlightFunc = (pos, curPos) => HighlightColumn(pos),
  323.                     HighlightFunc = (pos, curPos) => mouseCol == pos,
  324.                     TextAlign = HorizontalAlign.Center,
  325.                 };
  326.             }
  327.            
  328.             Table.DefineColumns(_colHeads);
  329.            
  330.            
  331.            
  332.             /* Rows */
  333.             TopTableCell[] _cells;  //define in for-loop, to get correct line numbers
  334.            
  335.             for (var i = _drawSubpage * MaxRows; i < _rows && i < (_drawSubpage +1) * MaxRows; i++)
  336.             {
  337.                 _cells = new TopTableCell[_cols];
  338.                 for (int j = 0; j < _cols; j++)
  339.                 {
  340.                     _cells[j] = new TopTableCell(Hud, (line, column, lineSorted, columnSorted) => GetCellText(line, column)) { TextAlign = HorizontalAlign.Center };
  341.                 }
  342.                
  343.                 Table.AddLine(
  344.                     new TopTableHeader(Hud, (pos, curPos) => GetLineHeaderText(pos))
  345.                     {
  346.                         RatioWidth = 0 / 1080f, // define only once on first line, value on other will be ignored
  347.                         // RatioWidth = 62 / 1080f, // define only once on first line, value on other will be ignored
  348.                         RatioHeight = 22 / 1080f,
  349.                         // HighlightFunc = (pos, curPos) => false,
  350.                         HighlightFunc = (pos, curPos) => mouseLine == pos,
  351.                         TextAlign = HorizontalAlign.Right,
  352.                         HighlightDecorator = new TopTableCellDecorator(Hud)
  353.                         {
  354.                             // BackgroundBrush = Hud.Render.CreateBrush(255, 0, 0, 0, 0),
  355.                             BackgroundBrush = Hud.Render.CreateBrush(255, 0, 0, 242, 0),
  356.                             BorderBrush = Hud.Render.CreateBrush(255, 255, 255, 255, -1),
  357.                             TextFont = Hud.Render.CreateFont("tahoma", 8, 255, 255, 255, 255, true, false, true),
  358.                         },
  359.                         CellHighlightDecorator = new TopTableCellDecorator(Hud)
  360.                         {
  361.                             // BackgroundBrush = Hud.Render.CreateBrush(255, 0, 0, 0, 0),
  362.                             BackgroundBrush = Hud.Render.CreateBrush(255, 0, 0, 242, 0),
  363.                             BorderBrush = Hud.Render.CreateBrush(255, 255, 255, 255, -1),
  364.                             TextFont = Hud.Render.CreateFont("tahoma", 8, 255, 255, 255, 255, true, false, true),
  365.                         },
  366.                     },
  367.                     _cells
  368.                 );
  369.             }
  370.            
  371.             _gobCnt = CountGoblin(_drawPageAct);
  372.             /** table highlight **/
  373.             TableRect = TableRectangle();
  374.             mouseLine = -1;
  375.         }
  376.        
  377.         /** mehrere pages für einen act ?? **/
  378.         private string GetColumnHeaderText(int pos)
  379.         {
  380.             return Goblins[ElementOrder[pos]];
  381.         }
  382.        
  383.         private string GetLineHeaderText(int pos)
  384.         {
  385.             /** _drawSubpage, MaxRows **/
  386.             return _lineHeads[_drawSubpage * MaxRows + pos];
  387.         }
  388.        
  389.         private string GetCellText(int line, int column)
  390.         {
  391.             /* act 0-5 */   /* goblin snos */   /* map name */  /* count */
  392.             // private Dictionary<int, Dictionary<uint, Dictionary<string, int>>> GoblinMapper;
  393.             return GoblinMapper[_drawPageAct][ElementOrder[column]][GetLineHeaderText(line)].ToString();
  394.         }
  395.        
  396.         private int CountGoblin(int act)
  397.         {
  398.             int _cnt = 0;
  399.            
  400.             foreach (var gob in ElementOrder)
  401.             {
  402.                 foreach (var map in _lineHeads)
  403.                 {
  404.                     _cnt += GoblinMapper[act][gob][map];
  405.                 }
  406.             }
  407.            
  408.             return _cnt;
  409.         }
  410.        
  411.         /** table highlight **/
  412.         private RectangleF TableRectangle()
  413.         {
  414.             float tablewidth = Table.Columns.Select(c => c.Width).Sum() + (Table.Columns.Count * Table.SpacingAdjustmentInPixels) - Table.SpacingAdjustmentInPixels;
  415.             float tableheight = Table.Lines.Select(c => c.Height).Sum() + (Table.Lines.Count * Table.SpacingAdjustmentInPixels) - Table.SpacingAdjustmentInPixels;
  416.            
  417.             float tableleft = Table.RatioPositionX * Hud.Window.Size.Width - tablewidth / 2;
  418.             float tabletop = Table.RatioPositionY * Hud.Window.Size.Height + Table.Columns.First().Height + Table.SpacingAdjustmentInPixels;
  419.            
  420.             return new RectangleF(tableleft, tabletop, tablewidth, tableheight);
  421.         }
  422.        
  423. /** bis hier tabelle **/   
  424.        
  425.        
  426.        
  427.         public void OnNewArea(bool newGame, ISnoArea area)
  428.         {
  429.             if (newGame)
  430.             {
  431.                 _lastGob.Clear();
  432.                 _show = false;
  433.             }
  434.         }
  435.        
  436.         //logic
  437.         public void AfterCollect()
  438.         {
  439.             /** für rifts _lastGobRift -> riftclose -> clear() **/
  440.            
  441.             if (Hud.Game.Me.SnoArea == null || Hud.Game.Me.SnoArea.Code == null || Hud.Game.Me.SnoArea.Code.Contains("x1_lr_level") )   //OHNE rifts...
  442.                 return;
  443.                
  444.             var goblins = Hud.Game.AliveMonsters.Where(x => x.SnoMonster.Priority == MonsterPriority.goblin && !(GelatinousSpawns.Contains(x.SnoMonster.Sno)) );
  445.            
  446.             /** count goblins **/
  447.             /** problem mehrere goblins onscreen - party oder bandit shrine **/
  448.             foreach (var goblin in goblins)
  449.             {
  450.                 if (!goblin.IsOnScreen) continue;
  451.                 if (_lastGob.Contains(goblin.AcdId)) continue;
  452.                
  453.                 //to be safe: is gobSNO in there
  454.                 //-> soll ich mich um den gob kümmern?
  455.                 if (ElementOrder.Contains(goblin.SnoMonster.Sno))
  456.                 {
  457.                     //counting
  458.                     //private Dictionary<int, Dictionary<uint, Dictionary<string, int>>> GoblinMapper;
  459.                     /* act 0-5 */   /* goblin snos */   /* map name */  /* count */
  460.                    
  461.                     if (!GoblinMapper[Hud.Game.Me.SnoArea.Act][goblin.SnoMonster.Sno].ContainsKey(Hud.Game.Me.SnoArea.NameLocalized))
  462.                     {
  463.                         foreach (var gobSno in ElementOrder)
  464.                             GoblinMapper[Hud.Game.Me.SnoArea.Act][gobSno].Add(Hud.Game.Me.SnoArea.NameLocalized,0);
  465.                     }
  466.                    
  467.                     GoblinMapper[Hud.Game.Me.SnoArea.Act][goblin.SnoMonster.Sno][Hud.Game.Me.SnoArea.NameLocalized]++;
  468.                 }
  469.                
  470.                 _lastGob.Add(goblin.AcdId);
  471.             }
  472.         }
  473.        
  474.         private void init()
  475.         {
  476.             //only set once not every cycle
  477.             /** Wii Menu Buttons - for drawing and menu function **/
  478.             System.Drawing.RectangleF uiRect = Hud.Render.GetUiElement("Root.NormalLayer.game_dialog_backgroundScreenPC.game_window_hud_overlay").Rectangle;
  479.             float openDlgX = uiRect.Right;
  480.             float openDlgY = uiRect.Top + uiRect.Height * 0.39f;
  481.             openDlgRect = new RectangleF(openDlgX, openDlgY, dlgBGTexture.Width, dlgBGTexture.Height);
  482.             openDlgX += (dlgBGTexture.Width - dlgImgTexture.Width)/2;
  483.             openDlgY += (dlgBGTexture.Height - dlgImgTexture.Height)/2;
  484.             openDlgImgRect = new RectangleF(openDlgX, openDlgY, dlgImgTexture.Width, dlgImgTexture.Height);
  485.            
  486.             /** Wii Menu Buttons - for drawing and menu function **/
  487.             rectPrevAct = new RectangleF(Hud.Window.Size.Width * 0.5f - _routingButtonSize * 3.5f, Hud.Window.Size.Height * 0.13f, _routingButtonSize, _routingButtonSize);
  488.             nextPrevAct = new RectangleF(Hud.Window.Size.Width * 0.5f + _routingButtonSize * 2.5f, Hud.Window.Size.Height * 0.13f, _routingButtonSize, _routingButtonSize);
  489.             rectPrevSubPage = new RectangleF(Hud.Window.Size.Width * 0.29f - _routingButtonSizeSmall * 2, Hud.Window.Size.Height * 0.22f, _routingButtonSizeSmall, _routingButtonSizeSmall);
  490.             nextPrevSubPage = new RectangleF(Hud.Window.Size.Width * 0.29f + _routingButtonSizeSmall, Hud.Window.Size.Height * 0.22f, _routingButtonSizeSmall, _routingButtonSizeSmall);
  491.            
  492.             /** init GoblinMapper **/
  493.             GoblinMapper = new Dictionary<int, Dictionary<uint, Dictionary<string, int>>>();
  494.             for (int i = 0; i <= 5; i++)
  495.             {
  496.                 GoblinMapper.Add(i, new Dictionary<uint, Dictionary<string, int>>());
  497.                 foreach (var gob in ElementOrder)
  498.                 {
  499.                     GoblinMapper[i].Add(gob, new Dictionary<string, int>());
  500.                 }
  501.             }
  502.            
  503.             _show = false;
  504.             _init = true;
  505.         }
  506.        
  507.         public void PaintTopInGame(ClipState clipState)
  508.         {
  509.             if (!_init)
  510.                 init();
  511.            
  512.             /** ElementOrder empty - nothing to do... **/
  513.             if (!ElementOrder.Any()) return;
  514.             if (!Hud.Game.IsInTown && _show) _show = false;
  515.             if (!Hud.Game.IsInTown) return;     //only in Town
  516.             if (clipState != ClipState.AfterClip) return;
  517.            
  518.             OpenDialog();
  519.             ShowDialog();
  520.         }
  521.        
  522.         private void OpenDialog()
  523.         {
  524.             //draw buttons
  525.             if (!_show)
  526.             {
  527.                 drawOpenDlg(_openDialogWatch.IsRunning, openDlgRect.Left, openDlgRect.Top);
  528.             }
  529.            
  530.             if (_show)
  531.             {
  532.                 drawOpenDlg(_closeDialogWatch.IsRunning, openDlgRect.Left, openDlgRect.Top);
  533.             }
  534.            
  535.            
  536.             //no open/close
  537.             if (!CursorInsideRect(openDlgRect))
  538.             {
  539.                 _openDialogWatch.Reset();
  540.                 _closeDialogWatch.Reset();
  541.             }
  542.            
  543.             /** draw routing - clock & numbers **/
  544.             if (_openDialogWatch.IsRunning)
  545.             {
  546.                 var _TimeLeft = openingTimeMS - _openDialogWatch.ElapsedMilliseconds;
  547.                 DrawTimeLeftClock(openDlgImgRect, _openDialogWatch.ElapsedMilliseconds, _TimeLeft);
  548.                 DrawTimeLeftNumbers(openDlgRect, _TimeLeft);
  549.             }
  550.             if (_closeDialogWatch.IsRunning)
  551.             {
  552.                 var _TimeLeft = closingTimeMS - _closeDialogWatch.ElapsedMilliseconds;
  553.                 DrawTimeLeftClock(openDlgImgRect, _closeDialogWatch.ElapsedMilliseconds, _TimeLeft);
  554.                 DrawTimeLeftNumbers(openDlgRect, _TimeLeft);
  555.             }
  556.            
  557.             /** routing logic **/
  558.             if (!_show && IsRouting(openDlgRect, _openDialogWatch, openingTimeMS))
  559.             {
  560.                 _drawPageAct = 1;
  561.                 _drawSubpage = 0;
  562.                 CalculateSubPageCount();
  563.                 InitTable();
  564.                 _show = true;
  565.             }
  566.            
  567.             if (_show && IsRouting(openDlgRect, _closeDialogWatch, closingTimeMS))
  568.             {
  569.                 _show = false;
  570.             }
  571.         }
  572.        
  573.         public void ShowDialog()
  574.         {
  575.             if (!_show) return;
  576.            
  577.            
  578.             drawActHeadline(_drawPageAct, Hud.Window.Size.Width * 0.5f, Hud.Window.Size.Height * 0.10f);
  579.             if (_ActSubPages > 1)
  580.                 drawSubpageHeadline(Hud.Window.Size.Width * 0.29f, Hud.Window.Size.Height * 0.18f);
  581.             Routing();
  582.            
  583.             if (_ActSubPages == 0) return;  //nothing toDo -> // noData
  584.            
  585.             Table.Paint();
  586.            
  587.             /** table highlight **/
  588.             if (CursorInsideRect(TableRect))
  589.             {
  590.                 mouseLine = (int) Math.Floor((Hud.Window.CursorY - TableRect.Top) / (Table.Columns.First().Height + Table.SpacingAdjustmentInPixels));
  591.                 mouseCol = (int) Math.Floor((Hud.Window.CursorX - TableRect.Left) / (Table.Columns.First().Width + Table.SpacingAdjustmentInPixels));
  592.             }
  593.         }
  594.        
  595.         private void drawOpenDlg(bool active, float x, float y)
  596.         {
  597.             //relative positioning
  598.             float _xPlus;
  599.             float _yPlus;
  600.             float opacity = active ? 0.7f : 1.0f;
  601.            
  602.             /** dialog button BG **/
  603.             dlgBGTexture.Draw(x, y, dlgBGTexture.Width, dlgBGTexture.Height);
  604.            
  605.             if (_show)
  606.             {
  607.                 /** dialog button close **/
  608.                 _xPlus = (dlgBGTexture.Width - dlgCloseTexture.Width)/2;;
  609.                 _yPlus = (dlgBGTexture.Height - dlgCloseTexture.Height)/2;
  610.                 dlgCloseTexture.Draw(x + _xPlus, y + _yPlus, dlgCloseTexture.Width, dlgCloseTexture.Height, opacity);
  611.             }
  612.             else
  613.             {
  614.                 /** dialog button img **/
  615.                 _xPlus = (dlgBGTexture.Width - dlgImgTexture.Width)/2;;
  616.                 _yPlus = (dlgBGTexture.Height - dlgImgTexture.Height)/2;
  617.                 dlgImgTexture.Draw(x + _xPlus, y + _yPlus, dlgImgTexture.Width, dlgImgTexture.Height, opacity);
  618.             }
  619.            
  620.             //ab hier nur falls active
  621.             if (!active) return;
  622.            
  623.             /** dialog button active frame **/
  624.             dlgActiveTexture.Draw(x, y, dlgActiveTexture.Width, dlgActiveTexture.Height);
  625.         }
  626.        
  627.         /** headline **/
  628.         private void drawActHeadline(int act, float xCenter, float yTop)
  629.         {
  630.             if (act < 0 || act > 5) return;
  631.             //relative positioning
  632.             float _xPlus;
  633.             float _yPlus;
  634.            
  635.             /** act number **/
  636.             _xPlus = -actTexture[act].Width/2;
  637.             _yPlus = 0f;
  638.             actTexture[act].Draw(xCenter + _xPlus, yTop + _yPlus, actTexture[act].Width, actTexture[act].Height);
  639.            
  640.             /** act0Texture **/
  641.             if (act == 0)
  642.             {
  643.                 _xPlus = -1.25f * act0Texture.Width/2;
  644.                 _yPlus = (actTexture[act].Height - 1.25f * act0Texture.Height)/2;
  645.                 act0Texture.Draw(xCenter + _xPlus, yTop + _yPlus, 1.25f * act0Texture.Width, 1.25f * act0Texture.Height);
  646.             }
  647.            
  648.            
  649.             /** act number ring **/
  650.             _xPlus = -ringTexture[act].Width/2;
  651.             _yPlus = (actTexture[act].Height - ringTexture[act].Height)/2;
  652.             ringTexture[act].Draw(xCenter + _xPlus, yTop + _yPlus, ringTexture[act].Width, ringTexture[act].Height);
  653.            
  654.            
  655.             /** bannerscroll **/
  656.             _xPlus = -bannerscrollTexture.Width/2;
  657.             _yPlus = 0.5f * actTexture[act].Height;
  658.             bannerscrollTexture.Draw(xCenter + _xPlus, yTop + _yPlus, bannerscrollTexture.Width, bannerscrollTexture.Height);
  659.            
  660.             /** hier kommt der act text **/
  661.             string _bannerText = MainBanner1 + (act == 0 ? MainBanner2 : MainBanner3 + act);
  662.             var _bannerLayout = BannerFont.GetTextLayout(_bannerText);
  663.             BannerFont.DrawText(_bannerLayout, xCenter + _xPlus + (bannerscrollTexture.Width - _bannerLayout.Metrics.Width)/2, yTop + _yPlus + bannerscrollTexture.Height * 0.32f - _bannerLayout.Metrics.Height/2);
  664.            
  665.             /** hovering button **/
  666.             _xPlus = -(1.1f * buttonTexture.Width)/2;
  667.             _yPlus += bannerscrollTexture.Height - 1.1f * buttonTexture.Height;
  668.             buttonTexture.Draw(xCenter + _xPlus, yTop + _yPlus, 1.1f * buttonTexture.Width, 1.1f * buttonTexture.Height);
  669.            
  670.             /** hier kommt der goblin count text **/
  671.             string _gCount = _gobCnt > 0 ? _gobCnt + GoblinCount1 : GoblinCount0;
  672.            
  673.             var _gCountLayout = GoblinCountFont.GetTextLayout(_gCount);
  674.             GoblinCountFont.DrawText(_gCountLayout, xCenter - (_gCountLayout.Metrics.Width)/2, yTop + _yPlus + buttonTexture.Height * 0.55f - _gCountLayout.Metrics.Height/2);
  675.            
  676.         }
  677.        
  678.         private void drawSubpageHeadline(float xCenter, float yTop)
  679.         {
  680.             //relative positioning
  681.             float _xPlus;
  682.             float _yPlus;
  683.            
  684.             /** Subpage Wimpel **/
  685.             _xPlus = -wimpelTexture.Width/2;
  686.             _yPlus = -smallBannerTexture.Height*0.60f;
  687.             wimpelTexture.Draw(xCenter + _xPlus, yTop + _yPlus, wimpelTexture.Width, wimpelTexture.Height);
  688.             /** Subpage Count **/
  689.             string _wimpelText = (_drawSubpage+1) + "/" + _ActSubPages;
  690.             var _wimpelLayout = SubpageCountFont.GetTextLayout(_wimpelText);
  691.             SubpageCountFont.DrawText(_wimpelLayout, xCenter + _xPlus + (wimpelTexture.Width - _wimpelLayout.Metrics.Width)/2, yTop + _yPlus + wimpelTexture.Height * 0.62f);
  692.            
  693.             /** Subpage Banner **/
  694.             _xPlus = -smallBannerTexture.Width/2;
  695.             _yPlus = 0f;
  696.             smallBannerTexture.Draw(xCenter + _xPlus, yTop + _yPlus, smallBannerTexture.Width, smallBannerTexture.Height);
  697.             /** Subpage **/
  698.             var _bannerLayout = SmallBannerFont.GetTextLayout(SubBanner);
  699.             SmallBannerFont.DrawText(_bannerLayout, xCenter + _xPlus + (smallBannerTexture.Width - _bannerLayout.Metrics.Width)/2, yTop + _yPlus + smallBannerTexture.Height * 0.25f);
  700.         }
  701.        
  702.        
  703.         /** Wii menu moving **/
  704.         private bool PrevAct()
  705.         {
  706.             _drawPageAct = (_drawPageAct + 5)%6;
  707.             _drawSubpage = 0;
  708.             CalculateSubPageCount();
  709.             return true;
  710.         }
  711.         private bool NextAct()
  712.         {
  713.             _drawPageAct = (_drawPageAct + 1)%6;
  714.             _drawSubpage = 0;
  715.             CalculateSubPageCount();
  716.             return true;
  717.         }
  718.        
  719.         private void CalculateSubPageCount()
  720.         {
  721.             _rows = GoblinMapper[_drawPageAct][ElementOrder.First()].Keys.Count();
  722.             int FullPageCount = _rows / MaxRows;
  723.             int beganPage = _rows % MaxRows > 0 ? 1 : 0;
  724.             _ActSubPages = FullPageCount + beganPage;
  725.         }
  726.        
  727.         /** subPages min count == 1 **/
  728.         private bool PrevSubPage(int subPages)
  729.         {
  730.             _drawSubpage = (_drawSubpage + subPages - 1)%subPages;
  731.             return true;
  732.         }
  733.         private bool NextSubPage(int subPages)
  734.         {
  735.             _drawSubpage = (_drawSubpage + 1)%subPages;
  736.             return true;
  737.         }
  738.         private bool CursorInsideRect(RectangleF rect)
  739.         {
  740.             if (Hud.Window.CursorInsideRect(rect.X, rect.Y, rect.Width, rect.Height))
  741.                 return true;
  742.             else
  743.                 return false;
  744.         }
  745.        
  746.         /** mehrere watches?? **/
  747.         private bool IsRouting(RectangleF rect, IWatch watch, long time)
  748.         {
  749.             if (!CursorInsideRect(rect))
  750.                 return false;
  751.            
  752.             if (!watch.IsRunning)
  753.                 watch.Start();
  754.             else if (time <= watch.ElapsedMilliseconds)
  755.             {
  756.                 watch.Stop();
  757.                 watch.Reset();
  758.                 return true;
  759.             }
  760.            
  761.             //still running - not finished yet
  762.             return false;
  763.         }
  764.        
  765.         private void Routing()
  766.         {
  767.             /** Draw Buttons **/
  768.             DrawButton(rectPrevAct, "<<");
  769.             DrawButton(nextPrevAct, ">>");
  770.             if (_ActSubPages > 1)
  771.             {
  772.                 DrawButton(rectPrevSubPage, "<");
  773.                 DrawButton(nextPrevSubPage, ">");
  774.             }
  775.  
  776.             RectangleF _currRect = RectangleF.Empty;
  777.             int _route = 0;
  778.             if (CursorInsideRect(rectPrevAct))
  779.             {
  780.                 _currRect = rectPrevAct;
  781.                 _route = -10;
  782.             }
  783.             else if (CursorInsideRect(nextPrevAct))
  784.             {
  785.                 _currRect = nextPrevAct;
  786.                 _route = 10;
  787.             }
  788.             else if (_ActSubPages > 1 && CursorInsideRect(rectPrevSubPage))
  789.             {
  790.                 _currRect = rectPrevSubPage;
  791.                 _route = -1;
  792.             }
  793.             else if (_ActSubPages > 1 && CursorInsideRect(nextPrevSubPage))
  794.             {
  795.                 _currRect = nextPrevSubPage;
  796.                 _route = 1;
  797.             }
  798.             else if (_routingWatch.IsRunning)
  799.             {
  800.                 _routingWatch.Stop();
  801.                 _routingWatch.Reset();
  802.             }
  803.            
  804.             if (_route == 0) return;
  805.            
  806.            
  807.             /** draw routing - clock & numbers **/
  808.             if (_routingWatch.IsRunning)
  809.             {
  810.                 var _TimeLeft = routingTimeMS - _routingWatch.ElapsedMilliseconds;
  811.                 DrawTimeLeftClockSquare(_currRect, _routingWatch.ElapsedMilliseconds, _TimeLeft);
  812.                 DrawTimeLeftNumbers(_currRect, _TimeLeft);
  813.             }
  814.            
  815.            
  816.             /** routing success ? **/
  817.             if (IsRouting(_currRect, _routingWatch, routingTimeMS))
  818.             {
  819.                 bool _reinit = false;
  820.                 switch (_route)
  821.                 {
  822.                     case -10:
  823.                         _reinit = PrevAct();
  824.                         break;
  825.                     case 10:
  826.                         _reinit = NextAct();
  827.                         break;
  828.                     case -1:
  829.                         _reinit = PrevSubPage(_ActSubPages);
  830.                         break;
  831.                     case 1:
  832.                         _reinit = NextSubPage(_ActSubPages);
  833.                         break;
  834.                 }
  835.                
  836.                 if (_reinit)
  837.                 {
  838.                     InitTable();
  839.                 }
  840.             }
  841.            
  842.         }
  843.        
  844.         /** Buttons in Show **/
  845.         private void DrawButton(RectangleF rect, string text)
  846.         {
  847.             _RoutingButtonText = text;
  848.            
  849.             if (CursorInsideRect(rect))
  850.             {
  851.                 _RoutingButtonText = "";
  852.                 RoutingButton.BackgroundTexture2 = Hud.Texture.BackgroundTextureGreen;
  853.             }
  854.             else
  855.                 RoutingButton.BackgroundTexture2 = Hud.Texture.BackgroundTextureBlue;
  856.            
  857.             RoutingButton.Paint(rect.X, rect.Y, rect.Width, rect.Height, HorizontalAlign.Center);
  858.         }
  859.        
  860.         /** for buttons - clock & numbers **/
  861.         private void DrawTimeLeftClock(RectangleF rect, double elapsed, double timeLeft)
  862.         {
  863.             if ((timeLeft > 0) && (elapsed >= 0) && (TimeLeftClockBrush != null))
  864.             {
  865.                 var endAngle = Convert.ToInt32((360.0d / (timeLeft + elapsed)) * elapsed);
  866.                 var startAngle = 0;
  867.                 TimeLeftClockBrush.Opacity = 1 - (float)(0.3f / (timeLeft + elapsed) * elapsed);
  868.                 var rad = rect.Width * 0.45f;
  869.                 using (var pg = Hud.Render.CreateGeometry())
  870.                 {
  871.                     using (var gs = pg.Open())
  872.                     {
  873.                         gs.BeginFigure(rect.Center, FigureBegin.Filled);
  874.                         for (int angle = startAngle; angle <= endAngle; angle++)
  875.                         {
  876.                             var mx = rad * (float)Math.Cos((angle - 90) * Math.PI / 180.0f);
  877.                             var my = rad * (float)Math.Sin((angle - 90) * Math.PI / 180.0f);
  878.                             var vec = new Vector2(rect.Center.X + mx, rect.Center.Y + my);
  879.                             gs.AddLine(vec);
  880.                         }
  881.                         gs.EndFigure(FigureEnd.Closed);
  882.                         gs.Close();
  883.                     }
  884.                     TimeLeftClockBrush.DrawGeometry(pg);
  885.                 }
  886.             }
  887.         }
  888.        
  889.         /** for buttons - clock & numbers **/
  890.         private void DrawTimeLeftClockSquare(RectangleF rect, double elapsed, double timeLeft)
  891.         {
  892.             if ((timeLeft > 0) && (elapsed >= 0) && (TimeLeftClockBrush != null))
  893.             {
  894.                 var endAngle = Convert.ToInt32((360.0d / (timeLeft + elapsed)) * elapsed);
  895.                 var startAngle = 0;
  896.                 TimeLeftClockBrush.Opacity = 1 - (float)(0.3f / (timeLeft + elapsed) * elapsed);
  897.                 var rad = rect.Width * 0.45f;
  898.                 using (var pg = Hud.Render.CreateGeometry())
  899.                 {
  900.                     using (var gs = pg.Open())
  901.                     {
  902.                         gs.BeginFigure(rect.Center, FigureBegin.Filled);
  903.                         for (int angle = startAngle; angle <= endAngle; angle++)
  904.                         {
  905.                             /** draw TimeLeft als square **/
  906.                             float r;
  907.                             if (angle <= 45 || (135 < angle && angle <= 225) || 315 < angle)
  908.                                 r = (float) Math.Abs(1f/Math.Cos(angle * Math.PI / 180f));
  909.                             else
  910.                                 r = (float) Math.Abs(1f/Math.Sin(angle * Math.PI / 180f));
  911.                            
  912.                             var mx = rad * r * (float)Math.Cos((angle - 90) * Math.PI / 180.0f);
  913.                             var my = rad * r * (float)Math.Sin((angle - 90) * Math.PI / 180.0f);
  914.                             var vec = new Vector2(rect.Center.X + mx, rect.Center.Y + my);
  915.                             gs.AddLine(vec);
  916.                         }
  917.                         gs.EndFigure(FigureEnd.Closed);
  918.                         gs.Close();
  919.                     }
  920.                     TimeLeftClockBrush.DrawGeometry(pg);
  921.                 }
  922.             }
  923.         }
  924.        
  925.         /** for buttons - clock & numbers **/
  926.         private void DrawTimeLeftNumbers(RectangleF rect, double TimeLeftMS)
  927.         {
  928.             var TimeLeft = TimeLeftMS * 0.001f;
  929.             if (TimeLeft == 0) return;
  930.            
  931.             var text = "";
  932.             if (TimeLeft > 1.0f)
  933.             {
  934.                 var mins = Convert.ToInt32(Math.Floor(TimeLeft / 60.0d));
  935.                 var secs = Math.Floor(TimeLeft - mins * 60.0d);
  936.                 if (TimeLeft >= 60)
  937.                 {
  938.                     text = mins.ToString("F0", CultureInfo.InvariantCulture) + ":" + (secs < 10 ? "0" : "") + secs.ToString("F0", CultureInfo.InvariantCulture);
  939.                 }
  940.                 else text = TimeLeft.ToString("F0", CultureInfo.InvariantCulture);
  941.             }
  942.             else text = TimeLeft.ToString("F1", CultureInfo.InvariantCulture);
  943.            
  944.             var layout = TimeLeftFont.GetTextLayout(text);
  945.             TimeLeftFont.DrawText(layout, rect.X + (rect.Width - (float)Math.Ceiling(layout.Metrics.Width)) / 2.0f, rect.Y + (rect.Height - layout.Metrics.Height) / 2);
  946.         }
  947.     }
  948. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement