Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Globalization;
- using SharpDX;
- using SharpDX.Direct2D1;
- using Turbo.Plugins.Default;
- using Turbo.Plugins.Jack.Decorators.TopTables; //table
- namespace Turbo.Plugins.gjuz
- {
- public class GoblinListPlugin : BasePlugin, IInGameTopPainter, IAfterCollectHandler , INewAreaHandler
- {
- /**
- plan:
- toDo
- sorting -> table
- golbin party handling -> rifts
- bandit shrine handling
- export data??
- **/
- private HashSet<uint> GelatinousSpawns = new HashSet<uint>()
- {
- // 408354, //Gelatinous Sire groß
- 429796, //Gelatinous Spawn mittel
- 429797 //Gelatinous Spawn klein
- };
- /* international */
- public Dictionary<uint, string> Goblins { get; set; } //international names set here
- public List<uint> ElementOrder { get; set; } //order in table set here
- public string MainBanner1 { get; set; } //international strings
- public string MainBanner2 { get; set; } //international strings
- public string MainBanner3 { get; set; } //international strings
- public string GoblinCount0 { get; set; } //international strings
- public string GoblinCount1 { get; set; } //international strings
- public string SubBanner { get; set; } //international strings
- /* international */
- /** init **/
- private bool _init;
- /** show **/
- private bool _show;
- /** data **/
- /** act, Golbin, Map, count **/
- private Dictionary<int, Dictionary<uint, Dictionary<string, int>>> GoblinMapper;
- /* act 0-5 */ /* goblin snos */ /* map name */ /* count */
- private HashSet<uint> _lastGob;
- // private HashSet<uint> _lastGobRift;
- private int _gobCnt;
- /** tabelle **/
- public TopTable Table { get; private set; }
- private List<string> _lineHeads;
- private int _cols;
- private int _rows;
- /** table highlight **/
- private int mouseLine;
- private int mouseCol;
- private RectangleF TableRect;
- /** Draw **/
- private int _drawPageAct;
- private int _drawSubpage;
- private int _ActSubPages;
- public int MaxRows { get; set; }
- /** Wii Menu **/
- private IWatch _openDialogWatch; // for opening closing ListDialog
- private IWatch _closeDialogWatch; // for opening closing ListDialog
- private IWatch _routingWatch; // for switching pages in ListDialog
- public long openingTimeMS { get; set; }
- public long closingTimeMS { get; set; }
- public long routingTimeMS { get; set; }
- private float _routingButtonSize;
- private float _routingButtonSizeSmall;
- /** Wii Menu Buttons - for drawing and menu function **/
- private RectangleF openDlgRect;
- private RectangleF openDlgImgRect;
- private RectangleF rectPrevAct;
- private RectangleF nextPrevAct;
- private RectangleF rectPrevSubPage;
- private RectangleF nextPrevSubPage;
- /** Buttons **/
- private string _OpenButtonText;
- public TopLabelDecorator RoutingButton { get; set; }
- private string _RoutingButtonText;
- public IFont TimeLeftFont { get; set; }
- public IBrush TimeLeftClockBrush { get; set; }
- /** Texture Ids **/
- private List<uint> actId = new List<uint>() {
- 1805812053,
- 1805812053,
- 1806997974,
- 1808183895,
- 1809369816,
- 1810555737
- };
- private List<uint> ringId = new List<uint>() {
- 2734730716,
- 2734730717,
- 2734730718,
- 2734730742,
- 2734730743,
- 2734730744
- };
- private uint act0Id = 3572241856;
- private uint bannerscrollId = 1640038511;
- private uint buttontexId = 2326263137;
- private uint dlgBGId = 679903159;
- private uint dlgImgId = 2605755780;
- private uint dlgCloseId = 1429036410;
- private uint dlgActiveId = 672253601;
- private uint wimpelId = 995379405;
- private uint smallBannerId = 1611575647;
- /** Textures **/
- private List<ITexture> actTexture;
- private List<ITexture> ringTexture;
- private ITexture act0Texture;
- private ITexture bannerscrollTexture;
- private ITexture buttonTexture;
- private ITexture dlgBGTexture;
- private ITexture dlgImgTexture;
- private ITexture dlgCloseTexture;
- private ITexture dlgActiveTexture;
- private ITexture wimpelTexture;
- private ITexture smallBannerTexture;
- /** fronts **/
- public IFont BannerFont { get; set; }
- public IFont SmallBannerFont { get; set; }
- public IFont GoblinCountFont { get; set; }
- public IFont SubpageCountFont { get; set; }
- public GoblinListPlugin()
- {
- Enabled = true;
- }
- public override void Load(IController hud)
- {
- base.Load(hud);
- /** strings **/
- MainBanner1 = "List of all Goblins found ";
- MainBanner2 = "somwhere else";
- MainBanner3 = "in Act ";
- GoblinCount0 = "No Goblins here";
- GoblinCount1 = " Goblins";
- SubBanner = "Subpage";
- /** short names of goblins **/
- Goblins = new Dictionary<uint, string> () //short strings
- {
- {429785, "Malevolent"}, //"Malevolent Tormentor"
- {429787, "Blood"}, //"Blood Thief"
- {429794, "Collector"}, //"Odious Collector"
- {429793, "Gems"}, //"Gem Hoarder"
- {429792, "Gelatinous"}, //"Gelatinous Sire"
- {429803, "Gold"}, //"Gilded Baron"
- {429789, "Insufferable"}, //"Insufferable Miscreant"
- {451059, "Menagerist"}, //"Menagerist Goblin"
- {429795, "Treasure"}, //"Treasure Goblin"
- {405624, "Rainbow"}, //"Rainbow Goblin"
- };
- /** order of table **/
- ElementOrder = new List<uint>()
- {
- 405624, //Rainbow Goblin
- 429792, //Gelatinous Sire
- 429785, //Malevolent Tormentor
- 429789, //Insufferable Miscreant
- 429787, //Blood Thief
- 429794, //Odious Collector
- 429793, //Gem Hoarder
- 429803, //Gilded Baron
- 429795, //Treasure Goblin
- 451059, //Menagerist Goblin
- };
- _lastGob = new HashSet<uint>();
- /** Textures **/
- actTexture = new List<ITexture>();
- foreach (uint id in actId)
- actTexture.Add(Hud.Texture.GetTexture(id));
- ringTexture = new List<ITexture>();
- foreach (uint id in ringId)
- ringTexture.Add(Hud.Texture.GetTexture(id));
- act0Texture = Hud.Texture.GetTexture(act0Id);
- bannerscrollTexture = Hud.Texture.GetTexture(bannerscrollId);
- buttonTexture = Hud.Texture.GetTexture(buttontexId);
- dlgBGTexture = Hud.Texture.GetTexture(dlgBGId);
- dlgImgTexture = Hud.Texture.GetTexture(dlgImgId);
- dlgCloseTexture = Hud.Texture.GetTexture(dlgCloseId);
- dlgActiveTexture = Hud.Texture.GetTexture(dlgActiveId);
- wimpelTexture = Hud.Texture.GetTexture(wimpelId);
- smallBannerTexture = Hud.Texture.GetTexture(smallBannerId);
- /** fronts **/
- BannerFont = Hud.Render.CreateFont("tahoma", 10f, 255, 0, 0, 0, false, false, true);
- SmallBannerFont = Hud.Render.CreateFont("tahoma", 7f, 255, 0, 0, 0, false, false, true);
- GoblinCountFont = Hud.Render.CreateFont("tahoma", 10f, 255, 255, 255, 255, false, false, true);
- SubpageCountFont = Hud.Render.CreateFont("tahoma", 7f, 255, 255, 255, 255, false, false, true);
- /** Draw **/
- _drawPageAct = 1;
- _drawSubpage = 0;
- _ActSubPages = 0;
- MaxRows = 25;
- /** Wii Menu **/
- _openDialogWatch = Hud.Time.CreateWatch();
- _closeDialogWatch = Hud.Time.CreateWatch();
- _routingWatch = Hud.Time.CreateWatch();
- openingTimeMS = 3000;
- closingTimeMS = 1000;
- routingTimeMS = 1500;
- _routingButtonSizeSmall = 35f;
- _routingButtonSize = 50f;
- /** Wii Menu Buttons - for drawing and menu function **/
- TimeLeftFont = Hud.Render.CreateFont("tahoma", 7, 255, 255, 255, 255, false, false, 255, 0, 0, 0, true);
- TimeLeftClockBrush = Hud.Render.CreateBrush(220, 0, 0, 0, 0);
- /** RoutingButton **/
- RoutingButton = new TopLabelDecorator(Hud)
- {
- TextFont = Hud.Render.CreateFont("tahoma", 8, 200, 255, 255, 255, true, false, false),
- // Option #2: Use textures for background
- BackgroundTexture1 = Hud.Texture.ButtonTextureGray,
- BackgroundTexture2 = Hud.Texture.BackgroundTextureBlue,
- BackgroundTextureOpacity2 = 0.25f,
- HintFunc = () => "",
- TextFunc = () => _RoutingButtonText
- };
- }
- /** sorting **/
- /** Table **/
- private void InitTable()
- {
- /** for reinit **/
- if (Table != null)
- Table.Dispose();
- /* DifficultiesInfoPlugin */
- _lineHeads = GoblinMapper[_drawPageAct][ElementOrder.First()].Keys.ToList();
- _cols = ElementOrder.Count();
- _rows = _lineHeads.Count();
- /* Table */
- Table = new TopTable(Hud)
- {
- RatioPositionX = 0.5f, //um Hud.Window.Size.Width->50% zentriert -> HorizontalCenter
- RatioPositionY = 0.3f, //ab Hud.Window.Size.Height->20% -> !VerticalCenter
- HorizontalCenter = true,
- VerticalCenter = false,
- PositionFromRight = false,
- PositionFromBottom = false,
- ShowHeaderLeft = true,
- ShowHeaderTop = true,
- ShowHeaderRight = false,
- ShowHeaderBottom = false,
- DefaultCellDecorator = new TopTableCellDecorator(Hud)
- {
- BackgroundBrush = Hud.Render.CreateBrush(255, 0, 0, 0, 0),
- BorderBrush = Hud.Render.CreateBrush(255, 255, 255, 255, -1),
- TextFont = Hud.Render.CreateFont("tahoma", 8, 255, 255, 255, 255, false, false, true),
- },
- DefaultHighlightDecorator = new TopTableCellDecorator(Hud)
- {
- BackgroundBrush = Hud.Render.CreateBrush(255, 0, 0, 242, 0),
- BorderBrush = Hud.Render.CreateBrush(255, 255, 255, 255, -1),
- TextFont = Hud.Render.CreateFont("tahoma", 8, 255, 255, 255, 255, false, false, true),
- },
- DefaultHeaderDecorator = new TopTableCellDecorator(Hud)
- {
- TextFont = Hud.Render.CreateFont("tahoma", 8, 255, 255, 255, 255, false, false, true),
- }
- };
- /* Columns - Header */
- TopTableHeader[] _colHeads = new TopTableHeader[_cols];
- _colHeads[0] = new TopTableHeader(Hud, (pos, curPos) => GetColumnHeaderText(pos))
- {
- RatioHeight = 22 / 1080f, // define only once on first column, value on others will be ignored
- RatioWidth = 0.075f,
- // HighlightFunc = (pos, curPos) => HighlightColumn(pos),
- HighlightFunc = (pos, curPos) => mouseCol == pos,
- TextAlign = HorizontalAlign.Center,
- };
- for (int i = 1; i < _cols; i++)
- {
- _colHeads[i] = new TopTableHeader(Hud, (pos, curPos) => GetColumnHeaderText(pos))
- {
- RatioWidth = 0.075f,
- // HighlightFunc = (pos, curPos) => HighlightColumn(pos),
- HighlightFunc = (pos, curPos) => mouseCol == pos,
- TextAlign = HorizontalAlign.Center,
- };
- }
- Table.DefineColumns(_colHeads);
- /* Rows */
- TopTableCell[] _cells; //define in for-loop, to get correct line numbers
- for (var i = _drawSubpage * MaxRows; i < _rows && i < (_drawSubpage +1) * MaxRows; i++)
- {
- _cells = new TopTableCell[_cols];
- for (int j = 0; j < _cols; j++)
- {
- _cells[j] = new TopTableCell(Hud, (line, column, lineSorted, columnSorted) => GetCellText(line, column)) { TextAlign = HorizontalAlign.Center };
- }
- Table.AddLine(
- new TopTableHeader(Hud, (pos, curPos) => GetLineHeaderText(pos))
- {
- RatioWidth = 0 / 1080f, // define only once on first line, value on other will be ignored
- // RatioWidth = 62 / 1080f, // define only once on first line, value on other will be ignored
- RatioHeight = 22 / 1080f,
- // HighlightFunc = (pos, curPos) => false,
- HighlightFunc = (pos, curPos) => mouseLine == pos,
- TextAlign = HorizontalAlign.Right,
- HighlightDecorator = new TopTableCellDecorator(Hud)
- {
- // BackgroundBrush = Hud.Render.CreateBrush(255, 0, 0, 0, 0),
- BackgroundBrush = Hud.Render.CreateBrush(255, 0, 0, 242, 0),
- BorderBrush = Hud.Render.CreateBrush(255, 255, 255, 255, -1),
- TextFont = Hud.Render.CreateFont("tahoma", 8, 255, 255, 255, 255, true, false, true),
- },
- CellHighlightDecorator = new TopTableCellDecorator(Hud)
- {
- // BackgroundBrush = Hud.Render.CreateBrush(255, 0, 0, 0, 0),
- BackgroundBrush = Hud.Render.CreateBrush(255, 0, 0, 242, 0),
- BorderBrush = Hud.Render.CreateBrush(255, 255, 255, 255, -1),
- TextFont = Hud.Render.CreateFont("tahoma", 8, 255, 255, 255, 255, true, false, true),
- },
- },
- _cells
- );
- }
- _gobCnt = CountGoblin(_drawPageAct);
- /** table highlight **/
- TableRect = TableRectangle();
- mouseLine = -1;
- }
- /** mehrere pages für einen act ?? **/
- private string GetColumnHeaderText(int pos)
- {
- return Goblins[ElementOrder[pos]];
- }
- private string GetLineHeaderText(int pos)
- {
- /** _drawSubpage, MaxRows **/
- return _lineHeads[_drawSubpage * MaxRows + pos];
- }
- private string GetCellText(int line, int column)
- {
- /* act 0-5 */ /* goblin snos */ /* map name */ /* count */
- // private Dictionary<int, Dictionary<uint, Dictionary<string, int>>> GoblinMapper;
- return GoblinMapper[_drawPageAct][ElementOrder[column]][GetLineHeaderText(line)].ToString();
- }
- private int CountGoblin(int act)
- {
- int _cnt = 0;
- foreach (var gob in ElementOrder)
- {
- foreach (var map in _lineHeads)
- {
- _cnt += GoblinMapper[act][gob][map];
- }
- }
- return _cnt;
- }
- /** table highlight **/
- private RectangleF TableRectangle()
- {
- float tablewidth = Table.Columns.Select(c => c.Width).Sum() + (Table.Columns.Count * Table.SpacingAdjustmentInPixels) - Table.SpacingAdjustmentInPixels;
- float tableheight = Table.Lines.Select(c => c.Height).Sum() + (Table.Lines.Count * Table.SpacingAdjustmentInPixels) - Table.SpacingAdjustmentInPixels;
- float tableleft = Table.RatioPositionX * Hud.Window.Size.Width - tablewidth / 2;
- float tabletop = Table.RatioPositionY * Hud.Window.Size.Height + Table.Columns.First().Height + Table.SpacingAdjustmentInPixels;
- return new RectangleF(tableleft, tabletop, tablewidth, tableheight);
- }
- /** bis hier tabelle **/
- public void OnNewArea(bool newGame, ISnoArea area)
- {
- if (newGame)
- {
- _lastGob.Clear();
- _show = false;
- }
- }
- //logic
- public void AfterCollect()
- {
- /** für rifts _lastGobRift -> riftclose -> clear() **/
- if (Hud.Game.Me.SnoArea == null || Hud.Game.Me.SnoArea.Code == null || Hud.Game.Me.SnoArea.Code.Contains("x1_lr_level") ) //OHNE rifts...
- return;
- var goblins = Hud.Game.AliveMonsters.Where(x => x.SnoMonster.Priority == MonsterPriority.goblin && !(GelatinousSpawns.Contains(x.SnoMonster.Sno)) );
- /** count goblins **/
- /** problem mehrere goblins onscreen - party oder bandit shrine **/
- foreach (var goblin in goblins)
- {
- if (!goblin.IsOnScreen) continue;
- if (_lastGob.Contains(goblin.AcdId)) continue;
- //to be safe: is gobSNO in there
- //-> soll ich mich um den gob kümmern?
- if (ElementOrder.Contains(goblin.SnoMonster.Sno))
- {
- //counting
- //private Dictionary<int, Dictionary<uint, Dictionary<string, int>>> GoblinMapper;
- /* act 0-5 */ /* goblin snos */ /* map name */ /* count */
- if (!GoblinMapper[Hud.Game.Me.SnoArea.Act][goblin.SnoMonster.Sno].ContainsKey(Hud.Game.Me.SnoArea.NameLocalized))
- {
- foreach (var gobSno in ElementOrder)
- GoblinMapper[Hud.Game.Me.SnoArea.Act][gobSno].Add(Hud.Game.Me.SnoArea.NameLocalized,0);
- }
- GoblinMapper[Hud.Game.Me.SnoArea.Act][goblin.SnoMonster.Sno][Hud.Game.Me.SnoArea.NameLocalized]++;
- }
- _lastGob.Add(goblin.AcdId);
- }
- }
- private void init()
- {
- //only set once not every cycle
- /** Wii Menu Buttons - for drawing and menu function **/
- System.Drawing.RectangleF uiRect = Hud.Render.GetUiElement("Root.NormalLayer.game_dialog_backgroundScreenPC.game_window_hud_overlay").Rectangle;
- float openDlgX = uiRect.Right;
- float openDlgY = uiRect.Top + uiRect.Height * 0.39f;
- openDlgRect = new RectangleF(openDlgX, openDlgY, dlgBGTexture.Width, dlgBGTexture.Height);
- openDlgX += (dlgBGTexture.Width - dlgImgTexture.Width)/2;
- openDlgY += (dlgBGTexture.Height - dlgImgTexture.Height)/2;
- openDlgImgRect = new RectangleF(openDlgX, openDlgY, dlgImgTexture.Width, dlgImgTexture.Height);
- /** Wii Menu Buttons - for drawing and menu function **/
- rectPrevAct = new RectangleF(Hud.Window.Size.Width * 0.5f - _routingButtonSize * 3.5f, Hud.Window.Size.Height * 0.13f, _routingButtonSize, _routingButtonSize);
- nextPrevAct = new RectangleF(Hud.Window.Size.Width * 0.5f + _routingButtonSize * 2.5f, Hud.Window.Size.Height * 0.13f, _routingButtonSize, _routingButtonSize);
- rectPrevSubPage = new RectangleF(Hud.Window.Size.Width * 0.29f - _routingButtonSizeSmall * 2, Hud.Window.Size.Height * 0.22f, _routingButtonSizeSmall, _routingButtonSizeSmall);
- nextPrevSubPage = new RectangleF(Hud.Window.Size.Width * 0.29f + _routingButtonSizeSmall, Hud.Window.Size.Height * 0.22f, _routingButtonSizeSmall, _routingButtonSizeSmall);
- /** init GoblinMapper **/
- GoblinMapper = new Dictionary<int, Dictionary<uint, Dictionary<string, int>>>();
- for (int i = 0; i <= 5; i++)
- {
- GoblinMapper.Add(i, new Dictionary<uint, Dictionary<string, int>>());
- foreach (var gob in ElementOrder)
- {
- GoblinMapper[i].Add(gob, new Dictionary<string, int>());
- }
- }
- _show = false;
- _init = true;
- }
- public void PaintTopInGame(ClipState clipState)
- {
- if (!_init)
- init();
- /** ElementOrder empty - nothing to do... **/
- if (!ElementOrder.Any()) return;
- if (!Hud.Game.IsInTown && _show) _show = false;
- if (!Hud.Game.IsInTown) return; //only in Town
- if (clipState != ClipState.AfterClip) return;
- OpenDialog();
- ShowDialog();
- }
- private void OpenDialog()
- {
- //draw buttons
- if (!_show)
- {
- drawOpenDlg(_openDialogWatch.IsRunning, openDlgRect.Left, openDlgRect.Top);
- }
- if (_show)
- {
- drawOpenDlg(_closeDialogWatch.IsRunning, openDlgRect.Left, openDlgRect.Top);
- }
- //no open/close
- if (!CursorInsideRect(openDlgRect))
- {
- _openDialogWatch.Reset();
- _closeDialogWatch.Reset();
- }
- /** draw routing - clock & numbers **/
- if (_openDialogWatch.IsRunning)
- {
- var _TimeLeft = openingTimeMS - _openDialogWatch.ElapsedMilliseconds;
- DrawTimeLeftClock(openDlgImgRect, _openDialogWatch.ElapsedMilliseconds, _TimeLeft);
- DrawTimeLeftNumbers(openDlgRect, _TimeLeft);
- }
- if (_closeDialogWatch.IsRunning)
- {
- var _TimeLeft = closingTimeMS - _closeDialogWatch.ElapsedMilliseconds;
- DrawTimeLeftClock(openDlgImgRect, _closeDialogWatch.ElapsedMilliseconds, _TimeLeft);
- DrawTimeLeftNumbers(openDlgRect, _TimeLeft);
- }
- /** routing logic **/
- if (!_show && IsRouting(openDlgRect, _openDialogWatch, openingTimeMS))
- {
- _drawPageAct = 1;
- _drawSubpage = 0;
- CalculateSubPageCount();
- InitTable();
- _show = true;
- }
- if (_show && IsRouting(openDlgRect, _closeDialogWatch, closingTimeMS))
- {
- _show = false;
- }
- }
- public void ShowDialog()
- {
- if (!_show) return;
- drawActHeadline(_drawPageAct, Hud.Window.Size.Width * 0.5f, Hud.Window.Size.Height * 0.10f);
- if (_ActSubPages > 1)
- drawSubpageHeadline(Hud.Window.Size.Width * 0.29f, Hud.Window.Size.Height * 0.18f);
- Routing();
- if (_ActSubPages == 0) return; //nothing toDo -> // noData
- Table.Paint();
- /** table highlight **/
- if (CursorInsideRect(TableRect))
- {
- mouseLine = (int) Math.Floor((Hud.Window.CursorY - TableRect.Top) / (Table.Columns.First().Height + Table.SpacingAdjustmentInPixels));
- mouseCol = (int) Math.Floor((Hud.Window.CursorX - TableRect.Left) / (Table.Columns.First().Width + Table.SpacingAdjustmentInPixels));
- }
- }
- private void drawOpenDlg(bool active, float x, float y)
- {
- //relative positioning
- float _xPlus;
- float _yPlus;
- float opacity = active ? 0.7f : 1.0f;
- /** dialog button BG **/
- dlgBGTexture.Draw(x, y, dlgBGTexture.Width, dlgBGTexture.Height);
- if (_show)
- {
- /** dialog button close **/
- _xPlus = (dlgBGTexture.Width - dlgCloseTexture.Width)/2;;
- _yPlus = (dlgBGTexture.Height - dlgCloseTexture.Height)/2;
- dlgCloseTexture.Draw(x + _xPlus, y + _yPlus, dlgCloseTexture.Width, dlgCloseTexture.Height, opacity);
- }
- else
- {
- /** dialog button img **/
- _xPlus = (dlgBGTexture.Width - dlgImgTexture.Width)/2;;
- _yPlus = (dlgBGTexture.Height - dlgImgTexture.Height)/2;
- dlgImgTexture.Draw(x + _xPlus, y + _yPlus, dlgImgTexture.Width, dlgImgTexture.Height, opacity);
- }
- //ab hier nur falls active
- if (!active) return;
- /** dialog button active frame **/
- dlgActiveTexture.Draw(x, y, dlgActiveTexture.Width, dlgActiveTexture.Height);
- }
- /** headline **/
- private void drawActHeadline(int act, float xCenter, float yTop)
- {
- if (act < 0 || act > 5) return;
- //relative positioning
- float _xPlus;
- float _yPlus;
- /** act number **/
- _xPlus = -actTexture[act].Width/2;
- _yPlus = 0f;
- actTexture[act].Draw(xCenter + _xPlus, yTop + _yPlus, actTexture[act].Width, actTexture[act].Height);
- /** act0Texture **/
- if (act == 0)
- {
- _xPlus = -1.25f * act0Texture.Width/2;
- _yPlus = (actTexture[act].Height - 1.25f * act0Texture.Height)/2;
- act0Texture.Draw(xCenter + _xPlus, yTop + _yPlus, 1.25f * act0Texture.Width, 1.25f * act0Texture.Height);
- }
- /** act number ring **/
- _xPlus = -ringTexture[act].Width/2;
- _yPlus = (actTexture[act].Height - ringTexture[act].Height)/2;
- ringTexture[act].Draw(xCenter + _xPlus, yTop + _yPlus, ringTexture[act].Width, ringTexture[act].Height);
- /** bannerscroll **/
- _xPlus = -bannerscrollTexture.Width/2;
- _yPlus = 0.5f * actTexture[act].Height;
- bannerscrollTexture.Draw(xCenter + _xPlus, yTop + _yPlus, bannerscrollTexture.Width, bannerscrollTexture.Height);
- /** hier kommt der act text **/
- string _bannerText = MainBanner1 + (act == 0 ? MainBanner2 : MainBanner3 + act);
- var _bannerLayout = BannerFont.GetTextLayout(_bannerText);
- BannerFont.DrawText(_bannerLayout, xCenter + _xPlus + (bannerscrollTexture.Width - _bannerLayout.Metrics.Width)/2, yTop + _yPlus + bannerscrollTexture.Height * 0.32f - _bannerLayout.Metrics.Height/2);
- /** hovering button **/
- _xPlus = -(1.1f * buttonTexture.Width)/2;
- _yPlus += bannerscrollTexture.Height - 1.1f * buttonTexture.Height;
- buttonTexture.Draw(xCenter + _xPlus, yTop + _yPlus, 1.1f * buttonTexture.Width, 1.1f * buttonTexture.Height);
- /** hier kommt der goblin count text **/
- string _gCount = _gobCnt > 0 ? _gobCnt + GoblinCount1 : GoblinCount0;
- var _gCountLayout = GoblinCountFont.GetTextLayout(_gCount);
- GoblinCountFont.DrawText(_gCountLayout, xCenter - (_gCountLayout.Metrics.Width)/2, yTop + _yPlus + buttonTexture.Height * 0.55f - _gCountLayout.Metrics.Height/2);
- }
- private void drawSubpageHeadline(float xCenter, float yTop)
- {
- //relative positioning
- float _xPlus;
- float _yPlus;
- /** Subpage Wimpel **/
- _xPlus = -wimpelTexture.Width/2;
- _yPlus = -smallBannerTexture.Height*0.60f;
- wimpelTexture.Draw(xCenter + _xPlus, yTop + _yPlus, wimpelTexture.Width, wimpelTexture.Height);
- /** Subpage Count **/
- string _wimpelText = (_drawSubpage+1) + "/" + _ActSubPages;
- var _wimpelLayout = SubpageCountFont.GetTextLayout(_wimpelText);
- SubpageCountFont.DrawText(_wimpelLayout, xCenter + _xPlus + (wimpelTexture.Width - _wimpelLayout.Metrics.Width)/2, yTop + _yPlus + wimpelTexture.Height * 0.62f);
- /** Subpage Banner **/
- _xPlus = -smallBannerTexture.Width/2;
- _yPlus = 0f;
- smallBannerTexture.Draw(xCenter + _xPlus, yTop + _yPlus, smallBannerTexture.Width, smallBannerTexture.Height);
- /** Subpage **/
- var _bannerLayout = SmallBannerFont.GetTextLayout(SubBanner);
- SmallBannerFont.DrawText(_bannerLayout, xCenter + _xPlus + (smallBannerTexture.Width - _bannerLayout.Metrics.Width)/2, yTop + _yPlus + smallBannerTexture.Height * 0.25f);
- }
- /** Wii menu moving **/
- private bool PrevAct()
- {
- _drawPageAct = (_drawPageAct + 5)%6;
- _drawSubpage = 0;
- CalculateSubPageCount();
- return true;
- }
- private bool NextAct()
- {
- _drawPageAct = (_drawPageAct + 1)%6;
- _drawSubpage = 0;
- CalculateSubPageCount();
- return true;
- }
- private void CalculateSubPageCount()
- {
- _rows = GoblinMapper[_drawPageAct][ElementOrder.First()].Keys.Count();
- int FullPageCount = _rows / MaxRows;
- int beganPage = _rows % MaxRows > 0 ? 1 : 0;
- _ActSubPages = FullPageCount + beganPage;
- }
- /** subPages min count == 1 **/
- private bool PrevSubPage(int subPages)
- {
- _drawSubpage = (_drawSubpage + subPages - 1)%subPages;
- return true;
- }
- private bool NextSubPage(int subPages)
- {
- _drawSubpage = (_drawSubpage + 1)%subPages;
- return true;
- }
- private bool CursorInsideRect(RectangleF rect)
- {
- if (Hud.Window.CursorInsideRect(rect.X, rect.Y, rect.Width, rect.Height))
- return true;
- else
- return false;
- }
- /** mehrere watches?? **/
- private bool IsRouting(RectangleF rect, IWatch watch, long time)
- {
- if (!CursorInsideRect(rect))
- return false;
- if (!watch.IsRunning)
- watch.Start();
- else if (time <= watch.ElapsedMilliseconds)
- {
- watch.Stop();
- watch.Reset();
- return true;
- }
- //still running - not finished yet
- return false;
- }
- private void Routing()
- {
- /** Draw Buttons **/
- DrawButton(rectPrevAct, "<<");
- DrawButton(nextPrevAct, ">>");
- if (_ActSubPages > 1)
- {
- DrawButton(rectPrevSubPage, "<");
- DrawButton(nextPrevSubPage, ">");
- }
- RectangleF _currRect = RectangleF.Empty;
- int _route = 0;
- if (CursorInsideRect(rectPrevAct))
- {
- _currRect = rectPrevAct;
- _route = -10;
- }
- else if (CursorInsideRect(nextPrevAct))
- {
- _currRect = nextPrevAct;
- _route = 10;
- }
- else if (_ActSubPages > 1 && CursorInsideRect(rectPrevSubPage))
- {
- _currRect = rectPrevSubPage;
- _route = -1;
- }
- else if (_ActSubPages > 1 && CursorInsideRect(nextPrevSubPage))
- {
- _currRect = nextPrevSubPage;
- _route = 1;
- }
- else if (_routingWatch.IsRunning)
- {
- _routingWatch.Stop();
- _routingWatch.Reset();
- }
- if (_route == 0) return;
- /** draw routing - clock & numbers **/
- if (_routingWatch.IsRunning)
- {
- var _TimeLeft = routingTimeMS - _routingWatch.ElapsedMilliseconds;
- DrawTimeLeftClockSquare(_currRect, _routingWatch.ElapsedMilliseconds, _TimeLeft);
- DrawTimeLeftNumbers(_currRect, _TimeLeft);
- }
- /** routing success ? **/
- if (IsRouting(_currRect, _routingWatch, routingTimeMS))
- {
- bool _reinit = false;
- switch (_route)
- {
- case -10:
- _reinit = PrevAct();
- break;
- case 10:
- _reinit = NextAct();
- break;
- case -1:
- _reinit = PrevSubPage(_ActSubPages);
- break;
- case 1:
- _reinit = NextSubPage(_ActSubPages);
- break;
- }
- if (_reinit)
- {
- InitTable();
- }
- }
- }
- /** Buttons in Show **/
- private void DrawButton(RectangleF rect, string text)
- {
- _RoutingButtonText = text;
- if (CursorInsideRect(rect))
- {
- _RoutingButtonText = "";
- RoutingButton.BackgroundTexture2 = Hud.Texture.BackgroundTextureGreen;
- }
- else
- RoutingButton.BackgroundTexture2 = Hud.Texture.BackgroundTextureBlue;
- RoutingButton.Paint(rect.X, rect.Y, rect.Width, rect.Height, HorizontalAlign.Center);
- }
- /** for buttons - clock & numbers **/
- private void DrawTimeLeftClock(RectangleF rect, double elapsed, double timeLeft)
- {
- if ((timeLeft > 0) && (elapsed >= 0) && (TimeLeftClockBrush != null))
- {
- var endAngle = Convert.ToInt32((360.0d / (timeLeft + elapsed)) * elapsed);
- var startAngle = 0;
- TimeLeftClockBrush.Opacity = 1 - (float)(0.3f / (timeLeft + elapsed) * elapsed);
- var rad = rect.Width * 0.45f;
- using (var pg = Hud.Render.CreateGeometry())
- {
- using (var gs = pg.Open())
- {
- gs.BeginFigure(rect.Center, FigureBegin.Filled);
- for (int angle = startAngle; angle <= endAngle; angle++)
- {
- var mx = rad * (float)Math.Cos((angle - 90) * Math.PI / 180.0f);
- var my = rad * (float)Math.Sin((angle - 90) * Math.PI / 180.0f);
- var vec = new Vector2(rect.Center.X + mx, rect.Center.Y + my);
- gs.AddLine(vec);
- }
- gs.EndFigure(FigureEnd.Closed);
- gs.Close();
- }
- TimeLeftClockBrush.DrawGeometry(pg);
- }
- }
- }
- /** for buttons - clock & numbers **/
- private void DrawTimeLeftClockSquare(RectangleF rect, double elapsed, double timeLeft)
- {
- if ((timeLeft > 0) && (elapsed >= 0) && (TimeLeftClockBrush != null))
- {
- var endAngle = Convert.ToInt32((360.0d / (timeLeft + elapsed)) * elapsed);
- var startAngle = 0;
- TimeLeftClockBrush.Opacity = 1 - (float)(0.3f / (timeLeft + elapsed) * elapsed);
- var rad = rect.Width * 0.45f;
- using (var pg = Hud.Render.CreateGeometry())
- {
- using (var gs = pg.Open())
- {
- gs.BeginFigure(rect.Center, FigureBegin.Filled);
- for (int angle = startAngle; angle <= endAngle; angle++)
- {
- /** draw TimeLeft als square **/
- float r;
- if (angle <= 45 || (135 < angle && angle <= 225) || 315 < angle)
- r = (float) Math.Abs(1f/Math.Cos(angle * Math.PI / 180f));
- else
- r = (float) Math.Abs(1f/Math.Sin(angle * Math.PI / 180f));
- var mx = rad * r * (float)Math.Cos((angle - 90) * Math.PI / 180.0f);
- var my = rad * r * (float)Math.Sin((angle - 90) * Math.PI / 180.0f);
- var vec = new Vector2(rect.Center.X + mx, rect.Center.Y + my);
- gs.AddLine(vec);
- }
- gs.EndFigure(FigureEnd.Closed);
- gs.Close();
- }
- TimeLeftClockBrush.DrawGeometry(pg);
- }
- }
- }
- /** for buttons - clock & numbers **/
- private void DrawTimeLeftNumbers(RectangleF rect, double TimeLeftMS)
- {
- var TimeLeft = TimeLeftMS * 0.001f;
- if (TimeLeft == 0) return;
- var text = "";
- if (TimeLeft > 1.0f)
- {
- var mins = Convert.ToInt32(Math.Floor(TimeLeft / 60.0d));
- var secs = Math.Floor(TimeLeft - mins * 60.0d);
- if (TimeLeft >= 60)
- {
- text = mins.ToString("F0", CultureInfo.InvariantCulture) + ":" + (secs < 10 ? "0" : "") + secs.ToString("F0", CultureInfo.InvariantCulture);
- }
- else text = TimeLeft.ToString("F0", CultureInfo.InvariantCulture);
- }
- else text = TimeLeft.ToString("F1", CultureInfo.InvariantCulture);
- var layout = TimeLeftFont.GetTextLayout(text);
- TimeLeftFont.DrawText(layout, rect.X + (rect.Width - (float)Math.Ceiling(layout.Metrics.Width)) / 2.0f, rect.Y + (rect.Height - layout.Metrics.Height) / 2);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement