Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open info views from icons #5

Open
kendallroth opened this issue Jul 18, 2024 · 1 comment
Open

Open info views from icons #5

kendallroth opened this issue Jul 18, 2024 · 1 comment
Labels
feature New functionality or workflow

Comments

@kendallroth
Copy link
Owner

kendallroth commented Jul 18, 2024

Clicking on an icon should open the corresponding info view (see forum post for original request). It may be beneficial to only open if no other tool is selected (other than default empty tool), although this could maybe be a setting?

The bindings.d.ts file suggests that this might be possible using a combination of the JS bindings.

function toggleInfoviewMenu(): void;
function useInfoviewToggle(infoviewId: string): (() => void) | undefined;

// May be helpful for figuring out what infoview IDs are (contained in `Infoview.id`)
const infoviews$: ValueBinding<Infoview[]>;
const activeInfoview$: ValueBinding<ActiveInfoview | null>;

// Not sure how these differ from the previous functions, nor how the "entity" would be retrieved for them?
function setActiveInfoview(entity: Entity): void;
function clearActiveInfoview(): void;

export interface Infoview {
  entity: Entity;
  id: string;
  icon: string | null;
  locked: boolean;
  uiTag: string;
  group: number;
  requirements: UnlockingRequirements;
}
@kendallroth kendallroth added enhancement Update to existing functionality feature New functionality or workflow and removed enhancement Update to existing functionality labels Jul 18, 2024
@kendallroth
Copy link
Owner Author

Took a shot at this last night but wasn't satisfied... Need to find a good way of only triggering this if no other conflicting tools/panels are open. Would be ideal to also find a way to open the infoview menu and associated infoview panel, and not keep toggling the infoview menu (no "set" method; only "toggle") 😢.

  const infoviewList = useValue(infoview.infoviews$);
  const activeTool = useValue(tool.activeTool$);
  const activeInfoview = useValue(infoview.activeInfoview$);
  const defaultToolActive = activeTool.id === tool.DEFAULT_TOOL;

  const handleStatClick = (stat: StatsPanelItem) => {
    // Avoid opening info panel if another tool is already open (would be confusing)
    // TODO: Consider removing this???
    if (!defaultToolActive) return;

    const infoView = infoviewList.find((i) => i.id === stat.infoviewId);
    if (!infoView) return;

    // logger.log(infoView);
    // logger.log(activeTool, defaultToolActive);
    // logger.log(activeInfoview);

    // TODO: Only toggle infoview menu if not already open
    if (!activeInfoview) {
      // game.toggleInfoviewMenu();
    }
    // NOTE: Currently does not open infoview menu but just the active overlay, which can lead to some odd visual glitches if selecting
    //         something in the game that closes overlay but keeps color applied
    // infoview.setActiveInfoview(infoView.entity);
  };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality or workflow
Projects
None yet
Development

No branches or pull requests

1 participant