-
Notifications
You must be signed in to change notification settings - Fork 3
Added Team Loadouts to PlayerData #954
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
base: main
Are you sure you want to change the base?
Conversation
Added:
TeamLoadOut (serializable)
-CustomCharacterListObject[] Slots (size 3)
-IsEmpty to help check if a slot has no characters
PlayerData:
-TeamLoadOut[] LoadOuts = { new(), new(), new() } = three saved teams
-int SelectedLoadOut = 0 — current selection (0 = no loadout / “Current”)
-ApplyLoadout(int index) = loads saved team into SelectedCharacterIds
-SaveCurrentTeamToLoadout(int index) = writes SelectedCharacterIds to a slot with value copy (new instances)
-OnCurrentTeamChanged_AutoSave() = when user edits team and a saved slot (1-3) is active, automatically save the position and persist it through Storefront
(Decided to copy the values into a new CustomCharacterListObject when saving a loadout so we don’t share the same reference as SelectedCharacterIds)
-Added fourth loadout button on the left side of the existing ones
|
|
||
| // Copies values from the saved slot to the active team (without sharing references) | ||
| for (int i = 0; i < 3; i++) | ||
| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suorittaisin tuon SelectedCharacterIds tarkistuksen ensin, koska silloin, jos savedMember on tyhjä, ei tarvitse luoda uutta CustomCharacterListObjectia sitä varten ja voi vain lisätä "null ja CharacterID.None" SetDataan suoraan.
Mutta toimii tämä näinkin.
| /// </summary> | ||
| public void ApplyLoadout(int index) | ||
| { | ||
| if (index < 0 || index > 3) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pistäisin Debug.LogError viestin, että yritettiin käyttää virheellistä indexiä.
Lisäksi voit käyttää LoadOutin pituutta, sen sijaan että kovakoodataan kolmonen.
| /// </summary> | ||
| public void SaveCurrentTeamToLoadout(int index) | ||
| { | ||
| if (index <= 0 || index > 3) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pistäisin Debug.LogError viestin, että yritettiin käyttää virheellistä indexiä.
Lisäksi voit käyttää LoadOutin pituutta, sen sijaan että kovakoodataan kolmonen.
Voit myös tehdä tästä oman metodinsa.
| { | ||
| if (index <= 0 || index > 3) return; | ||
|
|
||
| if (LoadOuts[index - 1] == null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huom. mikäli indexiä ei ole varattu arrayssä, tämä heittää OutOfIndex virheen.
Tällä ei pitäisi olla väliä, kunhan vain arrayn pituus on jo määritetty.
| }; | ||
|
|
||
| [Serializable] | ||
| public class TeamLoadOut |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suosittelen siirtämään tämän omaan skriptiinsä, ettei se turhaan kuluta tilaa tästä. Ja muutenkin suosittelen lisäämään lisäluokat skriptin loppuun, ei alkuun.
| bool slotIsEmpty = | ||
| (slot == null) || | ||
| (slot.CharacterID == CharacterID.None && | ||
| (slot.ServerID == null || slot.ServerID.Length == 0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ServerIDn arvoa ei tarvitse tarkistaa jos CharacterID on None, koska sillä ei pitäisi edes olla arvoa silloin.
| { | ||
| if (Slots == null) return true; | ||
|
|
||
| for (int index = 0; index < Slots.Length; index++) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eikös tämän voisi korvata foreach loopilla?
-Moved TeamLoadOut-class to its own script -Changed hardcoded values to use LoadOuts.Length -Added Debug.LogError messages on invalid loadout index in ApplyLoadout and SaveCurrentTeamToLoadout -Removed the ServerID check
…er and LoadOutController -Awake() Gets the ModelController component and subscribes to the OnPlayerDataReady event to receive playerdata once its loaded -Start() Binds each loadout button in the list to the OnPressLoadout method. When button is clicked, it passes its corresponding index to handle loadout selection or saving -HaldePlayerDataReady() This is called when playerdata becomes available, it stores the reference to the loaded player and updates the button states -OnPressLoadout() Handles what happens when a loadout button is pressed, also updates button states and saves the playerdata afterward -RefreshButtons() Updates the button interactability based on which loadout is currently active, and the active loadout button is disabled to indicate selection In ModelController.cs i added: -Event to notify LoadOutController when playerdata has been successfully loaded -Public readonly property to expose the current PlayerData instance -OnPlayerDataReady?.Invoke(_playerData) that invokes the OnPlayerDataReady event once the player data has finished loading
| _loadoutButtons[i].onClick.AddListener(() => OnPressLoadout(loadoutIndex)); | ||
| } | ||
| } | ||
| //Pitäisikö tähän lisätä OnDestroy-metodi? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ei taida tarvita, koska toi event bindaus menee poikki muutenkin, kun skriptit poistetaan. Normaalisti tämä on ongelma, jos eventit ovat staattisia, koska silloin ne eventit eivät korjaa poistu, jotenka ne bindaukset pitää poistaa erikseen. Toisaalta, jos haluat varmistaa että se bindaus poistuu niin sit voit lisätä sen sinne.
| private void Awake() | ||
| { | ||
| if (_modelController == null) | ||
| _modelController = GetComponent<ModelController>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kannattaa ottaa huomioon, että mitäs jos ModelController ei olekaan samassa objektissa kiinni.
Tämän voisi periaatteessa ratkaista sillä että sen voi tarjota koodille editorin puolelta SerializeFieldin avulla tai sitten esim. lisätä RequireComponent vaatimuksen luokalle, jolloin tätä skriptiä ei voi lisätä ellei ModelControlleria ei ole (ja se taitaa lisätä sen automaattisesti).
Henk. koht. suosin ehkä ensimmäistä vaihtoehtoa.
|
|
||
| private void OnPressLoadout(int loadoutIndex) | ||
| { | ||
| if (_player == null) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jos pelaajan tietoja ei löydy niin voisi kokeilla hakea ne Datastoresta.
Lisäksi kannattaa miettiä että onko mahdollista, että aikaisemmin haetut pelaajan tiedot eivät olekaan ajan tasalla? Kannattaisiko sen takia muutenkin hakea varmuuden vuoksi tiedot uudestaan?
| Storefront.Get().SavePlayerData(_player, null); | ||
| } | ||
|
|
||
| private void RefreshButtons() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Voisiko tuon PlayerDatan antaa tälle metodin attribuuttina, koska jokainen paikalla, josta tätä kutsutaan on kumminkin PlayerData käsissään. Lisäksi lisää tarkistuksen että jos se syystä tai toisesta onkin null, ettei peli kaadu sen takia.
…o OnPressLoadout, add Storefront fallback fetch - Exposed ModelController to the scene via SerializeField so it can be assigned from the editor - Changed OnPressLoadout to accept PlayerData as a parameter and added a null check - If PlayerData is not available, added a fallback fetch from Storefront in LoadOutController to ensure the latest player info is retrieved before applying a loadout.
- Moved new PlayerData.cs methods to the end of the file for clarity - Added a confirmation popup that asks whether to save the current loadout to the current slot before switching - Hooked up a new popup window that opens from the “0” button - Implemented a LoadoutPopup UI with three character slots and a save button (just UI, not working yet)
…disabled autosave - Implemented new SelectedCharacters slots in the LoadoutPopup window - Updated and refined the LoadoutPopup UI layout for better usability - Disabled the autosave functionality as it's not needed right now
…rovements etc. - Added a confirmation popup (LoadoutSaveConfirmPopup) that appears before saving a loadout - Hooked up all “save” buttons to open the confirmation popup instead of saving immediately - Added logic in LoadoutRowController to track the active loadout row and handle confirmed saves - Added clickable dark-blue row backgrounds to allow selecting a saved loadout directly - Hooked up background buttons to call OnRowBackgroundClicked and update the active loadout selection - Added LoadoutEditorOpener helper for opening the edit panel through SignalBus - Improved (or at least tried) slot button initialization and error handling in LoadoutRowController
- Added new LoadoutButtons prefab and a LoadoutButtons Variant prefab for the two loadout layouts - Added “Popup Loadout” and “Inline Loadout” buttons to the tab ribbon to switch between layouts - Implemented a small LoadoutModeSwitcher script that toggles visibility between the default loadout buttons and the variant based on the selected mode
… automatic button resizing -Implemented the new Loadout 2 variant where players can add additional loadout slots by pressing the plus button in the UI -Added method AddNewLoadoutSlot() to LoadOutController, which creates a new loadout button, inserts it before the plus button, and wires up the correct click logic -ScrollView currently displays 4 loadouts plus the add (“+”) button Added new script InlineLoadoutButtonSizer.cs that: -Automatically calculates the correct button size based on the viewport width, layout padding, and spacing -Ensures that a fixed number of loadout buttons fit visibly in the horizontal ScrollView -Resizes both width and height of each button to maintain a consistent square layout Also did some general UI adjustments and button refresh logic improvements to support dynamically created loadouts and added mode switch highlighting for Popup/Inline loadout buttons, making the selected mode button appear dark (disabled state), matching the style of the loadout buttons
… and fixed inline button issue - Added functionality so the first three loadouts shown on the popup loadout main page are now also displayed correctly in popup rows 1–3 - Added automatic hiding of the "+" button in the inline loadout view when the maximum number of loadouts has been created - Fixed an issue where inline loadout buttons had oversized raycast areas, causing clicks to select the button to the right instead of the intended one
…up interaction - Hidden the inline loadout “+” button once the 8th loadout becomes visible - Extracted copy button into its own prefab - Inline and popup loadouts now share the same unified 8-slot list - Added SwipeBlocker to the popup loadout window - Updated popup loadout: rename “Save” button to “Change” and connect it to open the character selection view
… EditingPopup & ModelController - Added support for opening the character editing popup from a specific loadout - Modified EditingPopup to track whether it was opened via loadout editing - Added new signal handling so character changes update the correct loadout instead of only SelectedCharacterIds - Implemented HandleLoadoutCharacterChanged in ModelController to write changes directly into the chosen loadout - Synced logic so that when the edited loadout is the currently selected one, SelectedCharacterIds and server data are also updated - Ensured automatic saving occurs for the correct loadout when editing is closed
Added:
TeamLoadOut (serializable)
PlayerData:
(Decided to copy the values into a new CustomCharacterListObject when saving a loadout so we don’t share the same reference as SelectedCharacterIds)