RuneHive-Game
Loading...
Searching...
No Matches
InterfaceManager.java
Go to the documentation of this file.
1package com.runehive.game.world.entity.mob.player;
2
3import com.runehive.Config;
4import com.runehive.content.store.Store;
5import com.runehive.content.tradingpost.TradingPost;
6import com.runehive.game.world.entity.mob.player.exchange.ExchangeSessionType;
7import com.runehive.net.packet.out.*;
8
9/**
10 * Contains information about the state of interfaces enter in the client.
11 *
12 * @author Daniel
13 */
14public class InterfaceManager {
15
16 /** The player instance. */
17 private Player player;
18
19 /** The current main interface. */
20 private int main = -1;
21
22 /** The current overlay interface. */
23 private int overlay = -1;
24
25 /** The current walkable-interface. */
26 private int walkable = -1;
27
28 /** The current dialogue. */
29 private int dialogue = -1;
30
31 private int[] sidebars = new int[15];
32
33 /** Creates a new <code>InterfaceManager<code>. */
35 this.player = player;
36 }
37
38 /** Opens an interface for the player. */
39 public void open(int identification) {
40 open(identification, true);
41 }
42
43 /** Opens an itemcontainer for the player. */
44 public void open(int identification, boolean secure) {
45 if (secure) {
46 if (player.isBot || main == identification) {
47 return;
48 }
49
50 if (player.getCombat().inCombat()) {
51 player.send(new SendMessage("You can't do this right now!"));
52 return;
53 }
54
55 if (player.dialogueFactory.isActive() || player.dialogueFactory.isOption()) {
56 player.dialogueFactory.clear();
57 }
58 }
59
60 main = identification;
61 player.movement.reset();
62 player.send(new SendInterface(identification));
63 player.send(new SendString("[CLOSE_MENU]", 0));
65 }
66
67 /** Opens a walkable-itemcontainer for the player. */
68 public void openWalkable(int identification) {
69 if (walkable == identification) {
70 return;
71 }
72 walkable = identification;
73 player.send(new SendWalkableInterface(identification));
74 }
75
76 /** Opens an inventory interface for the player. */
77 public void openInventory(int identification, int overlay) {
78 if (player.isBot || main == identification && this.overlay == overlay) {
79 return;
80 }
81
82 main = identification;
83 this.overlay = overlay;
84 player.movement.reset();
85 player.send(new SendString("[CLOSE_MENU]", 0));
86 player.send(new SendInventoryInterface(identification, overlay));
88
89 }
90
91 public void close(int interfaceId) {
92 if (isInterfaceOpen(interfaceId)) {
93 close();
94 }
95 }
96
97 /** Clears the player's screen. */
98 public void close() {
99 close(true);
100 }
101
102 /** Handles clearing the screen. */
103 public void close(boolean walkable) {
104 com.runehive.game.world.entity.mob.player.camera.DialogueCameraDirector.requestReset(player);
105 if (player.isBot) {
106 return;
107 }
108
109 if (player.attributes.has("SHOP")) {
111 }
112
113 if (player.attributes.is("BANK_KEY")) {
114 player.bank.close();
115 }
116
117 if (player.attributes.is("PRICE_CHECKER_KEY")) {
118 player.priceChecker.close();
119 }
120
121 if (player.attributes.is("TRADE_KEY")) {
122 player.exchangeSession.reset(ExchangeSessionType.TRADE);
123 }
124
125 if (player.attributes.is("DUEL_KEY")) {
126 player.exchangeSession.reset(ExchangeSessionType.DUEL);
127 }
128
129 if (player.attributes.is("DONATOR_DEPOSIT_KEY")) {
130 player.donatorDeposit.close();
131 }
132
134 player.tradingPost.cleanUp();
135 }
136
137 if (walkable) {
138 openWalkable(-1);
139 }
140
141 main = -1;
142 dialogue = -1;
143 player.dialogueFactory.clear();
144 player.send(new SendRemoveInterface());
145// player.send(new SendString("[CLOSE_MENU]", 0));
147 }
148
149 public void setSidebar(int tab, int id) {
150 if (sidebars[tab] == id && id != -1) {
151 return;
152 }
153 sidebars[tab] = id;
154 player.send(new SendSideBarInterface(tab, id));
155
156 }
157
158 /** Checks if a certain interface is enter. */
159 public boolean isInterfaceOpen(int id) {
160 return main == id;
161 }
162
163 public boolean hasAnyOpen(int... ids) {
164 for (int id : ids) {
165 if (main == id)
166 return true;
167 }
168 return false;
169 }
170
171 /** Checks if the player's screen is clear. */
172 public boolean isClear() {
173 return main == -1 && dialogue == -1 && walkable == -1;
174 }
175
176 /** Checks if the main interface is clear. */
177 public boolean isMainClear() {
178 return main == -1;
179 }
180
181 /** Checks if the dialogue interface is clear. */
182 public boolean isDialogueClear() {
183 return dialogue == -1;
184 }
185
186 /** Sets the current interface. */
187 public void setMain(int currentInterface) {
188 this.main = currentInterface;
189 }
190
191 /** gets the current main interface. */
192 public int getMain() {
193 return main;
194 }
195
196 /** Gets the dialogue interface. */
197 public int getDialogue() {
198 return dialogue;
199 }
200
201 /** Sets the dialogue interface. */
202 public void setDialogue(int dialogueInterface) {
203 this.dialogue = dialogueInterface;
204 }
205
206 /** Gets the walkable interface. */
207 public int getWalkable() {
208 return walkable;
209 }
210
211 /** Sets the walkable interface. */
212 public void setWalkable(int walkableInterface) {
213 this.walkable = walkableInterface;
214 }
215
216 public int getSidebar(int tab) {
217 if (tab > sidebars.length) {
218 return -1;
219 }
220 return sidebars[tab];
221 }
222
223 public boolean isSidebar(int tab, int id) {
224 return tab <= sidebars.length && sidebars[tab] == id;
225 }
226
227 public boolean hasSidebar(int id) {
228 for (int sidebar : sidebars) {
229 if (sidebar == id) {
230 return true;
231 }
232 }
233 return false;
234 }
235}
The class that contains setting-related constants for the server.
Definition Config.java:24
static final int LOGOUT_TAB
Definition Config.java:194
The class which holds support for further abstraction for shops.
Definition Store.java:20
static void closeShop(Player player)
Definition Store.java:47
static final int BUYING_PAGE_INTERFACE_ID
InterfaceManager(Player player)
Creates a new InterfaceManager.
boolean isClear()
Checks if the player's screen is clear.
void setMain(int currentInterface)
Sets the current interface.
boolean isDialogueClear()
Checks if the dialogue interface is clear.
void setWalkable(int walkableInterface)
Sets the walkable interface.
void open(int identification, boolean secure)
Opens an itemcontainer for the player.
boolean isInterfaceOpen(int id)
Checks if a certain interface is enter.
void openInventory(int identification, int overlay)
Opens an inventory interface for the player.
void openWalkable(int identification)
Opens a walkable-itemcontainer for the player.
void setDialogue(int dialogueInterface)
Sets the dialogue interface.
void open(int identification)
Opens an interface for the player.
boolean isMainClear()
Checks if the main interface is clear.
void close(boolean walkable)
Handles clearing the screen.
This class represents a character controlled by a player.
Definition Player.java:125
The OutgoingPacket that opens an itemcontainer for Player.
The OutgoingPacket that opens the inventory with itemcontainer.
The OutgoingPacket that sends a message to a Players chatbox in the client.
The OutgoingPacket that sends a string to a Players itemcontainer in the client.