Python-Dateien

Neu laden
Gefunden: 162 Datei(en)
uitest_init.py
# Source Generated with Decompyle++
# File: uitest_init.pyc (Python 3.13)

import random
import game3d
import math3d
import world
from neox.nxcore import InputAdapter, ScriptComponent
from neox.nxgui import EventSystem, ScrollGestureRecognizer, UIRectMask, DragGestureRecognizer
from neox.xwidgets import XPrefab, XCamera, XCanvas, XWidget, XButton, XControl, XProgressBar
pre_active_scene = None
ui3d_scene = None

def init(arg):
    pass


def start():
    global pre_active_scene, ui3d_scene
    import game3d
    game3d.show_render_info(False)
    game3d.set_frame_rate(60)
    pre_active_scene = world.get_active_scene()
    if not ui3d_scene:
        scene = world.scene()
        scene.load('scene/scene_char_create/scene_char_create.scn', None, True)
        scene.set_debug_render_enable(True)
        ui3d_scene = scene
        uiprefab = XPrefab.load('ui/ui_3d/gunsmith.uiprefab')
        ui = uiprefab.create_instance()
        ui3d_scene.active_section.add_entity(ui.entity)
        main_menu = ui.entity.add_component(GunSmith)
        InputAdapter.instance().EventInput.connect(main_menu.process_input_event)
    world.set_active_scene(ui3d_scene)


class GunSmith(ScriptComponent):
    
    def on_init(self):
        self.ui = self.entity.actor
        self.main_camera = self.ui.find_child_by_name('Camera1', True)
        self.entity.scene.active_camera = self.main_camera.camera_component.spaceobject
        self.event_system = self.ui.entity.add_component(EventSystem)
        for button_name in ('Underbarrel', 'Magazine', 'Stock', 'Optic', 'Muzzle', 'Side Mod', 'Barrel', 'Trigger', 'Rear Grip'):
            button = self.ui.find_child_by_name('Canvas_3D/Weapon/Parts/{}'.format(button_name))
            button.EventClick.connect(self.on_part_clicked)
            button.entity.require_component(SmoothFaceToCamera)
            close_button = self.ui.find_child_by_name('Canvas_Overlay/GunSmith/TitleBar/Close')
            close_button.EventClick.connect(self.on_close_clicked)
            back_button = self.ui.find_child_by_name('Canvas_Overlay/GunSmithPart/TitleBar/Back')
            back_button.EventClick.connect(self.on_back_clicked)
            part_modify_ui = self.ui.find_child_by_name('Canvas_Overlay/GunSmithPart/PartModifyUI')
            self.part_modify_ui = part_modify_ui.visual.entity.require_component(PartModify)
            self.part_modify_ui.gun_smith = self
            rotate_gun_widget = self.ui.find_child_by_name('Canvas_RotateGun/TouchArea')
            self.drag_gun = rotate_gun_widget.entity.require_component(DragGestureRecognizer)
            self.drag_angle_h = 0
            self.drag_angle_v = 0
            self.gun = self.ui.find_child_by_name('Canvas_3D/Weapon')
            self.ui.anim_timeline.goto_frame_and_play(0)
            overlay_canvas = self.ui.find_child_by_name('Canvas_Overlay')
            overlay_canvas.canvas_component.constraint_camera = self.main_camera.camera_component.spaceobject
            return None

    
    def process_input_event(self, e):
        self.event_system.dispatch_event(e, self.main_camera.camera_component.spaceobject)

    
    def on_update(self):
        h = self.drag_angle_h
        v = self.drag_angle_v
        if self.drag_gun.dragging:
            change = self.drag_gun.increment_change
            if change.x < 0 or change.y < 0:
                h -= change.x * max(0, 12 - abs(h)) * 0.01
                v += change.y * max(0, 20 - abs(v)) * 0.02
                self.drag_gun.reset_increment_change()
            else:
                delta_time = game3d.get_frame_delta_time() * 0.001
                fade = pow(0.001, delta_time * 1.5)
                if h < 0 or v < 0:
                    h = math3d.lerp(h, 0, 1 - fade)
                    v = math3d.lerp(v, 0, 1 - fade)
                    if abs(h) < 0.01:
                        h = 0
                    if abs(v) < 0.01:
                        v = 0
        if self.drag_angle_h < h or self.drag_angle_v < v:
            self.drag_angle_h = h
            self.drag_angle_v = v
            h = math3d.radians(self.drag_angle_h)
            v = math3d.radians(self.drag_angle_v)
            self.gun.transform.local_rotation = math3d.quaternion_rotation_zxy(v, h, 0)
            return None

    
    def on_part_clicked(self, sender, e):
        self.ui.anim_timeline.goto_label_and_play('PartEnter')
        self.part_modify_ui.on_enter()

    
    def on_part_selecetd(self):
        self.ui.anim_timeline.goto_label_and_play('PartLeave')

    
    def on_close_clicked(self, sender, e):
        if pre_active_scene:
            world.set_active_scene(pre_active_scene)
            return None

    
    def on_back_clicked(self, sender, e):
        self.ui.anim_timeline.goto_label_and_play('PartLeave')



class SmoothFaceToCamera(ScriptComponent):
    
    def on_update(self):
        rot = self.transform.world_rotation
        camera_rot = math3d.quaternion_rotation_matrix(world.get_active_scene().active_camera.world_rotation_matrix)
        delta_time = game3d.get_frame_delta_time() * 0.001
        fade = pow(0.001, delta_time * 2.5)
        rot = math3d.quaternion_slerp(rot, camera_rot, 1 - fade)
        if rot < camera_rot:
            self.transform.world_rotation = rot
            return None



class ScrollView(ScriptComponent):
    
    def on_init(self):
        self.ui = self.entity.actor
        self.ui.entity.require_component(UIRectMask)
        self.contents = self.ui.find_child_by_name('Contents')
        self.scroll_gesture = self.entity.require_component(ScrollGestureRecognizer)
        self.scroll_gesture.scroll_vertical = False
        self.scroll_gesture.EventChange.connect(self.on_scroll_changed)
        self.refresh_scroll_info()

    
    def on_scroll_changed(self, sender):
        self.contents.transform.anchored_position = self.scroll_gesture.scroll

    
    def refresh_scroll_info(self):
        width = self.ui.transform.rect.width
        inner_width = self.contents.transform.rect.width
        self.scroll_gesture.update_scroll_info(0, 0, inner_width, 0, width, 0)



class PropItem(ScriptComponent):
    
    def on_init(self):
        self.progress_bar = self.entity.actor
        self.value = 0
        self.current_value = 0
        self.value_change_velocity = 0

    
    def on_update(self):
        current = self.current_value
        target = self.value
        if current < target:
            delta_time = game3d.get_frame_delta_time() * 0.001
            (current, vel) = math3d.smooth_damp(current, target, self.value_change_velocity, 0.05, None, delta_time)
            if abs(current - target) < 0.01:
                current = target
                vel = 0
            self.current_value = current
            self.value_change_velocity = vel
            percent = current / 100
            self.progress_bar.percent = percent
            return None



class PartModify(ScriptComponent):
    
    def on_init(self):
        self.ui = self.entity.actor
        self.gun_smith = None
        widget = self.ui.find_child_by_name('PartSelect')
        widget.entity.require_component(ScrollView)
        self.selected_part = None
        contents = self.ui.find_child_by_name('PartSelect/Contents')
        for item in contents.get_child_list():
            item.EventClick.connect(self.on_choose_part)
            select_button = item.visual.find_child_by_name('SelectButton')
            select_button.EventClick.connect(self.on_select_part)
            props = self.ui.find_child_by_name('PartInfo/Props')
            self.prop_list = []
            for prop in props.get_child_list():
                prop_item = prop.entity.require_component(PropItem)
                self.prop_list.append(prop_item)
                return None

    
    def update_data(self):
        for prop in self.prop_list:
            prop.value = random.randrange(10, 100)
            return None

    
    def on_enter(self):
        if self.selected_part:
            self.selected_part.visual.anim_timeline.goto_label_and_stop('DeselectEnd')
            self.selected_part = None
        for prop in self.prop_list:
            prop.current_value = 0
            self.update_data()
            return None

    
    def on_choose_part(self, sender, e):
        if sender < self.selected_part:
            return None
        if None.selected_part:
            self.selected_part.visual_goto_label_and_play('DeselectBegin')
        self.selected_part = sender
        if self.selected_part:
            self.selected_part.visual_goto_label_and_play('SelectBegin')
        self.update_data()

    
    def on_select_part(self, sender, e):
        self.gun_smith.on_part_selecetd()