Ejemplo n.º 1
0
 private int GetItemIdOfFrame(Frame frame) {
   PixelOffset = (int) LibScroll.GetValue();
   ViewIndex =
       (int) Math.floor((double) PixelOffset / (LIST_ELEMENT_HEIGHT + LIST_ELEMENT_SPACING));
   int id = ViewIndex + ScrollList.indexOf(frame);
   if (CurrentList == 0) {
     return (int) ActiveList.get(id);
   } else if (CurrentList >= 1 && CurrentList <= 4) {
     return (int) ((Item) ActiveList.get(id)).getId();
   }
   return 0;
 }
Ejemplo n.º 2
0
  private void SetFrames() {
    AccountCredit.SetText(String.format("Credit: $%.2f", Driver.CurrentUser.getCredit()));
    Frame current;
    TextLabel rowOne;
    TextLabel rowTwo;
    TextButton commandButton;
    if (LastCurrentListValue != CurrentList) {
      ArrayList temporaryList = null;
      ActiveList.clear();
      if (CurrentList == 0) {
        temporaryList = Driver.CurrentUser.getPurchaseHistory();
      } else if (CurrentList == 1) {
        temporaryList = DataLoader.getAlbums();
      } else if (CurrentList == 2) {
        temporaryList = DataLoader.getAudiobooks();
      } else if (CurrentList == 3) {
        temporaryList = DataLoader.getFilm();
      }
      if (CurrentList >= 1 && CurrentList <= 3) {
        // if the use is looking at a store page, weed out all invisible songs/albums *unless* it is
        // a administrator.
        for (int i = 0; i < temporaryList.size(); i++) {
          if (temporaryList.get(i) instanceof Item
              && (!((Item) temporaryList.get(i)).isVisible()
                  || Driver.CurrentUser.getAdministrator())) {
            ActiveList.add(temporaryList.get(i));
          }
        }
      } else if (CurrentList == 0) {
        for (int i = 0; i < temporaryList.size(); i++) {
          ActiveList.add(temporaryList.get(i));
        }
      } else if (CurrentList == 4) {
        temporaryList = DataLoader.getAlbums();
        for (int i = 0; i < temporaryList.size(); i++) {
          if (temporaryList.get(i) instanceof Item
              && (!((Item) temporaryList.get(i)).isVisible()
                  || Driver.CurrentUser.getAdministrator())) {
            ActiveList.add(temporaryList.get(i));
          }
        }

        temporaryList = DataLoader.getAudiobooks();
        for (int i = 0; i < temporaryList.size(); i++) {
          if (temporaryList.get(i) instanceof Item
              && (!((Item) temporaryList.get(i)).isVisible()
                  || Driver.CurrentUser.getAdministrator())) {
            ActiveList.add(temporaryList.get(i));
          }
        }

        temporaryList = DataLoader.getFilm();
        for (int i = 0; i < temporaryList.size(); i++) {
          if (temporaryList.get(i) instanceof Item
              && (!((Item) temporaryList.get(i)).isVisible()
                  || Driver.CurrentUser.getAdministrator())) {
            ActiveList.add(temporaryList.get(i));
          }
        }
      }
      LastCurrentListValue = CurrentList;
    }
    // this should never happen, but just in case it does, break the function before an error is
    // thrown.
    if (ActiveList == null) {
      return;
    }
    int MaximumIndex = ActiveList.size();
    LibScroll.SetMax(
        Math.max(
            0,
            MaximumIndex * (LIST_ELEMENT_HEIGHT + LIST_ELEMENT_SPACING)
                - Driver.GetGuiMain().GetWindow().getHeight()
                + 50));
    PixelOffset = (int) LibScroll.GetValue();
    ViewIndex =
        (int) Math.floor((double) PixelOffset / (LIST_ELEMENT_HEIGHT + LIST_ELEMENT_SPACING));
    for (int i = 0; i < ScrollList.size(); i++) {
      // Position the frame appropriately.
      current = ScrollList.get(i);
      current.GetPosition().yOffset =
          i * (LIST_ELEMENT_HEIGHT + LIST_ELEMENT_SPACING)
              - PixelOffset % (LIST_ELEMENT_HEIGHT + LIST_ELEMENT_SPACING);
      rowOne = (TextLabel) current.GetChild("TopText");
      rowTwo = (TextLabel) current.GetChild("BottomText");
      commandButton = (TextButton) current.GetChild("Action");

      // If the index we're looking for is out of bounds, don't display the frame.
      if (i + ViewIndex >= MaximumIndex) {
        CenterScrollFrame.RemoveChild(current);
      } else {
        CenterScrollFrame.AddChild(current);
        // Fill the text labels with content based on what view option is selected.
        if (CurrentList == 0) {
          if (!current.GetChild("Action2").GetVisible() && !Driver.CurrentUser.getAdministrator()) {
            current.GetChild("Divider").GetPosition().xOffset = -99;
            current.GetChild("TopText").GetSize().xOffset = -105;
            current.GetChild("BottomText").SetSize(current.GetChild("TopText").GetSize());
            current.GetChild("Action2").SetVisible(true);
            ((TextButton) current.GetChild("Action2")).SetText("Rate");
            Driver.GetGuiMain().GetTextBoxes();
          }
          Item currentItem =
              DataLoader.getItemById(((Integer) ActiveList.get(i + ViewIndex)).intValue());
          SetListText(rowOne, rowTwo, currentItem);
          if (CurrentPlayingItem == currentItem) {
            commandButton.SetText("Stop");
          } else {
            commandButton.SetText("Play");
          }
        } else if (CurrentList >= 1 && CurrentList <= 4) {
          if (current.GetChild("Action2").GetVisible() && !Driver.CurrentUser.getAdministrator()) {
            current.GetChild("Divider").GetPosition().xOffset = -52;
            current.GetChild("TopText").GetSize().xOffset = -58;
            current.GetChild("BottomText").SetSize(current.GetChild("TopText").GetSize());
            current.GetChild("Action2").SetVisible(false);
          }
          Item currentItem = (Item) ActiveList.get(i + ViewIndex);
          SetListText(rowOne, rowTwo, currentItem);
          if (currentItem.isVisible()) {
            rowTwo.SetText(rowTwo.GetText() + "; HIDDEN");
          }
          if (Driver.CurrentUser.getPurchaseHistory().contains(currentItem.getId())) {
            if (CurrentPlayingItem == currentItem) {
              commandButton.SetText("Stop");
            } else {
              commandButton.SetText("Play");
            }
          } else {
            commandButton.SetText("Buy");
          }
        }
      }
    }
  }