feat/redesign (#1)

Reviewed-on: #1
Co-authored-by: Gonçalo Correia <goncalojoaocorreia@gmail.com>
Co-committed-by: Gonçalo Correia <goncalojoaocorreia@gmail.com>
This commit is contained in:
Gonçalo Correia 2026-05-15 14:53:15 +01:00 committed by rukira
parent 6a44458443
commit 6ebb92c62b
21 changed files with 1395 additions and 273 deletions

0
docs/1-interface.md Normal file → Executable file
View file

0
docs/2-skills.md Normal file → Executable file
View file

0
docs/3-announce.md Normal file → Executable file
View file

78
docs/4-redesign.md Executable file
View file

@ -0,0 +1,78 @@
# Feature: Major Redesign
This redesign of the Addon's window will start by following the following [design](./roll_tab_design.png)
- The window will be a tabbed window
- The 'Use Skills' tab will correspond to the current roll screen
- The 'Build Skills' tab will be a new screen, to be implemented later. For now, leave it empty.
- The 'Log' should record all rolls made by the user, and be displayed in a scrollable list.
- They should be displayed in the same style as the announced rolls, even when the announce option is off
- The log should store a maximum of 100 rolls
## Implementation plan
### 1. Restructure the main window layout (UI.lua)
- Increase `WINDOW_WIDTH` to roughly double (≈660) to accommodate the two-column layout (left panel for tabs, right panel for the log)
- Replace `BasicFrameTemplateWithInset` or layer a new structure inside it:
- **Left column (~50% width):** contains two tabs ("Use Skills", "Build Skills") and their content panels
- **Right column (~50% width):** contains the "Log" header and a scrollable log list
- Keep the title bar ("AltSystem") and close button at the top spanning the full width
### 2. Implement the tab system (UI.lua)
- Create two tab buttons ("Use Skills" and "Build Skills") anchored at the top of the left column
- Use `PanelTemplates_SetNumTabs` / `PanelTemplates_SetTab` or manual highlight toggling to switch active tab styling
- **"Use Skills" tab content:** migrate all existing UI elements (Roll Type radios → Skill dropdown → Armor radios → Modifiers checkboxes → Announce dropdown → Roll button) into this tab's content frame
- Adapt the current layout from `CreateMainFrame` — re-parent all widgets to the tab content frame instead of `f` directly
- **"Build Skills" tab content:** create an empty placeholder frame (can show a "Coming soon" label)
- Toggling tabs shows/hides the corresponding content frame
### 3. Redesign the "Use Skills" tab to match the mockup (UI.lua)
- Replace the current separate Attack/Defense buttons with a **Roll Type** radio-button group ("Attack Roll" / "Defense Roll") that sets `AltSystem.State.rollType`
- Keep the **Skill** dropdown as-is (already matches the mockup)
- Replace the current Defense dropdown with an **Armor** radio-button group ("No Armor" / "Basic Armor (+1)" / "Heavy Armor (+2)")
- Map these to the existing `AltSystem.Data.Defenses` entries; show armor options only when Defense Roll is selected, or always visible per mockup
- Group **Shield** and **Pet** checkboxes under a "Modifiers (optional)" section header with a "Label" sub-header matching the mockup
- Replace the Announce checkbox + channel dropdown with a single **"Announce Roll"** dropdown whose options are "Self Roll" (no announce) plus the existing channel list (Emote, Party, Raid, Guild)
- "Self Roll" maps to `announceEnabled = false`; any other selection maps to `announceEnabled = true` with the corresponding channel index
- Add a single **"Roll $rollType"** button at the bottom (text dynamically reflects "Roll Attack" or "Roll Defense")
- Remove the old roll-result text area from this tab (results now go to the Log panel)
### 4. Build the Log panel (UI.lua)
- Create a right-side panel with a "Log" header label
- Inside, create a `ScrollFrame` (using `UIPanelScrollFrameTemplate` or a manual scroll child) to hold log entries
- Each log entry is a small frame/fontstring displaying the roll result in the same format as the announced message:
- `"[Name] rolled [d20 result] [modifiers] = [total]"` (reuse `BuildModifierString` from Roll.lua)
- Critical rolls show "rolled a Critical Failure!" or "rolled a Critical Success!"
- Entries are listed newest-first (most recent at top) in a vertically stacked layout
### 5. Implement the roll log data store (Core.lua / Roll.lua)
- Add `AltSystem.State.rollLog = {}` — an array of log entry tables, each containing: `{ text = "...", timestamp = time() }`
- In `Roll.lua`, after every roll result is calculated (in `CalculateAndDisplayResult`), build the log message string (same format as announce) and insert it into `AltSystem.State.rollLog`
- Cap the log at **100 entries**: if `#rollLog > 100`, remove the oldest entry (`table.remove(rollLog, 1)`)
- After inserting, call a UI refresh function to update the scroll frame content
- The log is **always populated**, regardless of the announce setting (per the requirement: "displayed in the same style as the announced rolls, even when the announce option is off")
- Log does **not** need to persist across sessions (not mentioned in requirements); keep it in memory only
### 6. Wire up the new Roll button (Roll.lua)
- The single "Roll $rollType" button calls `AltSystem:PerformRoll(state.rollType)` where `state.rollType` is set by the radio-button group ("attack" or "defense")
- Existing `PerformRoll` and `CalculateAndDisplayResult` logic remains largely unchanged; only the final display step changes from setting `ResultText` to appending to the log + refreshing the log UI
### 7. Update state persistence (Core.lua)
- Save/restore `rollType` selection (attack/defense) in `AltSystemDB`
- Update announce state handling to work with the new single-dropdown approach (save selected option index)
- Armor selection (radio group) replaces `selectedDefenseIndex` — reuse same key or migrate
### 8. Update the .toc file if needed (AltSystem.toc)
- No new Lua files are expected (all changes fit in existing files), but verify the load order is still correct
### 9. Testing checklist
- [ ] Window opens at new size, tabs switch correctly
- [ ] "Use Skills" tab shows all controls matching the mockup layout
- [ ] "Build Skills" tab is empty / shows placeholder
- [ ] Attack and Defense rolls work correctly via the new single Roll button
- [ ] Log panel populates with each roll, formatted like announce messages
- [ ] Log scrolls when entries exceed visible area
- [ ] Log caps at 100 entries, oldest removed first
- [ ] Log populates even when announce is set to "Self Roll" (off)
- [ ] Announce still works when a channel is selected
- [ ] State (roll type, armor, announce option) persists across sessions
- [ ] Window is draggable and clamps to screen

132
docs/5-build_skills.md Executable file
View file

@ -0,0 +1,132 @@
# Feature: Build Skills tab
The second tab of the addon will follow these [designs](./build_skills_tab_design.png).
## Acceptance Criteria
- This screen should show the same skills we use in the main screen, which come from the TRP profile
- The skills should be sorted by level
- The skill list should be scrollable, with the "Save" button pinned/sticky to the bottom
## Editing skills
- The user should be able to edit the name, level, and numerical score of each skill
- Edits should not be saved until the user explicitly clicks the "Save" button
### Skill Level and Value
- When a skill level is selected, the numerical score dropdown should update to only allow values within the skill level
- Inept: 0
- Novice: 1-5
- Adept: 6-10
- Expert: 11-19
- Master: 20
### Deleting skills
- Clicking the "Delete" button should remove the skill from the list
### Adding Skills
- Clicking the "Add a Row" button should add a new skill row to the list
- Default values for the new skill should be:
- Name: Skillname
- Level: Novice
- Value: 1
### Saving Skills
- When clicking the "Save" button:
- Newly added skills should be added to the TRP profile
- Existing skills should be updated in the TRP profile
- Skills that were deleted should also be removed from the TRP profile
- Icons should not be changed
## References
- Refer to [Data.lua](../Data.lua) for details on how we currently fetch the skills from TRP
- Refer to the TRP3 source code in case it's necessary [here](https://github.com/Total-RP/Total-RP-3)
---
## Implementation Plan
### 1. Add a `SaveSkills` function to Data.lua
- Create `AltSystem.Data:SaveSkills(editedSkills)` that writes skills back to the TRP3 profile
- Access the TRP3 profile via `TRP3_API.profile.getData("player/characteristics")` to get the `characteristics.PS` (personality traits) array
- For each edited skill, update or insert entries in `PS`:
- `LT` = skill name
- `RT` = level keyword (e.g. "Novice", "Adept", etc.)
- `V2` = numeric value (020)
- `IC` = preserve existing icon (do not change); for new skills, use a sensible default icon (e.g. `"inv_misc_questionmark"`)
- Remove any PS entries that were deleted by the user
- After writing, call `TRP3_API.dashboard.showCharacteristics()` or fire the appropriate TRP3 event if needed to refresh TRP3's own UI
- **Edge case:** If the TRP3 API is unavailable, show a warning message and abort save
### 2. Extract skill-level constants into shared lookup tables in Data.lua
- The acceptance criteria defines value ranges per level (Inept: 0, Novice: 15, Adept: 610, Expert: 1119, Master: 20)
- `SKILL_KEYWORD_RANGES` already exists but excludes Inept/Master min-max correctly for the Build tab's needs; extend or create a new table `AltSystem.Data.SkillValueRanges` that is accessible from UI.lua:
```
{ Inept = {min=0, max=0}, Novice = {min=1, max=5}, Adept = {min=6, max=10}, Expert = {min=11, max=19}, Master = {min=20, max=20} }
```
- Create `AltSystem.Data.SkillLevelOrder` — an ordered array `{"Inept", "Novice", "Adept", "Expert", "Master"}` for populating the level dropdown in display order
- Create a helper `AltSystem.Data:GetDefaultValueForLevel(level)` that returns the minimum value for that level (used when the user changes level to auto-set the value)
### 3. Add a function to read raw skills (with numeric values) from TRP3 in Data.lua
- Currently `RefreshSkills()` converts TRP3 traits into `{name, level, modifier}` — the Build tab needs the raw **numeric value** and the **icon** as well
- Create `AltSystem.Data:GetEditableSkills()` that returns an array of `{name, level, value, icon}` for each valid skill trait in the TRP3 profile (excluding Base Roll and Unskilled, which are system-generated entries)
- Sort the returned skills by level using `AltSystem.Data.SkillLevelOrder` ordering (Inept first, Master last) — matching the acceptance criteria "sorted by level"
- Reuse existing helpers `FindSkillKeyword` and `ParseSkillLevel` (promote them from local to module-level if needed, or call internally)
### 4. Build the Build Skills tab UI (new file: BuildSkillsUI.lua)
- Create a new file to keep UI.lua manageable; register it in `AltSystem.toc` between `UI.lua` and `Roll.lua`
- Create `AltSystem:CreateBuildSkillsContent(parentFrame)` called from `CreateMainFrame` in UI.lua (replacing the placeholder)
- **Layout structure:**
- **Info text** at top — two golden/yellow paragraphs explaining that skills come from TRP (matches mockup)
- **"Skill list" section header**
- **Column headers**: Name, Level, Value (bold golden text)
- **Scrollable skill list** — a `ScrollFrame` containing dynamically created skill rows
- **"Add A Row" button** — anchored below the last skill row, inside the scroll child
- **"Save Skills to TRP" button** — pinned/sticky at the bottom of the tab, outside the scroll frame
### 5. Implement editable skill rows
- Each skill row is a frame containing:
- **Name**: `EditBox` (text input) — pre-filled with current skill name
- **Level**: `DropdownButton` (WowStyle1DropdownTemplate) — options: Inept, Novice, Adept, Expert, Master
- **Value**: `DropdownButton` — options dynamically generated based on selected level (e.g. Novice → 1,2,3,4,5)
- **Delete button**: A button with a trash-can icon/red texture that removes the row
- Store all row data in a local working copy array (`editableSkills`), not directly in `AltSystem.Data.Skills`
- When the **level dropdown** changes:
- Update the value dropdown options to only show valid values for the new level
- Auto-set the value to the minimum for that level (e.g. switching to Adept → value becomes 6)
- **Row management:**
- `CreateSkillRow(parent, index, skillData)` — creates or recycles a row frame
- `RefreshSkillRows()` — rebuilds/repositions all rows and updates scroll child height
- Deleting a row removes it from `editableSkills` and calls `RefreshSkillRows()`
### 6. Implement "Add A Row" functionality
- Clicking "Add A Row" inserts a new entry into `editableSkills`:
- `{ name = "Skillname", level = "Novice", value = 1, icon = "inv_misc_questionmark", isNew = true }`
- Calls `RefreshSkillRows()` to render the new row
- The scroll frame should auto-scroll to show the new row
### 7. Implement "Save Skills to TRP" functionality
- On click, call `AltSystem.Data:SaveSkills(editableSkills)` which:
1. Reads current `characteristics.PS` from TRP3
2. Rebuilds the PS array: keeps non-skill traits untouched, updates/adds/removes skill traits based on `editableSkills`
3. Writes the updated PS back to the TRP3 profile data
4. Calls `RefreshSkills()` so the Use Skills tab dropdown reflects the changes immediately
- Show a confirmation message (print to chat or a brief on-screen text) on successful save
- **Edge cases:**
- Empty skill list: allowed — just remove all skill traits from PS
- Duplicate skill names: allowed (TRP3 doesn't enforce uniqueness)
- Unsaved changes + tab switch: no confirmation dialog required (per spec, changes are just lost)
### 8. Wire up tab switching to populate Build Skills tab
- In `SelectTab(2)` (UI.lua), call `AltSystem:RefreshBuildSkillsList()` to reload skills from TRP3 into the working copy
- This ensures the Build tab always shows the latest TRP3 data when opened, and any unsaved edits are discarded on tab switch
### 9. Update AltSystem.toc
- Add `BuildSkillsUI.lua` to the file list (after `UI.lua`, before `Roll.lua`)
### 10. Testing checklist
- [ ] Build Skills tab shows skills from TRP3 profile, sorted by level
- [ ] Skill name is editable via text input
- [ ] Level dropdown shows all 5 levels; changing level updates value dropdown options and auto-selects minimum value
- [ ] Value dropdown only shows values valid for the current level
- [ ] Delete button removes the row immediately
- [ ] "Add A Row" adds a row with defaults (Skillname, Novice, 1)
- [ ] Skill list scrolls when rows exceed visible area
- [ ] "Save" button is always visible (pinned to bottom)
- [ ] Save writes correct data to TRP3 profile (LT, RT, V2, IC preserved)
- [ ] Save does not modify icons of existing skills
- [ ] After save, Use Skills tab dropdown reflects the updated skills
- [ ] Switching tabs discards unsaved changes and reloads from TRP3
- [ ] Works correctly with 0 skills (empty profile)
- [ ] Works correctly with many skills (20+) — scroll behavior

3
docs/Changelog.md Normal file → Executable file
View file

@ -1,3 +0,0 @@
- Adding default 'Unskilled (-4)' option
- The roll window now remembers all user selections (skill, item, armor type, shield, pet, announce and channel) across sessions
- Fixed an issue where the wrong rolls were displayed when in a large enough group

BIN
docs/build_skills_tab_design.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

BIN
docs/roll_tab_design.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB