Skip to content
This repository has been archived by the owner on Dec 18, 2017. It is now read-only.

Commit

Permalink
Reimplemented the cityview!
Browse files Browse the repository at this point in the history
I essentially gutted the last implementation and rewrote it from the
ground up. This implementation is more stateful and can tolerate much more
abuse. This implementation also resolves issues #10 and #19, along with
providing a fix for the Civ VI bug requiring the city ranged strike
button to be pressed twice. Yay for bugfixes!
  • Loading branch information
chaorace committed Oct 30, 2016
1 parent d0c21a9 commit 9f3433e
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 118 deletions.
230 changes: 116 additions & 114 deletions UI/Panels/CityPanel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ include( "Civ6Common" ); -- GetYieldString()
include( "Colors" );
include( "InstanceManager" );
include( "SupportFunctions" ); -- Round(), Clamp(), DarkenLightenColor()
include( "ToolTipHelper" );
include( "ToolTipHelper" );

-- ===========================================================================
-- DEBUG
Expand Down Expand Up @@ -60,6 +60,117 @@ local m_primaryColor :number = 0xcafef00d;
local m_secondaryColor :number = 0xf00d1ace;
local m_kTutorialDisabledControls :table = nil;

-- ====================CQUI Cityview==========================================

local CQUI_cityview = false;
local CQUI_usingStrikeButton = false;

function CQUI_CityviewEnableManager()
if(not CQUI_cityview) then
LuaEvents.CQUI_ProductionPanel_CityviewEnable();
LuaEvents.CQUI_CityPanel_CityviewEnable();
LuaEvents.CQUI_CityPanelOverview_CityviewEnable();
CQUI_cityview = true;
end
end

function CQUI_CityviewDisableManager()
if(CQUI_cityview) then
LuaEvents.CQUI_ProductionPanel_CityviewDisable();
LuaEvents.CQUI_CityPanel_CityviewDisable();
LuaEvents.CQUI_CityPanelOverview_CityviewDisable();
CQUI_cityview = false;
end
end

function CQUI_OnCityviewEnabled()
ContextPtr:SetHide(false);
Controls.CityPanelAlpha:SetToBeginning();
Controls.CityPanelAlpha:Play();
Controls.CityPanelSlide:SetToBeginning();
Controls.CityPanelSlide:Play();
Refresh();
UILens.ToggleLayerOn(LensLayers.PURCHASE_PLOT);
UILens.ToggleLayerOn(LensLayers.CITIZEN_MANAGEMENT);
UI.SetFixedTiltMode(true);
UI.SetInterfaceMode(InterfaceModeTypes.CITY_MANAGEMENT);
end

function CQUI_OnCityviewDisabled()
Close();
UI.DeselectAllCities();
UILens.ToggleLayerOff(LensLayers.PURCHASE_PLOT);
UILens.ToggleLayerOff(LensLayers.CITIZEN_MANAGEMENT);
UI.SetFixedTiltMode(false);
UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
end

function CQUI_WonderMode()
Close();
UILens.ToggleLayerOff(LensLayers.PURCHASE_PLOT);
UILens.ToggleLayerOff(LensLayers.CITIZEN_MANAGEMENT);
UI.SetFixedTiltMode(false);
end

LuaEvents.CQUI_CityPanel_CityviewEnable.Add( CQUI_OnCityviewEnabled);
LuaEvents.CQUI_CityPanel_CityviewDisable.Add( CQUI_OnCityviewDisabled);
LuaEvents.CQUI_CityviewDisable.Add( CQUI_CityviewDisableManager);
LuaEvents.CQUI_CityviewEnable.Add( CQUI_CityviewEnableManager);
LuaEvents.CQUI_Strike_Enter.Add (function() CQUI_usingStrikeButton = true; end)
LuaEvents.CQUI_Strike_Exit.Add (function() CQUI_usingStrikeButton = false; end)

function CQUI_OnInterfaceModeChanged( eOldMode:number, eNewMode:number )
if(eOldMode == InterfaceModeTypes.CITY_MANAGEMENT or eOldMode == InterfaceModeTypes.DISTRICT_PLACEMENT or eOldMode == InterfaceModeTypes.BUILDING_PLACEMENT) then
if(eNewMode == InterfaceModeTypes.DISTRICT_PLACEMENT or eNewMode == InterfaceModeTypes.BUILDING_PLACEMENT) then
CQUI_WonderMode();
else
LuaEvents.CQUI_CityviewDisable();
end
elseif(eOldMode == InterfaceModeTypes.CITY_RANGE_ATTACK) then
UI.DeselectAllCities()
end
end

function CQUI_OnCitySelectionChanged( ownerPlayerID:number, cityID:number, i:number, j:number, k:number, isSelected:boolean, isEditable:boolean)
if (ownerPlayerID == Game.GetLocalPlayer()) then
if (isSelected) then
-- Determine if should switch to cityview mode
local shouldSwitchToCityview:boolean = true;
if UI.GetInterfaceMode() == InterfaceModeTypes.ICBM_STRIKE then
-- During ICBM_STRIKE only switch to cityview if we're selecting a city
-- which doesn't own the active missile silo
local siloPlotX:number = UI.GetInterfaceModeParameter(CityCommandTypes.PARAM_X0);
local siloPlotY:number = UI.GetInterfaceModeParameter(CityCommandTypes.PARAM_Y0);
local siloPlot:table = Map.GetPlot(siloPlotX, siloPlotY);
if siloPlot then
local owningCity = Cities.GetPlotPurchaseCity(siloPlot);
if owningCity:GetID() == cityID then
shouldSwitchToCityview = false;
end
end
end
if (CQUI_usingStrikeButton) then
shouldSwitchToCityview = false;
end
if shouldSwitchToCityview then
LuaEvents.CQUI_CityviewEnable();
Refresh();
end
end
end
end

function CQUI_OnNextCity()
local kCity:table = UI.GetHeadSelectedCity();
UI.SelectNextCity(kCity);
UI.PlaySound("UI_Click_Sweetener_Metal_Button_Small");
end

function CQUI_OnPreviousCity()
local kCity:table = UI.GetHeadSelectedCity();
UI.SelectPrevCity(kCity);
UI.PlaySound("UI_Click_Sweetener_Metal_Button_Small");
end

-- ===========================================================================
--
Expand Down Expand Up @@ -518,47 +629,6 @@ function OnToggleOverviewPanel()
end
end

function OnCitySelectionChanged( ownerPlayerID:number, cityID:number, i:number, j:number, k:number, isSelected:boolean, isEditable:boolean)
if ownerPlayerID == Game.GetLocalPlayer() then
if (isSelected) then
-- Determine if we should switch to the SELECTION interface mode
local shouldSwitchToSelection:boolean = true;
if UI.GetInterfaceMode() == InterfaceModeTypes.CITY_MANAGEMENT then
shouldSwitchToSelection = false;
end
if UI.GetInterfaceMode() == InterfaceModeTypes.ICBM_STRIKE then
-- During ICBM_STRIKE only switch to SELECTION if we're selecting a city
-- which doesn't own the active missile silo
local siloPlotX:number = UI.GetInterfaceModeParameter(CityCommandTypes.PARAM_X0);
local siloPlotY:number = UI.GetInterfaceModeParameter(CityCommandTypes.PARAM_Y0);
local siloPlot:table = Map.GetPlot(siloPlotX, siloPlotY);
if siloPlot then
local owningCity = Cities.GetPlotPurchaseCity(siloPlot);
if owningCity:GetID() == cityID then
shouldSwitchToSelection = false;
end
end
end
if shouldSwitchToSelection then
UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
end

OnToggleOverviewPanel();
ContextPtr:SetHide(false);
Controls.CityPanelAlpha:SetToBeginning();
Controls.CityPanelAlpha:Play();
Controls.CityPanelSlide:SetToBeginning();
Controls.CityPanelSlide:Play();
Refresh();
else
Close();
UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
-- Tell the CityPanelOverview a city was deselected
LuaEvents.CityPanel_LiveCityDataChanged( nil, false );
end
end
end

-- ===========================================================================
-- GAME Event
-- ===========================================================================
Expand Down Expand Up @@ -700,24 +770,6 @@ function OnResetYieldToNormal( yieldType:number, yieldName:string )
SetYieldIgnore( yieldType ); -- One more ignore to flip it off
end

-- ===========================================================================
-- Cycle to the next city
-- ===========================================================================
function OnNextCity()
local kCity:table = UI.GetHeadSelectedCity();
UI.SelectNextCity(kCity);
UI.PlaySound("UI_Click_Sweetener_Metal_Button_Small");
end

-- ===========================================================================
-- Cycle to the previous city
-- ===========================================================================
function OnPreviousCity()
local kCity:table = UI.GetHeadSelectedCity();
UI.SelectPrevCity(kCity);
UI.PlaySound("UI_Click_Sweetener_Metal_Button_Small");
end

-- ===========================================================================
-- Recenter camera on city
-- ===========================================================================
Expand Down Expand Up @@ -788,18 +840,6 @@ end
-- current state in deciding what is populate in a lens layer.
-- ===========================================================================
function OnToggleManageCitizens()
if Controls.ManageCitizensCheck:IsChecked() then
if not Controls.PurchaseTileCheck:IsChecked() then
UI.SetInterfaceMode(InterfaceModeTypes.CITY_MANAGEMENT); -- Enter mode
end
RecenterCameraOnCity();
UILens.ToggleLayerOn( LensLayers.CITIZEN_MANAGEMENT );
else
if not Controls.PurchaseTileCheck:IsChecked() then
UI.SetInterfaceMode(InterfaceModeTypes.SELECTION); -- Exit mode
end
UILens.ToggleLayerOff( LensLayers.CITIZEN_MANAGEMENT );
end
end

-- ===========================================================================
Expand All @@ -823,44 +863,6 @@ function EnableIfNotTutorialBlocked( controlName:string )
Controls[ controlName ]:SetDisabled( isDisabled );
end

-- ===========================================================================
-- GAME Event
-- eOldMode, mode the engine was formally in
-- eNewMode, new mode the engine has just changed to
-- ===========================================================================
function OnInterfaceModeChanged( eOldMode:number, eNewMode:number )
if eOldMode == InterfaceModeTypes.CITY_MANAGEMENT then
if eNewMode ~= InterfaceModeTypes.DISTRICT_PLACEMENT and eNewMode ~= InterfaceModeTypes.BUILDING_PLACEMENT then
UI.DeselectAllCities();
end
UILens.ToggleLayerOff(LensLayers.PURCHASE_PLOT);
UILens.ToggleLayerOff(LensLayers.CITIZEN_MANAGEMENT);
LuaEvents.CityPanel_ProductionClose();
UI.SetFixedTiltMode( false );
EnableIfNotTutorialBlocked("PurchaseTileCheck");
EnableIfNotTutorialBlocked("ManageCitizensCheck");
EnableIfNotTutorialBlocked("ChangeProductionCheck");
elseif eNewMode == InterfaceModeTypes.CITY_MANAGEMENT then
ContextPtr:SetHide(false);
LuaEvents.CityPanel_ProductionOpen();
LuaEvents.CityPanel_ShowOverviewPanel(true);
UILens.ToggleLayerOn(LensLayers.PURCHASE_PLOT);
UILens.ToggleLayerOn(LensLayers.CITIZEN_MANAGEMENT);
UI.SetFixedTiltMode(true);
end

if eNewMode == InterfaceModeTypes.CITY_RANGE_ATTACK or eNewMode == InterfaceModeTypes.DISTRICT_RANGE_ATTACK then
if ContextPtr:IsHidden()==false then
Close();
end
end

if not ContextPtr:IsHidden() then
ViewMain( m_kData );
end
end


-- ===========================================================================
-- Engine EVENT
-- Local player changed; likely a hotseat game
Expand Down Expand Up @@ -970,8 +972,8 @@ function Initialize()
Controls.GoldIgnore:RegisterCallback( Mouse.eLClick, function() OnResetYieldToNormal( YieldTypes.GOLD, "Gold"); end);
Controls.ProductionIgnore:RegisterCallback( Mouse.eLClick, function() OnResetYieldToNormal( YieldTypes.PRODUCTION, "Production"); end);
Controls.ScienceIgnore:RegisterCallback( Mouse.eLClick, function() OnResetYieldToNormal( YieldTypes.SCIENCE, "Science"); end);
Controls.NextCityButton:RegisterCallback( Mouse.eLClick, OnNextCity);
Controls.PrevCityButton:RegisterCallback( Mouse.eLClick, OnPreviousCity);
Controls.NextCityButton:RegisterCallback( Mouse.eLClick, CQUI_OnNextCity);
Controls.PrevCityButton:RegisterCallback( Mouse.eLClick, CQUI_OnPreviousCity);


Controls.PurchaseTileCheck:RegisterCheckHandler( OnTogglePurchaseTile );
Expand All @@ -989,7 +991,7 @@ function Initialize()

-- Game Core Events
Events.CityAddedToMap.Add( OnCityAddedToMap );
Events.CitySelectionChanged.Add( OnCitySelectionChanged );
Events.CitySelectionChanged.Add( CQUI_OnCitySelectionChanged );
Events.CityFocusChanged.Add( OnCityFocusChange );
Events.CityProductionCompleted.Add( OnCityProductionCompleted );
Events.CityProductionUpdated.Add( OnCityProductionUpdated );
Expand All @@ -998,7 +1000,7 @@ function Initialize()
Events.DistrictDamageChanged.Add( OnCityProductionChanged );
Events.LocalPlayerTurnBegin.Add( OnLocalPlayerTurnBegin );
Events.ImprovementChanged.Add( OnCityProductionChanged );
Events.InterfaceModeChanged.Add( OnInterfaceModeChanged );
Events.InterfaceModeChanged.Add( CQUI_OnInterfaceModeChanged );
Events.LocalPlayerChanged.Add( OnLocalPlayerChanged );
Events.UnitSelectionChanged.Add( OnUnitSelectionChanged );

Expand Down
16 changes: 15 additions & 1 deletion UI/Panels/CityPanelOverview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ local ms_eventID = 0;
local m_tabs;
local m_isShowingPanel :boolean = false;

-- ====================CQUI Cityview==========================================

function CQUI_OnCityviewEnabled()
OnShowOverviewPanel(true)
end

function CQUI_OnCityviewDisabled()
OnShowOverviewPanel(false);
end

LuaEvents.CQUI_CityPanelOverview_CityviewEnable.Add( CQUI_OnCityviewEnabled);
LuaEvents.CQUI_CityPanelOverview_CityviewDisable.Add( CQUI_OnCityviewDisabled);

-- ===========================================================================

function UpdateYieldData( data:table )
data.CulturePerTurn = Round( m_pCity:GetYield( YieldTypes.CULTURE ), 1);
Expand Down Expand Up @@ -813,7 +827,7 @@ function OnClose()
end

function OnCloseButtonClicked()
UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
LuaEvents.CQUI_CityPanel_CityviewDisable();
end

function View(data)
Expand Down
16 changes: 15 additions & 1 deletion UI/Panels/ProductionPanel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ local m_recommendedItems:table;

--local prodAlreadyStarting :boolean = false;

-- ====================CQUI Cityview==========================================

function CQUI_OnCityviewEnabled()
Open();
end

function CQUI_OnCityviewDisabled()
Close();
end

LuaEvents.CQUI_ProductionPanel_CityviewEnable.Add( CQUI_OnCityviewEnabled);
LuaEvents.CQUI_ProductionPanel_CityviewDisable.Add( CQUI_OnCityviewDisabled);
Events.CityMadePurchase.Add( function() Refresh(); end)

-- ===========================================================================
function toint(n)
local s = tostring(n)
Expand Down Expand Up @@ -377,7 +391,7 @@ end
-- ===========================================================================
-- Close via click
function OnClose()
UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
LuaEvents.CQUI_CityPanel_CityviewDisable();
end

-- ===========================================================================
Expand Down
4 changes: 3 additions & 1 deletion UI/WorldView/CityBannerManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ function CityBanner.Initialize( self : CityBanner, playerID: number, cityID : nu
if (bannerStyle == BANNERSTYLE_LOCAL_TEAM) then
if (playerID == Game.GetLocalPlayer()) then
self.m_Instance.CityRangeStrikeButton:RegisterCallback( Mouse.eLClick, OnCityRangeStrikeButtonClick );
self.m_Instance.CityRangeStrikeButton:RegisterCallback( Mouse.eMouseEnter, function() LuaEvents.CQUI_Strike_Enter(); end );
self.m_Instance.CityRangeStrikeButton:RegisterCallback( Mouse.eMouseExit, function() LuaEvents.CQUI_Strike_Exit(); end );
self.m_Instance.CityRangeStrikeButton:SetVoid1(playerID);
self.m_Instance.CityRangeStrikeButton:SetVoid2(cityID);
self.m_Instance.CityProduction:RegisterCallback( Mouse.eLClick, OnProductionClick );
Expand Down Expand Up @@ -1951,8 +1953,8 @@ function OnCityRangeStrikeButtonClick( playerID, cityID )
return;
end;

UI.SelectCity( pCity );
UI.SetInterfaceMode(InterfaceModeTypes.CITY_RANGE_ATTACK);
UI.SelectCity( pCity );
end

-- ===========================================================================
Expand Down
1 change: 0 additions & 1 deletion UI/WorldView/PlotInfo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,6 @@ function OnDistrictAddedToMap( playerID: number, districtID : number, cityID :nu
end

function OnBuildingAddedToMap( plotX:number, plotY:number, buildingType:number, misc1, misc2, misc3 )
UI.DeselectAllCities();
end

-- ===========================================================================
Expand Down

0 comments on commit 9f3433e

Please sign in to comment.