tweaks to how the gang ui is loaded, making it more like stock market

This commit is contained in:
Olivier Gagnon 2021-06-17 18:29:43 -04:00
parent 94ea0d253c
commit febf0835c2
5 changed files with 39 additions and 39 deletions

@ -1,41 +1,32 @@
import * as React from "react"; import * as React from "react";
import * as ReactDOM from "react-dom"; import * as ReactDOM from "react-dom";
import { createElement } from "../../utils/uiHelpers/createElement";
import { IPlayer } from "../PersonObjects/IPlayer"; import { IPlayer } from "../PersonObjects/IPlayer";
import { IEngine } from "../IEngine"; import { IEngine } from "../IEngine";
import { Root } from "./ui/Root"; import { Root } from "./ui/Root";
import { Gang } from "./Gang"; import { Gang } from "./Gang";
import { Page, routing } from ".././ui/navigationTracking";
let gangContainer: HTMLElement;
(function() {
function set(): void {
const c = document.getElementById("gang-container");
if(c === null) throw new Error("Could not find element 'gang-container'");
gangContainer = c;
document.removeEventListener("DOMContentLoaded", set);
}
document.addEventListener("DOMContentLoaded", set);
})();
// Gang UI Dom Elements
const UIElems: {
gangContentCreated: boolean;
gangContainer: HTMLElement | null;
} = {
gangContentCreated: false,
gangContainer: null,
}
export function displayGangContent(engine: IEngine, gang: Gang, player: IPlayer): void { export function displayGangContent(engine: IEngine, gang: Gang, player: IPlayer): void {
if (!UIElems.gangContentCreated || UIElems.gangContainer == null) { if (!routing.isOn(Page.Gang)) {
UIElems.gangContentCreated = true; return;
// Create gang container
UIElems.gangContainer = createElement("div", {
id:"gang-container", class:"generic-menupage-container",
});
ReactDOM.render(<Root engine={engine} gang={gang} player={player} />, UIElems.gangContainer);
const container = document.getElementById("entire-game-container");
if(!container) throw new Error('entire-game-container was null');
container.appendChild(UIElems.gangContainer);
} }
if(UIElems.gangContainer) UIElems.gangContainer.style.display = "block";
}
export function clearGangUI(): void { ReactDOM.render(<Root
if(UIElems.gangContainer) UIElems.gangContainer.style.display = 'none'; engine={engine}
if (UIElems.gangContainer instanceof Element) ReactDOM.unmountComponentAtNode(UIElems.gangContainer); gang={gang}
UIElems.gangContainer = null; player={player} />, gangContainer);
UIElems.gangContentCreated = false;
} }

@ -40,8 +40,7 @@ export function TaskSelector(props: IProps): React.ReactElement {
className="dropdown" className="dropdown"
value={currentTask}> value={currentTask}>
<option key={0} value={"---"}>---</option> <option key={0} value={"---"}>---</option>
{tasks.map((task: string, i: number) => {tasks.map((task: string, i: number) => <option key={i+1} value={task}>{task}</option>)}
<option key={i+1} value={task}>{task}</option>)}
</select> </select>
<div>{StatsTable(data, null)}</div> <div>{StatsTable(data, null)}</div>
</>); </>);

@ -14,7 +14,6 @@ import { Engine } from "./engine";
import { Faction } from "./Faction/Faction"; import { Faction } from "./Faction/Faction";
import { Factions, initFactions } from "./Faction/Factions"; import { Factions, initFactions } from "./Faction/Factions";
import { joinFaction } from "./Faction/FactionHelpers"; import { joinFaction } from "./Faction/FactionHelpers";
import { clearGangUI } from "./Gang/Helpers";
import { updateHashManagerCapacity } from "./Hacknet/HacknetHelpers"; import { updateHashManagerCapacity } from "./Hacknet/HacknetHelpers";
import { initMessages } from "./Message/MessageHelpers"; import { initMessages } from "./Message/MessageHelpers";
import { prestigeWorkerScripts } from "./NetscriptWorker"; import { prestigeWorkerScripts } from "./NetscriptWorker";

@ -32,7 +32,7 @@ import {
processPassiveFactionRepGain, processPassiveFactionRepGain,
inviteToFaction, inviteToFaction,
} from "./Faction/FactionHelpers"; } from "./Faction/FactionHelpers";
import { displayGangContent, clearGangUI } from "./Gang/Helpers"; import { displayGangContent } from "./Gang/Helpers";
import { displayInfiltrationContent } from "./Infiltration/Helper"; import { displayInfiltrationContent } from "./Infiltration/Helper";
import { import {
getHackingWorkRepGain, getHackingWorkRepGain,
@ -228,6 +228,7 @@ const Engine = {
tutorialContent: null, tutorialContent: null,
infiltrationContent: null, infiltrationContent: null,
stockMarketContent: null, stockMarketContent: null,
gangContent: null,
locationContent: null, locationContent: null,
workInProgressContent: null, workInProgressContent: null,
redPillContent: null, redPillContent: null,
@ -439,9 +440,10 @@ const Engine = {
loadGangContent: function() { loadGangContent: function() {
Engine.hideAllContent(); Engine.hideAllContent();
if (document.getElementById("gang-container") || Player.inGang()) { if (Player.inGang()) {
displayGangContent(this, Player.gang, Player); Engine.Display.gangContent.style.display = "block";
routing.navigateTo(Page.Gang); routing.navigateTo(Page.Gang);
displayGangContent(this, Player.gang, Player);
} else { } else {
Engine.loadTerminalContent(); Engine.loadTerminalContent();
routing.navigateTo(Page.Terminal); routing.navigateTo(Page.Terminal);
@ -525,6 +527,9 @@ const Engine = {
Engine.Display.locationContent.style.display = "none"; Engine.Display.locationContent.style.display = "none";
ReactDOM.unmountComponentAtNode(Engine.Display.locationContent); ReactDOM.unmountComponentAtNode(Engine.Display.locationContent);
Engine.Display.gangContent.style.display = "none";
ReactDOM.unmountComponentAtNode(Engine.Display.gangContent);
Engine.Display.workInProgressContent.style.display = "none"; Engine.Display.workInProgressContent.style.display = "none";
Engine.Display.redPillContent.style.display = "none"; Engine.Display.redPillContent.style.display = "none";
Engine.Display.cinematicTextContent.style.display = "none"; Engine.Display.cinematicTextContent.style.display = "none";
@ -534,9 +539,6 @@ const Engine = {
document.getElementById("gang-container").style.display = "none"; document.getElementById("gang-container").style.display = "none";
} }
if (Player.inGang()) {
clearGangUI();
}
if (Player.corporation instanceof Corporation) { if (Player.corporation instanceof Corporation) {
Player.corporation.clearUI(); Player.corporation.clearUI();
} }
@ -570,6 +572,7 @@ const Engine = {
MainMenuLinks.Travel.classList.remove("active"); MainMenuLinks.Travel.classList.remove("active");
MainMenuLinks.Job.classList.remove("active"); MainMenuLinks.Job.classList.remove("active");
MainMenuLinks.StockMarket.classList.remove("active"); MainMenuLinks.StockMarket.classList.remove("active");
MainMenuLinks.Gang.classList.remove("active");
MainMenuLinks.Bladeburner.classList.remove("active"); MainMenuLinks.Bladeburner.classList.remove("active");
MainMenuLinks.Corporation.classList.remove("active"); MainMenuLinks.Corporation.classList.remove("active");
MainMenuLinks.Gang.classList.remove("active"); MainMenuLinks.Gang.classList.remove("active");
@ -1321,6 +1324,9 @@ const Engine = {
Engine.Display.stockMarketContent = document.getElementById("stock-market-container"); Engine.Display.stockMarketContent = document.getElementById("stock-market-container");
Engine.Display.stockMarketContent.style.display = "none"; Engine.Display.stockMarketContent.style.display = "none";
Engine.Display.gangContent = document.getElementById("gang-container");
Engine.Display.gangContent.style.display = "none";
Engine.Display.missionContent = document.getElementById("mission-container"); Engine.Display.missionContent = document.getElementById("mission-container");
Engine.Display.missionContent.style.display = "none"; Engine.Display.missionContent.style.display = "none";
@ -1449,6 +1455,7 @@ const Engine = {
MainMenuLinks.Gang.addEventListener("click", function() { MainMenuLinks.Gang.addEventListener("click", function() {
Engine.loadGangContent(); Engine.loadGangContent();
MainMenuLinks.Gang.classList.add('active');
return false; return false;
}); });

@ -284,6 +284,10 @@ if (htmlWebpackPlugin.options.googleAnalytics.trackingId) { %>
<!-- React Component --> <!-- React Component -->
</div> </div>
<div id="gang-container" class="generic-menupage-container">
<!-- React Component -->
</div>
<!-- Log Box --> <!-- Log Box -->
<div id="log-box-container"> <div id="log-box-container">
<div id="log-box-content"> <div id="log-box-content">