示例#1
0
    def on_level_up(self):
        super().on_level_up()
        # determines if some tracks require level which was just hit
        CONFIG_DB_CURSOR.execute(
            'SELECT track_number FROM track_config WHERE level = ? AND map_id = ?',
            (self.level, self.map_id))
        tracks_parsed = [t[0] for t in CONFIG_DB_CURSOR.fetchall()]
        # adjusts "unlock_from_level" condition for all tracks
        for track in tracks_parsed:
            CONSTRUCTION_STATE_MATRIX[
                self.map_id][TRACKS][track][UNLOCK_CONDITION_FROM_LEVEL] = TRUE
            # if all three conditions are met, track is available for construction
            self.on_check_track_unlock_conditions(track)
            self.view.on_update_construction_state(TRACKS, track)

        # same for environment
        CONFIG_DB_CURSOR.execute(
            'SELECT tier FROM environment_config WHERE level = ? AND map_id = ?',
            (self.level, self.map_id))
        tiers_parsed = [t[0] for t in CONFIG_DB_CURSOR.fetchall()]
        for tier in tiers_parsed:
            CONSTRUCTION_STATE_MATRIX[self.map_id][ENVIRONMENT][tier][
                UNLOCK_CONDITION_FROM_LEVEL] = TRUE
            self.on_check_environment_unlock_conditions(tier)
            self.view.on_update_construction_state(ENVIRONMENT, tier)
示例#2
0
    def create_signals(self):
        signals = {}
        signals_list = []
        CONFIG_DB_CURSOR.execute('''SELECT DISTINCT track FROM signal_config WHERE map_id = ?''', (PASSENGER_MAP,))
        for i in CONFIG_DB_CURSOR.fetchall():
            signals[i[0]] = {}

        CONFIG_DB_CURSOR.execute('''SELECT track, base_route FROM signal_config WHERE map_id = ?''', (PASSENGER_MAP,))
        for i in CONFIG_DB_CURSOR.fetchall():
            signals[i[0]][i[1]] = PassengerMapSignalController(self, *i)
            signals_list.append(signals[i[0]][i[1]])

        return signals, signals_list
示例#3
0
def _create_window():
    CONFIG_DB_CURSOR.execute(
        'SELECT app_width, app_height FROM screen_resolution_config')
    screen_resolution_config = CONFIG_DB_CURSOR.fetchall()
    monitor_resolution_config = (windll.user32.GetSystemMetrics(0),
                                 windll.user32.GetSystemMetrics(1))
    USER_DB_CURSOR.execute('SELECT fullscreen FROM graphics')
    if USER_DB_CURSOR.fetchone(
    )[0] and monitor_resolution_config in screen_resolution_config:
        window = Window(width=monitor_resolution_config[0],
                        height=monitor_resolution_config[1],
                        caption='Railway Station Simulator',
                        style='borderless',
                        fullscreen=False,
                        vsync=False)
        window.set_fullscreen(True)
        return window

    USER_DB_CURSOR.execute('SELECT app_width, app_height FROM graphics')
    screen_resolution = USER_DB_CURSOR.fetchone()
    return Window(width=screen_resolution[0],
                  height=screen_resolution[1],
                  caption='Railway Station Simulator',
                  style='borderless',
                  fullscreen=False,
                  vsync=False)
示例#4
0
 def get_crossovers_to_unlock_with_environment(self, tier):
     CONFIG_DB_CURSOR.execute(
         '''SELECT track_param_1, track_param_2, crossover_type FROM crossovers_config 
         WHERE track_unlocked_with <= ? AND environment_unlocked_with = ? AND map_id = ?''',
         (self.unlocked_tracks, tier, self.map_id)
     )
     return CONFIG_DB_CURSOR.fetchall()
示例#5
0
 def get_signals_to_unlock_with_environment(self, tier):
     CONFIG_DB_CURSOR.execute(
         '''SELECT track, base_route FROM signal_config 
         WHERE track_unlocked_with <= ? AND environment_unlocked_with = ? AND map_id = ?''',
         (self.unlocked_tracks, tier, self.map_id)
     )
     return CONFIG_DB_CURSOR.fetchall()
示例#6
0
 def get_switches_to_unlock_with_track(self, track):
     CONFIG_DB_CURSOR.execute(
         '''SELECT track_param_1, track_param_2, switch_type FROM switches_config 
         WHERE track_unlocked_with = ? AND environment_unlocked_with <= ? AND map_id = ?''',
         (track, self.unlocked_environment, self.map_id)
     )
     return CONFIG_DB_CURSOR.fetchall()
    def create_train_routes(self):
        train_routes = {}
        train_routes_sorted_list = []
        CONFIG_DB_CURSOR.execute(
            '''SELECT DISTINCT track FROM train_route_config WHERE map_id = ?''',
            (FREIGHT_MAP, ))
        for i in CONFIG_DB_CURSOR.fetchall():
            train_routes[i[0]] = {}

        CONFIG_DB_CURSOR.execute(
            '''SELECT track, train_route FROM train_route_config WHERE map_id = ?''',
            (FREIGHT_MAP, ))
        for i in CONFIG_DB_CURSOR.fetchall():
            train_routes[i[0]][i[1]] = FreightTrainRouteController(self, *i)
            train_routes_sorted_list.append(train_routes[i[0]][i[1]])

        return train_routes, train_routes_sorted_list
示例#8
0
 def __init__(self, controller, view):
     super().__init__(controller, view, logger=getLogger('root.app.model'))
     USER_DB_CURSOR.execute('SELECT fullscreen FROM graphics')
     self.fullscreen_mode = USER_DB_CURSOR.fetchone()[0]
     CONFIG_DB_CURSOR.execute('SELECT app_width, app_height FROM screen_resolution_config')
     self.screen_resolution_config = CONFIG_DB_CURSOR.fetchall()
     if (monitor_resolution_config := (windll.user32.GetSystemMetrics(0), windll.user32.GetSystemMetrics(1))) \
             in self.screen_resolution_config:
         self.fullscreen_mode_available = True
         self.fullscreen_resolution = monitor_resolution_config
示例#9
0
 def __init__(self, controller, view, map_id):
     super().__init__(controller, view, map_id, logger=getLogger(f'root.app.game.map.{map_id}.dispatcher.model'))
     self.trains = []
     USER_DB_CURSOR.execute('''SELECT unlocked_tracks FROM map_progress WHERE map_id = ?''', (self.map_id, ))
     self.unlocked_tracks = USER_DB_CURSOR.fetchone()[0]
     USER_DB_CURSOR.execute('SELECT busy FROM tracks WHERE map_id = ?', (self.map_id, ))
     self.track_busy_status = [TRUE, *[t[0] for t in USER_DB_CURSOR.fetchall()]]
     CONFIG_DB_CURSOR.execute(
         '''SELECT supported_cars_min, supported_cars_max FROM track_config WHERE map_id = ?''', (self.map_id, )
     )
     self.supported_cars_by_track = ((0, 20), *CONFIG_DB_CURSOR.fetchall())
示例#10
0
 def __init__(self, controller, view, map_id, track_param_1, track_param_2,
              switch_type):
     super().__init__(
         controller,
         view,
         map_id,
         logger=getLogger(
             f'root.app.game.map.{map_id}.railroad_switch.{track_param_1}.{track_param_2}.{switch_type}.model'
         ))
     self.track_param_1 = track_param_1
     self.track_param_2 = track_param_2
     self.switch_type = switch_type
     USER_DB_CURSOR.execute(
         '''SELECT busy, force_busy FROM switches 
         WHERE track_param_1 = ? AND track_param_2 = ? AND switch_type = ? AND map_id = ?''',
         (self.track_param_1, self.track_param_2, self.switch_type,
          self.map_id))
     self.busy, self.force_busy = USER_DB_CURSOR.fetchone()
     USER_DB_CURSOR.execute(
         '''SELECT last_entered_by, current_position FROM switches 
         WHERE track_param_1 = ? AND track_param_2 = ? AND switch_type = ? AND map_id = ?''',
         (self.track_param_1, self.track_param_2, self.switch_type,
          self.map_id))
     self.last_entered_by, self.current_position = USER_DB_CURSOR.fetchone()
     CONFIG_DB_CURSOR.execute(
         '''SELECT track, train_route, section_number FROM train_route_sections
         WHERE track_param_1 = ? AND track_param_2 = ? AND section_type = ? AND map_id = ?''',
         (self.track_param_1, self.track_param_2, self.switch_type,
          self.map_id))
     self.state_change_listeners = CONFIG_DB_CURSOR.fetchall()
     USER_DB_CURSOR.execute(
         '''SELECT locked FROM switches 
         WHERE track_param_1 = ? AND track_param_2 = ? AND switch_type = ? AND map_id = ?''',
         (self.track_param_1, self.track_param_2, self.switch_type,
          self.map_id))
     self.locked = USER_DB_CURSOR.fetchone()[0]
示例#11
0
 def __init__(self, controller, view, map_id, track_param_1, track_param_2,
              crossover_type):
     super().__init__(
         controller,
         view,
         map_id,
         logger=getLogger(
             f'root.app.game.map.{map_id}.crossover.{track_param_1}.{track_param_2}.{crossover_type}.model'
         ))
     self.track_param_1 = track_param_1
     self.track_param_2 = track_param_2
     self.crossover_type = crossover_type
     self.busy = {track_param_1: {}, track_param_2: {}}
     self.force_busy = {track_param_1: {}, track_param_2: {}}
     self.last_entered_by = {track_param_1: {}, track_param_2: {}}
     self.state_change_listeners = {track_param_1: {}, track_param_2: {}}
     USER_DB_CURSOR.execute(
         '''SELECT busy_1_1, busy_1_2, busy_2_1, busy_2_2, force_busy_1_1, force_busy_1_2, 
         force_busy_2_1, force_busy_2_2 FROM crossovers 
         WHERE track_param_1 = ? AND track_param_2 = ? AND crossover_type = ? AND map_id = ?''',
         (self.track_param_1, self.track_param_2, self.crossover_type,
          self.map_id))
     self.busy[self.track_param_1][self.track_param_1], self.busy[self.track_param_1][self.track_param_2], \
         self.busy[self.track_param_2][self.track_param_1], self.busy[self.track_param_2][self.track_param_2], \
         self.force_busy[self.track_param_1][self.track_param_1], \
         self.force_busy[self.track_param_1][self.track_param_2], \
         self.force_busy[self.track_param_2][self.track_param_1], \
         self.force_busy[self.track_param_2][self.track_param_2] = USER_DB_CURSOR.fetchone()
     USER_DB_CURSOR.execute(
         '''SELECT last_entered_by_1_1, last_entered_by_1_2, last_entered_by_2_1, last_entered_by_2_2, 
         current_position_1, current_position_2 FROM crossovers 
         WHERE track_param_1 = ? AND track_param_2 = ? AND crossover_type = ? AND map_id = ?''',
         (self.track_param_1, self.track_param_2, self.crossover_type,
          self.map_id))
     self.last_entered_by[self.track_param_1][self.track_param_1], \
         self.last_entered_by[self.track_param_1][self.track_param_2], \
         self.last_entered_by[self.track_param_2][self.track_param_1], \
         self.last_entered_by[self.track_param_2][self.track_param_2], \
         self.current_position_1, self.current_position_2 = USER_DB_CURSOR.fetchone()
     CONFIG_DB_CURSOR.execute(
         '''SELECT track, train_route, section_number FROM train_route_sections
         WHERE track_param_1 = ? AND track_param_2 = ? AND section_type = ?
         AND position_1 = ? AND position_2 = ? AND map_id = ?''',
         (self.track_param_1, self.track_param_2, self.crossover_type,
          self.track_param_1, self.track_param_1, self.map_id))
     self.state_change_listeners[self.track_param_1][
         self.track_param_1] = CONFIG_DB_CURSOR.fetchall()
     CONFIG_DB_CURSOR.execute(
         '''SELECT track, train_route, section_number FROM train_route_sections
         WHERE track_param_1 = ? AND track_param_2 = ? AND section_type = ?
         AND position_1 = ? AND position_2 = ? AND map_id = ?''',
         (self.track_param_1, self.track_param_2, self.crossover_type,
          self.track_param_1, self.track_param_2, self.map_id))
     self.state_change_listeners[self.track_param_1][
         self.track_param_2] = CONFIG_DB_CURSOR.fetchall()
     CONFIG_DB_CURSOR.execute(
         '''SELECT track, train_route, section_number FROM train_route_sections
         WHERE track_param_1 = ? AND track_param_2 = ? AND section_type = ?
         AND position_1 = ? AND position_2 = ? AND map_id = ?''',
         (self.track_param_1, self.track_param_2, self.crossover_type,
          self.track_param_2, self.track_param_1, self.map_id))
     self.state_change_listeners[self.track_param_2][
         self.track_param_1] = CONFIG_DB_CURSOR.fetchall()
     CONFIG_DB_CURSOR.execute(
         '''SELECT track, train_route, section_number FROM train_route_sections
         WHERE track_param_1 = ? AND track_param_2 = ? AND section_type = ?
         AND position_1 = ? AND position_2 = ? AND map_id = ?''',
         (self.track_param_1, self.track_param_2, self.crossover_type,
          self.track_param_2, self.track_param_2, self.map_id))
     self.state_change_listeners[self.track_param_2][
         self.track_param_2] = CONFIG_DB_CURSOR.fetchall()
     USER_DB_CURSOR.execute(
         '''SELECT locked FROM crossovers 
         WHERE track_param_1 = ? AND track_param_2 = ? AND crossover_type = ? AND map_id = ?''',
         (self.track_param_1, self.track_param_2, self.crossover_type,
          self.map_id))
     self.locked = USER_DB_CURSOR.fetchone()[0]
示例#12
0
    def __init__(self, controller):
        def on_accept_changes(button):
            self.controller.parent_controller.on_accept_changes(
                self.temp_windowed_resolution, self.temp_display_fps,
                self.temp_fade_animations_enabled, self.temp_clock_24h_enabled,
                self.temp_level_up_notification_enabled, self.temp_feature_unlocked_notification_enabled,
                self.temp_construction_completed_notification_enabled, self.temp_enough_money_notification_enabled,
                self.temp_bonus_expired_notification_enabled, self.temp_shop_storage_notification_enabled,
                self.temp_voice_not_found_notification_enabled,
                self.temp_master_volume, self.temp_announcements_enabled
            )
            self.controller.on_save_and_commit_state()
            self.controller.parent_controller.on_close_settings()

        def on_reject_changes(button):
            self.controller.parent_controller.on_close_settings()

        def on_update_windowed_resolution_state(index):
            self.on_change_temp_windowed_resolution(self.available_windowed_resolutions[index])

        def on_update_display_fps_state(new_state):
            self.temp_display_fps = new_state

        def on_update_fade_animations_state(new_state):
            self.temp_fade_animations_enabled = new_state

        def on_update_clock_24h_state(new_state):
            self.temp_clock_24h_enabled = new_state

        def on_update_level_up_notifications_state(new_state):
            self.temp_level_up_notification_enabled = new_state

        def on_update_feature_unlocked_notifications_state(new_state):
            self.temp_feature_unlocked_notification_enabled = new_state

        def on_update_construction_completed_notifications_state(new_state):
            self.temp_construction_completed_notification_enabled = new_state

        def on_update_enough_money_notifications_state(new_state):
            self.temp_enough_money_notification_enabled = new_state

        def on_update_bonus_expired_notifications_state(new_state):
            self.temp_bonus_expired_notification_enabled = new_state

        def on_update_shop_storage_notifications_state(new_state):
            self.temp_shop_storage_notification_enabled = new_state

        def on_update_voice_not_found_notifications_state(new_state):
            self.temp_voice_not_found_notification_enabled = new_state

        def on_update_master_volume(master_volume):
            self.temp_master_volume = master_volume

        def on_update_announcements_state(new_state):
            self.temp_announcements_enabled = new_state

        super().__init__(controller, logger=getLogger('root.app.settings.view'))
        self.temp_windowed_resolution = (0, 0)
        self.temp_display_fps = FALSE
        self.temp_fade_animations_enabled = FALSE
        self.temp_clock_24h_enabled = FALSE
        self.temp_master_volume = 0
        self.temp_announcements_enabled = TRUE
        self.display_fps_checkbox = DisplayFPSCheckbox(
            column=-1, row=2, on_update_state_action=on_update_display_fps_state, parent_viewport=self.viewport
        )
        self.fade_animations_checkbox = FadeAnimationsEnabledCheckbox(
            column=-1, row=0, on_update_state_action=on_update_fade_animations_state, parent_viewport=self.viewport
        )
        self.clock_24h_checkbox = Clock24HCheckbox(
            column=-1, row=-2, on_update_state_action=on_update_clock_24h_state, parent_viewport=self.viewport
        )
        self.master_volume_knob = MasterVolumeSettingsKnob(
            column=-1, row=-5, on_update_state_action=on_update_master_volume, parent_viewport=self.viewport
        )
        self.announcements_checkbox = AnnouncementsEnabledCheckbox(
            column=-1, row=-8, on_update_state_action=on_update_announcements_state, parent_viewport=self.viewport
        )
        self.temp_level_up_notification_enabled = FALSE
        self.temp_feature_unlocked_notification_enabled = FALSE
        self.temp_construction_completed_notification_enabled = FALSE
        self.temp_enough_money_notification_enabled = FALSE
        self.temp_bonus_expired_notification_enabled = FALSE
        self.temp_shop_storage_notification_enabled = FALSE
        self.temp_voice_not_found_notification_enabled = FALSE
        self.game_progress_notifications_checkbox_group = GameProgressNotificationsCheckboxGroup(
            column=1, row=9, on_update_state_actions=[
                on_update_level_up_notifications_state,
                on_update_feature_unlocked_notifications_state,
                on_update_construction_completed_notifications_state,
                on_update_enough_money_notifications_state,
                on_update_bonus_expired_notifications_state,
                on_update_shop_storage_notifications_state
            ], parent_viewport=self.viewport
        )
        self.malfunction_notifications_checkbox_group = MalfunctionNotificationsCheckboxGroup(
            column=1, row=-7, on_update_state_actions=[
                on_update_voice_not_found_notifications_state
            ], parent_viewport=self.viewport
        )
        CONFIG_DB_CURSOR.execute(
            '''SELECT app_width, app_height FROM screen_resolution_config WHERE manual_setup = 1 AND app_width <= ?''',
            (windll.user32.GetSystemMetrics(0),)
        )
        self.available_windowed_resolutions = CONFIG_DB_CURSOR.fetchall()
        self.available_windowed_resolutions_position = 0
        self.screen_resolution_control = ScreenResolutionControl(
            column=-1, row=8, possible_values_list=self.available_windowed_resolutions,
            on_update_state_action=on_update_windowed_resolution_state, parent_viewport=self.viewport
        )
        self.accept_settings_button = AcceptSettingsButton(
            on_click_action=on_accept_changes, parent_viewport=self.viewport
        )
        self.reject_settings_button = RejectSettingsButton(
            on_click_action=on_reject_changes, parent_viewport=self.viewport
        )
        self.buttons = [
            self.accept_settings_button, self.reject_settings_button,
            *self.screen_resolution_control.buttons, *self.display_fps_checkbox.buttons,
            *self.fade_animations_checkbox.buttons, *self.clock_24h_checkbox.buttons,
            *self.game_progress_notifications_checkbox_group.buttons,
            *self.malfunction_notifications_checkbox_group.buttons,
            *self.announcements_checkbox.buttons
        ]
        self.shader_sprite = SettingsViewShaderSprite(view=self)
        self.on_mouse_motion_handlers.extend(self.master_volume_knob.on_mouse_motion_handlers)
        self.on_mouse_press_handlers.extend(self.master_volume_knob.on_mouse_press_handlers)
        self.on_mouse_release_handlers.extend(self.master_volume_knob.on_mouse_release_handlers)
        self.on_mouse_drag_handlers.extend(self.master_volume_knob.on_mouse_drag_handlers)
        self.on_window_resize_handlers.extend(
            [
                *self.display_fps_checkbox.on_window_resize_handlers,
                *self.fade_animations_checkbox.on_window_resize_handlers,
                *self.clock_24h_checkbox.on_window_resize_handlers,
                *self.game_progress_notifications_checkbox_group.on_window_resize_handlers,
                *self.malfunction_notifications_checkbox_group.on_window_resize_handlers,
                *self.screen_resolution_control.on_window_resize_handlers,
                *self.master_volume_knob.on_window_resize_handlers,
                *self.announcements_checkbox.on_window_resize_handlers,
                self.shader_sprite.on_window_resize
            ]
        )
        self.on_append_window_handlers()
示例#13
0
            '''SELECT start_point_v2, stop_point_v2, destination_point_v2, checkpoints_v2 FROM train_route_config 
            WHERE track = ? AND train_route = ? AND map_id = ?''',
            (self.track, self.train_route, self.map_id))
        for i in range(len(fetched_data := list(CONFIG_DB_CURSOR.fetchone()))):
            if fetched_data[i] is not None:
                fetched_data[i] = tuple(
                    int(p) for p in fetched_data[i].split(','))

        self.start_point_v2, self.stop_point_v2, self.destination_point_v2, self.checkpoints_v2 = fetched_data
        self.trail_points_v2 = TrailPointsV2(self.map_id, self.track,
                                             self.train_route)
        CONFIG_DB_CURSOR.execute(
            '''SELECT section_type, track_param_1, track_param_2 FROM train_route_sections 
            WHERE track = ? and train_route = ? AND map_id = ?''',
            (self.track, self.train_route, self.map_id))
        self.train_route_sections = CONFIG_DB_CURSOR.fetchall()
        self.signal_base_route, self.signal_track = None, None
        if len(self.train_route_sections) > 1:
            self.signal_base_route, self.signal_track = self.train_route_sections[
                0][:2]

        CONFIG_DB_CURSOR.execute(
            '''SELECT position_1, position_2 FROM train_route_sections 
            WHERE track = ? and train_route = ? AND map_id = ?''',
            (self.track, self.train_route, self.map_id))
        self.train_route_section_positions = CONFIG_DB_CURSOR.fetchall()

    @final
    def on_save_state(self):
        USER_DB_CURSOR.execute(
            '''UPDATE train_routes SET opened = ?, last_opened_by = ?, current_checkpoint = ?, priority = ?, cars = ?, 
示例#14
0
 def get_shops_to_unlock_with_track(self, track):
     CONFIG_DB_CURSOR.execute(
         '''SELECT shop_id FROM shops_config WHERE map_id = ? AND track_required = ?''', (self.map_id, track)
     )
     return CONFIG_DB_CURSOR.fetchall()
示例#15
0
    def __init__(self, controller):
        def on_close_game(button):
            WINDOW.dispatch_event('on_close')

        def on_iconify_game(button):
            WINDOW.minimize()

        def on_app_window_fullscreen(button):
            button.paired_button.opacity = button.opacity
            button.on_deactivate(instant=True)
            button.paired_button.on_activate()
            self.controller.on_fullscreen_button_click()

        def on_app_window_restore(button):
            button.paired_button.opacity = button.opacity
            button.on_deactivate(instant=True)
            button.paired_button.on_activate()
            self.controller.on_restore_button_click()

        def on_set_en_locale(button):
            self.controller.on_update_current_locale(ENGLISH)
            self.controller.on_update_clock_state(clock_24h_enabled=False)

        def on_set_ru_locale(button):
            self.controller.on_update_current_locale(RUSSIAN)
            self.controller.on_update_clock_state(clock_24h_enabled=True)

        super().__init__(controller, logger=getLogger('root.app.view'))
        self.shader_sprite = AppViewShaderSprite(view=self)
        self.title_label = AppTitleLabel(parent_viewport=self.viewport)
        self.fps_display = FPSDisplay(parent_viewport=self.viewport)
        self.us_flag_sprite = USFlagSprite(parent_viewport=self.viewport)
        self.ru_flag_sprite = RUFlagSprite(parent_viewport=self.viewport)
        self.close_game_button = CloseGameButton(on_click_action=on_close_game,
                                                 parent_viewport=self.viewport)
        self.iconify_button = IconifyButton(on_click_action=on_iconify_game,
                                            parent_viewport=self.viewport)
        self.fullscreen_button, self.restore_button = create_two_state_button(
            FullscreenButton(on_click_action=on_app_window_fullscreen,
                             parent_viewport=self.viewport),
            RestoreButton(on_click_action=on_app_window_restore,
                          parent_viewport=self.viewport))
        self.en_locale_button = ENLocaleButton(
            on_click_action=on_set_en_locale, parent_viewport=self.viewport)
        self.ru_locale_button = RULocaleButton(
            on_click_action=on_set_ru_locale, parent_viewport=self.viewport)
        self.buttons = [
            self.close_game_button, self.iconify_button,
            self.fullscreen_button, self.restore_button, self.en_locale_button,
            self.ru_locale_button
        ]
        self.on_window_resize_handlers.extend([
            *self.fps_display.on_window_resize_handlers,
            self.title_label.on_window_resize,
            self.shader_sprite.on_window_resize,
            self.us_flag_sprite.on_window_resize,
            self.ru_flag_sprite.on_window_resize
        ])
        self.on_append_window_handlers()
        self.app_window_move_mode = False
        self.app_window_move_offset = (0, 0)
        self.game_window_handler = GetActiveWindow()
        self.game_window_position = GetWindowRect(self.game_window_handler)
        self.absolute_mouse_pos = GetCursorPos()
        self.on_mouse_press_handlers.append(self.on_mouse_press)
        self.on_mouse_release_handlers.append(self.on_mouse_release)
        self.on_mouse_drag_handlers.append(self.on_mouse_drag)
        USER_DB_CURSOR.execute('SELECT fullscreen FROM graphics')
        self.fullscreen_mode = USER_DB_CURSOR.fetchone()[0]
        self.fullscreen_mode_available = False
        CONFIG_DB_CURSOR.execute(
            'SELECT app_width, app_height FROM screen_resolution_config')
        self.screen_resolution_config = CONFIG_DB_CURSOR.fetchall()
        if (windll.user32.GetSystemMetrics(0),
                windll.user32.GetSystemMetrics(1)
            ) in self.screen_resolution_config:
            self.fullscreen_mode_available = True
示例#16
0
    def __init__(self, controller, map_id):
        def on_leave_action():
            self.on_map_move_mode_available()

        def on_hover_action():
            self.on_map_move_mode_unavailable()

        def on_open_schedule(button):
            button.on_deactivate(instant=True)
            button.state = 'normal'
            self.controller.on_open_schedule()

        def on_open_constructor(button):
            button.on_deactivate(instant=True)
            button.state = 'normal'
            self.controller.on_open_constructor()

        def on_open_shop_details(button):
            self.controller.on_open_shop_details(
                self.shop_buttons.index(button))

        super().__init__(controller,
                         map_id,
                         logger=getLogger(f'root.app.game.map.{map_id}.view'))
        USER_DB_CURSOR.execute(
            '''SELECT unlocked_tracks FROM map_progress WHERE map_id = ?''',
            (self.map_id, ))
        self.unlocked_tracks = USER_DB_CURSOR.fetchone()[0]
        self.mini_map_offset = (0, 0)
        self.main_map_sprite = MainMapSprite(map_id=self.map_id,
                                             parent_viewport=self.viewport)
        self.environment_sprite = MainEnvironmentSprite(
            map_id=self.map_id, parent_viewport=self.viewport)
        self.mini_map_timer = 0.0
        USER_DB_CURSOR.execute(
            '''SELECT last_known_base_offset FROM map_position_settings WHERE map_id = ?''',
            (self.map_id, ))
        self.base_offset = tuple(
            int(p) for p in USER_DB_CURSOR.fetchone()[0].split(','))
        USER_DB_CURSOR.execute(
            '''SELECT last_known_zoom FROM map_position_settings WHERE map_id = ?''',
            (self.map_id, ))
        self.zoom = USER_DB_CURSOR.fetchone()[0]
        self.base_offset_lower_left_limit = (0, 0)
        self.base_offset_upper_right_limit = (0, 0)
        self.open_schedule_button = OpenScheduleButton(
            on_click_action=on_open_schedule, parent_viewport=self.viewport)
        self.open_constructor_button = OpenConstructorButton(
            on_click_action=on_open_constructor, parent_viewport=self.viewport)
        self.buttons = [
            self.open_schedule_button, self.open_constructor_button
        ]
        self.shader_sprite = MapViewShaderSprite(view=self)
        self.on_window_resize_handlers.append(
            self.shader_sprite.on_window_resize)
        self.on_append_window_handlers()
        self.shop_buttons = []
        CONFIG_DB_CURSOR.execute(
            '''SELECT COUNT(*) FROM shops_config WHERE map_id = ?''',
            (self.map_id, ))
        for shop_id in range(CONFIG_DB_CURSOR.fetchone()[0]):
            self.shop_buttons.append(
                OpenShopDetailsButton(map_id=self.map_id,
                                      shop_id=shop_id,
                                      on_click_action=on_open_shop_details,
                                      on_hover_action=on_hover_action,
                                      on_leave_action=on_leave_action))

        CONFIG_DB_CURSOR.execute(
            '''SELECT track_required FROM shops_config WHERE map_id = ?''',
            (self.map_id, ))
        self.shops_track_required_state = tuple(
            s[0] for s in CONFIG_DB_CURSOR.fetchall())
        self.buttons.extend(self.shop_buttons)
        for b in self.shop_buttons:
            b.position = b.get_position()
            b.on_change_scale()

        self.map_move_mode_available = False
        self.map_move_mode = False
        self.on_mouse_press_handlers.append(self.on_mouse_press)
        self.on_mouse_release_handlers.append(self.on_mouse_release)
        self.on_mouse_drag_handlers.append(self.on_mouse_drag)
        self.on_mouse_scroll_handlers.append(self.on_mouse_scroll)
        USER_DB_CURSOR.execute(
            '''SELECT SUM(t.constructions_locked) FROM (
                    SELECT COUNT(track_number) AS constructions_locked FROM tracks 
                    WHERE locked = 1 AND map_id = ?
                    UNION
                    SELECT COUNT(tier) AS constructions_locked FROM environment 
                    WHERE locked = 1 AND map_id = ?
            ) AS t''', (self.map_id, self.map_id))
        self.constructions_locked = USER_DB_CURSOR.fetchone()[0]
        self.is_mini_map_timer_activated = False