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

Fixes in the City View: Update Tiles, Make Tile Purchase better #330

Merged
merged 1 commit into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions Assets/UI/WorldView/plotinfo_CQUI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ BASE_CQUI_OnDistrictAddedToMap = OnDistrictAddedToMap;
BASE_CQUI_AggregateLensHexes = AggregateLensHexes;
BASE_CQUI_RealizeTilt = RealizeTilt;
BASE_CQUI_Initialize = Initialize;
BASE_CQUI_OnClickCitizen = OnClickCitizen;

-- ===========================================================================
-- CQUI Members
Expand All @@ -22,7 +23,7 @@ local CQUI_WorkIconAlpha = .60;
local CQUI_SmartWorkIcon: boolean = true;
local CQUI_SmartWorkIconSize: number = 64;
local CQUI_SmartWorkIconAlpha = .45;
local CQUI_DragStarted = false;
local CQUI_DragThresholdExceeded = false;
local CITY_CENTER_DISTRICT_INDEX = GameInfo.Districts["DISTRICT_CITY_CENTER"].Index;

function CQUI_OnSettingsUpdate()
Expand Down Expand Up @@ -54,6 +55,7 @@ function CQUI_UpdateCloseCitiesCitizensWhenCityFounded(playerID, cityID)
end
end

-- ===========================================================================
--Takes a table with duplicates and returns a new table without duplicates. Credit to vogomatix at stask exchange for the code
function CQUI_RemoveDuplicates(i:table)
local hash = {};
Expand All @@ -67,8 +69,22 @@ function CQUI_RemoveDuplicates(i:table)
return o;
end

function CQUI_StartDragMap()
CQUI_DragStarted = true;
-- ===========================================================================
function CQUI_DragThresholdExceeded()
CQUI_DragThresholdExceeded = true;
end

-- ===========================================================================
-- CQUI modified OnClickCitizen function
-- Force the tiles in the city view to update when a citizen icon is clicked
-- ===========================================================================
function OnClickCitizen( plotId:number )
local pSelectedCity :table = UI.GetHeadSelectedCity();
if pSelectedCity ~= nil then
LuaEvents.CQUI_RefreshCitizenManagement(pSelectedCity:GetID());
end

BASE_CQUI_OnClickCitizen(plotId);
end

-- ===========================================================================
Expand All @@ -93,14 +109,13 @@ end
-- Update the city data
-- ===========================================================================
function OnClickPurchasePlot( plotId:number )
-- CQUI (Azurency) : if we're dragging, don't purchase
if CQUI_DragStarted then
CQUI_DragStarted = false;
return;
-- CQUI: If we're dragging and we exceeded the threshold for how far we could move the mouse while dragging, do not purchase
if CQUI_DragThresholdExceeded then
CQUI_DragThresholdExceeded = false;
return false;
end

local result = BASE_CQUI_OnClickPurchasePlot(plotId);

OnClickCitizen(); -- CQUI : update selected city citizens and data

return result;
Expand Down Expand Up @@ -199,7 +214,7 @@ function Initialize_PlotInfo_CQUI()

LuaEvents.CQUI_SettingsUpdate.Add(CQUI_OnSettingsUpdate);
LuaEvents.CQUI_SettingsInitialized.Add(CQUI_OnSettingsUpdate);
LuaEvents.CQUI_StartDragMap.Add(CQUI_StartDragMap);
LuaEvents.CQUI_DragThresholdExceeded.Add(CQUI_DragThresholdExceeded);
LuaEvents.CQUI_RefreshPurchasePlots.Add(RefreshPurchasePlots);
end
Initialize_PlotInfo_CQUI();
48 changes: 41 additions & 7 deletions Assets/UI/worldinput_CQUI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ include("CQUICommon.lua");
-- ===========================================================================
-- Cached Base Functions
-- ===========================================================================
BASE_CQUI_StartDragMap = StartDragMap;
BASE_CQUI_EndDragMap = EndDragMap;
BASE_CQUI_UpdateDragMap = UpdateDragMap;
BASE_CQUI_OnUnitSelectionChanged = OnUnitSelectionChanged;
BASE_CQUI_DefaultKeyDownHandler = DefaultKeyDownHandler;
Expand All @@ -18,12 +20,17 @@ BASE_CQUI_LateInitialize = LateInitialize;
local CQUI_HOTKEYMODE_CLASSIC = 1;
local CQUI_HOTKEYMODE_STANDARD = 0;

local CQUI_cityview :boolean = false;
local CQUI_hotkeyMode :number = CQUI_HOTKEYMODE_CLASSIC;
local CQUI_isShiftDown :boolean = false;
local CQUI_isAltDown :boolean = false;
local CQUI_cityview :boolean = false;
local CQUI_hotkeyMode :number = CQUI_HOTKEYMODE_CLASSIC;
local CQUI_isShiftDown :boolean = false;
local CQUI_isAltDown :boolean = false;
local CQUI_ActiveLensSaved :boolean = false;

local CQUI_dragStartX :number = 0;
local CQUI_dragStartY :number = 0;
local CQUI_dragThreshold :number = 0.025;
local CQUI_dragThresholdExceeded :boolean = false;

local CQUI_keyMaps :table = {};

function CQUI_OnSettingsUpdate()
Expand Down Expand Up @@ -58,14 +65,41 @@ function OnUserRequestClose()
BASE_CQUI_OnUserRequestClose();
end

-- ===========================================================================
function StartDragMap()
CQUI_dragThresholdExceeded = false;
-- Get the position of the mouse when the Dragging of the map starts
CQUI_dragStartX, CQUI_dragStartY = UIManager:GetNormalizedMousePos();

BASE_CQUI_StartDragMap();
end

-- ===========================================================================
function EndDragMap(resetSpin:boolean)
-- This function is called if nothing handled the release of the mouse button
CQUI_dragThresholdExceeded = false;
BASE_CQUI_EndDragMap(resetSpin);
end

-- ===========================================================================
function UpdateDragMap()
if g_isMouseDragging then
-- Event sets a global in PlotInfo so tiles are not purchased while dragging
LuaEvents.CQUI_StartDragMap();
if (CQUI_dragThresholdExceeded == false) then
-- if the threshold has not yet been exceeded then get the current position and see if it has
-- once the mouse is moved far enough away from the original drag point, the threshold is considered exceeded
-- this covers the scenario where the drag starts while on the purchase tile button, moves far off, then moves back to original position
-- in that scenario it would not be desired to do the purchase tile
local dragStartX:number, dragStartY:number = UIManager:GetNormalizedMousePos();
if (math.abs(CQUI_dragStartX - dragStartX) > CQUI_dragThreshold)
or (math.abs(CQUI_dragStartY - dragStartY) > CQUI_dragThreshold) then
CQUI_dragThresholdExceeded = true;
-- Fire the event to set the value in PlotInfo
LuaEvents.CQUI_DragThresholdExceeded();
end
end
end

return BASE_CQUI_UpdateDragMap();
BASE_CQUI_UpdateDragMap();
end

-- ===========================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,26 @@ function ShowCitizenManagementLens(cityID:number)
end

-- ===========================================================================
function ClearCitizenManagementLens()
function ClearCitizenManagementLens(clearBorder:boolean)
if UILens.IsLayerOn(ML_LENS_LAYER) then
UILens.ToggleLayerOff(ML_LENS_LAYER);
end

LuaEvents.MinimapPanel_SetActiveModLens("NONE");

local pOverlay:object = UILens.GetOverlay("CityBorders");
pOverlay:ClearPlotChannel();
pOverlay:SetVisible(false);
if (clearBorder == nil or clearBorder == true) then
local pOverlay:object = UILens.GetOverlay("CityBorders");
pOverlay:ClearPlotChannel();
pOverlay:SetVisible(false);
end

m_cityID = -1;
end

-- ===========================================================================
function RefreshCitizenManagementLens(cityID:number)
ClearCitizenManagementLens();
-- Do not redraw the border for the city, just refresh the tiles
ClearCitizenManagementLens(false);
ShowCitizenManagementLens(cityID);
end

Expand Down