auto create & edit choice
This commit is contained in:
parent
723723dea1
commit
9f676f6b9d
6 changed files with 166 additions and 59 deletions
|
|
@ -10,14 +10,14 @@ from warchron.view.view import PlayerDialog, WarDialog, CampaignDialog, Objectiv
|
|||
|
||||
class Controller:
|
||||
def __init__(self, model: Model, view: View):
|
||||
self.model = model
|
||||
self.view = view
|
||||
self.model: Model = model
|
||||
self.view: View = view
|
||||
self.current_file: Path | None = None
|
||||
self.selected_war_id = None
|
||||
self.selected_campaign_id = None
|
||||
self.selected_round_id = None
|
||||
self.selected_war_id: str = None
|
||||
self.selected_campaign_id: str = None
|
||||
self.selected_round_id: str = None
|
||||
self.view.on_close_callback = self.on_app_close
|
||||
self.is_dirty = False
|
||||
self.is_dirty: bool = False
|
||||
self.__connect()
|
||||
self.refresh_players_view()
|
||||
self.refresh_wars_view()
|
||||
|
|
@ -165,26 +165,24 @@ class Controller:
|
|||
self.view.display_campaign_participants(participants_for_display)
|
||||
|
||||
def _fill_round_details(self, round_id: str):
|
||||
index = self.model.get_round_index(round_id)
|
||||
self.view.show_round_details(index=index)
|
||||
camp, rnd, participants, sectors = self.model.get_round_choices_data(round_id)
|
||||
rows = []
|
||||
rnd = self.model.get_round(round_id)
|
||||
camp = self.model.get_campaign_by_round(round_id)
|
||||
self.view.show_round_details(index=camp.get_round_index(round_id))
|
||||
participants = self.model.get_round_participants(round_id)
|
||||
choices_for_display = []
|
||||
for part in participants:
|
||||
player = self.model.get_player(part.id)
|
||||
choice = rnd.get_choice(part.id)
|
||||
priority_name = ""
|
||||
secondary_name = ""
|
||||
if choice and choice.priority_sector_id:
|
||||
priority_name = self.model.get_sector(choice.priority_sector_id).name
|
||||
if choice and choice.secondary_sector_id:
|
||||
secondary_name = self.model.get_sector(choice.secondary_sector_id).name
|
||||
rows.append({
|
||||
"participant_id": part.id,
|
||||
"participant_name": player.name,
|
||||
"priority": priority_name,
|
||||
"secondary": secondary_name,
|
||||
})
|
||||
self.view.display_round_choices(rows)
|
||||
if not choice:
|
||||
choice=self.model.create_choice(round_id=rnd.id, participant_id=part.id)
|
||||
priority_name = camp.get_sector_name(choice.priority_sector_id) if choice else ""
|
||||
secondary_name = camp.get_sector_name(choice.secondary_sector_id) if choice else ""
|
||||
choices_for_display.append((
|
||||
self.model.get_player_name(part.id),
|
||||
priority_name,
|
||||
secondary_name,
|
||||
choice.participant_id
|
||||
))
|
||||
self.view.display_round_choices(choices_for_display)
|
||||
|
||||
def on_tree_selection_changed(self, selection):
|
||||
self.selected_war_id = None
|
||||
|
|
@ -578,6 +576,8 @@ class Controller:
|
|||
self.is_dirty = True
|
||||
self.refresh_and_select(RefreshScope.WARS_TREE, item_type=ItemType.ROUND, item_id=rnd.id)
|
||||
|
||||
# Choices methods
|
||||
|
||||
def edit_round_choice(self, choice_id: str):
|
||||
round_id = self.selected_round_id
|
||||
if not round_id:
|
||||
|
|
@ -586,11 +586,13 @@ class Controller:
|
|||
choice = rnd.get_choice(choice_id)
|
||||
if not choice:
|
||||
return
|
||||
participant = camp.participants[choice.participant_id]
|
||||
part = camp.participants[choice.participant_id]
|
||||
player = self.model.get_player(part.id)
|
||||
part_opt = ParticipantOption(id=player.id, name=player.name)
|
||||
dialog = ChoicesDialog(
|
||||
self.view,
|
||||
participants=[participant],
|
||||
default_participant_id=participant.id,
|
||||
participants=[part_opt],
|
||||
default_participant_id=part.id,
|
||||
sectors=sectors,
|
||||
default_priority_id=choice.priority_sector_id,
|
||||
default_secondary_id=choice.secondary_sector_id,
|
||||
|
|
@ -598,7 +600,8 @@ class Controller:
|
|||
if dialog.exec() != QDialog.DialogCode.Accepted:
|
||||
return
|
||||
rnd.set_choice(
|
||||
participant_id=participant.id,
|
||||
participant_id=part.id,
|
||||
priority_sector_id=dialog.get_priority_id(),
|
||||
secondary_sector_id=dialog.get_secondary_id(),
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue