def makeGui(self): self.notify.debugStateCall(self) # Check if the timer exists, if so then the gui has been # made. if (hasattr(self, 'cancelButton')): return fishGui = loader.loadModel("phase_4/models/gui/fishingGui") self.cancelButton = DirectGui.DirectButton( relief=None, scale=(0.67), pos=(-0.133, 0.0, 0.13), #pos = (0,0,0), text=("", TTLocalizer.FishingExit, TTLocalizer.FishingExit), text_align=TextNode.ACenter, text_fg=Vec4(1, 1, 1, 1), text_shadow=Vec4(0, 0, 0, 1), text_pos=(0.0, -0.12), textMayChange=0, text_scale=0.1, image=(fishGui.find("**/exit_buttonUp"), fishGui.find("**/exit_buttonDown"), fishGui.find("**/exit_buttonRollover")), text_font=ToontownGlobals.getInterfaceFont(), command=self.d_requestExit, parent=base.a2dBottomRight #pressEffect = False, ) self.cancelButton.hide()
def _callback(texture: core.Texture): if parent_frame.is_empty(): return frame_size = gui.size_inside_square_for_texture(texture, 0.2) if frame_size is None: return tile = DirectGui.DirectButton( parent=parent_frame, frameSize=(0.01, frame_size.x - 0.01, -0.01, -(frame_size.y - 0.01)), frameTexture=texture, relief=DirectGuiGlobals.FLAT, command=self._select_tile, extraArgs=[picnum], ) self._bind_scroll(tile) tile_number = DirectGui.DirectLabel( parent=tile, pos=core.Vec3(0, 0, -constants.TEXT_SIZE), scale=constants.TEXT_SIZE, text=str(picnum), frameColor=(0, 0, 0, 0), text_align=core.TextNode.A_left, text_fg=(1, 1, 1, 0.75), ) self._bind_scroll(tile_number)
def makeGui(self): self.notify.debugStateCall(self) if hasattr(self, 'cancelButton'): return else: fishGui = loader.loadModel('phase_4/models/gui/fishingGui') self.cancelButton = DirectGui.DirectButton( relief=None, scale=0.67, parent=base.a2dBottomRight, pos=(-0.173333, 0, 0.1), text=('', TTLocalizer.FishingExit, TTLocalizer.FishingExit), text_align=TextNode.ACenter, text_fg=Vec4(1, 1, 1, 1), text_shadow=Vec4(0, 0, 0, 1), text_pos=(0.0, -0.12), textMayChange=0, text_scale=0.1, image=(fishGui.find('**/exit_buttonUp'), fishGui.find('**/exit_buttonDown'), fishGui.find('**/exit_buttonRollover')), text_font=ToontownGlobals.getInterfaceFont(), command=self.d_requestExit) self.cancelButton.hide() return
def __init__( self, parent: core.NodePath, tile_manager: manager.Manager, edit_mode: edit_mode.EditMode, task_manager: Task.TaskManager, ): self._dialog = DirectGui.DirectFrame(parent=parent, frameSize=(-1.1, 1.1, -0.9, 0.9)) self._dialog.hide() self._tile_manager = tile_manager self._tile_selected: typing.Optional[typing.Callable[[int], None]] = None DirectGui.DirectButton( parent=self._dialog, text="Ok", scale=0.05, pos=core.Vec3(0.81, -0.85), command=self._confirm, ) DirectGui.DirectButton( parent=self._dialog, text="Cancel", scale=0.05, pos=core.Vec3(0.95, -0.85), command=self._hide, ) self._tiles = tile_view.TileView( self._dialog, (-1.05, 1.05, -0.8, 0.88), self._tile_manager, self._select_tile, ) self._tiles.load_tiles() self._task_manager = task_manager self._edit_mode = edit_mode self._selected_picnum: typing.Optional[int] = None
def _get_tile_frame(self, picnum: int): if picnum not in self._tile_frames: frame = DirectGui.DirectButton( parent=self._canvas, frameSize=(0, 0.2, 0, -0.2), frameColor=(0, 0, 0, 0), relief=DirectGuiGlobals.FLAT, command=self._select_tile, extraArgs=[picnum], ) frame.set_python_tag("picnum", picnum) self._bind_scroll(frame) self._tile_frames[picnum] = frame callback = self._make_tile_callback(frame, picnum) self._tile_manager.get_tile_async(picnum, 0, callback) return self._tile_frames[picnum]
def add_command(self, text: str, command: typing.Optional[typing.Callable[[], None]]): new_button = DirectGui.DirectButton( parent=self._frame, pos=core.Vec3( 0, self._bottom - self._TEXT_SIZE / 2 - constants.PADDING), text=text, text_align=core.TextNode.A_left, scale=self._TEXT_SIZE, command=self._wrapped_command(command), relief=DirectGuiGlobals.FLAT, pressEffect=False, frameColor=(0, 0, 0, 0), ) self._adjust_frame(new_button) new_button.bind(DirectGuiGlobals.ENTER, self._highlight_button, extraArgs=[new_button]) new_button.bind(DirectGuiGlobals.EXIT, self._unhighlight_button, extraArgs=[new_button]) return new_button
def __init__(self, parent: core.NodePath, edit_mode_selector: edit_mode.EditMode): self._edit_mode_selector = edit_mode_selector self._type_selected: typing.Optional[typing.Callable[[str], None]] = None self._frame = DirectGui.DirectFrame( parent=parent, pos=core.Vec3(-0.18, -0.1), frameSize=(0, 0.36, 0, 0.24), relief=DirectGuiGlobals.RAISED, borderWidth=(0.01, 0.01), ) self._frame.hide() self._ror_type_selector = DirectGui.DirectOptionMenu( parent=self._frame, pos=core.Vec3(0.04, 0.14), scale=constants.HUGE_TEXT_SIZE, items=[ ror_constants.ROR_TYPE_LINK, ror_constants.ROR_TYPE_STACK, ror_constants.ROR_TYPE_WATER, ror_constants.ROR_TYPE_GOO, ], ) DirectGui.DirectButton( parent=self._frame, pos=core.Vec3(0.18, 0.05), frameSize=core.Vec4(-0.06, 0.06, -0.02, 0.06) / constants.BIG_TEXT_SIZE, scale=constants.BIG_TEXT_SIZE, text="Ok", command=self._confirm, )
def __init__( self, parent: core.NodePath, edit_mode: edit_mode.EditMode, task_manager: Task.TaskManager, sound_browser: sound_view.SoundView, tile_viewer: tile_dialog.TileDialog, ): self._task_manager = task_manager self._dialog = DirectGui.DirectFrame( parent=parent, pos=core.Vec3(-1.1, -0.9), frameSize=(0, 2.2, 0, 1.8), relief=DirectGuiGlobals.RAISED, borderWidth=(0.01, 0.01), ) self._dialog.hide() self._tile_section = DirectGui.DirectFrame(parent=self._dialog, pos=core.Vec3(0.65, 0.07), frameColor=(0, 0, 0, 0)) current_tile_frame_parent = DirectGui.DirectFrame( parent=self._tile_section, pos=core.Vec3(0, constants.TEXT_SIZE), frameSize=(0, self._TILE_FRAME_SIZE, 0, self._TILE_FRAME_SIZE), frameColor=(0.65, 0.65, 0.65, 1), relief=DirectGuiGlobals.SUNKEN, borderWidth=(0.01, 0.01), ) self._current_tile_frame = DirectGui.DirectButton( pos=core.Vec3(0.01, 0.01), parent=current_tile_frame_parent, frameSize=(0, self._TILE_FRAME_SIZE, self._TILE_FRAME_SIZE, 0), relief=DirectGuiGlobals.FLAT, command=self._show_tiles, ) self._current_tile_frame.set_transparency(True) self._change_tile_button = DirectGui.DirectButton( parent=self._tile_section, scale=constants.TEXT_SIZE, text="Change Tile", text_align=core.TextNode.A_left, command=self._show_tiles, ) self._property_parent: core.NodePath = self._dialog.attach_new_node( "properties") self._property_parent.set_pos(0.66, 0, 0.38) self._sound_browser = sound_browser self._tile_viewer = tile_viewer self._edit_mode = edit_mode self._sprite: typing.Optional[map_objects.EditorSprite] = None self._selected_descriptor: map_objects.sprite_type_descriptor.Descriptor = ( map_objects.sprite_type_descriptor.Descriptor(-1, {})) self._current_descriptor: map_objects.sprite_type_descriptor.Descriptor = ( map_objects.sprite_type_descriptor.Descriptor(-1, {})) self._current_picnum: typing.Optional[int] = None self._current_palette: typing.Optional[int] = None self._current_status_number: typing.Optional[int] = None self._sprite_category_options = DirectGui.DirectOptionMenu( parent=self._dialog, pos=core.Vec3(0.04, 1.72), items=list(descriptors.sprite_category_descriptors.keys()), command=self._select_sprite_category, scale=constants.TEXT_SIZE, text_align=core.TextNode.A_left, ) self._sprite_type_list = sprite_type_list.SpriteTypeList( self._dialog, self._tile_viewer.tile_manager, self._select_sprite_type) self._properties: typing.Optional[ sprite_property_view.SpritePropertyView] = None self._droppables = { descriptor.name: sprite_type for sprite_type, descriptor in descriptors.sprite_types.items() if descriptor.get_is_droppable( descriptors.sprite_category_descriptors) } self._droppables["None"] = 0 DirectGui.DirectLabel( parent=self._dialog, text="Special Source:", pos=core.Vec3(1.74, 0.38), scale=constants.TEXT_SIZE, ) self._special_source_menu = DirectGui.DirectOptionMenu( parent=self._dialog, pos=core.Vec3(1.90, 0.38), items=["None", "Level Start"], scale=constants.TEXT_SIZE, ) DirectGui.DirectLabel( parent=self._dialog, text="Special Target:", pos=core.Vec3(1.74, 0.38 - constants.TEXT_SIZE - 0.02), scale=constants.TEXT_SIZE, ) self._special_target_menu = DirectGui.DirectOptionMenu( parent=self._dialog, pos=core.Vec3(1.90, 0.38 - constants.TEXT_SIZE - 0.02), items=["None", "Secret", "Next Level", "Secret Level"], scale=constants.TEXT_SIZE, ) DirectGui.DirectButton( parent=self._dialog, pos=core.Vec3(1.98, 0.07), text="Ok", scale=constants.TEXT_SIZE, command=self._save_changes, ) DirectGui.DirectButton( parent=self._dialog, pos=core.Vec3(2.1, 0.07), text="Cancel", scale=constants.TEXT_SIZE, command=self._hide, )
def __init__( self, parent: core.NodePath, audio_manager: manager.Manager, task_manager: Task.TaskManager, edit_mode_selector: edit_mode.EditMode, ): path = find_resource("sound_names.yaml") with open(path, "r") as file: self._sound_descriptors = yaml.safe_load(file.read()) self._dialog = DirectGui.DirectFrame( parent=parent, frameSize=(-1.02, 1.02, -0.95, 0.95), frameColor=(0.85, 0.85, 0.85, 1), relief=DirectGuiGlobals.RAISED, borderWidth=(0.01, 0.01), ) self._dialog.hide() self._frame = DirectGui.DirectScrolledFrame( parent=self._dialog, frameColor=(0.65, 0.65, 0.65, 1), frameSize=(-1, 1, -0.8, 0.93), canvasSize=(0, self._CANVAS_WIDTH, -1, 0), scrollBarWidth=0.04, relief=DirectGuiGlobals.SUNKEN, ) self._bind_scroll(self._frame) self._audio_manager = audio_manager self._task_manager = task_manager self._edit_mode_selector = edit_mode_selector self._preview_sound: core.AudioSound = None self._selected_sound_index = -1 self._stop_sound_callback: typing.Callable[[], None] = None self._selected_label: DirectGui.DirectButton = None self._clicked_label: DirectGui.DirectButton = None self._sound_selected: typing.Callable[[int], None] = None self._categorized_sound_names: typing.Dict[str, typing.List[int]] = defaultdict( lambda: [] ) for index, descriptor in self._sound_descriptors.items(): sounds = self._categorized_sound_names[descriptor["category"]] sounds.append(index) self._labels: typing.Dict[int, DirectGui.DirectButton] = {} half_height = self._TEXT_FRAME_SCALE / (2 * constants.TEXT_SIZE) for sound_index, descriptor in self._sound_descriptors.items(): text = f"{sound_index}. {descriptor['name']}" label = DirectGui.DirectButton( parent=self._canvas, frameSize=( 0, self._DESCRIPTION_WIDTH / constants.TEXT_SIZE, -half_height, half_height, ), frameColor=(0, 0, 0, 0), scale=constants.TEXT_SIZE, text=text, text_align=core.TextNode.A_left, text_wordwrap=(self._DESCRIPTION_WIDTH) / constants.TEXT_SIZE, ) self._bind_scroll(label) label["extraArgs"] = [label, sound_index, descriptor] label["command"] = self._select_sound self._labels[sound_index] = label self._show_category("misc") items = self._categorized_sound_names.keys() items = list(sorted(items)) DirectGui.DirectOptionMenu( parent=self._dialog, pos=core.Vec3(-1, -0.9), items=items, scale=constants.TEXT_SIZE, text_align=core.TextNode.A_left, command=self._show_category, ) DirectGui.DirectButton( parent=self._dialog, pos=core.Vec3(0.8, -0.9), text="Ok", scale=constants.TEXT_SIZE, command=self._confirm, ) DirectGui.DirectButton( parent=self._dialog, pos=core.Vec3(0.92, -0.9), text="Cancel", scale=constants.TEXT_SIZE, command=self._hide, )
def __init__( self, parent: core.NodePath, default_tile: int, properties: typing.Dict[str, Property], sound_browser: sound_view.SoundView, update_tile: typing.Callable[[int], None], canvas_height: float, frame_width: float, frame_height: float, alpha=1, ): self._canvas_height = canvas_height self._frame_width = frame_width self._frame_height = frame_height self._frame = DirectGui.DirectScrolledFrame( parent=parent, frameSize=(0, self._frame_width, 0.05, self._frame_height + 0.05), frameColor=(0.65, 0.65, 0.65, alpha), state=DirectGuiGlobals.NORMAL, scrollBarWidth=0.04, relief=DirectGuiGlobals.SUNKEN, ) self._bind_scroll(self._frame) self._canvas = self._frame.getCanvas() self._default_tile = default_tile self._properties = properties self._sound_browser = sound_browser self._update_tile = update_tile self.get_current_tile: typing.Callable[[], int] = lambda: None property_list: _PROPERTY_LIST_TYPE = list(self._properties.items()) property_count = len(property_list) columns = math.ceil(property_count / self._property_rows) self._frame["canvasSize"] = ( 0, columns * self._padded_property_width + 0.2, -self._canvas_height, 0, ) self._value_setters: typing.Dict[str, typing.Any] = {} for column in range(columns): for row in range(self._property_rows): index = column * self._property_rows + row if index >= property_count: break name, descriptor = property_list[index] x = column * ( self._padded_property_width) + self._PROPERTY_PADDING / 4 y = -(row + 1) * self._property_height label = DirectGui.DirectLabel( parent=self._canvas, pos=core.Vec3(x, y), text=name, scale=constants.TEXT_SIZE, text_align=core.TextNode.A_left, frameColor=(0, 0, 0, 0), ) self._bind_scroll(label) label_size = label.node().get_frame() * constants.TEXT_SIZE label_width = (label_size[1] - label_size[0]) + self._PROPERTY_PADDING width_left = (self._PROPERTY_WIDTH - label_width) / constants.TEXT_SIZE if descriptor.property_type == Property.INTEGER_PROPERTY: setter = DirectGui.DirectEntry( parent=self._canvas, pos=core.Vec3(x + label_width, y), width=width_left, frameColor=(1, 1, 1, 1), relief=DirectGuiGlobals.SUNKEN, scale=constants.TEXT_SIZE, initialText=str(descriptor.value - descriptor.offset), ) elif descriptor.property_type == Property.BOOLEAN_PROPERTY: setter = DirectGui.DirectCheckButton( parent=self._canvas, pos=core.Vec3(x + self._PROPERTY_WIDTH, y + constants.TEXT_SIZE / 2), scale=constants.TEXT_SIZE, indicatorValue=descriptor.value ^ descriptor.offset, ) elif descriptor.property_type == Property.SOUND_PROPERTY: setter = DirectGui.DirectButton( parent=self._canvas, pos=core.Vec3(x + self._PROPERTY_WIDTH, y + constants.TEXT_SIZE / 2), scale=constants.TEXT_SIZE, text="Browse", command=self._browse_sounds, text_align=core.TextNode.A_right, ) setter.set_python_tag("sound_index", descriptor.value) elif descriptor.property_type == Property.ENUM_PROPERTY: items = list(descriptor.enum_values.keys()) setter = DirectGui.DirectOptionMenu( parent=self._canvas, pos=core.Vec3(x + label_width, y), scale=constants.TEXT_SIZE, items=items, ) setter.set( descriptor.reverse_enum_values[descriptor.value]) setter.set_python_tag("enum_values", descriptor.enum_values) else: raise ValueError( f"Invalid property type {descriptor.property_type}") self._bind_scroll(setter) self._value_setters[name] = setter setter["state"] = DirectGuiGlobals.NORMAL setter["extraArgs"] = [setter, descriptor] if descriptor.tile_link_type == Property.TILE_LINK_OFFSET: self._setup_tile_link_offset_setter(setter, descriptor)
def add_sprite_type( self, descriptor: map_objects.sprite_type_descriptor.Descriptor): frame = DirectGui.DirectButton( parent=self._canvas, pos=core.Vec3(0, self._top), frameColor=(0, 0, 0, 0), frameSize=(0, 0.54, -self._SPRITE_FRAME_SIZE, 0), relief=DirectGuiGlobals.FLAT, command=self._select_sprite_type, ) frame["extraArgs"] = [frame] self._bind_scroll(frame) frame.set_python_tag("descriptor", descriptor) texture = self._tile_manager.get_tile(descriptor.default_tile, descriptor.palette or 0) texture_frame_size = gui.size_inside_square_for_texture( texture, self._SPRITE_FRAME_SIZE) if texture_frame_size is None: return y_offset = (texture_frame_size.y - self._SPRITE_FRAME_SIZE) / 2 sprite_frame = DirectGui.DirectButton( parent=frame, pos=core.Vec3(0, y_offset), frameSize=(0, texture_frame_size.x, 0, -texture_frame_size.y), frameTexture=texture, relief=DirectGuiGlobals.FLAT, command=self._select_sprite_type, extraArgs=[frame], ) sprite_frame.set_transparency(True) self._bind_scroll(sprite_frame) word_wrap = (0.54 - texture_frame_size.x) / constants.LARGE_TEXT_SIZE frame_size = (core.Vec4( 0, 0.54 - texture_frame_size.x - 0.02, self._SPRITE_FRAME_SIZE / 2, -self._SPRITE_FRAME_SIZE / 2, ) / constants.LARGE_TEXT_SIZE) label_frame = DirectGui.DirectButton( parent=frame, pos=core.Vec3(texture_frame_size.x + 0.02, -self._SPRITE_FRAME_SIZE / 2), scale=constants.LARGE_TEXT_SIZE, text=descriptor.name, relief=DirectGuiGlobals.FLAT, frameSize=frame_size, frameColor=(0, 0, 0, 0), text_align=core.TextNode.A_left, text_wordwrap=word_wrap, command=self._select_sprite_type, extraArgs=[frame], ) self._bind_scroll(label_frame) self._top -= self._SPRITE_FRAME_SIZE + self._PADDING self._update_canvas_size() self._sprite_frames.append(frame)
def __init__(self, parent: core.NodePath, edit_mode: edit_mode.EditMode): self._dialog = DirectGui.DirectFrame( parent=parent, pos=core.Vec3(-0.78, -0.9), frameSize=(0, 1.58, 0, 1.8), relief=DirectGuiGlobals.RAISED, borderWidth=(0.01, 0.01), ) self._dialog.hide() self._property_parent: core.NodePath = self._dialog.attach_new_node( "properties") self._property_parent.set_pos(0.04, 0, 0.38) self._edit_mode = edit_mode self._wall: map_objects.EditorWall = None self._selected_descriptor: wall_type_descriptor.WallTypeDescriptor = None self._current_descriptor: wall_type_descriptor.WallTypeDescriptor = None self._current_picnum: int = None self._current_palette: int = None self._current_status_number: int = None self._properties: sprite_property_view.SpritePropertyView = None self._type_lookup = { wall_type.name: type_index for type_index, wall_type in descriptors.wall_types.items() } type_names = list(self._type_lookup.keys()) self._type_selector = DirectGui.DirectOptionMenu( parent=self._dialog, pos=core.Vec3(0.05, 0.38), scale=constants.TEXT_SIZE, items=type_names, command=self._type_changed, ) DirectGui.DirectLabel( parent=self._dialog, text="Special Source:", pos=core.Vec3(1.12, 0.38), scale=constants.TEXT_SIZE, ) self._special_source_menu = DirectGui.DirectOptionMenu( parent=self._dialog, pos=core.Vec3(1.28, 0.38), items=["None", "Level Start"], scale=constants.TEXT_SIZE, ) DirectGui.DirectLabel( parent=self._dialog, text="Special Target:", pos=core.Vec3(1.12, 0.38 - constants.TEXT_SIZE - 0.02), scale=constants.TEXT_SIZE, ) self._special_target_menu = DirectGui.DirectOptionMenu( parent=self._dialog, pos=core.Vec3(1.28, 0.38 - constants.TEXT_SIZE - 0.02), items=["None", "Next Level", "Secret Level"], scale=constants.TEXT_SIZE, ) DirectGui.DirectButton( parent=self._dialog, pos=core.Vec3(1.36, 0.07), text="Ok", scale=constants.TEXT_SIZE, command=self._save_changes, ) DirectGui.DirectButton( parent=self._dialog, pos=core.Vec3(1.48, 0.07), text="Cancel", scale=constants.TEXT_SIZE, command=self._hide, )