AGSScriptModuleKitaiCe module permet d'utiliser des inventaires "typés"TypeInvBtn1.0è(#define TYPE_PROPRIETE "Type_Inv" #define COULEUR_BORDURES -1 int Nb_Boutons; int N_ligne[]; int N_col[]; DynamicSprite* Finv[]; DynamicSprite* Tinv[]; DynamicSprite* Fcache[]; String Boutons[]; String BPropriete[]; int BPerso[]; int NB_Lignes[]; int NB_Colonnes[]; function Scroll(this Button*, int direction) { String id_gui_bouton = String.Format("%d.%d", this.OwningGUI.ID, this.ID); int n; while (n < Nb_Boutons) { if (id_gui_bouton == Boutons[n]) { int w_i = Finv[n].Width, h_i = (Tinv[n].Height / NB_Lignes[n]); int col = Tinv[n].Width / NB_Colonnes[n]; if ((direction == 1) && (N_ligne[n] < NB_Lignes[n] - 1)) N_ligne[n]++; if ((direction == -1) && (N_ligne[n] > 0)) N_ligne[n]--; if ((direction == 2) && (N_col[n] < NB_Colonnes[n] - 1)) N_col[n]++; if ((direction == -2) && (N_col[n] > 0)) N_col[n]--; Finv[n] = DynamicSprite.CreateFromExistingSprite(Tinv[n].Graphic); Finv[n].Crop(N_col[n] * col, N_ligne[n] * h_i, Tinv[n].Width - N_col[n] * col, Tinv[n].Height - N_ligne[n] * h_i); Finv[n].ChangeCanvasSize(this.Width, this.Height, 0, 0); DrawingSurface* surf = Finv[n].GetDrawingSurface(); surf.DrawingColor = COULEUR_BORDURES; surf.DrawLine(0, 0, this.Width-1, 0); surf.DrawLine(this.Width-1, 0, this.Width-1, this.Height-1); surf.DrawLine(0, 0, 0, this.Height-1); surf.DrawLine(this.Width-1, this.Height-1, 0, this.Height-1); surf.Release(); this.NormalGraphic = Finv[n].Graphic; return; } n++; } } function ScrollUp(this Button*) { this.Scroll(-1); } function ScrollDown(this Button*) { this.Scroll(1); } function ScrollLeft(this Button*) { this.Scroll(-2); } function ScrollRight(this Button*) { this.Scroll(2); } int Nouveau_Bouton(this Button*, String propriete, Character* personnage) { String id_gui_bouton = String.Format("%d.%d", this.OwningGUI.ID, this.ID); int n; while (n < Nb_Boutons) { if (id_gui_bouton == Boutons[n]) { Finv[n] = DynamicSprite.Create(this.Width, this.Height); N_ligne[n] = 0; N_col[n] = 0; return n; } n++; } Nb_Boutons++; if (Nb_Boutons > 1) { DynamicSprite* ftmp[]; ftmp = new DynamicSprite[Nb_Boutons-1]; DynamicSprite* ttmp[]; ttmp = new DynamicSprite[Nb_Boutons-1]; DynamicSprite* buffer[]; buffer = new DynamicSprite[Nb_Boutons-1]; String btmp[]; btmp = new String[Nb_Boutons-1]; int ltmp[]; ltmp = new int[Nb_Boutons-1]; int ctmp[]; ctmp = new int[Nb_Boutons-1]; String ptmp[]; ptmp = new String[Nb_Boutons-1]; int perstmp[]; perstmp = new int[Nb_Boutons-1]; int nltmp[]; nltmp = new int[Nb_Boutons-1]; int nctmp[]; nctmp = new int[Nb_Boutons-1]; int i; while (i < Nb_Boutons - 1) { ftmp[i] = Finv[i]; ttmp[i] = Tinv[i]; buffer[i] = Fcache[i]; btmp[i] = Boutons[i]; ltmp[i] = N_ligne[i]; ctmp[i] = N_col[i]; ptmp[i] = BPropriete[i]; perstmp[i] = BPerso[i]; nltmp[i] = NB_Lignes[i]; nctmp[i] = NB_Colonnes[i]; i++; } Finv = new DynamicSprite[Nb_Boutons]; Tinv = new DynamicSprite[Nb_Boutons]; Fcache = new DynamicSprite[Nb_Boutons]; Boutons = new String[Nb_Boutons]; N_ligne = new int[Nb_Boutons]; N_col = new int[Nb_Boutons]; BPropriete = new String[Nb_Boutons]; BPerso = new int[Nb_Boutons]; NB_Lignes = new int[Nb_Boutons]; NB_Colonnes = new int[Nb_Boutons]; i = 0; while (i < Nb_Boutons - 1) { Finv[i] = ftmp[i]; Tinv[i] = ttmp[i]; Fcache[i] = buffer[i]; Boutons[i] = btmp[i]; N_ligne[i] = ltmp[i]; N_col[i] = ctmp[i]; BPropriete[i] = ptmp[i]; BPerso[i] = perstmp[i]; NB_Lignes[i] = nltmp[i]; NB_Colonnes[i] = nctmp[i]; i++; } } else { Finv = new DynamicSprite[Nb_Boutons]; Tinv = new DynamicSprite[Nb_Boutons]; Fcache = new DynamicSprite[Nb_Boutons]; Boutons = new String[Nb_Boutons]; N_ligne = new int[Nb_Boutons]; N_col = new int[Nb_Boutons]; BPropriete = new String[Nb_Boutons]; BPerso = new int[Nb_Boutons]; NB_Lignes = new int[Nb_Boutons]; NB_Colonnes = new int[Nb_Boutons]; } Boutons[Nb_Boutons - 1] = id_gui_bouton; BPropriete[Nb_Boutons - 1] = propriete; BPerso[Nb_Boutons - 1] = personnage.ID; return Nb_Boutons - 1; } function AsInv(this Button*, Character* personnage, String propriete, InvBtn_ScrollType scroll_type) { int n = this.Nouveau_Bouton(propriete, personnage), i = 1, x, y, w_i, h_i, nombre_items, items_par_ligne, items_par_colonnes; bool stop = false; while (i <= Game.InventoryItemCount) { if ((personnage.HasInventory(inventory[i])) && (inventory[i].GetTextProperty(TYPE_PROPRIETE) == propriete)) { int a, nb = personnage.InventoryQuantity[inventory[i].ID]; if ((nb > 0) && (GetGameOption(OPT_MULTIPLEINV) == 0)) nb = 1; while (a < nb) { DynamicSprite* tmp = DynamicSprite.CreateFromExistingSprite(inventory[i].Graphic); if ((2 + tmp.Width) > w_i) w_i = 2 + tmp.Width; if ((2 + tmp.Height) > h_i) h_i = 2 + tmp.Height; tmp.Delete(); nombre_items++; a++; } } i++; } NB_Lignes[n] = 1; NB_Colonnes[n] = 1; if (nombre_items > 0) { items_par_ligne = this.Width / w_i; items_par_colonnes = this.Height / h_i; if (items_par_ligne == 0) items_par_ligne = 1; if (items_par_colonnes == 0) items_par_colonnes = 1; if (scroll_type == 0) NB_Lignes[n] = FloatToInt(IntToFloat(nombre_items) / IntToFloat(items_par_ligne), eRoundUp); if (scroll_type == 1) NB_Colonnes[n] = FloatToInt(IntToFloat(nombre_items) / IntToFloat(items_par_colonnes), eRoundUp); int spr_w = this.Width, spr_h = this.Height; if (scroll_type == 0) spr_h = NB_Lignes[n] * h_i; else if (scroll_type == 1) spr_w = NB_Colonnes[n] * w_i; Tinv[n] = DynamicSprite.Create(spr_w, spr_h); Fcache[n] = DynamicSprite.Create(spr_w, spr_h); } else { Tinv[n] = DynamicSprite.Create(1, 1); Fcache[n] = DynamicSprite.Create(1, 1); } DrawingSurface* buffer = Fcache[n].GetDrawingSurface(); buffer.UseHighResCoordinates = true; DrawingSurface* tout = Tinv[n].GetDrawingSurface(); tout.UseHighResCoordinates = true; i = 0; while ((i <= Game.InventoryItemCount) && (!stop)) { if ((personnage.HasInventory(inventory[i])) && (inventory[i].GetTextProperty(TYPE_PROPRIETE) == propriete)) { int a, nb = player.InventoryQuantity[inventory[i].ID]; if ((nb > 0) && (GetGameOption(OPT_MULTIPLEINV) == 0)) nb = 1; while (a < nb) { DynamicSprite* tmp = DynamicSprite.CreateFromExistingSprite(inventory[i].Graphic); tout.DrawImage(x * w_i + ((w_i - tmp.Width) / 2), y * h_i + ((h_i - tmp.Height) / 2), tmp.Graphic); buffer.DrawingColor = i + 31; buffer.DrawRectangle(x * w_i, y * h_i, (x + 1) * w_i, (y + 1) * h_i); if (scroll_type == 0) { x++; if (x >= items_par_ligne) { y++; x = 0; } } if (scroll_type == 1) { y++; if (y >= items_par_colonnes) { x++; y = 0; } } tmp.Delete(); a++; } } i++; } tout.Release(); buffer.Release(); Finv[n] = DynamicSprite.CreateFromExistingSprite(Tinv[n].Graphic); this.ScrollUp(); } InventoryItem* GetInvBtnAt(int x, int y) { GUIControl* ct = GUIControl.GetAtScreenXY(x, y); if (ct == null) return null; Button* bt = ct.AsButton; if (bt == null) return null; int n; while (n < Nb_Boutons) { String ftmp = String.Format("%d.%d", bt.OwningGUI.ID, bt.ID); if (ftmp == Boutons[n]) { DrawingSurface* buffer = Fcache[n].GetDrawingSurface(); int dx = mouse.x - bt.OwningGUI.X - bt.X, dy = mouse.y - bt.OwningGUI.Y - bt.Y; int color = buffer.GetPixel(dx + N_col[n] * Tinv[n].Width / NB_Colonnes[n], dy + (N_ligne[n] * (Tinv[n].Height / NB_Lignes[n]))); if ((color > 31) && (color - 31 <= Game.InventoryItemCount)) return inventory[color - 31]; return null; } n++; } return null; } function InvBtnFree() { int i; while (i 1) bouton.AsInv(character[BPerso[n]], BPropriete[n], eInvBtn_Vertical); else bouton.AsInv(character[BPerso[n]], BPropriete[n], eInvBtn_Horizontal); } n++; } } if (event == eEventGUIMouseDown) { if (!Mouse.IsButtonDown(eMouseLeft)) return; InventoryItem* itmp = GetInvBtnAt(mouse.x, mouse.y); if (itmp == null) return; if (mouse.Mode == 2) player.ActiveInventory = itmp; else itmp.RunInteraction(mouse.Mode); } } function repeatedly_execute() { int n; while (n < Nb_Boutons) { int id_gui = FloatToInt(Boutons[n].AsFloat, eRoundDown); if (!gui[id_gui].Visible) { Finv[n].Delete(); Tinv[n].Delete(); Fcache[n].Delete(); } n++; } }×enum InvBtn_ScrollType { eInvBtn_Vertical = 0, eInvBtn_Horizontal = 1 }; import function AsInv(this Button*, Character* personnage, String propriete, InvBtn_ScrollType scroll_type = eInvBtn_Vertical); import function ScrollUp(this Button*); import function ScrollDown(this Button*); import function ScrollLeft(this Button*); import function ScrollRight(this Button*); import InventoryItem* GetInvBtnAt(int x, int y); import function InvBtnFree();8£Üej÷´