pokerogue/src/ui/ui-handler.ts

59 lines
1.2 KiB
TypeScript
Raw Normal View History

import BattleScene from "../battle-scene";
import { TextStyle, getTextColor } from "./text";
import { Mode } from "./ui";
import {Button} from "../enums/buttons";
2023-03-28 19:54:52 +01:00
Add Challenges (#1459) * Initial challenge framework * Add type localisation * Change how challenges are tracked Also fixes the difficulty total text * MVP Renames challenge types, temporarily hides difficulty, and implements challenge saving. * Attempt to fix one legal pokemon in a double battle * Make monotype ignore type changing effects * Make isOfType correctly detect normal types * Try to fix double battles again * Make challenge function more like classic * Add helper function for fainted or not allowed * Add framework for fresh start challenge and improve comments * Try to fix evolution issues * Make form changing items only usable from rewards screen * Update localisation * Additional localisation change * Add achievements for completing challenges * Fix initialisation bug with challenge achievements * Add support for gamemode specific fixed battles Also make monogen challenges face the e4 of their generation * Add better support for mobile in challenges * Localise illegal evolution/form change message * Update achievement names * Make alternate forms count for monogen * Update monotype achievement icons * Add more comments * Improve comments * Fix mid battle form changes * Reorder mode list * Remove currently unused localisation entry * Add type overrides for monotype challenges Meloetta always counts for psychic and castform always counts for normal * Change how form changes are handled Now attempts a switch at the start of each turn instead of immediately * Add start button to challenge select screen * Make starter select back out to challenge screen if using challenges * Fix daily runs * Update tests to new game mode logic
2024-06-08 06:07:23 +01:00
/**
* A basic abstract class to act as a holder and processor for UI elements.
*/
2023-03-28 19:54:52 +01:00
export default abstract class UiHandler {
protected scene: BattleScene;
protected mode: integer;
protected cursor: integer = 0;
2023-03-29 05:31:25 +01:00
public active: boolean = false;
2023-03-28 19:54:52 +01:00
Add Challenges (#1459) * Initial challenge framework * Add type localisation * Change how challenges are tracked Also fixes the difficulty total text * MVP Renames challenge types, temporarily hides difficulty, and implements challenge saving. * Attempt to fix one legal pokemon in a double battle * Make monotype ignore type changing effects * Make isOfType correctly detect normal types * Try to fix double battles again * Make challenge function more like classic * Add helper function for fainted or not allowed * Add framework for fresh start challenge and improve comments * Try to fix evolution issues * Make form changing items only usable from rewards screen * Update localisation * Additional localisation change * Add achievements for completing challenges * Fix initialisation bug with challenge achievements * Add support for gamemode specific fixed battles Also make monogen challenges face the e4 of their generation * Add better support for mobile in challenges * Localise illegal evolution/form change message * Update achievement names * Make alternate forms count for monogen * Update monotype achievement icons * Add more comments * Improve comments * Fix mid battle form changes * Reorder mode list * Remove currently unused localisation entry * Add type overrides for monotype challenges Meloetta always counts for psychic and castform always counts for normal * Change how form changes are handled Now attempts a switch at the start of each turn instead of immediately * Add start button to challenge select screen * Make starter select back out to challenge screen if using challenges * Fix daily runs * Update tests to new game mode logic
2024-06-08 06:07:23 +01:00
/**
* @param {BattleScene} scene The same scene as everything else.
* @param {Mode} mode The mode of the UI element. These should be unique.
*/
2023-03-28 19:54:52 +01:00
constructor(scene: BattleScene, mode: Mode) {
this.scene = scene;
this.mode = mode;
}
abstract setup(): void;
2023-12-30 23:41:25 +00:00
show(_args: any[]): boolean {
2023-03-28 19:54:52 +01:00
this.active = true;
2023-12-30 23:41:25 +00:00
return true;
2023-03-28 19:54:52 +01:00
}
abstract processInput(button: Button): boolean;
2023-03-28 19:54:52 +01:00
getUi() {
return this.scene.ui;
}
getTextColor(style: TextStyle, shadow: boolean = false): string {
return getTextColor(style, shadow, this.scene.uiTheme);
}
2023-03-31 04:02:35 +01:00
getCursor(): integer {
return this.cursor;
}
2023-03-28 19:54:52 +01:00
setCursor(cursor: integer): boolean {
const changed = this.cursor !== cursor;
if (changed) {
2023-03-28 19:54:52 +01:00
this.cursor = cursor;
}
2023-03-28 19:54:52 +01:00
return changed;
}
clear() {
this.active = false;
}
}